raspberrypi.patch 3.1 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490564915649256493564945649556496564975649856499565005650156502565035650456505565065650756508565095651056511565125651356514565155651656517565185651956520565215652256523565245652556526565275652856529565305653156532565335653456535565365653756538565395654056541565425654356544565455654656547565485654956550565515655256553565545655556556565575655856559565605656156562565635656456565565665656756568565695657056571565725657356574565755657656577565785657956580565815658256583565845658556586565875658856589565905659156592565935659456595565965659756598565995660056601566025660356604566055660656607566085660956610566115661256613566145661556616566175661856619566205662156622566235662456625566265662756628566295663056631566325663356634566355663656637566385663956640566415664256643566445664556646566475664856649566505665156652566535665456655566565665756658566595666056661566625666356664566655666656667566685666956670566715667256673566745667556676566775667856679566805668156682566835668456685566865668756688566895669056691566925669356694566955669656697566985669956700567015670256703567045670556706567075670856709567105671156712567135671456715567165671756718567195672056721567225672356724567255672656727567285672956730567315673256733567345673556736567375673856739567405674156742567435674456745567465674756748567495675056751567525675356754567555675656757567585675956760567615676256763567645676556766567675676856769567705677156772567735677456775567765677756778567795678056781567825678356784567855678656787567885678956790567915679256793567945679556796567975679856799568005680156802568035680456805568065680756808568095681056811568125681356814568155681656817568185681956820568215682256823568245682556826568275682856829568305683156832568335683456835568365683756838568395684056841568425684356844568455684656847568485684956850568515685256853568545685556856568575685856859568605686156862568635686456865568665686756868568695687056871568725687356874568755687656877568785687956880568815688256883568845688556886568875688856889568905689156892568935689456895568965689756898568995690056901569025690356904569055690656907569085690956910569115691256913569145691556916569175691856919569205692156922569235692456925569265692756928569295693056931569325693356934569355693656937569385693956940569415694256943569445694556946569475694856949569505695156952569535695456955569565695756958569595696056961569625696356964569655696656967569685696956970569715697256973569745697556976569775697856979569805698156982569835698456985569865698756988569895699056991569925699356994569955699656997569985699957000570015700257003570045700557006570075700857009570105701157012570135701457015570165701757018570195702057021570225702357024570255702657027570285702957030570315703257033570345703557036570375703857039570405704157042570435704457045570465704757048570495705057051570525705357054570555705657057570585705957060570615706257063570645706557066570675706857069570705707157072570735707457075570765707757078570795708057081570825708357084570855708657087570885708957090570915709257093570945709557096570975709857099571005710157102571035710457105571065710757108571095711057111571125711357114571155711657117571185711957120571215712257123571245712557126571275712857129571305713157132571335713457135571365713757138571395714057141571425714357144571455714657147571485714957150571515715257153571545715557156571575715857159571605716157162571635716457165571665716757168571695717057171571725717357174571755717657177571785717957180571815718257183571845718557186571875718857189571905719157192571935719457195571965719757198571995720057201572025720357204572055720657207572085720957210572115721257213572145721557216572175721857219572205722157222572235722457225572265722757228572295723057231572325723357234572355723657237572385723957240572415724257243572445724557246572475724857249572505725157252572535725457255572565725757258572595726057261572625726357264572655726657267572685726957270572715727257273572745727557276572775727857279572805728157282572835728457285572865728757288572895729057291572925729357294572955729657297572985729957300573015730257303573045730557306573075730857309573105731157312573135731457315573165731757318573195732057321573225732357324573255732657327573285732957330573315733257333573345733557336573375733857339573405734157342573435734457345573465734757348573495735057351573525735357354573555735657357573585735957360573615736257363573645736557366573675736857369573705737157372573735737457375573765737757378573795738057381573825738357384573855738657387573885738957390573915739257393573945739557396573975739857399574005740157402574035740457405574065740757408574095741057411574125741357414574155741657417574185741957420574215742257423574245742557426574275742857429574305743157432574335743457435574365743757438574395744057441574425744357444574455744657447574485744957450574515745257453574545745557456574575745857459574605746157462574635746457465574665746757468574695747057471574725747357474574755747657477574785747957480574815748257483574845748557486574875748857489574905749157492574935749457495574965749757498574995750057501575025750357504575055750657507575085750957510575115751257513575145751557516575175751857519575205752157522575235752457525575265752757528575295753057531575325753357534575355753657537575385753957540575415754257543575445754557546575475754857549575505755157552575535755457555575565755757558575595756057561575625756357564575655756657567575685756957570575715757257573575745757557576575775757857579575805758157582575835758457585575865758757588575895759057591575925759357594575955759657597575985759957600576015760257603576045760557606576075760857609576105761157612576135761457615576165761757618576195762057621576225762357624576255762657627576285762957630576315763257633576345763557636576375763857639576405764157642576435764457645576465764757648576495765057651576525765357654576555765657657576585765957660576615766257663576645766557666576675766857669576705767157672576735767457675576765767757678576795768057681576825768357684576855768657687576885768957690576915769257693576945769557696576975769857699577005770157702577035770457705577065770757708577095771057711577125771357714577155771657717577185771957720577215772257723577245772557726577275772857729577305773157732577335773457735577365773757738577395774057741577425774357744577455774657747577485774957750577515775257753577545775557756577575775857759577605776157762577635776457765577665776757768577695777057771577725777357774577755777657777577785777957780577815778257783577845778557786577875778857789577905779157792577935779457795577965779757798577995780057801578025780357804578055780657807578085780957810578115781257813578145781557816578175781857819578205782157822578235782457825578265782757828578295783057831578325783357834578355783657837578385783957840578415784257843578445784557846578475784857849578505785157852578535785457855578565785757858578595786057861578625786357864578655786657867578685786957870578715787257873578745787557876578775787857879578805788157882578835788457885578865788757888578895789057891578925789357894578955789657897578985789957900579015790257903579045790557906579075790857909579105791157912579135791457915579165791757918579195792057921579225792357924579255792657927579285792957930579315793257933579345793557936579375793857939579405794157942579435794457945579465794757948579495795057951579525795357954579555795657957579585795957960579615796257963579645796557966579675796857969579705797157972579735797457975579765797757978579795798057981579825798357984579855798657987579885798957990579915799257993579945799557996579975799857999580005800158002580035800458005580065800758008580095801058011580125801358014580155801658017580185801958020580215802258023580245802558026580275802858029580305803158032580335803458035580365803758038580395804058041580425804358044580455804658047580485804958050580515805258053580545805558056580575805858059580605806158062580635806458065580665806758068580695807058071580725807358074580755807658077580785807958080580815808258083580845808558086580875808858089580905809158092580935809458095580965809758098580995810058101581025810358104581055810658107581085810958110581115811258113581145811558116581175811858119581205812158122581235812458125581265812758128581295813058131581325813358134581355813658137581385813958140581415814258143581445814558146581475814858149581505815158152581535815458155581565815758158581595816058161581625816358164581655816658167581685816958170581715817258173581745817558176581775817858179581805818158182581835818458185581865818758188581895819058191581925819358194581955819658197581985819958200582015820258203582045820558206582075820858209582105821158212582135821458215582165821758218582195822058221582225822358224582255822658227582285822958230582315823258233582345823558236582375823858239582405824158242582435824458245582465824758248582495825058251582525825358254582555825658257582585825958260582615826258263582645826558266582675826858269582705827158272582735827458275582765827758278582795828058281582825828358284582855828658287582885828958290582915829258293582945829558296582975829858299583005830158302583035830458305583065830758308583095831058311583125831358314583155831658317583185831958320583215832258323583245832558326583275832858329583305833158332583335833458335583365833758338583395834058341583425834358344583455834658347583485834958350583515835258353583545835558356583575835858359583605836158362583635836458365583665836758368583695837058371583725837358374583755837658377583785837958380583815838258383583845838558386583875838858389583905839158392583935839458395583965839758398583995840058401584025840358404584055840658407584085840958410584115841258413584145841558416584175841858419584205842158422584235842458425584265842758428584295843058431584325843358434584355843658437584385843958440584415844258443584445844558446584475844858449584505845158452584535845458455584565845758458584595846058461584625846358464584655846658467584685846958470584715847258473584745847558476584775847858479584805848158482584835848458485584865848758488584895849058491584925849358494584955849658497584985849958500585015850258503585045850558506585075850858509585105851158512585135851458515585165851758518585195852058521585225852358524585255852658527585285852958530585315853258533585345853558536585375853858539585405854158542585435854458545585465854758548585495855058551585525855358554585555855658557585585855958560585615856258563585645856558566585675856858569585705857158572585735857458575585765857758578585795858058581585825858358584585855858658587585885858958590585915859258593585945859558596585975859858599586005860158602586035860458605586065860758608586095861058611586125861358614586155861658617586185861958620586215862258623586245862558626586275862858629586305863158632586335863458635586365863758638586395864058641586425864358644586455864658647586485864958650586515865258653586545865558656586575865858659586605866158662586635866458665586665866758668586695867058671586725867358674586755867658677586785867958680586815868258683586845868558686586875868858689586905869158692586935869458695586965869758698586995870058701587025870358704587055870658707587085870958710587115871258713587145871558716587175871858719587205872158722587235872458725587265872758728587295873058731587325873358734587355873658737587385873958740587415874258743587445874558746587475874858749587505875158752587535875458755587565875758758587595876058761587625876358764587655876658767587685876958770587715877258773587745877558776587775877858779587805878158782587835878458785587865878758788587895879058791587925879358794587955879658797587985879958800588015880258803588045880558806588075880858809588105881158812588135881458815588165881758818588195882058821588225882358824588255882658827588285882958830588315883258833588345883558836588375883858839588405884158842588435884458845588465884758848588495885058851588525885358854588555885658857588585885958860588615886258863588645886558866588675886858869588705887158872588735887458875588765887758878588795888058881588825888358884588855888658887588885888958890588915889258893588945889558896588975889858899589005890158902589035890458905589065890758908589095891058911589125891358914589155891658917589185891958920589215892258923589245892558926589275892858929589305893158932589335893458935589365893758938589395894058941589425894358944589455894658947589485894958950589515895258953589545895558956589575895858959589605896158962589635896458965589665896758968589695897058971589725897358974589755897658977589785897958980589815898258983589845898558986589875898858989589905899158992589935899458995589965899758998589995900059001590025900359004590055900659007590085900959010590115901259013590145901559016590175901859019590205902159022590235902459025590265902759028590295903059031590325903359034590355903659037590385903959040590415904259043590445904559046590475904859049590505905159052590535905459055590565905759058590595906059061590625906359064590655906659067590685906959070590715907259073590745907559076590775907859079590805908159082590835908459085590865908759088590895909059091590925909359094590955909659097590985909959100591015910259103591045910559106591075910859109591105911159112591135911459115591165911759118591195912059121591225912359124591255912659127591285912959130591315913259133591345913559136591375913859139591405914159142591435914459145591465914759148591495915059151591525915359154591555915659157591585915959160591615916259163591645916559166591675916859169591705917159172591735917459175591765917759178591795918059181591825918359184591855918659187591885918959190591915919259193591945919559196591975919859199592005920159202592035920459205592065920759208592095921059211592125921359214592155921659217592185921959220592215922259223592245922559226592275922859229592305923159232592335923459235592365923759238592395924059241592425924359244592455924659247592485924959250592515925259253592545925559256592575925859259592605926159262592635926459265592665926759268592695927059271592725927359274592755927659277592785927959280592815928259283592845928559286592875928859289592905929159292592935929459295592965929759298592995930059301593025930359304593055930659307593085930959310593115931259313593145931559316593175931859319593205932159322593235932459325593265932759328593295933059331593325933359334593355933659337593385933959340593415934259343593445934559346593475934859349593505935159352593535935459355593565935759358593595936059361593625936359364593655936659367593685936959370593715937259373593745937559376593775937859379593805938159382593835938459385593865938759388593895939059391593925939359394593955939659397593985939959400594015940259403594045940559406594075940859409594105941159412594135941459415594165941759418594195942059421594225942359424594255942659427594285942959430594315943259433594345943559436594375943859439594405944159442594435944459445594465944759448594495945059451594525945359454594555945659457594585945959460594615946259463594645946559466594675946859469594705947159472594735947459475594765947759478594795948059481594825948359484594855948659487594885948959490594915949259493594945949559496594975949859499595005950159502595035950459505595065950759508595095951059511595125951359514595155951659517595185951959520595215952259523595245952559526595275952859529595305953159532595335953459535595365953759538595395954059541595425954359544595455954659547595485954959550595515955259553595545955559556595575955859559595605956159562595635956459565595665956759568595695957059571595725957359574595755957659577595785957959580595815958259583595845958559586595875958859589595905959159592595935959459595595965959759598595995960059601596025960359604596055960659607596085960959610596115961259613596145961559616596175961859619596205962159622596235962459625596265962759628596295963059631596325963359634596355963659637596385963959640596415964259643596445964559646596475964859649596505965159652596535965459655596565965759658596595966059661596625966359664596655966659667596685966959670596715967259673596745967559676596775967859679596805968159682596835968459685596865968759688596895969059691596925969359694596955969659697596985969959700597015970259703597045970559706597075970859709597105971159712597135971459715597165971759718597195972059721597225972359724597255972659727597285972959730597315973259733597345973559736597375973859739597405974159742597435974459745597465974759748597495975059751597525975359754597555975659757597585975959760597615976259763597645976559766597675976859769597705977159772597735977459775597765977759778597795978059781597825978359784597855978659787597885978959790597915979259793597945979559796597975979859799598005980159802598035980459805598065980759808598095981059811598125981359814598155981659817598185981959820598215982259823598245982559826598275982859829598305983159832598335983459835598365983759838598395984059841598425984359844598455984659847598485984959850598515985259853598545985559856598575985859859598605986159862598635986459865598665986759868598695987059871598725987359874598755987659877598785987959880598815988259883598845988559886598875988859889598905989159892598935989459895598965989759898598995990059901599025990359904599055990659907599085990959910599115991259913599145991559916599175991859919599205992159922599235992459925599265992759928599295993059931599325993359934599355993659937599385993959940599415994259943599445994559946599475994859949599505995159952599535995459955599565995759958599595996059961599625996359964599655996659967599685996959970599715997259973599745997559976599775997859979599805998159982599835998459985599865998759988599895999059991599925999359994599955999659997599985999960000600016000260003600046000560006600076000860009600106001160012600136001460015600166001760018600196002060021600226002360024600256002660027600286002960030600316003260033600346003560036600376003860039600406004160042600436004460045600466004760048600496005060051600526005360054600556005660057600586005960060600616006260063600646006560066600676006860069600706007160072600736007460075600766007760078600796008060081600826008360084600856008660087600886008960090600916009260093600946009560096600976009860099601006010160102601036010460105601066010760108601096011060111601126011360114601156011660117601186011960120601216012260123601246012560126601276012860129601306013160132601336013460135601366013760138601396014060141601426014360144601456014660147601486014960150601516015260153601546015560156601576015860159601606016160162601636016460165601666016760168601696017060171601726017360174601756017660177601786017960180601816018260183601846018560186601876018860189601906019160192601936019460195601966019760198601996020060201602026020360204602056020660207602086020960210602116021260213602146021560216602176021860219602206022160222602236022460225602266022760228602296023060231602326023360234602356023660237602386023960240602416024260243602446024560246602476024860249602506025160252602536025460255602566025760258602596026060261602626026360264602656026660267602686026960270602716027260273602746027560276602776027860279602806028160282602836028460285602866028760288602896029060291602926029360294602956029660297602986029960300603016030260303603046030560306603076030860309603106031160312603136031460315603166031760318603196032060321603226032360324603256032660327603286032960330603316033260333603346033560336603376033860339603406034160342603436034460345603466034760348603496035060351603526035360354603556035660357603586035960360603616036260363603646036560366603676036860369603706037160372603736037460375603766037760378603796038060381603826038360384603856038660387603886038960390603916039260393603946039560396603976039860399604006040160402604036040460405604066040760408604096041060411604126041360414604156041660417604186041960420604216042260423604246042560426604276042860429604306043160432604336043460435604366043760438604396044060441604426044360444604456044660447604486044960450604516045260453604546045560456604576045860459604606046160462604636046460465604666046760468604696047060471604726047360474604756047660477604786047960480604816048260483604846048560486604876048860489604906049160492604936049460495604966049760498604996050060501605026050360504605056050660507605086050960510605116051260513605146051560516605176051860519605206052160522605236052460525605266052760528605296053060531605326053360534605356053660537605386053960540605416054260543605446054560546605476054860549605506055160552605536055460555605566055760558605596056060561605626056360564605656056660567605686056960570605716057260573605746057560576605776057860579605806058160582605836058460585605866058760588605896059060591605926059360594605956059660597605986059960600606016060260603606046060560606606076060860609606106061160612606136061460615606166061760618606196062060621606226062360624606256062660627606286062960630606316063260633606346063560636606376063860639606406064160642606436064460645606466064760648606496065060651606526065360654606556065660657606586065960660606616066260663606646066560666606676066860669606706067160672606736067460675606766067760678606796068060681606826068360684606856068660687606886068960690606916069260693606946069560696606976069860699607006070160702607036070460705607066070760708607096071060711607126071360714607156071660717607186071960720607216072260723607246072560726607276072860729607306073160732607336073460735607366073760738607396074060741607426074360744607456074660747607486074960750607516075260753607546075560756607576075860759607606076160762607636076460765607666076760768607696077060771607726077360774607756077660777607786077960780607816078260783607846078560786607876078860789607906079160792607936079460795607966079760798607996080060801608026080360804608056080660807608086080960810608116081260813608146081560816608176081860819608206082160822608236082460825608266082760828608296083060831608326083360834608356083660837608386083960840608416084260843608446084560846608476084860849608506085160852608536085460855608566085760858608596086060861608626086360864608656086660867608686086960870608716087260873608746087560876608776087860879608806088160882608836088460885608866088760888608896089060891608926089360894608956089660897608986089960900609016090260903609046090560906609076090860909609106091160912609136091460915609166091760918609196092060921609226092360924609256092660927609286092960930609316093260933609346093560936609376093860939609406094160942609436094460945609466094760948609496095060951609526095360954609556095660957609586095960960609616096260963609646096560966609676096860969609706097160972609736097460975609766097760978609796098060981609826098360984609856098660987609886098960990609916099260993609946099560996609976099860999610006100161002610036100461005610066100761008610096101061011610126101361014610156101661017610186101961020610216102261023610246102561026610276102861029610306103161032610336103461035610366103761038610396104061041610426104361044610456104661047610486104961050610516105261053610546105561056610576105861059610606106161062610636106461065610666106761068610696107061071610726107361074610756107661077610786107961080610816108261083610846108561086610876108861089610906109161092610936109461095610966109761098610996110061101611026110361104611056110661107611086110961110611116111261113611146111561116611176111861119611206112161122611236112461125611266112761128611296113061131611326113361134611356113661137611386113961140611416114261143611446114561146611476114861149611506115161152611536115461155611566115761158611596116061161611626116361164611656116661167611686116961170611716117261173611746117561176611776117861179611806118161182611836118461185611866118761188611896119061191611926119361194611956119661197611986119961200612016120261203612046120561206612076120861209612106121161212612136121461215612166121761218612196122061221612226122361224612256122661227612286122961230612316123261233612346123561236612376123861239612406124161242612436124461245612466124761248612496125061251612526125361254612556125661257612586125961260612616126261263612646126561266612676126861269612706127161272612736127461275612766127761278612796128061281612826128361284612856128661287612886128961290612916129261293612946129561296612976129861299613006130161302613036130461305613066130761308613096131061311613126131361314613156131661317613186131961320613216132261323613246132561326613276132861329613306133161332613336133461335613366133761338613396134061341613426134361344613456134661347613486134961350613516135261353613546135561356613576135861359613606136161362613636136461365613666136761368613696137061371613726137361374613756137661377613786137961380613816138261383613846138561386613876138861389613906139161392613936139461395613966139761398613996140061401614026140361404614056140661407614086140961410614116141261413614146141561416614176141861419614206142161422614236142461425614266142761428614296143061431614326143361434614356143661437614386143961440614416144261443614446144561446614476144861449614506145161452614536145461455614566145761458614596146061461614626146361464614656146661467614686146961470614716147261473614746147561476614776147861479614806148161482614836148461485614866148761488614896149061491614926149361494614956149661497614986149961500615016150261503615046150561506615076150861509615106151161512615136151461515615166151761518615196152061521615226152361524615256152661527615286152961530615316153261533615346153561536615376153861539615406154161542615436154461545615466154761548615496155061551615526155361554615556155661557615586155961560615616156261563615646156561566615676156861569615706157161572615736157461575615766157761578615796158061581615826158361584615856158661587615886158961590615916159261593615946159561596615976159861599616006160161602616036160461605616066160761608616096161061611616126161361614616156161661617616186161961620616216162261623616246162561626616276162861629616306163161632616336163461635616366163761638616396164061641616426164361644616456164661647616486164961650616516165261653616546165561656616576165861659616606166161662616636166461665616666166761668616696167061671616726167361674616756167661677616786167961680616816168261683616846168561686616876168861689616906169161692616936169461695616966169761698616996170061701617026170361704617056170661707617086170961710617116171261713617146171561716617176171861719617206172161722617236172461725617266172761728617296173061731617326173361734617356173661737617386173961740617416174261743617446174561746617476174861749617506175161752617536175461755617566175761758617596176061761617626176361764617656176661767617686176961770617716177261773617746177561776617776177861779617806178161782617836178461785617866178761788617896179061791617926179361794617956179661797617986179961800618016180261803618046180561806618076180861809618106181161812618136181461815618166181761818618196182061821618226182361824618256182661827618286182961830618316183261833618346183561836618376183861839618406184161842618436184461845618466184761848618496185061851618526185361854618556185661857618586185961860618616186261863618646186561866618676186861869618706187161872618736187461875618766187761878618796188061881618826188361884618856188661887618886188961890618916189261893618946189561896618976189861899619006190161902619036190461905619066190761908619096191061911619126191361914619156191661917619186191961920619216192261923619246192561926619276192861929619306193161932619336193461935619366193761938619396194061941619426194361944619456194661947619486194961950619516195261953619546195561956619576195861959619606196161962619636196461965619666196761968619696197061971619726197361974619756197661977619786197961980619816198261983619846198561986619876198861989619906199161992619936199461995619966199761998619996200062001620026200362004620056200662007620086200962010620116201262013620146201562016620176201862019620206202162022620236202462025620266202762028620296203062031620326203362034620356203662037620386203962040620416204262043620446204562046620476204862049620506205162052620536205462055620566205762058620596206062061620626206362064620656206662067620686206962070620716207262073620746207562076620776207862079620806208162082620836208462085620866208762088620896209062091620926209362094620956209662097620986209962100621016210262103621046210562106621076210862109621106211162112621136211462115621166211762118621196212062121621226212362124621256212662127621286212962130621316213262133621346213562136621376213862139621406214162142621436214462145621466214762148621496215062151621526215362154621556215662157621586215962160621616216262163621646216562166621676216862169621706217162172621736217462175621766217762178621796218062181621826218362184621856218662187621886218962190621916219262193621946219562196621976219862199622006220162202622036220462205622066220762208622096221062211622126221362214622156221662217622186221962220622216222262223622246222562226622276222862229622306223162232622336223462235622366223762238622396224062241622426224362244622456224662247622486224962250622516225262253622546225562256622576225862259622606226162262622636226462265622666226762268622696227062271622726227362274622756227662277622786227962280622816228262283622846228562286622876228862289622906229162292622936229462295622966229762298622996230062301623026230362304623056230662307623086230962310623116231262313623146231562316623176231862319623206232162322623236232462325623266232762328623296233062331623326233362334623356233662337623386233962340623416234262343623446234562346623476234862349623506235162352623536235462355623566235762358623596236062361623626236362364623656236662367623686236962370623716237262373623746237562376623776237862379623806238162382623836238462385623866238762388623896239062391623926239362394623956239662397623986239962400624016240262403624046240562406624076240862409624106241162412624136241462415624166241762418624196242062421624226242362424624256242662427624286242962430624316243262433624346243562436624376243862439624406244162442624436244462445624466244762448624496245062451624526245362454624556245662457624586245962460624616246262463624646246562466624676246862469624706247162472624736247462475624766247762478624796248062481624826248362484624856248662487624886248962490624916249262493624946249562496624976249862499625006250162502625036250462505625066250762508625096251062511625126251362514625156251662517625186251962520625216252262523625246252562526625276252862529625306253162532625336253462535625366253762538625396254062541625426254362544625456254662547625486254962550625516255262553625546255562556625576255862559625606256162562625636256462565625666256762568625696257062571625726257362574625756257662577625786257962580625816258262583625846258562586625876258862589625906259162592625936259462595625966259762598625996260062601626026260362604626056260662607626086260962610626116261262613626146261562616626176261862619626206262162622626236262462625626266262762628626296263062631626326263362634626356263662637626386263962640626416264262643626446264562646626476264862649626506265162652626536265462655626566265762658626596266062661626626266362664626656266662667626686266962670626716267262673626746267562676626776267862679626806268162682626836268462685626866268762688626896269062691626926269362694626956269662697626986269962700627016270262703627046270562706627076270862709627106271162712627136271462715627166271762718627196272062721627226272362724627256272662727627286272962730627316273262733627346273562736627376273862739627406274162742627436274462745627466274762748627496275062751627526275362754627556275662757627586275962760627616276262763627646276562766627676276862769627706277162772627736277462775627766277762778627796278062781627826278362784627856278662787627886278962790627916279262793627946279562796627976279862799628006280162802628036280462805628066280762808628096281062811628126281362814628156281662817628186281962820628216282262823628246282562826628276282862829628306283162832628336283462835628366283762838628396284062841628426284362844628456284662847628486284962850628516285262853628546285562856628576285862859628606286162862628636286462865628666286762868628696287062871628726287362874628756287662877628786287962880628816288262883628846288562886628876288862889628906289162892628936289462895628966289762898628996290062901629026290362904629056290662907629086290962910629116291262913629146291562916629176291862919629206292162922629236292462925629266292762928629296293062931629326293362934629356293662937629386293962940629416294262943629446294562946629476294862949629506295162952629536295462955629566295762958629596296062961629626296362964629656296662967629686296962970629716297262973629746297562976629776297862979629806298162982629836298462985629866298762988629896299062991629926299362994629956299662997629986299963000630016300263003630046300563006630076300863009630106301163012630136301463015630166301763018630196302063021630226302363024630256302663027630286302963030630316303263033630346303563036630376303863039630406304163042630436304463045630466304763048630496305063051630526305363054630556305663057630586305963060630616306263063630646306563066630676306863069630706307163072630736307463075630766307763078630796308063081630826308363084630856308663087630886308963090630916309263093630946309563096630976309863099631006310163102631036310463105631066310763108631096311063111631126311363114631156311663117631186311963120631216312263123631246312563126631276312863129631306313163132631336313463135631366313763138631396314063141631426314363144631456314663147631486314963150631516315263153631546315563156631576315863159631606316163162631636316463165631666316763168631696317063171631726317363174631756317663177631786317963180631816318263183631846318563186631876318863189631906319163192631936319463195631966319763198631996320063201632026320363204632056320663207632086320963210632116321263213632146321563216632176321863219632206322163222632236322463225632266322763228632296323063231632326323363234632356323663237632386323963240632416324263243632446324563246632476324863249632506325163252632536325463255632566325763258632596326063261632626326363264632656326663267632686326963270632716327263273632746327563276632776327863279632806328163282632836328463285632866328763288632896329063291632926329363294632956329663297632986329963300633016330263303633046330563306633076330863309633106331163312633136331463315633166331763318633196332063321633226332363324633256332663327633286332963330633316333263333633346333563336633376333863339633406334163342633436334463345633466334763348633496335063351633526335363354633556335663357633586335963360633616336263363633646336563366633676336863369633706337163372633736337463375633766337763378633796338063381633826338363384633856338663387633886338963390633916339263393633946339563396633976339863399634006340163402634036340463405634066340763408634096341063411634126341363414634156341663417634186341963420634216342263423634246342563426634276342863429634306343163432634336343463435634366343763438634396344063441634426344363444634456344663447634486344963450634516345263453634546345563456634576345863459634606346163462634636346463465634666346763468634696347063471634726347363474634756347663477634786347963480634816348263483634846348563486634876348863489634906349163492634936349463495634966349763498634996350063501635026350363504635056350663507635086350963510635116351263513635146351563516635176351863519635206352163522635236352463525635266352763528635296353063531635326353363534635356353663537635386353963540635416354263543635446354563546635476354863549635506355163552635536355463555635566355763558635596356063561635626356363564635656356663567635686356963570635716357263573635746357563576635776357863579635806358163582635836358463585635866358763588635896359063591635926359363594635956359663597635986359963600636016360263603636046360563606636076360863609636106361163612636136361463615636166361763618636196362063621636226362363624636256362663627636286362963630636316363263633636346363563636636376363863639636406364163642636436364463645636466364763648636496365063651636526365363654636556365663657636586365963660636616366263663636646366563666636676366863669636706367163672636736367463675636766367763678636796368063681636826368363684636856368663687636886368963690636916369263693636946369563696636976369863699637006370163702637036370463705637066370763708637096371063711637126371363714637156371663717637186371963720637216372263723637246372563726637276372863729637306373163732637336373463735637366373763738637396374063741637426374363744637456374663747637486374963750637516375263753637546375563756637576375863759637606376163762637636376463765637666376763768637696377063771637726377363774637756377663777637786377963780637816378263783637846378563786637876378863789637906379163792637936379463795637966379763798637996380063801638026380363804638056380663807638086380963810638116381263813638146381563816638176381863819638206382163822638236382463825638266382763828638296383063831638326383363834638356383663837638386383963840638416384263843638446384563846638476384863849638506385163852638536385463855638566385763858638596386063861638626386363864638656386663867638686386963870638716387263873638746387563876638776387863879638806388163882638836388463885638866388763888638896389063891638926389363894638956389663897638986389963900639016390263903639046390563906639076390863909639106391163912639136391463915639166391763918639196392063921639226392363924639256392663927639286392963930639316393263933639346393563936639376393863939639406394163942639436394463945639466394763948639496395063951639526395363954639556395663957639586395963960639616396263963639646396563966639676396863969639706397163972639736397463975639766397763978639796398063981639826398363984639856398663987639886398963990639916399263993639946399563996639976399863999640006400164002640036400464005640066400764008640096401064011640126401364014640156401664017640186401964020640216402264023640246402564026640276402864029640306403164032640336403464035640366403764038640396404064041640426404364044640456404664047640486404964050640516405264053640546405564056640576405864059640606406164062640636406464065640666406764068640696407064071640726407364074640756407664077640786407964080640816408264083640846408564086640876408864089640906409164092640936409464095640966409764098640996410064101641026410364104641056410664107641086410964110641116411264113641146411564116641176411864119641206412164122641236412464125641266412764128641296413064131641326413364134641356413664137641386413964140641416414264143641446414564146641476414864149641506415164152641536415464155641566415764158641596416064161641626416364164641656416664167641686416964170641716417264173641746417564176641776417864179641806418164182641836418464185641866418764188641896419064191641926419364194641956419664197641986419964200642016420264203642046420564206642076420864209642106421164212642136421464215642166421764218642196422064221642226422364224642256422664227642286422964230642316423264233642346423564236642376423864239642406424164242642436424464245642466424764248642496425064251642526425364254642556425664257642586425964260642616426264263642646426564266642676426864269642706427164272642736427464275642766427764278642796428064281642826428364284642856428664287642886428964290642916429264293642946429564296642976429864299643006430164302643036430464305643066430764308643096431064311643126431364314643156431664317643186431964320643216432264323643246432564326643276432864329643306433164332643336433464335643366433764338643396434064341643426434364344643456434664347643486434964350643516435264353643546435564356643576435864359643606436164362643636436464365643666436764368643696437064371643726437364374643756437664377643786437964380643816438264383643846438564386643876438864389643906439164392643936439464395643966439764398643996440064401644026440364404644056440664407644086440964410644116441264413644146441564416644176441864419644206442164422644236442464425644266442764428644296443064431644326443364434644356443664437644386443964440644416444264443644446444564446644476444864449644506445164452644536445464455644566445764458644596446064461644626446364464644656446664467644686446964470644716447264473644746447564476644776447864479644806448164482644836448464485644866448764488644896449064491644926449364494644956449664497644986449964500645016450264503645046450564506645076450864509645106451164512645136451464515645166451764518645196452064521645226452364524645256452664527645286452964530645316453264533645346453564536645376453864539645406454164542645436454464545645466454764548645496455064551645526455364554645556455664557645586455964560645616456264563645646456564566645676456864569645706457164572645736457464575645766457764578645796458064581645826458364584645856458664587645886458964590645916459264593645946459564596645976459864599646006460164602646036460464605646066460764608646096461064611646126461364614646156461664617646186461964620646216462264623646246462564626646276462864629646306463164632646336463464635646366463764638646396464064641646426464364644646456464664647646486464964650646516465264653646546465564656646576465864659646606466164662646636466464665646666466764668646696467064671646726467364674646756467664677646786467964680646816468264683646846468564686646876468864689646906469164692646936469464695646966469764698646996470064701647026470364704647056470664707647086470964710647116471264713647146471564716647176471864719647206472164722647236472464725647266472764728647296473064731647326473364734647356473664737647386473964740647416474264743647446474564746647476474864749647506475164752647536475464755647566475764758647596476064761647626476364764647656476664767647686476964770647716477264773647746477564776647776477864779647806478164782647836478464785647866478764788647896479064791647926479364794647956479664797647986479964800648016480264803648046480564806648076480864809648106481164812648136481464815648166481764818648196482064821648226482364824648256482664827648286482964830648316483264833648346483564836648376483864839648406484164842648436484464845648466484764848648496485064851648526485364854648556485664857648586485964860648616486264863648646486564866648676486864869648706487164872648736487464875648766487764878648796488064881648826488364884648856488664887648886488964890648916489264893648946489564896648976489864899649006490164902649036490464905649066490764908649096491064911649126491364914649156491664917649186491964920649216492264923649246492564926649276492864929649306493164932649336493464935649366493764938649396494064941649426494364944649456494664947649486494964950649516495264953649546495564956649576495864959649606496164962649636496464965649666496764968649696497064971649726497364974649756497664977649786497964980649816498264983649846498564986649876498864989649906499164992649936499464995649966499764998649996500065001650026500365004650056500665007650086500965010650116501265013650146501565016650176501865019650206502165022650236502465025650266502765028650296503065031650326503365034650356503665037650386503965040650416504265043650446504565046650476504865049650506505165052650536505465055650566505765058650596506065061650626506365064650656506665067650686506965070650716507265073650746507565076650776507865079650806508165082650836508465085650866508765088650896509065091650926509365094650956509665097650986509965100651016510265103651046510565106651076510865109651106511165112651136511465115651166511765118651196512065121651226512365124651256512665127651286512965130651316513265133651346513565136651376513865139651406514165142651436514465145651466514765148651496515065151651526515365154651556515665157651586515965160651616516265163651646516565166651676516865169651706517165172651736517465175651766517765178651796518065181651826518365184651856518665187651886518965190651916519265193651946519565196651976519865199652006520165202652036520465205652066520765208652096521065211652126521365214652156521665217652186521965220652216522265223652246522565226652276522865229652306523165232652336523465235652366523765238652396524065241652426524365244652456524665247652486524965250652516525265253652546525565256652576525865259652606526165262652636526465265652666526765268652696527065271652726527365274652756527665277652786527965280652816528265283652846528565286652876528865289652906529165292652936529465295652966529765298652996530065301653026530365304653056530665307653086530965310653116531265313653146531565316653176531865319653206532165322653236532465325653266532765328653296533065331653326533365334653356533665337653386533965340653416534265343653446534565346653476534865349653506535165352653536535465355653566535765358653596536065361653626536365364653656536665367653686536965370653716537265373653746537565376653776537865379653806538165382653836538465385653866538765388653896539065391653926539365394653956539665397653986539965400654016540265403654046540565406654076540865409654106541165412654136541465415654166541765418654196542065421654226542365424654256542665427654286542965430654316543265433654346543565436654376543865439654406544165442654436544465445654466544765448654496545065451654526545365454654556545665457654586545965460654616546265463654646546565466654676546865469654706547165472654736547465475654766547765478654796548065481654826548365484654856548665487654886548965490654916549265493654946549565496654976549865499655006550165502655036550465505655066550765508655096551065511655126551365514655156551665517655186551965520655216552265523655246552565526655276552865529655306553165532655336553465535655366553765538655396554065541655426554365544655456554665547655486554965550655516555265553655546555565556655576555865559655606556165562655636556465565655666556765568655696557065571655726557365574655756557665577655786557965580655816558265583655846558565586655876558865589655906559165592655936559465595655966559765598655996560065601656026560365604656056560665607656086560965610656116561265613656146561565616656176561865619656206562165622656236562465625656266562765628656296563065631656326563365634656356563665637656386563965640656416564265643656446564565646656476564865649656506565165652656536565465655656566565765658656596566065661656626566365664656656566665667656686566965670656716567265673656746567565676656776567865679656806568165682656836568465685656866568765688656896569065691656926569365694656956569665697656986569965700657016570265703657046570565706657076570865709657106571165712657136571465715657166571765718657196572065721657226572365724657256572665727657286572965730657316573265733657346573565736657376573865739657406574165742657436574465745657466574765748657496575065751657526575365754657556575665757657586575965760657616576265763657646576565766657676576865769657706577165772657736577465775657766577765778657796578065781657826578365784657856578665787657886578965790657916579265793657946579565796657976579865799658006580165802658036580465805658066580765808658096581065811658126581365814658156581665817658186581965820658216582265823658246582565826658276582865829658306583165832658336583465835658366583765838658396584065841658426584365844658456584665847658486584965850658516585265853658546585565856658576585865859658606586165862658636586465865658666586765868658696587065871658726587365874658756587665877658786587965880658816588265883658846588565886658876588865889658906589165892658936589465895658966589765898658996590065901659026590365904659056590665907659086590965910659116591265913659146591565916659176591865919659206592165922659236592465925659266592765928659296593065931659326593365934659356593665937659386593965940659416594265943659446594565946659476594865949659506595165952659536595465955659566595765958659596596065961659626596365964659656596665967659686596965970659716597265973659746597565976659776597865979659806598165982659836598465985659866598765988659896599065991659926599365994659956599665997659986599966000660016600266003660046600566006660076600866009660106601166012660136601466015660166601766018660196602066021660226602366024660256602666027660286602966030660316603266033660346603566036660376603866039660406604166042660436604466045660466604766048660496605066051660526605366054660556605666057660586605966060660616606266063660646606566066660676606866069660706607166072660736607466075660766607766078660796608066081660826608366084660856608666087660886608966090660916609266093660946609566096660976609866099661006610166102661036610466105661066610766108661096611066111661126611366114661156611666117661186611966120661216612266123661246612566126661276612866129661306613166132661336613466135661366613766138661396614066141661426614366144661456614666147661486614966150661516615266153661546615566156661576615866159661606616166162661636616466165661666616766168661696617066171661726617366174661756617666177661786617966180661816618266183661846618566186661876618866189661906619166192661936619466195661966619766198661996620066201662026620366204662056620666207662086620966210662116621266213662146621566216662176621866219662206622166222662236622466225662266622766228662296623066231662326623366234662356623666237662386623966240662416624266243662446624566246662476624866249662506625166252662536625466255662566625766258662596626066261662626626366264662656626666267662686626966270662716627266273662746627566276662776627866279662806628166282662836628466285662866628766288662896629066291662926629366294662956629666297662986629966300663016630266303663046630566306663076630866309663106631166312663136631466315663166631766318663196632066321663226632366324663256632666327663286632966330663316633266333663346633566336663376633866339663406634166342663436634466345663466634766348663496635066351663526635366354663556635666357663586635966360663616636266363663646636566366663676636866369663706637166372663736637466375663766637766378663796638066381663826638366384663856638666387663886638966390663916639266393663946639566396663976639866399664006640166402664036640466405664066640766408664096641066411664126641366414664156641666417664186641966420664216642266423664246642566426664276642866429664306643166432664336643466435664366643766438664396644066441664426644366444664456644666447664486644966450664516645266453664546645566456664576645866459664606646166462664636646466465664666646766468664696647066471664726647366474664756647666477664786647966480664816648266483664846648566486664876648866489664906649166492664936649466495664966649766498664996650066501665026650366504665056650666507665086650966510665116651266513665146651566516665176651866519665206652166522665236652466525665266652766528665296653066531665326653366534665356653666537665386653966540665416654266543665446654566546665476654866549665506655166552665536655466555665566655766558665596656066561665626656366564665656656666567665686656966570665716657266573665746657566576665776657866579665806658166582665836658466585665866658766588665896659066591665926659366594665956659666597665986659966600666016660266603666046660566606666076660866609666106661166612666136661466615666166661766618666196662066621666226662366624666256662666627666286662966630666316663266633666346663566636666376663866639666406664166642666436664466645666466664766648666496665066651666526665366654666556665666657666586665966660666616666266663666646666566666666676666866669666706667166672666736667466675666766667766678666796668066681666826668366684666856668666687666886668966690666916669266693666946669566696666976669866699667006670166702667036670466705667066670766708667096671066711667126671366714667156671666717667186671966720667216672266723667246672566726667276672866729667306673166732667336673466735667366673766738667396674066741667426674366744667456674666747667486674966750667516675266753667546675566756667576675866759667606676166762667636676466765667666676766768667696677066771667726677366774667756677666777667786677966780667816678266783667846678566786667876678866789667906679166792667936679466795667966679766798667996680066801668026680366804668056680666807668086680966810668116681266813668146681566816668176681866819668206682166822668236682466825668266682766828668296683066831668326683366834668356683666837668386683966840668416684266843668446684566846668476684866849668506685166852668536685466855668566685766858668596686066861668626686366864668656686666867668686686966870668716687266873668746687566876668776687866879668806688166882668836688466885668866688766888668896689066891668926689366894668956689666897668986689966900669016690266903669046690566906669076690866909669106691166912669136691466915669166691766918669196692066921669226692366924669256692666927669286692966930669316693266933669346693566936669376693866939669406694166942669436694466945669466694766948669496695066951669526695366954669556695666957669586695966960669616696266963669646696566966669676696866969669706697166972669736697466975669766697766978669796698066981669826698366984669856698666987669886698966990669916699266993669946699566996669976699866999670006700167002670036700467005670066700767008670096701067011670126701367014670156701667017670186701967020670216702267023670246702567026670276702867029670306703167032670336703467035670366703767038670396704067041670426704367044670456704667047670486704967050670516705267053670546705567056670576705867059670606706167062670636706467065670666706767068670696707067071670726707367074670756707667077670786707967080670816708267083670846708567086670876708867089670906709167092670936709467095670966709767098670996710067101671026710367104671056710667107671086710967110671116711267113671146711567116671176711867119671206712167122671236712467125671266712767128671296713067131671326713367134671356713667137671386713967140671416714267143671446714567146671476714867149671506715167152671536715467155671566715767158671596716067161671626716367164671656716667167671686716967170671716717267173671746717567176671776717867179671806718167182671836718467185671866718767188671896719067191671926719367194671956719667197671986719967200672016720267203672046720567206672076720867209672106721167212672136721467215672166721767218672196722067221672226722367224672256722667227672286722967230672316723267233672346723567236672376723867239672406724167242672436724467245672466724767248672496725067251672526725367254672556725667257672586725967260672616726267263672646726567266672676726867269672706727167272672736727467275672766727767278672796728067281672826728367284672856728667287672886728967290672916729267293672946729567296672976729867299673006730167302673036730467305673066730767308673096731067311673126731367314673156731667317673186731967320673216732267323673246732567326673276732867329673306733167332673336733467335673366733767338673396734067341673426734367344673456734667347673486734967350673516735267353673546735567356673576735867359673606736167362673636736467365673666736767368673696737067371673726737367374673756737667377673786737967380673816738267383673846738567386673876738867389673906739167392673936739467395673966739767398673996740067401674026740367404674056740667407674086740967410674116741267413674146741567416674176741867419674206742167422674236742467425674266742767428674296743067431674326743367434674356743667437674386743967440674416744267443674446744567446674476744867449674506745167452674536745467455674566745767458674596746067461674626746367464674656746667467674686746967470674716747267473674746747567476674776747867479674806748167482674836748467485674866748767488674896749067491674926749367494674956749667497674986749967500675016750267503675046750567506675076750867509675106751167512675136751467515675166751767518675196752067521675226752367524675256752667527675286752967530675316753267533675346753567536675376753867539675406754167542675436754467545675466754767548675496755067551675526755367554675556755667557675586755967560675616756267563675646756567566675676756867569675706757167572675736757467575675766757767578675796758067581675826758367584675856758667587675886758967590675916759267593675946759567596675976759867599676006760167602676036760467605676066760767608676096761067611676126761367614676156761667617676186761967620676216762267623676246762567626676276762867629676306763167632676336763467635676366763767638676396764067641676426764367644676456764667647676486764967650676516765267653676546765567656676576765867659676606766167662676636766467665676666766767668676696767067671676726767367674676756767667677676786767967680676816768267683676846768567686676876768867689676906769167692676936769467695676966769767698676996770067701677026770367704677056770667707677086770967710677116771267713677146771567716677176771867719677206772167722677236772467725677266772767728677296773067731677326773367734677356773667737677386773967740677416774267743677446774567746677476774867749677506775167752677536775467755677566775767758677596776067761677626776367764677656776667767677686776967770677716777267773677746777567776677776777867779677806778167782677836778467785677866778767788677896779067791677926779367794677956779667797677986779967800678016780267803678046780567806678076780867809678106781167812678136781467815678166781767818678196782067821678226782367824678256782667827678286782967830678316783267833678346783567836678376783867839678406784167842678436784467845678466784767848678496785067851678526785367854678556785667857678586785967860678616786267863678646786567866678676786867869678706787167872678736787467875678766787767878678796788067881678826788367884678856788667887678886788967890678916789267893678946789567896678976789867899679006790167902679036790467905679066790767908679096791067911679126791367914679156791667917679186791967920679216792267923679246792567926679276792867929679306793167932679336793467935679366793767938679396794067941679426794367944679456794667947679486794967950679516795267953679546795567956679576795867959679606796167962679636796467965679666796767968679696797067971679726797367974679756797667977679786797967980679816798267983679846798567986679876798867989679906799167992679936799467995679966799767998679996800068001680026800368004680056800668007680086800968010680116801268013680146801568016680176801868019680206802168022680236802468025680266802768028680296803068031680326803368034680356803668037680386803968040680416804268043680446804568046680476804868049680506805168052680536805468055680566805768058680596806068061680626806368064680656806668067680686806968070680716807268073680746807568076680776807868079680806808168082680836808468085680866808768088680896809068091680926809368094680956809668097680986809968100681016810268103681046810568106681076810868109681106811168112681136811468115681166811768118681196812068121681226812368124681256812668127681286812968130681316813268133681346813568136681376813868139681406814168142681436814468145681466814768148681496815068151681526815368154681556815668157681586815968160681616816268163681646816568166681676816868169681706817168172681736817468175681766817768178681796818068181681826818368184681856818668187681886818968190681916819268193681946819568196681976819868199682006820168202682036820468205682066820768208682096821068211682126821368214682156821668217682186821968220682216822268223682246822568226682276822868229682306823168232682336823468235682366823768238682396824068241682426824368244682456824668247682486824968250682516825268253682546825568256682576825868259682606826168262682636826468265682666826768268682696827068271682726827368274682756827668277682786827968280682816828268283682846828568286682876828868289682906829168292682936829468295682966829768298682996830068301683026830368304683056830668307683086830968310683116831268313683146831568316683176831868319683206832168322683236832468325683266832768328683296833068331683326833368334683356833668337683386833968340683416834268343683446834568346683476834868349683506835168352683536835468355683566835768358683596836068361683626836368364683656836668367683686836968370683716837268373683746837568376683776837868379683806838168382683836838468385683866838768388683896839068391683926839368394683956839668397683986839968400684016840268403684046840568406684076840868409684106841168412684136841468415684166841768418684196842068421684226842368424684256842668427684286842968430684316843268433684346843568436684376843868439684406844168442684436844468445684466844768448684496845068451684526845368454684556845668457684586845968460684616846268463684646846568466684676846868469684706847168472684736847468475684766847768478684796848068481684826848368484684856848668487684886848968490684916849268493684946849568496684976849868499685006850168502685036850468505685066850768508685096851068511685126851368514685156851668517685186851968520685216852268523685246852568526685276852868529685306853168532685336853468535685366853768538685396854068541685426854368544685456854668547685486854968550685516855268553685546855568556685576855868559685606856168562685636856468565685666856768568685696857068571685726857368574685756857668577685786857968580685816858268583685846858568586685876858868589685906859168592685936859468595685966859768598685996860068601686026860368604686056860668607686086860968610686116861268613686146861568616686176861868619686206862168622686236862468625686266862768628686296863068631686326863368634686356863668637686386863968640686416864268643686446864568646686476864868649686506865168652686536865468655686566865768658686596866068661686626866368664686656866668667686686866968670686716867268673686746867568676686776867868679686806868168682686836868468685686866868768688686896869068691686926869368694686956869668697686986869968700687016870268703687046870568706687076870868709687106871168712687136871468715687166871768718687196872068721687226872368724687256872668727687286872968730687316873268733687346873568736687376873868739687406874168742687436874468745687466874768748687496875068751687526875368754687556875668757687586875968760687616876268763687646876568766687676876868769687706877168772687736877468775687766877768778687796878068781687826878368784687856878668787687886878968790687916879268793687946879568796687976879868799688006880168802688036880468805688066880768808688096881068811688126881368814688156881668817688186881968820688216882268823688246882568826688276882868829688306883168832688336883468835688366883768838688396884068841688426884368844688456884668847688486884968850688516885268853688546885568856688576885868859688606886168862688636886468865688666886768868688696887068871688726887368874688756887668877688786887968880688816888268883688846888568886688876888868889688906889168892688936889468895688966889768898688996890068901689026890368904689056890668907689086890968910689116891268913689146891568916689176891868919689206892168922689236892468925689266892768928689296893068931689326893368934689356893668937689386893968940689416894268943689446894568946689476894868949689506895168952689536895468955689566895768958689596896068961689626896368964689656896668967689686896968970689716897268973689746897568976689776897868979689806898168982689836898468985689866898768988689896899068991689926899368994689956899668997689986899969000690016900269003690046900569006690076900869009690106901169012690136901469015690166901769018690196902069021690226902369024690256902669027690286902969030690316903269033690346903569036690376903869039690406904169042690436904469045690466904769048690496905069051690526905369054690556905669057690586905969060690616906269063690646906569066690676906869069690706907169072690736907469075690766907769078690796908069081690826908369084690856908669087690886908969090690916909269093690946909569096690976909869099691006910169102691036910469105691066910769108691096911069111691126911369114691156911669117691186911969120691216912269123691246912569126691276912869129691306913169132691336913469135691366913769138691396914069141691426914369144691456914669147691486914969150691516915269153691546915569156691576915869159691606916169162691636916469165691666916769168691696917069171691726917369174691756917669177691786917969180691816918269183691846918569186691876918869189691906919169192691936919469195691966919769198691996920069201692026920369204692056920669207692086920969210692116921269213692146921569216692176921869219692206922169222692236922469225692266922769228692296923069231692326923369234692356923669237692386923969240692416924269243692446924569246692476924869249692506925169252692536925469255692566925769258692596926069261692626926369264692656926669267692686926969270692716927269273692746927569276692776927869279692806928169282692836928469285692866928769288692896929069291692926929369294692956929669297692986929969300693016930269303693046930569306693076930869309693106931169312693136931469315693166931769318693196932069321693226932369324693256932669327693286932969330693316933269333693346933569336693376933869339693406934169342693436934469345693466934769348693496935069351693526935369354693556935669357693586935969360693616936269363693646936569366693676936869369693706937169372693736937469375693766937769378693796938069381693826938369384693856938669387693886938969390693916939269393693946939569396693976939869399694006940169402694036940469405694066940769408694096941069411694126941369414694156941669417694186941969420694216942269423694246942569426694276942869429694306943169432694336943469435694366943769438694396944069441694426944369444694456944669447694486944969450694516945269453694546945569456694576945869459694606946169462694636946469465694666946769468694696947069471694726947369474694756947669477694786947969480694816948269483694846948569486694876948869489694906949169492694936949469495694966949769498694996950069501695026950369504695056950669507695086950969510695116951269513695146951569516695176951869519695206952169522695236952469525695266952769528695296953069531695326953369534695356953669537695386953969540695416954269543695446954569546695476954869549695506955169552695536955469555695566955769558695596956069561695626956369564695656956669567695686956969570695716957269573695746957569576695776957869579695806958169582695836958469585695866958769588695896959069591695926959369594695956959669597695986959969600696016960269603696046960569606696076960869609696106961169612696136961469615696166961769618696196962069621696226962369624696256962669627696286962969630696316963269633696346963569636696376963869639696406964169642696436964469645696466964769648696496965069651696526965369654696556965669657696586965969660696616966269663696646966569666696676966869669696706967169672696736967469675696766967769678696796968069681696826968369684696856968669687696886968969690696916969269693696946969569696696976969869699697006970169702697036970469705697066970769708697096971069711697126971369714697156971669717697186971969720697216972269723697246972569726697276972869729697306973169732697336973469735697366973769738697396974069741697426974369744697456974669747697486974969750697516975269753697546975569756697576975869759697606976169762697636976469765697666976769768697696977069771697726977369774697756977669777697786977969780697816978269783697846978569786697876978869789697906979169792697936979469795697966979769798697996980069801698026980369804698056980669807698086980969810698116981269813698146981569816698176981869819698206982169822698236982469825698266982769828698296983069831698326983369834698356983669837698386983969840698416984269843698446984569846698476984869849698506985169852698536985469855698566985769858698596986069861698626986369864698656986669867698686986969870698716987269873698746987569876698776987869879698806988169882698836988469885698866988769888698896989069891698926989369894698956989669897698986989969900699016990269903699046990569906699076990869909699106991169912699136991469915699166991769918699196992069921699226992369924699256992669927699286992969930699316993269933699346993569936699376993869939699406994169942699436994469945699466994769948699496995069951699526995369954699556995669957699586995969960699616996269963699646996569966699676996869969699706997169972699736997469975699766997769978699796998069981699826998369984699856998669987699886998969990699916999269993699946999569996699976999869999700007000170002700037000470005700067000770008700097001070011700127001370014700157001670017700187001970020700217002270023700247002570026700277002870029700307003170032700337003470035700367003770038700397004070041700427004370044700457004670047700487004970050700517005270053700547005570056700577005870059700607006170062700637006470065700667006770068700697007070071700727007370074700757007670077700787007970080700817008270083700847008570086700877008870089700907009170092700937009470095700967009770098700997010070101701027010370104701057010670107701087010970110701117011270113701147011570116701177011870119701207012170122701237012470125701267012770128701297013070131701327013370134701357013670137701387013970140701417014270143701447014570146701477014870149701507015170152701537015470155701567015770158701597016070161701627016370164701657016670167701687016970170701717017270173701747017570176701777017870179701807018170182701837018470185701867018770188701897019070191701927019370194701957019670197701987019970200702017020270203702047020570206702077020870209702107021170212702137021470215702167021770218702197022070221702227022370224702257022670227702287022970230702317023270233702347023570236702377023870239702407024170242702437024470245702467024770248702497025070251702527025370254702557025670257702587025970260702617026270263702647026570266702677026870269702707027170272702737027470275702767027770278702797028070281702827028370284702857028670287702887028970290702917029270293702947029570296702977029870299703007030170302703037030470305703067030770308703097031070311703127031370314703157031670317703187031970320703217032270323703247032570326703277032870329703307033170332703337033470335703367033770338703397034070341703427034370344703457034670347703487034970350703517035270353703547035570356703577035870359703607036170362703637036470365703667036770368703697037070371703727037370374703757037670377703787037970380703817038270383703847038570386703877038870389703907039170392703937039470395703967039770398703997040070401704027040370404704057040670407704087040970410704117041270413704147041570416704177041870419704207042170422704237042470425704267042770428704297043070431704327043370434704357043670437704387043970440704417044270443704447044570446704477044870449704507045170452704537045470455704567045770458704597046070461704627046370464704657046670467704687046970470704717047270473704747047570476704777047870479704807048170482704837048470485704867048770488704897049070491704927049370494704957049670497704987049970500705017050270503705047050570506705077050870509705107051170512705137051470515705167051770518705197052070521705227052370524705257052670527705287052970530705317053270533705347053570536705377053870539705407054170542705437054470545705467054770548705497055070551705527055370554705557055670557705587055970560705617056270563705647056570566705677056870569705707057170572705737057470575705767057770578705797058070581705827058370584705857058670587705887058970590705917059270593705947059570596705977059870599706007060170602706037060470605706067060770608706097061070611706127061370614706157061670617706187061970620706217062270623706247062570626706277062870629706307063170632706337063470635706367063770638706397064070641706427064370644706457064670647706487064970650706517065270653706547065570656706577065870659706607066170662706637066470665706667066770668706697067070671706727067370674706757067670677706787067970680706817068270683706847068570686706877068870689706907069170692706937069470695706967069770698706997070070701707027070370704707057070670707707087070970710707117071270713707147071570716707177071870719707207072170722707237072470725707267072770728707297073070731707327073370734707357073670737707387073970740707417074270743707447074570746707477074870749707507075170752707537075470755707567075770758707597076070761707627076370764707657076670767707687076970770707717077270773707747077570776707777077870779707807078170782707837078470785707867078770788707897079070791707927079370794707957079670797707987079970800708017080270803708047080570806708077080870809708107081170812708137081470815708167081770818708197082070821708227082370824708257082670827708287082970830708317083270833708347083570836708377083870839708407084170842708437084470845708467084770848708497085070851708527085370854708557085670857708587085970860708617086270863708647086570866708677086870869708707087170872708737087470875708767087770878708797088070881708827088370884708857088670887708887088970890708917089270893708947089570896708977089870899709007090170902709037090470905709067090770908709097091070911709127091370914709157091670917709187091970920709217092270923709247092570926709277092870929709307093170932709337093470935709367093770938709397094070941709427094370944709457094670947709487094970950709517095270953709547095570956709577095870959709607096170962709637096470965709667096770968709697097070971709727097370974709757097670977709787097970980709817098270983709847098570986709877098870989709907099170992709937099470995709967099770998709997100071001710027100371004710057100671007710087100971010710117101271013710147101571016710177101871019710207102171022710237102471025710267102771028710297103071031710327103371034710357103671037710387103971040710417104271043710447104571046710477104871049710507105171052710537105471055710567105771058710597106071061710627106371064710657106671067710687106971070710717107271073710747107571076710777107871079710807108171082710837108471085710867108771088710897109071091710927109371094710957109671097710987109971100711017110271103711047110571106711077110871109711107111171112711137111471115711167111771118711197112071121711227112371124711257112671127711287112971130711317113271133711347113571136711377113871139711407114171142711437114471145711467114771148711497115071151711527115371154711557115671157711587115971160711617116271163711647116571166711677116871169711707117171172711737117471175711767117771178711797118071181711827118371184711857118671187711887118971190711917119271193711947119571196711977119871199712007120171202712037120471205712067120771208712097121071211712127121371214712157121671217712187121971220712217122271223712247122571226712277122871229712307123171232712337123471235712367123771238712397124071241712427124371244712457124671247712487124971250712517125271253712547125571256712577125871259712607126171262712637126471265712667126771268712697127071271712727127371274712757127671277712787127971280712817128271283712847128571286712877128871289712907129171292712937129471295712967129771298712997130071301713027130371304713057130671307713087130971310713117131271313713147131571316713177131871319713207132171322713237132471325713267132771328713297133071331713327133371334713357133671337713387133971340713417134271343713447134571346713477134871349713507135171352713537135471355713567135771358713597136071361713627136371364713657136671367713687136971370713717137271373713747137571376713777137871379713807138171382713837138471385713867138771388713897139071391713927139371394713957139671397713987139971400714017140271403714047140571406714077140871409714107141171412714137141471415714167141771418714197142071421714227142371424714257142671427714287142971430714317143271433714347143571436714377143871439714407144171442714437144471445714467144771448714497145071451714527145371454714557145671457714587145971460714617146271463714647146571466714677146871469714707147171472714737147471475714767147771478714797148071481714827148371484714857148671487714887148971490714917149271493714947149571496714977149871499715007150171502715037150471505715067150771508715097151071511715127151371514715157151671517715187151971520715217152271523715247152571526715277152871529715307153171532715337153471535715367153771538715397154071541715427154371544715457154671547715487154971550715517155271553715547155571556715577155871559715607156171562715637156471565715667156771568715697157071571715727157371574715757157671577715787157971580715817158271583715847158571586715877158871589715907159171592715937159471595715967159771598715997160071601716027160371604716057160671607716087160971610716117161271613716147161571616716177161871619716207162171622716237162471625716267162771628716297163071631716327163371634716357163671637716387163971640716417164271643716447164571646716477164871649716507165171652716537165471655716567165771658716597166071661716627166371664716657166671667716687166971670716717167271673716747167571676716777167871679716807168171682716837168471685716867168771688716897169071691716927169371694716957169671697716987169971700717017170271703717047170571706717077170871709717107171171712717137171471715717167171771718717197172071721717227172371724717257172671727717287172971730717317173271733717347173571736717377173871739717407174171742717437174471745717467174771748717497175071751717527175371754717557175671757717587175971760717617176271763717647176571766717677176871769717707177171772717737177471775717767177771778717797178071781717827178371784717857178671787717887178971790717917179271793717947179571796717977179871799718007180171802718037180471805718067180771808718097181071811718127181371814718157181671817718187181971820718217182271823718247182571826718277182871829718307183171832718337183471835718367183771838718397184071841718427184371844718457184671847718487184971850718517185271853718547185571856718577185871859718607186171862718637186471865718667186771868718697187071871718727187371874718757187671877718787187971880718817188271883718847188571886718877188871889718907189171892718937189471895718967189771898718997190071901719027190371904719057190671907719087190971910719117191271913719147191571916719177191871919719207192171922719237192471925719267192771928719297193071931719327193371934719357193671937719387193971940719417194271943719447194571946719477194871949719507195171952719537195471955719567195771958719597196071961719627196371964719657196671967719687196971970719717197271973719747197571976719777197871979719807198171982719837198471985719867198771988719897199071991719927199371994719957199671997719987199972000720017200272003720047200572006720077200872009720107201172012720137201472015720167201772018720197202072021720227202372024720257202672027720287202972030720317203272033720347203572036720377203872039720407204172042720437204472045720467204772048720497205072051720527205372054720557205672057720587205972060720617206272063720647206572066720677206872069720707207172072720737207472075720767207772078720797208072081720827208372084720857208672087720887208972090720917209272093720947209572096720977209872099721007210172102721037210472105721067210772108721097211072111721127211372114721157211672117721187211972120721217212272123721247212572126721277212872129721307213172132721337213472135721367213772138721397214072141721427214372144721457214672147721487214972150721517215272153721547215572156721577215872159721607216172162721637216472165721667216772168721697217072171721727217372174721757217672177721787217972180721817218272183721847218572186721877218872189721907219172192721937219472195721967219772198721997220072201722027220372204722057220672207722087220972210722117221272213722147221572216722177221872219722207222172222722237222472225722267222772228722297223072231722327223372234722357223672237722387223972240722417224272243722447224572246722477224872249722507225172252722537225472255722567225772258722597226072261722627226372264722657226672267722687226972270722717227272273722747227572276722777227872279722807228172282722837228472285722867228772288722897229072291722927229372294722957229672297722987229972300723017230272303723047230572306723077230872309723107231172312723137231472315723167231772318723197232072321723227232372324723257232672327723287232972330723317233272333723347233572336723377233872339723407234172342723437234472345723467234772348723497235072351723527235372354723557235672357723587235972360723617236272363723647236572366723677236872369723707237172372723737237472375723767237772378723797238072381723827238372384723857238672387723887238972390723917239272393723947239572396723977239872399724007240172402724037240472405724067240772408724097241072411724127241372414724157241672417724187241972420724217242272423724247242572426724277242872429724307243172432724337243472435724367243772438724397244072441724427244372444724457244672447724487244972450724517245272453724547245572456724577245872459724607246172462724637246472465724667246772468724697247072471724727247372474724757247672477724787247972480724817248272483724847248572486724877248872489724907249172492724937249472495724967249772498724997250072501725027250372504725057250672507725087250972510725117251272513725147251572516725177251872519725207252172522725237252472525725267252772528725297253072531725327253372534725357253672537725387253972540725417254272543725447254572546725477254872549725507255172552725537255472555725567255772558725597256072561725627256372564725657256672567725687256972570725717257272573725747257572576725777257872579725807258172582725837258472585725867258772588725897259072591725927259372594725957259672597725987259972600726017260272603726047260572606726077260872609726107261172612726137261472615726167261772618726197262072621726227262372624726257262672627726287262972630726317263272633726347263572636726377263872639726407264172642726437264472645726467264772648726497265072651726527265372654726557265672657726587265972660726617266272663726647266572666726677266872669726707267172672726737267472675726767267772678726797268072681726827268372684726857268672687726887268972690726917269272693726947269572696726977269872699727007270172702727037270472705727067270772708727097271072711727127271372714727157271672717727187271972720727217272272723727247272572726727277272872729727307273172732727337273472735727367273772738727397274072741727427274372744727457274672747727487274972750727517275272753727547275572756727577275872759727607276172762727637276472765727667276772768727697277072771727727277372774727757277672777727787277972780727817278272783727847278572786727877278872789727907279172792727937279472795727967279772798727997280072801728027280372804728057280672807728087280972810728117281272813728147281572816728177281872819728207282172822728237282472825728267282772828728297283072831728327283372834728357283672837728387283972840728417284272843728447284572846728477284872849728507285172852728537285472855728567285772858728597286072861728627286372864728657286672867728687286972870728717287272873728747287572876728777287872879728807288172882728837288472885728867288772888728897289072891728927289372894728957289672897728987289972900729017290272903729047290572906729077290872909729107291172912729137291472915729167291772918729197292072921729227292372924729257292672927729287292972930729317293272933729347293572936729377293872939729407294172942729437294472945729467294772948729497295072951729527295372954729557295672957729587295972960729617296272963729647296572966729677296872969729707297172972729737297472975729767297772978729797298072981729827298372984729857298672987729887298972990729917299272993729947299572996729977299872999730007300173002730037300473005730067300773008730097301073011730127301373014730157301673017730187301973020730217302273023730247302573026730277302873029730307303173032730337303473035730367303773038730397304073041730427304373044730457304673047730487304973050730517305273053730547305573056730577305873059730607306173062730637306473065730667306773068730697307073071730727307373074730757307673077730787307973080730817308273083730847308573086730877308873089730907309173092730937309473095730967309773098730997310073101731027310373104731057310673107731087310973110731117311273113731147311573116731177311873119731207312173122731237312473125731267312773128731297313073131731327313373134731357313673137731387313973140731417314273143731447314573146731477314873149731507315173152731537315473155731567315773158731597316073161731627316373164731657316673167731687316973170731717317273173731747317573176731777317873179731807318173182731837318473185731867318773188731897319073191731927319373194731957319673197731987319973200732017320273203732047320573206732077320873209732107321173212732137321473215732167321773218732197322073221732227322373224732257322673227732287322973230732317323273233732347323573236732377323873239732407324173242732437324473245732467324773248732497325073251732527325373254732557325673257732587325973260732617326273263732647326573266732677326873269732707327173272732737327473275732767327773278732797328073281732827328373284732857328673287732887328973290732917329273293732947329573296732977329873299733007330173302733037330473305733067330773308733097331073311733127331373314733157331673317733187331973320733217332273323733247332573326733277332873329733307333173332733337333473335733367333773338733397334073341733427334373344733457334673347733487334973350733517335273353733547335573356733577335873359733607336173362733637336473365733667336773368733697337073371733727337373374733757337673377733787337973380733817338273383733847338573386733877338873389733907339173392733937339473395733967339773398733997340073401734027340373404734057340673407734087340973410734117341273413734147341573416734177341873419734207342173422734237342473425734267342773428734297343073431734327343373434734357343673437734387343973440734417344273443734447344573446734477344873449734507345173452734537345473455734567345773458734597346073461734627346373464734657346673467734687346973470734717347273473734747347573476734777347873479734807348173482734837348473485734867348773488734897349073491734927349373494734957349673497734987349973500735017350273503735047350573506735077350873509735107351173512735137351473515735167351773518735197352073521735227352373524735257352673527735287352973530735317353273533735347353573536735377353873539735407354173542735437354473545735467354773548735497355073551735527355373554735557355673557735587355973560735617356273563735647356573566735677356873569735707357173572735737357473575735767357773578735797358073581735827358373584735857358673587735887358973590735917359273593735947359573596735977359873599736007360173602736037360473605736067360773608736097361073611736127361373614736157361673617736187361973620736217362273623736247362573626736277362873629736307363173632736337363473635736367363773638736397364073641736427364373644736457364673647736487364973650736517365273653736547365573656736577365873659736607366173662736637366473665736667366773668736697367073671736727367373674736757367673677736787367973680736817368273683736847368573686736877368873689736907369173692736937369473695736967369773698736997370073701737027370373704737057370673707737087370973710737117371273713737147371573716737177371873719737207372173722737237372473725737267372773728737297373073731737327373373734737357373673737737387373973740737417374273743737447374573746737477374873749737507375173752737537375473755737567375773758737597376073761737627376373764737657376673767737687376973770737717377273773737747377573776737777377873779737807378173782737837378473785737867378773788737897379073791737927379373794737957379673797737987379973800738017380273803738047380573806738077380873809738107381173812738137381473815738167381773818738197382073821738227382373824738257382673827738287382973830738317383273833738347383573836738377383873839738407384173842738437384473845738467384773848738497385073851738527385373854738557385673857738587385973860738617386273863738647386573866738677386873869738707387173872738737387473875738767387773878738797388073881738827388373884738857388673887738887388973890738917389273893738947389573896738977389873899739007390173902739037390473905739067390773908739097391073911739127391373914739157391673917739187391973920739217392273923739247392573926739277392873929739307393173932739337393473935739367393773938739397394073941739427394373944739457394673947739487394973950739517395273953739547395573956739577395873959739607396173962739637396473965739667396773968739697397073971739727397373974739757397673977739787397973980739817398273983739847398573986739877398873989739907399173992739937399473995739967399773998739997400074001740027400374004740057400674007740087400974010740117401274013740147401574016740177401874019740207402174022740237402474025740267402774028740297403074031740327403374034740357403674037740387403974040740417404274043740447404574046740477404874049740507405174052740537405474055740567405774058740597406074061740627406374064740657406674067740687406974070740717407274073740747407574076740777407874079740807408174082740837408474085740867408774088740897409074091740927409374094740957409674097740987409974100741017410274103741047410574106741077410874109741107411174112741137411474115741167411774118741197412074121741227412374124741257412674127741287412974130741317413274133741347413574136741377413874139741407414174142741437414474145741467414774148741497415074151741527415374154741557415674157741587415974160741617416274163741647416574166741677416874169741707417174172741737417474175741767417774178741797418074181741827418374184741857418674187741887418974190741917419274193741947419574196741977419874199742007420174202742037420474205742067420774208742097421074211742127421374214742157421674217742187421974220742217422274223742247422574226742277422874229742307423174232742337423474235742367423774238742397424074241742427424374244742457424674247742487424974250742517425274253742547425574256742577425874259742607426174262742637426474265742667426774268742697427074271742727427374274742757427674277742787427974280742817428274283742847428574286742877428874289742907429174292742937429474295742967429774298742997430074301743027430374304743057430674307743087430974310743117431274313743147431574316743177431874319743207432174322743237432474325743267432774328743297433074331743327433374334743357433674337743387433974340743417434274343743447434574346743477434874349743507435174352743537435474355743567435774358743597436074361743627436374364743657436674367743687436974370743717437274373743747437574376743777437874379743807438174382743837438474385743867438774388743897439074391743927439374394743957439674397743987439974400744017440274403744047440574406744077440874409744107441174412744137441474415744167441774418744197442074421744227442374424744257442674427744287442974430744317443274433744347443574436744377443874439744407444174442744437444474445744467444774448744497445074451744527445374454744557445674457744587445974460744617446274463744647446574466744677446874469744707447174472744737447474475744767447774478744797448074481744827448374484744857448674487744887448974490744917449274493744947449574496744977449874499745007450174502745037450474505745067450774508745097451074511745127451374514745157451674517745187451974520745217452274523745247452574526745277452874529745307453174532745337453474535745367453774538745397454074541745427454374544745457454674547745487454974550745517455274553745547455574556745577455874559745607456174562745637456474565745667456774568745697457074571745727457374574745757457674577745787457974580745817458274583745847458574586745877458874589745907459174592745937459474595745967459774598745997460074601746027460374604746057460674607746087460974610746117461274613746147461574616746177461874619746207462174622746237462474625746267462774628746297463074631746327463374634746357463674637746387463974640746417464274643746447464574646746477464874649746507465174652746537465474655746567465774658746597466074661746627466374664746657466674667746687466974670746717467274673746747467574676746777467874679746807468174682746837468474685746867468774688746897469074691746927469374694746957469674697746987469974700747017470274703747047470574706747077470874709747107471174712747137471474715747167471774718747197472074721747227472374724747257472674727747287472974730747317473274733747347473574736747377473874739747407474174742747437474474745747467474774748747497475074751747527475374754747557475674757747587475974760747617476274763747647476574766747677476874769747707477174772747737477474775747767477774778747797478074781747827478374784747857478674787747887478974790747917479274793747947479574796747977479874799748007480174802748037480474805748067480774808748097481074811748127481374814748157481674817748187481974820748217482274823748247482574826748277482874829748307483174832748337483474835748367483774838748397484074841748427484374844748457484674847748487484974850748517485274853748547485574856748577485874859748607486174862748637486474865748667486774868748697487074871748727487374874748757487674877748787487974880748817488274883748847488574886748877488874889748907489174892748937489474895748967489774898748997490074901749027490374904749057490674907749087490974910749117491274913749147491574916749177491874919749207492174922749237492474925749267492774928749297493074931749327493374934749357493674937749387493974940749417494274943749447494574946749477494874949749507495174952749537495474955749567495774958749597496074961749627496374964749657496674967749687496974970749717497274973749747497574976749777497874979749807498174982749837498474985749867498774988749897499074991749927499374994749957499674997749987499975000750017500275003750047500575006750077500875009750107501175012750137501475015750167501775018750197502075021750227502375024750257502675027750287502975030750317503275033750347503575036750377503875039750407504175042750437504475045750467504775048750497505075051750527505375054750557505675057750587505975060750617506275063750647506575066750677506875069750707507175072750737507475075750767507775078750797508075081750827508375084750857508675087750887508975090750917509275093750947509575096750977509875099751007510175102751037510475105751067510775108751097511075111751127511375114751157511675117751187511975120751217512275123751247512575126751277512875129751307513175132751337513475135751367513775138751397514075141751427514375144751457514675147751487514975150751517515275153751547515575156751577515875159751607516175162751637516475165751667516775168751697517075171751727517375174751757517675177751787517975180751817518275183751847518575186751877518875189751907519175192751937519475195751967519775198751997520075201752027520375204752057520675207752087520975210752117521275213752147521575216752177521875219752207522175222752237522475225752267522775228752297523075231752327523375234752357523675237752387523975240752417524275243752447524575246752477524875249752507525175252752537525475255752567525775258752597526075261752627526375264752657526675267752687526975270752717527275273752747527575276752777527875279752807528175282752837528475285752867528775288752897529075291752927529375294752957529675297752987529975300753017530275303753047530575306753077530875309753107531175312753137531475315753167531775318753197532075321753227532375324753257532675327753287532975330753317533275333753347533575336753377533875339753407534175342753437534475345753467534775348753497535075351753527535375354753557535675357753587535975360753617536275363753647536575366753677536875369753707537175372753737537475375753767537775378753797538075381753827538375384753857538675387753887538975390753917539275393753947539575396753977539875399754007540175402754037540475405754067540775408754097541075411754127541375414754157541675417754187541975420754217542275423754247542575426754277542875429754307543175432754337543475435754367543775438754397544075441754427544375444754457544675447754487544975450754517545275453754547545575456754577545875459754607546175462754637546475465754667546775468754697547075471754727547375474754757547675477754787547975480754817548275483754847548575486754877548875489754907549175492754937549475495754967549775498754997550075501755027550375504755057550675507755087550975510755117551275513755147551575516755177551875519755207552175522755237552475525755267552775528755297553075531755327553375534755357553675537755387553975540755417554275543755447554575546755477554875549755507555175552755537555475555755567555775558755597556075561755627556375564755657556675567755687556975570755717557275573755747557575576755777557875579755807558175582755837558475585755867558775588755897559075591755927559375594755957559675597755987559975600756017560275603756047560575606756077560875609756107561175612756137561475615756167561775618756197562075621756227562375624756257562675627756287562975630756317563275633756347563575636756377563875639756407564175642756437564475645756467564775648756497565075651756527565375654756557565675657756587565975660756617566275663756647566575666756677566875669756707567175672756737567475675756767567775678756797568075681756827568375684756857568675687756887568975690756917569275693756947569575696756977569875699757007570175702757037570475705757067570775708757097571075711757127571375714757157571675717757187571975720757217572275723757247572575726757277572875729757307573175732757337573475735757367573775738757397574075741757427574375744757457574675747757487574975750757517575275753757547575575756757577575875759757607576175762757637576475765757667576775768757697577075771757727577375774757757577675777757787577975780757817578275783757847578575786757877578875789757907579175792757937579475795757967579775798757997580075801758027580375804758057580675807758087580975810758117581275813758147581575816758177581875819758207582175822758237582475825758267582775828758297583075831758327583375834758357583675837758387583975840758417584275843758447584575846758477584875849758507585175852758537585475855758567585775858758597586075861758627586375864758657586675867758687586975870758717587275873758747587575876758777587875879758807588175882758837588475885758867588775888758897589075891758927589375894758957589675897758987589975900759017590275903759047590575906759077590875909759107591175912759137591475915759167591775918759197592075921759227592375924759257592675927759287592975930759317593275933759347593575936759377593875939759407594175942759437594475945759467594775948759497595075951759527595375954759557595675957759587595975960759617596275963759647596575966759677596875969759707597175972759737597475975759767597775978759797598075981759827598375984759857598675987759887598975990759917599275993759947599575996759977599875999760007600176002760037600476005760067600776008760097601076011760127601376014760157601676017760187601976020760217602276023760247602576026760277602876029760307603176032760337603476035760367603776038760397604076041760427604376044760457604676047760487604976050760517605276053760547605576056760577605876059760607606176062760637606476065760667606776068760697607076071760727607376074760757607676077760787607976080760817608276083760847608576086760877608876089760907609176092760937609476095760967609776098760997610076101761027610376104761057610676107761087610976110761117611276113761147611576116761177611876119761207612176122761237612476125761267612776128761297613076131761327613376134761357613676137761387613976140761417614276143761447614576146761477614876149761507615176152761537615476155761567615776158761597616076161761627616376164761657616676167761687616976170761717617276173761747617576176761777617876179761807618176182761837618476185761867618776188761897619076191761927619376194761957619676197761987619976200762017620276203762047620576206762077620876209762107621176212762137621476215762167621776218762197622076221762227622376224762257622676227762287622976230762317623276233762347623576236762377623876239762407624176242762437624476245762467624776248762497625076251762527625376254762557625676257762587625976260762617626276263762647626576266762677626876269762707627176272762737627476275762767627776278762797628076281762827628376284762857628676287762887628976290762917629276293762947629576296762977629876299763007630176302763037630476305763067630776308763097631076311763127631376314763157631676317763187631976320763217632276323763247632576326763277632876329763307633176332763337633476335763367633776338763397634076341763427634376344763457634676347763487634976350763517635276353763547635576356763577635876359763607636176362763637636476365763667636776368763697637076371763727637376374763757637676377763787637976380763817638276383763847638576386763877638876389763907639176392763937639476395763967639776398763997640076401764027640376404764057640676407764087640976410764117641276413764147641576416764177641876419764207642176422764237642476425764267642776428764297643076431764327643376434764357643676437764387643976440764417644276443764447644576446764477644876449764507645176452764537645476455764567645776458764597646076461764627646376464764657646676467764687646976470764717647276473764747647576476764777647876479764807648176482764837648476485764867648776488764897649076491764927649376494764957649676497764987649976500765017650276503765047650576506765077650876509765107651176512765137651476515765167651776518765197652076521765227652376524765257652676527765287652976530765317653276533765347653576536765377653876539765407654176542765437654476545765467654776548765497655076551765527655376554765557655676557765587655976560765617656276563765647656576566765677656876569765707657176572765737657476575765767657776578765797658076581765827658376584765857658676587765887658976590765917659276593765947659576596765977659876599766007660176602766037660476605766067660776608766097661076611766127661376614766157661676617766187661976620766217662276623766247662576626766277662876629766307663176632766337663476635766367663776638766397664076641766427664376644766457664676647766487664976650766517665276653766547665576656766577665876659766607666176662766637666476665766667666776668766697667076671766727667376674766757667676677766787667976680766817668276683766847668576686766877668876689766907669176692766937669476695766967669776698766997670076701767027670376704767057670676707767087670976710767117671276713767147671576716767177671876719767207672176722767237672476725767267672776728767297673076731767327673376734767357673676737767387673976740767417674276743767447674576746767477674876749767507675176752767537675476755767567675776758767597676076761767627676376764767657676676767767687676976770767717677276773767747677576776767777677876779767807678176782767837678476785767867678776788767897679076791767927679376794767957679676797767987679976800768017680276803768047680576806768077680876809768107681176812768137681476815768167681776818768197682076821768227682376824768257682676827768287682976830768317683276833768347683576836768377683876839768407684176842768437684476845768467684776848768497685076851768527685376854768557685676857768587685976860768617686276863768647686576866768677686876869768707687176872768737687476875768767687776878768797688076881768827688376884768857688676887768887688976890768917689276893768947689576896768977689876899769007690176902769037690476905769067690776908769097691076911769127691376914769157691676917769187691976920769217692276923769247692576926769277692876929769307693176932769337693476935769367693776938769397694076941769427694376944769457694676947769487694976950769517695276953769547695576956769577695876959769607696176962769637696476965769667696776968769697697076971769727697376974769757697676977769787697976980769817698276983769847698576986769877698876989769907699176992769937699476995769967699776998769997700077001770027700377004770057700677007770087700977010770117701277013770147701577016770177701877019770207702177022770237702477025770267702777028770297703077031770327703377034770357703677037770387703977040770417704277043770447704577046770477704877049770507705177052770537705477055770567705777058770597706077061770627706377064770657706677067770687706977070770717707277073770747707577076770777707877079770807708177082770837708477085770867708777088770897709077091770927709377094770957709677097770987709977100771017710277103771047710577106771077710877109771107711177112771137711477115771167711777118771197712077121771227712377124771257712677127771287712977130771317713277133771347713577136771377713877139771407714177142771437714477145771467714777148771497715077151771527715377154771557715677157771587715977160771617716277163771647716577166771677716877169771707717177172771737717477175771767717777178771797718077181771827718377184771857718677187771887718977190771917719277193771947719577196771977719877199772007720177202772037720477205772067720777208772097721077211772127721377214772157721677217772187721977220772217722277223772247722577226772277722877229772307723177232772337723477235772367723777238772397724077241772427724377244772457724677247772487724977250772517725277253772547725577256772577725877259772607726177262772637726477265772667726777268772697727077271772727727377274772757727677277772787727977280772817728277283772847728577286772877728877289772907729177292772937729477295772967729777298772997730077301773027730377304773057730677307773087730977310773117731277313773147731577316773177731877319773207732177322773237732477325773267732777328773297733077331773327733377334773357733677337773387733977340773417734277343773447734577346773477734877349773507735177352773537735477355773567735777358773597736077361773627736377364773657736677367773687736977370773717737277373773747737577376773777737877379773807738177382773837738477385773867738777388773897739077391773927739377394773957739677397773987739977400774017740277403774047740577406774077740877409774107741177412774137741477415774167741777418774197742077421774227742377424774257742677427774287742977430774317743277433774347743577436774377743877439774407744177442774437744477445774467744777448774497745077451774527745377454774557745677457774587745977460774617746277463774647746577466774677746877469774707747177472774737747477475774767747777478774797748077481774827748377484774857748677487774887748977490774917749277493774947749577496774977749877499775007750177502775037750477505775067750777508775097751077511775127751377514775157751677517775187751977520775217752277523775247752577526775277752877529775307753177532775337753477535775367753777538775397754077541775427754377544775457754677547775487754977550775517755277553775547755577556775577755877559775607756177562775637756477565775667756777568775697757077571775727757377574775757757677577775787757977580775817758277583775847758577586775877758877589775907759177592775937759477595775967759777598775997760077601776027760377604776057760677607776087760977610776117761277613776147761577616776177761877619776207762177622776237762477625776267762777628776297763077631776327763377634776357763677637776387763977640776417764277643776447764577646776477764877649776507765177652776537765477655776567765777658776597766077661776627766377664776657766677667776687766977670776717767277673776747767577676776777767877679776807768177682776837768477685776867768777688776897769077691776927769377694776957769677697776987769977700777017770277703777047770577706777077770877709777107771177712777137771477715777167771777718777197772077721777227772377724777257772677727777287772977730777317773277733777347773577736777377773877739777407774177742777437774477745777467774777748777497775077751777527775377754777557775677757777587775977760777617776277763777647776577766777677776877769777707777177772777737777477775777767777777778777797778077781777827778377784777857778677787777887778977790777917779277793777947779577796777977779877799778007780177802778037780477805778067780777808778097781077811778127781377814778157781677817778187781977820778217782277823778247782577826778277782877829778307783177832778337783477835778367783777838778397784077841778427784377844778457784677847778487784977850778517785277853778547785577856778577785877859778607786177862778637786477865778667786777868778697787077871778727787377874778757787677877778787787977880778817788277883778847788577886778877788877889778907789177892778937789477895778967789777898778997790077901779027790377904779057790677907779087790977910779117791277913779147791577916779177791877919779207792177922779237792477925779267792777928779297793077931779327793377934779357793677937779387793977940779417794277943779447794577946779477794877949779507795177952779537795477955779567795777958779597796077961779627796377964779657796677967779687796977970779717797277973779747797577976779777797877979779807798177982779837798477985779867798777988779897799077991779927799377994779957799677997779987799978000780017800278003780047800578006780077800878009780107801178012780137801478015780167801778018780197802078021780227802378024780257802678027780287802978030780317803278033780347803578036780377803878039780407804178042780437804478045780467804778048780497805078051780527805378054780557805678057780587805978060780617806278063780647806578066780677806878069780707807178072780737807478075780767807778078780797808078081780827808378084780857808678087780887808978090780917809278093780947809578096780977809878099781007810178102781037810478105781067810778108781097811078111781127811378114781157811678117781187811978120781217812278123781247812578126781277812878129781307813178132781337813478135781367813778138781397814078141781427814378144781457814678147781487814978150781517815278153781547815578156781577815878159781607816178162781637816478165781667816778168781697817078171781727817378174781757817678177781787817978180781817818278183781847818578186781877818878189781907819178192781937819478195781967819778198781997820078201782027820378204782057820678207782087820978210782117821278213782147821578216782177821878219782207822178222782237822478225782267822778228782297823078231782327823378234782357823678237782387823978240782417824278243782447824578246782477824878249782507825178252782537825478255782567825778258782597826078261782627826378264782657826678267782687826978270782717827278273782747827578276782777827878279782807828178282782837828478285782867828778288782897829078291782927829378294782957829678297782987829978300783017830278303783047830578306783077830878309783107831178312783137831478315783167831778318783197832078321783227832378324783257832678327783287832978330783317833278333783347833578336783377833878339783407834178342783437834478345783467834778348783497835078351783527835378354783557835678357783587835978360783617836278363783647836578366783677836878369783707837178372783737837478375783767837778378783797838078381783827838378384783857838678387783887838978390783917839278393783947839578396783977839878399784007840178402784037840478405784067840778408784097841078411784127841378414784157841678417784187841978420784217842278423784247842578426784277842878429784307843178432784337843478435784367843778438784397844078441784427844378444784457844678447784487844978450784517845278453784547845578456784577845878459784607846178462784637846478465784667846778468784697847078471784727847378474784757847678477784787847978480784817848278483784847848578486784877848878489784907849178492784937849478495784967849778498784997850078501785027850378504785057850678507785087850978510785117851278513785147851578516785177851878519785207852178522785237852478525785267852778528785297853078531785327853378534785357853678537785387853978540785417854278543785447854578546785477854878549785507855178552785537855478555785567855778558785597856078561785627856378564785657856678567785687856978570785717857278573785747857578576785777857878579785807858178582785837858478585785867858778588785897859078591785927859378594785957859678597785987859978600786017860278603786047860578606786077860878609786107861178612786137861478615786167861778618786197862078621786227862378624786257862678627786287862978630786317863278633786347863578636786377863878639786407864178642786437864478645786467864778648786497865078651786527865378654786557865678657786587865978660786617866278663786647866578666786677866878669786707867178672786737867478675786767867778678786797868078681786827868378684786857868678687786887868978690786917869278693786947869578696786977869878699787007870178702787037870478705787067870778708787097871078711787127871378714787157871678717787187871978720787217872278723787247872578726787277872878729787307873178732787337873478735787367873778738787397874078741787427874378744787457874678747787487874978750787517875278753787547875578756787577875878759787607876178762787637876478765787667876778768787697877078771787727877378774787757877678777787787877978780787817878278783787847878578786787877878878789787907879178792787937879478795787967879778798787997880078801788027880378804788057880678807788087880978810788117881278813788147881578816788177881878819788207882178822788237882478825788267882778828788297883078831788327883378834788357883678837788387883978840788417884278843788447884578846788477884878849788507885178852788537885478855788567885778858788597886078861788627886378864788657886678867788687886978870788717887278873788747887578876788777887878879788807888178882788837888478885788867888778888788897889078891788927889378894788957889678897788987889978900789017890278903789047890578906789077890878909789107891178912789137891478915789167891778918789197892078921789227892378924789257892678927789287892978930789317893278933789347893578936789377893878939789407894178942789437894478945789467894778948789497895078951789527895378954789557895678957789587895978960789617896278963789647896578966789677896878969789707897178972789737897478975789767897778978789797898078981789827898378984789857898678987789887898978990789917899278993789947899578996789977899878999790007900179002790037900479005790067900779008790097901079011790127901379014790157901679017790187901979020790217902279023790247902579026790277902879029790307903179032790337903479035790367903779038790397904079041790427904379044790457904679047790487904979050790517905279053790547905579056790577905879059790607906179062790637906479065790667906779068790697907079071790727907379074790757907679077790787907979080790817908279083790847908579086790877908879089790907909179092790937909479095790967909779098790997910079101791027910379104791057910679107791087910979110791117911279113791147911579116791177911879119791207912179122791237912479125791267912779128791297913079131791327913379134791357913679137791387913979140791417914279143791447914579146791477914879149791507915179152791537915479155791567915779158791597916079161791627916379164791657916679167791687916979170791717917279173791747917579176791777917879179791807918179182791837918479185791867918779188791897919079191791927919379194791957919679197791987919979200792017920279203792047920579206792077920879209792107921179212792137921479215792167921779218792197922079221792227922379224792257922679227792287922979230792317923279233792347923579236792377923879239792407924179242792437924479245792467924779248792497925079251792527925379254792557925679257792587925979260792617926279263792647926579266792677926879269792707927179272792737927479275792767927779278792797928079281792827928379284792857928679287792887928979290792917929279293792947929579296792977929879299793007930179302793037930479305793067930779308793097931079311793127931379314793157931679317793187931979320793217932279323793247932579326793277932879329793307933179332793337933479335793367933779338793397934079341793427934379344793457934679347793487934979350793517935279353793547935579356793577935879359793607936179362793637936479365793667936779368793697937079371793727937379374793757937679377793787937979380793817938279383793847938579386793877938879389793907939179392793937939479395793967939779398793997940079401794027940379404794057940679407794087940979410794117941279413794147941579416794177941879419794207942179422794237942479425794267942779428794297943079431794327943379434794357943679437794387943979440794417944279443794447944579446794477944879449794507945179452794537945479455794567945779458794597946079461794627946379464794657946679467794687946979470794717947279473794747947579476794777947879479794807948179482794837948479485794867948779488794897949079491794927949379494794957949679497794987949979500795017950279503795047950579506795077950879509795107951179512795137951479515795167951779518795197952079521795227952379524795257952679527795287952979530795317953279533795347953579536795377953879539795407954179542795437954479545795467954779548795497955079551795527955379554795557955679557795587955979560795617956279563795647956579566795677956879569795707957179572795737957479575795767957779578795797958079581795827958379584795857958679587795887958979590795917959279593795947959579596795977959879599796007960179602796037960479605796067960779608796097961079611796127961379614796157961679617796187961979620796217962279623796247962579626796277962879629796307963179632796337963479635796367963779638796397964079641796427964379644796457964679647796487964979650796517965279653796547965579656796577965879659796607966179662796637966479665796667966779668796697967079671796727967379674796757967679677796787967979680796817968279683796847968579686796877968879689796907969179692796937969479695796967969779698796997970079701797027970379704797057970679707797087970979710797117971279713797147971579716797177971879719797207972179722797237972479725797267972779728797297973079731797327973379734797357973679737797387973979740797417974279743797447974579746797477974879749797507975179752797537975479755797567975779758797597976079761797627976379764797657976679767797687976979770797717977279773797747977579776797777977879779797807978179782797837978479785797867978779788797897979079791797927979379794797957979679797797987979979800798017980279803798047980579806798077980879809798107981179812798137981479815798167981779818798197982079821798227982379824798257982679827798287982979830798317983279833798347983579836798377983879839798407984179842798437984479845798467984779848798497985079851798527985379854798557985679857798587985979860798617986279863798647986579866798677986879869798707987179872798737987479875798767987779878798797988079881798827988379884798857988679887798887988979890798917989279893798947989579896798977989879899799007990179902799037990479905799067990779908799097991079911799127991379914799157991679917799187991979920799217992279923799247992579926799277992879929799307993179932799337993479935799367993779938799397994079941799427994379944799457994679947799487994979950799517995279953799547995579956799577995879959799607996179962799637996479965799667996779968799697997079971799727997379974799757997679977799787997979980799817998279983799847998579986799877998879989799907999179992799937999479995799967999779998799998000080001800028000380004800058000680007800088000980010800118001280013800148001580016800178001880019800208002180022800238002480025800268002780028800298003080031800328003380034800358003680037800388003980040800418004280043800448004580046800478004880049800508005180052800538005480055800568005780058800598006080061800628006380064800658006680067800688006980070800718007280073800748007580076800778007880079800808008180082800838008480085800868008780088800898009080091800928009380094800958009680097800988009980100801018010280103801048010580106801078010880109801108011180112801138011480115801168011780118801198012080121801228012380124801258012680127801288012980130801318013280133801348013580136801378013880139801408014180142801438014480145801468014780148801498015080151801528015380154801558015680157801588015980160801618016280163801648016580166801678016880169801708017180172801738017480175801768017780178801798018080181801828018380184801858018680187801888018980190801918019280193801948019580196801978019880199802008020180202802038020480205802068020780208802098021080211802128021380214802158021680217802188021980220802218022280223802248022580226802278022880229802308023180232802338023480235802368023780238802398024080241802428024380244802458024680247802488024980250802518025280253802548025580256802578025880259802608026180262802638026480265802668026780268802698027080271802728027380274802758027680277802788027980280802818028280283802848028580286802878028880289802908029180292802938029480295802968029780298802998030080301803028030380304803058030680307803088030980310803118031280313803148031580316803178031880319803208032180322803238032480325803268032780328803298033080331803328033380334803358033680337803388033980340803418034280343803448034580346803478034880349803508035180352803538035480355803568035780358803598036080361803628036380364803658036680367803688036980370803718037280373803748037580376803778037880379803808038180382803838038480385803868038780388803898039080391803928039380394803958039680397803988039980400804018040280403804048040580406804078040880409804108041180412804138041480415804168041780418804198042080421804228042380424804258042680427804288042980430804318043280433804348043580436804378043880439804408044180442804438044480445804468044780448804498045080451804528045380454804558045680457804588045980460804618046280463804648046580466804678046880469804708047180472804738047480475804768047780478804798048080481804828048380484804858048680487804888048980490804918049280493804948049580496804978049880499805008050180502805038050480505805068050780508805098051080511805128051380514805158051680517805188051980520805218052280523805248052580526805278052880529805308053180532805338053480535805368053780538805398054080541805428054380544805458054680547805488054980550805518055280553805548055580556805578055880559805608056180562805638056480565805668056780568805698057080571805728057380574805758057680577805788057980580805818058280583805848058580586805878058880589805908059180592805938059480595805968059780598805998060080601806028060380604806058060680607806088060980610806118061280613806148061580616806178061880619806208062180622806238062480625806268062780628806298063080631806328063380634806358063680637806388063980640806418064280643806448064580646806478064880649806508065180652806538065480655806568065780658806598066080661806628066380664806658066680667806688066980670806718067280673806748067580676806778067880679806808068180682806838068480685806868068780688806898069080691806928069380694806958069680697806988069980700807018070280703807048070580706807078070880709807108071180712807138071480715807168071780718807198072080721807228072380724807258072680727807288072980730807318073280733807348073580736807378073880739807408074180742807438074480745807468074780748807498075080751807528075380754807558075680757807588075980760807618076280763807648076580766807678076880769807708077180772807738077480775807768077780778807798078080781807828078380784807858078680787807888078980790807918079280793807948079580796807978079880799808008080180802808038080480805808068080780808808098081080811808128081380814808158081680817808188081980820808218082280823808248082580826808278082880829808308083180832808338083480835808368083780838808398084080841808428084380844808458084680847808488084980850808518085280853808548085580856808578085880859808608086180862808638086480865808668086780868808698087080871808728087380874808758087680877808788087980880808818088280883808848088580886808878088880889808908089180892808938089480895808968089780898808998090080901809028090380904809058090680907809088090980910809118091280913809148091580916809178091880919809208092180922809238092480925809268092780928809298093080931809328093380934809358093680937809388093980940809418094280943809448094580946809478094880949809508095180952809538095480955809568095780958809598096080961809628096380964809658096680967809688096980970809718097280973809748097580976809778097880979809808098180982809838098480985809868098780988809898099080991809928099380994809958099680997809988099981000810018100281003810048100581006810078100881009810108101181012810138101481015810168101781018810198102081021810228102381024810258102681027810288102981030810318103281033810348103581036810378103881039810408104181042810438104481045810468104781048810498105081051810528105381054810558105681057810588105981060810618106281063810648106581066810678106881069810708107181072810738107481075810768107781078810798108081081810828108381084810858108681087810888108981090810918109281093810948109581096810978109881099811008110181102811038110481105811068110781108811098111081111811128111381114811158111681117811188111981120811218112281123811248112581126811278112881129811308113181132811338113481135811368113781138811398114081141811428114381144811458114681147811488114981150811518115281153811548115581156811578115881159811608116181162811638116481165811668116781168811698117081171811728117381174811758117681177811788117981180811818118281183811848118581186811878118881189811908119181192811938119481195811968119781198811998120081201812028120381204812058120681207812088120981210812118121281213812148121581216812178121881219812208122181222812238122481225812268122781228812298123081231812328123381234812358123681237812388123981240812418124281243812448124581246812478124881249812508125181252812538125481255812568125781258812598126081261812628126381264812658126681267812688126981270812718127281273812748127581276812778127881279812808128181282812838128481285812868128781288812898129081291812928129381294812958129681297812988129981300813018130281303813048130581306813078130881309813108131181312813138131481315813168131781318813198132081321813228132381324813258132681327813288132981330813318133281333813348133581336813378133881339813408134181342813438134481345813468134781348813498135081351813528135381354813558135681357813588135981360813618136281363813648136581366813678136881369813708137181372813738137481375813768137781378813798138081381813828138381384813858138681387813888138981390813918139281393813948139581396813978139881399814008140181402814038140481405814068140781408814098141081411814128141381414814158141681417814188141981420814218142281423814248142581426814278142881429814308143181432814338143481435814368143781438814398144081441814428144381444814458144681447814488144981450814518145281453814548145581456814578145881459814608146181462814638146481465814668146781468814698147081471814728147381474814758147681477814788147981480814818148281483814848148581486814878148881489814908149181492814938149481495814968149781498814998150081501815028150381504815058150681507815088150981510815118151281513815148151581516815178151881519815208152181522815238152481525815268152781528815298153081531815328153381534815358153681537815388153981540815418154281543815448154581546815478154881549815508155181552815538155481555815568155781558815598156081561815628156381564815658156681567815688156981570815718157281573815748157581576815778157881579815808158181582815838158481585815868158781588815898159081591815928159381594815958159681597815988159981600816018160281603816048160581606816078160881609816108161181612816138161481615816168161781618816198162081621816228162381624816258162681627816288162981630816318163281633816348163581636816378163881639816408164181642816438164481645816468164781648816498165081651816528165381654816558165681657816588165981660816618166281663816648166581666816678166881669816708167181672816738167481675816768167781678816798168081681816828168381684816858168681687816888168981690816918169281693816948169581696816978169881699817008170181702817038170481705817068170781708817098171081711817128171381714817158171681717817188171981720817218172281723817248172581726817278172881729817308173181732817338173481735817368173781738817398174081741817428174381744817458174681747817488174981750817518175281753817548175581756817578175881759817608176181762817638176481765817668176781768817698177081771817728177381774817758177681777817788177981780817818178281783817848178581786817878178881789817908179181792817938179481795817968179781798817998180081801818028180381804818058180681807818088180981810818118181281813818148181581816818178181881819818208182181822818238182481825818268182781828818298183081831818328183381834818358183681837818388183981840818418184281843818448184581846818478184881849818508185181852818538185481855818568185781858818598186081861818628186381864818658186681867818688186981870818718187281873818748187581876818778187881879818808188181882818838188481885818868188781888818898189081891818928189381894818958189681897818988189981900819018190281903819048190581906819078190881909819108191181912819138191481915819168191781918819198192081921819228192381924819258192681927819288192981930819318193281933819348193581936819378193881939819408194181942819438194481945819468194781948819498195081951819528195381954819558195681957819588195981960819618196281963819648196581966819678196881969819708197181972819738197481975819768197781978819798198081981819828198381984819858198681987819888198981990819918199281993819948199581996819978199881999820008200182002820038200482005820068200782008820098201082011820128201382014820158201682017820188201982020820218202282023820248202582026820278202882029820308203182032820338203482035820368203782038820398204082041820428204382044820458204682047820488204982050820518205282053820548205582056820578205882059820608206182062820638206482065820668206782068820698207082071820728207382074820758207682077820788207982080820818208282083820848208582086820878208882089820908209182092820938209482095820968209782098820998210082101821028210382104821058210682107821088210982110821118211282113821148211582116821178211882119821208212182122821238212482125821268212782128821298213082131821328213382134821358213682137821388213982140821418214282143821448214582146821478214882149821508215182152821538215482155821568215782158821598216082161821628216382164821658216682167821688216982170821718217282173821748217582176821778217882179821808218182182821838218482185821868218782188821898219082191821928219382194821958219682197821988219982200822018220282203822048220582206822078220882209822108221182212822138221482215822168221782218822198222082221822228222382224822258222682227822288222982230822318223282233822348223582236822378223882239822408224182242822438224482245822468224782248822498225082251822528225382254822558225682257822588225982260822618226282263822648226582266822678226882269822708227182272822738227482275822768227782278822798228082281822828228382284822858228682287822888228982290822918229282293822948229582296822978229882299823008230182302823038230482305823068230782308823098231082311823128231382314823158231682317823188231982320823218232282323823248232582326823278232882329823308233182332823338233482335823368233782338823398234082341823428234382344823458234682347823488234982350823518235282353823548235582356823578235882359823608236182362823638236482365823668236782368823698237082371823728237382374823758237682377823788237982380823818238282383823848238582386823878238882389823908239182392823938239482395823968239782398823998240082401824028240382404824058240682407824088240982410824118241282413824148241582416824178241882419824208242182422824238242482425824268242782428824298243082431824328243382434824358243682437824388243982440824418244282443824448244582446824478244882449824508245182452824538245482455824568245782458824598246082461824628246382464824658246682467824688246982470824718247282473824748247582476824778247882479824808248182482824838248482485824868248782488824898249082491824928249382494824958249682497824988249982500825018250282503825048250582506825078250882509825108251182512825138251482515825168251782518825198252082521825228252382524825258252682527825288252982530825318253282533825348253582536825378253882539825408254182542825438254482545825468254782548825498255082551825528255382554825558255682557825588255982560825618256282563825648256582566825678256882569825708257182572825738257482575825768257782578825798258082581825828258382584825858258682587825888258982590825918259282593825948259582596825978259882599826008260182602826038260482605826068260782608826098261082611826128261382614826158261682617826188261982620826218262282623826248262582626826278262882629826308263182632826338263482635826368263782638826398264082641826428264382644826458264682647826488264982650826518265282653826548265582656826578265882659826608266182662826638266482665826668266782668826698267082671826728267382674826758267682677826788267982680826818268282683826848268582686826878268882689826908269182692826938269482695826968269782698826998270082701827028270382704827058270682707827088270982710827118271282713827148271582716827178271882719827208272182722827238272482725827268272782728827298273082731827328273382734827358273682737827388273982740827418274282743827448274582746827478274882749827508275182752827538275482755827568275782758827598276082761827628276382764827658276682767827688276982770827718277282773827748277582776827778277882779827808278182782827838278482785827868278782788827898279082791827928279382794827958279682797827988279982800828018280282803828048280582806828078280882809828108281182812828138281482815828168281782818828198282082821828228282382824828258282682827828288282982830828318283282833828348283582836828378283882839828408284182842828438284482845828468284782848828498285082851828528285382854828558285682857828588285982860828618286282863828648286582866828678286882869828708287182872828738287482875828768287782878828798288082881828828288382884828858288682887828888288982890828918289282893828948289582896828978289882899829008290182902829038290482905829068290782908829098291082911829128291382914829158291682917829188291982920829218292282923829248292582926829278292882929829308293182932829338293482935829368293782938829398294082941829428294382944829458294682947829488294982950829518295282953829548295582956829578295882959829608296182962829638296482965829668296782968829698297082971829728297382974829758297682977829788297982980829818298282983829848298582986829878298882989829908299182992829938299482995829968299782998829998300083001830028300383004830058300683007830088300983010830118301283013830148301583016830178301883019830208302183022830238302483025830268302783028830298303083031830328303383034830358303683037830388303983040830418304283043830448304583046830478304883049830508305183052830538305483055830568305783058830598306083061830628306383064830658306683067830688306983070830718307283073830748307583076830778307883079830808308183082830838308483085830868308783088830898309083091830928309383094830958309683097830988309983100831018310283103831048310583106831078310883109831108311183112831138311483115831168311783118831198312083121831228312383124831258312683127831288312983130831318313283133831348313583136831378313883139831408314183142831438314483145831468314783148831498315083151831528315383154831558315683157831588315983160831618316283163831648316583166831678316883169831708317183172831738317483175831768317783178831798318083181831828318383184831858318683187831888318983190831918319283193831948319583196831978319883199832008320183202832038320483205832068320783208832098321083211832128321383214832158321683217832188321983220832218322283223832248322583226832278322883229832308323183232832338323483235832368323783238832398324083241832428324383244832458324683247832488324983250832518325283253832548325583256832578325883259832608326183262832638326483265832668326783268832698327083271832728327383274832758327683277832788327983280832818328283283832848328583286832878328883289832908329183292832938329483295832968329783298832998330083301833028330383304833058330683307833088330983310833118331283313833148331583316833178331883319833208332183322833238332483325833268332783328833298333083331833328333383334833358333683337833388333983340833418334283343833448334583346833478334883349833508335183352833538335483355833568335783358833598336083361833628336383364833658336683367833688336983370833718337283373833748337583376833778337883379833808338183382833838338483385833868338783388833898339083391833928339383394833958339683397833988339983400834018340283403834048340583406834078340883409834108341183412834138341483415834168341783418834198342083421834228342383424834258342683427834288342983430834318343283433834348343583436834378343883439834408344183442834438344483445834468344783448834498345083451834528345383454834558345683457834588345983460834618346283463834648346583466834678346883469834708347183472834738347483475834768347783478834798348083481834828348383484834858348683487834888348983490834918349283493834948349583496834978349883499835008350183502835038350483505835068350783508835098351083511835128351383514835158351683517835188351983520835218352283523835248352583526835278352883529835308353183532835338353483535835368353783538835398354083541835428354383544835458354683547835488354983550835518355283553835548355583556835578355883559835608356183562835638356483565835668356783568835698357083571835728357383574835758357683577835788357983580835818358283583835848358583586835878358883589835908359183592835938359483595835968359783598835998360083601836028360383604836058360683607836088360983610836118361283613836148361583616836178361883619836208362183622836238362483625836268362783628836298363083631836328363383634836358363683637836388363983640836418364283643836448364583646836478364883649836508365183652836538365483655836568365783658836598366083661836628366383664836658366683667836688366983670836718367283673836748367583676836778367883679836808368183682836838368483685836868368783688836898369083691836928369383694836958369683697836988369983700837018370283703837048370583706837078370883709837108371183712837138371483715837168371783718837198372083721837228372383724837258372683727837288372983730837318373283733837348373583736837378373883739837408374183742837438374483745837468374783748837498375083751837528375383754837558375683757837588375983760837618376283763837648376583766837678376883769837708377183772837738377483775837768377783778837798378083781837828378383784837858378683787837888378983790837918379283793837948379583796837978379883799838008380183802838038380483805838068380783808838098381083811838128381383814838158381683817838188381983820838218382283823838248382583826838278382883829838308383183832838338383483835838368383783838838398384083841838428384383844838458384683847838488384983850838518385283853838548385583856838578385883859838608386183862838638386483865838668386783868838698387083871838728387383874838758387683877838788387983880838818388283883838848388583886838878388883889838908389183892838938389483895838968389783898838998390083901839028390383904839058390683907839088390983910839118391283913839148391583916839178391883919839208392183922839238392483925839268392783928839298393083931839328393383934839358393683937839388393983940839418394283943839448394583946839478394883949839508395183952839538395483955839568395783958839598396083961839628396383964839658396683967839688396983970839718397283973839748397583976839778397883979839808398183982839838398483985839868398783988839898399083991839928399383994839958399683997839988399984000840018400284003840048400584006840078400884009840108401184012840138401484015840168401784018840198402084021840228402384024840258402684027840288402984030840318403284033840348403584036840378403884039840408404184042840438404484045840468404784048840498405084051840528405384054840558405684057840588405984060840618406284063840648406584066840678406884069840708407184072840738407484075840768407784078840798408084081840828408384084840858408684087840888408984090840918409284093840948409584096840978409884099841008410184102841038410484105841068410784108841098411084111841128411384114841158411684117841188411984120841218412284123841248412584126841278412884129841308413184132841338413484135841368413784138841398414084141841428414384144841458414684147841488414984150841518415284153841548415584156841578415884159841608416184162841638416484165841668416784168841698417084171841728417384174841758417684177841788417984180841818418284183841848418584186841878418884189841908419184192841938419484195841968419784198841998420084201842028420384204842058420684207842088420984210842118421284213842148421584216842178421884219842208422184222842238422484225842268422784228842298423084231842328423384234842358423684237842388423984240842418424284243842448424584246842478424884249842508425184252842538425484255842568425784258842598426084261842628426384264842658426684267842688426984270842718427284273842748427584276842778427884279842808428184282842838428484285842868428784288842898429084291842928429384294842958429684297842988429984300843018430284303843048430584306843078430884309843108431184312843138431484315843168431784318843198432084321843228432384324843258432684327843288432984330843318433284333843348433584336843378433884339843408434184342843438434484345843468434784348843498435084351843528435384354843558435684357843588435984360843618436284363843648436584366843678436884369843708437184372843738437484375843768437784378843798438084381843828438384384843858438684387843888438984390843918439284393843948439584396843978439884399844008440184402844038440484405844068440784408844098441084411844128441384414844158441684417844188441984420844218442284423844248442584426844278442884429844308443184432844338443484435844368443784438844398444084441844428444384444844458444684447844488444984450844518445284453844548445584456844578445884459844608446184462844638446484465844668446784468844698447084471844728447384474844758447684477844788447984480844818448284483844848448584486844878448884489844908449184492844938449484495844968449784498844998450084501845028450384504845058450684507845088450984510845118451284513845148451584516845178451884519845208452184522845238452484525845268452784528845298453084531845328453384534845358453684537845388453984540845418454284543845448454584546845478454884549845508455184552845538455484555845568455784558845598456084561845628456384564845658456684567845688456984570845718457284573845748457584576845778457884579845808458184582845838458484585845868458784588845898459084591845928459384594845958459684597845988459984600846018460284603846048460584606846078460884609846108461184612846138461484615846168461784618846198462084621846228462384624846258462684627846288462984630846318463284633846348463584636846378463884639846408464184642846438464484645846468464784648846498465084651846528465384654846558465684657846588465984660846618466284663846648466584666846678466884669846708467184672846738467484675846768467784678846798468084681846828468384684846858468684687846888468984690846918469284693846948469584696846978469884699847008470184702847038470484705847068470784708847098471084711847128471384714847158471684717847188471984720847218472284723847248472584726847278472884729847308473184732847338473484735847368473784738847398474084741847428474384744847458474684747847488474984750847518475284753847548475584756847578475884759847608476184762847638476484765847668476784768847698477084771847728477384774847758477684777847788477984780847818478284783847848478584786847878478884789847908479184792847938479484795847968479784798847998480084801848028480384804848058480684807848088480984810848118481284813848148481584816848178481884819848208482184822848238482484825848268482784828848298483084831848328483384834848358483684837848388483984840848418484284843848448484584846848478484884849848508485184852848538485484855848568485784858848598486084861848628486384864848658486684867848688486984870848718487284873848748487584876848778487884879848808488184882848838488484885848868488784888848898489084891848928489384894848958489684897848988489984900849018490284903849048490584906849078490884909849108491184912849138491484915849168491784918849198492084921849228492384924849258492684927849288492984930849318493284933849348493584936849378493884939849408494184942849438494484945849468494784948849498495084951849528495384954849558495684957849588495984960849618496284963849648496584966849678496884969849708497184972849738497484975849768497784978849798498084981849828498384984849858498684987849888498984990849918499284993849948499584996849978499884999850008500185002850038500485005850068500785008850098501085011850128501385014850158501685017850188501985020850218502285023850248502585026850278502885029850308503185032850338503485035850368503785038850398504085041850428504385044850458504685047850488504985050850518505285053850548505585056850578505885059850608506185062850638506485065850668506785068850698507085071850728507385074850758507685077850788507985080850818508285083850848508585086850878508885089850908509185092850938509485095850968509785098850998510085101851028510385104851058510685107851088510985110851118511285113851148511585116851178511885119851208512185122851238512485125851268512785128851298513085131851328513385134851358513685137851388513985140851418514285143851448514585146851478514885149851508515185152851538515485155851568515785158851598516085161851628516385164851658516685167851688516985170851718517285173851748517585176851778517885179851808518185182851838518485185851868518785188851898519085191851928519385194851958519685197851988519985200852018520285203852048520585206852078520885209852108521185212852138521485215852168521785218852198522085221852228522385224852258522685227852288522985230852318523285233852348523585236852378523885239852408524185242852438524485245852468524785248852498525085251852528525385254852558525685257852588525985260852618526285263852648526585266852678526885269852708527185272852738527485275852768527785278852798528085281852828528385284852858528685287852888528985290852918529285293852948529585296852978529885299853008530185302853038530485305853068530785308853098531085311853128531385314853158531685317853188531985320853218532285323853248532585326853278532885329853308533185332853338533485335853368533785338853398534085341853428534385344853458534685347853488534985350853518535285353853548535585356853578535885359853608536185362853638536485365853668536785368853698537085371853728537385374853758537685377853788537985380853818538285383853848538585386853878538885389853908539185392853938539485395853968539785398853998540085401854028540385404854058540685407854088540985410854118541285413854148541585416854178541885419854208542185422854238542485425854268542785428854298543085431854328543385434854358543685437854388543985440854418544285443854448544585446854478544885449854508545185452854538545485455854568545785458854598546085461854628546385464854658546685467854688546985470854718547285473854748547585476854778547885479854808548185482854838548485485854868548785488854898549085491854928549385494854958549685497854988549985500855018550285503855048550585506855078550885509855108551185512855138551485515855168551785518855198552085521855228552385524855258552685527855288552985530855318553285533855348553585536855378553885539855408554185542855438554485545855468554785548855498555085551855528555385554855558555685557855588555985560855618556285563855648556585566855678556885569855708557185572855738557485575855768557785578855798558085581855828558385584855858558685587855888558985590855918559285593855948559585596855978559885599856008560185602856038560485605856068560785608856098561085611856128561385614856158561685617856188561985620856218562285623856248562585626856278562885629856308563185632856338563485635856368563785638856398564085641856428564385644856458564685647856488564985650856518565285653856548565585656856578565885659856608566185662856638566485665856668566785668856698567085671856728567385674856758567685677856788567985680856818568285683856848568585686856878568885689856908569185692856938569485695856968569785698856998570085701857028570385704857058570685707857088570985710857118571285713857148571585716857178571885719857208572185722857238572485725857268572785728857298573085731857328573385734857358573685737857388573985740857418574285743857448574585746857478574885749857508575185752857538575485755857568575785758857598576085761857628576385764857658576685767857688576985770857718577285773857748577585776857778577885779857808578185782857838578485785857868578785788857898579085791857928579385794857958579685797857988579985800858018580285803858048580585806858078580885809858108581185812858138581485815858168581785818858198582085821858228582385824858258582685827858288582985830858318583285833858348583585836858378583885839858408584185842858438584485845858468584785848858498585085851858528585385854858558585685857858588585985860858618586285863858648586585866858678586885869858708587185872858738587485875858768587785878858798588085881858828588385884858858588685887858888588985890858918589285893858948589585896858978589885899859008590185902859038590485905859068590785908859098591085911859128591385914859158591685917859188591985920859218592285923859248592585926859278592885929859308593185932859338593485935859368593785938859398594085941859428594385944859458594685947859488594985950859518595285953859548595585956859578595885959859608596185962859638596485965859668596785968859698597085971859728597385974859758597685977859788597985980859818598285983859848598585986859878598885989859908599185992859938599485995859968599785998859998600086001860028600386004860058600686007860088600986010860118601286013860148601586016860178601886019860208602186022860238602486025860268602786028860298603086031860328603386034860358603686037860388603986040860418604286043860448604586046860478604886049860508605186052860538605486055860568605786058860598606086061860628606386064860658606686067860688606986070860718607286073860748607586076860778607886079860808608186082860838608486085860868608786088860898609086091860928609386094860958609686097860988609986100861018610286103861048610586106861078610886109861108611186112861138611486115861168611786118861198612086121861228612386124861258612686127861288612986130861318613286133861348613586136861378613886139861408614186142861438614486145861468614786148861498615086151861528615386154861558615686157861588615986160861618616286163861648616586166861678616886169861708617186172861738617486175861768617786178861798618086181861828618386184861858618686187861888618986190861918619286193861948619586196861978619886199862008620186202862038620486205862068620786208862098621086211862128621386214862158621686217862188621986220862218622286223862248622586226862278622886229862308623186232862338623486235862368623786238862398624086241862428624386244862458624686247862488624986250862518625286253862548625586256862578625886259862608626186262862638626486265862668626786268862698627086271862728627386274862758627686277862788627986280862818628286283862848628586286862878628886289862908629186292862938629486295862968629786298862998630086301863028630386304863058630686307863088630986310863118631286313863148631586316863178631886319863208632186322863238632486325863268632786328863298633086331863328633386334863358633686337863388633986340863418634286343863448634586346863478634886349863508635186352863538635486355863568635786358863598636086361863628636386364863658636686367863688636986370863718637286373863748637586376863778637886379863808638186382863838638486385863868638786388863898639086391863928639386394863958639686397863988639986400864018640286403864048640586406864078640886409864108641186412864138641486415864168641786418864198642086421864228642386424864258642686427864288642986430864318643286433864348643586436864378643886439864408644186442864438644486445864468644786448864498645086451864528645386454864558645686457864588645986460864618646286463864648646586466864678646886469864708647186472864738647486475864768647786478864798648086481864828648386484864858648686487864888648986490864918649286493864948649586496864978649886499865008650186502865038650486505865068650786508865098651086511865128651386514865158651686517865188651986520865218652286523865248652586526865278652886529865308653186532865338653486535865368653786538865398654086541865428654386544865458654686547865488654986550865518655286553865548655586556865578655886559865608656186562865638656486565865668656786568865698657086571865728657386574865758657686577865788657986580865818658286583865848658586586865878658886589865908659186592865938659486595865968659786598865998660086601866028660386604866058660686607866088660986610866118661286613866148661586616866178661886619866208662186622866238662486625866268662786628866298663086631866328663386634866358663686637866388663986640866418664286643866448664586646866478664886649866508665186652866538665486655866568665786658866598666086661866628666386664866658666686667866688666986670866718667286673866748667586676866778667886679866808668186682866838668486685866868668786688866898669086691866928669386694866958669686697866988669986700867018670286703867048670586706867078670886709867108671186712867138671486715867168671786718867198672086721867228672386724867258672686727867288672986730867318673286733867348673586736867378673886739867408674186742867438674486745867468674786748867498675086751867528675386754867558675686757867588675986760867618676286763867648676586766867678676886769867708677186772867738677486775867768677786778867798678086781867828678386784867858678686787867888678986790867918679286793867948679586796867978679886799868008680186802868038680486805868068680786808868098681086811868128681386814868158681686817868188681986820868218682286823868248682586826868278682886829868308683186832868338683486835868368683786838868398684086841868428684386844868458684686847868488684986850868518685286853868548685586856868578685886859868608686186862868638686486865868668686786868868698687086871868728687386874868758687686877868788687986880868818688286883868848688586886868878688886889868908689186892868938689486895868968689786898868998690086901869028690386904869058690686907869088690986910869118691286913869148691586916869178691886919869208692186922869238692486925869268692786928869298693086931869328693386934869358693686937869388693986940869418694286943869448694586946869478694886949869508695186952869538695486955869568695786958869598696086961869628696386964869658696686967869688696986970869718697286973869748697586976869778697886979869808698186982869838698486985869868698786988869898699086991869928699386994869958699686997869988699987000870018700287003870048700587006870078700887009870108701187012870138701487015870168701787018870198702087021870228702387024870258702687027870288702987030870318703287033870348703587036870378703887039870408704187042870438704487045870468704787048870498705087051870528705387054870558705687057870588705987060870618706287063870648706587066870678706887069870708707187072870738707487075870768707787078870798708087081870828708387084870858708687087870888708987090870918709287093870948709587096870978709887099871008710187102871038710487105871068710787108871098711087111871128711387114871158711687117871188711987120871218712287123871248712587126871278712887129871308713187132871338713487135871368713787138871398714087141871428714387144871458714687147871488714987150871518715287153871548715587156871578715887159871608716187162871638716487165871668716787168871698717087171871728717387174871758717687177871788717987180871818718287183871848718587186871878718887189871908719187192871938719487195871968719787198871998720087201872028720387204872058720687207872088720987210872118721287213872148721587216872178721887219872208722187222872238722487225872268722787228872298723087231872328723387234872358723687237872388723987240872418724287243872448724587246872478724887249872508725187252872538725487255872568725787258872598726087261872628726387264872658726687267872688726987270872718727287273872748727587276872778727887279872808728187282872838728487285872868728787288872898729087291872928729387294872958729687297872988729987300873018730287303873048730587306873078730887309873108731187312873138731487315873168731787318873198732087321873228732387324873258732687327873288732987330873318733287333873348733587336873378733887339873408734187342873438734487345873468734787348873498735087351873528735387354873558735687357873588735987360873618736287363873648736587366873678736887369873708737187372873738737487375873768737787378873798738087381873828738387384873858738687387873888738987390873918739287393873948739587396873978739887399874008740187402874038740487405874068740787408874098741087411874128741387414874158741687417874188741987420874218742287423874248742587426874278742887429874308743187432874338743487435874368743787438874398744087441874428744387444874458744687447874488744987450874518745287453874548745587456874578745887459874608746187462874638746487465874668746787468874698747087471874728747387474874758747687477874788747987480874818748287483874848748587486874878748887489874908749187492874938749487495874968749787498874998750087501875028750387504875058750687507875088750987510875118751287513875148751587516875178751887519875208752187522875238752487525875268752787528875298753087531875328753387534875358753687537875388753987540875418754287543875448754587546875478754887549875508755187552875538755487555875568755787558875598756087561875628756387564875658756687567875688756987570875718757287573875748757587576875778757887579875808758187582875838758487585875868758787588875898759087591875928759387594875958759687597875988759987600876018760287603876048760587606876078760887609876108761187612876138761487615876168761787618876198762087621876228762387624876258762687627876288762987630876318763287633876348763587636876378763887639876408764187642876438764487645876468764787648876498765087651876528765387654876558765687657876588765987660876618766287663876648766587666876678766887669876708767187672876738767487675876768767787678876798768087681876828768387684876858768687687876888768987690876918769287693876948769587696876978769887699877008770187702877038770487705877068770787708877098771087711877128771387714877158771687717877188771987720877218772287723877248772587726877278772887729877308773187732877338773487735877368773787738877398774087741877428774387744877458774687747877488774987750877518775287753877548775587756877578775887759877608776187762877638776487765877668776787768877698777087771877728777387774877758777687777877788777987780877818778287783877848778587786877878778887789877908779187792877938779487795877968779787798877998780087801878028780387804878058780687807878088780987810878118781287813878148781587816878178781887819878208782187822878238782487825878268782787828878298783087831878328783387834878358783687837878388783987840878418784287843878448784587846878478784887849878508785187852878538785487855878568785787858878598786087861878628786387864878658786687867878688786987870878718787287873878748787587876878778787887879878808788187882878838788487885878868788787888878898789087891878928789387894878958789687897878988789987900879018790287903879048790587906879078790887909879108791187912879138791487915879168791787918879198792087921879228792387924879258792687927879288792987930879318793287933879348793587936879378793887939879408794187942879438794487945879468794787948879498795087951879528795387954879558795687957879588795987960879618796287963879648796587966879678796887969879708797187972879738797487975879768797787978879798798087981879828798387984879858798687987879888798987990879918799287993879948799587996879978799887999880008800188002880038800488005880068800788008880098801088011880128801388014880158801688017880188801988020880218802288023880248802588026880278802888029880308803188032880338803488035880368803788038880398804088041880428804388044880458804688047880488804988050880518805288053880548805588056880578805888059880608806188062880638806488065880668806788068880698807088071880728807388074880758807688077880788807988080880818808288083880848808588086880878808888089880908809188092880938809488095880968809788098880998810088101881028810388104881058810688107881088810988110881118811288113881148811588116881178811888119881208812188122881238812488125881268812788128881298813088131881328813388134881358813688137881388813988140881418814288143881448814588146881478814888149881508815188152881538815488155881568815788158881598816088161881628816388164881658816688167881688816988170881718817288173881748817588176881778817888179881808818188182881838818488185881868818788188881898819088191881928819388194881958819688197881988819988200882018820288203882048820588206882078820888209882108821188212882138821488215882168821788218882198822088221882228822388224882258822688227882288822988230882318823288233882348823588236882378823888239882408824188242882438824488245882468824788248882498825088251882528825388254882558825688257882588825988260882618826288263882648826588266882678826888269882708827188272882738827488275882768827788278882798828088281882828828388284882858828688287882888828988290882918829288293882948829588296882978829888299883008830188302883038830488305883068830788308883098831088311883128831388314883158831688317883188831988320883218832288323883248832588326883278832888329883308833188332883338833488335883368833788338883398834088341883428834388344883458834688347883488834988350883518835288353883548835588356883578835888359883608836188362883638836488365883668836788368883698837088371883728837388374883758837688377883788837988380883818838288383883848838588386883878838888389883908839188392883938839488395883968839788398883998840088401884028840388404884058840688407884088840988410884118841288413884148841588416884178841888419884208842188422884238842488425884268842788428884298843088431884328843388434884358843688437884388843988440884418844288443884448844588446884478844888449884508845188452884538845488455884568845788458884598846088461884628846388464884658846688467884688846988470884718847288473884748847588476884778847888479884808848188482884838848488485884868848788488884898849088491884928849388494884958849688497884988849988500885018850288503885048850588506885078850888509885108851188512885138851488515885168851788518885198852088521885228852388524885258852688527885288852988530885318853288533885348853588536885378853888539885408854188542885438854488545885468854788548885498855088551885528855388554885558855688557885588855988560885618856288563885648856588566885678856888569885708857188572885738857488575885768857788578885798858088581885828858388584885858858688587885888858988590885918859288593885948859588596885978859888599886008860188602886038860488605886068860788608886098861088611886128861388614886158861688617886188861988620886218862288623886248862588626886278862888629886308863188632886338863488635886368863788638886398864088641886428864388644886458864688647886488864988650886518865288653886548865588656886578865888659886608866188662886638866488665886668866788668886698867088671886728867388674886758867688677886788867988680886818868288683886848868588686886878868888689886908869188692886938869488695886968869788698886998870088701887028870388704887058870688707887088870988710887118871288713887148871588716887178871888719887208872188722887238872488725887268872788728887298873088731887328873388734887358873688737887388873988740887418874288743887448874588746887478874888749887508875188752887538875488755887568875788758887598876088761887628876388764887658876688767887688876988770887718877288773887748877588776887778877888779887808878188782887838878488785887868878788788887898879088791887928879388794887958879688797887988879988800888018880288803888048880588806888078880888809888108881188812888138881488815888168881788818888198882088821888228882388824888258882688827888288882988830888318883288833888348883588836888378883888839888408884188842888438884488845888468884788848888498885088851888528885388854888558885688857888588885988860888618886288863888648886588866888678886888869888708887188872888738887488875888768887788878888798888088881888828888388884888858888688887888888888988890888918889288893888948889588896888978889888899889008890188902889038890488905889068890788908889098891088911889128891388914889158891688917889188891988920889218892288923889248892588926889278892888929889308893188932889338893488935889368893788938889398894088941889428894388944889458894688947889488894988950889518895288953889548895588956889578895888959889608896188962889638896488965889668896788968889698897088971889728897388974889758897688977889788897988980889818898288983889848898588986889878898888989889908899188992889938899488995889968899788998889998900089001890028900389004890058900689007890088900989010890118901289013890148901589016890178901889019890208902189022890238902489025890268902789028890298903089031890328903389034890358903689037890388903989040890418904289043890448904589046890478904889049890508905189052890538905489055890568905789058890598906089061890628906389064890658906689067890688906989070890718907289073890748907589076890778907889079890808908189082890838908489085890868908789088890898909089091890928909389094890958909689097890988909989100891018910289103891048910589106891078910889109891108911189112891138911489115891168911789118891198912089121891228912389124891258912689127891288912989130891318913289133891348913589136891378913889139891408914189142891438914489145891468914789148891498915089151891528915389154891558915689157891588915989160891618916289163891648916589166891678916889169891708917189172891738917489175891768917789178891798918089181891828918389184891858918689187891888918989190891918919289193891948919589196891978919889199892008920189202892038920489205892068920789208892098921089211892128921389214892158921689217892188921989220892218922289223892248922589226892278922889229892308923189232892338923489235892368923789238892398924089241892428924389244892458924689247892488924989250892518925289253892548925589256892578925889259892608926189262892638926489265892668926789268892698927089271892728927389274892758927689277892788927989280892818928289283892848928589286892878928889289892908929189292892938929489295892968929789298892998930089301893028930389304893058930689307893088930989310893118931289313893148931589316893178931889319893208932189322893238932489325893268932789328893298933089331893328933389334893358933689337893388933989340893418934289343893448934589346893478934889349893508935189352893538935489355893568935789358893598936089361893628936389364893658936689367893688936989370893718937289373893748937589376893778937889379893808938189382893838938489385893868938789388893898939089391893928939389394893958939689397893988939989400894018940289403894048940589406894078940889409894108941189412894138941489415894168941789418894198942089421894228942389424894258942689427894288942989430894318943289433894348943589436894378943889439894408944189442894438944489445894468944789448894498945089451894528945389454894558945689457894588945989460894618946289463894648946589466894678946889469894708947189472894738947489475894768947789478894798948089481894828948389484894858948689487894888948989490894918949289493894948949589496894978949889499895008950189502895038950489505895068950789508895098951089511895128951389514895158951689517895188951989520895218952289523895248952589526895278952889529895308953189532895338953489535895368953789538895398954089541895428954389544895458954689547895488954989550895518955289553895548955589556895578955889559895608956189562895638956489565895668956789568895698957089571895728957389574895758957689577895788957989580895818958289583895848958589586895878958889589895908959189592895938959489595895968959789598895998960089601896028960389604896058960689607896088960989610896118961289613896148961589616896178961889619896208962189622896238962489625896268962789628896298963089631896328963389634896358963689637896388963989640896418964289643896448964589646896478964889649896508965189652896538965489655896568965789658896598966089661896628966389664896658966689667896688966989670896718967289673896748967589676896778967889679896808968189682896838968489685896868968789688896898969089691896928969389694896958969689697896988969989700897018970289703897048970589706897078970889709897108971189712897138971489715897168971789718897198972089721897228972389724897258972689727897288972989730897318973289733897348973589736897378973889739897408974189742897438974489745897468974789748897498975089751897528975389754897558975689757897588975989760897618976289763897648976589766897678976889769897708977189772897738977489775897768977789778897798978089781897828978389784897858978689787897888978989790897918979289793897948979589796897978979889799898008980189802898038980489805898068980789808898098981089811898128981389814898158981689817898188981989820898218982289823898248982589826898278982889829898308983189832898338983489835898368983789838898398984089841898428984389844898458984689847898488984989850898518985289853898548985589856898578985889859898608986189862898638986489865898668986789868898698987089871898728987389874898758987689877898788987989880898818988289883898848988589886898878988889889898908989189892898938989489895898968989789898898998990089901899028990389904899058990689907899088990989910899118991289913899148991589916899178991889919899208992189922899238992489925899268992789928899298993089931899328993389934899358993689937899388993989940899418994289943899448994589946899478994889949899508995189952899538995489955899568995789958899598996089961899628996389964899658996689967899688996989970899718997289973899748997589976899778997889979899808998189982899838998489985899868998789988899898999089991899928999389994899958999689997899988999990000900019000290003900049000590006900079000890009900109001190012900139001490015900169001790018900199002090021900229002390024900259002690027900289002990030900319003290033900349003590036900379003890039900409004190042900439004490045900469004790048900499005090051900529005390054900559005690057900589005990060900619006290063900649006590066900679006890069900709007190072900739007490075900769007790078900799008090081900829008390084900859008690087900889008990090900919009290093900949009590096900979009890099901009010190102901039010490105901069010790108901099011090111901129011390114901159011690117901189011990120901219012290123901249012590126901279012890129901309013190132901339013490135901369013790138901399014090141901429014390144901459014690147901489014990150901519015290153901549015590156901579015890159901609016190162901639016490165901669016790168901699017090171901729017390174901759017690177901789017990180901819018290183901849018590186901879018890189901909019190192901939019490195901969019790198901999020090201902029020390204902059020690207902089020990210902119021290213902149021590216902179021890219902209022190222902239022490225902269022790228902299023090231902329023390234902359023690237902389023990240902419024290243902449024590246902479024890249902509025190252902539025490255902569025790258902599026090261902629026390264902659026690267902689026990270902719027290273902749027590276902779027890279902809028190282902839028490285902869028790288902899029090291902929029390294902959029690297902989029990300903019030290303903049030590306903079030890309903109031190312903139031490315903169031790318903199032090321903229032390324903259032690327903289032990330903319033290333903349033590336903379033890339903409034190342903439034490345903469034790348903499035090351903529035390354903559035690357903589035990360903619036290363903649036590366903679036890369903709037190372903739037490375903769037790378903799038090381903829038390384903859038690387903889038990390903919039290393903949039590396903979039890399904009040190402904039040490405904069040790408904099041090411904129041390414904159041690417904189041990420904219042290423904249042590426904279042890429904309043190432904339043490435904369043790438904399044090441904429044390444904459044690447904489044990450904519045290453904549045590456904579045890459904609046190462904639046490465904669046790468904699047090471904729047390474904759047690477904789047990480904819048290483904849048590486904879048890489904909049190492904939049490495904969049790498904999050090501905029050390504905059050690507905089050990510905119051290513905149051590516905179051890519905209052190522905239052490525905269052790528905299053090531905329053390534905359053690537905389053990540905419054290543905449054590546905479054890549905509055190552905539055490555905569055790558905599056090561905629056390564905659056690567905689056990570905719057290573905749057590576905779057890579905809058190582905839058490585905869058790588905899059090591905929059390594905959059690597905989059990600906019060290603906049060590606906079060890609906109061190612906139061490615906169061790618906199062090621906229062390624906259062690627906289062990630906319063290633906349063590636906379063890639906409064190642906439064490645906469064790648906499065090651906529065390654906559065690657906589065990660906619066290663906649066590666906679066890669906709067190672906739067490675906769067790678906799068090681906829068390684906859068690687906889068990690906919069290693906949069590696906979069890699907009070190702907039070490705907069070790708907099071090711907129071390714907159071690717907189071990720907219072290723907249072590726907279072890729907309073190732907339073490735907369073790738907399074090741907429074390744907459074690747907489074990750907519075290753907549075590756907579075890759907609076190762907639076490765907669076790768907699077090771907729077390774907759077690777907789077990780907819078290783907849078590786907879078890789907909079190792907939079490795907969079790798907999080090801908029080390804908059080690807908089080990810908119081290813908149081590816908179081890819908209082190822908239082490825908269082790828908299083090831908329083390834908359083690837908389083990840908419084290843908449084590846908479084890849908509085190852908539085490855908569085790858908599086090861908629086390864908659086690867908689086990870908719087290873908749087590876908779087890879908809088190882908839088490885908869088790888908899089090891908929089390894908959089690897908989089990900909019090290903909049090590906909079090890909909109091190912909139091490915909169091790918909199092090921909229092390924909259092690927909289092990930909319093290933909349093590936909379093890939909409094190942909439094490945909469094790948909499095090951909529095390954909559095690957909589095990960909619096290963909649096590966909679096890969909709097190972909739097490975909769097790978909799098090981909829098390984909859098690987909889098990990909919099290993909949099590996909979099890999910009100191002910039100491005910069100791008910099101091011910129101391014910159101691017910189101991020910219102291023910249102591026910279102891029910309103191032910339103491035910369103791038910399104091041910429104391044910459104691047910489104991050910519105291053910549105591056910579105891059910609106191062910639106491065910669106791068910699107091071910729107391074910759107691077910789107991080910819108291083910849108591086910879108891089910909109191092910939109491095910969109791098910999110091101911029110391104911059110691107911089110991110911119111291113911149111591116911179111891119911209112191122911239112491125911269112791128911299113091131911329113391134911359113691137911389113991140911419114291143911449114591146911479114891149911509115191152911539115491155911569115791158911599116091161911629116391164911659116691167911689116991170911719117291173911749117591176911779117891179911809118191182911839118491185911869118791188911899119091191911929119391194911959119691197911989119991200912019120291203912049120591206912079120891209912109121191212912139121491215912169121791218912199122091221912229122391224912259122691227912289122991230912319123291233912349123591236912379123891239912409124191242912439124491245912469124791248912499125091251912529125391254912559125691257912589125991260912619126291263912649126591266912679126891269912709127191272912739127491275912769127791278912799128091281912829128391284912859128691287912889128991290912919129291293912949129591296912979129891299913009130191302913039130491305913069130791308913099131091311913129131391314913159131691317913189131991320913219132291323913249132591326913279132891329913309133191332913339133491335913369133791338913399134091341913429134391344913459134691347913489134991350913519135291353913549135591356913579135891359913609136191362913639136491365913669136791368913699137091371913729137391374913759137691377913789137991380913819138291383913849138591386913879138891389913909139191392913939139491395913969139791398913999140091401914029140391404914059140691407914089140991410914119141291413914149141591416914179141891419914209142191422914239142491425914269142791428914299143091431914329143391434914359143691437914389143991440914419144291443914449144591446914479144891449914509145191452914539145491455914569145791458914599146091461914629146391464914659146691467914689146991470914719147291473914749147591476914779147891479914809148191482914839148491485914869148791488914899149091491914929149391494914959149691497914989149991500915019150291503915049150591506915079150891509915109151191512915139151491515915169151791518915199152091521915229152391524915259152691527915289152991530915319153291533915349153591536915379153891539915409154191542915439154491545915469154791548915499155091551915529155391554915559155691557915589155991560915619156291563915649156591566915679156891569915709157191572915739157491575915769157791578915799158091581915829158391584915859158691587915889158991590915919159291593915949159591596915979159891599916009160191602916039160491605916069160791608916099161091611916129161391614916159161691617916189161991620916219162291623916249162591626916279162891629916309163191632916339163491635916369163791638916399164091641916429164391644916459164691647916489164991650916519165291653916549165591656916579165891659916609166191662916639166491665916669166791668916699167091671916729167391674916759167691677916789167991680916819168291683916849168591686916879168891689916909169191692916939169491695916969169791698916999170091701917029170391704917059170691707917089170991710917119171291713917149171591716917179171891719917209172191722917239172491725917269172791728917299173091731917329173391734917359173691737917389173991740917419174291743917449174591746917479174891749917509175191752917539175491755917569175791758917599176091761917629176391764917659176691767917689176991770917719177291773917749177591776917779177891779917809178191782917839178491785917869178791788917899179091791917929179391794917959179691797917989179991800918019180291803918049180591806918079180891809918109181191812918139181491815918169181791818918199182091821918229182391824918259182691827918289182991830918319183291833918349183591836918379183891839918409184191842918439184491845918469184791848918499185091851918529185391854918559185691857918589185991860918619186291863918649186591866918679186891869918709187191872918739187491875918769187791878918799188091881918829188391884918859188691887918889188991890918919189291893918949189591896918979189891899919009190191902919039190491905919069190791908919099191091911919129191391914919159191691917919189191991920919219192291923919249192591926919279192891929919309193191932919339193491935919369193791938919399194091941919429194391944919459194691947919489194991950919519195291953919549195591956919579195891959919609196191962919639196491965919669196791968919699197091971919729197391974919759197691977919789197991980919819198291983919849198591986919879198891989919909199191992919939199491995919969199791998919999200092001920029200392004920059200692007920089200992010920119201292013920149201592016920179201892019920209202192022920239202492025920269202792028920299203092031920329203392034920359203692037920389203992040920419204292043920449204592046920479204892049920509205192052920539205492055920569205792058920599206092061920629206392064920659206692067920689206992070920719207292073920749207592076920779207892079920809208192082920839208492085920869208792088920899209092091920929209392094920959209692097920989209992100921019210292103921049210592106921079210892109921109211192112921139211492115921169211792118921199212092121921229212392124921259212692127921289212992130921319213292133921349213592136921379213892139921409214192142921439214492145921469214792148921499215092151921529215392154921559215692157921589215992160921619216292163921649216592166921679216892169921709217192172921739217492175921769217792178921799218092181921829218392184921859218692187921889218992190921919219292193921949219592196921979219892199922009220192202922039220492205922069220792208922099221092211922129221392214922159221692217922189221992220922219222292223922249222592226922279222892229922309223192232922339223492235922369223792238922399224092241922429224392244922459224692247922489224992250922519225292253922549225592256922579225892259922609226192262922639226492265922669226792268922699227092271922729227392274922759227692277922789227992280922819228292283922849228592286922879228892289922909229192292922939229492295922969229792298922999230092301923029230392304923059230692307923089230992310923119231292313923149231592316923179231892319923209232192322923239232492325923269232792328923299233092331923329233392334923359233692337923389233992340923419234292343923449234592346923479234892349923509235192352923539235492355923569235792358923599236092361923629236392364923659236692367923689236992370923719237292373923749237592376923779237892379923809238192382923839238492385923869238792388923899239092391923929239392394923959239692397923989239992400924019240292403924049240592406924079240892409924109241192412924139241492415924169241792418924199242092421924229242392424924259242692427924289242992430924319243292433924349243592436924379243892439924409244192442924439244492445924469244792448924499245092451924529245392454924559245692457924589245992460924619246292463924649246592466924679246892469924709247192472924739247492475924769247792478924799248092481924829248392484924859248692487924889248992490924919249292493924949249592496924979249892499925009250192502925039250492505925069250792508925099251092511925129251392514925159251692517925189251992520925219252292523925249252592526925279252892529925309253192532925339253492535925369253792538925399254092541925429254392544925459254692547925489254992550925519255292553925549255592556925579255892559925609256192562925639256492565925669256792568925699257092571925729257392574925759257692577925789257992580925819258292583925849258592586925879258892589925909259192592925939259492595925969259792598925999260092601926029260392604926059260692607926089260992610926119261292613926149261592616926179261892619926209262192622926239262492625926269262792628926299263092631926329263392634926359263692637926389263992640926419264292643926449264592646926479264892649926509265192652926539265492655926569265792658926599266092661926629266392664926659266692667926689266992670926719267292673926749267592676926779267892679926809268192682926839268492685926869268792688926899269092691926929269392694926959269692697926989269992700927019270292703927049270592706927079270892709927109271192712927139271492715927169271792718927199272092721927229272392724927259272692727927289272992730927319273292733927349273592736927379273892739927409274192742927439274492745927469274792748927499275092751927529275392754927559275692757927589275992760927619276292763927649276592766927679276892769927709277192772927739277492775927769277792778927799278092781927829278392784927859278692787927889278992790927919279292793927949279592796927979279892799928009280192802928039280492805928069280792808928099281092811928129281392814928159281692817928189281992820928219282292823928249282592826928279282892829928309283192832928339283492835928369283792838928399284092841928429284392844928459284692847928489284992850928519285292853928549285592856928579285892859928609286192862928639286492865928669286792868928699287092871928729287392874928759287692877928789287992880928819288292883928849288592886928879288892889928909289192892928939289492895928969289792898928999290092901929029290392904929059290692907929089290992910929119291292913929149291592916929179291892919929209292192922929239292492925929269292792928929299293092931929329293392934929359293692937929389293992940929419294292943929449294592946929479294892949929509295192952929539295492955929569295792958929599296092961929629296392964929659296692967929689296992970929719297292973929749297592976929779297892979929809298192982929839298492985929869298792988929899299092991929929299392994929959299692997929989299993000930019300293003930049300593006930079300893009930109301193012930139301493015930169301793018930199302093021930229302393024930259302693027930289302993030930319303293033930349303593036930379303893039930409304193042930439304493045930469304793048930499305093051930529305393054930559305693057930589305993060930619306293063930649306593066930679306893069930709307193072930739307493075930769307793078930799308093081930829308393084930859308693087930889308993090930919309293093930949309593096930979309893099931009310193102931039310493105931069310793108931099311093111931129311393114931159311693117931189311993120931219312293123931249312593126931279312893129931309313193132931339313493135931369313793138931399314093141931429314393144931459314693147931489314993150931519315293153931549315593156931579315893159931609316193162931639316493165931669316793168931699317093171931729317393174931759317693177931789317993180931819318293183931849318593186931879318893189931909319193192931939319493195931969319793198931999320093201932029320393204932059320693207932089320993210932119321293213932149321593216932179321893219932209322193222932239322493225932269322793228932299323093231932329323393234932359323693237932389323993240932419324293243932449324593246932479324893249932509325193252932539325493255932569325793258932599326093261932629326393264932659326693267932689326993270932719327293273932749327593276932779327893279932809328193282932839328493285932869328793288932899329093291932929329393294932959329693297932989329993300933019330293303933049330593306933079330893309933109331193312933139331493315933169331793318933199332093321933229332393324933259332693327933289332993330933319333293333933349333593336933379333893339933409334193342933439334493345933469334793348933499335093351933529335393354933559335693357933589335993360933619336293363933649336593366933679336893369933709337193372933739337493375933769337793378933799338093381933829338393384933859338693387933889338993390933919339293393933949339593396933979339893399934009340193402934039340493405934069340793408934099341093411934129341393414934159341693417934189341993420934219342293423934249342593426934279342893429934309343193432934339343493435934369343793438934399344093441934429344393444934459344693447934489344993450934519345293453934549345593456934579345893459934609346193462934639346493465934669346793468934699347093471934729347393474934759347693477934789347993480934819348293483934849348593486934879348893489934909349193492934939349493495934969349793498934999350093501935029350393504935059350693507935089350993510935119351293513935149351593516935179351893519935209352193522935239352493525935269352793528935299353093531935329353393534935359353693537935389353993540935419354293543935449354593546935479354893549935509355193552935539355493555935569355793558935599356093561935629356393564935659356693567935689356993570935719357293573935749357593576935779357893579935809358193582935839358493585935869358793588935899359093591935929359393594935959359693597935989359993600936019360293603936049360593606936079360893609936109361193612936139361493615936169361793618936199362093621936229362393624936259362693627936289362993630936319363293633936349363593636936379363893639936409364193642936439364493645936469364793648936499365093651936529365393654936559365693657936589365993660936619366293663936649366593666936679366893669936709367193672936739367493675936769367793678936799368093681936829368393684936859368693687936889368993690936919369293693936949369593696936979369893699937009370193702937039370493705937069370793708937099371093711937129371393714937159371693717937189371993720937219372293723937249372593726937279372893729937309373193732937339373493735937369373793738937399374093741937429374393744937459374693747937489374993750937519375293753937549375593756937579375893759937609376193762937639376493765937669376793768937699377093771937729377393774937759377693777937789377993780937819378293783937849378593786937879378893789937909379193792937939379493795937969379793798937999380093801938029380393804938059380693807938089380993810938119381293813938149381593816938179381893819938209382193822938239382493825938269382793828938299383093831938329383393834938359383693837938389383993840938419384293843938449384593846938479384893849938509385193852938539385493855938569385793858938599386093861938629386393864938659386693867938689386993870938719387293873938749387593876938779387893879938809388193882938839388493885938869388793888938899389093891938929389393894938959389693897938989389993900939019390293903939049390593906939079390893909939109391193912939139391493915939169391793918939199392093921939229392393924939259392693927939289392993930939319393293933939349393593936939379393893939939409394193942939439394493945939469394793948939499395093951939529395393954939559395693957939589395993960939619396293963939649396593966939679396893969939709397193972939739397493975939769397793978939799398093981939829398393984939859398693987939889398993990939919399293993939949399593996939979399893999940009400194002940039400494005940069400794008940099401094011940129401394014940159401694017940189401994020940219402294023940249402594026940279402894029940309403194032940339403494035940369403794038940399404094041940429404394044940459404694047940489404994050940519405294053940549405594056940579405894059940609406194062940639406494065940669406794068940699407094071940729407394074940759407694077940789407994080940819408294083940849408594086940879408894089940909409194092940939409494095940969409794098940999410094101941029410394104941059410694107941089410994110941119411294113941149411594116941179411894119941209412194122941239412494125941269412794128941299413094131941329413394134941359413694137941389413994140941419414294143941449414594146941479414894149941509415194152941539415494155941569415794158941599416094161941629416394164941659416694167941689416994170941719417294173941749417594176941779417894179941809418194182941839418494185941869418794188941899419094191941929419394194941959419694197941989419994200942019420294203942049420594206942079420894209942109421194212942139421494215942169421794218942199422094221942229422394224942259422694227942289422994230942319423294233942349423594236942379423894239942409424194242942439424494245942469424794248942499425094251942529425394254942559425694257942589425994260942619426294263942649426594266942679426894269942709427194272942739427494275942769427794278942799428094281942829428394284942859428694287942889428994290942919429294293942949429594296942979429894299943009430194302943039430494305943069430794308943099431094311943129431394314943159431694317943189431994320943219432294323943249432594326943279432894329943309433194332943339433494335943369433794338943399434094341943429434394344943459434694347943489434994350943519435294353943549435594356943579435894359943609436194362943639436494365943669436794368943699437094371943729437394374943759437694377943789437994380943819438294383943849438594386943879438894389943909439194392943939439494395943969439794398943999440094401944029440394404944059440694407944089440994410944119441294413944149441594416944179441894419944209442194422944239442494425944269442794428944299443094431944329443394434944359443694437944389443994440944419444294443944449444594446944479444894449944509445194452944539445494455944569445794458944599446094461944629446394464944659446694467944689446994470944719447294473944749447594476944779447894479944809448194482944839448494485944869448794488944899449094491944929449394494944959449694497944989449994500945019450294503945049450594506945079450894509945109451194512945139451494515945169451794518945199452094521945229452394524945259452694527945289452994530945319453294533945349453594536945379453894539945409454194542945439454494545945469454794548945499455094551945529455394554945559455694557945589455994560945619456294563945649456594566945679456894569945709457194572945739457494575945769457794578945799458094581945829458394584945859458694587945889458994590945919459294593945949459594596945979459894599946009460194602946039460494605946069460794608946099461094611946129461394614946159461694617946189461994620946219462294623946249462594626946279462894629946309463194632946339463494635946369463794638946399464094641946429464394644946459464694647946489464994650946519465294653946549465594656946579465894659946609466194662946639466494665946669466794668946699467094671946729467394674946759467694677946789467994680946819468294683946849468594686946879468894689946909469194692946939469494695946969469794698946999470094701947029470394704947059470694707947089470994710947119471294713947149471594716947179471894719947209472194722947239472494725947269472794728947299473094731947329473394734947359473694737947389473994740947419474294743947449474594746947479474894749947509475194752947539475494755947569475794758947599476094761947629476394764947659476694767947689476994770947719477294773947749477594776947779477894779947809478194782947839478494785947869478794788947899479094791947929479394794947959479694797947989479994800948019480294803948049480594806948079480894809948109481194812948139481494815948169481794818948199482094821948229482394824948259482694827948289482994830948319483294833948349483594836948379483894839948409484194842948439484494845948469484794848948499485094851948529485394854948559485694857948589485994860948619486294863948649486594866948679486894869948709487194872948739487494875948769487794878948799488094881948829488394884948859488694887948889488994890948919489294893948949489594896948979489894899949009490194902949039490494905949069490794908949099491094911949129491394914949159491694917949189491994920949219492294923949249492594926949279492894929949309493194932949339493494935949369493794938949399494094941949429494394944949459494694947949489494994950949519495294953949549495594956949579495894959949609496194962949639496494965949669496794968949699497094971949729497394974949759497694977949789497994980949819498294983949849498594986949879498894989949909499194992949939499494995949969499794998949999500095001950029500395004950059500695007950089500995010950119501295013950149501595016950179501895019950209502195022950239502495025950269502795028950299503095031950329503395034950359503695037950389503995040950419504295043950449504595046950479504895049950509505195052950539505495055950569505795058950599506095061950629506395064950659506695067950689506995070950719507295073950749507595076950779507895079950809508195082950839508495085950869508795088950899509095091950929509395094950959509695097950989509995100951019510295103951049510595106951079510895109951109511195112951139511495115951169511795118951199512095121951229512395124951259512695127951289512995130951319513295133951349513595136951379513895139951409514195142951439514495145951469514795148951499515095151951529515395154951559515695157951589515995160951619516295163951649516595166951679516895169951709517195172951739517495175951769517795178951799518095181951829518395184951859518695187951889518995190951919519295193951949519595196951979519895199952009520195202952039520495205952069520795208952099521095211952129521395214952159521695217952189521995220952219522295223952249522595226952279522895229952309523195232952339523495235952369523795238952399524095241952429524395244952459524695247952489524995250952519525295253952549525595256952579525895259952609526195262952639526495265952669526795268952699527095271952729527395274952759527695277952789527995280952819528295283952849528595286952879528895289952909529195292952939529495295952969529795298952999530095301953029530395304953059530695307953089530995310953119531295313953149531595316953179531895319953209532195322953239532495325953269532795328953299533095331953329533395334953359533695337953389533995340953419534295343953449534595346953479534895349953509535195352953539535495355953569535795358953599536095361953629536395364953659536695367953689536995370953719537295373953749537595376953779537895379953809538195382953839538495385953869538795388953899539095391953929539395394953959539695397953989539995400954019540295403954049540595406954079540895409954109541195412954139541495415954169541795418954199542095421954229542395424954259542695427954289542995430954319543295433954349543595436954379543895439954409544195442954439544495445954469544795448954499545095451954529545395454954559545695457954589545995460954619546295463954649546595466954679546895469954709547195472954739547495475954769547795478954799548095481954829548395484954859548695487954889548995490954919549295493954949549595496954979549895499955009550195502955039550495505955069550795508955099551095511955129551395514955159551695517955189551995520955219552295523955249552595526955279552895529955309553195532955339553495535955369553795538955399554095541955429554395544955459554695547955489554995550955519555295553955549555595556955579555895559955609556195562955639556495565955669556795568955699557095571955729557395574955759557695577955789557995580955819558295583955849558595586955879558895589955909559195592955939559495595955969559795598955999560095601956029560395604956059560695607956089560995610956119561295613956149561595616956179561895619956209562195622956239562495625956269562795628956299563095631956329563395634956359563695637956389563995640956419564295643956449564595646956479564895649956509565195652956539565495655956569565795658956599566095661956629566395664956659566695667956689566995670956719567295673956749567595676956779567895679956809568195682956839568495685956869568795688956899569095691956929569395694956959569695697956989569995700957019570295703957049570595706957079570895709957109571195712957139571495715957169571795718957199572095721957229572395724957259572695727957289572995730957319573295733957349573595736957379573895739957409574195742957439574495745957469574795748957499575095751957529575395754957559575695757957589575995760957619576295763957649576595766957679576895769957709577195772957739577495775957769577795778957799578095781957829578395784957859578695787957889578995790957919579295793957949579595796957979579895799958009580195802958039580495805958069580795808958099581095811958129581395814958159581695817958189581995820958219582295823958249582595826958279582895829958309583195832958339583495835958369583795838958399584095841958429584395844958459584695847958489584995850958519585295853958549585595856958579585895859958609586195862958639586495865958669586795868958699587095871958729587395874958759587695877958789587995880958819588295883958849588595886958879588895889958909589195892958939589495895958969589795898958999590095901959029590395904959059590695907959089590995910959119591295913959149591595916959179591895919959209592195922959239592495925959269592795928959299593095931959329593395934959359593695937959389593995940959419594295943959449594595946959479594895949959509595195952959539595495955959569595795958959599596095961959629596395964959659596695967959689596995970959719597295973959749597595976959779597895979959809598195982959839598495985959869598795988959899599095991959929599395994959959599695997959989599996000960019600296003960049600596006960079600896009960109601196012960139601496015960169601796018960199602096021960229602396024960259602696027960289602996030960319603296033960349603596036960379603896039960409604196042960439604496045960469604796048960499605096051960529605396054960559605696057960589605996060960619606296063960649606596066960679606896069960709607196072960739607496075960769607796078960799608096081960829608396084960859608696087960889608996090960919609296093960949609596096960979609896099961009610196102961039610496105961069610796108961099611096111961129611396114961159611696117961189611996120961219612296123961249612596126961279612896129961309613196132961339613496135961369613796138961399614096141961429614396144961459614696147961489614996150961519615296153961549615596156961579615896159961609616196162961639616496165961669616796168961699617096171961729617396174961759617696177961789617996180961819618296183961849618596186961879618896189961909619196192961939619496195961969619796198961999620096201962029620396204962059620696207962089620996210962119621296213962149621596216962179621896219962209622196222962239622496225962269622796228962299623096231962329623396234962359623696237962389623996240962419624296243962449624596246962479624896249962509625196252962539625496255962569625796258962599626096261962629626396264962659626696267962689626996270962719627296273962749627596276962779627896279962809628196282962839628496285962869628796288962899629096291962929629396294962959629696297962989629996300963019630296303963049630596306963079630896309963109631196312963139631496315963169631796318963199632096321963229632396324963259632696327963289632996330963319633296333963349633596336963379633896339963409634196342963439634496345963469634796348963499635096351963529635396354963559635696357963589635996360963619636296363963649636596366963679636896369963709637196372963739637496375963769637796378963799638096381963829638396384963859638696387963889638996390963919639296393963949639596396963979639896399964009640196402964039640496405964069640796408964099641096411964129641396414964159641696417964189641996420964219642296423964249642596426964279642896429964309643196432964339643496435964369643796438964399644096441964429644396444964459644696447964489644996450964519645296453964549645596456964579645896459964609646196462964639646496465964669646796468964699647096471964729647396474964759647696477964789647996480964819648296483964849648596486964879648896489964909649196492964939649496495964969649796498964999650096501965029650396504965059650696507965089650996510965119651296513965149651596516965179651896519965209652196522965239652496525965269652796528965299653096531965329653396534965359653696537965389653996540965419654296543965449654596546965479654896549965509655196552965539655496555965569655796558965599656096561965629656396564965659656696567965689656996570965719657296573965749657596576965779657896579965809658196582965839658496585965869658796588965899659096591965929659396594965959659696597965989659996600966019660296603966049660596606966079660896609966109661196612966139661496615966169661796618966199662096621966229662396624966259662696627966289662996630966319663296633966349663596636966379663896639966409664196642966439664496645966469664796648966499665096651966529665396654966559665696657966589665996660966619666296663966649666596666966679666896669966709667196672966739667496675966769667796678966799668096681966829668396684966859668696687966889668996690966919669296693966949669596696966979669896699967009670196702967039670496705967069670796708967099671096711967129671396714967159671696717967189671996720967219672296723967249672596726967279672896729967309673196732967339673496735967369673796738967399674096741967429674396744967459674696747967489674996750967519675296753967549675596756967579675896759967609676196762967639676496765967669676796768967699677096771967729677396774967759677696777967789677996780967819678296783967849678596786967879678896789967909679196792967939679496795967969679796798967999680096801968029680396804968059680696807968089680996810968119681296813968149681596816968179681896819968209682196822968239682496825968269682796828968299683096831968329683396834968359683696837968389683996840968419684296843968449684596846968479684896849968509685196852968539685496855968569685796858968599686096861968629686396864968659686696867968689686996870968719687296873968749687596876968779687896879968809688196882968839688496885968869688796888968899689096891968929689396894968959689696897968989689996900969019690296903969049690596906969079690896909969109691196912969139691496915969169691796918969199692096921969229692396924969259692696927969289692996930969319693296933969349693596936969379693896939969409694196942969439694496945969469694796948969499695096951969529695396954969559695696957969589695996960969619696296963969649696596966969679696896969969709697196972969739697496975969769697796978969799698096981969829698396984969859698696987969889698996990969919699296993969949699596996969979699896999970009700197002970039700497005970069700797008970099701097011970129701397014970159701697017970189701997020970219702297023970249702597026970279702897029970309703197032970339703497035970369703797038970399704097041970429704397044970459704697047970489704997050970519705297053970549705597056970579705897059970609706197062970639706497065970669706797068970699707097071970729707397074970759707697077970789707997080970819708297083970849708597086970879708897089970909709197092970939709497095970969709797098970999710097101971029710397104971059710697107971089710997110971119711297113971149711597116971179711897119971209712197122971239712497125971269712797128971299713097131971329713397134971359713697137971389713997140971419714297143971449714597146971479714897149971509715197152971539715497155971569715797158971599716097161971629716397164971659716697167971689716997170971719717297173971749717597176971779717897179971809718197182971839718497185971869718797188971899719097191971929719397194971959719697197971989719997200972019720297203972049720597206972079720897209972109721197212972139721497215972169721797218972199722097221972229722397224972259722697227972289722997230972319723297233972349723597236972379723897239972409724197242972439724497245972469724797248972499725097251972529725397254972559725697257972589725997260972619726297263972649726597266972679726897269972709727197272972739727497275972769727797278972799728097281972829728397284972859728697287972889728997290972919729297293972949729597296972979729897299973009730197302973039730497305973069730797308973099731097311973129731397314973159731697317973189731997320973219732297323973249732597326973279732897329973309733197332973339733497335973369733797338973399734097341973429734397344973459734697347973489734997350973519735297353973549735597356973579735897359973609736197362973639736497365973669736797368973699737097371973729737397374973759737697377973789737997380973819738297383973849738597386973879738897389973909739197392973939739497395973969739797398973999740097401974029740397404974059740697407974089740997410974119741297413974149741597416974179741897419974209742197422974239742497425974269742797428974299743097431974329743397434974359743697437974389743997440974419744297443974449744597446974479744897449974509745197452974539745497455974569745797458974599746097461974629746397464974659746697467974689746997470974719747297473974749747597476974779747897479974809748197482974839748497485974869748797488974899749097491974929749397494974959749697497974989749997500975019750297503975049750597506975079750897509975109751197512975139751497515975169751797518975199752097521975229752397524975259752697527975289752997530975319753297533975349753597536975379753897539975409754197542975439754497545975469754797548975499755097551975529755397554975559755697557975589755997560975619756297563975649756597566975679756897569975709757197572975739757497575975769757797578975799758097581975829758397584975859758697587975889758997590975919759297593975949759597596975979759897599976009760197602976039760497605976069760797608976099761097611976129761397614976159761697617976189761997620976219762297623976249762597626976279762897629976309763197632976339763497635976369763797638976399764097641976429764397644976459764697647976489764997650976519765297653976549765597656976579765897659976609766197662976639766497665976669766797668976699767097671976729767397674976759767697677976789767997680976819768297683976849768597686976879768897689976909769197692976939769497695976969769797698976999770097701977029770397704977059770697707977089770997710977119771297713977149771597716977179771897719977209772197722977239772497725977269772797728977299773097731977329773397734977359773697737977389773997740977419774297743977449774597746977479774897749977509775197752977539775497755977569775797758977599776097761977629776397764977659776697767977689776997770977719777297773977749777597776977779777897779977809778197782977839778497785977869778797788977899779097791977929779397794977959779697797977989779997800978019780297803978049780597806978079780897809978109781197812978139781497815978169781797818978199782097821978229782397824978259782697827978289782997830978319783297833978349783597836978379783897839978409784197842978439784497845978469784797848978499785097851978529785397854978559785697857978589785997860978619786297863978649786597866978679786897869978709787197872978739787497875978769787797878978799788097881978829788397884978859788697887978889788997890978919789297893978949789597896978979789897899979009790197902979039790497905979069790797908979099791097911979129791397914979159791697917979189791997920979219792297923979249792597926979279792897929979309793197932979339793497935979369793797938979399794097941979429794397944979459794697947979489794997950979519795297953979549795597956979579795897959979609796197962979639796497965979669796797968979699797097971979729797397974979759797697977979789797997980979819798297983979849798597986979879798897989979909799197992979939799497995979969799797998979999800098001980029800398004980059800698007980089800998010980119801298013980149801598016980179801898019980209802198022980239802498025980269802798028980299803098031980329803398034980359803698037980389803998040980419804298043980449804598046980479804898049980509805198052980539805498055980569805798058980599806098061980629806398064980659806698067980689806998070980719807298073980749807598076980779807898079980809808198082980839808498085980869808798088980899809098091980929809398094980959809698097980989809998100981019810298103981049810598106981079810898109981109811198112981139811498115981169811798118981199812098121981229812398124981259812698127981289812998130981319813298133981349813598136981379813898139981409814198142981439814498145981469814798148981499815098151981529815398154981559815698157981589815998160981619816298163981649816598166981679816898169981709817198172981739817498175981769817798178981799818098181981829818398184981859818698187981889818998190981919819298193981949819598196981979819898199982009820198202982039820498205982069820798208982099821098211982129821398214982159821698217982189821998220982219822298223982249822598226982279822898229982309823198232982339823498235982369823798238982399824098241982429824398244982459824698247982489824998250982519825298253982549825598256982579825898259982609826198262982639826498265982669826798268982699827098271982729827398274982759827698277982789827998280982819828298283982849828598286982879828898289982909829198292982939829498295982969829798298982999830098301983029830398304983059830698307983089830998310983119831298313983149831598316983179831898319983209832198322983239832498325983269832798328983299833098331983329833398334983359833698337983389833998340983419834298343983449834598346983479834898349983509835198352983539835498355983569835798358983599836098361983629836398364983659836698367983689836998370983719837298373983749837598376983779837898379983809838198382983839838498385983869838798388983899839098391983929839398394983959839698397983989839998400984019840298403984049840598406984079840898409984109841198412984139841498415984169841798418984199842098421984229842398424984259842698427984289842998430984319843298433984349843598436984379843898439984409844198442984439844498445984469844798448984499845098451984529845398454984559845698457984589845998460984619846298463984649846598466984679846898469984709847198472984739847498475984769847798478984799848098481984829848398484984859848698487984889848998490984919849298493984949849598496984979849898499985009850198502985039850498505985069850798508985099851098511985129851398514985159851698517985189851998520985219852298523985249852598526985279852898529985309853198532985339853498535985369853798538985399854098541985429854398544985459854698547985489854998550985519855298553985549855598556985579855898559985609856198562985639856498565985669856798568985699857098571985729857398574985759857698577985789857998580985819858298583985849858598586985879858898589985909859198592985939859498595985969859798598985999860098601986029860398604986059860698607986089860998610986119861298613986149861598616986179861898619986209862198622986239862498625986269862798628986299863098631986329863398634986359863698637986389863998640986419864298643986449864598646986479864898649986509865198652986539865498655986569865798658986599866098661986629866398664986659866698667986689866998670986719867298673986749867598676986779867898679986809868198682986839868498685986869868798688986899869098691986929869398694986959869698697986989869998700987019870298703987049870598706987079870898709987109871198712987139871498715987169871798718987199872098721987229872398724987259872698727987289872998730987319873298733987349873598736987379873898739987409874198742987439874498745987469874798748987499875098751987529875398754987559875698757987589875998760987619876298763987649876598766987679876898769987709877198772987739877498775987769877798778987799878098781987829878398784987859878698787987889878998790987919879298793987949879598796987979879898799988009880198802988039880498805988069880798808988099881098811988129881398814988159881698817988189881998820988219882298823988249882598826988279882898829988309883198832988339883498835988369883798838988399884098841988429884398844988459884698847988489884998850988519885298853988549885598856988579885898859988609886198862988639886498865988669886798868988699887098871988729887398874988759887698877988789887998880988819888298883988849888598886988879888898889988909889198892988939889498895988969889798898988999890098901989029890398904989059890698907989089890998910989119891298913989149891598916989179891898919989209892198922989239892498925989269892798928989299893098931989329893398934989359893698937989389893998940989419894298943989449894598946989479894898949989509895198952989539895498955989569895798958989599896098961989629896398964989659896698967989689896998970989719897298973989749897598976989779897898979989809898198982989839898498985989869898798988989899899098991989929899398994989959899698997989989899999000990019900299003990049900599006990079900899009990109901199012990139901499015990169901799018990199902099021990229902399024990259902699027990289902999030990319903299033990349903599036990379903899039990409904199042990439904499045990469904799048990499905099051990529905399054990559905699057990589905999060990619906299063990649906599066990679906899069990709907199072990739907499075990769907799078990799908099081990829908399084990859908699087990889908999090990919909299093990949909599096990979909899099991009910199102991039910499105991069910799108991099911099111991129911399114991159911699117991189911999120991219912299123991249912599126991279912899129991309913199132991339913499135991369913799138991399914099141991429914399144991459914699147991489914999150991519915299153991549915599156991579915899159991609916199162991639916499165991669916799168991699917099171991729917399174991759917699177991789917999180991819918299183991849918599186991879918899189991909919199192991939919499195991969919799198991999920099201992029920399204992059920699207992089920999210992119921299213992149921599216992179921899219992209922199222992239922499225992269922799228992299923099231992329923399234992359923699237992389923999240992419924299243992449924599246992479924899249992509925199252992539925499255992569925799258992599926099261992629926399264992659926699267992689926999270992719927299273992749927599276992779927899279992809928199282992839928499285992869928799288992899929099291992929929399294992959929699297992989929999300993019930299303993049930599306993079930899309993109931199312993139931499315993169931799318993199932099321993229932399324993259932699327993289932999330993319933299333993349933599336993379933899339993409934199342993439934499345993469934799348993499935099351993529935399354993559935699357993589935999360993619936299363993649936599366993679936899369993709937199372993739937499375993769937799378993799938099381993829938399384993859938699387993889938999390993919939299393993949939599396993979939899399994009940199402994039940499405994069940799408994099941099411994129941399414994159941699417994189941999420994219942299423994249942599426994279942899429994309943199432994339943499435994369943799438994399944099441994429944399444994459944699447994489944999450994519945299453994549945599456994579945899459994609946199462994639946499465994669946799468994699947099471994729947399474994759947699477994789947999480994819948299483994849948599486994879948899489994909949199492994939949499495994969949799498994999950099501995029950399504995059950699507995089950999510995119951299513995149951599516995179951899519995209952199522995239952499525995269952799528995299953099531995329953399534995359953699537995389953999540995419954299543995449954599546995479954899549995509955199552995539955499555995569955799558995599956099561995629956399564995659956699567995689956999570995719957299573995749957599576995779957899579995809958199582995839958499585995869958799588995899959099591995929959399594995959959699597995989959999600996019960299603996049960599606996079960899609996109961199612996139961499615996169961799618996199962099621996229962399624996259962699627996289962999630996319963299633996349963599636996379963899639996409964199642996439964499645996469964799648996499965099651996529965399654996559965699657996589965999660996619966299663996649966599666996679966899669996709967199672996739967499675996769967799678996799968099681996829968399684996859968699687996889968999690996919969299693996949969599696996979969899699997009970199702997039970499705997069970799708997099971099711997129971399714997159971699717997189971999720997219972299723997249972599726997279972899729997309973199732997339973499735997369973799738997399974099741997429974399744997459974699747997489974999750997519975299753997549975599756997579975899759997609976199762997639976499765997669976799768997699977099771997729977399774997759977699777997789977999780997819978299783997849978599786997879978899789997909979199792997939979499795997969979799798997999980099801998029980399804998059980699807998089980999810998119981299813998149981599816998179981899819998209982199822998239982499825998269982799828998299983099831998329983399834998359983699837998389983999840998419984299843998449984599846998479984899849998509985199852998539985499855998569985799858998599986099861998629986399864998659986699867998689986999870998719987299873998749987599876998779987899879998809988199882998839988499885998869988799888998899989099891998929989399894998959989699897998989989999900999019990299903999049990599906999079990899909999109991199912999139991499915999169991799918999199992099921999229992399924999259992699927999289992999930999319993299933999349993599936999379993899939999409994199942999439994499945999469994799948999499995099951999529995399954999559995699957999589995999960999619996299963999649996599966999679996899969999709997199972999739997499975999769997799978999799998099981999829998399984999859998699987999889998999990999919999299993999949999599996999979999899999100000100001100002100003100004100005100006100007100008100009100010100011100012100013100014100015100016100017100018100019100020100021100022100023100024100025100026100027100028100029100030100031100032100033100034100035100036100037100038100039100040100041100042100043100044100045100046100047100048100049100050100051100052100053100054100055100056100057100058100059100060100061100062100063100064100065100066100067100068100069100070100071100072100073100074100075100076100077100078100079100080100081100082100083100084100085100086100087100088100089100090100091100092100093100094100095100096100097100098100099100100100101100102100103100104100105100106100107100108100109100110100111100112100113100114100115100116100117100118100119100120100121100122100123100124100125100126100127100128100129100130100131100132100133100134100135100136100137100138100139100140100141100142100143100144100145100146100147100148100149100150100151100152100153100154100155100156100157100158100159100160100161100162100163100164100165100166100167100168100169100170100171100172100173100174100175100176100177100178100179100180100181100182100183100184100185100186100187100188100189100190100191100192100193100194100195100196100197100198100199100200100201100202100203100204100205100206100207100208100209100210100211100212100213100214100215100216100217100218100219100220100221100222100223100224100225100226100227100228100229100230100231100232100233100234100235100236100237100238100239100240100241100242100243100244100245100246100247100248100249100250100251100252100253100254100255100256100257100258100259100260100261100262100263100264100265100266100267100268100269100270100271100272100273100274100275100276100277100278100279100280100281100282100283100284100285100286100287100288100289100290100291100292100293100294100295100296100297100298100299100300100301100302100303100304100305100306100307100308100309100310100311100312100313100314100315100316100317100318100319100320100321100322100323100324100325100326100327100328100329100330100331100332100333100334100335100336100337100338100339100340100341100342100343100344100345100346100347100348100349100350100351100352100353100354100355100356100357100358100359100360100361100362100363100364100365100366100367100368100369100370100371100372100373100374100375100376100377100378100379100380100381100382100383100384100385100386100387100388100389100390100391100392100393100394100395100396100397100398100399100400100401100402100403100404100405100406100407100408100409100410100411100412100413100414100415100416100417100418100419100420100421100422100423100424100425100426100427100428100429100430100431100432100433100434100435100436100437100438100439100440100441100442100443100444100445100446100447100448100449100450100451100452100453100454100455100456100457100458100459100460100461100462100463100464100465100466100467100468100469100470100471100472100473100474100475100476100477100478100479100480100481100482100483100484100485100486100487100488100489100490100491100492100493100494100495100496100497100498100499100500100501100502100503100504100505100506100507100508100509100510100511100512100513100514100515100516100517100518100519100520100521100522100523100524100525100526100527100528100529100530100531100532100533100534100535100536100537100538100539100540100541100542100543100544100545100546100547100548100549100550100551100552100553100554100555100556100557100558100559100560100561100562100563100564100565100566100567100568100569100570100571100572100573100574100575100576100577100578100579100580100581100582100583100584100585100586100587100588100589100590100591100592100593100594100595100596100597100598100599100600100601100602100603100604100605100606100607100608100609100610100611100612100613100614100615100616100617100618100619100620100621100622100623100624100625100626100627100628100629100630100631100632100633100634100635100636100637100638100639100640100641100642100643100644100645100646100647100648100649100650100651100652100653100654100655100656100657100658100659100660100661100662100663100664100665100666100667100668100669100670100671100672100673100674100675100676100677100678100679100680100681100682100683100684100685100686100687100688100689100690100691100692100693100694100695100696100697100698100699100700100701100702100703100704100705100706100707100708100709100710100711100712100713100714100715100716100717100718100719100720100721100722100723100724100725100726100727100728100729100730100731100732100733100734100735100736100737100738100739100740100741100742100743100744100745100746100747100748100749100750100751100752100753100754100755100756100757100758100759100760100761100762100763100764100765100766100767100768100769100770100771100772100773100774100775100776100777100778100779100780100781100782100783100784100785100786100787100788100789100790100791100792100793100794100795100796100797100798100799100800100801100802100803100804100805100806100807100808100809100810100811100812100813100814100815100816100817100818100819100820100821100822100823100824100825100826100827100828100829100830100831100832100833100834100835100836100837100838100839100840100841100842100843100844100845100846100847100848100849100850100851100852100853100854100855100856100857100858100859100860100861100862100863100864100865100866100867100868100869100870100871100872100873100874100875100876100877100878100879100880100881100882100883100884100885100886100887100888100889100890100891100892100893100894100895100896100897100898100899100900100901100902100903100904100905100906100907100908100909100910100911100912100913100914100915100916100917100918100919100920100921100922100923100924100925100926100927100928100929100930100931100932100933100934100935100936100937100938100939100940100941100942100943100944100945100946100947100948100949100950100951100952100953100954100955100956100957100958100959100960100961100962100963100964100965100966100967100968100969100970100971100972100973100974100975100976100977100978100979100980100981100982100983100984100985100986100987100988100989100990100991100992100993100994100995100996100997100998100999101000101001101002101003101004101005101006101007101008101009101010101011101012101013101014101015101016101017101018101019101020101021101022101023101024101025101026101027101028101029101030101031101032101033101034101035101036101037101038101039101040101041101042101043101044101045101046101047101048101049101050101051101052101053101054101055101056101057101058101059101060101061101062101063101064101065101066101067101068101069101070101071101072101073101074101075101076101077101078101079101080101081101082101083101084101085101086101087101088101089101090101091101092101093101094101095101096101097101098101099101100101101101102101103101104101105101106101107101108101109101110101111101112101113101114101115101116101117101118101119101120101121101122101123101124101125101126101127101128101129101130101131101132101133101134101135101136101137101138101139101140101141101142101143101144101145101146101147101148101149101150101151101152101153101154101155101156101157101158101159101160101161101162101163101164101165101166101167101168101169101170101171101172101173101174101175101176101177101178101179101180101181101182101183101184101185101186101187101188101189101190101191101192101193101194101195101196101197101198101199101200101201101202101203101204101205101206101207101208101209101210101211101212101213101214101215101216101217101218101219101220101221101222101223101224101225101226101227101228101229101230101231101232101233101234101235101236101237101238101239101240101241101242101243101244101245101246101247101248101249101250101251101252101253101254101255101256101257101258101259101260101261101262101263101264101265101266101267101268101269101270101271101272101273101274101275101276101277101278101279101280101281101282101283101284101285101286101287101288101289101290101291101292101293101294101295101296101297101298101299101300101301101302101303101304101305101306101307101308101309101310101311101312101313101314101315101316101317101318101319101320101321101322101323101324101325101326101327101328101329101330101331101332101333101334101335101336101337101338101339101340101341101342101343101344101345101346101347101348101349101350101351101352101353101354101355101356101357101358101359101360101361101362101363101364101365101366101367101368101369101370101371101372101373101374101375101376101377101378101379101380101381101382101383101384101385101386101387101388101389101390101391101392101393101394101395101396101397101398101399101400101401101402101403101404101405101406101407101408101409101410101411101412101413101414101415101416101417101418101419101420101421101422101423101424101425101426101427101428101429101430101431101432101433101434101435101436101437101438101439101440101441101442101443101444101445101446101447101448101449101450101451101452101453101454101455101456101457101458101459101460101461101462101463101464101465101466101467101468101469101470101471101472101473101474101475101476101477101478101479101480101481101482101483101484101485101486101487101488101489101490101491101492101493101494101495101496101497101498101499101500101501101502101503101504101505101506101507101508101509101510101511101512101513101514101515101516101517101518101519101520101521101522101523101524101525101526101527101528101529101530101531101532101533101534101535101536101537101538101539101540101541101542101543101544101545101546101547101548101549101550101551101552101553101554101555101556101557101558101559101560101561101562101563101564101565101566101567101568101569101570101571101572101573101574101575101576101577101578101579101580101581101582101583101584101585101586101587101588101589101590101591101592101593101594101595101596101597101598101599101600101601101602101603101604101605101606101607101608101609101610101611101612101613101614101615101616101617101618101619101620101621101622101623101624101625101626101627101628101629101630101631101632101633101634101635101636101637101638101639101640101641101642101643101644101645101646101647101648101649101650101651101652101653101654101655101656101657101658101659101660101661101662101663101664101665101666101667101668101669101670101671101672101673101674101675101676101677101678101679101680101681101682101683101684101685101686101687101688101689101690101691101692101693101694101695101696101697101698101699101700101701101702101703101704101705101706101707101708101709101710101711101712101713101714101715101716101717101718101719101720101721101722101723101724101725101726101727101728101729101730101731101732101733101734101735101736101737101738101739101740101741101742101743101744101745101746101747101748101749101750101751101752101753101754101755101756101757101758101759101760101761101762101763101764101765101766101767101768101769101770101771101772101773101774101775101776101777101778101779101780101781101782101783101784101785101786101787101788101789101790101791101792101793101794101795101796101797101798101799101800101801101802101803101804101805101806101807101808101809101810101811101812101813101814101815101816101817101818101819101820101821101822101823101824101825101826101827101828101829101830101831101832101833101834101835101836101837101838101839101840101841101842101843101844101845101846101847101848101849101850101851101852101853101854101855101856101857101858101859101860101861101862101863101864101865101866101867101868101869101870101871101872101873101874101875101876101877101878101879101880101881101882101883101884101885101886101887101888101889101890101891101892101893101894101895101896101897101898101899101900101901101902101903101904101905101906101907101908101909101910101911101912101913101914101915101916101917101918101919101920101921101922101923101924101925101926101927101928101929101930101931101932101933101934101935101936101937101938101939101940101941101942101943101944101945101946101947101948101949101950101951101952101953101954101955101956101957101958101959101960101961101962101963101964101965101966101967101968101969101970101971101972101973101974101975101976101977101978101979101980101981101982101983101984101985101986101987101988101989101990101991101992101993101994101995101996101997101998101999102000102001102002102003102004102005102006102007102008102009102010102011102012102013102014102015102016102017102018102019102020102021102022102023102024102025102026102027102028102029102030102031102032102033102034102035102036102037102038102039102040102041102042102043102044102045102046102047102048102049102050102051102052102053102054102055102056102057102058102059102060102061102062102063102064102065102066102067102068102069102070102071102072102073102074102075102076102077102078102079102080102081102082102083102084102085102086102087102088102089102090102091102092102093102094102095102096102097102098102099102100102101102102102103102104102105102106102107102108102109102110102111102112102113102114102115102116102117102118102119102120102121102122102123102124102125102126102127102128102129102130102131102132102133102134102135102136102137102138102139102140102141102142102143102144102145102146102147102148102149102150102151102152102153102154102155102156102157102158102159102160102161102162102163102164102165102166102167102168102169102170102171102172102173102174102175102176102177102178102179102180102181102182102183102184102185102186102187102188102189102190102191102192102193102194102195102196102197102198102199102200102201102202102203102204102205102206102207102208102209102210102211102212102213102214102215102216102217102218102219102220102221102222102223102224102225102226102227102228102229102230102231102232102233102234102235102236102237102238102239102240102241102242102243102244102245102246102247102248102249102250102251102252102253102254102255102256102257102258102259102260102261102262102263102264102265102266102267102268102269102270102271102272102273102274102275102276102277102278102279102280102281102282102283102284102285102286102287102288102289102290102291102292102293102294102295102296102297102298102299102300102301102302102303102304102305102306102307102308102309102310102311102312102313102314102315102316102317102318102319102320102321102322102323102324102325102326102327102328102329102330102331102332102333102334102335102336102337102338102339102340102341102342102343102344102345102346102347102348102349102350102351102352102353102354102355102356102357102358102359102360102361102362102363102364102365102366102367102368102369102370102371102372102373102374102375102376102377102378102379102380102381102382102383102384102385102386102387102388102389102390102391102392102393102394102395102396102397102398102399102400102401102402102403102404102405102406102407102408102409102410102411102412102413102414102415102416102417102418102419102420102421102422102423102424102425102426102427102428102429102430102431102432102433102434102435102436102437102438102439102440102441102442102443102444102445102446102447102448102449102450102451102452102453102454102455102456102457102458102459102460102461102462102463102464102465102466102467102468102469102470102471102472102473102474102475102476102477102478102479102480102481102482102483102484102485102486102487102488102489102490102491102492102493102494102495102496102497102498102499102500102501102502102503102504102505102506102507102508102509102510102511102512102513102514102515102516102517102518102519102520102521102522102523102524102525102526102527102528102529102530102531102532102533102534102535102536102537102538102539102540102541102542102543102544102545102546102547102548102549102550102551102552102553102554102555102556102557102558102559102560102561102562102563102564102565102566102567102568102569102570102571102572102573102574102575102576102577102578102579102580102581102582102583102584102585102586102587102588102589102590102591102592102593102594102595102596102597102598102599102600102601102602102603102604102605102606102607102608102609102610102611102612102613102614102615102616102617102618102619102620102621102622102623102624102625102626102627102628102629102630102631102632102633102634102635102636102637102638102639102640102641102642102643102644102645102646102647102648102649102650102651102652102653102654102655102656102657102658102659102660102661102662102663102664102665102666102667102668102669102670102671102672102673102674102675102676102677102678102679102680102681102682102683102684102685102686102687102688102689102690102691102692102693102694102695102696102697102698102699102700102701102702102703102704102705102706102707102708102709102710102711102712102713102714102715102716102717102718102719102720102721102722102723102724102725102726102727102728102729102730102731102732102733102734102735102736102737102738102739102740102741102742102743102744102745102746102747102748102749102750102751102752102753102754102755102756102757102758102759102760102761102762102763102764102765102766102767102768102769102770102771102772102773102774102775102776102777102778102779102780102781102782102783102784102785102786102787102788102789102790102791102792102793102794102795102796102797102798102799102800102801102802102803102804102805102806102807102808102809102810102811102812102813102814102815102816102817102818102819102820102821102822102823102824102825102826102827102828102829102830102831102832102833102834102835102836102837102838102839102840102841102842102843102844102845102846102847102848102849102850102851102852102853102854102855102856102857102858102859102860102861102862102863102864102865102866102867102868102869102870102871102872102873102874102875102876102877102878102879102880102881102882102883102884102885102886102887102888102889102890102891102892102893102894102895102896102897102898102899102900102901102902102903102904102905102906102907102908102909102910102911102912102913102914102915102916102917102918102919102920102921102922102923102924102925102926102927102928102929102930102931102932102933102934102935102936102937102938102939102940102941102942102943102944102945102946102947102948102949102950102951102952102953102954102955102956102957102958102959102960102961102962102963102964102965102966102967102968102969102970102971102972102973102974102975102976102977102978102979102980102981102982102983102984102985102986102987102988102989102990102991102992102993102994102995102996102997102998102999103000103001103002103003103004103005103006103007103008103009103010103011103012103013103014103015103016103017103018103019103020103021103022103023103024103025103026103027103028103029103030103031103032103033103034103035103036103037103038103039103040103041103042103043103044103045103046103047103048103049103050103051103052103053103054103055103056103057103058103059103060103061103062103063103064103065103066103067103068103069103070103071103072103073103074103075103076103077103078103079103080103081103082103083103084103085103086103087103088103089103090103091103092103093103094103095103096103097103098103099103100103101103102103103103104103105103106103107103108103109103110103111103112103113103114103115103116103117103118103119103120103121103122103123103124103125103126103127103128103129103130103131103132103133103134103135103136103137103138103139103140103141103142103143103144103145103146103147103148103149103150103151103152103153103154103155103156103157103158103159103160103161103162103163103164103165103166103167103168103169103170103171103172103173103174103175103176103177103178103179103180103181103182103183103184103185103186103187103188103189103190103191103192103193103194103195103196103197103198103199103200103201103202103203103204103205103206103207103208103209103210103211103212103213103214103215103216103217103218103219103220103221103222103223103224103225103226103227103228103229103230103231103232103233103234103235103236103237103238103239103240103241103242103243103244103245103246103247103248103249103250103251103252103253103254103255103256103257103258103259103260103261103262103263103264103265103266103267103268103269103270103271103272103273103274103275103276103277103278103279103280103281103282103283103284103285103286103287103288103289103290103291103292103293103294103295103296103297103298103299103300103301103302103303103304103305103306103307103308103309103310103311103312103313103314103315103316103317103318103319103320103321103322103323103324103325103326103327103328103329103330103331103332103333103334103335103336103337103338103339103340103341103342103343103344103345103346103347103348103349103350103351103352103353103354103355103356103357103358103359103360103361103362103363103364103365103366103367103368103369103370103371103372103373103374103375103376103377103378103379103380103381103382103383103384103385103386103387103388103389103390103391103392103393103394103395103396103397103398103399103400103401103402103403103404103405103406103407103408103409103410103411103412103413103414103415103416103417103418103419103420103421103422103423103424103425103426103427103428103429103430103431103432103433103434103435103436103437103438103439103440103441103442103443103444103445103446103447103448103449103450103451103452103453103454103455103456103457103458103459103460103461103462103463103464103465103466103467103468103469103470103471103472103473103474103475103476103477103478103479103480103481103482103483103484103485103486103487103488103489103490103491103492103493103494103495103496103497103498103499103500103501103502103503103504103505103506103507103508103509103510103511103512103513103514103515103516103517103518103519103520103521103522103523103524103525103526103527103528103529103530103531103532103533103534103535103536103537103538103539103540103541103542103543103544103545103546103547103548103549103550103551103552103553103554103555103556103557103558103559103560103561103562103563103564103565103566103567103568103569103570103571103572103573103574103575103576103577103578103579103580103581103582103583103584103585103586103587103588103589103590103591103592103593103594103595103596103597103598103599103600103601103602103603103604103605103606103607103608103609103610103611103612103613103614103615103616103617103618103619103620103621103622103623103624103625103626103627103628103629103630103631103632103633103634103635103636103637103638103639103640103641103642103643103644103645103646103647103648103649103650103651103652103653103654103655103656103657103658103659103660103661103662103663103664103665103666103667103668103669103670103671103672103673103674103675103676103677103678103679103680103681103682103683103684103685103686103687103688103689103690103691103692103693103694103695103696103697103698103699103700103701103702103703103704103705103706103707103708103709103710103711103712103713103714103715103716103717103718103719103720103721103722103723103724103725103726103727103728103729103730103731103732103733103734103735103736103737103738103739103740103741103742103743103744103745103746103747103748103749103750103751103752103753103754103755103756103757103758103759103760103761103762103763103764103765103766103767103768103769103770103771103772103773103774103775103776103777103778103779103780103781103782103783103784103785103786103787103788103789103790103791103792103793103794103795103796103797103798103799103800103801103802103803103804103805103806103807103808103809103810103811103812103813103814103815103816103817103818103819103820103821103822103823103824103825103826103827103828103829103830103831103832103833103834103835103836103837103838103839103840103841103842103843103844103845103846103847103848103849103850103851103852103853103854103855103856103857103858103859103860103861103862103863103864103865103866103867103868103869103870103871103872103873103874103875103876103877103878103879103880103881103882103883103884103885103886103887103888103889103890103891103892103893103894103895103896103897103898103899103900103901103902103903103904103905103906103907103908103909103910103911103912103913103914103915103916103917103918103919103920103921103922103923103924103925103926103927103928103929103930103931103932103933103934103935103936103937103938103939103940103941103942103943103944103945103946103947103948103949103950103951103952103953103954103955103956103957103958103959103960103961103962103963103964103965103966103967103968103969103970103971103972103973103974103975103976103977103978103979103980103981103982103983103984103985103986103987103988103989103990103991103992103993103994103995103996103997103998103999104000104001104002104003104004104005104006104007104008104009104010104011104012104013104014104015104016104017104018104019104020104021104022104023104024104025104026104027104028104029104030104031104032104033104034104035104036104037104038104039104040104041104042104043104044104045104046104047104048104049104050104051104052104053104054104055104056104057104058104059104060104061104062104063104064104065104066104067104068104069104070104071104072104073104074104075104076104077104078104079104080104081104082104083104084104085104086104087104088104089104090104091104092104093104094104095104096104097104098104099104100104101104102104103104104104105104106104107104108104109104110104111104112104113104114104115104116104117104118104119104120104121104122104123104124104125104126104127104128104129104130104131104132104133104134104135104136104137104138104139104140104141104142104143104144104145104146104147104148104149104150104151104152104153104154104155104156104157104158104159104160104161104162104163104164104165104166104167104168104169104170104171104172104173104174104175104176104177104178104179104180104181104182104183104184104185104186104187104188104189104190104191104192104193104194104195104196104197104198104199104200104201104202104203104204104205104206104207104208104209104210104211104212104213104214104215104216104217104218104219104220104221104222104223104224104225104226104227104228104229104230104231104232104233104234104235104236104237104238104239104240104241104242104243104244104245104246104247104248104249104250104251104252104253104254104255104256104257104258104259104260104261104262104263104264104265104266104267104268104269104270104271104272104273104274104275104276104277104278104279104280104281104282104283104284104285104286104287104288104289104290104291104292104293104294104295104296104297104298104299104300104301104302104303104304104305104306104307104308104309104310104311104312104313104314104315104316104317104318104319104320104321104322104323104324104325104326104327104328104329104330104331104332104333104334104335104336104337104338104339104340104341104342104343104344104345104346104347104348104349104350104351104352104353104354104355104356104357104358104359104360104361104362104363104364104365104366104367104368104369104370104371104372104373104374104375104376104377104378104379104380104381104382104383104384104385104386104387104388104389104390104391104392104393104394104395104396104397104398104399104400104401104402104403104404104405104406104407104408104409104410104411104412104413104414104415104416104417104418104419104420104421104422104423104424104425104426104427104428104429104430104431104432104433104434104435104436104437104438104439104440104441104442104443104444104445104446104447104448104449104450104451104452104453104454104455104456104457104458104459104460104461104462104463104464104465104466104467104468104469104470104471104472104473104474104475104476104477104478104479104480104481104482104483104484104485104486104487104488104489104490104491104492104493104494104495104496104497104498104499104500104501104502104503104504104505104506104507104508104509104510104511104512104513104514104515104516104517104518104519104520104521104522104523104524104525104526104527104528104529104530104531104532104533104534104535104536104537104538104539104540104541104542104543104544104545104546104547104548104549104550104551104552104553104554104555104556104557104558104559104560104561104562104563104564104565104566104567104568104569104570104571104572104573104574104575104576104577104578104579104580104581104582104583104584104585104586104587104588104589104590104591104592104593104594104595104596104597104598104599104600104601104602104603104604104605104606104607104608104609104610104611104612104613104614104615104616104617104618104619104620104621104622104623104624104625104626104627104628104629104630104631104632104633104634104635104636104637104638104639104640104641104642104643104644104645104646104647104648104649104650104651104652104653104654104655104656104657104658104659104660104661104662104663104664104665104666104667104668104669104670104671104672104673104674104675104676104677104678104679104680104681104682104683104684104685104686104687104688104689104690104691104692104693104694104695104696104697104698104699104700104701104702104703104704104705104706104707104708104709104710104711104712104713104714104715104716104717104718104719104720104721104722104723104724104725104726104727104728104729104730104731104732104733104734104735104736104737104738104739104740104741104742104743104744104745104746104747104748104749104750104751104752104753104754104755104756104757104758104759104760104761104762104763104764104765104766104767104768104769104770104771104772104773104774104775104776104777104778104779104780104781104782104783104784104785104786104787104788104789104790104791104792104793104794104795104796104797104798104799104800104801104802104803104804104805104806104807104808104809104810104811104812104813104814104815104816104817104818104819104820104821104822104823104824104825104826104827104828104829104830104831104832104833104834104835104836104837104838104839104840104841104842104843104844104845104846104847104848104849104850104851104852104853104854104855104856104857104858104859104860104861104862104863104864104865104866104867104868104869104870104871104872104873104874104875104876104877104878104879104880104881104882104883104884104885104886104887104888104889104890104891104892104893104894104895104896104897104898104899104900104901104902104903104904104905104906104907104908104909104910104911104912104913104914104915104916104917104918104919104920104921104922104923104924104925104926104927104928104929104930104931104932104933104934104935104936104937104938104939104940104941104942104943104944104945104946104947104948104949104950104951104952104953104954104955104956104957104958104959104960104961104962104963104964104965104966104967104968104969104970104971104972104973104974104975104976104977104978104979104980104981104982104983104984104985104986104987104988104989104990104991104992104993104994104995104996104997104998104999105000105001105002105003105004105005105006105007105008105009105010105011105012105013105014105015105016105017105018105019105020105021105022105023105024105025105026105027105028105029105030105031105032105033105034105035105036105037105038105039105040105041105042105043105044105045105046105047105048105049105050105051105052105053105054105055105056105057105058105059105060105061105062105063105064105065105066105067105068105069105070105071105072105073105074105075105076105077105078105079105080105081105082105083105084105085105086105087105088105089105090105091105092105093105094105095105096105097105098105099105100105101105102105103105104105105105106105107105108105109105110105111105112105113105114105115105116105117105118105119105120105121105122105123105124105125105126105127105128105129105130105131105132105133105134105135105136105137105138105139105140105141105142105143105144105145105146105147105148105149105150105151105152105153105154105155105156105157105158105159105160105161105162105163105164105165105166105167105168105169105170105171105172105173105174105175105176105177105178105179105180105181105182105183105184105185105186105187105188105189105190105191105192105193105194105195105196105197105198105199105200105201105202105203105204105205105206105207105208105209105210105211105212105213105214105215105216105217105218105219105220105221105222105223105224105225105226105227105228105229105230105231105232105233105234105235105236105237105238105239105240105241105242105243105244105245105246105247105248105249105250105251105252105253105254105255105256105257105258105259105260105261105262105263105264105265105266105267105268105269105270105271105272105273105274105275105276105277105278105279105280105281105282105283105284105285105286105287105288105289105290105291105292105293105294105295105296105297105298105299105300105301105302105303105304105305105306105307105308105309105310105311105312105313105314105315105316105317105318105319105320105321105322105323105324105325105326105327105328105329105330105331105332105333105334105335105336105337105338105339105340105341105342105343105344105345105346105347105348105349105350105351105352105353105354105355105356105357105358105359105360105361105362105363105364105365105366105367105368105369105370105371105372105373105374105375105376105377105378105379105380105381105382105383105384105385105386105387105388105389105390105391105392105393105394105395105396105397105398105399105400105401105402105403105404105405105406105407105408105409105410105411105412105413105414105415105416105417105418105419105420105421105422105423105424105425105426105427105428105429105430105431105432105433105434105435105436105437105438105439105440105441105442105443105444105445105446105447105448105449105450105451105452105453105454105455105456105457105458105459105460105461105462105463105464105465105466105467105468105469105470105471105472105473105474105475105476105477105478105479105480105481105482105483105484105485105486105487105488105489105490105491105492105493105494105495105496105497105498105499105500105501105502105503105504105505105506105507105508105509105510105511105512105513105514105515105516105517105518105519105520105521105522105523105524105525105526105527105528105529105530105531105532105533105534105535105536105537105538105539105540105541105542105543105544105545105546105547105548105549105550105551105552105553105554105555105556105557105558105559105560105561105562105563105564105565105566105567105568105569105570105571105572105573105574105575105576105577105578105579105580105581105582105583105584105585105586105587105588105589105590105591105592105593105594105595105596105597105598105599105600105601105602105603105604105605105606105607105608105609105610105611105612105613105614105615105616105617105618105619105620105621105622105623105624105625105626105627105628105629105630105631105632105633105634105635105636105637105638105639105640105641105642105643105644105645105646105647105648105649105650105651105652105653105654105655105656105657105658105659105660105661105662105663105664105665105666105667105668105669105670105671105672105673105674105675105676105677105678105679105680105681105682105683105684105685105686105687105688105689105690105691105692105693105694105695105696105697105698105699105700105701105702105703105704105705105706105707105708105709105710105711105712105713105714105715105716105717105718105719105720105721105722105723105724105725105726105727105728105729105730105731105732105733105734105735105736105737105738105739105740105741105742105743105744105745105746105747105748105749105750105751105752105753105754105755105756105757105758105759105760105761105762105763105764105765105766105767105768105769105770105771105772105773105774105775105776105777105778105779105780105781105782105783105784105785105786105787105788105789105790105791105792105793105794105795105796105797105798105799105800105801105802105803105804105805105806105807105808105809105810105811105812105813105814105815105816105817105818105819105820105821105822105823105824105825105826105827105828105829105830105831105832105833105834105835105836105837105838105839105840105841105842105843105844105845105846105847105848105849105850105851105852105853105854105855105856105857105858105859105860105861105862105863105864105865105866105867105868105869105870105871105872105873105874105875105876105877105878105879105880105881105882105883105884105885105886105887105888105889105890105891105892105893105894105895105896105897105898105899105900105901105902105903105904105905105906105907105908105909105910105911105912105913105914105915105916105917105918105919105920105921105922105923105924105925105926105927105928105929105930105931105932105933105934105935105936105937105938105939105940105941105942105943105944105945105946105947105948105949105950105951105952105953105954105955105956105957105958105959105960105961105962105963105964105965105966105967105968105969105970105971105972105973105974105975105976105977105978105979105980105981105982105983105984105985105986105987105988105989105990105991105992105993105994105995105996105997105998105999106000106001106002106003106004106005106006106007106008106009106010106011106012106013106014106015106016106017106018106019106020106021106022106023106024106025106026106027106028106029106030106031106032106033106034106035106036106037106038106039106040106041106042106043106044106045106046106047106048106049106050106051106052106053106054106055106056106057106058106059106060106061106062106063106064106065106066106067106068106069106070106071106072106073106074106075106076106077106078106079106080106081106082106083106084106085106086106087106088106089106090106091106092106093106094106095106096106097106098106099106100106101106102106103106104106105106106106107106108106109106110106111106112106113106114106115106116106117106118106119106120106121106122106123106124106125106126106127106128106129106130106131106132106133106134106135106136106137106138106139106140106141106142106143106144106145106146106147106148106149106150106151106152106153106154106155106156106157106158106159106160106161106162106163106164106165106166106167106168106169106170106171106172106173106174106175106176106177106178106179106180106181106182106183106184106185106186106187106188106189106190106191106192106193106194106195106196106197106198106199106200106201106202106203106204106205106206106207106208106209106210106211106212106213106214106215106216106217106218106219106220106221106222106223106224106225106226106227106228106229106230106231106232106233106234106235106236106237106238106239106240106241106242106243106244106245106246106247106248106249106250106251106252106253106254106255106256106257106258106259106260106261106262106263106264106265106266106267106268106269106270106271106272106273106274106275106276106277106278106279106280106281106282106283106284106285106286106287106288106289106290106291106292106293106294106295106296106297106298106299106300106301106302106303106304106305106306106307106308106309106310106311106312106313106314106315106316106317106318106319106320106321106322106323106324106325106326106327106328106329106330106331106332106333106334106335106336106337106338106339106340106341106342106343106344106345106346106347106348106349106350106351106352106353106354106355106356106357106358106359106360106361106362106363106364106365106366106367106368
  1. diff -Nur linux-3.15.4/arch/arm/configs/bcmrpi_cutdown_defconfig linux-rpi/arch/arm/configs/bcmrpi_cutdown_defconfig
  2. --- linux-3.15.4/arch/arm/configs/bcmrpi_cutdown_defconfig 1970-01-01 01:00:00.000000000 +0100
  3. +++ linux-rpi/arch/arm/configs/bcmrpi_cutdown_defconfig 2014-07-07 10:44:57.000000000 +0200
  4. @@ -0,0 +1,503 @@
  5. +CONFIG_EXPERIMENTAL=y
  6. +# CONFIG_LOCALVERSION_AUTO is not set
  7. +CONFIG_SYSVIPC=y
  8. +CONFIG_POSIX_MQUEUE=y
  9. +CONFIG_IKCONFIG=y
  10. +CONFIG_IKCONFIG_PROC=y
  11. +# CONFIG_UID16 is not set
  12. +# CONFIG_KALLSYMS is not set
  13. +CONFIG_EMBEDDED=y
  14. +# CONFIG_VM_EVENT_COUNTERS is not set
  15. +# CONFIG_COMPAT_BRK is not set
  16. +CONFIG_SLAB=y
  17. +CONFIG_MODULES=y
  18. +CONFIG_MODULE_UNLOAD=y
  19. +CONFIG_MODVERSIONS=y
  20. +CONFIG_MODULE_SRCVERSION_ALL=y
  21. +# CONFIG_BLK_DEV_BSG is not set
  22. +CONFIG_ARCH_BCM2708=y
  23. +CONFIG_NO_HZ=y
  24. +CONFIG_HIGH_RES_TIMERS=y
  25. +CONFIG_AEABI=y
  26. +CONFIG_ZBOOT_ROM_TEXT=0x0
  27. +CONFIG_ZBOOT_ROM_BSS=0x0
  28. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext3 rootwait"
  29. +CONFIG_CPU_IDLE=y
  30. +CONFIG_VFP=y
  31. +CONFIG_BINFMT_MISC=m
  32. +CONFIG_NET=y
  33. +CONFIG_PACKET=y
  34. +CONFIG_UNIX=y
  35. +CONFIG_XFRM_USER=y
  36. +CONFIG_NET_KEY=m
  37. +CONFIG_INET=y
  38. +CONFIG_IP_MULTICAST=y
  39. +CONFIG_IP_PNP=y
  40. +CONFIG_IP_PNP_DHCP=y
  41. +CONFIG_IP_PNP_RARP=y
  42. +CONFIG_SYN_COOKIES=y
  43. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  44. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  45. +# CONFIG_INET_XFRM_MODE_BEET is not set
  46. +# CONFIG_INET_LRO is not set
  47. +# CONFIG_INET_DIAG is not set
  48. +# CONFIG_IPV6 is not set
  49. +CONFIG_NET_PKTGEN=m
  50. +CONFIG_IRDA=m
  51. +CONFIG_IRLAN=m
  52. +CONFIG_IRCOMM=m
  53. +CONFIG_IRDA_ULTRA=y
  54. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  55. +CONFIG_IRDA_FAST_RR=y
  56. +CONFIG_IRTTY_SIR=m
  57. +CONFIG_KINGSUN_DONGLE=m
  58. +CONFIG_KSDAZZLE_DONGLE=m
  59. +CONFIG_KS959_DONGLE=m
  60. +CONFIG_USB_IRDA=m
  61. +CONFIG_SIGMATEL_FIR=m
  62. +CONFIG_MCS_FIR=m
  63. +CONFIG_BT=m
  64. +CONFIG_BT_L2CAP=y
  65. +CONFIG_BT_SCO=y
  66. +CONFIG_BT_RFCOMM=m
  67. +CONFIG_BT_RFCOMM_TTY=y
  68. +CONFIG_BT_BNEP=m
  69. +CONFIG_BT_BNEP_MC_FILTER=y
  70. +CONFIG_BT_BNEP_PROTO_FILTER=y
  71. +CONFIG_BT_HIDP=m
  72. +CONFIG_BT_HCIBTUSB=m
  73. +CONFIG_BT_HCIBCM203X=m
  74. +CONFIG_BT_HCIBPA10X=m
  75. +CONFIG_BT_HCIBFUSB=m
  76. +CONFIG_BT_HCIVHCI=m
  77. +CONFIG_BT_MRVL=m
  78. +CONFIG_BT_MRVL_SDIO=m
  79. +CONFIG_BT_ATH3K=m
  80. +CONFIG_CFG80211=m
  81. +CONFIG_MAC80211=m
  82. +CONFIG_MAC80211_RC_PID=y
  83. +CONFIG_MAC80211_MESH=y
  84. +CONFIG_WIMAX=m
  85. +CONFIG_NET_9P=m
  86. +CONFIG_NFC=m
  87. +CONFIG_NFC_PN533=m
  88. +CONFIG_DEVTMPFS=y
  89. +CONFIG_BLK_DEV_LOOP=y
  90. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  91. +CONFIG_BLK_DEV_NBD=m
  92. +CONFIG_BLK_DEV_RAM=y
  93. +CONFIG_CDROM_PKTCDVD=m
  94. +CONFIG_MISC_DEVICES=y
  95. +CONFIG_SCSI=y
  96. +# CONFIG_SCSI_PROC_FS is not set
  97. +CONFIG_BLK_DEV_SD=m
  98. +CONFIG_BLK_DEV_SR=m
  99. +CONFIG_SCSI_MULTI_LUN=y
  100. +# CONFIG_SCSI_LOWLEVEL is not set
  101. +CONFIG_NETDEVICES=y
  102. +CONFIG_TUN=m
  103. +CONFIG_PHYLIB=m
  104. +CONFIG_MDIO_BITBANG=m
  105. +CONFIG_NET_ETHERNET=y
  106. +# CONFIG_NETDEV_1000 is not set
  107. +# CONFIG_NETDEV_10000 is not set
  108. +CONFIG_LIBERTAS_THINFIRM=m
  109. +CONFIG_LIBERTAS_THINFIRM_USB=m
  110. +CONFIG_AT76C50X_USB=m
  111. +CONFIG_USB_ZD1201=m
  112. +CONFIG_USB_NET_RNDIS_WLAN=m
  113. +CONFIG_RTL8187=m
  114. +CONFIG_MAC80211_HWSIM=m
  115. +CONFIG_ATH_COMMON=m
  116. +CONFIG_ATH9K=m
  117. +CONFIG_ATH9K_HTC=m
  118. +CONFIG_CARL9170=m
  119. +CONFIG_B43=m
  120. +CONFIG_B43LEGACY=m
  121. +CONFIG_HOSTAP=m
  122. +CONFIG_IWM=m
  123. +CONFIG_LIBERTAS=m
  124. +CONFIG_LIBERTAS_USB=m
  125. +CONFIG_LIBERTAS_SDIO=m
  126. +CONFIG_P54_COMMON=m
  127. +CONFIG_P54_USB=m
  128. +CONFIG_RT2X00=m
  129. +CONFIG_RT2500USB=m
  130. +CONFIG_RT73USB=m
  131. +CONFIG_RT2800USB=m
  132. +CONFIG_RT2800USB_RT53XX=y
  133. +CONFIG_RTL8192CU=m
  134. +CONFIG_WL1251=m
  135. +CONFIG_WL12XX_MENU=m
  136. +CONFIG_ZD1211RW=m
  137. +CONFIG_MWIFIEX=m
  138. +CONFIG_MWIFIEX_SDIO=m
  139. +CONFIG_WIMAX_I2400M_USB=m
  140. +CONFIG_USB_CATC=m
  141. +CONFIG_USB_KAWETH=m
  142. +CONFIG_USB_PEGASUS=m
  143. +CONFIG_USB_RTL8150=m
  144. +CONFIG_USB_USBNET=y
  145. +CONFIG_USB_NET_AX8817X=m
  146. +CONFIG_USB_NET_CDCETHER=m
  147. +CONFIG_USB_NET_CDC_EEM=m
  148. +CONFIG_USB_NET_DM9601=m
  149. +CONFIG_USB_NET_SMSC75XX=m
  150. +CONFIG_USB_NET_SMSC95XX=y
  151. +CONFIG_USB_NET_GL620A=m
  152. +CONFIG_USB_NET_NET1080=m
  153. +CONFIG_USB_NET_PLUSB=m
  154. +CONFIG_USB_NET_MCS7830=m
  155. +CONFIG_USB_NET_CDC_SUBSET=m
  156. +CONFIG_USB_ALI_M5632=y
  157. +CONFIG_USB_AN2720=y
  158. +CONFIG_USB_KC2190=y
  159. +# CONFIG_USB_NET_ZAURUS is not set
  160. +CONFIG_USB_NET_CX82310_ETH=m
  161. +CONFIG_USB_NET_KALMIA=m
  162. +CONFIG_USB_NET_INT51X1=m
  163. +CONFIG_USB_IPHETH=m
  164. +CONFIG_USB_SIERRA_NET=m
  165. +CONFIG_USB_VL600=m
  166. +CONFIG_PPP=m
  167. +CONFIG_PPP_ASYNC=m
  168. +CONFIG_PPP_SYNC_TTY=m
  169. +CONFIG_PPP_DEFLATE=m
  170. +CONFIG_PPP_BSDCOMP=m
  171. +CONFIG_SLIP=m
  172. +CONFIG_SLIP_COMPRESSED=y
  173. +CONFIG_NETCONSOLE=m
  174. +CONFIG_INPUT_POLLDEV=m
  175. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  176. +CONFIG_INPUT_JOYDEV=m
  177. +CONFIG_INPUT_EVDEV=m
  178. +# CONFIG_INPUT_KEYBOARD is not set
  179. +# CONFIG_INPUT_MOUSE is not set
  180. +CONFIG_INPUT_MISC=y
  181. +CONFIG_INPUT_AD714X=m
  182. +CONFIG_INPUT_ATI_REMOTE=m
  183. +CONFIG_INPUT_ATI_REMOTE2=m
  184. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  185. +CONFIG_INPUT_POWERMATE=m
  186. +CONFIG_INPUT_YEALINK=m
  187. +CONFIG_INPUT_CM109=m
  188. +CONFIG_INPUT_UINPUT=m
  189. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  190. +CONFIG_INPUT_ADXL34X=m
  191. +CONFIG_INPUT_CMA3000=m
  192. +CONFIG_SERIO=m
  193. +CONFIG_SERIO_RAW=m
  194. +CONFIG_GAMEPORT=m
  195. +CONFIG_GAMEPORT_NS558=m
  196. +CONFIG_GAMEPORT_L4=m
  197. +CONFIG_VT_HW_CONSOLE_BINDING=y
  198. +# CONFIG_LEGACY_PTYS is not set
  199. +# CONFIG_DEVKMEM is not set
  200. +CONFIG_SERIAL_AMBA_PL011=y
  201. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  202. +# CONFIG_HW_RANDOM is not set
  203. +CONFIG_RAW_DRIVER=y
  204. +CONFIG_GPIO_SYSFS=y
  205. +# CONFIG_HWMON is not set
  206. +CONFIG_WATCHDOG=y
  207. +CONFIG_BCM2708_WDT=m
  208. +# CONFIG_MFD_SUPPORT is not set
  209. +CONFIG_FB=y
  210. +CONFIG_FB_BCM2708=y
  211. +CONFIG_FRAMEBUFFER_CONSOLE=y
  212. +CONFIG_LOGO=y
  213. +# CONFIG_LOGO_LINUX_MONO is not set
  214. +# CONFIG_LOGO_LINUX_VGA16 is not set
  215. +CONFIG_SOUND=y
  216. +CONFIG_SND=m
  217. +CONFIG_SND_SEQUENCER=m
  218. +CONFIG_SND_SEQ_DUMMY=m
  219. +CONFIG_SND_MIXER_OSS=m
  220. +CONFIG_SND_PCM_OSS=m
  221. +CONFIG_SND_SEQUENCER_OSS=y
  222. +CONFIG_SND_HRTIMER=m
  223. +CONFIG_SND_DUMMY=m
  224. +CONFIG_SND_ALOOP=m
  225. +CONFIG_SND_VIRMIDI=m
  226. +CONFIG_SND_MTPAV=m
  227. +CONFIG_SND_SERIAL_U16550=m
  228. +CONFIG_SND_MPU401=m
  229. +CONFIG_SND_BCM2835=m
  230. +CONFIG_SND_USB_AUDIO=m
  231. +CONFIG_SND_USB_UA101=m
  232. +CONFIG_SND_USB_CAIAQ=m
  233. +CONFIG_SND_USB_6FIRE=m
  234. +CONFIG_SOUND_PRIME=m
  235. +CONFIG_HID_PID=y
  236. +CONFIG_USB_HIDDEV=y
  237. +CONFIG_HID_A4TECH=m
  238. +CONFIG_HID_ACRUX=m
  239. +CONFIG_HID_APPLE=m
  240. +CONFIG_HID_BELKIN=m
  241. +CONFIG_HID_CHERRY=m
  242. +CONFIG_HID_CHICONY=m
  243. +CONFIG_HID_CYPRESS=m
  244. +CONFIG_HID_DRAGONRISE=m
  245. +CONFIG_HID_EMS_FF=m
  246. +CONFIG_HID_ELECOM=m
  247. +CONFIG_HID_EZKEY=m
  248. +CONFIG_HID_HOLTEK=m
  249. +CONFIG_HID_KEYTOUCH=m
  250. +CONFIG_HID_KYE=m
  251. +CONFIG_HID_UCLOGIC=m
  252. +CONFIG_HID_WALTOP=m
  253. +CONFIG_HID_GYRATION=m
  254. +CONFIG_HID_TWINHAN=m
  255. +CONFIG_HID_KENSINGTON=m
  256. +CONFIG_HID_LCPOWER=m
  257. +CONFIG_HID_LOGITECH=m
  258. +CONFIG_HID_MAGICMOUSE=m
  259. +CONFIG_HID_MICROSOFT=m
  260. +CONFIG_HID_MONTEREY=m
  261. +CONFIG_HID_MULTITOUCH=m
  262. +CONFIG_HID_NTRIG=m
  263. +CONFIG_HID_ORTEK=m
  264. +CONFIG_HID_PANTHERLORD=m
  265. +CONFIG_HID_PETALYNX=m
  266. +CONFIG_HID_PICOLCD=m
  267. +CONFIG_HID_QUANTA=m
  268. +CONFIG_HID_ROCCAT=m
  269. +CONFIG_HID_SAMSUNG=m
  270. +CONFIG_HID_SONY=m
  271. +CONFIG_HID_SPEEDLINK=m
  272. +CONFIG_HID_SUNPLUS=m
  273. +CONFIG_HID_GREENASIA=m
  274. +CONFIG_HID_SMARTJOYPLUS=m
  275. +CONFIG_HID_TOPSEED=m
  276. +CONFIG_HID_THRUSTMASTER=m
  277. +CONFIG_HID_WACOM=m
  278. +CONFIG_HID_WIIMOTE=m
  279. +CONFIG_HID_ZEROPLUS=m
  280. +CONFIG_HID_ZYDACRON=m
  281. +CONFIG_USB=y
  282. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  283. +CONFIG_USB_MON=m
  284. +CONFIG_USB_DWCOTG=y
  285. +CONFIG_USB_STORAGE=y
  286. +CONFIG_USB_STORAGE_REALTEK=m
  287. +CONFIG_USB_STORAGE_DATAFAB=m
  288. +CONFIG_USB_STORAGE_FREECOM=m
  289. +CONFIG_USB_STORAGE_ISD200=m
  290. +CONFIG_USB_STORAGE_USBAT=m
  291. +CONFIG_USB_STORAGE_SDDR09=m
  292. +CONFIG_USB_STORAGE_SDDR55=m
  293. +CONFIG_USB_STORAGE_JUMPSHOT=m
  294. +CONFIG_USB_STORAGE_ALAUDA=m
  295. +CONFIG_USB_STORAGE_ONETOUCH=m
  296. +CONFIG_USB_STORAGE_KARMA=m
  297. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  298. +CONFIG_USB_STORAGE_ENE_UB6250=m
  299. +CONFIG_USB_UAS=m
  300. +CONFIG_USB_LIBUSUAL=y
  301. +CONFIG_USB_MDC800=m
  302. +CONFIG_USB_MICROTEK=m
  303. +CONFIG_USB_SERIAL=m
  304. +CONFIG_USB_SERIAL_GENERIC=y
  305. +CONFIG_USB_SERIAL_AIRCABLE=m
  306. +CONFIG_USB_SERIAL_ARK3116=m
  307. +CONFIG_USB_SERIAL_BELKIN=m
  308. +CONFIG_USB_SERIAL_CH341=m
  309. +CONFIG_USB_SERIAL_WHITEHEAT=m
  310. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  311. +CONFIG_USB_SERIAL_CP210X=m
  312. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  313. +CONFIG_USB_SERIAL_EMPEG=m
  314. +CONFIG_USB_SERIAL_FTDI_SIO=m
  315. +CONFIG_USB_SERIAL_FUNSOFT=m
  316. +CONFIG_USB_SERIAL_VISOR=m
  317. +CONFIG_USB_SERIAL_IPAQ=m
  318. +CONFIG_USB_SERIAL_IR=m
  319. +CONFIG_USB_SERIAL_EDGEPORT=m
  320. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  321. +CONFIG_USB_SERIAL_GARMIN=m
  322. +CONFIG_USB_SERIAL_IPW=m
  323. +CONFIG_USB_SERIAL_IUU=m
  324. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  325. +CONFIG_USB_SERIAL_KEYSPAN=m
  326. +CONFIG_USB_SERIAL_KLSI=m
  327. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  328. +CONFIG_USB_SERIAL_MCT_U232=m
  329. +CONFIG_USB_SERIAL_MOS7720=m
  330. +CONFIG_USB_SERIAL_MOS7840=m
  331. +CONFIG_USB_SERIAL_MOTOROLA=m
  332. +CONFIG_USB_SERIAL_NAVMAN=m
  333. +CONFIG_USB_SERIAL_PL2303=m
  334. +CONFIG_USB_SERIAL_OTI6858=m
  335. +CONFIG_USB_SERIAL_QCAUX=m
  336. +CONFIG_USB_SERIAL_QUALCOMM=m
  337. +CONFIG_USB_SERIAL_SPCP8X5=m
  338. +CONFIG_USB_SERIAL_HP4X=m
  339. +CONFIG_USB_SERIAL_SAFE=m
  340. +CONFIG_USB_SERIAL_SIEMENS_MPI=m
  341. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  342. +CONFIG_USB_SERIAL_SYMBOL=m
  343. +CONFIG_USB_SERIAL_TI=m
  344. +CONFIG_USB_SERIAL_CYBERJACK=m
  345. +CONFIG_USB_SERIAL_XIRCOM=m
  346. +CONFIG_USB_SERIAL_OPTION=m
  347. +CONFIG_USB_SERIAL_OMNINET=m
  348. +CONFIG_USB_SERIAL_OPTICON=m
  349. +CONFIG_USB_SERIAL_VIVOPAY_SERIAL=m
  350. +CONFIG_USB_SERIAL_ZIO=m
  351. +CONFIG_USB_SERIAL_SSU100=m
  352. +CONFIG_USB_SERIAL_DEBUG=m
  353. +CONFIG_USB_EMI62=m
  354. +CONFIG_USB_EMI26=m
  355. +CONFIG_USB_ADUTUX=m
  356. +CONFIG_USB_SEVSEG=m
  357. +CONFIG_USB_RIO500=m
  358. +CONFIG_USB_LEGOTOWER=m
  359. +CONFIG_USB_LCD=m
  360. +CONFIG_USB_LED=m
  361. +CONFIG_USB_CYPRESS_CY7C63=m
  362. +CONFIG_USB_CYTHERM=m
  363. +CONFIG_USB_IDMOUSE=m
  364. +CONFIG_USB_FTDI_ELAN=m
  365. +CONFIG_USB_APPLEDISPLAY=m
  366. +CONFIG_USB_LD=m
  367. +CONFIG_USB_TRANCEVIBRATOR=m
  368. +CONFIG_USB_IOWARRIOR=m
  369. +CONFIG_USB_TEST=m
  370. +CONFIG_USB_ISIGHTFW=m
  371. +CONFIG_USB_YUREX=m
  372. +CONFIG_MMC=y
  373. +CONFIG_MMC_SDHCI=y
  374. +CONFIG_MMC_SDHCI_PLTFM=y
  375. +CONFIG_MMC_SDHCI_BCM2708=y
  376. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  377. +CONFIG_LEDS_GPIO=y
  378. +CONFIG_LEDS_TRIGGER_TIMER=m
  379. +CONFIG_LEDS_TRIGGER_HEARTBEAT=m
  380. +CONFIG_LEDS_TRIGGER_DEFAULT_ON=m
  381. +CONFIG_UIO=m
  382. +CONFIG_UIO_PDRV=m
  383. +CONFIG_UIO_PDRV_GENIRQ=m
  384. +# CONFIG_IOMMU_SUPPORT is not set
  385. +CONFIG_EXT4_FS=y
  386. +CONFIG_EXT4_FS_POSIX_ACL=y
  387. +CONFIG_EXT4_FS_SECURITY=y
  388. +CONFIG_REISERFS_FS=m
  389. +CONFIG_REISERFS_FS_XATTR=y
  390. +CONFIG_REISERFS_FS_POSIX_ACL=y
  391. +CONFIG_REISERFS_FS_SECURITY=y
  392. +CONFIG_JFS_FS=m
  393. +CONFIG_JFS_POSIX_ACL=y
  394. +CONFIG_JFS_SECURITY=y
  395. +CONFIG_XFS_FS=m
  396. +CONFIG_XFS_QUOTA=y
  397. +CONFIG_XFS_POSIX_ACL=y
  398. +CONFIG_XFS_RT=y
  399. +CONFIG_GFS2_FS=m
  400. +CONFIG_OCFS2_FS=m
  401. +CONFIG_BTRFS_FS=m
  402. +CONFIG_BTRFS_FS_POSIX_ACL=y
  403. +CONFIG_NILFS2_FS=m
  404. +CONFIG_AUTOFS4_FS=y
  405. +CONFIG_FUSE_FS=m
  406. +CONFIG_CUSE=m
  407. +CONFIG_FSCACHE=y
  408. +CONFIG_CACHEFILES=y
  409. +CONFIG_ISO9660_FS=m
  410. +CONFIG_JOLIET=y
  411. +CONFIG_ZISOFS=y
  412. +CONFIG_UDF_FS=m
  413. +CONFIG_MSDOS_FS=y
  414. +CONFIG_VFAT_FS=y
  415. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  416. +CONFIG_NTFS_FS=m
  417. +CONFIG_TMPFS=y
  418. +CONFIG_TMPFS_POSIX_ACL=y
  419. +CONFIG_CONFIGFS_FS=y
  420. +CONFIG_SQUASHFS=m
  421. +CONFIG_SQUASHFS_XATTR=y
  422. +CONFIG_SQUASHFS_LZO=y
  423. +CONFIG_SQUASHFS_XZ=y
  424. +CONFIG_NFS_FS=y
  425. +CONFIG_NFS_V3=y
  426. +CONFIG_NFS_V3_ACL=y
  427. +CONFIG_NFS_V4=y
  428. +CONFIG_ROOT_NFS=y
  429. +CONFIG_NFS_FSCACHE=y
  430. +CONFIG_CIFS=m
  431. +CONFIG_CIFS_WEAK_PW_HASH=y
  432. +CONFIG_CIFS_XATTR=y
  433. +CONFIG_CIFS_POSIX=y
  434. +CONFIG_9P_FS=m
  435. +CONFIG_PARTITION_ADVANCED=y
  436. +CONFIG_MAC_PARTITION=y
  437. +CONFIG_EFI_PARTITION=y
  438. +CONFIG_NLS_DEFAULT="utf8"
  439. +CONFIG_NLS_CODEPAGE_437=y
  440. +CONFIG_NLS_CODEPAGE_737=m
  441. +CONFIG_NLS_CODEPAGE_775=m
  442. +CONFIG_NLS_CODEPAGE_850=m
  443. +CONFIG_NLS_CODEPAGE_852=m
  444. +CONFIG_NLS_CODEPAGE_855=m
  445. +CONFIG_NLS_CODEPAGE_857=m
  446. +CONFIG_NLS_CODEPAGE_860=m
  447. +CONFIG_NLS_CODEPAGE_861=m
  448. +CONFIG_NLS_CODEPAGE_862=m
  449. +CONFIG_NLS_CODEPAGE_863=m
  450. +CONFIG_NLS_CODEPAGE_864=m
  451. +CONFIG_NLS_CODEPAGE_865=m
  452. +CONFIG_NLS_CODEPAGE_866=m
  453. +CONFIG_NLS_CODEPAGE_869=m
  454. +CONFIG_NLS_CODEPAGE_936=m
  455. +CONFIG_NLS_CODEPAGE_950=m
  456. +CONFIG_NLS_CODEPAGE_932=m
  457. +CONFIG_NLS_CODEPAGE_949=m
  458. +CONFIG_NLS_CODEPAGE_874=m
  459. +CONFIG_NLS_ISO8859_8=m
  460. +CONFIG_NLS_CODEPAGE_1250=m
  461. +CONFIG_NLS_CODEPAGE_1251=m
  462. +CONFIG_NLS_ASCII=y
  463. +CONFIG_NLS_ISO8859_1=m
  464. +CONFIG_NLS_ISO8859_2=m
  465. +CONFIG_NLS_ISO8859_3=m
  466. +CONFIG_NLS_ISO8859_4=m
  467. +CONFIG_NLS_ISO8859_5=m
  468. +CONFIG_NLS_ISO8859_6=m
  469. +CONFIG_NLS_ISO8859_7=m
  470. +CONFIG_NLS_ISO8859_9=m
  471. +CONFIG_NLS_ISO8859_13=m
  472. +CONFIG_NLS_ISO8859_14=m
  473. +CONFIG_NLS_ISO8859_15=m
  474. +CONFIG_NLS_KOI8_R=m
  475. +CONFIG_NLS_KOI8_U=m
  476. +CONFIG_NLS_UTF8=m
  477. +# CONFIG_SCHED_DEBUG is not set
  478. +# CONFIG_DEBUG_BUGVERBOSE is not set
  479. +# CONFIG_FTRACE is not set
  480. +# CONFIG_ARM_UNWIND is not set
  481. +CONFIG_CRYPTO_AUTHENC=m
  482. +CONFIG_CRYPTO_SEQIV=m
  483. +CONFIG_CRYPTO_CBC=y
  484. +CONFIG_CRYPTO_HMAC=y
  485. +CONFIG_CRYPTO_XCBC=m
  486. +CONFIG_CRYPTO_MD5=y
  487. +CONFIG_CRYPTO_SHA1=y
  488. +CONFIG_CRYPTO_SHA256=m
  489. +CONFIG_CRYPTO_SHA512=m
  490. +CONFIG_CRYPTO_TGR192=m
  491. +CONFIG_CRYPTO_WP512=m
  492. +CONFIG_CRYPTO_CAST5=m
  493. +CONFIG_CRYPTO_DES=y
  494. +CONFIG_CRYPTO_DEFLATE=m
  495. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  496. +# CONFIG_CRYPTO_HW is not set
  497. +CONFIG_CRC_ITU_T=y
  498. +CONFIG_LIBCRC32C=y
  499. +CONFIG_I2C=y
  500. +CONFIG_I2C_BOARDINFO=y
  501. +CONFIG_I2C_COMPAT=y
  502. +CONFIG_I2C_CHARDEV=m
  503. +CONFIG_I2C_HELPER_AUTO=y
  504. +CONFIG_I2C_BCM2708=m
  505. +CONFIG_SPI=y
  506. +CONFIG_SPI_MASTER=y
  507. +CONFIG_SPI_BCM2708=m
  508. diff -Nur linux-3.15.4/arch/arm/configs/bcmrpi_defconfig linux-rpi/arch/arm/configs/bcmrpi_defconfig
  509. --- linux-3.15.4/arch/arm/configs/bcmrpi_defconfig 1970-01-01 01:00:00.000000000 +0100
  510. +++ linux-rpi/arch/arm/configs/bcmrpi_defconfig 2014-07-07 10:44:57.000000000 +0200
  511. @@ -0,0 +1,1099 @@
  512. +# CONFIG_ARM_PATCH_PHYS_VIRT is not set
  513. +# CONFIG_LOCALVERSION_AUTO is not set
  514. +CONFIG_SYSVIPC=y
  515. +CONFIG_POSIX_MQUEUE=y
  516. +CONFIG_FHANDLE=y
  517. +CONFIG_AUDIT=y
  518. +CONFIG_NO_HZ=y
  519. +CONFIG_HIGH_RES_TIMERS=y
  520. +CONFIG_BSD_PROCESS_ACCT=y
  521. +CONFIG_BSD_PROCESS_ACCT_V3=y
  522. +CONFIG_TASKSTATS=y
  523. +CONFIG_TASK_DELAY_ACCT=y
  524. +CONFIG_TASK_XACCT=y
  525. +CONFIG_TASK_IO_ACCOUNTING=y
  526. +CONFIG_IKCONFIG=y
  527. +CONFIG_IKCONFIG_PROC=y
  528. +CONFIG_CGROUP_FREEZER=y
  529. +CONFIG_CGROUP_DEVICE=y
  530. +CONFIG_CGROUP_CPUACCT=y
  531. +CONFIG_RESOURCE_COUNTERS=y
  532. +CONFIG_MEMCG=y
  533. +CONFIG_BLK_CGROUP=y
  534. +CONFIG_NAMESPACES=y
  535. +CONFIG_SCHED_AUTOGROUP=y
  536. +CONFIG_RELAY=y
  537. +CONFIG_BLK_DEV_INITRD=y
  538. +CONFIG_EMBEDDED=y
  539. +# CONFIG_COMPAT_BRK is not set
  540. +CONFIG_PROFILING=y
  541. +CONFIG_OPROFILE=m
  542. +CONFIG_KPROBES=y
  543. +CONFIG_JUMP_LABEL=y
  544. +CONFIG_MODULES=y
  545. +CONFIG_MODULE_UNLOAD=y
  546. +CONFIG_MODVERSIONS=y
  547. +CONFIG_MODULE_SRCVERSION_ALL=y
  548. +CONFIG_BLK_DEV_THROTTLING=y
  549. +CONFIG_PARTITION_ADVANCED=y
  550. +CONFIG_MAC_PARTITION=y
  551. +CONFIG_CFQ_GROUP_IOSCHED=y
  552. +CONFIG_ARCH_BCM2708=y
  553. +CONFIG_PREEMPT=y
  554. +CONFIG_AEABI=y
  555. +CONFIG_CLEANCACHE=y
  556. +CONFIG_FRONTSWAP=y
  557. +CONFIG_CMA=y
  558. +CONFIG_UACCESS_WITH_MEMCPY=y
  559. +CONFIG_SECCOMP=y
  560. +CONFIG_ZBOOT_ROM_TEXT=0x0
  561. +CONFIG_ZBOOT_ROM_BSS=0x0
  562. +CONFIG_CMDLINE="console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
  563. +CONFIG_KEXEC=y
  564. +CONFIG_CPU_FREQ=y
  565. +CONFIG_CPU_FREQ_STAT=m
  566. +CONFIG_CPU_FREQ_STAT_DETAILS=y
  567. +CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE=y
  568. +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
  569. +CONFIG_CPU_FREQ_GOV_USERSPACE=y
  570. +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
  571. +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
  572. +CONFIG_CPU_IDLE=y
  573. +CONFIG_VFP=y
  574. +CONFIG_BINFMT_MISC=m
  575. +CONFIG_NET=y
  576. +CONFIG_PACKET=y
  577. +CONFIG_UNIX=y
  578. +CONFIG_XFRM_USER=y
  579. +CONFIG_NET_KEY=m
  580. +CONFIG_INET=y
  581. +CONFIG_IP_MULTICAST=y
  582. +CONFIG_IP_ADVANCED_ROUTER=y
  583. +CONFIG_IP_MULTIPLE_TABLES=y
  584. +CONFIG_IP_ROUTE_MULTIPATH=y
  585. +CONFIG_IP_ROUTE_VERBOSE=y
  586. +CONFIG_IP_PNP=y
  587. +CONFIG_IP_PNP_DHCP=y
  588. +CONFIG_IP_PNP_RARP=y
  589. +CONFIG_NET_IPIP=m
  590. +CONFIG_NET_IPGRE_DEMUX=m
  591. +CONFIG_NET_IPGRE=m
  592. +CONFIG_IP_MROUTE=y
  593. +CONFIG_IP_MROUTE_MULTIPLE_TABLES=y
  594. +CONFIG_IP_PIMSM_V1=y
  595. +CONFIG_IP_PIMSM_V2=y
  596. +CONFIG_SYN_COOKIES=y
  597. +CONFIG_INET_AH=m
  598. +CONFIG_INET_ESP=m
  599. +CONFIG_INET_IPCOMP=m
  600. +CONFIG_INET_XFRM_MODE_TRANSPORT=m
  601. +CONFIG_INET_XFRM_MODE_TUNNEL=m
  602. +CONFIG_INET_XFRM_MODE_BEET=m
  603. +CONFIG_INET_LRO=m
  604. +CONFIG_INET_DIAG=m
  605. +CONFIG_INET6_AH=m
  606. +CONFIG_INET6_ESP=m
  607. +CONFIG_INET6_IPCOMP=m
  608. +CONFIG_IPV6_TUNNEL=m
  609. +CONFIG_IPV6_MULTIPLE_TABLES=y
  610. +CONFIG_IPV6_MROUTE=y
  611. +CONFIG_IPV6_MROUTE_MULTIPLE_TABLES=y
  612. +CONFIG_IPV6_PIMSM_V2=y
  613. +CONFIG_NETFILTER=y
  614. +CONFIG_NF_CONNTRACK=m
  615. +CONFIG_NF_CONNTRACK_ZONES=y
  616. +CONFIG_NF_CONNTRACK_EVENTS=y
  617. +CONFIG_NF_CONNTRACK_TIMESTAMP=y
  618. +CONFIG_NF_CT_PROTO_DCCP=m
  619. +CONFIG_NF_CT_PROTO_UDPLITE=m
  620. +CONFIG_NF_CONNTRACK_AMANDA=m
  621. +CONFIG_NF_CONNTRACK_FTP=m
  622. +CONFIG_NF_CONNTRACK_H323=m
  623. +CONFIG_NF_CONNTRACK_IRC=m
  624. +CONFIG_NF_CONNTRACK_NETBIOS_NS=m
  625. +CONFIG_NF_CONNTRACK_SNMP=m
  626. +CONFIG_NF_CONNTRACK_PPTP=m
  627. +CONFIG_NF_CONNTRACK_SANE=m
  628. +CONFIG_NF_CONNTRACK_SIP=m
  629. +CONFIG_NF_CONNTRACK_TFTP=m
  630. +CONFIG_NF_CT_NETLINK=m
  631. +CONFIG_NETFILTER_XT_SET=m
  632. +CONFIG_NETFILTER_XT_TARGET_AUDIT=m
  633. +CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m
  634. +CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
  635. +CONFIG_NETFILTER_XT_TARGET_CONNMARK=m
  636. +CONFIG_NETFILTER_XT_TARGET_DSCP=m
  637. +CONFIG_NETFILTER_XT_TARGET_HMARK=m
  638. +CONFIG_NETFILTER_XT_TARGET_IDLETIMER=m
  639. +CONFIG_NETFILTER_XT_TARGET_LED=m
  640. +CONFIG_NETFILTER_XT_TARGET_LOG=m
  641. +CONFIG_NETFILTER_XT_TARGET_MARK=m
  642. +CONFIG_NETFILTER_XT_TARGET_NFLOG=m
  643. +CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
  644. +CONFIG_NETFILTER_XT_TARGET_NOTRACK=m
  645. +CONFIG_NETFILTER_XT_TARGET_TEE=m
  646. +CONFIG_NETFILTER_XT_TARGET_TPROXY=m
  647. +CONFIG_NETFILTER_XT_TARGET_TRACE=m
  648. +CONFIG_NETFILTER_XT_TARGET_TCPMSS=m
  649. +CONFIG_NETFILTER_XT_TARGET_TCPOPTSTRIP=m
  650. +CONFIG_NETFILTER_XT_MATCH_ADDRTYPE=m
  651. +CONFIG_NETFILTER_XT_MATCH_BPF=m
  652. +CONFIG_NETFILTER_XT_MATCH_CLUSTER=m
  653. +CONFIG_NETFILTER_XT_MATCH_COMMENT=m
  654. +CONFIG_NETFILTER_XT_MATCH_CONNBYTES=m
  655. +CONFIG_NETFILTER_XT_MATCH_CONNLABEL=m
  656. +CONFIG_NETFILTER_XT_MATCH_CONNLIMIT=m
  657. +CONFIG_NETFILTER_XT_MATCH_CONNMARK=m
  658. +CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m
  659. +CONFIG_NETFILTER_XT_MATCH_CPU=m
  660. +CONFIG_NETFILTER_XT_MATCH_DCCP=m
  661. +CONFIG_NETFILTER_XT_MATCH_DEVGROUP=m
  662. +CONFIG_NETFILTER_XT_MATCH_DSCP=m
  663. +CONFIG_NETFILTER_XT_MATCH_ESP=m
  664. +CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m
  665. +CONFIG_NETFILTER_XT_MATCH_HELPER=m
  666. +CONFIG_NETFILTER_XT_MATCH_IPRANGE=m
  667. +CONFIG_NETFILTER_XT_MATCH_IPVS=m
  668. +CONFIG_NETFILTER_XT_MATCH_LENGTH=m
  669. +CONFIG_NETFILTER_XT_MATCH_LIMIT=m
  670. +CONFIG_NETFILTER_XT_MATCH_MAC=m
  671. +CONFIG_NETFILTER_XT_MATCH_MARK=m
  672. +CONFIG_NETFILTER_XT_MATCH_MULTIPORT=m
  673. +CONFIG_NETFILTER_XT_MATCH_NFACCT=m
  674. +CONFIG_NETFILTER_XT_MATCH_OSF=m
  675. +CONFIG_NETFILTER_XT_MATCH_OWNER=m
  676. +CONFIG_NETFILTER_XT_MATCH_POLICY=m
  677. +CONFIG_NETFILTER_XT_MATCH_PHYSDEV=m
  678. +CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
  679. +CONFIG_NETFILTER_XT_MATCH_QUOTA=m
  680. +CONFIG_NETFILTER_XT_MATCH_RATEEST=m
  681. +CONFIG_NETFILTER_XT_MATCH_REALM=m
  682. +CONFIG_NETFILTER_XT_MATCH_RECENT=m
  683. +CONFIG_NETFILTER_XT_MATCH_SOCKET=m
  684. +CONFIG_NETFILTER_XT_MATCH_STATE=m
  685. +CONFIG_NETFILTER_XT_MATCH_STATISTIC=m
  686. +CONFIG_NETFILTER_XT_MATCH_STRING=m
  687. +CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
  688. +CONFIG_NETFILTER_XT_MATCH_TIME=m
  689. +CONFIG_NETFILTER_XT_MATCH_U32=m
  690. +CONFIG_IP_SET=m
  691. +CONFIG_IP_SET_BITMAP_IP=m
  692. +CONFIG_IP_SET_BITMAP_IPMAC=m
  693. +CONFIG_IP_SET_BITMAP_PORT=m
  694. +CONFIG_IP_SET_HASH_IP=m
  695. +CONFIG_IP_SET_HASH_IPPORT=m
  696. +CONFIG_IP_SET_HASH_IPPORTIP=m
  697. +CONFIG_IP_SET_HASH_IPPORTNET=m
  698. +CONFIG_IP_SET_HASH_NET=m
  699. +CONFIG_IP_SET_HASH_NETPORT=m
  700. +CONFIG_IP_SET_HASH_NETIFACE=m
  701. +CONFIG_IP_SET_LIST_SET=m
  702. +CONFIG_IP_VS=m
  703. +CONFIG_IP_VS_PROTO_TCP=y
  704. +CONFIG_IP_VS_PROTO_UDP=y
  705. +CONFIG_IP_VS_PROTO_ESP=y
  706. +CONFIG_IP_VS_PROTO_AH=y
  707. +CONFIG_IP_VS_PROTO_SCTP=y
  708. +CONFIG_IP_VS_RR=m
  709. +CONFIG_IP_VS_WRR=m
  710. +CONFIG_IP_VS_LC=m
  711. +CONFIG_IP_VS_WLC=m
  712. +CONFIG_IP_VS_LBLC=m
  713. +CONFIG_IP_VS_LBLCR=m
  714. +CONFIG_IP_VS_DH=m
  715. +CONFIG_IP_VS_SH=m
  716. +CONFIG_IP_VS_SED=m
  717. +CONFIG_IP_VS_NQ=m
  718. +CONFIG_IP_VS_FTP=m
  719. +CONFIG_IP_VS_PE_SIP=m
  720. +CONFIG_NF_CONNTRACK_IPV4=m
  721. +CONFIG_IP_NF_IPTABLES=m
  722. +CONFIG_IP_NF_MATCH_AH=m
  723. +CONFIG_IP_NF_MATCH_ECN=m
  724. +CONFIG_IP_NF_MATCH_TTL=m
  725. +CONFIG_IP_NF_FILTER=m
  726. +CONFIG_IP_NF_TARGET_REJECT=m
  727. +CONFIG_IP_NF_TARGET_ULOG=m
  728. +CONFIG_NF_NAT_IPV4=m
  729. +CONFIG_IP_NF_TARGET_MASQUERADE=m
  730. +CONFIG_IP_NF_TARGET_NETMAP=m
  731. +CONFIG_IP_NF_TARGET_REDIRECT=m
  732. +CONFIG_IP_NF_MANGLE=m
  733. +CONFIG_IP_NF_TARGET_ECN=m
  734. +CONFIG_IP_NF_TARGET_TTL=m
  735. +CONFIG_IP_NF_RAW=m
  736. +CONFIG_IP_NF_ARPTABLES=m
  737. +CONFIG_IP_NF_ARPFILTER=m
  738. +CONFIG_IP_NF_ARP_MANGLE=m
  739. +CONFIG_NF_CONNTRACK_IPV6=m
  740. +CONFIG_IP6_NF_IPTABLES=m
  741. +CONFIG_IP6_NF_MATCH_AH=m
  742. +CONFIG_IP6_NF_MATCH_EUI64=m
  743. +CONFIG_IP6_NF_MATCH_FRAG=m
  744. +CONFIG_IP6_NF_MATCH_OPTS=m
  745. +CONFIG_IP6_NF_MATCH_HL=m
  746. +CONFIG_IP6_NF_MATCH_IPV6HEADER=m
  747. +CONFIG_IP6_NF_MATCH_MH=m
  748. +CONFIG_IP6_NF_MATCH_RT=m
  749. +CONFIG_IP6_NF_TARGET_HL=m
  750. +CONFIG_IP6_NF_FILTER=m
  751. +CONFIG_IP6_NF_TARGET_REJECT=m
  752. +CONFIG_IP6_NF_MANGLE=m
  753. +CONFIG_IP6_NF_RAW=m
  754. +CONFIG_NF_NAT_IPV6=m
  755. +CONFIG_IP6_NF_TARGET_MASQUERADE=m
  756. +CONFIG_IP6_NF_TARGET_NPT=m
  757. +CONFIG_BRIDGE_NF_EBTABLES=m
  758. +CONFIG_BRIDGE_EBT_BROUTE=m
  759. +CONFIG_BRIDGE_EBT_T_FILTER=m
  760. +CONFIG_BRIDGE_EBT_T_NAT=m
  761. +CONFIG_BRIDGE_EBT_802_3=m
  762. +CONFIG_BRIDGE_EBT_AMONG=m
  763. +CONFIG_BRIDGE_EBT_ARP=m
  764. +CONFIG_BRIDGE_EBT_IP=m
  765. +CONFIG_BRIDGE_EBT_IP6=m
  766. +CONFIG_BRIDGE_EBT_LIMIT=m
  767. +CONFIG_BRIDGE_EBT_MARK=m
  768. +CONFIG_BRIDGE_EBT_PKTTYPE=m
  769. +CONFIG_BRIDGE_EBT_STP=m
  770. +CONFIG_BRIDGE_EBT_VLAN=m
  771. +CONFIG_BRIDGE_EBT_ARPREPLY=m
  772. +CONFIG_BRIDGE_EBT_DNAT=m
  773. +CONFIG_BRIDGE_EBT_MARK_T=m
  774. +CONFIG_BRIDGE_EBT_REDIRECT=m
  775. +CONFIG_BRIDGE_EBT_SNAT=m
  776. +CONFIG_BRIDGE_EBT_LOG=m
  777. +CONFIG_BRIDGE_EBT_ULOG=m
  778. +CONFIG_BRIDGE_EBT_NFLOG=m
  779. +CONFIG_SCTP_COOKIE_HMAC_SHA1=y
  780. +CONFIG_L2TP=m
  781. +CONFIG_L2TP_V3=y
  782. +CONFIG_L2TP_IP=m
  783. +CONFIG_L2TP_ETH=m
  784. +CONFIG_BRIDGE=m
  785. +CONFIG_VLAN_8021Q=m
  786. +CONFIG_VLAN_8021Q_GVRP=y
  787. +CONFIG_ATALK=m
  788. +CONFIG_NET_SCHED=y
  789. +CONFIG_NET_SCH_CBQ=m
  790. +CONFIG_NET_SCH_HTB=m
  791. +CONFIG_NET_SCH_HFSC=m
  792. +CONFIG_NET_SCH_PRIO=m
  793. +CONFIG_NET_SCH_MULTIQ=m
  794. +CONFIG_NET_SCH_RED=m
  795. +CONFIG_NET_SCH_SFB=m
  796. +CONFIG_NET_SCH_SFQ=m
  797. +CONFIG_NET_SCH_TEQL=m
  798. +CONFIG_NET_SCH_TBF=m
  799. +CONFIG_NET_SCH_GRED=m
  800. +CONFIG_NET_SCH_DSMARK=m
  801. +CONFIG_NET_SCH_NETEM=m
  802. +CONFIG_NET_SCH_DRR=m
  803. +CONFIG_NET_SCH_MQPRIO=m
  804. +CONFIG_NET_SCH_CHOKE=m
  805. +CONFIG_NET_SCH_QFQ=m
  806. +CONFIG_NET_SCH_CODEL=m
  807. +CONFIG_NET_SCH_FQ_CODEL=m
  808. +CONFIG_NET_SCH_INGRESS=m
  809. +CONFIG_NET_SCH_PLUG=m
  810. +CONFIG_NET_CLS_BASIC=m
  811. +CONFIG_NET_CLS_TCINDEX=m
  812. +CONFIG_NET_CLS_ROUTE4=m
  813. +CONFIG_NET_CLS_FW=m
  814. +CONFIG_NET_CLS_U32=m
  815. +CONFIG_CLS_U32_MARK=y
  816. +CONFIG_NET_CLS_RSVP=m
  817. +CONFIG_NET_CLS_RSVP6=m
  818. +CONFIG_NET_CLS_FLOW=m
  819. +CONFIG_NET_CLS_CGROUP=m
  820. +CONFIG_NET_EMATCH=y
  821. +CONFIG_NET_EMATCH_CMP=m
  822. +CONFIG_NET_EMATCH_NBYTE=m
  823. +CONFIG_NET_EMATCH_U32=m
  824. +CONFIG_NET_EMATCH_META=m
  825. +CONFIG_NET_EMATCH_TEXT=m
  826. +CONFIG_NET_EMATCH_IPSET=m
  827. +CONFIG_NET_CLS_ACT=y
  828. +CONFIG_NET_ACT_POLICE=m
  829. +CONFIG_NET_ACT_GACT=m
  830. +CONFIG_GACT_PROB=y
  831. +CONFIG_NET_ACT_MIRRED=m
  832. +CONFIG_NET_ACT_IPT=m
  833. +CONFIG_NET_ACT_NAT=m
  834. +CONFIG_NET_ACT_PEDIT=m
  835. +CONFIG_NET_ACT_SIMP=m
  836. +CONFIG_NET_ACT_SKBEDIT=m
  837. +CONFIG_NET_ACT_CSUM=m
  838. +CONFIG_BATMAN_ADV=m
  839. +CONFIG_OPENVSWITCH=m
  840. +CONFIG_NET_PKTGEN=m
  841. +CONFIG_HAMRADIO=y
  842. +CONFIG_AX25=m
  843. +CONFIG_NETROM=m
  844. +CONFIG_ROSE=m
  845. +CONFIG_MKISS=m
  846. +CONFIG_6PACK=m
  847. +CONFIG_BPQETHER=m
  848. +CONFIG_BAYCOM_SER_FDX=m
  849. +CONFIG_BAYCOM_SER_HDX=m
  850. +CONFIG_YAM=m
  851. +CONFIG_IRDA=m
  852. +CONFIG_IRLAN=m
  853. +CONFIG_IRNET=m
  854. +CONFIG_IRCOMM=m
  855. +CONFIG_IRDA_ULTRA=y
  856. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  857. +CONFIG_IRDA_FAST_RR=y
  858. +CONFIG_IRTTY_SIR=m
  859. +CONFIG_KINGSUN_DONGLE=m
  860. +CONFIG_KSDAZZLE_DONGLE=m
  861. +CONFIG_KS959_DONGLE=m
  862. +CONFIG_USB_IRDA=m
  863. +CONFIG_SIGMATEL_FIR=m
  864. +CONFIG_MCS_FIR=m
  865. +CONFIG_BT=m
  866. +CONFIG_BT_RFCOMM=m
  867. +CONFIG_BT_RFCOMM_TTY=y
  868. +CONFIG_BT_BNEP=m
  869. +CONFIG_BT_BNEP_MC_FILTER=y
  870. +CONFIG_BT_BNEP_PROTO_FILTER=y
  871. +CONFIG_BT_HIDP=m
  872. +CONFIG_BT_HCIBTUSB=m
  873. +CONFIG_BT_HCIBCM203X=m
  874. +CONFIG_BT_HCIBPA10X=m
  875. +CONFIG_BT_HCIBFUSB=m
  876. +CONFIG_BT_HCIVHCI=m
  877. +CONFIG_BT_MRVL=m
  878. +CONFIG_BT_MRVL_SDIO=m
  879. +CONFIG_BT_ATH3K=m
  880. +CONFIG_BT_WILINK=m
  881. +CONFIG_CFG80211=m
  882. +CONFIG_CFG80211_WEXT=y
  883. +CONFIG_MAC80211=m
  884. +CONFIG_MAC80211_RC_PID=y
  885. +CONFIG_MAC80211_MESH=y
  886. +CONFIG_WIMAX=m
  887. +CONFIG_RFKILL=m
  888. +CONFIG_RFKILL_INPUT=y
  889. +CONFIG_NET_9P=m
  890. +CONFIG_NFC=m
  891. +CONFIG_NFC_PN533=m
  892. +CONFIG_DEVTMPFS=y
  893. +CONFIG_DEVTMPFS_MOUNT=y
  894. +CONFIG_DMA_CMA=y
  895. +CONFIG_CMA_SIZE_MBYTES=5
  896. +CONFIG_BLK_DEV_LOOP=y
  897. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  898. +CONFIG_BLK_DEV_DRBD=m
  899. +CONFIG_BLK_DEV_NBD=m
  900. +CONFIG_BLK_DEV_RAM=y
  901. +CONFIG_CDROM_PKTCDVD=m
  902. +CONFIG_SCSI=y
  903. +# CONFIG_SCSI_PROC_FS is not set
  904. +CONFIG_BLK_DEV_SD=y
  905. +CONFIG_CHR_DEV_ST=m
  906. +CONFIG_CHR_DEV_OSST=m
  907. +CONFIG_BLK_DEV_SR=m
  908. +CONFIG_CHR_DEV_SG=m
  909. +CONFIG_SCSI_MULTI_LUN=y
  910. +CONFIG_SCSI_ISCSI_ATTRS=y
  911. +CONFIG_ISCSI_TCP=m
  912. +CONFIG_ISCSI_BOOT_SYSFS=m
  913. +CONFIG_MD=y
  914. +CONFIG_MD_LINEAR=m
  915. +CONFIG_MD_RAID0=m
  916. +CONFIG_BLK_DEV_DM=m
  917. +CONFIG_DM_CRYPT=m
  918. +CONFIG_DM_SNAPSHOT=m
  919. +CONFIG_DM_MIRROR=m
  920. +CONFIG_DM_LOG_USERSPACE=m
  921. +CONFIG_DM_RAID=m
  922. +CONFIG_DM_ZERO=m
  923. +CONFIG_DM_DELAY=m
  924. +CONFIG_NETDEVICES=y
  925. +CONFIG_BONDING=m
  926. +CONFIG_DUMMY=m
  927. +CONFIG_IFB=m
  928. +CONFIG_MACVLAN=m
  929. +CONFIG_NETCONSOLE=m
  930. +CONFIG_TUN=m
  931. +CONFIG_VETH=m
  932. +CONFIG_MDIO_BITBANG=m
  933. +CONFIG_PPP=m
  934. +CONFIG_PPP_BSDCOMP=m
  935. +CONFIG_PPP_DEFLATE=m
  936. +CONFIG_PPP_FILTER=y
  937. +CONFIG_PPP_MPPE=m
  938. +CONFIG_PPP_MULTILINK=y
  939. +CONFIG_PPPOE=m
  940. +CONFIG_PPPOL2TP=m
  941. +CONFIG_PPP_ASYNC=m
  942. +CONFIG_PPP_SYNC_TTY=m
  943. +CONFIG_SLIP=m
  944. +CONFIG_SLIP_COMPRESSED=y
  945. +CONFIG_SLIP_SMART=y
  946. +CONFIG_USB_CATC=m
  947. +CONFIG_USB_KAWETH=m
  948. +CONFIG_USB_PEGASUS=m
  949. +CONFIG_USB_RTL8150=m
  950. +CONFIG_USB_RTL8152=m
  951. +CONFIG_USB_USBNET=y
  952. +CONFIG_USB_NET_AX8817X=m
  953. +CONFIG_USB_NET_AX88179_178A=m
  954. +CONFIG_USB_NET_CDCETHER=m
  955. +CONFIG_USB_NET_CDC_EEM=m
  956. +CONFIG_USB_NET_CDC_NCM=m
  957. +CONFIG_USB_NET_CDC_MBIM=m
  958. +CONFIG_USB_NET_DM9601=m
  959. +CONFIG_USB_NET_SMSC75XX=m
  960. +CONFIG_USB_NET_SMSC95XX=y
  961. +CONFIG_USB_NET_GL620A=m
  962. +CONFIG_USB_NET_NET1080=m
  963. +CONFIG_USB_NET_PLUSB=m
  964. +CONFIG_USB_NET_MCS7830=m
  965. +CONFIG_USB_NET_CDC_SUBSET=m
  966. +CONFIG_USB_ALI_M5632=y
  967. +CONFIG_USB_AN2720=y
  968. +CONFIG_USB_EPSON2888=y
  969. +CONFIG_USB_KC2190=y
  970. +CONFIG_USB_NET_ZAURUS=m
  971. +CONFIG_USB_NET_CX82310_ETH=m
  972. +CONFIG_USB_NET_KALMIA=m
  973. +CONFIG_USB_NET_QMI_WWAN=m
  974. +CONFIG_USB_HSO=m
  975. +CONFIG_USB_NET_INT51X1=m
  976. +CONFIG_USB_IPHETH=m
  977. +CONFIG_USB_SIERRA_NET=m
  978. +CONFIG_USB_VL600=m
  979. +CONFIG_LIBERTAS_THINFIRM=m
  980. +CONFIG_LIBERTAS_THINFIRM_USB=m
  981. +CONFIG_AT76C50X_USB=m
  982. +CONFIG_USB_ZD1201=m
  983. +CONFIG_USB_NET_RNDIS_WLAN=m
  984. +CONFIG_RTL8187=m
  985. +CONFIG_MAC80211_HWSIM=m
  986. +CONFIG_ATH_CARDS=m
  987. +CONFIG_ATH9K=m
  988. +CONFIG_ATH9K_HTC=m
  989. +CONFIG_CARL9170=m
  990. +CONFIG_ATH6KL=m
  991. +CONFIG_ATH6KL_USB=m
  992. +CONFIG_AR5523=m
  993. +CONFIG_B43=m
  994. +# CONFIG_B43_PHY_N is not set
  995. +CONFIG_B43LEGACY=m
  996. +CONFIG_HOSTAP=m
  997. +CONFIG_LIBERTAS=m
  998. +CONFIG_LIBERTAS_USB=m
  999. +CONFIG_LIBERTAS_SDIO=m
  1000. +CONFIG_P54_COMMON=m
  1001. +CONFIG_P54_USB=m
  1002. +CONFIG_RT2X00=m
  1003. +CONFIG_RT2500USB=m
  1004. +CONFIG_RT73USB=m
  1005. +CONFIG_RT2800USB=m
  1006. +CONFIG_RT2800USB_RT3573=y
  1007. +CONFIG_RT2800USB_RT53XX=y
  1008. +CONFIG_RT2800USB_RT55XX=y
  1009. +CONFIG_RT2800USB_UNKNOWN=y
  1010. +CONFIG_RTL8192CU=m
  1011. +CONFIG_ZD1211RW=m
  1012. +CONFIG_MWIFIEX=m
  1013. +CONFIG_MWIFIEX_SDIO=m
  1014. +CONFIG_WIMAX_I2400M_USB=m
  1015. +CONFIG_INPUT_POLLDEV=m
  1016. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  1017. +CONFIG_INPUT_JOYDEV=m
  1018. +CONFIG_INPUT_EVDEV=m
  1019. +# CONFIG_INPUT_KEYBOARD is not set
  1020. +# CONFIG_INPUT_MOUSE is not set
  1021. +CONFIG_INPUT_JOYSTICK=y
  1022. +CONFIG_JOYSTICK_IFORCE=m
  1023. +CONFIG_JOYSTICK_IFORCE_USB=y
  1024. +CONFIG_JOYSTICK_XPAD=m
  1025. +CONFIG_JOYSTICK_XPAD_FF=y
  1026. +CONFIG_INPUT_MISC=y
  1027. +CONFIG_INPUT_AD714X=m
  1028. +CONFIG_INPUT_ATI_REMOTE2=m
  1029. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  1030. +CONFIG_INPUT_POWERMATE=m
  1031. +CONFIG_INPUT_YEALINK=m
  1032. +CONFIG_INPUT_CM109=m
  1033. +CONFIG_INPUT_UINPUT=m
  1034. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  1035. +CONFIG_INPUT_ADXL34X=m
  1036. +CONFIG_INPUT_CMA3000=m
  1037. +CONFIG_SERIO=m
  1038. +CONFIG_SERIO_RAW=m
  1039. +CONFIG_GAMEPORT=m
  1040. +CONFIG_GAMEPORT_NS558=m
  1041. +CONFIG_GAMEPORT_L4=m
  1042. +# CONFIG_LEGACY_PTYS is not set
  1043. +# CONFIG_DEVKMEM is not set
  1044. +CONFIG_SERIAL_AMBA_PL011=y
  1045. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  1046. +CONFIG_TTY_PRINTK=y
  1047. +CONFIG_HW_RANDOM=y
  1048. +CONFIG_HW_RANDOM_BCM2708=m
  1049. +CONFIG_RAW_DRIVER=y
  1050. +CONFIG_BRCM_CHAR_DRIVERS=y
  1051. +CONFIG_BCM_VC_CMA=y
  1052. +CONFIG_I2C=y
  1053. +CONFIG_I2C_CHARDEV=m
  1054. +CONFIG_I2C_BCM2708=m
  1055. +CONFIG_SPI=y
  1056. +CONFIG_SPI_BCM2708=m
  1057. +CONFIG_SPI_SPIDEV=y
  1058. +CONFIG_GPIO_SYSFS=y
  1059. +CONFIG_W1=m
  1060. +CONFIG_W1_MASTER_DS2490=m
  1061. +CONFIG_W1_MASTER_DS2482=m
  1062. +CONFIG_W1_MASTER_DS1WM=m
  1063. +CONFIG_W1_MASTER_GPIO=m
  1064. +CONFIG_W1_SLAVE_THERM=m
  1065. +CONFIG_W1_SLAVE_SMEM=m
  1066. +CONFIG_W1_SLAVE_DS2408=m
  1067. +CONFIG_W1_SLAVE_DS2413=m
  1068. +CONFIG_W1_SLAVE_DS2423=m
  1069. +CONFIG_W1_SLAVE_DS2431=m
  1070. +CONFIG_W1_SLAVE_DS2433=m
  1071. +CONFIG_W1_SLAVE_DS2760=m
  1072. +CONFIG_W1_SLAVE_DS2780=m
  1073. +CONFIG_W1_SLAVE_DS2781=m
  1074. +CONFIG_W1_SLAVE_DS28E04=m
  1075. +CONFIG_W1_SLAVE_BQ27000=m
  1076. +CONFIG_BATTERY_DS2760=m
  1077. +# CONFIG_HWMON is not set
  1078. +CONFIG_THERMAL=y
  1079. +CONFIG_THERMAL_BCM2835=y
  1080. +CONFIG_WATCHDOG=y
  1081. +CONFIG_BCM2708_WDT=m
  1082. +CONFIG_MEDIA_SUPPORT=m
  1083. +CONFIG_MEDIA_CAMERA_SUPPORT=y
  1084. +CONFIG_MEDIA_ANALOG_TV_SUPPORT=y
  1085. +CONFIG_MEDIA_DIGITAL_TV_SUPPORT=y
  1086. +CONFIG_MEDIA_RADIO_SUPPORT=y
  1087. +CONFIG_MEDIA_RC_SUPPORT=y
  1088. +CONFIG_MEDIA_CONTROLLER=y
  1089. +CONFIG_LIRC=m
  1090. +CONFIG_RC_DEVICES=y
  1091. +CONFIG_RC_ATI_REMOTE=m
  1092. +CONFIG_IR_IMON=m
  1093. +CONFIG_IR_MCEUSB=m
  1094. +CONFIG_IR_REDRAT3=m
  1095. +CONFIG_IR_STREAMZAP=m
  1096. +CONFIG_IR_IGUANA=m
  1097. +CONFIG_IR_TTUSBIR=m
  1098. +CONFIG_RC_LOOPBACK=m
  1099. +CONFIG_IR_GPIO_CIR=m
  1100. +CONFIG_MEDIA_USB_SUPPORT=y
  1101. +CONFIG_USB_VIDEO_CLASS=m
  1102. +CONFIG_USB_M5602=m
  1103. +CONFIG_USB_STV06XX=m
  1104. +CONFIG_USB_GL860=m
  1105. +CONFIG_USB_GSPCA_BENQ=m
  1106. +CONFIG_USB_GSPCA_CONEX=m
  1107. +CONFIG_USB_GSPCA_CPIA1=m
  1108. +CONFIG_USB_GSPCA_ETOMS=m
  1109. +CONFIG_USB_GSPCA_FINEPIX=m
  1110. +CONFIG_USB_GSPCA_JEILINJ=m
  1111. +CONFIG_USB_GSPCA_JL2005BCD=m
  1112. +CONFIG_USB_GSPCA_KINECT=m
  1113. +CONFIG_USB_GSPCA_KONICA=m
  1114. +CONFIG_USB_GSPCA_MARS=m
  1115. +CONFIG_USB_GSPCA_MR97310A=m
  1116. +CONFIG_USB_GSPCA_NW80X=m
  1117. +CONFIG_USB_GSPCA_OV519=m
  1118. +CONFIG_USB_GSPCA_OV534=m
  1119. +CONFIG_USB_GSPCA_OV534_9=m
  1120. +CONFIG_USB_GSPCA_PAC207=m
  1121. +CONFIG_USB_GSPCA_PAC7302=m
  1122. +CONFIG_USB_GSPCA_PAC7311=m
  1123. +CONFIG_USB_GSPCA_SE401=m
  1124. +CONFIG_USB_GSPCA_SN9C2028=m
  1125. +CONFIG_USB_GSPCA_SN9C20X=m
  1126. +CONFIG_USB_GSPCA_SONIXB=m
  1127. +CONFIG_USB_GSPCA_SONIXJ=m
  1128. +CONFIG_USB_GSPCA_SPCA500=m
  1129. +CONFIG_USB_GSPCA_SPCA501=m
  1130. +CONFIG_USB_GSPCA_SPCA505=m
  1131. +CONFIG_USB_GSPCA_SPCA506=m
  1132. +CONFIG_USB_GSPCA_SPCA508=m
  1133. +CONFIG_USB_GSPCA_SPCA561=m
  1134. +CONFIG_USB_GSPCA_SPCA1528=m
  1135. +CONFIG_USB_GSPCA_SQ905=m
  1136. +CONFIG_USB_GSPCA_SQ905C=m
  1137. +CONFIG_USB_GSPCA_SQ930X=m
  1138. +CONFIG_USB_GSPCA_STK014=m
  1139. +CONFIG_USB_GSPCA_STV0680=m
  1140. +CONFIG_USB_GSPCA_SUNPLUS=m
  1141. +CONFIG_USB_GSPCA_T613=m
  1142. +CONFIG_USB_GSPCA_TOPRO=m
  1143. +CONFIG_USB_GSPCA_TV8532=m
  1144. +CONFIG_USB_GSPCA_VC032X=m
  1145. +CONFIG_USB_GSPCA_VICAM=m
  1146. +CONFIG_USB_GSPCA_XIRLINK_CIT=m
  1147. +CONFIG_USB_GSPCA_ZC3XX=m
  1148. +CONFIG_USB_PWC=m
  1149. +CONFIG_VIDEO_CPIA2=m
  1150. +CONFIG_USB_ZR364XX=m
  1151. +CONFIG_USB_STKWEBCAM=m
  1152. +CONFIG_USB_S2255=m
  1153. +CONFIG_VIDEO_PVRUSB2=m
  1154. +CONFIG_VIDEO_HDPVR=m
  1155. +CONFIG_VIDEO_TLG2300=m
  1156. +CONFIG_VIDEO_USBVISION=m
  1157. +CONFIG_VIDEO_AU0828=m
  1158. +CONFIG_VIDEO_CX231XX=m
  1159. +CONFIG_VIDEO_CX231XX_ALSA=m
  1160. +CONFIG_VIDEO_CX231XX_DVB=m
  1161. +CONFIG_VIDEO_TM6000=m
  1162. +CONFIG_VIDEO_TM6000_ALSA=m
  1163. +CONFIG_VIDEO_TM6000_DVB=m
  1164. +CONFIG_DVB_USB=m
  1165. +CONFIG_DVB_USB_A800=m
  1166. +CONFIG_DVB_USB_DIBUSB_MB=m
  1167. +CONFIG_DVB_USB_DIBUSB_MB_FAULTY=y
  1168. +CONFIG_DVB_USB_DIBUSB_MC=m
  1169. +CONFIG_DVB_USB_DIB0700=m
  1170. +CONFIG_DVB_USB_UMT_010=m
  1171. +CONFIG_DVB_USB_CXUSB=m
  1172. +CONFIG_DVB_USB_M920X=m
  1173. +CONFIG_DVB_USB_DIGITV=m
  1174. +CONFIG_DVB_USB_VP7045=m
  1175. +CONFIG_DVB_USB_VP702X=m
  1176. +CONFIG_DVB_USB_GP8PSK=m
  1177. +CONFIG_DVB_USB_NOVA_T_USB2=m
  1178. +CONFIG_DVB_USB_TTUSB2=m
  1179. +CONFIG_DVB_USB_DTT200U=m
  1180. +CONFIG_DVB_USB_OPERA1=m
  1181. +CONFIG_DVB_USB_AF9005=m
  1182. +CONFIG_DVB_USB_AF9005_REMOTE=m
  1183. +CONFIG_DVB_USB_PCTV452E=m
  1184. +CONFIG_DVB_USB_DW2102=m
  1185. +CONFIG_DVB_USB_CINERGY_T2=m
  1186. +CONFIG_DVB_USB_DTV5100=m
  1187. +CONFIG_DVB_USB_FRIIO=m
  1188. +CONFIG_DVB_USB_AZ6027=m
  1189. +CONFIG_DVB_USB_TECHNISAT_USB2=m
  1190. +CONFIG_DVB_USB_V2=m
  1191. +CONFIG_DVB_USB_AF9015=m
  1192. +CONFIG_DVB_USB_AF9035=m
  1193. +CONFIG_DVB_USB_ANYSEE=m
  1194. +CONFIG_DVB_USB_AU6610=m
  1195. +CONFIG_DVB_USB_AZ6007=m
  1196. +CONFIG_DVB_USB_CE6230=m
  1197. +CONFIG_DVB_USB_EC168=m
  1198. +CONFIG_DVB_USB_GL861=m
  1199. +CONFIG_DVB_USB_IT913X=m
  1200. +CONFIG_DVB_USB_LME2510=m
  1201. +CONFIG_DVB_USB_MXL111SF=m
  1202. +CONFIG_DVB_USB_RTL28XXU=m
  1203. +CONFIG_SMS_USB_DRV=m
  1204. +CONFIG_DVB_B2C2_FLEXCOP_USB=m
  1205. +CONFIG_VIDEO_EM28XX=m
  1206. +CONFIG_VIDEO_EM28XX_ALSA=m
  1207. +CONFIG_VIDEO_EM28XX_DVB=m
  1208. +CONFIG_V4L_PLATFORM_DRIVERS=y
  1209. +CONFIG_VIDEO_BCM2835=y
  1210. +CONFIG_VIDEO_BCM2835_MMAL=m
  1211. +CONFIG_RADIO_SI470X=y
  1212. +CONFIG_USB_SI470X=m
  1213. +CONFIG_I2C_SI470X=m
  1214. +CONFIG_RADIO_SI4713=m
  1215. +CONFIG_USB_MR800=m
  1216. +CONFIG_USB_DSBR=m
  1217. +CONFIG_RADIO_SHARK=m
  1218. +CONFIG_RADIO_SHARK2=m
  1219. +CONFIG_USB_KEENE=m
  1220. +CONFIG_USB_MA901=m
  1221. +CONFIG_RADIO_TEA5764=m
  1222. +CONFIG_RADIO_SAA7706H=m
  1223. +CONFIG_RADIO_TEF6862=m
  1224. +CONFIG_RADIO_WL1273=m
  1225. +CONFIG_RADIO_WL128X=m
  1226. +CONFIG_FB=y
  1227. +CONFIG_FB_BCM2708=y
  1228. +# CONFIG_BACKLIGHT_GENERIC is not set
  1229. +CONFIG_FRAMEBUFFER_CONSOLE=y
  1230. +CONFIG_LOGO=y
  1231. +# CONFIG_LOGO_LINUX_MONO is not set
  1232. +# CONFIG_LOGO_LINUX_VGA16 is not set
  1233. +CONFIG_SOUND=y
  1234. +CONFIG_SND=m
  1235. +CONFIG_SND_SEQUENCER=m
  1236. +CONFIG_SND_SEQ_DUMMY=m
  1237. +CONFIG_SND_MIXER_OSS=m
  1238. +CONFIG_SND_PCM_OSS=m
  1239. +CONFIG_SND_SEQUENCER_OSS=y
  1240. +CONFIG_SND_HRTIMER=m
  1241. +CONFIG_SND_DUMMY=m
  1242. +CONFIG_SND_ALOOP=m
  1243. +CONFIG_SND_VIRMIDI=m
  1244. +CONFIG_SND_MTPAV=m
  1245. +CONFIG_SND_SERIAL_U16550=m
  1246. +CONFIG_SND_MPU401=m
  1247. +CONFIG_SND_BCM2835=m
  1248. +CONFIG_SND_USB_AUDIO=m
  1249. +CONFIG_SND_USB_UA101=m
  1250. +CONFIG_SND_USB_CAIAQ=m
  1251. +CONFIG_SND_USB_CAIAQ_INPUT=y
  1252. +CONFIG_SND_USB_6FIRE=m
  1253. +CONFIG_SND_SOC=m
  1254. +CONFIG_SND_SOC_DMAENGINE_PCM=y
  1255. +CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM=y
  1256. +CONFIG_SND_SOC_WM8804=m
  1257. +CONFIG_SND_BCM2708_SOC_I2S=m
  1258. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
  1259. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI=m
  1260. +CONFIG_SND_BCM2708_SOC_RPI_DAC=m
  1261. +CONFIG_SND_SOC_I2C_AND_SPI=m
  1262. +CONFIG_SND_SOC_PCM5102A=m
  1263. +CONFIG_SND_SOC_PCM1794A=m
  1264. +CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
  1265. +CONFIG_SOUND_PRIME=m
  1266. +CONFIG_HIDRAW=y
  1267. +CONFIG_HID_A4TECH=m
  1268. +CONFIG_HID_ACRUX=m
  1269. +CONFIG_HID_APPLE=m
  1270. +CONFIG_HID_BELKIN=m
  1271. +CONFIG_HID_CHERRY=m
  1272. +CONFIG_HID_CHICONY=m
  1273. +CONFIG_HID_CYPRESS=m
  1274. +CONFIG_HID_DRAGONRISE=m
  1275. +CONFIG_HID_EMS_FF=m
  1276. +CONFIG_HID_ELECOM=m
  1277. +CONFIG_HID_EZKEY=m
  1278. +CONFIG_HID_HOLTEK=m
  1279. +CONFIG_HID_KEYTOUCH=m
  1280. +CONFIG_HID_KYE=m
  1281. +CONFIG_HID_UCLOGIC=m
  1282. +CONFIG_HID_WALTOP=m
  1283. +CONFIG_HID_GYRATION=m
  1284. +CONFIG_HID_TWINHAN=m
  1285. +CONFIG_HID_KENSINGTON=m
  1286. +CONFIG_HID_LCPOWER=m
  1287. +CONFIG_HID_LOGITECH=m
  1288. +CONFIG_HID_MAGICMOUSE=m
  1289. +CONFIG_HID_MICROSOFT=m
  1290. +CONFIG_HID_MONTEREY=m
  1291. +CONFIG_HID_MULTITOUCH=m
  1292. +CONFIG_HID_NTRIG=m
  1293. +CONFIG_HID_ORTEK=m
  1294. +CONFIG_HID_PANTHERLORD=m
  1295. +CONFIG_HID_PETALYNX=m
  1296. +CONFIG_HID_PICOLCD=m
  1297. +CONFIG_HID_ROCCAT=m
  1298. +CONFIG_HID_SAMSUNG=m
  1299. +CONFIG_HID_SONY=m
  1300. +CONFIG_HID_SPEEDLINK=m
  1301. +CONFIG_HID_SUNPLUS=m
  1302. +CONFIG_HID_GREENASIA=m
  1303. +CONFIG_HID_SMARTJOYPLUS=m
  1304. +CONFIG_HID_TOPSEED=m
  1305. +CONFIG_HID_THINGM=m
  1306. +CONFIG_HID_THRUSTMASTER=m
  1307. +CONFIG_HID_WACOM=m
  1308. +CONFIG_HID_WIIMOTE=m
  1309. +CONFIG_HID_XINMO=m
  1310. +CONFIG_HID_ZEROPLUS=m
  1311. +CONFIG_HID_ZYDACRON=m
  1312. +CONFIG_HID_PID=y
  1313. +CONFIG_USB_HIDDEV=y
  1314. +CONFIG_USB=y
  1315. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  1316. +CONFIG_USB_MON=m
  1317. +CONFIG_USB_DWCOTG=y
  1318. +CONFIG_USB_PRINTER=m
  1319. +CONFIG_USB_STORAGE=y
  1320. +CONFIG_USB_STORAGE_REALTEK=m
  1321. +CONFIG_USB_STORAGE_DATAFAB=m
  1322. +CONFIG_USB_STORAGE_FREECOM=m
  1323. +CONFIG_USB_STORAGE_ISD200=m
  1324. +CONFIG_USB_STORAGE_USBAT=m
  1325. +CONFIG_USB_STORAGE_SDDR09=m
  1326. +CONFIG_USB_STORAGE_SDDR55=m
  1327. +CONFIG_USB_STORAGE_JUMPSHOT=m
  1328. +CONFIG_USB_STORAGE_ALAUDA=m
  1329. +CONFIG_USB_STORAGE_ONETOUCH=m
  1330. +CONFIG_USB_STORAGE_KARMA=m
  1331. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  1332. +CONFIG_USB_STORAGE_ENE_UB6250=m
  1333. +CONFIG_USB_MDC800=m
  1334. +CONFIG_USB_MICROTEK=m
  1335. +CONFIG_USB_SERIAL=m
  1336. +CONFIG_USB_SERIAL_GENERIC=y
  1337. +CONFIG_USB_SERIAL_AIRCABLE=m
  1338. +CONFIG_USB_SERIAL_ARK3116=m
  1339. +CONFIG_USB_SERIAL_BELKIN=m
  1340. +CONFIG_USB_SERIAL_CH341=m
  1341. +CONFIG_USB_SERIAL_WHITEHEAT=m
  1342. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  1343. +CONFIG_USB_SERIAL_CP210X=m
  1344. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  1345. +CONFIG_USB_SERIAL_EMPEG=m
  1346. +CONFIG_USB_SERIAL_FTDI_SIO=m
  1347. +CONFIG_USB_SERIAL_VISOR=m
  1348. +CONFIG_USB_SERIAL_IPAQ=m
  1349. +CONFIG_USB_SERIAL_IR=m
  1350. +CONFIG_USB_SERIAL_EDGEPORT=m
  1351. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  1352. +CONFIG_USB_SERIAL_F81232=m
  1353. +CONFIG_USB_SERIAL_GARMIN=m
  1354. +CONFIG_USB_SERIAL_IPW=m
  1355. +CONFIG_USB_SERIAL_IUU=m
  1356. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  1357. +CONFIG_USB_SERIAL_KEYSPAN=m
  1358. +CONFIG_USB_SERIAL_KLSI=m
  1359. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  1360. +CONFIG_USB_SERIAL_MCT_U232=m
  1361. +CONFIG_USB_SERIAL_METRO=m
  1362. +CONFIG_USB_SERIAL_MOS7720=m
  1363. +CONFIG_USB_SERIAL_MOS7840=m
  1364. +CONFIG_USB_SERIAL_NAVMAN=m
  1365. +CONFIG_USB_SERIAL_PL2303=m
  1366. +CONFIG_USB_SERIAL_OTI6858=m
  1367. +CONFIG_USB_SERIAL_QCAUX=m
  1368. +CONFIG_USB_SERIAL_QUALCOMM=m
  1369. +CONFIG_USB_SERIAL_SPCP8X5=m
  1370. +CONFIG_USB_SERIAL_SAFE=m
  1371. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  1372. +CONFIG_USB_SERIAL_SYMBOL=m
  1373. +CONFIG_USB_SERIAL_TI=m
  1374. +CONFIG_USB_SERIAL_CYBERJACK=m
  1375. +CONFIG_USB_SERIAL_XIRCOM=m
  1376. +CONFIG_USB_SERIAL_OPTION=m
  1377. +CONFIG_USB_SERIAL_OMNINET=m
  1378. +CONFIG_USB_SERIAL_OPTICON=m
  1379. +CONFIG_USB_SERIAL_XSENS_MT=m
  1380. +CONFIG_USB_SERIAL_WISHBONE=m
  1381. +CONFIG_USB_SERIAL_ZTE=m
  1382. +CONFIG_USB_SERIAL_SSU100=m
  1383. +CONFIG_USB_SERIAL_QT2=m
  1384. +CONFIG_USB_SERIAL_DEBUG=m
  1385. +CONFIG_USB_EMI62=m
  1386. +CONFIG_USB_EMI26=m
  1387. +CONFIG_USB_ADUTUX=m
  1388. +CONFIG_USB_SEVSEG=m
  1389. +CONFIG_USB_RIO500=m
  1390. +CONFIG_USB_LEGOTOWER=m
  1391. +CONFIG_USB_LCD=m
  1392. +CONFIG_USB_LED=m
  1393. +CONFIG_USB_CYPRESS_CY7C63=m
  1394. +CONFIG_USB_CYTHERM=m
  1395. +CONFIG_USB_IDMOUSE=m
  1396. +CONFIG_USB_FTDI_ELAN=m
  1397. +CONFIG_USB_APPLEDISPLAY=m
  1398. +CONFIG_USB_LD=m
  1399. +CONFIG_USB_TRANCEVIBRATOR=m
  1400. +CONFIG_USB_IOWARRIOR=m
  1401. +CONFIG_USB_TEST=m
  1402. +CONFIG_USB_ISIGHTFW=m
  1403. +CONFIG_USB_YUREX=m
  1404. +CONFIG_MMC=y
  1405. +CONFIG_MMC_BLOCK_MINORS=32
  1406. +CONFIG_MMC_SDHCI=y
  1407. +CONFIG_MMC_SDHCI_PLTFM=y
  1408. +CONFIG_MMC_SDHCI_BCM2708=y
  1409. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  1410. +CONFIG_MMC_SPI=m
  1411. +CONFIG_LEDS_GPIO=m
  1412. +CONFIG_LEDS_TRIGGER_TIMER=y
  1413. +CONFIG_LEDS_TRIGGER_ONESHOT=y
  1414. +CONFIG_LEDS_TRIGGER_HEARTBEAT=y
  1415. +CONFIG_LEDS_TRIGGER_BACKLIGHT=y
  1416. +CONFIG_LEDS_TRIGGER_CPU=y
  1417. +CONFIG_LEDS_TRIGGER_GPIO=y
  1418. +CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
  1419. +CONFIG_LEDS_TRIGGER_TRANSIENT=m
  1420. +CONFIG_LEDS_TRIGGER_CAMERA=m
  1421. +CONFIG_RTC_CLASS=y
  1422. +# CONFIG_RTC_HCTOSYS is not set
  1423. +CONFIG_RTC_DRV_DS1307=m
  1424. +CONFIG_RTC_DRV_DS1374=m
  1425. +CONFIG_RTC_DRV_DS1672=m
  1426. +CONFIG_RTC_DRV_DS3232=m
  1427. +CONFIG_RTC_DRV_MAX6900=m
  1428. +CONFIG_RTC_DRV_RS5C372=m
  1429. +CONFIG_RTC_DRV_ISL1208=m
  1430. +CONFIG_RTC_DRV_ISL12022=m
  1431. +CONFIG_RTC_DRV_ISL12057=m
  1432. +CONFIG_RTC_DRV_X1205=m
  1433. +CONFIG_RTC_DRV_PCF2127=m
  1434. +CONFIG_RTC_DRV_PCF8523=m
  1435. +CONFIG_RTC_DRV_PCF8563=m
  1436. +CONFIG_RTC_DRV_PCF8583=m
  1437. +CONFIG_RTC_DRV_M41T80=m
  1438. +CONFIG_RTC_DRV_BQ32K=m
  1439. +CONFIG_RTC_DRV_S35390A=m
  1440. +CONFIG_RTC_DRV_FM3130=m
  1441. +CONFIG_RTC_DRV_RX8581=m
  1442. +CONFIG_RTC_DRV_RX8025=m
  1443. +CONFIG_RTC_DRV_EM3027=m
  1444. +CONFIG_RTC_DRV_RV3029C2=m
  1445. +CONFIG_RTC_DRV_M41T93=m
  1446. +CONFIG_RTC_DRV_M41T94=m
  1447. +CONFIG_RTC_DRV_DS1305=m
  1448. +CONFIG_RTC_DRV_DS1390=m
  1449. +CONFIG_RTC_DRV_MAX6902=m
  1450. +CONFIG_RTC_DRV_R9701=m
  1451. +CONFIG_RTC_DRV_RS5C348=m
  1452. +CONFIG_RTC_DRV_DS3234=m
  1453. +CONFIG_RTC_DRV_PCF2123=m
  1454. +CONFIG_RTC_DRV_RX4581=m
  1455. +CONFIG_DMADEVICES=y
  1456. +CONFIG_DMA_BCM2708=m
  1457. +CONFIG_DMA_ENGINE=y
  1458. +CONFIG_DMA_VIRTUAL_CHANNELS=m
  1459. +CONFIG_UIO=m
  1460. +CONFIG_UIO_PDRV_GENIRQ=m
  1461. +CONFIG_STAGING=y
  1462. +CONFIG_W35UND=m
  1463. +CONFIG_PRISM2_USB=m
  1464. +CONFIG_R8712U=m
  1465. +CONFIG_VT6656=m
  1466. +CONFIG_SPEAKUP=m
  1467. +CONFIG_SPEAKUP_SYNTH_SOFT=m
  1468. +CONFIG_STAGING_MEDIA=y
  1469. +CONFIG_DVB_AS102=m
  1470. +CONFIG_USB_SN9C102=m
  1471. +CONFIG_LIRC_STAGING=y
  1472. +CONFIG_LIRC_IGORPLUGUSB=m
  1473. +CONFIG_LIRC_IMON=m
  1474. +CONFIG_LIRC_RPI=m
  1475. +CONFIG_LIRC_SASEM=m
  1476. +CONFIG_LIRC_SERIAL=m
  1477. +# CONFIG_IOMMU_SUPPORT is not set
  1478. +CONFIG_EXT4_FS=y
  1479. +CONFIG_EXT4_FS_POSIX_ACL=y
  1480. +CONFIG_EXT4_FS_SECURITY=y
  1481. +CONFIG_REISERFS_FS=m
  1482. +CONFIG_REISERFS_FS_XATTR=y
  1483. +CONFIG_REISERFS_FS_POSIX_ACL=y
  1484. +CONFIG_REISERFS_FS_SECURITY=y
  1485. +CONFIG_JFS_FS=m
  1486. +CONFIG_JFS_POSIX_ACL=y
  1487. +CONFIG_JFS_SECURITY=y
  1488. +CONFIG_JFS_STATISTICS=y
  1489. +CONFIG_XFS_FS=m
  1490. +CONFIG_XFS_QUOTA=y
  1491. +CONFIG_XFS_POSIX_ACL=y
  1492. +CONFIG_XFS_RT=y
  1493. +CONFIG_GFS2_FS=m
  1494. +CONFIG_OCFS2_FS=m
  1495. +CONFIG_BTRFS_FS=m
  1496. +CONFIG_BTRFS_FS_POSIX_ACL=y
  1497. +CONFIG_NILFS2_FS=m
  1498. +CONFIG_FANOTIFY=y
  1499. +CONFIG_QFMT_V1=m
  1500. +CONFIG_QFMT_V2=m
  1501. +CONFIG_AUTOFS4_FS=y
  1502. +CONFIG_FUSE_FS=m
  1503. +CONFIG_CUSE=m
  1504. +CONFIG_FSCACHE=y
  1505. +CONFIG_FSCACHE_STATS=y
  1506. +CONFIG_FSCACHE_HISTOGRAM=y
  1507. +CONFIG_CACHEFILES=y
  1508. +CONFIG_ISO9660_FS=m
  1509. +CONFIG_JOLIET=y
  1510. +CONFIG_ZISOFS=y
  1511. +CONFIG_UDF_FS=m
  1512. +CONFIG_MSDOS_FS=y
  1513. +CONFIG_VFAT_FS=y
  1514. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  1515. +CONFIG_NTFS_FS=m
  1516. +CONFIG_NTFS_RW=y
  1517. +CONFIG_TMPFS=y
  1518. +CONFIG_TMPFS_POSIX_ACL=y
  1519. +CONFIG_CONFIGFS_FS=y
  1520. +CONFIG_ECRYPT_FS=m
  1521. +CONFIG_HFS_FS=m
  1522. +CONFIG_HFSPLUS_FS=m
  1523. +CONFIG_SQUASHFS=m
  1524. +CONFIG_SQUASHFS_XATTR=y
  1525. +CONFIG_SQUASHFS_LZO=y
  1526. +CONFIG_SQUASHFS_XZ=y
  1527. +CONFIG_F2FS_FS=y
  1528. +CONFIG_NFS_FS=y
  1529. +CONFIG_NFS_V3_ACL=y
  1530. +CONFIG_NFS_V4=y
  1531. +CONFIG_ROOT_NFS=y
  1532. +CONFIG_NFS_FSCACHE=y
  1533. +CONFIG_NFSD=m
  1534. +CONFIG_NFSD_V3_ACL=y
  1535. +CONFIG_NFSD_V4=y
  1536. +CONFIG_CIFS=m
  1537. +CONFIG_CIFS_WEAK_PW_HASH=y
  1538. +CONFIG_CIFS_XATTR=y
  1539. +CONFIG_CIFS_POSIX=y
  1540. +CONFIG_9P_FS=m
  1541. +CONFIG_9P_FS_POSIX_ACL=y
  1542. +CONFIG_NLS_DEFAULT="utf8"
  1543. +CONFIG_NLS_CODEPAGE_437=y
  1544. +CONFIG_NLS_CODEPAGE_737=m
  1545. +CONFIG_NLS_CODEPAGE_775=m
  1546. +CONFIG_NLS_CODEPAGE_850=m
  1547. +CONFIG_NLS_CODEPAGE_852=m
  1548. +CONFIG_NLS_CODEPAGE_855=m
  1549. +CONFIG_NLS_CODEPAGE_857=m
  1550. +CONFIG_NLS_CODEPAGE_860=m
  1551. +CONFIG_NLS_CODEPAGE_861=m
  1552. +CONFIG_NLS_CODEPAGE_862=m
  1553. +CONFIG_NLS_CODEPAGE_863=m
  1554. +CONFIG_NLS_CODEPAGE_864=m
  1555. +CONFIG_NLS_CODEPAGE_865=m
  1556. +CONFIG_NLS_CODEPAGE_866=m
  1557. +CONFIG_NLS_CODEPAGE_869=m
  1558. +CONFIG_NLS_CODEPAGE_936=m
  1559. +CONFIG_NLS_CODEPAGE_950=m
  1560. +CONFIG_NLS_CODEPAGE_932=m
  1561. +CONFIG_NLS_CODEPAGE_949=m
  1562. +CONFIG_NLS_CODEPAGE_874=m
  1563. +CONFIG_NLS_ISO8859_8=m
  1564. +CONFIG_NLS_CODEPAGE_1250=m
  1565. +CONFIG_NLS_CODEPAGE_1251=m
  1566. +CONFIG_NLS_ASCII=y
  1567. +CONFIG_NLS_ISO8859_1=m
  1568. +CONFIG_NLS_ISO8859_2=m
  1569. +CONFIG_NLS_ISO8859_3=m
  1570. +CONFIG_NLS_ISO8859_4=m
  1571. +CONFIG_NLS_ISO8859_5=m
  1572. +CONFIG_NLS_ISO8859_6=m
  1573. +CONFIG_NLS_ISO8859_7=m
  1574. +CONFIG_NLS_ISO8859_9=m
  1575. +CONFIG_NLS_ISO8859_13=m
  1576. +CONFIG_NLS_ISO8859_14=m
  1577. +CONFIG_NLS_ISO8859_15=m
  1578. +CONFIG_NLS_KOI8_R=m
  1579. +CONFIG_NLS_KOI8_U=m
  1580. +CONFIG_DLM=m
  1581. +CONFIG_PRINTK_TIME=y
  1582. +CONFIG_BOOT_PRINTK_DELAY=y
  1583. +CONFIG_DEBUG_FS=y
  1584. +CONFIG_DEBUG_MEMORY_INIT=y
  1585. +CONFIG_DETECT_HUNG_TASK=y
  1586. +CONFIG_TIMER_STATS=y
  1587. +# CONFIG_DEBUG_PREEMPT is not set
  1588. +CONFIG_LATENCYTOP=y
  1589. +# CONFIG_KPROBE_EVENT is not set
  1590. +CONFIG_KGDB=y
  1591. +CONFIG_KGDB_KDB=y
  1592. +CONFIG_KDB_KEYBOARD=y
  1593. +CONFIG_STRICT_DEVMEM=y
  1594. +CONFIG_CRYPTO_USER=m
  1595. +CONFIG_CRYPTO_NULL=m
  1596. +CONFIG_CRYPTO_CRYPTD=m
  1597. +CONFIG_CRYPTO_CBC=y
  1598. +CONFIG_CRYPTO_XTS=m
  1599. +CONFIG_CRYPTO_XCBC=m
  1600. +CONFIG_CRYPTO_SHA1_ARM=m
  1601. +CONFIG_CRYPTO_SHA512=m
  1602. +CONFIG_CRYPTO_TGR192=m
  1603. +CONFIG_CRYPTO_WP512=m
  1604. +CONFIG_CRYPTO_AES_ARM=m
  1605. +CONFIG_CRYPTO_CAST5=m
  1606. +CONFIG_CRYPTO_DES=y
  1607. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  1608. +# CONFIG_CRYPTO_HW is not set
  1609. +CONFIG_CRC_ITU_T=y
  1610. +CONFIG_LIBCRC32C=y
  1611. diff -Nur linux-3.15.4/arch/arm/configs/bcmrpi_emergency_defconfig linux-rpi/arch/arm/configs/bcmrpi_emergency_defconfig
  1612. --- linux-3.15.4/arch/arm/configs/bcmrpi_emergency_defconfig 1970-01-01 01:00:00.000000000 +0100
  1613. +++ linux-rpi/arch/arm/configs/bcmrpi_emergency_defconfig 2014-07-07 10:44:57.000000000 +0200
  1614. @@ -0,0 +1,532 @@
  1615. +CONFIG_EXPERIMENTAL=y
  1616. +# CONFIG_LOCALVERSION_AUTO is not set
  1617. +CONFIG_SYSVIPC=y
  1618. +CONFIG_POSIX_MQUEUE=y
  1619. +CONFIG_BSD_PROCESS_ACCT=y
  1620. +CONFIG_BSD_PROCESS_ACCT_V3=y
  1621. +CONFIG_FHANDLE=y
  1622. +CONFIG_AUDIT=y
  1623. +CONFIG_IKCONFIG=y
  1624. +CONFIG_IKCONFIG_PROC=y
  1625. +CONFIG_BLK_DEV_INITRD=y
  1626. +CONFIG_INITRAMFS_SOURCE="../target_fs"
  1627. +CONFIG_CGROUP_FREEZER=y
  1628. +CONFIG_CGROUP_DEVICE=y
  1629. +CONFIG_CGROUP_CPUACCT=y
  1630. +CONFIG_RESOURCE_COUNTERS=y
  1631. +CONFIG_BLK_CGROUP=y
  1632. +CONFIG_NAMESPACES=y
  1633. +CONFIG_SCHED_AUTOGROUP=y
  1634. +CONFIG_EMBEDDED=y
  1635. +# CONFIG_COMPAT_BRK is not set
  1636. +CONFIG_SLAB=y
  1637. +CONFIG_PROFILING=y
  1638. +CONFIG_OPROFILE=m
  1639. +CONFIG_KPROBES=y
  1640. +CONFIG_MODULES=y
  1641. +CONFIG_MODULE_UNLOAD=y
  1642. +CONFIG_MODVERSIONS=y
  1643. +CONFIG_MODULE_SRCVERSION_ALL=y
  1644. +# CONFIG_BLK_DEV_BSG is not set
  1645. +CONFIG_BLK_DEV_THROTTLING=y
  1646. +CONFIG_CFQ_GROUP_IOSCHED=y
  1647. +CONFIG_ARCH_BCM2708=y
  1648. +CONFIG_NO_HZ=y
  1649. +CONFIG_HIGH_RES_TIMERS=y
  1650. +CONFIG_AEABI=y
  1651. +CONFIG_SECCOMP=y
  1652. +CONFIG_CC_STACKPROTECTOR=y
  1653. +CONFIG_ZBOOT_ROM_TEXT=0x0
  1654. +CONFIG_ZBOOT_ROM_BSS=0x0
  1655. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext3 rootwait"
  1656. +CONFIG_KEXEC=y
  1657. +CONFIG_CPU_IDLE=y
  1658. +CONFIG_VFP=y
  1659. +CONFIG_BINFMT_MISC=m
  1660. +CONFIG_NET=y
  1661. +CONFIG_PACKET=y
  1662. +CONFIG_UNIX=y
  1663. +CONFIG_XFRM_USER=y
  1664. +CONFIG_NET_KEY=m
  1665. +CONFIG_INET=y
  1666. +CONFIG_IP_MULTICAST=y
  1667. +CONFIG_IP_PNP=y
  1668. +CONFIG_IP_PNP_DHCP=y
  1669. +CONFIG_IP_PNP_RARP=y
  1670. +CONFIG_SYN_COOKIES=y
  1671. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  1672. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  1673. +# CONFIG_INET_XFRM_MODE_BEET is not set
  1674. +# CONFIG_INET_LRO is not set
  1675. +# CONFIG_INET_DIAG is not set
  1676. +# CONFIG_IPV6 is not set
  1677. +CONFIG_NET_PKTGEN=m
  1678. +CONFIG_IRDA=m
  1679. +CONFIG_IRLAN=m
  1680. +CONFIG_IRCOMM=m
  1681. +CONFIG_IRDA_ULTRA=y
  1682. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  1683. +CONFIG_IRDA_FAST_RR=y
  1684. +CONFIG_IRTTY_SIR=m
  1685. +CONFIG_KINGSUN_DONGLE=m
  1686. +CONFIG_KSDAZZLE_DONGLE=m
  1687. +CONFIG_KS959_DONGLE=m
  1688. +CONFIG_USB_IRDA=m
  1689. +CONFIG_SIGMATEL_FIR=m
  1690. +CONFIG_MCS_FIR=m
  1691. +CONFIG_BT=m
  1692. +CONFIG_BT_L2CAP=y
  1693. +CONFIG_BT_SCO=y
  1694. +CONFIG_BT_RFCOMM=m
  1695. +CONFIG_BT_RFCOMM_TTY=y
  1696. +CONFIG_BT_BNEP=m
  1697. +CONFIG_BT_BNEP_MC_FILTER=y
  1698. +CONFIG_BT_BNEP_PROTO_FILTER=y
  1699. +CONFIG_BT_HIDP=m
  1700. +CONFIG_BT_HCIBTUSB=m
  1701. +CONFIG_BT_HCIBCM203X=m
  1702. +CONFIG_BT_HCIBPA10X=m
  1703. +CONFIG_BT_HCIBFUSB=m
  1704. +CONFIG_BT_HCIVHCI=m
  1705. +CONFIG_BT_MRVL=m
  1706. +CONFIG_BT_MRVL_SDIO=m
  1707. +CONFIG_BT_ATH3K=m
  1708. +CONFIG_CFG80211=m
  1709. +CONFIG_MAC80211=m
  1710. +CONFIG_MAC80211_RC_PID=y
  1711. +CONFIG_MAC80211_MESH=y
  1712. +CONFIG_WIMAX=m
  1713. +CONFIG_NET_9P=m
  1714. +CONFIG_NFC=m
  1715. +CONFIG_NFC_PN533=m
  1716. +CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
  1717. +CONFIG_BLK_DEV_LOOP=y
  1718. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  1719. +CONFIG_BLK_DEV_NBD=m
  1720. +CONFIG_BLK_DEV_RAM=y
  1721. +CONFIG_CDROM_PKTCDVD=m
  1722. +CONFIG_MISC_DEVICES=y
  1723. +CONFIG_SCSI=y
  1724. +# CONFIG_SCSI_PROC_FS is not set
  1725. +CONFIG_BLK_DEV_SD=y
  1726. +CONFIG_BLK_DEV_SR=m
  1727. +CONFIG_SCSI_MULTI_LUN=y
  1728. +# CONFIG_SCSI_LOWLEVEL is not set
  1729. +CONFIG_MD=y
  1730. +CONFIG_NETDEVICES=y
  1731. +CONFIG_TUN=m
  1732. +CONFIG_PHYLIB=m
  1733. +CONFIG_MDIO_BITBANG=m
  1734. +CONFIG_NET_ETHERNET=y
  1735. +# CONFIG_NETDEV_1000 is not set
  1736. +# CONFIG_NETDEV_10000 is not set
  1737. +CONFIG_LIBERTAS_THINFIRM=m
  1738. +CONFIG_LIBERTAS_THINFIRM_USB=m
  1739. +CONFIG_AT76C50X_USB=m
  1740. +CONFIG_USB_ZD1201=m
  1741. +CONFIG_USB_NET_RNDIS_WLAN=m
  1742. +CONFIG_RTL8187=m
  1743. +CONFIG_MAC80211_HWSIM=m
  1744. +CONFIG_ATH_COMMON=m
  1745. +CONFIG_ATH9K=m
  1746. +CONFIG_ATH9K_HTC=m
  1747. +CONFIG_CARL9170=m
  1748. +CONFIG_B43=m
  1749. +CONFIG_B43LEGACY=m
  1750. +CONFIG_HOSTAP=m
  1751. +CONFIG_IWM=m
  1752. +CONFIG_LIBERTAS=m
  1753. +CONFIG_LIBERTAS_USB=m
  1754. +CONFIG_LIBERTAS_SDIO=m
  1755. +CONFIG_P54_COMMON=m
  1756. +CONFIG_P54_USB=m
  1757. +CONFIG_RT2X00=m
  1758. +CONFIG_RT2500USB=m
  1759. +CONFIG_RT73USB=m
  1760. +CONFIG_RT2800USB=m
  1761. +CONFIG_RT2800USB_RT53XX=y
  1762. +CONFIG_RTL8192CU=m
  1763. +CONFIG_WL1251=m
  1764. +CONFIG_WL12XX_MENU=m
  1765. +CONFIG_ZD1211RW=m
  1766. +CONFIG_MWIFIEX=m
  1767. +CONFIG_MWIFIEX_SDIO=m
  1768. +CONFIG_WIMAX_I2400M_USB=m
  1769. +CONFIG_USB_CATC=m
  1770. +CONFIG_USB_KAWETH=m
  1771. +CONFIG_USB_PEGASUS=m
  1772. +CONFIG_USB_RTL8150=m
  1773. +CONFIG_USB_USBNET=y
  1774. +CONFIG_USB_NET_AX8817X=m
  1775. +CONFIG_USB_NET_CDCETHER=m
  1776. +CONFIG_USB_NET_CDC_EEM=m
  1777. +CONFIG_USB_NET_DM9601=m
  1778. +CONFIG_USB_NET_SMSC75XX=m
  1779. +CONFIG_USB_NET_SMSC95XX=y
  1780. +CONFIG_USB_NET_GL620A=m
  1781. +CONFIG_USB_NET_NET1080=m
  1782. +CONFIG_USB_NET_PLUSB=m
  1783. +CONFIG_USB_NET_MCS7830=m
  1784. +CONFIG_USB_NET_CDC_SUBSET=m
  1785. +CONFIG_USB_ALI_M5632=y
  1786. +CONFIG_USB_AN2720=y
  1787. +CONFIG_USB_KC2190=y
  1788. +# CONFIG_USB_NET_ZAURUS is not set
  1789. +CONFIG_USB_NET_CX82310_ETH=m
  1790. +CONFIG_USB_NET_KALMIA=m
  1791. +CONFIG_USB_NET_INT51X1=m
  1792. +CONFIG_USB_IPHETH=m
  1793. +CONFIG_USB_SIERRA_NET=m
  1794. +CONFIG_USB_VL600=m
  1795. +CONFIG_PPP=m
  1796. +CONFIG_PPP_ASYNC=m
  1797. +CONFIG_PPP_SYNC_TTY=m
  1798. +CONFIG_PPP_DEFLATE=m
  1799. +CONFIG_PPP_BSDCOMP=m
  1800. +CONFIG_SLIP=m
  1801. +CONFIG_SLIP_COMPRESSED=y
  1802. +CONFIG_NETCONSOLE=m
  1803. +CONFIG_INPUT_POLLDEV=m
  1804. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  1805. +CONFIG_INPUT_JOYDEV=m
  1806. +CONFIG_INPUT_EVDEV=m
  1807. +# CONFIG_INPUT_KEYBOARD is not set
  1808. +# CONFIG_INPUT_MOUSE is not set
  1809. +CONFIG_INPUT_MISC=y
  1810. +CONFIG_INPUT_AD714X=m
  1811. +CONFIG_INPUT_ATI_REMOTE=m
  1812. +CONFIG_INPUT_ATI_REMOTE2=m
  1813. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  1814. +CONFIG_INPUT_POWERMATE=m
  1815. +CONFIG_INPUT_YEALINK=m
  1816. +CONFIG_INPUT_CM109=m
  1817. +CONFIG_INPUT_UINPUT=m
  1818. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  1819. +CONFIG_INPUT_ADXL34X=m
  1820. +CONFIG_INPUT_CMA3000=m
  1821. +CONFIG_SERIO=m
  1822. +CONFIG_SERIO_RAW=m
  1823. +CONFIG_GAMEPORT=m
  1824. +CONFIG_GAMEPORT_NS558=m
  1825. +CONFIG_GAMEPORT_L4=m
  1826. +CONFIG_VT_HW_CONSOLE_BINDING=y
  1827. +# CONFIG_LEGACY_PTYS is not set
  1828. +# CONFIG_DEVKMEM is not set
  1829. +CONFIG_SERIAL_AMBA_PL011=y
  1830. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  1831. +# CONFIG_HW_RANDOM is not set
  1832. +CONFIG_RAW_DRIVER=y
  1833. +CONFIG_GPIO_SYSFS=y
  1834. +# CONFIG_HWMON is not set
  1835. +CONFIG_WATCHDOG=y
  1836. +CONFIG_BCM2708_WDT=m
  1837. +# CONFIG_MFD_SUPPORT is not set
  1838. +CONFIG_FB=y
  1839. +CONFIG_FB_BCM2708=y
  1840. +CONFIG_FRAMEBUFFER_CONSOLE=y
  1841. +CONFIG_LOGO=y
  1842. +# CONFIG_LOGO_LINUX_MONO is not set
  1843. +# CONFIG_LOGO_LINUX_VGA16 is not set
  1844. +CONFIG_SOUND=y
  1845. +CONFIG_SND=m
  1846. +CONFIG_SND_SEQUENCER=m
  1847. +CONFIG_SND_SEQ_DUMMY=m
  1848. +CONFIG_SND_MIXER_OSS=m
  1849. +CONFIG_SND_PCM_OSS=m
  1850. +CONFIG_SND_SEQUENCER_OSS=y
  1851. +CONFIG_SND_HRTIMER=m
  1852. +CONFIG_SND_DUMMY=m
  1853. +CONFIG_SND_ALOOP=m
  1854. +CONFIG_SND_VIRMIDI=m
  1855. +CONFIG_SND_MTPAV=m
  1856. +CONFIG_SND_SERIAL_U16550=m
  1857. +CONFIG_SND_MPU401=m
  1858. +CONFIG_SND_BCM2835=m
  1859. +CONFIG_SND_USB_AUDIO=m
  1860. +CONFIG_SND_USB_UA101=m
  1861. +CONFIG_SND_USB_CAIAQ=m
  1862. +CONFIG_SND_USB_6FIRE=m
  1863. +CONFIG_SOUND_PRIME=m
  1864. +CONFIG_HID_PID=y
  1865. +CONFIG_USB_HIDDEV=y
  1866. +CONFIG_HID_A4TECH=m
  1867. +CONFIG_HID_ACRUX=m
  1868. +CONFIG_HID_APPLE=m
  1869. +CONFIG_HID_BELKIN=m
  1870. +CONFIG_HID_CHERRY=m
  1871. +CONFIG_HID_CHICONY=m
  1872. +CONFIG_HID_CYPRESS=m
  1873. +CONFIG_HID_DRAGONRISE=m
  1874. +CONFIG_HID_EMS_FF=m
  1875. +CONFIG_HID_ELECOM=m
  1876. +CONFIG_HID_EZKEY=m
  1877. +CONFIG_HID_HOLTEK=m
  1878. +CONFIG_HID_KEYTOUCH=m
  1879. +CONFIG_HID_KYE=m
  1880. +CONFIG_HID_UCLOGIC=m
  1881. +CONFIG_HID_WALTOP=m
  1882. +CONFIG_HID_GYRATION=m
  1883. +CONFIG_HID_TWINHAN=m
  1884. +CONFIG_HID_KENSINGTON=m
  1885. +CONFIG_HID_LCPOWER=m
  1886. +CONFIG_HID_LOGITECH=m
  1887. +CONFIG_HID_MAGICMOUSE=m
  1888. +CONFIG_HID_MICROSOFT=m
  1889. +CONFIG_HID_MONTEREY=m
  1890. +CONFIG_HID_MULTITOUCH=m
  1891. +CONFIG_HID_NTRIG=m
  1892. +CONFIG_HID_ORTEK=m
  1893. +CONFIG_HID_PANTHERLORD=m
  1894. +CONFIG_HID_PETALYNX=m
  1895. +CONFIG_HID_PICOLCD=m
  1896. +CONFIG_HID_QUANTA=m
  1897. +CONFIG_HID_ROCCAT=m
  1898. +CONFIG_HID_SAMSUNG=m
  1899. +CONFIG_HID_SONY=m
  1900. +CONFIG_HID_SPEEDLINK=m
  1901. +CONFIG_HID_SUNPLUS=m
  1902. +CONFIG_HID_GREENASIA=m
  1903. +CONFIG_HID_SMARTJOYPLUS=m
  1904. +CONFIG_HID_TOPSEED=m
  1905. +CONFIG_HID_THRUSTMASTER=m
  1906. +CONFIG_HID_WACOM=m
  1907. +CONFIG_HID_WIIMOTE=m
  1908. +CONFIG_HID_ZEROPLUS=m
  1909. +CONFIG_HID_ZYDACRON=m
  1910. +CONFIG_USB=y
  1911. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  1912. +CONFIG_USB_MON=m
  1913. +CONFIG_USB_DWCOTG=y
  1914. +CONFIG_USB_STORAGE=y
  1915. +CONFIG_USB_STORAGE_REALTEK=m
  1916. +CONFIG_USB_STORAGE_DATAFAB=m
  1917. +CONFIG_USB_STORAGE_FREECOM=m
  1918. +CONFIG_USB_STORAGE_ISD200=m
  1919. +CONFIG_USB_STORAGE_USBAT=m
  1920. +CONFIG_USB_STORAGE_SDDR09=m
  1921. +CONFIG_USB_STORAGE_SDDR55=m
  1922. +CONFIG_USB_STORAGE_JUMPSHOT=m
  1923. +CONFIG_USB_STORAGE_ALAUDA=m
  1924. +CONFIG_USB_STORAGE_ONETOUCH=m
  1925. +CONFIG_USB_STORAGE_KARMA=m
  1926. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  1927. +CONFIG_USB_STORAGE_ENE_UB6250=m
  1928. +CONFIG_USB_UAS=y
  1929. +CONFIG_USB_LIBUSUAL=y
  1930. +CONFIG_USB_MDC800=m
  1931. +CONFIG_USB_MICROTEK=m
  1932. +CONFIG_USB_SERIAL=m
  1933. +CONFIG_USB_SERIAL_GENERIC=y
  1934. +CONFIG_USB_SERIAL_AIRCABLE=m
  1935. +CONFIG_USB_SERIAL_ARK3116=m
  1936. +CONFIG_USB_SERIAL_BELKIN=m
  1937. +CONFIG_USB_SERIAL_CH341=m
  1938. +CONFIG_USB_SERIAL_WHITEHEAT=m
  1939. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  1940. +CONFIG_USB_SERIAL_CP210X=m
  1941. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  1942. +CONFIG_USB_SERIAL_EMPEG=m
  1943. +CONFIG_USB_SERIAL_FTDI_SIO=m
  1944. +CONFIG_USB_SERIAL_FUNSOFT=m
  1945. +CONFIG_USB_SERIAL_VISOR=m
  1946. +CONFIG_USB_SERIAL_IPAQ=m
  1947. +CONFIG_USB_SERIAL_IR=m
  1948. +CONFIG_USB_SERIAL_EDGEPORT=m
  1949. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  1950. +CONFIG_USB_SERIAL_GARMIN=m
  1951. +CONFIG_USB_SERIAL_IPW=m
  1952. +CONFIG_USB_SERIAL_IUU=m
  1953. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  1954. +CONFIG_USB_SERIAL_KEYSPAN=m
  1955. +CONFIG_USB_SERIAL_KLSI=m
  1956. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  1957. +CONFIG_USB_SERIAL_MCT_U232=m
  1958. +CONFIG_USB_SERIAL_MOS7720=m
  1959. +CONFIG_USB_SERIAL_MOS7840=m
  1960. +CONFIG_USB_SERIAL_MOTOROLA=m
  1961. +CONFIG_USB_SERIAL_NAVMAN=m
  1962. +CONFIG_USB_SERIAL_PL2303=m
  1963. +CONFIG_USB_SERIAL_OTI6858=m
  1964. +CONFIG_USB_SERIAL_QCAUX=m
  1965. +CONFIG_USB_SERIAL_QUALCOMM=m
  1966. +CONFIG_USB_SERIAL_SPCP8X5=m
  1967. +CONFIG_USB_SERIAL_HP4X=m
  1968. +CONFIG_USB_SERIAL_SAFE=m
  1969. +CONFIG_USB_SERIAL_SIEMENS_MPI=m
  1970. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  1971. +CONFIG_USB_SERIAL_SYMBOL=m
  1972. +CONFIG_USB_SERIAL_TI=m
  1973. +CONFIG_USB_SERIAL_CYBERJACK=m
  1974. +CONFIG_USB_SERIAL_XIRCOM=m
  1975. +CONFIG_USB_SERIAL_OPTION=m
  1976. +CONFIG_USB_SERIAL_OMNINET=m
  1977. +CONFIG_USB_SERIAL_OPTICON=m
  1978. +CONFIG_USB_SERIAL_VIVOPAY_SERIAL=m
  1979. +CONFIG_USB_SERIAL_ZIO=m
  1980. +CONFIG_USB_SERIAL_SSU100=m
  1981. +CONFIG_USB_SERIAL_DEBUG=m
  1982. +CONFIG_USB_EMI62=m
  1983. +CONFIG_USB_EMI26=m
  1984. +CONFIG_USB_ADUTUX=m
  1985. +CONFIG_USB_SEVSEG=m
  1986. +CONFIG_USB_RIO500=m
  1987. +CONFIG_USB_LEGOTOWER=m
  1988. +CONFIG_USB_LCD=m
  1989. +CONFIG_USB_LED=m
  1990. +CONFIG_USB_CYPRESS_CY7C63=m
  1991. +CONFIG_USB_CYTHERM=m
  1992. +CONFIG_USB_IDMOUSE=m
  1993. +CONFIG_USB_FTDI_ELAN=m
  1994. +CONFIG_USB_APPLEDISPLAY=m
  1995. +CONFIG_USB_LD=m
  1996. +CONFIG_USB_TRANCEVIBRATOR=m
  1997. +CONFIG_USB_IOWARRIOR=m
  1998. +CONFIG_USB_TEST=m
  1999. +CONFIG_USB_ISIGHTFW=m
  2000. +CONFIG_USB_YUREX=m
  2001. +CONFIG_MMC=y
  2002. +CONFIG_MMC_SDHCI=y
  2003. +CONFIG_MMC_SDHCI_PLTFM=y
  2004. +CONFIG_MMC_SDHCI_BCM2708=y
  2005. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  2006. +CONFIG_LEDS_GPIO=y
  2007. +CONFIG_LEDS_TRIGGER_TIMER=m
  2008. +CONFIG_LEDS_TRIGGER_HEARTBEAT=m
  2009. +CONFIG_LEDS_TRIGGER_DEFAULT_ON=m
  2010. +CONFIG_UIO=m
  2011. +CONFIG_UIO_PDRV=m
  2012. +CONFIG_UIO_PDRV_GENIRQ=m
  2013. +# CONFIG_IOMMU_SUPPORT is not set
  2014. +CONFIG_EXT4_FS=y
  2015. +CONFIG_EXT4_FS_POSIX_ACL=y
  2016. +CONFIG_EXT4_FS_SECURITY=y
  2017. +CONFIG_REISERFS_FS=m
  2018. +CONFIG_REISERFS_FS_XATTR=y
  2019. +CONFIG_REISERFS_FS_POSIX_ACL=y
  2020. +CONFIG_REISERFS_FS_SECURITY=y
  2021. +CONFIG_JFS_FS=m
  2022. +CONFIG_JFS_POSIX_ACL=y
  2023. +CONFIG_JFS_SECURITY=y
  2024. +CONFIG_JFS_STATISTICS=y
  2025. +CONFIG_XFS_FS=m
  2026. +CONFIG_XFS_QUOTA=y
  2027. +CONFIG_XFS_POSIX_ACL=y
  2028. +CONFIG_XFS_RT=y
  2029. +CONFIG_GFS2_FS=m
  2030. +CONFIG_OCFS2_FS=m
  2031. +CONFIG_BTRFS_FS=m
  2032. +CONFIG_BTRFS_FS_POSIX_ACL=y
  2033. +CONFIG_NILFS2_FS=m
  2034. +CONFIG_FANOTIFY=y
  2035. +CONFIG_AUTOFS4_FS=y
  2036. +CONFIG_FUSE_FS=m
  2037. +CONFIG_CUSE=m
  2038. +CONFIG_FSCACHE=y
  2039. +CONFIG_FSCACHE_STATS=y
  2040. +CONFIG_FSCACHE_HISTOGRAM=y
  2041. +CONFIG_CACHEFILES=y
  2042. +CONFIG_ISO9660_FS=m
  2043. +CONFIG_JOLIET=y
  2044. +CONFIG_ZISOFS=y
  2045. +CONFIG_UDF_FS=m
  2046. +CONFIG_MSDOS_FS=y
  2047. +CONFIG_VFAT_FS=y
  2048. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  2049. +CONFIG_NTFS_FS=m
  2050. +CONFIG_TMPFS=y
  2051. +CONFIG_TMPFS_POSIX_ACL=y
  2052. +CONFIG_CONFIGFS_FS=y
  2053. +CONFIG_SQUASHFS=m
  2054. +CONFIG_SQUASHFS_XATTR=y
  2055. +CONFIG_SQUASHFS_LZO=y
  2056. +CONFIG_SQUASHFS_XZ=y
  2057. +CONFIG_NFS_FS=y
  2058. +CONFIG_NFS_V3=y
  2059. +CONFIG_NFS_V3_ACL=y
  2060. +CONFIG_NFS_V4=y
  2061. +CONFIG_ROOT_NFS=y
  2062. +CONFIG_NFS_FSCACHE=y
  2063. +CONFIG_CIFS=m
  2064. +CONFIG_CIFS_WEAK_PW_HASH=y
  2065. +CONFIG_CIFS_XATTR=y
  2066. +CONFIG_CIFS_POSIX=y
  2067. +CONFIG_9P_FS=m
  2068. +CONFIG_9P_FS_POSIX_ACL=y
  2069. +CONFIG_PARTITION_ADVANCED=y
  2070. +CONFIG_MAC_PARTITION=y
  2071. +CONFIG_EFI_PARTITION=y
  2072. +CONFIG_NLS_DEFAULT="utf8"
  2073. +CONFIG_NLS_CODEPAGE_437=y
  2074. +CONFIG_NLS_CODEPAGE_737=m
  2075. +CONFIG_NLS_CODEPAGE_775=m
  2076. +CONFIG_NLS_CODEPAGE_850=m
  2077. +CONFIG_NLS_CODEPAGE_852=m
  2078. +CONFIG_NLS_CODEPAGE_855=m
  2079. +CONFIG_NLS_CODEPAGE_857=m
  2080. +CONFIG_NLS_CODEPAGE_860=m
  2081. +CONFIG_NLS_CODEPAGE_861=m
  2082. +CONFIG_NLS_CODEPAGE_862=m
  2083. +CONFIG_NLS_CODEPAGE_863=m
  2084. +CONFIG_NLS_CODEPAGE_864=m
  2085. +CONFIG_NLS_CODEPAGE_865=m
  2086. +CONFIG_NLS_CODEPAGE_866=m
  2087. +CONFIG_NLS_CODEPAGE_869=m
  2088. +CONFIG_NLS_CODEPAGE_936=m
  2089. +CONFIG_NLS_CODEPAGE_950=m
  2090. +CONFIG_NLS_CODEPAGE_932=m
  2091. +CONFIG_NLS_CODEPAGE_949=m
  2092. +CONFIG_NLS_CODEPAGE_874=m
  2093. +CONFIG_NLS_ISO8859_8=m
  2094. +CONFIG_NLS_CODEPAGE_1250=m
  2095. +CONFIG_NLS_CODEPAGE_1251=m
  2096. +CONFIG_NLS_ASCII=y
  2097. +CONFIG_NLS_ISO8859_1=m
  2098. +CONFIG_NLS_ISO8859_2=m
  2099. +CONFIG_NLS_ISO8859_3=m
  2100. +CONFIG_NLS_ISO8859_4=m
  2101. +CONFIG_NLS_ISO8859_5=m
  2102. +CONFIG_NLS_ISO8859_6=m
  2103. +CONFIG_NLS_ISO8859_7=m
  2104. +CONFIG_NLS_ISO8859_9=m
  2105. +CONFIG_NLS_ISO8859_13=m
  2106. +CONFIG_NLS_ISO8859_14=m
  2107. +CONFIG_NLS_ISO8859_15=m
  2108. +CONFIG_NLS_KOI8_R=m
  2109. +CONFIG_NLS_KOI8_U=m
  2110. +CONFIG_NLS_UTF8=m
  2111. +CONFIG_PRINTK_TIME=y
  2112. +CONFIG_DETECT_HUNG_TASK=y
  2113. +CONFIG_TIMER_STATS=y
  2114. +CONFIG_DEBUG_STACK_USAGE=y
  2115. +CONFIG_DEBUG_INFO=y
  2116. +CONFIG_DEBUG_MEMORY_INIT=y
  2117. +CONFIG_BOOT_PRINTK_DELAY=y
  2118. +CONFIG_LATENCYTOP=y
  2119. +CONFIG_SYSCTL_SYSCALL_CHECK=y
  2120. +CONFIG_IRQSOFF_TRACER=y
  2121. +CONFIG_SCHED_TRACER=y
  2122. +CONFIG_STACK_TRACER=y
  2123. +CONFIG_BLK_DEV_IO_TRACE=y
  2124. +CONFIG_FUNCTION_PROFILER=y
  2125. +CONFIG_KGDB=y
  2126. +CONFIG_KGDB_KDB=y
  2127. +CONFIG_KDB_KEYBOARD=y
  2128. +CONFIG_STRICT_DEVMEM=y
  2129. +CONFIG_CRYPTO_AUTHENC=m
  2130. +CONFIG_CRYPTO_SEQIV=m
  2131. +CONFIG_CRYPTO_CBC=y
  2132. +CONFIG_CRYPTO_HMAC=y
  2133. +CONFIG_CRYPTO_XCBC=m
  2134. +CONFIG_CRYPTO_MD5=y
  2135. +CONFIG_CRYPTO_SHA1=y
  2136. +CONFIG_CRYPTO_SHA256=m
  2137. +CONFIG_CRYPTO_SHA512=m
  2138. +CONFIG_CRYPTO_TGR192=m
  2139. +CONFIG_CRYPTO_WP512=m
  2140. +CONFIG_CRYPTO_CAST5=m
  2141. +CONFIG_CRYPTO_DES=y
  2142. +CONFIG_CRYPTO_DEFLATE=m
  2143. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  2144. +# CONFIG_CRYPTO_HW is not set
  2145. +CONFIG_CRC_ITU_T=y
  2146. +CONFIG_LIBCRC32C=y
  2147. diff -Nur linux-3.15.4/arch/arm/configs/bcmrpi_quick_defconfig linux-rpi/arch/arm/configs/bcmrpi_quick_defconfig
  2148. --- linux-3.15.4/arch/arm/configs/bcmrpi_quick_defconfig 1970-01-01 01:00:00.000000000 +0100
  2149. +++ linux-rpi/arch/arm/configs/bcmrpi_quick_defconfig 2014-04-13 17:32:40.000000000 +0200
  2150. @@ -0,0 +1,197 @@
  2151. +# CONFIG_ARM_PATCH_PHYS_VIRT is not set
  2152. +CONFIG_LOCALVERSION="-quick"
  2153. +# CONFIG_LOCALVERSION_AUTO is not set
  2154. +# CONFIG_SWAP is not set
  2155. +CONFIG_SYSVIPC=y
  2156. +CONFIG_POSIX_MQUEUE=y
  2157. +CONFIG_NO_HZ=y
  2158. +CONFIG_HIGH_RES_TIMERS=y
  2159. +CONFIG_IKCONFIG=y
  2160. +CONFIG_IKCONFIG_PROC=y
  2161. +CONFIG_KALLSYMS_ALL=y
  2162. +CONFIG_EMBEDDED=y
  2163. +CONFIG_PERF_EVENTS=y
  2164. +# CONFIG_COMPAT_BRK is not set
  2165. +CONFIG_SLAB=y
  2166. +CONFIG_MODULES=y
  2167. +CONFIG_MODULE_UNLOAD=y
  2168. +CONFIG_MODVERSIONS=y
  2169. +CONFIG_MODULE_SRCVERSION_ALL=y
  2170. +# CONFIG_BLK_DEV_BSG is not set
  2171. +CONFIG_ARCH_BCM2708=y
  2172. +CONFIG_PREEMPT=y
  2173. +CONFIG_AEABI=y
  2174. +CONFIG_UACCESS_WITH_MEMCPY=y
  2175. +CONFIG_ZBOOT_ROM_TEXT=0x0
  2176. +CONFIG_ZBOOT_ROM_BSS=0x0
  2177. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
  2178. +CONFIG_CPU_FREQ=y
  2179. +CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE=y
  2180. +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
  2181. +CONFIG_CPU_FREQ_GOV_USERSPACE=y
  2182. +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
  2183. +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
  2184. +CONFIG_CPU_IDLE=y
  2185. +CONFIG_VFP=y
  2186. +CONFIG_BINFMT_MISC=y
  2187. +CONFIG_NET=y
  2188. +CONFIG_PACKET=y
  2189. +CONFIG_UNIX=y
  2190. +CONFIG_INET=y
  2191. +CONFIG_IP_MULTICAST=y
  2192. +CONFIG_IP_PNP=y
  2193. +CONFIG_IP_PNP_DHCP=y
  2194. +CONFIG_IP_PNP_RARP=y
  2195. +CONFIG_SYN_COOKIES=y
  2196. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  2197. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  2198. +# CONFIG_INET_XFRM_MODE_BEET is not set
  2199. +# CONFIG_INET_LRO is not set
  2200. +# CONFIG_INET_DIAG is not set
  2201. +# CONFIG_IPV6 is not set
  2202. +# CONFIG_WIRELESS is not set
  2203. +CONFIG_DEVTMPFS=y
  2204. +CONFIG_DEVTMPFS_MOUNT=y
  2205. +CONFIG_BLK_DEV_LOOP=y
  2206. +CONFIG_BLK_DEV_RAM=y
  2207. +CONFIG_SCSI=y
  2208. +# CONFIG_SCSI_PROC_FS is not set
  2209. +# CONFIG_SCSI_LOWLEVEL is not set
  2210. +CONFIG_NETDEVICES=y
  2211. +# CONFIG_NET_VENDOR_BROADCOM is not set
  2212. +# CONFIG_NET_VENDOR_CIRRUS is not set
  2213. +# CONFIG_NET_VENDOR_FARADAY is not set
  2214. +# CONFIG_NET_VENDOR_INTEL is not set
  2215. +# CONFIG_NET_VENDOR_MARVELL is not set
  2216. +# CONFIG_NET_VENDOR_MICREL is not set
  2217. +# CONFIG_NET_VENDOR_NATSEMI is not set
  2218. +# CONFIG_NET_VENDOR_SEEQ is not set
  2219. +# CONFIG_NET_VENDOR_STMICRO is not set
  2220. +# CONFIG_NET_VENDOR_WIZNET is not set
  2221. +CONFIG_USB_USBNET=y
  2222. +# CONFIG_USB_NET_AX8817X is not set
  2223. +# CONFIG_USB_NET_CDCETHER is not set
  2224. +# CONFIG_USB_NET_CDC_NCM is not set
  2225. +CONFIG_USB_NET_SMSC95XX=y
  2226. +# CONFIG_USB_NET_NET1080 is not set
  2227. +# CONFIG_USB_NET_CDC_SUBSET is not set
  2228. +# CONFIG_USB_NET_ZAURUS is not set
  2229. +# CONFIG_WLAN is not set
  2230. +# CONFIG_INPUT_MOUSEDEV is not set
  2231. +CONFIG_INPUT_EVDEV=y
  2232. +# CONFIG_INPUT_KEYBOARD is not set
  2233. +# CONFIG_INPUT_MOUSE is not set
  2234. +# CONFIG_SERIO is not set
  2235. +CONFIG_VT_HW_CONSOLE_BINDING=y
  2236. +# CONFIG_LEGACY_PTYS is not set
  2237. +# CONFIG_DEVKMEM is not set
  2238. +CONFIG_SERIAL_AMBA_PL011=y
  2239. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  2240. +CONFIG_TTY_PRINTK=y
  2241. +CONFIG_HW_RANDOM=y
  2242. +CONFIG_HW_RANDOM_BCM2708=y
  2243. +CONFIG_RAW_DRIVER=y
  2244. +CONFIG_THERMAL=y
  2245. +CONFIG_THERMAL_BCM2835=y
  2246. +CONFIG_WATCHDOG=y
  2247. +CONFIG_BCM2708_WDT=y
  2248. +CONFIG_REGULATOR=y
  2249. +CONFIG_REGULATOR_DEBUG=y
  2250. +CONFIG_REGULATOR_FIXED_VOLTAGE=y
  2251. +CONFIG_REGULATOR_VIRTUAL_CONSUMER=y
  2252. +CONFIG_REGULATOR_USERSPACE_CONSUMER=y
  2253. +CONFIG_FB=y
  2254. +CONFIG_FB_BCM2708=y
  2255. +CONFIG_FRAMEBUFFER_CONSOLE=y
  2256. +CONFIG_LOGO=y
  2257. +# CONFIG_LOGO_LINUX_MONO is not set
  2258. +# CONFIG_LOGO_LINUX_VGA16 is not set
  2259. +CONFIG_SOUND=y
  2260. +CONFIG_SND=y
  2261. +CONFIG_SND_BCM2835=y
  2262. +# CONFIG_SND_USB is not set
  2263. +CONFIG_USB=y
  2264. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  2265. +CONFIG_USB_DWCOTG=y
  2266. +CONFIG_MMC=y
  2267. +CONFIG_MMC_SDHCI=y
  2268. +CONFIG_MMC_SDHCI_PLTFM=y
  2269. +CONFIG_MMC_SDHCI_BCM2708=y
  2270. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  2271. +CONFIG_NEW_LEDS=y
  2272. +CONFIG_LEDS_CLASS=y
  2273. +CONFIG_LEDS_TRIGGERS=y
  2274. +# CONFIG_IOMMU_SUPPORT is not set
  2275. +CONFIG_EXT4_FS=y
  2276. +CONFIG_EXT4_FS_POSIX_ACL=y
  2277. +CONFIG_EXT4_FS_SECURITY=y
  2278. +CONFIG_AUTOFS4_FS=y
  2279. +CONFIG_FSCACHE=y
  2280. +CONFIG_CACHEFILES=y
  2281. +CONFIG_MSDOS_FS=y
  2282. +CONFIG_VFAT_FS=y
  2283. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  2284. +CONFIG_TMPFS=y
  2285. +CONFIG_TMPFS_POSIX_ACL=y
  2286. +CONFIG_CONFIGFS_FS=y
  2287. +# CONFIG_MISC_FILESYSTEMS is not set
  2288. +CONFIG_NFS_FS=y
  2289. +CONFIG_NFS_V3_ACL=y
  2290. +CONFIG_NFS_V4=y
  2291. +CONFIG_ROOT_NFS=y
  2292. +CONFIG_NFS_FSCACHE=y
  2293. +CONFIG_NLS_DEFAULT="utf8"
  2294. +CONFIG_NLS_CODEPAGE_437=y
  2295. +CONFIG_NLS_CODEPAGE_737=y
  2296. +CONFIG_NLS_CODEPAGE_775=y
  2297. +CONFIG_NLS_CODEPAGE_850=y
  2298. +CONFIG_NLS_CODEPAGE_852=y
  2299. +CONFIG_NLS_CODEPAGE_855=y
  2300. +CONFIG_NLS_CODEPAGE_857=y
  2301. +CONFIG_NLS_CODEPAGE_860=y
  2302. +CONFIG_NLS_CODEPAGE_861=y
  2303. +CONFIG_NLS_CODEPAGE_862=y
  2304. +CONFIG_NLS_CODEPAGE_863=y
  2305. +CONFIG_NLS_CODEPAGE_864=y
  2306. +CONFIG_NLS_CODEPAGE_865=y
  2307. +CONFIG_NLS_CODEPAGE_866=y
  2308. +CONFIG_NLS_CODEPAGE_869=y
  2309. +CONFIG_NLS_CODEPAGE_936=y
  2310. +CONFIG_NLS_CODEPAGE_950=y
  2311. +CONFIG_NLS_CODEPAGE_932=y
  2312. +CONFIG_NLS_CODEPAGE_949=y
  2313. +CONFIG_NLS_CODEPAGE_874=y
  2314. +CONFIG_NLS_ISO8859_8=y
  2315. +CONFIG_NLS_CODEPAGE_1250=y
  2316. +CONFIG_NLS_CODEPAGE_1251=y
  2317. +CONFIG_NLS_ASCII=y
  2318. +CONFIG_NLS_ISO8859_1=y
  2319. +CONFIG_NLS_ISO8859_2=y
  2320. +CONFIG_NLS_ISO8859_3=y
  2321. +CONFIG_NLS_ISO8859_4=y
  2322. +CONFIG_NLS_ISO8859_5=y
  2323. +CONFIG_NLS_ISO8859_6=y
  2324. +CONFIG_NLS_ISO8859_7=y
  2325. +CONFIG_NLS_ISO8859_9=y
  2326. +CONFIG_NLS_ISO8859_13=y
  2327. +CONFIG_NLS_ISO8859_14=y
  2328. +CONFIG_NLS_ISO8859_15=y
  2329. +CONFIG_NLS_UTF8=y
  2330. +CONFIG_PRINTK_TIME=y
  2331. +CONFIG_DEBUG_FS=y
  2332. +CONFIG_DETECT_HUNG_TASK=y
  2333. +# CONFIG_DEBUG_PREEMPT is not set
  2334. +# CONFIG_DEBUG_BUGVERBOSE is not set
  2335. +# CONFIG_FTRACE is not set
  2336. +CONFIG_KGDB=y
  2337. +CONFIG_KGDB_KDB=y
  2338. +# CONFIG_ARM_UNWIND is not set
  2339. +CONFIG_CRYPTO_CBC=y
  2340. +CONFIG_CRYPTO_HMAC=y
  2341. +CONFIG_CRYPTO_MD5=y
  2342. +CONFIG_CRYPTO_SHA1=y
  2343. +CONFIG_CRYPTO_DES=y
  2344. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  2345. +# CONFIG_CRYPTO_HW is not set
  2346. +CONFIG_CRC_ITU_T=y
  2347. +CONFIG_LIBCRC32C=y
  2348. diff -Nur linux-3.15.4/arch/arm/include/asm/irqflags.h linux-rpi/arch/arm/include/asm/irqflags.h
  2349. --- linux-3.15.4/arch/arm/include/asm/irqflags.h 2014-07-07 03:59:25.000000000 +0200
  2350. +++ linux-rpi/arch/arm/include/asm/irqflags.h 2014-07-07 10:44:57.000000000 +0200
  2351. @@ -145,12 +145,22 @@
  2352. }
  2353. /*
  2354. - * restore saved IRQ & FIQ state
  2355. + * restore saved IRQ state
  2356. */
  2357. static inline void arch_local_irq_restore(unsigned long flags)
  2358. {
  2359. - asm volatile(
  2360. - " msr " IRQMASK_REG_NAME_W ", %0 @ local_irq_restore"
  2361. + unsigned long temp = 0;
  2362. + flags &= ~(1 << 6);
  2363. + asm volatile (
  2364. + " mrs %0, cpsr"
  2365. + : "=r" (temp)
  2366. + :
  2367. + : "memory", "cc");
  2368. + /* Preserve FIQ bit */
  2369. + temp &= (1 << 6);
  2370. + flags = flags | temp;
  2371. + asm volatile (
  2372. + " msr cpsr_c, %0 @ local_irq_restore"
  2373. :
  2374. : "r" (flags)
  2375. : "memory", "cc");
  2376. diff -Nur linux-3.15.4/arch/arm/Kconfig linux-rpi/arch/arm/Kconfig
  2377. --- linux-3.15.4/arch/arm/Kconfig 2014-07-07 03:59:25.000000000 +0200
  2378. +++ linux-rpi/arch/arm/Kconfig 2014-07-07 10:44:57.000000000 +0200
  2379. @@ -384,6 +384,24 @@
  2380. This enables support for systems based on Atmel
  2381. AT91RM9200 and AT91SAM9* processors.
  2382. +config ARCH_BCM2708
  2383. + bool "Broadcom BCM2708 family"
  2384. + select CPU_V6
  2385. + select ARM_AMBA
  2386. + select HAVE_CLK
  2387. + select HAVE_SCHED_CLOCK
  2388. + select NEED_MACH_GPIO_H
  2389. + select NEED_MACH_MEMORY_H
  2390. + select CLKDEV_LOOKUP
  2391. + select ARCH_HAS_CPUFREQ
  2392. + select GENERIC_CLOCKEVENTS
  2393. + select ARM_ERRATA_411920
  2394. + select MACH_BCM2708
  2395. + select VC4
  2396. + select FIQ
  2397. + help
  2398. + This enables support for Broadcom BCM2708 boards.
  2399. +
  2400. config ARCH_CLPS711X
  2401. bool "Cirrus Logic CLPS711x/EP721x/EP731x-based"
  2402. select ARCH_REQUIRE_GPIOLIB
  2403. @@ -1068,6 +1086,7 @@
  2404. source "arch/arm/mach-vt8500/Kconfig"
  2405. source "arch/arm/mach-w90x900/Kconfig"
  2406. +source "arch/arm/mach-bcm2708/Kconfig"
  2407. source "arch/arm/mach-zynq/Kconfig"
  2408. diff -Nur linux-3.15.4/arch/arm/Kconfig.debug linux-rpi/arch/arm/Kconfig.debug
  2409. --- linux-3.15.4/arch/arm/Kconfig.debug 2014-07-07 03:59:25.000000000 +0200
  2410. +++ linux-rpi/arch/arm/Kconfig.debug 2014-07-07 10:44:57.000000000 +0200
  2411. @@ -916,6 +916,14 @@
  2412. options; the platform specific options are deprecated
  2413. and will be soon removed.
  2414. + config DEBUG_BCM2708_UART0
  2415. + bool "Broadcom BCM2708 UART0 (PL011)"
  2416. + depends on MACH_BCM2708
  2417. + help
  2418. + Say Y here if you want the debug print routines to direct
  2419. + their output to UART 0. The port must have been initialised
  2420. + by the boot-loader before use.
  2421. +
  2422. endchoice
  2423. config DEBUG_EXYNOS_UART
  2424. diff -Nur linux-3.15.4/arch/arm/kernel/fiqasm.S linux-rpi/arch/arm/kernel/fiqasm.S
  2425. --- linux-3.15.4/arch/arm/kernel/fiqasm.S 2014-07-07 03:59:25.000000000 +0200
  2426. +++ linux-rpi/arch/arm/kernel/fiqasm.S 2014-07-07 10:44:57.000000000 +0200
  2427. @@ -47,3 +47,7 @@
  2428. mov r0, r0 @ avoid hazard prior to ARMv4
  2429. mov pc, lr
  2430. ENDPROC(__get_fiq_regs)
  2431. +
  2432. +ENTRY(__FIQ_Branch)
  2433. + mov pc, r8
  2434. +ENDPROC(__FIQ_Branch)
  2435. diff -Nur linux-3.15.4/arch/arm/kernel/process.c linux-rpi/arch/arm/kernel/process.c
  2436. --- linux-3.15.4/arch/arm/kernel/process.c 2014-07-07 03:59:25.000000000 +0200
  2437. +++ linux-rpi/arch/arm/kernel/process.c 2014-07-07 10:44:57.000000000 +0200
  2438. @@ -171,6 +171,16 @@
  2439. }
  2440. #endif
  2441. +char bcm2708_reboot_mode = 'h';
  2442. +
  2443. +int __init reboot_setup(char *str)
  2444. +{
  2445. + bcm2708_reboot_mode = str[0];
  2446. + return 1;
  2447. +}
  2448. +
  2449. +__setup("reboot=", reboot_setup);
  2450. +
  2451. /*
  2452. * Called by kexec, immediately prior to machine_kexec().
  2453. *
  2454. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/armctrl.c linux-rpi/arch/arm/mach-bcm2708/armctrl.c
  2455. --- linux-3.15.4/arch/arm/mach-bcm2708/armctrl.c 1970-01-01 01:00:00.000000000 +0100
  2456. +++ linux-rpi/arch/arm/mach-bcm2708/armctrl.c 2014-04-13 17:32:40.000000000 +0200
  2457. @@ -0,0 +1,219 @@
  2458. +/*
  2459. + * linux/arch/arm/mach-bcm2708/armctrl.c
  2460. + *
  2461. + * Copyright (C) 2010 Broadcom
  2462. + *
  2463. + * This program is free software; you can redistribute it and/or modify
  2464. + * it under the terms of the GNU General Public License as published by
  2465. + * the Free Software Foundation; either version 2 of the License, or
  2466. + * (at your option) any later version.
  2467. + *
  2468. + * This program is distributed in the hope that it will be useful,
  2469. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2470. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2471. + * GNU General Public License for more details.
  2472. + *
  2473. + * You should have received a copy of the GNU General Public License
  2474. + * along with this program; if not, write to the Free Software
  2475. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  2476. + */
  2477. +#include <linux/init.h>
  2478. +#include <linux/list.h>
  2479. +#include <linux/io.h>
  2480. +#include <linux/version.h>
  2481. +#include <linux/syscore_ops.h>
  2482. +#include <linux/interrupt.h>
  2483. +
  2484. +#include <asm/mach/irq.h>
  2485. +#include <mach/hardware.h>
  2486. +#include "armctrl.h"
  2487. +
  2488. +/* For support of kernels >= 3.0 assume only one VIC for now*/
  2489. +static unsigned int remap_irqs[(INTERRUPT_ARASANSDIO + 1) - INTERRUPT_JPEG] = {
  2490. + INTERRUPT_VC_JPEG,
  2491. + INTERRUPT_VC_USB,
  2492. + INTERRUPT_VC_3D,
  2493. + INTERRUPT_VC_DMA2,
  2494. + INTERRUPT_VC_DMA3,
  2495. + INTERRUPT_VC_I2C,
  2496. + INTERRUPT_VC_SPI,
  2497. + INTERRUPT_VC_I2SPCM,
  2498. + INTERRUPT_VC_SDIO,
  2499. + INTERRUPT_VC_UART,
  2500. + INTERRUPT_VC_ARASANSDIO
  2501. +};
  2502. +
  2503. +static void armctrl_mask_irq(struct irq_data *d)
  2504. +{
  2505. + static const unsigned int disables[4] = {
  2506. + ARM_IRQ_DIBL1,
  2507. + ARM_IRQ_DIBL2,
  2508. + ARM_IRQ_DIBL3,
  2509. + 0
  2510. + };
  2511. +
  2512. + if (d->irq >= FIQ_START) {
  2513. + writel(0, __io_address(ARM_IRQ_FAST));
  2514. + } else {
  2515. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq);
  2516. + writel(1 << (data & 0x1f), __io_address(disables[(data >> 5) & 0x3]));
  2517. + }
  2518. +}
  2519. +
  2520. +static void armctrl_unmask_irq(struct irq_data *d)
  2521. +{
  2522. + static const unsigned int enables[4] = {
  2523. + ARM_IRQ_ENBL1,
  2524. + ARM_IRQ_ENBL2,
  2525. + ARM_IRQ_ENBL3,
  2526. + 0
  2527. + };
  2528. +
  2529. + if (d->irq >= FIQ_START) {
  2530. + unsigned int data =
  2531. + (unsigned int)irq_get_chip_data(d->irq) - FIQ_START;
  2532. + writel(0x80 | data, __io_address(ARM_IRQ_FAST));
  2533. + } else {
  2534. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq);
  2535. + writel(1 << (data & 0x1f), __io_address(enables[(data >> 5) & 0x3]));
  2536. + }
  2537. +}
  2538. +
  2539. +#if defined(CONFIG_PM)
  2540. +
  2541. +/* for kernels 3.xx use the new syscore_ops apis but for older kernels use the sys dev class */
  2542. +
  2543. +/* Static defines
  2544. + * struct armctrl_device - VIC PM device (< 3.xx)
  2545. + * @sysdev: The system device which is registered. (< 3.xx)
  2546. + * @irq: The IRQ number for the base of the VIC.
  2547. + * @base: The register base for the VIC.
  2548. + * @resume_sources: A bitmask of interrupts for resume.
  2549. + * @resume_irqs: The IRQs enabled for resume.
  2550. + * @int_select: Save for VIC_INT_SELECT.
  2551. + * @int_enable: Save for VIC_INT_ENABLE.
  2552. + * @soft_int: Save for VIC_INT_SOFT.
  2553. + * @protect: Save for VIC_PROTECT.
  2554. + */
  2555. +struct armctrl_info {
  2556. + void __iomem *base;
  2557. + int irq;
  2558. + u32 resume_sources;
  2559. + u32 resume_irqs;
  2560. + u32 int_select;
  2561. + u32 int_enable;
  2562. + u32 soft_int;
  2563. + u32 protect;
  2564. +} armctrl;
  2565. +
  2566. +static int armctrl_suspend(void)
  2567. +{
  2568. + return 0;
  2569. +}
  2570. +
  2571. +static void armctrl_resume(void)
  2572. +{
  2573. + return;
  2574. +}
  2575. +
  2576. +/**
  2577. + * armctrl_pm_register - Register a VIC for later power management control
  2578. + * @base: The base address of the VIC.
  2579. + * @irq: The base IRQ for the VIC.
  2580. + * @resume_sources: bitmask of interrupts allowed for resume sources.
  2581. + *
  2582. + * For older kernels (< 3.xx) do -
  2583. + * Register the VIC with the system device tree so that it can be notified
  2584. + * of suspend and resume requests and ensure that the correct actions are
  2585. + * taken to re-instate the settings on resume.
  2586. + */
  2587. +static void __init armctrl_pm_register(void __iomem * base, unsigned int irq,
  2588. + u32 resume_sources)
  2589. +{
  2590. + armctrl.base = base;
  2591. + armctrl.resume_sources = resume_sources;
  2592. + armctrl.irq = irq;
  2593. +}
  2594. +
  2595. +static int armctrl_set_wake(struct irq_data *d, unsigned int on)
  2596. +{
  2597. + unsigned int off = d->irq & 31;
  2598. + u32 bit = 1 << off;
  2599. +
  2600. + if (!(bit & armctrl.resume_sources))
  2601. + return -EINVAL;
  2602. +
  2603. + if (on)
  2604. + armctrl.resume_irqs |= bit;
  2605. + else
  2606. + armctrl.resume_irqs &= ~bit;
  2607. +
  2608. + return 0;
  2609. +}
  2610. +
  2611. +#else
  2612. +static inline void armctrl_pm_register(void __iomem * base, unsigned int irq,
  2613. + u32 arg1)
  2614. +{
  2615. +}
  2616. +
  2617. +#define armctrl_suspend NULL
  2618. +#define armctrl_resume NULL
  2619. +#define armctrl_set_wake NULL
  2620. +#endif /* CONFIG_PM */
  2621. +
  2622. +static struct syscore_ops armctrl_syscore_ops = {
  2623. + .suspend = armctrl_suspend,
  2624. + .resume = armctrl_resume,
  2625. +};
  2626. +
  2627. +/**
  2628. + * armctrl_syscore_init - initicall to register VIC pm functions
  2629. + *
  2630. + * This is called via late_initcall() to register
  2631. + * the resources for the VICs due to the early
  2632. + * nature of the VIC's registration.
  2633. +*/
  2634. +static int __init armctrl_syscore_init(void)
  2635. +{
  2636. + register_syscore_ops(&armctrl_syscore_ops);
  2637. + return 0;
  2638. +}
  2639. +
  2640. +late_initcall(armctrl_syscore_init);
  2641. +
  2642. +static struct irq_chip armctrl_chip = {
  2643. + .name = "ARMCTRL",
  2644. + .irq_ack = armctrl_mask_irq,
  2645. + .irq_mask = armctrl_mask_irq,
  2646. + .irq_unmask = armctrl_unmask_irq,
  2647. + .irq_set_wake = armctrl_set_wake,
  2648. +};
  2649. +
  2650. +/**
  2651. + * armctrl_init - initialise a vectored interrupt controller
  2652. + * @base: iomem base address
  2653. + * @irq_start: starting interrupt number, must be muliple of 32
  2654. + * @armctrl_sources: bitmask of interrupt sources to allow
  2655. + * @resume_sources: bitmask of interrupt sources to allow for resume
  2656. + */
  2657. +int __init armctrl_init(void __iomem * base, unsigned int irq_start,
  2658. + u32 armctrl_sources, u32 resume_sources)
  2659. +{
  2660. + unsigned int irq;
  2661. +
  2662. + for (irq = 0; irq < NR_IRQS; irq++) {
  2663. + unsigned int data = irq;
  2664. + if (irq >= INTERRUPT_JPEG && irq <= INTERRUPT_ARASANSDIO)
  2665. + data = remap_irqs[irq - INTERRUPT_JPEG];
  2666. +
  2667. + irq_set_chip(irq, &armctrl_chip);
  2668. + irq_set_chip_data(irq, (void *)data);
  2669. + irq_set_handler(irq, handle_level_irq);
  2670. + set_irq_flags(irq, IRQF_VALID | IRQF_PROBE | IRQF_DISABLED);
  2671. + }
  2672. +
  2673. + armctrl_pm_register(base, irq_start, resume_sources);
  2674. + init_FIQ(FIQ_START);
  2675. + return 0;
  2676. +}
  2677. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/armctrl.h linux-rpi/arch/arm/mach-bcm2708/armctrl.h
  2678. --- linux-3.15.4/arch/arm/mach-bcm2708/armctrl.h 1970-01-01 01:00:00.000000000 +0100
  2679. +++ linux-rpi/arch/arm/mach-bcm2708/armctrl.h 2014-04-13 17:32:40.000000000 +0200
  2680. @@ -0,0 +1,27 @@
  2681. +/*
  2682. + * linux/arch/arm/mach-bcm2708/armctrl.h
  2683. + *
  2684. + * Copyright (C) 2010 Broadcom
  2685. + *
  2686. + * This program is free software; you can redistribute it and/or modify
  2687. + * it under the terms of the GNU General Public License as published by
  2688. + * the Free Software Foundation; either version 2 of the License, or
  2689. + * (at your option) any later version.
  2690. + *
  2691. + * This program is distributed in the hope that it will be useful,
  2692. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2693. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2694. + * GNU General Public License for more details.
  2695. + *
  2696. + * You should have received a copy of the GNU General Public License
  2697. + * along with this program; if not, write to the Free Software
  2698. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  2699. + */
  2700. +
  2701. +#ifndef __BCM2708_ARMCTRL_H
  2702. +#define __BCM2708_ARMCTRL_H
  2703. +
  2704. +extern int __init armctrl_init(void __iomem * base, unsigned int irq_start,
  2705. + u32 armctrl_sources, u32 resume_sources);
  2706. +
  2707. +#endif
  2708. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/bcm2708.c linux-rpi/arch/arm/mach-bcm2708/bcm2708.c
  2709. --- linux-3.15.4/arch/arm/mach-bcm2708/bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  2710. +++ linux-rpi/arch/arm/mach-bcm2708/bcm2708.c 2014-07-07 10:44:57.000000000 +0200
  2711. @@ -0,0 +1,1031 @@
  2712. +/*
  2713. + * linux/arch/arm/mach-bcm2708/bcm2708.c
  2714. + *
  2715. + * Copyright (C) 2010 Broadcom
  2716. + *
  2717. + * This program is free software; you can redistribute it and/or modify
  2718. + * it under the terms of the GNU General Public License as published by
  2719. + * the Free Software Foundation; either version 2 of the License, or
  2720. + * (at your option) any later version.
  2721. + *
  2722. + * This program is distributed in the hope that it will be useful,
  2723. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2724. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2725. + * GNU General Public License for more details.
  2726. + *
  2727. + * You should have received a copy of the GNU General Public License
  2728. + * along with this program; if not, write to the Free Software
  2729. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  2730. + */
  2731. +
  2732. +#include <linux/init.h>
  2733. +#include <linux/device.h>
  2734. +#include <linux/dma-mapping.h>
  2735. +#include <linux/serial_8250.h>
  2736. +#include <linux/platform_device.h>
  2737. +#include <linux/syscore_ops.h>
  2738. +#include <linux/interrupt.h>
  2739. +#include <linux/amba/bus.h>
  2740. +#include <linux/amba/clcd.h>
  2741. +#include <linux/clockchips.h>
  2742. +#include <linux/cnt32_to_63.h>
  2743. +#include <linux/io.h>
  2744. +#include <linux/module.h>
  2745. +#include <linux/spi/spi.h>
  2746. +#include <linux/w1-gpio.h>
  2747. +
  2748. +#include <linux/version.h>
  2749. +#include <linux/clkdev.h>
  2750. +#include <asm/system_info.h>
  2751. +#include <mach/hardware.h>
  2752. +#include <asm/irq.h>
  2753. +#include <linux/leds.h>
  2754. +#include <asm/mach-types.h>
  2755. +#include <linux/sched_clock.h>
  2756. +
  2757. +#include <asm/mach/arch.h>
  2758. +#include <asm/mach/flash.h>
  2759. +#include <asm/mach/irq.h>
  2760. +#include <asm/mach/time.h>
  2761. +#include <asm/mach/map.h>
  2762. +
  2763. +#include <mach/timex.h>
  2764. +#include <mach/dma.h>
  2765. +#include <mach/vcio.h>
  2766. +#include <mach/system.h>
  2767. +
  2768. +#include <linux/delay.h>
  2769. +
  2770. +#include "bcm2708.h"
  2771. +#include "armctrl.h"
  2772. +#include "clock.h"
  2773. +
  2774. +#ifdef CONFIG_BCM_VC_CMA
  2775. +#include <linux/broadcom/vc_cma.h>
  2776. +#endif
  2777. +
  2778. +
  2779. +/* Effectively we have an IOMMU (ARM<->VideoCore map) that is set up to
  2780. + * give us IO access only to 64Mbytes of physical memory (26 bits). We could
  2781. + * represent this window by setting our dmamasks to 26 bits but, in fact
  2782. + * we're not going to use addresses outside this range (they're not in real
  2783. + * memory) so we don't bother.
  2784. + *
  2785. + * In the future we might include code to use this IOMMU to remap other
  2786. + * physical addresses onto VideoCore memory then the use of 32-bits would be
  2787. + * more legitimate.
  2788. + */
  2789. +#define DMA_MASK_BITS_COMMON 32
  2790. +
  2791. +// use GPIO 4 for the one-wire GPIO pin, if enabled
  2792. +#define W1_GPIO 4
  2793. +// ensure one-wire GPIO pullup is disabled by default
  2794. +#define W1_PULLUP -1
  2795. +
  2796. +/* command line parameters */
  2797. +static unsigned boardrev, serial;
  2798. +static unsigned uart_clock;
  2799. +static unsigned disk_led_gpio = 16;
  2800. +static unsigned disk_led_active_low = 1;
  2801. +static unsigned reboot_part = 0;
  2802. +static unsigned w1_gpio_pin = W1_GPIO;
  2803. +static unsigned w1_gpio_pullup = W1_PULLUP;
  2804. +
  2805. +static void __init bcm2708_init_led(void);
  2806. +
  2807. +void __init bcm2708_init_irq(void)
  2808. +{
  2809. + armctrl_init(__io_address(ARMCTRL_IC_BASE), 0, 0, 0);
  2810. +}
  2811. +
  2812. +static struct map_desc bcm2708_io_desc[] __initdata = {
  2813. + {
  2814. + .virtual = IO_ADDRESS(ARMCTRL_BASE),
  2815. + .pfn = __phys_to_pfn(ARMCTRL_BASE),
  2816. + .length = SZ_4K,
  2817. + .type = MT_DEVICE},
  2818. + {
  2819. + .virtual = IO_ADDRESS(UART0_BASE),
  2820. + .pfn = __phys_to_pfn(UART0_BASE),
  2821. + .length = SZ_4K,
  2822. + .type = MT_DEVICE},
  2823. + {
  2824. + .virtual = IO_ADDRESS(UART1_BASE),
  2825. + .pfn = __phys_to_pfn(UART1_BASE),
  2826. + .length = SZ_4K,
  2827. + .type = MT_DEVICE},
  2828. + {
  2829. + .virtual = IO_ADDRESS(DMA_BASE),
  2830. + .pfn = __phys_to_pfn(DMA_BASE),
  2831. + .length = SZ_4K,
  2832. + .type = MT_DEVICE},
  2833. + {
  2834. + .virtual = IO_ADDRESS(MCORE_BASE),
  2835. + .pfn = __phys_to_pfn(MCORE_BASE),
  2836. + .length = SZ_4K,
  2837. + .type = MT_DEVICE},
  2838. + {
  2839. + .virtual = IO_ADDRESS(ST_BASE),
  2840. + .pfn = __phys_to_pfn(ST_BASE),
  2841. + .length = SZ_4K,
  2842. + .type = MT_DEVICE},
  2843. + {
  2844. + .virtual = IO_ADDRESS(USB_BASE),
  2845. + .pfn = __phys_to_pfn(USB_BASE),
  2846. + .length = SZ_128K,
  2847. + .type = MT_DEVICE},
  2848. + {
  2849. + .virtual = IO_ADDRESS(PM_BASE),
  2850. + .pfn = __phys_to_pfn(PM_BASE),
  2851. + .length = SZ_4K,
  2852. + .type = MT_DEVICE},
  2853. + {
  2854. + .virtual = IO_ADDRESS(GPIO_BASE),
  2855. + .pfn = __phys_to_pfn(GPIO_BASE),
  2856. + .length = SZ_4K,
  2857. + .type = MT_DEVICE}
  2858. +};
  2859. +
  2860. +void __init bcm2708_map_io(void)
  2861. +{
  2862. + iotable_init(bcm2708_io_desc, ARRAY_SIZE(bcm2708_io_desc));
  2863. +}
  2864. +
  2865. +/* The STC is a free running counter that increments at the rate of 1MHz */
  2866. +#define STC_FREQ_HZ 1000000
  2867. +
  2868. +static inline uint32_t timer_read(void)
  2869. +{
  2870. + /* STC: a free running counter that increments at the rate of 1MHz */
  2871. + return readl(__io_address(ST_BASE + 0x04));
  2872. +}
  2873. +
  2874. +static unsigned long bcm2708_read_current_timer(void)
  2875. +{
  2876. + return timer_read();
  2877. +}
  2878. +
  2879. +static u32 notrace bcm2708_read_sched_clock(void)
  2880. +{
  2881. + return timer_read();
  2882. +}
  2883. +
  2884. +static cycle_t clksrc_read(struct clocksource *cs)
  2885. +{
  2886. + return timer_read();
  2887. +}
  2888. +
  2889. +static struct clocksource clocksource_stc = {
  2890. + .name = "stc",
  2891. + .rating = 300,
  2892. + .read = clksrc_read,
  2893. + .mask = CLOCKSOURCE_MASK(32),
  2894. + .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  2895. +};
  2896. +
  2897. +unsigned long frc_clock_ticks32(void)
  2898. +{
  2899. + return timer_read();
  2900. +}
  2901. +
  2902. +static void __init bcm2708_clocksource_init(void)
  2903. +{
  2904. + if (clocksource_register_hz(&clocksource_stc, STC_FREQ_HZ)) {
  2905. + printk(KERN_ERR "timer: failed to initialize clock "
  2906. + "source %s\n", clocksource_stc.name);
  2907. + }
  2908. +}
  2909. +
  2910. +
  2911. +/*
  2912. + * These are fixed clocks.
  2913. + */
  2914. +static struct clk ref24_clk = {
  2915. + .rate = UART0_CLOCK, /* The UART is clocked at 3MHz via APB_CLK */
  2916. +};
  2917. +
  2918. +static struct clk osc_clk = {
  2919. +#ifdef CONFIG_ARCH_BCM2708_CHIPIT
  2920. + .rate = 27000000,
  2921. +#else
  2922. + .rate = 500000000, /* ARM clock is set from the VideoCore booter */
  2923. +#endif
  2924. +};
  2925. +
  2926. +/* warning - the USB needs a clock > 34MHz */
  2927. +
  2928. +static struct clk sdhost_clk = {
  2929. +#ifdef CONFIG_ARCH_BCM2708_CHIPIT
  2930. + .rate = 4000000, /* 4MHz */
  2931. +#else
  2932. + .rate = 250000000, /* 250MHz */
  2933. +#endif
  2934. +};
  2935. +
  2936. +static struct clk_lookup lookups[] = {
  2937. + { /* UART0 */
  2938. + .dev_id = "dev:f1",
  2939. + .clk = &ref24_clk,
  2940. + },
  2941. + { /* USB */
  2942. + .dev_id = "bcm2708_usb",
  2943. + .clk = &osc_clk,
  2944. + }, { /* SPI */
  2945. + .dev_id = "bcm2708_spi.0",
  2946. + .clk = &sdhost_clk,
  2947. + }, { /* BSC0 */
  2948. + .dev_id = "bcm2708_i2c.0",
  2949. + .clk = &sdhost_clk,
  2950. + }, { /* BSC1 */
  2951. + .dev_id = "bcm2708_i2c.1",
  2952. + .clk = &sdhost_clk,
  2953. + }
  2954. +};
  2955. +
  2956. +#define UART0_IRQ { IRQ_UART, 0 /*NO_IRQ*/ }
  2957. +#define UART0_DMA { 15, 14 }
  2958. +
  2959. +AMBA_DEVICE(uart0, "dev:f1", UART0, NULL);
  2960. +
  2961. +static struct amba_device *amba_devs[] __initdata = {
  2962. + &uart0_device,
  2963. +};
  2964. +
  2965. +static struct resource bcm2708_dmaman_resources[] = {
  2966. + {
  2967. + .start = DMA_BASE,
  2968. + .end = DMA_BASE + SZ_4K - 1,
  2969. + .flags = IORESOURCE_MEM,
  2970. + }
  2971. +};
  2972. +
  2973. +static struct platform_device bcm2708_dmaman_device = {
  2974. + .name = BCM_DMAMAN_DRIVER_NAME,
  2975. + .id = 0, /* first bcm2708_dma */
  2976. + .resource = bcm2708_dmaman_resources,
  2977. + .num_resources = ARRAY_SIZE(bcm2708_dmaman_resources),
  2978. +};
  2979. +
  2980. +#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
  2981. +static struct w1_gpio_platform_data w1_gpio_pdata = {
  2982. + .pin = W1_GPIO,
  2983. + .ext_pullup_enable_pin = W1_PULLUP,
  2984. + .is_open_drain = 0,
  2985. +};
  2986. +
  2987. +static struct platform_device w1_device = {
  2988. + .name = "w1-gpio",
  2989. + .id = -1,
  2990. + .dev.platform_data = &w1_gpio_pdata,
  2991. +};
  2992. +#endif
  2993. +
  2994. +static u64 fb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  2995. +
  2996. +static struct platform_device bcm2708_fb_device = {
  2997. + .name = "bcm2708_fb",
  2998. + .id = -1, /* only one bcm2708_fb */
  2999. + .resource = NULL,
  3000. + .num_resources = 0,
  3001. + .dev = {
  3002. + .dma_mask = &fb_dmamask,
  3003. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3004. + },
  3005. +};
  3006. +
  3007. +static struct plat_serial8250_port bcm2708_uart1_platform_data[] = {
  3008. + {
  3009. + .mapbase = UART1_BASE + 0x40,
  3010. + .irq = IRQ_AUX,
  3011. + .uartclk = 125000000,
  3012. + .regshift = 2,
  3013. + .iotype = UPIO_MEM,
  3014. + .flags = UPF_FIXED_TYPE | UPF_IOREMAP | UPF_SKIP_TEST,
  3015. + .type = PORT_8250,
  3016. + },
  3017. + {},
  3018. +};
  3019. +
  3020. +static struct platform_device bcm2708_uart1_device = {
  3021. + .name = "serial8250",
  3022. + .id = PLAT8250_DEV_PLATFORM,
  3023. + .dev = {
  3024. + .platform_data = bcm2708_uart1_platform_data,
  3025. + },
  3026. +};
  3027. +
  3028. +static struct resource bcm2708_usb_resources[] = {
  3029. + [0] = {
  3030. + .start = USB_BASE,
  3031. + .end = USB_BASE + SZ_128K - 1,
  3032. + .flags = IORESOURCE_MEM,
  3033. + },
  3034. + [1] = {
  3035. + .start = MPHI_BASE,
  3036. + .end = MPHI_BASE + SZ_4K - 1,
  3037. + .flags = IORESOURCE_MEM,
  3038. + },
  3039. + [2] = {
  3040. + .start = IRQ_HOSTPORT,
  3041. + .end = IRQ_HOSTPORT,
  3042. + .flags = IORESOURCE_IRQ,
  3043. + },
  3044. + [3] = {
  3045. + .start = IRQ_USB,
  3046. + .end = IRQ_USB,
  3047. + .flags = IORESOURCE_IRQ,
  3048. + },
  3049. +};
  3050. +
  3051. +
  3052. +static u64 usb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3053. +
  3054. +static struct platform_device bcm2708_usb_device = {
  3055. + .name = "bcm2708_usb",
  3056. + .id = -1, /* only one bcm2708_usb */
  3057. + .resource = bcm2708_usb_resources,
  3058. + .num_resources = ARRAY_SIZE(bcm2708_usb_resources),
  3059. + .dev = {
  3060. + .dma_mask = &usb_dmamask,
  3061. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3062. + },
  3063. +};
  3064. +
  3065. +static struct resource bcm2708_vcio_resources[] = {
  3066. + [0] = { /* mailbox/semaphore/doorbell access */
  3067. + .start = MCORE_BASE,
  3068. + .end = MCORE_BASE + SZ_4K - 1,
  3069. + .flags = IORESOURCE_MEM,
  3070. + },
  3071. +};
  3072. +
  3073. +static u64 vcio_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3074. +
  3075. +static struct platform_device bcm2708_vcio_device = {
  3076. + .name = BCM_VCIO_DRIVER_NAME,
  3077. + .id = -1, /* only one VideoCore I/O area */
  3078. + .resource = bcm2708_vcio_resources,
  3079. + .num_resources = ARRAY_SIZE(bcm2708_vcio_resources),
  3080. + .dev = {
  3081. + .dma_mask = &vcio_dmamask,
  3082. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3083. + },
  3084. +};
  3085. +
  3086. +#ifdef CONFIG_BCM2708_GPIO
  3087. +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
  3088. +
  3089. +static struct resource bcm2708_gpio_resources[] = {
  3090. + [0] = { /* general purpose I/O */
  3091. + .start = GPIO_BASE,
  3092. + .end = GPIO_BASE + SZ_4K - 1,
  3093. + .flags = IORESOURCE_MEM,
  3094. + },
  3095. +};
  3096. +
  3097. +static u64 gpio_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3098. +
  3099. +static struct platform_device bcm2708_gpio_device = {
  3100. + .name = BCM_GPIO_DRIVER_NAME,
  3101. + .id = -1, /* only one VideoCore I/O area */
  3102. + .resource = bcm2708_gpio_resources,
  3103. + .num_resources = ARRAY_SIZE(bcm2708_gpio_resources),
  3104. + .dev = {
  3105. + .dma_mask = &gpio_dmamask,
  3106. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3107. + },
  3108. +};
  3109. +#endif
  3110. +
  3111. +static struct resource bcm2708_systemtimer_resources[] = {
  3112. + [0] = { /* system timer access */
  3113. + .start = ST_BASE,
  3114. + .end = ST_BASE + SZ_4K - 1,
  3115. + .flags = IORESOURCE_MEM,
  3116. + },
  3117. + {
  3118. + .start = IRQ_TIMER3,
  3119. + .end = IRQ_TIMER3,
  3120. + .flags = IORESOURCE_IRQ,
  3121. + }
  3122. +
  3123. +};
  3124. +
  3125. +static u64 systemtimer_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3126. +
  3127. +static struct platform_device bcm2708_systemtimer_device = {
  3128. + .name = "bcm2708_systemtimer",
  3129. + .id = -1, /* only one VideoCore I/O area */
  3130. + .resource = bcm2708_systemtimer_resources,
  3131. + .num_resources = ARRAY_SIZE(bcm2708_systemtimer_resources),
  3132. + .dev = {
  3133. + .dma_mask = &systemtimer_dmamask,
  3134. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3135. + },
  3136. +};
  3137. +
  3138. +#ifdef CONFIG_MMC_SDHCI_BCM2708 /* Arasan emmc SD */
  3139. +static struct resource bcm2708_emmc_resources[] = {
  3140. + [0] = {
  3141. + .start = EMMC_BASE,
  3142. + .end = EMMC_BASE + SZ_256 - 1, /* we only need this area */
  3143. + /* the memory map actually makes SZ_4K available */
  3144. + .flags = IORESOURCE_MEM,
  3145. + },
  3146. + [1] = {
  3147. + .start = IRQ_ARASANSDIO,
  3148. + .end = IRQ_ARASANSDIO,
  3149. + .flags = IORESOURCE_IRQ,
  3150. + },
  3151. +};
  3152. +
  3153. +static u64 bcm2708_emmc_dmamask = 0xffffffffUL;
  3154. +
  3155. +struct platform_device bcm2708_emmc_device = {
  3156. + .name = "bcm2708_sdhci",
  3157. + .id = 0,
  3158. + .num_resources = ARRAY_SIZE(bcm2708_emmc_resources),
  3159. + .resource = bcm2708_emmc_resources,
  3160. + .dev = {
  3161. + .dma_mask = &bcm2708_emmc_dmamask,
  3162. + .coherent_dma_mask = 0xffffffffUL},
  3163. +};
  3164. +#endif /* CONFIG_MMC_SDHCI_BCM2708 */
  3165. +
  3166. +static struct resource bcm2708_powerman_resources[] = {
  3167. + [0] = {
  3168. + .start = PM_BASE,
  3169. + .end = PM_BASE + SZ_256 - 1,
  3170. + .flags = IORESOURCE_MEM,
  3171. + },
  3172. +};
  3173. +
  3174. +static u64 powerman_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3175. +
  3176. +struct platform_device bcm2708_powerman_device = {
  3177. + .name = "bcm2708_powerman",
  3178. + .id = 0,
  3179. + .num_resources = ARRAY_SIZE(bcm2708_powerman_resources),
  3180. + .resource = bcm2708_powerman_resources,
  3181. + .dev = {
  3182. + .dma_mask = &powerman_dmamask,
  3183. + .coherent_dma_mask = 0xffffffffUL},
  3184. +};
  3185. +
  3186. +
  3187. +static struct platform_device bcm2708_alsa_devices[] = {
  3188. + [0] = {
  3189. + .name = "bcm2835_AUD0",
  3190. + .id = 0, /* first audio device */
  3191. + .resource = 0,
  3192. + .num_resources = 0,
  3193. + },
  3194. + [1] = {
  3195. + .name = "bcm2835_AUD1",
  3196. + .id = 1, /* second audio device */
  3197. + .resource = 0,
  3198. + .num_resources = 0,
  3199. + },
  3200. + [2] = {
  3201. + .name = "bcm2835_AUD2",
  3202. + .id = 2, /* third audio device */
  3203. + .resource = 0,
  3204. + .num_resources = 0,
  3205. + },
  3206. + [3] = {
  3207. + .name = "bcm2835_AUD3",
  3208. + .id = 3, /* forth audio device */
  3209. + .resource = 0,
  3210. + .num_resources = 0,
  3211. + },
  3212. + [4] = {
  3213. + .name = "bcm2835_AUD4",
  3214. + .id = 4, /* fifth audio device */
  3215. + .resource = 0,
  3216. + .num_resources = 0,
  3217. + },
  3218. + [5] = {
  3219. + .name = "bcm2835_AUD5",
  3220. + .id = 5, /* sixth audio device */
  3221. + .resource = 0,
  3222. + .num_resources = 0,
  3223. + },
  3224. + [6] = {
  3225. + .name = "bcm2835_AUD6",
  3226. + .id = 6, /* seventh audio device */
  3227. + .resource = 0,
  3228. + .num_resources = 0,
  3229. + },
  3230. + [7] = {
  3231. + .name = "bcm2835_AUD7",
  3232. + .id = 7, /* eighth audio device */
  3233. + .resource = 0,
  3234. + .num_resources = 0,
  3235. + },
  3236. +};
  3237. +
  3238. +static struct resource bcm2708_spi_resources[] = {
  3239. + {
  3240. + .start = SPI0_BASE,
  3241. + .end = SPI0_BASE + SZ_256 - 1,
  3242. + .flags = IORESOURCE_MEM,
  3243. + }, {
  3244. + .start = IRQ_SPI,
  3245. + .end = IRQ_SPI,
  3246. + .flags = IORESOURCE_IRQ,
  3247. + }
  3248. +};
  3249. +
  3250. +
  3251. +static u64 bcm2708_spi_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3252. +static struct platform_device bcm2708_spi_device = {
  3253. + .name = "bcm2708_spi",
  3254. + .id = 0,
  3255. + .num_resources = ARRAY_SIZE(bcm2708_spi_resources),
  3256. + .resource = bcm2708_spi_resources,
  3257. + .dev = {
  3258. + .dma_mask = &bcm2708_spi_dmamask,
  3259. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON)},
  3260. +};
  3261. +
  3262. +#ifdef CONFIG_BCM2708_SPIDEV
  3263. +static struct spi_board_info bcm2708_spi_devices[] = {
  3264. +#ifdef CONFIG_SPI_SPIDEV
  3265. + {
  3266. + .modalias = "spidev",
  3267. + .max_speed_hz = 500000,
  3268. + .bus_num = 0,
  3269. + .chip_select = 0,
  3270. + .mode = SPI_MODE_0,
  3271. + }, {
  3272. + .modalias = "spidev",
  3273. + .max_speed_hz = 500000,
  3274. + .bus_num = 0,
  3275. + .chip_select = 1,
  3276. + .mode = SPI_MODE_0,
  3277. + }
  3278. +#endif
  3279. +};
  3280. +#endif
  3281. +
  3282. +static struct resource bcm2708_bsc0_resources[] = {
  3283. + {
  3284. + .start = BSC0_BASE,
  3285. + .end = BSC0_BASE + SZ_256 - 1,
  3286. + .flags = IORESOURCE_MEM,
  3287. + }, {
  3288. + .start = INTERRUPT_I2C,
  3289. + .end = INTERRUPT_I2C,
  3290. + .flags = IORESOURCE_IRQ,
  3291. + }
  3292. +};
  3293. +
  3294. +static struct platform_device bcm2708_bsc0_device = {
  3295. + .name = "bcm2708_i2c",
  3296. + .id = 0,
  3297. + .num_resources = ARRAY_SIZE(bcm2708_bsc0_resources),
  3298. + .resource = bcm2708_bsc0_resources,
  3299. +};
  3300. +
  3301. +
  3302. +static struct resource bcm2708_bsc1_resources[] = {
  3303. + {
  3304. + .start = BSC1_BASE,
  3305. + .end = BSC1_BASE + SZ_256 - 1,
  3306. + .flags = IORESOURCE_MEM,
  3307. + }, {
  3308. + .start = INTERRUPT_I2C,
  3309. + .end = INTERRUPT_I2C,
  3310. + .flags = IORESOURCE_IRQ,
  3311. + }
  3312. +};
  3313. +
  3314. +static struct platform_device bcm2708_bsc1_device = {
  3315. + .name = "bcm2708_i2c",
  3316. + .id = 1,
  3317. + .num_resources = ARRAY_SIZE(bcm2708_bsc1_resources),
  3318. + .resource = bcm2708_bsc1_resources,
  3319. +};
  3320. +
  3321. +static struct platform_device bcm2835_hwmon_device = {
  3322. + .name = "bcm2835_hwmon",
  3323. +};
  3324. +
  3325. +static struct platform_device bcm2835_thermal_device = {
  3326. + .name = "bcm2835_thermal",
  3327. +};
  3328. +
  3329. +#ifdef CONFIG_SND_BCM2708_SOC_I2S_MODULE
  3330. +static struct resource bcm2708_i2s_resources[] = {
  3331. + {
  3332. + .start = I2S_BASE,
  3333. + .end = I2S_BASE + 0x20,
  3334. + .flags = IORESOURCE_MEM,
  3335. + },
  3336. + {
  3337. + .start = PCM_CLOCK_BASE,
  3338. + .end = PCM_CLOCK_BASE + 0x02,
  3339. + .flags = IORESOURCE_MEM,
  3340. + }
  3341. +};
  3342. +
  3343. +static struct platform_device bcm2708_i2s_device = {
  3344. + .name = "bcm2708-i2s",
  3345. + .id = 0,
  3346. + .num_resources = ARRAY_SIZE(bcm2708_i2s_resources),
  3347. + .resource = bcm2708_i2s_resources,
  3348. +};
  3349. +#endif
  3350. +
  3351. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC_MODULE)
  3352. +static struct platform_device snd_hifiberry_dac_device = {
  3353. + .name = "snd-hifiberry-dac",
  3354. + .id = 0,
  3355. + .num_resources = 0,
  3356. +};
  3357. +
  3358. +static struct platform_device snd_pcm5102a_codec_device = {
  3359. + .name = "pcm5102a-codec",
  3360. + .id = -1,
  3361. + .num_resources = 0,
  3362. +};
  3363. +#endif
  3364. +
  3365. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
  3366. +static struct platform_device snd_hifiberry_digi_device = {
  3367. + .name = "snd-hifiberry-digi",
  3368. + .id = 0,
  3369. + .num_resources = 0,
  3370. +};
  3371. +
  3372. +static struct i2c_board_info __initdata snd_wm8804_i2c_devices[] = {
  3373. + {
  3374. + I2C_BOARD_INFO("wm8804", 0x3b)
  3375. + },
  3376. +};
  3377. +
  3378. +#endif
  3379. +
  3380. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
  3381. +static struct platform_device snd_rpi_dac_device = {
  3382. + .name = "snd-rpi-dac",
  3383. + .id = 0,
  3384. + .num_resources = 0,
  3385. +};
  3386. +
  3387. +static struct platform_device snd_pcm1794a_codec_device = {
  3388. + .name = "pcm1794a-codec",
  3389. + .id = -1,
  3390. + .num_resources = 0,
  3391. +};
  3392. +#endif
  3393. +
  3394. +
  3395. +#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE)
  3396. +static struct platform_device snd_rpi_iqaudio_dac_device = {
  3397. + .name = "snd-rpi-iqaudio-dac",
  3398. + .id = 0,
  3399. + .num_resources = 0,
  3400. +};
  3401. +
  3402. +// Use the actual device name rather than generic driver name
  3403. +static struct i2c_board_info __initdata snd_pcm512x_i2c_devices[] = {
  3404. + {
  3405. + I2C_BOARD_INFO("pcm5122", 0x4c)
  3406. + },
  3407. +};
  3408. +#endif
  3409. +
  3410. +int __init bcm_register_device(struct platform_device *pdev)
  3411. +{
  3412. + int ret;
  3413. +
  3414. + ret = platform_device_register(pdev);
  3415. + if (ret)
  3416. + pr_debug("Unable to register platform device '%s': %d\n",
  3417. + pdev->name, ret);
  3418. +
  3419. + return ret;
  3420. +}
  3421. +
  3422. +int calc_rsts(int partition)
  3423. +{
  3424. + return PM_PASSWORD |
  3425. + ((partition & (1 << 0)) << 0) |
  3426. + ((partition & (1 << 1)) << 1) |
  3427. + ((partition & (1 << 2)) << 2) |
  3428. + ((partition & (1 << 3)) << 3) |
  3429. + ((partition & (1 << 4)) << 4) |
  3430. + ((partition & (1 << 5)) << 5);
  3431. +}
  3432. +
  3433. +static void bcm2708_restart(enum reboot_mode mode, const char *cmd)
  3434. +{
  3435. + extern char bcm2708_reboot_mode;
  3436. + uint32_t pm_rstc, pm_wdog;
  3437. + uint32_t timeout = 10;
  3438. + uint32_t pm_rsts = 0;
  3439. +
  3440. + if(bcm2708_reboot_mode == 'q')
  3441. + {
  3442. + // NOOBS < 1.3 booting with reboot=q
  3443. + pm_rsts = readl(__io_address(PM_RSTS));
  3444. + pm_rsts = PM_PASSWORD | pm_rsts | PM_RSTS_HADWRQ_SET;
  3445. + }
  3446. + else if(bcm2708_reboot_mode == 'p')
  3447. + {
  3448. + // NOOBS < 1.3 halting
  3449. + pm_rsts = readl(__io_address(PM_RSTS));
  3450. + pm_rsts = PM_PASSWORD | pm_rsts | PM_RSTS_HADWRH_SET;
  3451. + }
  3452. + else
  3453. + {
  3454. + pm_rsts = calc_rsts(reboot_part);
  3455. + }
  3456. +
  3457. + writel(pm_rsts, __io_address(PM_RSTS));
  3458. +
  3459. + /* Setup watchdog for reset */
  3460. + pm_rstc = readl(__io_address(PM_RSTC));
  3461. +
  3462. + pm_wdog = PM_PASSWORD | (timeout & PM_WDOG_TIME_SET); // watchdog timer = timer clock / 16; need password (31:16) + value (11:0)
  3463. + pm_rstc = PM_PASSWORD | (pm_rstc & PM_RSTC_WRCFG_CLR) | PM_RSTC_WRCFG_FULL_RESET;
  3464. +
  3465. + writel(pm_wdog, __io_address(PM_WDOG));
  3466. + writel(pm_rstc, __io_address(PM_RSTC));
  3467. +}
  3468. +
  3469. +/* We can't really power off, but if we do the normal reset scheme, and indicate to bootcode.bin not to reboot, then most of the chip will be powered off */
  3470. +static void bcm2708_power_off(void)
  3471. +{
  3472. + extern char bcm2708_reboot_mode;
  3473. + if(bcm2708_reboot_mode == 'q')
  3474. + {
  3475. + // NOOBS < v1.3
  3476. + bcm2708_restart('p', "");
  3477. + }
  3478. + else
  3479. + {
  3480. + /* partition 63 is special code for HALT the bootloader knows not to boot*/
  3481. + reboot_part = 63;
  3482. + /* continue with normal reset mechanism */
  3483. + bcm2708_restart(0, "");
  3484. + }
  3485. +}
  3486. +
  3487. +void __init bcm2708_init(void)
  3488. +{
  3489. + int i;
  3490. +
  3491. +#if defined(CONFIG_BCM_VC_CMA)
  3492. + vc_cma_early_init();
  3493. +#endif
  3494. + printk("bcm2708.uart_clock = %d\n", uart_clock);
  3495. + pm_power_off = bcm2708_power_off;
  3496. +
  3497. + if (uart_clock)
  3498. + lookups[0].clk->rate = uart_clock;
  3499. +
  3500. + for (i = 0; i < ARRAY_SIZE(lookups); i++)
  3501. + clkdev_add(&lookups[i]);
  3502. +
  3503. + bcm_register_device(&bcm2708_dmaman_device);
  3504. + bcm_register_device(&bcm2708_vcio_device);
  3505. +#ifdef CONFIG_BCM2708_GPIO
  3506. + bcm_register_device(&bcm2708_gpio_device);
  3507. +#endif
  3508. +#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
  3509. + w1_gpio_pdata.pin = w1_gpio_pin;
  3510. + w1_gpio_pdata.ext_pullup_enable_pin = w1_gpio_pullup;
  3511. + platform_device_register(&w1_device);
  3512. +#endif
  3513. + bcm_register_device(&bcm2708_systemtimer_device);
  3514. + bcm_register_device(&bcm2708_fb_device);
  3515. + bcm_register_device(&bcm2708_usb_device);
  3516. + bcm_register_device(&bcm2708_uart1_device);
  3517. + bcm_register_device(&bcm2708_powerman_device);
  3518. +
  3519. +#ifdef CONFIG_MMC_SDHCI_BCM2708
  3520. + bcm_register_device(&bcm2708_emmc_device);
  3521. +#endif
  3522. + bcm2708_init_led();
  3523. + for (i = 0; i < ARRAY_SIZE(bcm2708_alsa_devices); i++)
  3524. + bcm_register_device(&bcm2708_alsa_devices[i]);
  3525. +
  3526. + bcm_register_device(&bcm2708_spi_device);
  3527. + bcm_register_device(&bcm2708_bsc0_device);
  3528. + bcm_register_device(&bcm2708_bsc1_device);
  3529. +
  3530. + bcm_register_device(&bcm2835_hwmon_device);
  3531. + bcm_register_device(&bcm2835_thermal_device);
  3532. +
  3533. +#ifdef CONFIG_SND_BCM2708_SOC_I2S_MODULE
  3534. + bcm_register_device(&bcm2708_i2s_device);
  3535. +#endif
  3536. +
  3537. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC_MODULE)
  3538. + bcm_register_device(&snd_hifiberry_dac_device);
  3539. + bcm_register_device(&snd_pcm5102a_codec_device);
  3540. +#endif
  3541. +
  3542. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
  3543. + bcm_register_device(&snd_hifiberry_digi_device);
  3544. + i2c_register_board_info(1, snd_wm8804_i2c_devices, ARRAY_SIZE(snd_wm8804_i2c_devices));
  3545. +#endif
  3546. +
  3547. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
  3548. + bcm_register_device(&snd_rpi_dac_device);
  3549. + bcm_register_device(&snd_pcm1794a_codec_device);
  3550. +#endif
  3551. +
  3552. +#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE)
  3553. + bcm_register_device(&snd_rpi_iqaudio_dac_device);
  3554. + i2c_register_board_info(1, snd_pcm512x_i2c_devices, ARRAY_SIZE(snd_pcm512x_i2c_devices));
  3555. +#endif
  3556. +
  3557. +
  3558. + for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  3559. + struct amba_device *d = amba_devs[i];
  3560. + amba_device_register(d, &iomem_resource);
  3561. + }
  3562. + system_rev = boardrev;
  3563. + system_serial_low = serial;
  3564. +
  3565. +#ifdef CONFIG_BCM2708_SPIDEV
  3566. + spi_register_board_info(bcm2708_spi_devices,
  3567. + ARRAY_SIZE(bcm2708_spi_devices));
  3568. +#endif
  3569. +}
  3570. +
  3571. +static void timer_set_mode(enum clock_event_mode mode,
  3572. + struct clock_event_device *clk)
  3573. +{
  3574. + switch (mode) {
  3575. + case CLOCK_EVT_MODE_ONESHOT: /* Leave the timer disabled, .set_next_event will enable it */
  3576. + case CLOCK_EVT_MODE_SHUTDOWN:
  3577. + break;
  3578. + case CLOCK_EVT_MODE_PERIODIC:
  3579. +
  3580. + case CLOCK_EVT_MODE_UNUSED:
  3581. + case CLOCK_EVT_MODE_RESUME:
  3582. +
  3583. + default:
  3584. + printk(KERN_ERR "timer_set_mode: unhandled mode:%d\n",
  3585. + (int)mode);
  3586. + break;
  3587. + }
  3588. +
  3589. +}
  3590. +
  3591. +static int timer_set_next_event(unsigned long cycles,
  3592. + struct clock_event_device *unused)
  3593. +{
  3594. + unsigned long stc;
  3595. + do {
  3596. + stc = readl(__io_address(ST_BASE + 0x04));
  3597. + /* We could take a FIQ here, which may push ST above STC3 */
  3598. + writel(stc + cycles, __io_address(ST_BASE + 0x18));
  3599. + } while ((signed long) (readl(__io_address(ST_BASE + 0x04)) - stc)
  3600. + >= (signed long) cycles);
  3601. + return 0;
  3602. +}
  3603. +
  3604. +static struct clock_event_device timer0_clockevent = {
  3605. + .name = "timer0",
  3606. + .shift = 32,
  3607. + .features = CLOCK_EVT_FEAT_ONESHOT,
  3608. + .set_mode = timer_set_mode,
  3609. + .set_next_event = timer_set_next_event,
  3610. +};
  3611. +
  3612. +/*
  3613. + * IRQ handler for the timer
  3614. + */
  3615. +static irqreturn_t bcm2708_timer_interrupt(int irq, void *dev_id)
  3616. +{
  3617. + struct clock_event_device *evt = &timer0_clockevent;
  3618. +
  3619. + writel(1 << 3, __io_address(ST_BASE + 0x00)); /* stcs clear timer int */
  3620. +
  3621. + evt->event_handler(evt);
  3622. +
  3623. + return IRQ_HANDLED;
  3624. +}
  3625. +
  3626. +static struct irqaction bcm2708_timer_irq = {
  3627. + .name = "BCM2708 Timer Tick",
  3628. + .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  3629. + .handler = bcm2708_timer_interrupt,
  3630. +};
  3631. +
  3632. +/*
  3633. + * Set up timer interrupt, and return the current time in seconds.
  3634. + */
  3635. +
  3636. +static struct delay_timer bcm2708_delay_timer = {
  3637. + .read_current_timer = bcm2708_read_current_timer,
  3638. + .freq = STC_FREQ_HZ,
  3639. +};
  3640. +
  3641. +static void __init bcm2708_timer_init(void)
  3642. +{
  3643. + /* init high res timer */
  3644. + bcm2708_clocksource_init();
  3645. +
  3646. + /*
  3647. + * Initialise to a known state (all timers off)
  3648. + */
  3649. + writel(0, __io_address(ARM_T_CONTROL));
  3650. + /*
  3651. + * Make irqs happen for the system timer
  3652. + */
  3653. + setup_irq(IRQ_TIMER3, &bcm2708_timer_irq);
  3654. +
  3655. + setup_sched_clock(bcm2708_read_sched_clock, 32, STC_FREQ_HZ);
  3656. +
  3657. + timer0_clockevent.mult =
  3658. + div_sc(STC_FREQ_HZ, NSEC_PER_SEC, timer0_clockevent.shift);
  3659. + timer0_clockevent.max_delta_ns =
  3660. + clockevent_delta2ns(0xffffffff, &timer0_clockevent);
  3661. + timer0_clockevent.min_delta_ns =
  3662. + clockevent_delta2ns(0xf, &timer0_clockevent);
  3663. +
  3664. + timer0_clockevent.cpumask = cpumask_of(0);
  3665. + clockevents_register_device(&timer0_clockevent);
  3666. +
  3667. + register_current_timer_delay(&bcm2708_delay_timer);
  3668. +}
  3669. +
  3670. +#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
  3671. +#include <linux/leds.h>
  3672. +
  3673. +static struct gpio_led bcm2708_leds[] = {
  3674. + [0] = {
  3675. + .gpio = 16,
  3676. + .name = "led0",
  3677. + .default_trigger = "mmc0",
  3678. + .active_low = 1,
  3679. + },
  3680. +};
  3681. +
  3682. +static struct gpio_led_platform_data bcm2708_led_pdata = {
  3683. + .num_leds = ARRAY_SIZE(bcm2708_leds),
  3684. + .leds = bcm2708_leds,
  3685. +};
  3686. +
  3687. +static struct platform_device bcm2708_led_device = {
  3688. + .name = "leds-gpio",
  3689. + .id = -1,
  3690. + .dev = {
  3691. + .platform_data = &bcm2708_led_pdata,
  3692. + },
  3693. +};
  3694. +
  3695. +static void __init bcm2708_init_led(void)
  3696. +{
  3697. + bcm2708_leds[0].gpio = disk_led_gpio;
  3698. + bcm2708_leds[0].active_low = disk_led_active_low;
  3699. + platform_device_register(&bcm2708_led_device);
  3700. +}
  3701. +#else
  3702. +static inline void bcm2708_init_led(void)
  3703. +{
  3704. +}
  3705. +#endif
  3706. +
  3707. +void __init bcm2708_init_early(void)
  3708. +{
  3709. + /*
  3710. + * Some devices allocate their coherent buffers from atomic
  3711. + * context. Increase size of atomic coherent pool to make sure such
  3712. + * the allocations won't fail.
  3713. + */
  3714. + init_dma_coherent_pool_size(SZ_4M);
  3715. +}
  3716. +
  3717. +static void __init board_reserve(void)
  3718. +{
  3719. +#if defined(CONFIG_BCM_VC_CMA)
  3720. + vc_cma_reserve();
  3721. +#endif
  3722. +}
  3723. +
  3724. +MACHINE_START(BCM2708, "BCM2708")
  3725. + /* Maintainer: Broadcom Europe Ltd. */
  3726. + .map_io = bcm2708_map_io,
  3727. + .init_irq = bcm2708_init_irq,
  3728. + .init_time = bcm2708_timer_init,
  3729. + .init_machine = bcm2708_init,
  3730. + .init_early = bcm2708_init_early,
  3731. + .reserve = board_reserve,
  3732. + .restart = bcm2708_restart,
  3733. +MACHINE_END
  3734. +
  3735. +module_param(boardrev, uint, 0644);
  3736. +module_param(serial, uint, 0644);
  3737. +module_param(uart_clock, uint, 0644);
  3738. +module_param(disk_led_gpio, uint, 0644);
  3739. +module_param(disk_led_active_low, uint, 0644);
  3740. +module_param(reboot_part, uint, 0644);
  3741. +module_param(w1_gpio_pin, uint, 0644);
  3742. +module_param(w1_gpio_pullup, uint, 0644);
  3743. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/bcm2708_gpio.c linux-rpi/arch/arm/mach-bcm2708/bcm2708_gpio.c
  3744. --- linux-3.15.4/arch/arm/mach-bcm2708/bcm2708_gpio.c 1970-01-01 01:00:00.000000000 +0100
  3745. +++ linux-rpi/arch/arm/mach-bcm2708/bcm2708_gpio.c 2014-06-29 11:34:17.000000000 +0200
  3746. @@ -0,0 +1,361 @@
  3747. +/*
  3748. + * linux/arch/arm/mach-bcm2708/bcm2708_gpio.c
  3749. + *
  3750. + * Copyright (C) 2010 Broadcom
  3751. + *
  3752. + * This program is free software; you can redistribute it and/or modify
  3753. + * it under the terms of the GNU General Public License version 2 as
  3754. + * published by the Free Software Foundation.
  3755. + *
  3756. + */
  3757. +
  3758. +#include <linux/spinlock.h>
  3759. +#include <linux/module.h>
  3760. +#include <linux/list.h>
  3761. +#include <linux/io.h>
  3762. +#include <linux/irq.h>
  3763. +#include <linux/interrupt.h>
  3764. +#include <linux/slab.h>
  3765. +#include <mach/gpio.h>
  3766. +#include <linux/gpio.h>
  3767. +#include <linux/platform_device.h>
  3768. +#include <mach/platform.h>
  3769. +
  3770. +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
  3771. +#define DRIVER_NAME BCM_GPIO_DRIVER_NAME
  3772. +#define BCM_GPIO_USE_IRQ 1
  3773. +
  3774. +#define GPIOFSEL(x) (0x00+(x)*4)
  3775. +#define GPIOSET(x) (0x1c+(x)*4)
  3776. +#define GPIOCLR(x) (0x28+(x)*4)
  3777. +#define GPIOLEV(x) (0x34+(x)*4)
  3778. +#define GPIOEDS(x) (0x40+(x)*4)
  3779. +#define GPIOREN(x) (0x4c+(x)*4)
  3780. +#define GPIOFEN(x) (0x58+(x)*4)
  3781. +#define GPIOHEN(x) (0x64+(x)*4)
  3782. +#define GPIOLEN(x) (0x70+(x)*4)
  3783. +#define GPIOAREN(x) (0x7c+(x)*4)
  3784. +#define GPIOAFEN(x) (0x88+(x)*4)
  3785. +#define GPIOUD(x) (0x94+(x)*4)
  3786. +#define GPIOUDCLK(x) (0x98+(x)*4)
  3787. +
  3788. +enum { GPIO_FSEL_INPUT, GPIO_FSEL_OUTPUT,
  3789. + GPIO_FSEL_ALT5, GPIO_FSEL_ALT_4,
  3790. + GPIO_FSEL_ALT0, GPIO_FSEL_ALT1,
  3791. + GPIO_FSEL_ALT2, GPIO_FSEL_ALT3,
  3792. +};
  3793. +
  3794. + /* Each of the two spinlocks protects a different set of hardware
  3795. + * regiters and data structurs. This decouples the code of the IRQ from
  3796. + * the GPIO code. This also makes the case of a GPIO routine call from
  3797. + * the IRQ code simpler.
  3798. + */
  3799. +static DEFINE_SPINLOCK(lock); /* GPIO registers */
  3800. +
  3801. +struct bcm2708_gpio {
  3802. + struct list_head list;
  3803. + void __iomem *base;
  3804. + struct gpio_chip gc;
  3805. + unsigned long rising;
  3806. + unsigned long falling;
  3807. + unsigned long high;
  3808. + unsigned long low;
  3809. +};
  3810. +
  3811. +static int bcm2708_set_function(struct gpio_chip *gc, unsigned offset,
  3812. + int function)
  3813. +{
  3814. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  3815. + unsigned long flags;
  3816. + unsigned gpiodir;
  3817. + unsigned gpio_bank = offset / 10;
  3818. + unsigned gpio_field_offset = (offset - 10 * gpio_bank) * 3;
  3819. +
  3820. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_set_function %p (%d,%d)\n", gc, offset, function);
  3821. + if (offset >= BCM2708_NR_GPIOS)
  3822. + return -EINVAL;
  3823. +
  3824. + spin_lock_irqsave(&lock, flags);
  3825. +
  3826. + gpiodir = readl(gpio->base + GPIOFSEL(gpio_bank));
  3827. + gpiodir &= ~(7 << gpio_field_offset);
  3828. + gpiodir |= function << gpio_field_offset;
  3829. + writel(gpiodir, gpio->base + GPIOFSEL(gpio_bank));
  3830. + spin_unlock_irqrestore(&lock, flags);
  3831. + gpiodir = readl(gpio->base + GPIOFSEL(gpio_bank));
  3832. +
  3833. + return 0;
  3834. +}
  3835. +
  3836. +static int bcm2708_gpio_dir_in(struct gpio_chip *gc, unsigned offset)
  3837. +{
  3838. + return bcm2708_set_function(gc, offset, GPIO_FSEL_INPUT);
  3839. +}
  3840. +
  3841. +static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value);
  3842. +static int bcm2708_gpio_dir_out(struct gpio_chip *gc, unsigned offset,
  3843. + int value)
  3844. +{
  3845. + int ret;
  3846. + ret = bcm2708_set_function(gc, offset, GPIO_FSEL_OUTPUT);
  3847. + if (ret >= 0)
  3848. + bcm2708_gpio_set(gc, offset, value);
  3849. + return ret;
  3850. +}
  3851. +
  3852. +static int bcm2708_gpio_get(struct gpio_chip *gc, unsigned offset)
  3853. +{
  3854. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  3855. + unsigned gpio_bank = offset / 32;
  3856. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  3857. + unsigned lev;
  3858. +
  3859. + if (offset >= BCM2708_NR_GPIOS)
  3860. + return 0;
  3861. + lev = readl(gpio->base + GPIOLEV(gpio_bank));
  3862. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_get %p (%d)=%d\n", gc, offset, 0x1 & (lev>>gpio_field_offset));
  3863. + return 0x1 & (lev >> gpio_field_offset);
  3864. +}
  3865. +
  3866. +static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
  3867. +{
  3868. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  3869. + unsigned gpio_bank = offset / 32;
  3870. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  3871. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_set %p (%d=%d)\n", gc, offset, value);
  3872. + if (offset >= BCM2708_NR_GPIOS)
  3873. + return;
  3874. + if (value)
  3875. + writel(1 << gpio_field_offset, gpio->base + GPIOSET(gpio_bank));
  3876. + else
  3877. + writel(1 << gpio_field_offset, gpio->base + GPIOCLR(gpio_bank));
  3878. +}
  3879. +
  3880. +/*************************************************************************************************************************
  3881. + * bcm2708 GPIO IRQ
  3882. + */
  3883. +
  3884. +#if BCM_GPIO_USE_IRQ
  3885. +
  3886. +static int bcm2708_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
  3887. +{
  3888. + return gpio_to_irq(gpio);
  3889. +}
  3890. +
  3891. +static int bcm2708_gpio_irq_set_type(struct irq_data *d, unsigned type)
  3892. +{
  3893. + unsigned irq = d->irq;
  3894. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  3895. +
  3896. + gpio->rising &= ~(1 << irq_to_gpio(irq));
  3897. + gpio->falling &= ~(1 << irq_to_gpio(irq));
  3898. + gpio->high &= ~(1 << irq_to_gpio(irq));
  3899. + gpio->low &= ~(1 << irq_to_gpio(irq));
  3900. +
  3901. + if (type & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING | IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
  3902. + return -EINVAL;
  3903. +
  3904. + if (type & IRQ_TYPE_EDGE_RISING)
  3905. + gpio->rising |= (1 << irq_to_gpio(irq));
  3906. + if (type & IRQ_TYPE_EDGE_FALLING)
  3907. + gpio->falling |= (1 << irq_to_gpio(irq));
  3908. + if (type & IRQ_TYPE_LEVEL_HIGH)
  3909. + gpio->high |= (1 << irq_to_gpio(irq));
  3910. + if (type & IRQ_TYPE_LEVEL_LOW)
  3911. + gpio->low |= (1 << irq_to_gpio(irq));
  3912. + return 0;
  3913. +}
  3914. +
  3915. +static void bcm2708_gpio_irq_mask(struct irq_data *d)
  3916. +{
  3917. + unsigned irq = d->irq;
  3918. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  3919. + unsigned gn = irq_to_gpio(irq);
  3920. + unsigned gb = gn / 32;
  3921. + unsigned long rising = readl(gpio->base + GPIOREN(gb));
  3922. + unsigned long falling = readl(gpio->base + GPIOFEN(gb));
  3923. + unsigned long high = readl(gpio->base + GPIOHEN(gb));
  3924. + unsigned long low = readl(gpio->base + GPIOLEN(gb));
  3925. +
  3926. + gn = gn % 32;
  3927. +
  3928. + writel(rising & ~(1 << gn), gpio->base + GPIOREN(gb));
  3929. + writel(falling & ~(1 << gn), gpio->base + GPIOFEN(gb));
  3930. + writel(high & ~(1 << gn), gpio->base + GPIOHEN(gb));
  3931. + writel(low & ~(1 << gn), gpio->base + GPIOLEN(gb));
  3932. +}
  3933. +
  3934. +static void bcm2708_gpio_irq_unmask(struct irq_data *d)
  3935. +{
  3936. + unsigned irq = d->irq;
  3937. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  3938. + unsigned gn = irq_to_gpio(irq);
  3939. + unsigned gb = gn / 32;
  3940. + unsigned long rising = readl(gpio->base + GPIOREN(gb));
  3941. + unsigned long falling = readl(gpio->base + GPIOFEN(gb));
  3942. + unsigned long high = readl(gpio->base + GPIOHEN(gb));
  3943. + unsigned long low = readl(gpio->base + GPIOLEN(gb));
  3944. +
  3945. + gn = gn % 32;
  3946. +
  3947. + writel(1 << gn, gpio->base + GPIOEDS(gb));
  3948. +
  3949. + if (gpio->rising & (1 << gn)) {
  3950. + writel(rising | (1 << gn), gpio->base + GPIOREN(gb));
  3951. + } else {
  3952. + writel(rising & ~(1 << gn), gpio->base + GPIOREN(gb));
  3953. + }
  3954. +
  3955. + if (gpio->falling & (1 << gn)) {
  3956. + writel(falling | (1 << gn), gpio->base + GPIOFEN(gb));
  3957. + } else {
  3958. + writel(falling & ~(1 << gn), gpio->base + GPIOFEN(gb));
  3959. + }
  3960. +
  3961. + if (gpio->high & (1 << gn)) {
  3962. + writel(high | (1 << gn), gpio->base + GPIOHEN(gb));
  3963. + } else {
  3964. + writel(high & ~(1 << gn), gpio->base + GPIOHEN(gb));
  3965. + }
  3966. +
  3967. + if (gpio->low & (1 << gn)) {
  3968. + writel(low | (1 << gn), gpio->base + GPIOLEN(gb));
  3969. + } else {
  3970. + writel(low & ~(1 << gn), gpio->base + GPIOLEN(gb));
  3971. + }
  3972. +}
  3973. +
  3974. +static struct irq_chip bcm2708_irqchip = {
  3975. + .name = "GPIO",
  3976. + .irq_enable = bcm2708_gpio_irq_unmask,
  3977. + .irq_disable = bcm2708_gpio_irq_mask,
  3978. + .irq_unmask = bcm2708_gpio_irq_unmask,
  3979. + .irq_mask = bcm2708_gpio_irq_mask,
  3980. + .irq_set_type = bcm2708_gpio_irq_set_type,
  3981. +};
  3982. +
  3983. +static irqreturn_t bcm2708_gpio_interrupt(int irq, void *dev_id)
  3984. +{
  3985. + unsigned long edsr;
  3986. + unsigned bank;
  3987. + int i;
  3988. + unsigned gpio;
  3989. + for (bank = 0; bank <= 1; bank++) {
  3990. + edsr = readl(__io_address(GPIO_BASE) + GPIOEDS(bank));
  3991. + for_each_set_bit(i, &edsr, 32) {
  3992. + gpio = i + bank * 32;
  3993. + generic_handle_irq(gpio_to_irq(gpio));
  3994. + }
  3995. + writel(0xffffffff, __io_address(GPIO_BASE) + GPIOEDS(bank));
  3996. + }
  3997. + return IRQ_HANDLED;
  3998. +}
  3999. +
  4000. +static struct irqaction bcm2708_gpio_irq = {
  4001. + .name = "BCM2708 GPIO catchall handler",
  4002. + .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  4003. + .handler = bcm2708_gpio_interrupt,
  4004. +};
  4005. +
  4006. +static void bcm2708_gpio_irq_init(struct bcm2708_gpio *ucb)
  4007. +{
  4008. + unsigned irq;
  4009. +
  4010. + ucb->gc.to_irq = bcm2708_gpio_to_irq;
  4011. +
  4012. + for (irq = GPIO_IRQ_START; irq < (GPIO_IRQ_START + GPIO_IRQS); irq++) {
  4013. + irq_set_chip_data(irq, ucb);
  4014. + irq_set_chip(irq, &bcm2708_irqchip);
  4015. + set_irq_flags(irq, IRQF_VALID);
  4016. + }
  4017. + setup_irq(IRQ_GPIO3, &bcm2708_gpio_irq);
  4018. +}
  4019. +
  4020. +#else
  4021. +
  4022. +static void bcm2708_gpio_irq_init(struct bcm2708_gpio *ucb)
  4023. +{
  4024. +}
  4025. +
  4026. +#endif /* #if BCM_GPIO_USE_IRQ ***************************************************************************************************************** */
  4027. +
  4028. +static int bcm2708_gpio_probe(struct platform_device *dev)
  4029. +{
  4030. + struct bcm2708_gpio *ucb;
  4031. + struct resource *res;
  4032. + int err = 0;
  4033. +
  4034. + printk(KERN_INFO DRIVER_NAME ": bcm2708_gpio_probe %p\n", dev);
  4035. +
  4036. + ucb = kzalloc(sizeof(*ucb), GFP_KERNEL);
  4037. + if (NULL == ucb) {
  4038. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  4039. + "mailbox memory\n");
  4040. + err = -ENOMEM;
  4041. + goto err;
  4042. + }
  4043. +
  4044. + res = platform_get_resource(dev, IORESOURCE_MEM, 0);
  4045. +
  4046. + platform_set_drvdata(dev, ucb);
  4047. + ucb->base = __io_address(GPIO_BASE);
  4048. +
  4049. + ucb->gc.label = "bcm2708_gpio";
  4050. + ucb->gc.base = 0;
  4051. + ucb->gc.ngpio = BCM2708_NR_GPIOS;
  4052. + ucb->gc.owner = THIS_MODULE;
  4053. +
  4054. + ucb->gc.direction_input = bcm2708_gpio_dir_in;
  4055. + ucb->gc.direction_output = bcm2708_gpio_dir_out;
  4056. + ucb->gc.get = bcm2708_gpio_get;
  4057. + ucb->gc.set = bcm2708_gpio_set;
  4058. + ucb->gc.can_sleep = 0;
  4059. +
  4060. + bcm2708_gpio_irq_init(ucb);
  4061. +
  4062. + err = gpiochip_add(&ucb->gc);
  4063. + if (err)
  4064. + goto err;
  4065. +
  4066. +err:
  4067. + return err;
  4068. +
  4069. +}
  4070. +
  4071. +static int bcm2708_gpio_remove(struct platform_device *dev)
  4072. +{
  4073. + int err = 0;
  4074. + struct bcm2708_gpio *ucb = platform_get_drvdata(dev);
  4075. +
  4076. + printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_remove %p\n", dev);
  4077. +
  4078. + err = gpiochip_remove(&ucb->gc);
  4079. +
  4080. + platform_set_drvdata(dev, NULL);
  4081. + kfree(ucb);
  4082. +
  4083. + return err;
  4084. +}
  4085. +
  4086. +static struct platform_driver bcm2708_gpio_driver = {
  4087. + .probe = bcm2708_gpio_probe,
  4088. + .remove = bcm2708_gpio_remove,
  4089. + .driver = {
  4090. + .name = "bcm2708_gpio"},
  4091. +};
  4092. +
  4093. +static int __init bcm2708_gpio_init(void)
  4094. +{
  4095. + return platform_driver_register(&bcm2708_gpio_driver);
  4096. +}
  4097. +
  4098. +static void __exit bcm2708_gpio_exit(void)
  4099. +{
  4100. + platform_driver_unregister(&bcm2708_gpio_driver);
  4101. +}
  4102. +
  4103. +module_init(bcm2708_gpio_init);
  4104. +module_exit(bcm2708_gpio_exit);
  4105. +
  4106. +MODULE_DESCRIPTION("Broadcom BCM2708 GPIO driver");
  4107. +MODULE_LICENSE("GPL");
  4108. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/bcm2708.h linux-rpi/arch/arm/mach-bcm2708/bcm2708.h
  4109. --- linux-3.15.4/arch/arm/mach-bcm2708/bcm2708.h 1970-01-01 01:00:00.000000000 +0100
  4110. +++ linux-rpi/arch/arm/mach-bcm2708/bcm2708.h 2014-07-07 10:44:57.000000000 +0200
  4111. @@ -0,0 +1,49 @@
  4112. +/*
  4113. + * linux/arch/arm/mach-bcm2708/bcm2708.h
  4114. + *
  4115. + * BCM2708 machine support header
  4116. + *
  4117. + * Copyright (C) 2010 Broadcom
  4118. + *
  4119. + * This program is free software; you can redistribute it and/or modify
  4120. + * it under the terms of the GNU General Public License as published by
  4121. + * the Free Software Foundation; either version 2 of the License, or
  4122. + * (at your option) any later version.
  4123. + *
  4124. + * This program is distributed in the hope that it will be useful,
  4125. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4126. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4127. + * GNU General Public License for more details.
  4128. + *
  4129. + * You should have received a copy of the GNU General Public License
  4130. + * along with this program; if not, write to the Free Software
  4131. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4132. + */
  4133. +
  4134. +#ifndef __BCM2708_BCM2708_H
  4135. +#define __BCM2708_BCM2708_H
  4136. +
  4137. +#include <linux/amba/bus.h>
  4138. +
  4139. +extern void __init bcm2708_init(void);
  4140. +extern void __init bcm2708_init_irq(void);
  4141. +extern void __init bcm2708_map_io(void);
  4142. +extern struct sys_timer bcm2708_timer;
  4143. +extern unsigned int mmc_status(struct device *dev);
  4144. +
  4145. +#define AMBA_DEVICE(name, busid, base, plat) \
  4146. +static struct amba_device name##_device = { \
  4147. + .dev = { \
  4148. + .coherent_dma_mask = ~0, \
  4149. + .init_name = busid, \
  4150. + .platform_data = plat, \
  4151. + }, \
  4152. + .res = { \
  4153. + .start = base##_BASE, \
  4154. + .end = (base##_BASE) + SZ_4K - 1,\
  4155. + .flags = IORESOURCE_MEM, \
  4156. + }, \
  4157. + .irq = base##_IRQ, \
  4158. +}
  4159. +
  4160. +#endif
  4161. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/clock.c linux-rpi/arch/arm/mach-bcm2708/clock.c
  4162. --- linux-3.15.4/arch/arm/mach-bcm2708/clock.c 1970-01-01 01:00:00.000000000 +0100
  4163. +++ linux-rpi/arch/arm/mach-bcm2708/clock.c 2014-04-13 17:32:40.000000000 +0200
  4164. @@ -0,0 +1,61 @@
  4165. +/*
  4166. + * linux/arch/arm/mach-bcm2708/clock.c
  4167. + *
  4168. + * Copyright (C) 2010 Broadcom
  4169. + *
  4170. + * This program is free software; you can redistribute it and/or modify
  4171. + * it under the terms of the GNU General Public License as published by
  4172. + * the Free Software Foundation; either version 2 of the License, or
  4173. + * (at your option) any later version.
  4174. + *
  4175. + * This program is distributed in the hope that it will be useful,
  4176. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4177. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4178. + * GNU General Public License for more details.
  4179. + *
  4180. + * You should have received a copy of the GNU General Public License
  4181. + * along with this program; if not, write to the Free Software
  4182. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4183. + */
  4184. +#include <linux/module.h>
  4185. +#include <linux/kernel.h>
  4186. +#include <linux/device.h>
  4187. +#include <linux/list.h>
  4188. +#include <linux/errno.h>
  4189. +#include <linux/err.h>
  4190. +#include <linux/string.h>
  4191. +#include <linux/clk.h>
  4192. +#include <linux/mutex.h>
  4193. +
  4194. +#include <asm/clkdev.h>
  4195. +
  4196. +#include "clock.h"
  4197. +
  4198. +int clk_enable(struct clk *clk)
  4199. +{
  4200. + return 0;
  4201. +}
  4202. +EXPORT_SYMBOL(clk_enable);
  4203. +
  4204. +void clk_disable(struct clk *clk)
  4205. +{
  4206. +}
  4207. +EXPORT_SYMBOL(clk_disable);
  4208. +
  4209. +unsigned long clk_get_rate(struct clk *clk)
  4210. +{
  4211. + return clk->rate;
  4212. +}
  4213. +EXPORT_SYMBOL(clk_get_rate);
  4214. +
  4215. +long clk_round_rate(struct clk *clk, unsigned long rate)
  4216. +{
  4217. + return clk->rate;
  4218. +}
  4219. +EXPORT_SYMBOL(clk_round_rate);
  4220. +
  4221. +int clk_set_rate(struct clk *clk, unsigned long rate)
  4222. +{
  4223. + return -EIO;
  4224. +}
  4225. +EXPORT_SYMBOL(clk_set_rate);
  4226. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/clock.h linux-rpi/arch/arm/mach-bcm2708/clock.h
  4227. --- linux-3.15.4/arch/arm/mach-bcm2708/clock.h 1970-01-01 01:00:00.000000000 +0100
  4228. +++ linux-rpi/arch/arm/mach-bcm2708/clock.h 2014-04-13 17:32:40.000000000 +0200
  4229. @@ -0,0 +1,24 @@
  4230. +/*
  4231. + * linux/arch/arm/mach-bcm2708/clock.h
  4232. + *
  4233. + * Copyright (C) 2010 Broadcom
  4234. + *
  4235. + * This program is free software; you can redistribute it and/or modify
  4236. + * it under the terms of the GNU General Public License as published by
  4237. + * the Free Software Foundation; either version 2 of the License, or
  4238. + * (at your option) any later version.
  4239. + *
  4240. + * This program is distributed in the hope that it will be useful,
  4241. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4242. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4243. + * GNU General Public License for more details.
  4244. + *
  4245. + * You should have received a copy of the GNU General Public License
  4246. + * along with this program; if not, write to the Free Software
  4247. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4248. + */
  4249. +struct module;
  4250. +
  4251. +struct clk {
  4252. + unsigned long rate;
  4253. +};
  4254. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/dma.c linux-rpi/arch/arm/mach-bcm2708/dma.c
  4255. --- linux-3.15.4/arch/arm/mach-bcm2708/dma.c 1970-01-01 01:00:00.000000000 +0100
  4256. +++ linux-rpi/arch/arm/mach-bcm2708/dma.c 2014-04-13 17:32:40.000000000 +0200
  4257. @@ -0,0 +1,407 @@
  4258. +/*
  4259. + * linux/arch/arm/mach-bcm2708/dma.c
  4260. + *
  4261. + * Copyright (C) 2010 Broadcom
  4262. + *
  4263. + * This program is free software; you can redistribute it and/or modify
  4264. + * it under the terms of the GNU General Public License version 2 as
  4265. + * published by the Free Software Foundation.
  4266. + */
  4267. +
  4268. +#include <linux/slab.h>
  4269. +#include <linux/device.h>
  4270. +#include <linux/platform_device.h>
  4271. +#include <linux/module.h>
  4272. +#include <linux/scatterlist.h>
  4273. +
  4274. +#include <mach/dma.h>
  4275. +#include <mach/irqs.h>
  4276. +
  4277. +/*****************************************************************************\
  4278. + * *
  4279. + * Configuration *
  4280. + * *
  4281. +\*****************************************************************************/
  4282. +
  4283. +#define CACHE_LINE_MASK 31
  4284. +#define DRIVER_NAME BCM_DMAMAN_DRIVER_NAME
  4285. +#define DEFAULT_DMACHAN_BITMAP 0x10 /* channel 4 only */
  4286. +
  4287. +/* valid only for channels 0 - 14, 15 has its own base address */
  4288. +#define BCM2708_DMA_CHAN(n) ((n)<<8) /* base address */
  4289. +#define BCM2708_DMA_CHANIO(dma_base, n) \
  4290. + ((void __iomem *)((char *)(dma_base)+BCM2708_DMA_CHAN(n)))
  4291. +
  4292. +
  4293. +/*****************************************************************************\
  4294. + * *
  4295. + * DMA Auxilliary Functions *
  4296. + * *
  4297. +\*****************************************************************************/
  4298. +
  4299. +/* A DMA buffer on an arbitrary boundary may separate a cache line into a
  4300. + section inside the DMA buffer and another section outside it.
  4301. + Even if we flush DMA buffers from the cache there is always the chance that
  4302. + during a DMA someone will access the part of a cache line that is outside
  4303. + the DMA buffer - which will then bring in unwelcome data.
  4304. + Without being able to dictate our own buffer pools we must insist that
  4305. + DMA buffers consist of a whole number of cache lines.
  4306. +*/
  4307. +
  4308. +extern int
  4309. +bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len)
  4310. +{
  4311. + int i;
  4312. +
  4313. + for (i = 0; i < sg_len; i++) {
  4314. + if (sg_ptr[i].offset & CACHE_LINE_MASK ||
  4315. + sg_ptr[i].length & CACHE_LINE_MASK)
  4316. + return 0;
  4317. + }
  4318. +
  4319. + return 1;
  4320. +}
  4321. +EXPORT_SYMBOL_GPL(bcm_sg_suitable_for_dma);
  4322. +
  4323. +extern void
  4324. +bcm_dma_start(void __iomem *dma_chan_base, dma_addr_t control_block)
  4325. +{
  4326. + dsb(); /* ARM data synchronization (push) operation */
  4327. +
  4328. + writel(control_block, dma_chan_base + BCM2708_DMA_ADDR);
  4329. + writel(BCM2708_DMA_ACTIVE, dma_chan_base + BCM2708_DMA_CS);
  4330. +}
  4331. +
  4332. +extern void bcm_dma_wait_idle(void __iomem *dma_chan_base)
  4333. +{
  4334. + dsb();
  4335. +
  4336. + /* ugly busy wait only option for now */
  4337. + while (readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE)
  4338. + cpu_relax();
  4339. +}
  4340. +
  4341. +EXPORT_SYMBOL_GPL(bcm_dma_start);
  4342. +
  4343. +extern bool bcm_dma_is_busy(void __iomem *dma_chan_base)
  4344. +{
  4345. + dsb();
  4346. +
  4347. + return readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE;
  4348. +}
  4349. +EXPORT_SYMBOL_GPL(bcm_dma_is_busy);
  4350. +
  4351. +/* Complete an ongoing DMA (assuming its results are to be ignored)
  4352. + Does nothing if there is no DMA in progress.
  4353. + This routine waits for the current AXI transfer to complete before
  4354. + terminating the current DMA. If the current transfer is hung on a DREQ used
  4355. + by an uncooperative peripheral the AXI transfer may never complete. In this
  4356. + case the routine times out and return a non-zero error code.
  4357. + Use of this routine doesn't guarantee that the ongoing or aborted DMA
  4358. + does not produce an interrupt.
  4359. +*/
  4360. +extern int
  4361. +bcm_dma_abort(void __iomem *dma_chan_base)
  4362. +{
  4363. + unsigned long int cs;
  4364. + int rc = 0;
  4365. +
  4366. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  4367. +
  4368. + if (BCM2708_DMA_ACTIVE & cs) {
  4369. + long int timeout = 10000;
  4370. +
  4371. + /* write 0 to the active bit - pause the DMA */
  4372. + writel(0, dma_chan_base + BCM2708_DMA_CS);
  4373. +
  4374. + /* wait for any current AXI transfer to complete */
  4375. + while (0 != (cs & BCM2708_DMA_ISPAUSED) && --timeout >= 0)
  4376. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  4377. +
  4378. + if (0 != (cs & BCM2708_DMA_ISPAUSED)) {
  4379. + /* we'll un-pause when we set of our next DMA */
  4380. + rc = -ETIMEDOUT;
  4381. +
  4382. + } else if (BCM2708_DMA_ACTIVE & cs) {
  4383. + /* terminate the control block chain */
  4384. + writel(0, dma_chan_base + BCM2708_DMA_NEXTCB);
  4385. +
  4386. + /* abort the whole DMA */
  4387. + writel(BCM2708_DMA_ABORT | BCM2708_DMA_ACTIVE,
  4388. + dma_chan_base + BCM2708_DMA_CS);
  4389. + }
  4390. + }
  4391. +
  4392. + return rc;
  4393. +}
  4394. +EXPORT_SYMBOL_GPL(bcm_dma_abort);
  4395. +
  4396. +
  4397. +/***************************************************************************** \
  4398. + * *
  4399. + * DMA Manager Device Methods *
  4400. + * *
  4401. +\*****************************************************************************/
  4402. +
  4403. +struct vc_dmaman {
  4404. + void __iomem *dma_base;
  4405. + u32 chan_available; /* bitmap of available channels */
  4406. + u32 has_feature[BCM_DMA_FEATURE_COUNT]; /* bitmap of feature presence */
  4407. +};
  4408. +
  4409. +static void vc_dmaman_init(struct vc_dmaman *dmaman, void __iomem *dma_base,
  4410. + u32 chans_available)
  4411. +{
  4412. + dmaman->dma_base = dma_base;
  4413. + dmaman->chan_available = chans_available;
  4414. + dmaman->has_feature[BCM_DMA_FEATURE_FAST_ORD] = 0x0c; /* chans 2 & 3 */
  4415. + dmaman->has_feature[BCM_DMA_FEATURE_BULK_ORD] = 0x01; /* chan 0 */
  4416. +}
  4417. +
  4418. +static int vc_dmaman_chan_alloc(struct vc_dmaman *dmaman,
  4419. + unsigned preferred_feature_set)
  4420. +{
  4421. + u32 chans;
  4422. + int feature;
  4423. +
  4424. + chans = dmaman->chan_available;
  4425. + for (feature = 0; feature < BCM_DMA_FEATURE_COUNT; feature++)
  4426. + /* select the subset of available channels with the desired
  4427. + feature so long as some of the candidate channels have that
  4428. + feature */
  4429. + if ((preferred_feature_set & (1 << feature)) &&
  4430. + (chans & dmaman->has_feature[feature]))
  4431. + chans &= dmaman->has_feature[feature];
  4432. +
  4433. + if (chans) {
  4434. + int chan = 0;
  4435. + /* return the ordinal of the first channel in the bitmap */
  4436. + while (chans != 0 && (chans & 1) == 0) {
  4437. + chans >>= 1;
  4438. + chan++;
  4439. + }
  4440. + /* claim the channel */
  4441. + dmaman->chan_available &= ~(1 << chan);
  4442. + return chan;
  4443. + } else
  4444. + return -ENOMEM;
  4445. +}
  4446. +
  4447. +static int vc_dmaman_chan_free(struct vc_dmaman *dmaman, int chan)
  4448. +{
  4449. + if (chan < 0)
  4450. + return -EINVAL;
  4451. + else if ((1 << chan) & dmaman->chan_available)
  4452. + return -EIDRM;
  4453. + else {
  4454. + dmaman->chan_available |= (1 << chan);
  4455. + return 0;
  4456. + }
  4457. +}
  4458. +
  4459. +/*****************************************************************************\
  4460. + * *
  4461. + * DMA IRQs *
  4462. + * *
  4463. +\*****************************************************************************/
  4464. +
  4465. +static unsigned char bcm_dma_irqs[] = {
  4466. + IRQ_DMA0,
  4467. + IRQ_DMA1,
  4468. + IRQ_DMA2,
  4469. + IRQ_DMA3,
  4470. + IRQ_DMA4,
  4471. + IRQ_DMA5,
  4472. + IRQ_DMA6,
  4473. + IRQ_DMA7,
  4474. + IRQ_DMA8,
  4475. + IRQ_DMA9,
  4476. + IRQ_DMA10,
  4477. + IRQ_DMA11,
  4478. + IRQ_DMA12
  4479. +};
  4480. +
  4481. +
  4482. +/***************************************************************************** \
  4483. + * *
  4484. + * DMA Manager Monitor *
  4485. + * *
  4486. +\*****************************************************************************/
  4487. +
  4488. +static struct device *dmaman_dev; /* we assume there's only one! */
  4489. +
  4490. +extern int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  4491. + void __iomem **out_dma_base, int *out_dma_irq)
  4492. +{
  4493. + if (!dmaman_dev)
  4494. + return -ENODEV;
  4495. + else {
  4496. + struct vc_dmaman *dmaman = dev_get_drvdata(dmaman_dev);
  4497. + int rc;
  4498. +
  4499. + device_lock(dmaman_dev);
  4500. + rc = vc_dmaman_chan_alloc(dmaman, preferred_feature_set);
  4501. + if (rc >= 0) {
  4502. + *out_dma_base = BCM2708_DMA_CHANIO(dmaman->dma_base,
  4503. + rc);
  4504. + *out_dma_irq = bcm_dma_irqs[rc];
  4505. + }
  4506. + device_unlock(dmaman_dev);
  4507. +
  4508. + return rc;
  4509. + }
  4510. +}
  4511. +EXPORT_SYMBOL_GPL(bcm_dma_chan_alloc);
  4512. +
  4513. +extern int bcm_dma_chan_free(int channel)
  4514. +{
  4515. + if (dmaman_dev) {
  4516. + struct vc_dmaman *dmaman = dev_get_drvdata(dmaman_dev);
  4517. + int rc;
  4518. +
  4519. + device_lock(dmaman_dev);
  4520. + rc = vc_dmaman_chan_free(dmaman, channel);
  4521. + device_unlock(dmaman_dev);
  4522. +
  4523. + return rc;
  4524. + } else
  4525. + return -ENODEV;
  4526. +}
  4527. +EXPORT_SYMBOL_GPL(bcm_dma_chan_free);
  4528. +
  4529. +static int dev_dmaman_register(const char *dev_name, struct device *dev)
  4530. +{
  4531. + int rc = dmaman_dev ? -EINVAL : 0;
  4532. + dmaman_dev = dev;
  4533. + return rc;
  4534. +}
  4535. +
  4536. +static void dev_dmaman_deregister(const char *dev_name, struct device *dev)
  4537. +{
  4538. + dmaman_dev = NULL;
  4539. +}
  4540. +
  4541. +/*****************************************************************************\
  4542. + * *
  4543. + * DMA Device *
  4544. + * *
  4545. +\*****************************************************************************/
  4546. +
  4547. +static int dmachans = -1; /* module parameter */
  4548. +
  4549. +static int bcm_dmaman_probe(struct platform_device *pdev)
  4550. +{
  4551. + int ret = 0;
  4552. + struct vc_dmaman *dmaman;
  4553. + struct resource *dma_res = NULL;
  4554. + void __iomem *dma_base = NULL;
  4555. + int have_dma_region = 0;
  4556. +
  4557. + dmaman = kzalloc(sizeof(*dmaman), GFP_KERNEL);
  4558. + if (NULL == dmaman) {
  4559. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  4560. + "DMA management memory\n");
  4561. + ret = -ENOMEM;
  4562. + } else {
  4563. +
  4564. + dma_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  4565. + if (dma_res == NULL) {
  4566. + printk(KERN_ERR DRIVER_NAME ": failed to obtain memory "
  4567. + "resource\n");
  4568. + ret = -ENODEV;
  4569. + } else if (!request_mem_region(dma_res->start,
  4570. + resource_size(dma_res),
  4571. + DRIVER_NAME)) {
  4572. + dev_err(&pdev->dev, "cannot obtain DMA region\n");
  4573. + ret = -EBUSY;
  4574. + } else {
  4575. + have_dma_region = 1;
  4576. + dma_base = ioremap(dma_res->start,
  4577. + resource_size(dma_res));
  4578. + if (!dma_base) {
  4579. + dev_err(&pdev->dev, "cannot map DMA region\n");
  4580. + ret = -ENOMEM;
  4581. + } else {
  4582. + /* use module parameter if one was provided */
  4583. + if (dmachans > 0)
  4584. + vc_dmaman_init(dmaman, dma_base,
  4585. + dmachans);
  4586. + else
  4587. + vc_dmaman_init(dmaman, dma_base,
  4588. + DEFAULT_DMACHAN_BITMAP);
  4589. +
  4590. + platform_set_drvdata(pdev, dmaman);
  4591. + dev_dmaman_register(DRIVER_NAME, &pdev->dev);
  4592. +
  4593. + printk(KERN_INFO DRIVER_NAME ": DMA manager "
  4594. + "at %p\n", dma_base);
  4595. + }
  4596. + }
  4597. + }
  4598. + if (ret != 0) {
  4599. + if (dma_base)
  4600. + iounmap(dma_base);
  4601. + if (dma_res && have_dma_region)
  4602. + release_mem_region(dma_res->start,
  4603. + resource_size(dma_res));
  4604. + if (dmaman)
  4605. + kfree(dmaman);
  4606. + }
  4607. + return ret;
  4608. +}
  4609. +
  4610. +static int bcm_dmaman_remove(struct platform_device *pdev)
  4611. +{
  4612. + struct vc_dmaman *dmaman = platform_get_drvdata(pdev);
  4613. +
  4614. + platform_set_drvdata(pdev, NULL);
  4615. + dev_dmaman_deregister(DRIVER_NAME, &pdev->dev);
  4616. + kfree(dmaman);
  4617. +
  4618. + return 0;
  4619. +}
  4620. +
  4621. +static struct platform_driver bcm_dmaman_driver = {
  4622. + .probe = bcm_dmaman_probe,
  4623. + .remove = bcm_dmaman_remove,
  4624. +
  4625. + .driver = {
  4626. + .name = DRIVER_NAME,
  4627. + .owner = THIS_MODULE,
  4628. + },
  4629. +};
  4630. +
  4631. +/*****************************************************************************\
  4632. + * *
  4633. + * Driver init/exit *
  4634. + * *
  4635. +\*****************************************************************************/
  4636. +
  4637. +static int __init bcm_dmaman_drv_init(void)
  4638. +{
  4639. + int ret;
  4640. +
  4641. + ret = platform_driver_register(&bcm_dmaman_driver);
  4642. + if (ret != 0) {
  4643. + printk(KERN_ERR DRIVER_NAME ": failed to register "
  4644. + "on platform\n");
  4645. + }
  4646. +
  4647. + return ret;
  4648. +}
  4649. +
  4650. +static void __exit bcm_dmaman_drv_exit(void)
  4651. +{
  4652. + platform_driver_unregister(&bcm_dmaman_driver);
  4653. +}
  4654. +
  4655. +module_init(bcm_dmaman_drv_init);
  4656. +module_exit(bcm_dmaman_drv_exit);
  4657. +
  4658. +module_param(dmachans, int, 0644);
  4659. +
  4660. +MODULE_AUTHOR("Gray Girling <grayg@broadcom.com>");
  4661. +MODULE_DESCRIPTION("DMA channel manager driver");
  4662. +MODULE_LICENSE("GPL");
  4663. +
  4664. +MODULE_PARM_DESC(dmachans, "Bitmap of DMA channels available to the ARM");
  4665. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/include/mach/arm_control.h linux-rpi/arch/arm/mach-bcm2708/include/mach/arm_control.h
  4666. --- linux-3.15.4/arch/arm/mach-bcm2708/include/mach/arm_control.h 1970-01-01 01:00:00.000000000 +0100
  4667. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/arm_control.h 2014-04-13 17:32:40.000000000 +0200
  4668. @@ -0,0 +1,419 @@
  4669. +/*
  4670. + * linux/arch/arm/mach-bcm2708/arm_control.h
  4671. + *
  4672. + * Copyright (C) 2010 Broadcom
  4673. + *
  4674. + * This program is free software; you can redistribute it and/or modify
  4675. + * it under the terms of the GNU General Public License as published by
  4676. + * the Free Software Foundation; either version 2 of the License, or
  4677. + * (at your option) any later version.
  4678. + *
  4679. + * This program is distributed in the hope that it will be useful,
  4680. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4681. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4682. + * GNU General Public License for more details.
  4683. + *
  4684. + * You should have received a copy of the GNU General Public License
  4685. + * along with this program; if not, write to the Free Software
  4686. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4687. + */
  4688. +
  4689. +#ifndef __BCM2708_ARM_CONTROL_H
  4690. +#define __BCM2708_ARM_CONTROL_H
  4691. +
  4692. +/*
  4693. + * Definitions and addresses for the ARM CONTROL logic
  4694. + * This file is manually generated.
  4695. + */
  4696. +
  4697. +#define ARM_BASE 0x7E00B000
  4698. +
  4699. +/* Basic configuration */
  4700. +#define ARM_CONTROL0 HW_REGISTER_RW(ARM_BASE+0x000)
  4701. +#define ARM_C0_SIZ128M 0x00000000
  4702. +#define ARM_C0_SIZ256M 0x00000001
  4703. +#define ARM_C0_SIZ512M 0x00000002
  4704. +#define ARM_C0_SIZ1G 0x00000003
  4705. +#define ARM_C0_BRESP0 0x00000000
  4706. +#define ARM_C0_BRESP1 0x00000004
  4707. +#define ARM_C0_BRESP2 0x00000008
  4708. +#define ARM_C0_BOOTHI 0x00000010
  4709. +#define ARM_C0_UNUSED05 0x00000020 /* free */
  4710. +#define ARM_C0_FULLPERI 0x00000040
  4711. +#define ARM_C0_UNUSED78 0x00000180 /* free */
  4712. +#define ARM_C0_JTAGMASK 0x00000E00
  4713. +#define ARM_C0_JTAGOFF 0x00000000
  4714. +#define ARM_C0_JTAGBASH 0x00000800 /* Debug on GPIO off */
  4715. +#define ARM_C0_JTAGGPIO 0x00000C00 /* Debug on GPIO on */
  4716. +#define ARM_C0_APROTMSK 0x0000F000
  4717. +#define ARM_C0_DBG0SYNC 0x00010000 /* VPU0 halt sync */
  4718. +#define ARM_C0_DBG1SYNC 0x00020000 /* VPU1 halt sync */
  4719. +#define ARM_C0_SWDBGREQ 0x00040000 /* HW debug request */
  4720. +#define ARM_C0_PASSHALT 0x00080000 /* ARM halt passed to debugger */
  4721. +#define ARM_C0_PRIO_PER 0x00F00000 /* per priority mask */
  4722. +#define ARM_C0_PRIO_L2 0x0F000000
  4723. +#define ARM_C0_PRIO_UC 0xF0000000
  4724. +
  4725. +#define ARM_C0_APROTPASS 0x0000A000 /* Translate 1:1 */
  4726. +#define ARM_C0_APROTUSER 0x00000000 /* Only user mode */
  4727. +#define ARM_C0_APROTSYST 0x0000F000 /* Only system mode */
  4728. +
  4729. +
  4730. +#define ARM_CONTROL1 HW_REGISTER_RW(ARM_BASE+0x440)
  4731. +#define ARM_C1_TIMER 0x00000001 /* re-route timer IRQ to VC */
  4732. +#define ARM_C1_MAIL 0x00000002 /* re-route Mail IRQ to VC */
  4733. +#define ARM_C1_BELL0 0x00000004 /* re-route Doorbell 0 to VC */
  4734. +#define ARM_C1_BELL1 0x00000008 /* re-route Doorbell 1 to VC */
  4735. +#define ARM_C1_PERSON 0x00000100 /* peripherals on */
  4736. +#define ARM_C1_REQSTOP 0x00000200 /* ASYNC bridge request stop */
  4737. +
  4738. +#define ARM_STATUS HW_REGISTER_RW(ARM_BASE+0x444)
  4739. +#define ARM_S_ACKSTOP 0x80000000 /* Bridge stopped */
  4740. +#define ARM_S_READPEND 0x000003FF /* pending reads counter */
  4741. +#define ARM_S_WRITPEND 0x000FFC00 /* pending writes counter */
  4742. +
  4743. +#define ARM_ERRHALT HW_REGISTER_RW(ARM_BASE+0x448)
  4744. +#define ARM_EH_PERIBURST 0x00000001 /* Burst write seen on peri bus */
  4745. +#define ARM_EH_ILLADDRS1 0x00000002 /* Address bits 25-27 error */
  4746. +#define ARM_EH_ILLADDRS2 0x00000004 /* Address bits 31-28 error */
  4747. +#define ARM_EH_VPU0HALT 0x00000008 /* VPU0 halted & in debug mode */
  4748. +#define ARM_EH_VPU1HALT 0x00000010 /* VPU1 halted & in debug mode */
  4749. +#define ARM_EH_ARMHALT 0x00000020 /* ARM in halted debug mode */
  4750. +
  4751. +#define ARM_ID_SECURE HW_REGISTER_RW(ARM_BASE+0x00C)
  4752. +#define ARM_ID HW_REGISTER_RW(ARM_BASE+0x44C)
  4753. +#define ARM_IDVAL 0x364D5241
  4754. +
  4755. +/* Translation memory */
  4756. +#define ARM_TRANSLATE HW_REGISTER_RW(ARM_BASE+0x100)
  4757. +/* 32 locations: 0x100.. 0x17F */
  4758. +/* 32 spare means we CAN go to 64 pages.... */
  4759. +
  4760. +
  4761. +/* Interrupts */
  4762. +#define ARM_IRQ_PEND0 HW_REGISTER_RW(ARM_BASE+0x200) /* Top IRQ bits */
  4763. +#define ARM_I0_TIMER 0x00000001 /* timer IRQ */
  4764. +#define ARM_I0_MAIL 0x00000002 /* Mail IRQ */
  4765. +#define ARM_I0_BELL0 0x00000004 /* Doorbell 0 */
  4766. +#define ARM_I0_BELL1 0x00000008 /* Doorbell 1 */
  4767. +#define ARM_I0_BANK1 0x00000100 /* Bank1 IRQ */
  4768. +#define ARM_I0_BANK2 0x00000200 /* Bank2 IRQ */
  4769. +
  4770. +#define ARM_IRQ_PEND1 HW_REGISTER_RW(ARM_BASE+0x204) /* All bank1 IRQ bits */
  4771. +/* todo: all I1_interrupt sources */
  4772. +#define ARM_IRQ_PEND2 HW_REGISTER_RW(ARM_BASE+0x208) /* All bank2 IRQ bits */
  4773. +/* todo: all I2_interrupt sources */
  4774. +
  4775. +#define ARM_IRQ_FAST HW_REGISTER_RW(ARM_BASE+0x20C) /* FIQ control */
  4776. +#define ARM_IF_INDEX 0x0000007F /* FIQ select */
  4777. +#define ARM_IF_ENABLE 0x00000080 /* FIQ enable */
  4778. +#define ARM_IF_VCMASK 0x0000003F /* FIQ = (index from VC source) */
  4779. +#define ARM_IF_TIMER 0x00000040 /* FIQ = ARM timer */
  4780. +#define ARM_IF_MAIL 0x00000041 /* FIQ = ARM Mail */
  4781. +#define ARM_IF_BELL0 0x00000042 /* FIQ = ARM Doorbell 0 */
  4782. +#define ARM_IF_BELL1 0x00000043 /* FIQ = ARM Doorbell 1 */
  4783. +#define ARM_IF_VP0HALT 0x00000044 /* FIQ = VPU0 Halt seen */
  4784. +#define ARM_IF_VP1HALT 0x00000045 /* FIQ = VPU1 Halt seen */
  4785. +#define ARM_IF_ILLEGAL 0x00000046 /* FIQ = Illegal access seen */
  4786. +
  4787. +#define ARM_IRQ_ENBL1 HW_REGISTER_RW(ARM_BASE+0x210) /* Bank1 enable bits */
  4788. +#define ARM_IRQ_ENBL2 HW_REGISTER_RW(ARM_BASE+0x214) /* Bank2 enable bits */
  4789. +#define ARM_IRQ_ENBL3 HW_REGISTER_RW(ARM_BASE+0x218) /* ARM irqs enable bits */
  4790. +#define ARM_IRQ_DIBL1 HW_REGISTER_RW(ARM_BASE+0x21C) /* Bank1 disable bits */
  4791. +#define ARM_IRQ_DIBL2 HW_REGISTER_RW(ARM_BASE+0x220) /* Bank2 disable bits */
  4792. +#define ARM_IRQ_DIBL3 HW_REGISTER_RW(ARM_BASE+0x224) /* ARM irqs disable bits */
  4793. +#define ARM_IE_TIMER 0x00000001 /* Timer IRQ */
  4794. +#define ARM_IE_MAIL 0x00000002 /* Mail IRQ */
  4795. +#define ARM_IE_BELL0 0x00000004 /* Doorbell 0 */
  4796. +#define ARM_IE_BELL1 0x00000008 /* Doorbell 1 */
  4797. +#define ARM_IE_VP0HALT 0x00000010 /* VPU0 Halt */
  4798. +#define ARM_IE_VP1HALT 0x00000020 /* VPU1 Halt */
  4799. +#define ARM_IE_ILLEGAL 0x00000040 /* Illegal access seen */
  4800. +
  4801. +/* Timer */
  4802. +/* For reg. fields see sp804 spec. */
  4803. +#define ARM_T_LOAD HW_REGISTER_RW(ARM_BASE+0x400)
  4804. +#define ARM_T_VALUE HW_REGISTER_RW(ARM_BASE+0x404)
  4805. +#define ARM_T_CONTROL HW_REGISTER_RW(ARM_BASE+0x408)
  4806. +#define ARM_T_IRQCNTL HW_REGISTER_RW(ARM_BASE+0x40C)
  4807. +#define ARM_T_RAWIRQ HW_REGISTER_RW(ARM_BASE+0x410)
  4808. +#define ARM_T_MSKIRQ HW_REGISTER_RW(ARM_BASE+0x414)
  4809. +#define ARM_T_RELOAD HW_REGISTER_RW(ARM_BASE+0x418)
  4810. +#define ARM_T_PREDIV HW_REGISTER_RW(ARM_BASE+0x41c)
  4811. +#define ARM_T_FREECNT HW_REGISTER_RW(ARM_BASE+0x420)
  4812. +
  4813. +#define TIMER_CTRL_ONESHOT (1 << 0)
  4814. +#define TIMER_CTRL_32BIT (1 << 1)
  4815. +#define TIMER_CTRL_DIV1 (0 << 2)
  4816. +#define TIMER_CTRL_DIV16 (1 << 2)
  4817. +#define TIMER_CTRL_DIV256 (2 << 2)
  4818. +#define TIMER_CTRL_IE (1 << 5)
  4819. +#define TIMER_CTRL_PERIODIC (1 << 6)
  4820. +#define TIMER_CTRL_ENABLE (1 << 7)
  4821. +#define TIMER_CTRL_DBGHALT (1 << 8)
  4822. +#define TIMER_CTRL_ENAFREE (1 << 9)
  4823. +#define TIMER_CTRL_FREEDIV_SHIFT 16)
  4824. +#define TIMER_CTRL_FREEDIV_MASK 0xff
  4825. +
  4826. +/* Semaphores, Doorbells, Mailboxes */
  4827. +#define ARM_SBM_OWN0 (ARM_BASE+0x800)
  4828. +#define ARM_SBM_OWN1 (ARM_BASE+0x900)
  4829. +#define ARM_SBM_OWN2 (ARM_BASE+0xA00)
  4830. +#define ARM_SBM_OWN3 (ARM_BASE+0xB00)
  4831. +
  4832. +/* MAILBOXES
  4833. + * Register flags are common across all
  4834. + * owner registers. See end of this section
  4835. + *
  4836. + * Semaphores, Doorbells, Mailboxes Owner 0
  4837. + *
  4838. + */
  4839. +
  4840. +#define ARM_0_SEMS HW_REGISTER_RW(ARM_SBM_OWN0+0x00)
  4841. +#define ARM_0_SEM0 HW_REGISTER_RW(ARM_SBM_OWN0+0x00)
  4842. +#define ARM_0_SEM1 HW_REGISTER_RW(ARM_SBM_OWN0+0x04)
  4843. +#define ARM_0_SEM2 HW_REGISTER_RW(ARM_SBM_OWN0+0x08)
  4844. +#define ARM_0_SEM3 HW_REGISTER_RW(ARM_SBM_OWN0+0x0C)
  4845. +#define ARM_0_SEM4 HW_REGISTER_RW(ARM_SBM_OWN0+0x10)
  4846. +#define ARM_0_SEM5 HW_REGISTER_RW(ARM_SBM_OWN0+0x14)
  4847. +#define ARM_0_SEM6 HW_REGISTER_RW(ARM_SBM_OWN0+0x18)
  4848. +#define ARM_0_SEM7 HW_REGISTER_RW(ARM_SBM_OWN0+0x1C)
  4849. +#define ARM_0_BELL0 HW_REGISTER_RW(ARM_SBM_OWN0+0x40)
  4850. +#define ARM_0_BELL1 HW_REGISTER_RW(ARM_SBM_OWN0+0x44)
  4851. +#define ARM_0_BELL2 HW_REGISTER_RW(ARM_SBM_OWN0+0x48)
  4852. +#define ARM_0_BELL3 HW_REGISTER_RW(ARM_SBM_OWN0+0x4C)
  4853. +/* MAILBOX 0 access in Owner 0 area */
  4854. +/* Some addresses should ONLY be used by owner 0 */
  4855. +#define ARM_0_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN0+0x80) /* .. 0x8C (4 locations) */
  4856. +#define ARM_0_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN0+0x80) /* .. 0x8C (4 locations) Normal read */
  4857. +#define ARM_0_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN0+0x90) /* none-pop read */
  4858. +#define ARM_0_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN0+0x94) /* Sender read (only LS 2 bits) */
  4859. +#define ARM_0_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN0+0x98) /* Status read */
  4860. +#define ARM_0_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN0+0x9C) /* Config read/write */
  4861. +/* MAILBOX 1 access in Owner 0 area */
  4862. +/* Owner 0 should only WRITE to this mailbox */
  4863. +#define ARM_0_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN0+0xA0) /* .. 0xAC (4 locations) */
  4864. +/*#define ARM_0_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN0+0xA0) */ /* DO NOT USE THIS !!!!! */
  4865. +/*#define ARM_0_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN0+0xB0) */ /* DO NOT USE THIS !!!!! */
  4866. +/*#define ARM_0_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN0+0xB4) */ /* DO NOT USE THIS !!!!! */
  4867. +#define ARM_0_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN0+0xB8) /* Status read */
  4868. +/*#define ARM_0_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN0+0xBC) */ /* DO NOT USE THIS !!!!! */
  4869. +/* General SEM, BELL, MAIL config/status */
  4870. +#define ARM_0_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN0+0xE0) /* semaphore clear/debug register */
  4871. +#define ARM_0_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN0+0xE4) /* Doorbells clear/debug register */
  4872. +#define ARM_0_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN0+0xF8) /* ALL interrupts */
  4873. +#define ARM_0_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN0+0xFC) /* IRQS pending for owner 0 */
  4874. +
  4875. +/* Semaphores, Doorbells, Mailboxes Owner 1 */
  4876. +#define ARM_1_SEMS HW_REGISTER_RW(ARM_SBM_OWN1+0x00)
  4877. +#define ARM_1_SEM0 HW_REGISTER_RW(ARM_SBM_OWN1+0x00)
  4878. +#define ARM_1_SEM1 HW_REGISTER_RW(ARM_SBM_OWN1+0x04)
  4879. +#define ARM_1_SEM2 HW_REGISTER_RW(ARM_SBM_OWN1+0x08)
  4880. +#define ARM_1_SEM3 HW_REGISTER_RW(ARM_SBM_OWN1+0x0C)
  4881. +#define ARM_1_SEM4 HW_REGISTER_RW(ARM_SBM_OWN1+0x10)
  4882. +#define ARM_1_SEM5 HW_REGISTER_RW(ARM_SBM_OWN1+0x14)
  4883. +#define ARM_1_SEM6 HW_REGISTER_RW(ARM_SBM_OWN1+0x18)
  4884. +#define ARM_1_SEM7 HW_REGISTER_RW(ARM_SBM_OWN1+0x1C)
  4885. +#define ARM_1_BELL0 HW_REGISTER_RW(ARM_SBM_OWN1+0x40)
  4886. +#define ARM_1_BELL1 HW_REGISTER_RW(ARM_SBM_OWN1+0x44)
  4887. +#define ARM_1_BELL2 HW_REGISTER_RW(ARM_SBM_OWN1+0x48)
  4888. +#define ARM_1_BELL3 HW_REGISTER_RW(ARM_SBM_OWN1+0x4C)
  4889. +/* MAILBOX 0 access in Owner 0 area */
  4890. +/* Owner 1 should only WRITE to this mailbox */
  4891. +#define ARM_1_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN1+0x80) /* .. 0x8C (4 locations) */
  4892. +/*#define ARM_1_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN1+0x80) */ /* DO NOT USE THIS !!!!! */
  4893. +/*#define ARM_1_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN1+0x90) */ /* DO NOT USE THIS !!!!! */
  4894. +/*#define ARM_1_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN1+0x94) */ /* DO NOT USE THIS !!!!! */
  4895. +#define ARM_1_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN1+0x98) /* Status read */
  4896. +/*#define ARM_1_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN1+0x9C) */ /* DO NOT USE THIS !!!!! */
  4897. +/* MAILBOX 1 access in Owner 0 area */
  4898. +#define ARM_1_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN1+0xA0) /* .. 0xAC (4 locations) */
  4899. +#define ARM_1_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN1+0xA0) /* .. 0xAC (4 locations) Normal read */
  4900. +#define ARM_1_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN1+0xB0) /* none-pop read */
  4901. +#define ARM_1_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN1+0xB4) /* Sender read (only LS 2 bits) */
  4902. +#define ARM_1_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN1+0xB8) /* Status read */
  4903. +#define ARM_1_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN1+0xBC)
  4904. +/* General SEM, BELL, MAIL config/status */
  4905. +#define ARM_1_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN1+0xE0) /* semaphore clear/debug register */
  4906. +#define ARM_1_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN1+0xE4) /* Doorbells clear/debug register */
  4907. +#define ARM_1_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN1+0xFC) /* IRQS pending for owner 1 */
  4908. +#define ARM_1_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN1+0xF8) /* ALL interrupts */
  4909. +
  4910. +/* Semaphores, Doorbells, Mailboxes Owner 2 */
  4911. +#define ARM_2_SEMS HW_REGISTER_RW(ARM_SBM_OWN2+0x00)
  4912. +#define ARM_2_SEM0 HW_REGISTER_RW(ARM_SBM_OWN2+0x00)
  4913. +#define ARM_2_SEM1 HW_REGISTER_RW(ARM_SBM_OWN2+0x04)
  4914. +#define ARM_2_SEM2 HW_REGISTER_RW(ARM_SBM_OWN2+0x08)
  4915. +#define ARM_2_SEM3 HW_REGISTER_RW(ARM_SBM_OWN2+0x0C)
  4916. +#define ARM_2_SEM4 HW_REGISTER_RW(ARM_SBM_OWN2+0x10)
  4917. +#define ARM_2_SEM5 HW_REGISTER_RW(ARM_SBM_OWN2+0x14)
  4918. +#define ARM_2_SEM6 HW_REGISTER_RW(ARM_SBM_OWN2+0x18)
  4919. +#define ARM_2_SEM7 HW_REGISTER_RW(ARM_SBM_OWN2+0x1C)
  4920. +#define ARM_2_BELL0 HW_REGISTER_RW(ARM_SBM_OWN2+0x40)
  4921. +#define ARM_2_BELL1 HW_REGISTER_RW(ARM_SBM_OWN2+0x44)
  4922. +#define ARM_2_BELL2 HW_REGISTER_RW(ARM_SBM_OWN2+0x48)
  4923. +#define ARM_2_BELL3 HW_REGISTER_RW(ARM_SBM_OWN2+0x4C)
  4924. +/* MAILBOX 0 access in Owner 2 area */
  4925. +/* Owner 2 should only WRITE to this mailbox */
  4926. +#define ARM_2_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN2+0x80) /* .. 0x8C (4 locations) */
  4927. +/*#define ARM_2_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN2+0x80) */ /* DO NOT USE THIS !!!!! */
  4928. +/*#define ARM_2_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN2+0x90) */ /* DO NOT USE THIS !!!!! */
  4929. +/*#define ARM_2_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN2+0x94) */ /* DO NOT USE THIS !!!!! */
  4930. +#define ARM_2_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN2+0x98) /* Status read */
  4931. +/*#define ARM_2_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN2+0x9C) */ /* DO NOT USE THIS !!!!! */
  4932. +/* MAILBOX 1 access in Owner 2 area */
  4933. +/* Owner 2 should only WRITE to this mailbox */
  4934. +#define ARM_2_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN2+0xA0) /* .. 0xAC (4 locations) */
  4935. +/*#define ARM_2_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN2+0xA0) */ /* DO NOT USE THIS !!!!! */
  4936. +/*#define ARM_2_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN2+0xB0) */ /* DO NOT USE THIS !!!!! */
  4937. +/*#define ARM_2_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN2+0xB4) */ /* DO NOT USE THIS !!!!! */
  4938. +#define ARM_2_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN2+0xB8) /* Status read */
  4939. +/*#define ARM_2_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN2+0xBC) */ /* DO NOT USE THIS !!!!! */
  4940. +/* General SEM, BELL, MAIL config/status */
  4941. +#define ARM_2_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN2+0xE0) /* semaphore clear/debug register */
  4942. +#define ARM_2_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN2+0xE4) /* Doorbells clear/debug register */
  4943. +#define ARM_2_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN2+0xFC) /* IRQS pending for owner 2 */
  4944. +#define ARM_2_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN2+0xF8) /* ALL interrupts */
  4945. +
  4946. +/* Semaphores, Doorbells, Mailboxes Owner 3 */
  4947. +#define ARM_3_SEMS HW_REGISTER_RW(ARM_SBM_OWN3+0x00)
  4948. +#define ARM_3_SEM0 HW_REGISTER_RW(ARM_SBM_OWN3+0x00)
  4949. +#define ARM_3_SEM1 HW_REGISTER_RW(ARM_SBM_OWN3+0x04)
  4950. +#define ARM_3_SEM2 HW_REGISTER_RW(ARM_SBM_OWN3+0x08)
  4951. +#define ARM_3_SEM3 HW_REGISTER_RW(ARM_SBM_OWN3+0x0C)
  4952. +#define ARM_3_SEM4 HW_REGISTER_RW(ARM_SBM_OWN3+0x10)
  4953. +#define ARM_3_SEM5 HW_REGISTER_RW(ARM_SBM_OWN3+0x14)
  4954. +#define ARM_3_SEM6 HW_REGISTER_RW(ARM_SBM_OWN3+0x18)
  4955. +#define ARM_3_SEM7 HW_REGISTER_RW(ARM_SBM_OWN3+0x1C)
  4956. +#define ARM_3_BELL0 HW_REGISTER_RW(ARM_SBM_OWN3+0x40)
  4957. +#define ARM_3_BELL1 HW_REGISTER_RW(ARM_SBM_OWN3+0x44)
  4958. +#define ARM_3_BELL2 HW_REGISTER_RW(ARM_SBM_OWN3+0x48)
  4959. +#define ARM_3_BELL3 HW_REGISTER_RW(ARM_SBM_OWN3+0x4C)
  4960. +/* MAILBOX 0 access in Owner 3 area */
  4961. +/* Owner 3 should only WRITE to this mailbox */
  4962. +#define ARM_3_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN3+0x80) /* .. 0x8C (4 locations) */
  4963. +/*#define ARM_3_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN3+0x80) */ /* DO NOT USE THIS !!!!! */
  4964. +/*#define ARM_3_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN3+0x90) */ /* DO NOT USE THIS !!!!! */
  4965. +/*#define ARM_3_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN3+0x94) */ /* DO NOT USE THIS !!!!! */
  4966. +#define ARM_3_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN3+0x98) /* Status read */
  4967. +/*#define ARM_3_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN3+0x9C) */ /* DO NOT USE THIS !!!!! */
  4968. +/* MAILBOX 1 access in Owner 3 area */
  4969. +/* Owner 3 should only WRITE to this mailbox */
  4970. +#define ARM_3_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN3+0xA0) /* .. 0xAC (4 locations) */
  4971. +/*#define ARM_3_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN3+0xA0) */ /* DO NOT USE THIS !!!!! */
  4972. +/*#define ARM_3_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN3+0xB0) */ /* DO NOT USE THIS !!!!! */
  4973. +/*#define ARM_3_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN3+0xB4) */ /* DO NOT USE THIS !!!!! */
  4974. +#define ARM_3_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN3+0xB8) /* Status read */
  4975. +/*#define ARM_3_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN3+0xBC) */ /* DO NOT USE THIS !!!!! */
  4976. +/* General SEM, BELL, MAIL config/status */
  4977. +#define ARM_3_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN3+0xE0) /* semaphore clear/debug register */
  4978. +#define ARM_3_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN3+0xE4) /* Doorbells clear/debug register */
  4979. +#define ARM_3_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN3+0xFC) /* IRQS pending for owner 3 */
  4980. +#define ARM_3_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN3+0xF8) /* ALL interrupts */
  4981. +
  4982. +
  4983. +
  4984. +/* Mailbox flags. Valid for all owners */
  4985. +
  4986. +/* Mailbox status register (...0x98) */
  4987. +#define ARM_MS_FULL 0x80000000
  4988. +#define ARM_MS_EMPTY 0x40000000
  4989. +#define ARM_MS_LEVEL 0x400000FF /* Max. value depdnds on mailbox depth parameter */
  4990. +
  4991. +/* MAILBOX config/status register (...0x9C) */
  4992. +/* ANY write to this register clears the error bits! */
  4993. +#define ARM_MC_IHAVEDATAIRQEN 0x00000001 /* mailbox irq enable: has data */
  4994. +#define ARM_MC_IHAVESPACEIRQEN 0x00000002 /* mailbox irq enable: has space */
  4995. +#define ARM_MC_OPPISEMPTYIRQEN 0x00000004 /* mailbox irq enable: Opp. is empty */
  4996. +#define ARM_MC_MAIL_CLEAR 0x00000008 /* mailbox clear write 1, then 0 */
  4997. +#define ARM_MC_IHAVEDATAIRQPEND 0x00000010 /* mailbox irq pending: has space */
  4998. +#define ARM_MC_IHAVESPACEIRQPEND 0x00000020 /* mailbox irq pending: Opp. is empty */
  4999. +#define ARM_MC_OPPISEMPTYIRQPEND 0x00000040 /* mailbox irq pending */
  5000. +/* Bit 7 is unused */
  5001. +#define ARM_MC_ERRNOOWN 0x00000100 /* error : none owner read from mailbox */
  5002. +#define ARM_MC_ERROVERFLW 0x00000200 /* error : write to fill mailbox */
  5003. +#define ARM_MC_ERRUNDRFLW 0x00000400 /* error : read from empty mailbox */
  5004. +
  5005. +/* Semaphore clear/debug register (...0xE0) */
  5006. +#define ARM_SD_OWN0 0x00000003 /* Owner of sem 0 */
  5007. +#define ARM_SD_OWN1 0x0000000C /* Owner of sem 1 */
  5008. +#define ARM_SD_OWN2 0x00000030 /* Owner of sem 2 */
  5009. +#define ARM_SD_OWN3 0x000000C0 /* Owner of sem 3 */
  5010. +#define ARM_SD_OWN4 0x00000300 /* Owner of sem 4 */
  5011. +#define ARM_SD_OWN5 0x00000C00 /* Owner of sem 5 */
  5012. +#define ARM_SD_OWN6 0x00003000 /* Owner of sem 6 */
  5013. +#define ARM_SD_OWN7 0x0000C000 /* Owner of sem 7 */
  5014. +#define ARM_SD_SEM0 0x00010000 /* Status of sem 0 */
  5015. +#define ARM_SD_SEM1 0x00020000 /* Status of sem 1 */
  5016. +#define ARM_SD_SEM2 0x00040000 /* Status of sem 2 */
  5017. +#define ARM_SD_SEM3 0x00080000 /* Status of sem 3 */
  5018. +#define ARM_SD_SEM4 0x00100000 /* Status of sem 4 */
  5019. +#define ARM_SD_SEM5 0x00200000 /* Status of sem 5 */
  5020. +#define ARM_SD_SEM6 0x00400000 /* Status of sem 6 */
  5021. +#define ARM_SD_SEM7 0x00800000 /* Status of sem 7 */
  5022. +
  5023. +/* Doorbells clear/debug register (...0xE4) */
  5024. +#define ARM_BD_OWN0 0x00000003 /* Owner of doorbell 0 */
  5025. +#define ARM_BD_OWN1 0x0000000C /* Owner of doorbell 1 */
  5026. +#define ARM_BD_OWN2 0x00000030 /* Owner of doorbell 2 */
  5027. +#define ARM_BD_OWN3 0x000000C0 /* Owner of doorbell 3 */
  5028. +#define ARM_BD_BELL0 0x00000100 /* Status of doorbell 0 */
  5029. +#define ARM_BD_BELL1 0x00000200 /* Status of doorbell 1 */
  5030. +#define ARM_BD_BELL2 0x00000400 /* Status of doorbell 2 */
  5031. +#define ARM_BD_BELL3 0x00000800 /* Status of doorbell 3 */
  5032. +
  5033. +/* MY IRQS register (...0xF8) */
  5034. +#define ARM_MYIRQ_BELL 0x00000001 /* This owner has a doorbell IRQ */
  5035. +#define ARM_MYIRQ_MAIL 0x00000002 /* This owner has a mailbox IRQ */
  5036. +
  5037. +/* ALL IRQS register (...0xF8) */
  5038. +#define ARM_AIS_BELL0 0x00000001 /* Doorbell 0 IRQ pending */
  5039. +#define ARM_AIS_BELL1 0x00000002 /* Doorbell 1 IRQ pending */
  5040. +#define ARM_AIS_BELL2 0x00000004 /* Doorbell 2 IRQ pending */
  5041. +#define ARM_AIS_BELL3 0x00000008 /* Doorbell 3 IRQ pending */
  5042. +#define ARM_AIS0_HAVEDATA 0x00000010 /* MAIL 0 has data IRQ pending */
  5043. +#define ARM_AIS0_HAVESPAC 0x00000020 /* MAIL 0 has space IRQ pending */
  5044. +#define ARM_AIS0_OPPEMPTY 0x00000040 /* MAIL 0 opposite is empty IRQ */
  5045. +#define ARM_AIS1_HAVEDATA 0x00000080 /* MAIL 1 has data IRQ pending */
  5046. +#define ARM_AIS1_HAVESPAC 0x00000100 /* MAIL 1 has space IRQ pending */
  5047. +#define ARM_AIS1_OPPEMPTY 0x00000200 /* MAIL 1 opposite is empty IRQ */
  5048. +/* Note that bell-0, bell-1 and MAIL0 IRQ go only to the ARM */
  5049. +/* Whilst that bell-2, bell-3 and MAIL1 IRQ go only to the VC */
  5050. +/* */
  5051. +/* ARM JTAG BASH */
  5052. +/* */
  5053. +#define AJB_BASE 0x7e2000c0
  5054. +
  5055. +#define AJBCONF HW_REGISTER_RW(AJB_BASE+0x00)
  5056. +#define AJB_BITS0 0x000000
  5057. +#define AJB_BITS4 0x000004
  5058. +#define AJB_BITS8 0x000008
  5059. +#define AJB_BITS12 0x00000C
  5060. +#define AJB_BITS16 0x000010
  5061. +#define AJB_BITS20 0x000014
  5062. +#define AJB_BITS24 0x000018
  5063. +#define AJB_BITS28 0x00001C
  5064. +#define AJB_BITS32 0x000020
  5065. +#define AJB_BITS34 0x000022
  5066. +#define AJB_OUT_MS 0x000040
  5067. +#define AJB_OUT_LS 0x000000
  5068. +#define AJB_INV_CLK 0x000080
  5069. +#define AJB_D0_RISE 0x000100
  5070. +#define AJB_D0_FALL 0x000000
  5071. +#define AJB_D1_RISE 0x000200
  5072. +#define AJB_D1_FALL 0x000000
  5073. +#define AJB_IN_RISE 0x000400
  5074. +#define AJB_IN_FALL 0x000000
  5075. +#define AJB_ENABLE 0x000800
  5076. +#define AJB_HOLD0 0x000000
  5077. +#define AJB_HOLD1 0x001000
  5078. +#define AJB_HOLD2 0x002000
  5079. +#define AJB_HOLD3 0x003000
  5080. +#define AJB_RESETN 0x004000
  5081. +#define AJB_CLKSHFT 16
  5082. +#define AJB_BUSY 0x80000000
  5083. +#define AJBTMS HW_REGISTER_RW(AJB_BASE+0x04)
  5084. +#define AJBTDI HW_REGISTER_RW(AJB_BASE+0x08)
  5085. +#define AJBTDO HW_REGISTER_RW(AJB_BASE+0x0c)
  5086. +
  5087. +#endif
  5088. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/include/mach/arm_power.h linux-rpi/arch/arm/mach-bcm2708/include/mach/arm_power.h
  5089. --- linux-3.15.4/arch/arm/mach-bcm2708/include/mach/arm_power.h 1970-01-01 01:00:00.000000000 +0100
  5090. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/arm_power.h 2014-04-13 17:32:40.000000000 +0200
  5091. @@ -0,0 +1,60 @@
  5092. +/*
  5093. + * linux/arch/arm/mach-bcm2708/include/mach/arm_power.h
  5094. + *
  5095. + * Copyright (C) 2010 Broadcom
  5096. + *
  5097. + * This program is free software; you can redistribute it and/or modify
  5098. + * it under the terms of the GNU General Public License as published by
  5099. + * the Free Software Foundation; either version 2 of the License, or
  5100. + * (at your option) any later version.
  5101. + *
  5102. + * This program is distributed in the hope that it will be useful,
  5103. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5104. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5105. + * GNU General Public License for more details.
  5106. + *
  5107. + * You should have received a copy of the GNU General Public License
  5108. + * along with this program; if not, write to the Free Software
  5109. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5110. + */
  5111. +
  5112. +#ifndef _ARM_POWER_H
  5113. +#define _ARM_POWER_H
  5114. +
  5115. +/* Use meaningful names on each side */
  5116. +#ifdef __VIDEOCORE__
  5117. +#define PREFIX(x) ARM_##x
  5118. +#else
  5119. +#define PREFIX(x) BCM_##x
  5120. +#endif
  5121. +
  5122. +enum {
  5123. + PREFIX(POWER_SDCARD_BIT),
  5124. + PREFIX(POWER_UART_BIT),
  5125. + PREFIX(POWER_MINIUART_BIT),
  5126. + PREFIX(POWER_USB_BIT),
  5127. + PREFIX(POWER_I2C0_BIT),
  5128. + PREFIX(POWER_I2C1_BIT),
  5129. + PREFIX(POWER_I2C2_BIT),
  5130. + PREFIX(POWER_SPI_BIT),
  5131. + PREFIX(POWER_CCP2TX_BIT),
  5132. +
  5133. + PREFIX(POWER_MAX)
  5134. +};
  5135. +
  5136. +enum {
  5137. + PREFIX(POWER_SDCARD) = (1 << PREFIX(POWER_SDCARD_BIT)),
  5138. + PREFIX(POWER_UART) = (1 << PREFIX(POWER_UART_BIT)),
  5139. + PREFIX(POWER_MINIUART) = (1 << PREFIX(POWER_MINIUART_BIT)),
  5140. + PREFIX(POWER_USB) = (1 << PREFIX(POWER_USB_BIT)),
  5141. + PREFIX(POWER_I2C0) = (1 << PREFIX(POWER_I2C0_BIT)),
  5142. + PREFIX(POWER_I2C1_MASK) = (1 << PREFIX(POWER_I2C1_BIT)),
  5143. + PREFIX(POWER_I2C2_MASK) = (1 << PREFIX(POWER_I2C2_BIT)),
  5144. + PREFIX(POWER_SPI_MASK) = (1 << PREFIX(POWER_SPI_BIT)),
  5145. + PREFIX(POWER_CCP2TX_MASK) = (1 << PREFIX(POWER_CCP2TX_BIT)),
  5146. +
  5147. + PREFIX(POWER_MASK) = (1 << PREFIX(POWER_MAX)) - 1,
  5148. + PREFIX(POWER_NONE) = 0
  5149. +};
  5150. +
  5151. +#endif
  5152. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/include/mach/clkdev.h linux-rpi/arch/arm/mach-bcm2708/include/mach/clkdev.h
  5153. --- linux-3.15.4/arch/arm/mach-bcm2708/include/mach/clkdev.h 1970-01-01 01:00:00.000000000 +0100
  5154. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/clkdev.h 2014-04-13 17:32:40.000000000 +0200
  5155. @@ -0,0 +1,7 @@
  5156. +#ifndef __ASM_MACH_CLKDEV_H
  5157. +#define __ASM_MACH_CLKDEV_H
  5158. +
  5159. +#define __clk_get(clk) ({ 1; })
  5160. +#define __clk_put(clk) do { } while (0)
  5161. +
  5162. +#endif
  5163. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/include/mach/debug-macro.S linux-rpi/arch/arm/mach-bcm2708/include/mach/debug-macro.S
  5164. --- linux-3.15.4/arch/arm/mach-bcm2708/include/mach/debug-macro.S 1970-01-01 01:00:00.000000000 +0100
  5165. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/debug-macro.S 2014-07-07 10:44:57.000000000 +0200
  5166. @@ -0,0 +1,22 @@
  5167. +/* arch/arm/mach-bcm2708/include/mach/debug-macro.S
  5168. + *
  5169. + * Debugging macro include header
  5170. + *
  5171. + * Copyright (C) 2010 Broadcom
  5172. + * Copyright (C) 1994-1999 Russell King
  5173. + * Moved from linux/arch/arm/kernel/debug.S by Ben Dooks
  5174. + *
  5175. + * This program is free software; you can redistribute it and/or modify
  5176. + * it under the terms of the GNU General Public License version 2 as
  5177. + * published by the Free Software Foundation.
  5178. + *
  5179. +*/
  5180. +
  5181. +#include <mach/platform.h>
  5182. +
  5183. + .macro addruart, rp, rv, tmp
  5184. + ldr \rp, =UART0_BASE
  5185. + ldr \rv, =IO_ADDRESS(UART0_BASE)
  5186. + .endm
  5187. +
  5188. +#include <debug/pl01x.S>
  5189. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/include/mach/dma.h linux-rpi/arch/arm/mach-bcm2708/include/mach/dma.h
  5190. --- linux-3.15.4/arch/arm/mach-bcm2708/include/mach/dma.h 1970-01-01 01:00:00.000000000 +0100
  5191. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/dma.h 2014-04-13 17:32:40.000000000 +0200
  5192. @@ -0,0 +1,90 @@
  5193. +/*
  5194. + * linux/arch/arm/mach-bcm2708/include/mach/dma.h
  5195. + *
  5196. + * Copyright (C) 2010 Broadcom
  5197. + *
  5198. + * This program is free software; you can redistribute it and/or modify
  5199. + * it under the terms of the GNU General Public License version 2 as
  5200. + * published by the Free Software Foundation.
  5201. + */
  5202. +
  5203. +
  5204. +#ifndef _MACH_BCM2708_DMA_H
  5205. +#define _MACH_BCM2708_DMA_H
  5206. +
  5207. +#define BCM_DMAMAN_DRIVER_NAME "bcm2708_dma"
  5208. +
  5209. +/* DMA CS Control and Status bits */
  5210. +#define BCM2708_DMA_ACTIVE (1 << 0)
  5211. +#define BCM2708_DMA_INT (1 << 2)
  5212. +#define BCM2708_DMA_ISPAUSED (1 << 4) /* Pause requested or not active */
  5213. +#define BCM2708_DMA_ISHELD (1 << 5) /* Is held by DREQ flow control */
  5214. +#define BCM2708_DMA_ERR (1 << 8)
  5215. +#define BCM2708_DMA_ABORT (1 << 30) /* stop current CB, go to next, WO */
  5216. +#define BCM2708_DMA_RESET (1 << 31) /* WO, self clearing */
  5217. +
  5218. +/* DMA control block "info" field bits */
  5219. +#define BCM2708_DMA_INT_EN (1 << 0)
  5220. +#define BCM2708_DMA_TDMODE (1 << 1)
  5221. +#define BCM2708_DMA_WAIT_RESP (1 << 3)
  5222. +#define BCM2708_DMA_D_INC (1 << 4)
  5223. +#define BCM2708_DMA_D_WIDTH (1 << 5)
  5224. +#define BCM2708_DMA_D_DREQ (1 << 6)
  5225. +#define BCM2708_DMA_S_INC (1 << 8)
  5226. +#define BCM2708_DMA_S_WIDTH (1 << 9)
  5227. +#define BCM2708_DMA_S_DREQ (1 << 10)
  5228. +
  5229. +#define BCM2708_DMA_BURST(x) (((x)&0xf) << 12)
  5230. +#define BCM2708_DMA_PER_MAP(x) ((x) << 16)
  5231. +#define BCM2708_DMA_WAITS(x) (((x)&0x1f) << 21)
  5232. +
  5233. +#define BCM2708_DMA_DREQ_EMMC 11
  5234. +#define BCM2708_DMA_DREQ_SDHOST 13
  5235. +
  5236. +#define BCM2708_DMA_CS 0x00 /* Control and Status */
  5237. +#define BCM2708_DMA_ADDR 0x04
  5238. +/* the current control block appears in the following registers - read only */
  5239. +#define BCM2708_DMA_INFO 0x08
  5240. +#define BCM2708_DMA_SOURCE_AD 0x0c
  5241. +#define BCM2708_DMA_DEST_AD 0x10
  5242. +#define BCM2708_DMA_NEXTCB 0x1C
  5243. +#define BCM2708_DMA_DEBUG 0x20
  5244. +
  5245. +#define BCM2708_DMA4_CS (BCM2708_DMA_CHAN(4)+BCM2708_DMA_CS)
  5246. +#define BCM2708_DMA4_ADDR (BCM2708_DMA_CHAN(4)+BCM2708_DMA_ADDR)
  5247. +
  5248. +#define BCM2708_DMA_TDMODE_LEN(w, h) ((h) << 16 | (w))
  5249. +
  5250. +struct bcm2708_dma_cb {
  5251. + unsigned long info;
  5252. + unsigned long src;
  5253. + unsigned long dst;
  5254. + unsigned long length;
  5255. + unsigned long stride;
  5256. + unsigned long next;
  5257. + unsigned long pad[2];
  5258. +};
  5259. +struct scatterlist;
  5260. +
  5261. +extern int bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len);
  5262. +extern void bcm_dma_start(void __iomem *dma_chan_base,
  5263. + dma_addr_t control_block);
  5264. +extern void bcm_dma_wait_idle(void __iomem *dma_chan_base);
  5265. +extern bool bcm_dma_is_busy(void __iomem *dma_chan_base);
  5266. +extern int /*rc*/ bcm_dma_abort(void __iomem *dma_chan_base);
  5267. +
  5268. +/* When listing features we can ask for when allocating DMA channels give
  5269. + those with higher priority smaller ordinal numbers */
  5270. +#define BCM_DMA_FEATURE_FAST_ORD 0
  5271. +#define BCM_DMA_FEATURE_BULK_ORD 1
  5272. +#define BCM_DMA_FEATURE_FAST (1<<BCM_DMA_FEATURE_FAST_ORD)
  5273. +#define BCM_DMA_FEATURE_BULK (1<<BCM_DMA_FEATURE_BULK_ORD)
  5274. +#define BCM_DMA_FEATURE_COUNT 2
  5275. +
  5276. +/* return channel no or -ve error */
  5277. +extern int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  5278. + void __iomem **out_dma_base, int *out_dma_irq);
  5279. +extern int bcm_dma_chan_free(int channel);
  5280. +
  5281. +
  5282. +#endif /* _MACH_BCM2708_DMA_H */
  5283. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/include/mach/entry-macro.S linux-rpi/arch/arm/mach-bcm2708/include/mach/entry-macro.S
  5284. --- linux-3.15.4/arch/arm/mach-bcm2708/include/mach/entry-macro.S 1970-01-01 01:00:00.000000000 +0100
  5285. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/entry-macro.S 2014-04-13 17:32:40.000000000 +0200
  5286. @@ -0,0 +1,69 @@
  5287. +/*
  5288. + * arch/arm/mach-bcm2708/include/mach/entry-macro.S
  5289. + *
  5290. + * Low-level IRQ helper macros for BCM2708 platforms
  5291. + *
  5292. + * Copyright (C) 2010 Broadcom
  5293. + *
  5294. + * This program is free software; you can redistribute it and/or modify
  5295. + * it under the terms of the GNU General Public License as published by
  5296. + * the Free Software Foundation; either version 2 of the License, or
  5297. + * (at your option) any later version.
  5298. + *
  5299. + * This program is distributed in the hope that it will be useful,
  5300. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5301. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5302. + * GNU General Public License for more details.
  5303. + *
  5304. + * You should have received a copy of the GNU General Public License
  5305. + * along with this program; if not, write to the Free Software
  5306. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5307. + */
  5308. +#include <mach/hardware.h>
  5309. +
  5310. + .macro disable_fiq
  5311. + .endm
  5312. +
  5313. + .macro get_irqnr_preamble, base, tmp
  5314. + ldr \base, =IO_ADDRESS(ARMCTRL_IC_BASE)
  5315. + .endm
  5316. +
  5317. + .macro arch_ret_to_user, tmp1, tmp2
  5318. + .endm
  5319. +
  5320. + .macro get_irqnr_and_base, irqnr, irqstat, base, tmp
  5321. + /* get masked status */
  5322. + ldr \irqstat, [\base, #(ARM_IRQ_PEND0 - ARMCTRL_IC_BASE)]
  5323. + mov \irqnr, #(ARM_IRQ0_BASE + 31)
  5324. + and \tmp, \irqstat, #0x300 @ save bits 8 and 9
  5325. + /* clear bits 8 and 9, and test */
  5326. + bics \irqstat, \irqstat, #0x300
  5327. + bne 1010f
  5328. +
  5329. + tst \tmp, #0x100
  5330. + ldrne \irqstat, [\base, #(ARM_IRQ_PEND1 - ARMCTRL_IC_BASE)]
  5331. + movne \irqnr, #(ARM_IRQ1_BASE + 31)
  5332. + @ Mask out the interrupts also present in PEND0 - see SW-5809
  5333. + bicne \irqstat, #((1<<7) | (1<<9) | (1<<10))
  5334. + bicne \irqstat, #((1<<18) | (1<<19))
  5335. + bne 1010f
  5336. +
  5337. + tst \tmp, #0x200
  5338. + ldrne \irqstat, [\base, #(ARM_IRQ_PEND2 - ARMCTRL_IC_BASE)]
  5339. + movne \irqnr, #(ARM_IRQ2_BASE + 31)
  5340. + @ Mask out the interrupts also present in PEND0 - see SW-5809
  5341. + bicne \irqstat, #((1<<21) | (1<<22) | (1<<23) | (1<<24) | (1<<25))
  5342. + bicne \irqstat, #((1<<30))
  5343. + beq 1020f
  5344. +
  5345. +1010:
  5346. + @ For non-zero x, LSB(x) = 31 - CLZ(x^(x-1))
  5347. + @ N.B. CLZ is an ARM5 instruction.
  5348. + sub \tmp, \irqstat, #1
  5349. + eor \irqstat, \irqstat, \tmp
  5350. + clz \tmp, \irqstat
  5351. + sub \irqnr, \tmp
  5352. +
  5353. +1020: @ EQ will be set if no irqs pending
  5354. +
  5355. + .endm
  5356. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/include/mach/frc.h linux-rpi/arch/arm/mach-bcm2708/include/mach/frc.h
  5357. --- linux-3.15.4/arch/arm/mach-bcm2708/include/mach/frc.h 1970-01-01 01:00:00.000000000 +0100
  5358. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/frc.h 2014-04-13 17:32:40.000000000 +0200
  5359. @@ -0,0 +1,38 @@
  5360. +/*
  5361. + * arch/arm/mach-bcm2708/include/mach/timex.h
  5362. + *
  5363. + * BCM2708 free running counter (timer)
  5364. + *
  5365. + * Copyright (C) 2010 Broadcom
  5366. + *
  5367. + * This program is free software; you can redistribute it and/or modify
  5368. + * it under the terms of the GNU General Public License as published by
  5369. + * the Free Software Foundation; either version 2 of the License, or
  5370. + * (at your option) any later version.
  5371. + *
  5372. + * This program is distributed in the hope that it will be useful,
  5373. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5374. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5375. + * GNU General Public License for more details.
  5376. + *
  5377. + * You should have received a copy of the GNU General Public License
  5378. + * along with this program; if not, write to the Free Software
  5379. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5380. + */
  5381. +
  5382. +#ifndef _MACH_FRC_H
  5383. +#define _MACH_FRC_H
  5384. +
  5385. +#define FRC_TICK_RATE (1000000)
  5386. +
  5387. +/*! Free running counter incrementing at the CLOCK_TICK_RATE
  5388. + (slightly faster than frc_clock_ticks63()
  5389. + */
  5390. +extern unsigned long frc_clock_ticks32(void);
  5391. +
  5392. +/*! Free running counter incrementing at the CLOCK_TICK_RATE
  5393. + * Note - top bit should be ignored (see cnt32_to_63)
  5394. + */
  5395. +extern unsigned long long frc_clock_ticks63(void);
  5396. +
  5397. +#endif
  5398. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/include/mach/gpio.h linux-rpi/arch/arm/mach-bcm2708/include/mach/gpio.h
  5399. --- linux-3.15.4/arch/arm/mach-bcm2708/include/mach/gpio.h 1970-01-01 01:00:00.000000000 +0100
  5400. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/gpio.h 2014-07-07 10:44:57.000000000 +0200
  5401. @@ -0,0 +1,17 @@
  5402. +/*
  5403. + * arch/arm/mach-bcm2708/include/mach/gpio.h
  5404. + *
  5405. + * This file is licensed under the terms of the GNU General Public
  5406. + * License version 2. This program is licensed "as is" without any
  5407. + * warranty of any kind, whether express or implied.
  5408. + */
  5409. +
  5410. +#ifndef __ASM_ARCH_GPIO_H
  5411. +#define __ASM_ARCH_GPIO_H
  5412. +
  5413. +#define BCM2708_NR_GPIOS 54 // number of gpio lines
  5414. +
  5415. +#define gpio_to_irq(x) ((x) + GPIO_IRQ_START)
  5416. +#define irq_to_gpio(x) ((x) - GPIO_IRQ_START)
  5417. +
  5418. +#endif
  5419. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/include/mach/hardware.h linux-rpi/arch/arm/mach-bcm2708/include/mach/hardware.h
  5420. --- linux-3.15.4/arch/arm/mach-bcm2708/include/mach/hardware.h 1970-01-01 01:00:00.000000000 +0100
  5421. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/hardware.h 2014-04-13 17:32:40.000000000 +0200
  5422. @@ -0,0 +1,28 @@
  5423. +/*
  5424. + * arch/arm/mach-bcm2708/include/mach/hardware.h
  5425. + *
  5426. + * This file contains the hardware definitions of the BCM2708 devices.
  5427. + *
  5428. + * Copyright (C) 2010 Broadcom
  5429. + *
  5430. + * This program is free software; you can redistribute it and/or modify
  5431. + * it under the terms of the GNU General Public License as published by
  5432. + * the Free Software Foundation; either version 2 of the License, or
  5433. + * (at your option) any later version.
  5434. + *
  5435. + * This program is distributed in the hope that it will be useful,
  5436. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5437. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5438. + * GNU General Public License for more details.
  5439. + *
  5440. + * You should have received a copy of the GNU General Public License
  5441. + * along with this program; if not, write to the Free Software
  5442. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5443. + */
  5444. +#ifndef __ASM_ARCH_HARDWARE_H
  5445. +#define __ASM_ARCH_HARDWARE_H
  5446. +
  5447. +#include <asm/sizes.h>
  5448. +#include <mach/platform.h>
  5449. +
  5450. +#endif
  5451. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/include/mach/io.h linux-rpi/arch/arm/mach-bcm2708/include/mach/io.h
  5452. --- linux-3.15.4/arch/arm/mach-bcm2708/include/mach/io.h 1970-01-01 01:00:00.000000000 +0100
  5453. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/io.h 2014-04-13 17:32:40.000000000 +0200
  5454. @@ -0,0 +1,27 @@
  5455. +/*
  5456. + * arch/arm/mach-bcm2708/include/mach/io.h
  5457. + *
  5458. + * Copyright (C) 2003 ARM Limited
  5459. + *
  5460. + * This program is free software; you can redistribute it and/or modify
  5461. + * it under the terms of the GNU General Public License as published by
  5462. + * the Free Software Foundation; either version 2 of the License, or
  5463. + * (at your option) any later version.
  5464. + *
  5465. + * This program is distributed in the hope that it will be useful,
  5466. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5467. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5468. + * GNU General Public License for more details.
  5469. + *
  5470. + * You should have received a copy of the GNU General Public License
  5471. + * along with this program; if not, write to the Free Software
  5472. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5473. + */
  5474. +#ifndef __ASM_ARM_ARCH_IO_H
  5475. +#define __ASM_ARM_ARCH_IO_H
  5476. +
  5477. +#define IO_SPACE_LIMIT 0xffffffff
  5478. +
  5479. +#define __io(a) __typesafe_io(a)
  5480. +
  5481. +#endif
  5482. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/include/mach/irqs.h linux-rpi/arch/arm/mach-bcm2708/include/mach/irqs.h
  5483. --- linux-3.15.4/arch/arm/mach-bcm2708/include/mach/irqs.h 1970-01-01 01:00:00.000000000 +0100
  5484. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/irqs.h 2014-07-07 10:44:57.000000000 +0200
  5485. @@ -0,0 +1,197 @@
  5486. +/*
  5487. + * arch/arm/mach-bcm2708/include/mach/irqs.h
  5488. + *
  5489. + * Copyright (C) 2010 Broadcom
  5490. + * Copyright (C) 2003 ARM Limited
  5491. + * Copyright (C) 2000 Deep Blue Solutions Ltd.
  5492. + *
  5493. + * This program is free software; you can redistribute it and/or modify
  5494. + * it under the terms of the GNU General Public License as published by
  5495. + * the Free Software Foundation; either version 2 of the License, or
  5496. + * (at your option) any later version.
  5497. + *
  5498. + * This program is distributed in the hope that it will be useful,
  5499. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5500. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5501. + * GNU General Public License for more details.
  5502. + *
  5503. + * You should have received a copy of the GNU General Public License
  5504. + * along with this program; if not, write to the Free Software
  5505. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5506. + */
  5507. +
  5508. +#ifndef _BCM2708_IRQS_H_
  5509. +#define _BCM2708_IRQS_H_
  5510. +
  5511. +#include <mach/platform.h>
  5512. +
  5513. +/*
  5514. + * IRQ interrupts definitions are the same as the INT definitions
  5515. + * held within platform.h
  5516. + */
  5517. +#define IRQ_ARMCTRL_START 0
  5518. +#define IRQ_TIMER0 (IRQ_ARMCTRL_START + INTERRUPT_TIMER0)
  5519. +#define IRQ_TIMER1 (IRQ_ARMCTRL_START + INTERRUPT_TIMER1)
  5520. +#define IRQ_TIMER2 (IRQ_ARMCTRL_START + INTERRUPT_TIMER2)
  5521. +#define IRQ_TIMER3 (IRQ_ARMCTRL_START + INTERRUPT_TIMER3)
  5522. +#define IRQ_CODEC0 (IRQ_ARMCTRL_START + INTERRUPT_CODEC0)
  5523. +#define IRQ_CODEC1 (IRQ_ARMCTRL_START + INTERRUPT_CODEC1)
  5524. +#define IRQ_CODEC2 (IRQ_ARMCTRL_START + INTERRUPT_CODEC2)
  5525. +#define IRQ_JPEG (IRQ_ARMCTRL_START + INTERRUPT_JPEG)
  5526. +#define IRQ_ISP (IRQ_ARMCTRL_START + INTERRUPT_ISP)
  5527. +#define IRQ_USB (IRQ_ARMCTRL_START + INTERRUPT_USB)
  5528. +#define IRQ_3D (IRQ_ARMCTRL_START + INTERRUPT_3D)
  5529. +#define IRQ_TRANSPOSER (IRQ_ARMCTRL_START + INTERRUPT_TRANSPOSER)
  5530. +#define IRQ_MULTICORESYNC0 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC0)
  5531. +#define IRQ_MULTICORESYNC1 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC1)
  5532. +#define IRQ_MULTICORESYNC2 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC2)
  5533. +#define IRQ_MULTICORESYNC3 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC3)
  5534. +#define IRQ_DMA0 (IRQ_ARMCTRL_START + INTERRUPT_DMA0)
  5535. +#define IRQ_DMA1 (IRQ_ARMCTRL_START + INTERRUPT_DMA1)
  5536. +#define IRQ_DMA2 (IRQ_ARMCTRL_START + INTERRUPT_DMA2)
  5537. +#define IRQ_DMA3 (IRQ_ARMCTRL_START + INTERRUPT_DMA3)
  5538. +#define IRQ_DMA4 (IRQ_ARMCTRL_START + INTERRUPT_DMA4)
  5539. +#define IRQ_DMA5 (IRQ_ARMCTRL_START + INTERRUPT_DMA5)
  5540. +#define IRQ_DMA6 (IRQ_ARMCTRL_START + INTERRUPT_DMA6)
  5541. +#define IRQ_DMA7 (IRQ_ARMCTRL_START + INTERRUPT_DMA7)
  5542. +#define IRQ_DMA8 (IRQ_ARMCTRL_START + INTERRUPT_DMA8)
  5543. +#define IRQ_DMA9 (IRQ_ARMCTRL_START + INTERRUPT_DMA9)
  5544. +#define IRQ_DMA10 (IRQ_ARMCTRL_START + INTERRUPT_DMA10)
  5545. +#define IRQ_DMA11 (IRQ_ARMCTRL_START + INTERRUPT_DMA11)
  5546. +#define IRQ_DMA12 (IRQ_ARMCTRL_START + INTERRUPT_DMA12)
  5547. +#define IRQ_AUX (IRQ_ARMCTRL_START + INTERRUPT_AUX)
  5548. +#define IRQ_ARM (IRQ_ARMCTRL_START + INTERRUPT_ARM)
  5549. +#define IRQ_VPUDMA (IRQ_ARMCTRL_START + INTERRUPT_VPUDMA)
  5550. +#define IRQ_HOSTPORT (IRQ_ARMCTRL_START + INTERRUPT_HOSTPORT)
  5551. +#define IRQ_VIDEOSCALER (IRQ_ARMCTRL_START + INTERRUPT_VIDEOSCALER)
  5552. +#define IRQ_CCP2TX (IRQ_ARMCTRL_START + INTERRUPT_CCP2TX)
  5553. +#define IRQ_SDC (IRQ_ARMCTRL_START + INTERRUPT_SDC)
  5554. +#define IRQ_DSI0 (IRQ_ARMCTRL_START + INTERRUPT_DSI0)
  5555. +#define IRQ_AVE (IRQ_ARMCTRL_START + INTERRUPT_AVE)
  5556. +#define IRQ_CAM0 (IRQ_ARMCTRL_START + INTERRUPT_CAM0)
  5557. +#define IRQ_CAM1 (IRQ_ARMCTRL_START + INTERRUPT_CAM1)
  5558. +#define IRQ_HDMI0 (IRQ_ARMCTRL_START + INTERRUPT_HDMI0)
  5559. +#define IRQ_HDMI1 (IRQ_ARMCTRL_START + INTERRUPT_HDMI1)
  5560. +#define IRQ_PIXELVALVE1 (IRQ_ARMCTRL_START + INTERRUPT_PIXELVALVE1)
  5561. +#define IRQ_I2CSPISLV (IRQ_ARMCTRL_START + INTERRUPT_I2CSPISLV)
  5562. +#define IRQ_DSI1 (IRQ_ARMCTRL_START + INTERRUPT_DSI1)
  5563. +#define IRQ_PWA0 (IRQ_ARMCTRL_START + INTERRUPT_PWA0)
  5564. +#define IRQ_PWA1 (IRQ_ARMCTRL_START + INTERRUPT_PWA1)
  5565. +#define IRQ_CPR (IRQ_ARMCTRL_START + INTERRUPT_CPR)
  5566. +#define IRQ_SMI (IRQ_ARMCTRL_START + INTERRUPT_SMI)
  5567. +#define IRQ_GPIO0 (IRQ_ARMCTRL_START + INTERRUPT_GPIO0)
  5568. +#define IRQ_GPIO1 (IRQ_ARMCTRL_START + INTERRUPT_GPIO1)
  5569. +#define IRQ_GPIO2 (IRQ_ARMCTRL_START + INTERRUPT_GPIO2)
  5570. +#define IRQ_GPIO3 (IRQ_ARMCTRL_START + INTERRUPT_GPIO3)
  5571. +#define IRQ_I2C (IRQ_ARMCTRL_START + INTERRUPT_I2C)
  5572. +#define IRQ_SPI (IRQ_ARMCTRL_START + INTERRUPT_SPI)
  5573. +#define IRQ_I2SPCM (IRQ_ARMCTRL_START + INTERRUPT_I2SPCM)
  5574. +#define IRQ_SDIO (IRQ_ARMCTRL_START + INTERRUPT_SDIO)
  5575. +#define IRQ_UART (IRQ_ARMCTRL_START + INTERRUPT_UART)
  5576. +#define IRQ_SLIMBUS (IRQ_ARMCTRL_START + INTERRUPT_SLIMBUS)
  5577. +#define IRQ_VEC (IRQ_ARMCTRL_START + INTERRUPT_VEC)
  5578. +#define IRQ_CPG (IRQ_ARMCTRL_START + INTERRUPT_CPG)
  5579. +#define IRQ_RNG (IRQ_ARMCTRL_START + INTERRUPT_RNG)
  5580. +#define IRQ_ARASANSDIO (IRQ_ARMCTRL_START + INTERRUPT_ARASANSDIO)
  5581. +#define IRQ_AVSPMON (IRQ_ARMCTRL_START + INTERRUPT_AVSPMON)
  5582. +
  5583. +#define IRQ_ARM_TIMER (IRQ_ARMCTRL_START + INTERRUPT_ARM_TIMER)
  5584. +#define IRQ_ARM_MAILBOX (IRQ_ARMCTRL_START + INTERRUPT_ARM_MAILBOX)
  5585. +#define IRQ_ARM_DOORBELL_0 (IRQ_ARMCTRL_START + INTERRUPT_ARM_DOORBELL_0)
  5586. +#define IRQ_ARM_DOORBELL_1 (IRQ_ARMCTRL_START + INTERRUPT_ARM_DOORBELL_1)
  5587. +#define IRQ_VPU0_HALTED (IRQ_ARMCTRL_START + INTERRUPT_VPU0_HALTED)
  5588. +#define IRQ_VPU1_HALTED (IRQ_ARMCTRL_START + INTERRUPT_VPU1_HALTED)
  5589. +#define IRQ_ILLEGAL_TYPE0 (IRQ_ARMCTRL_START + INTERRUPT_ILLEGAL_TYPE0)
  5590. +#define IRQ_ILLEGAL_TYPE1 (IRQ_ARMCTRL_START + INTERRUPT_ILLEGAL_TYPE1)
  5591. +#define IRQ_PENDING1 (IRQ_ARMCTRL_START + INTERRUPT_PENDING1)
  5592. +#define IRQ_PENDING2 (IRQ_ARMCTRL_START + INTERRUPT_PENDING2)
  5593. +
  5594. +#define FIQ_START HARD_IRQS
  5595. +
  5596. +/*
  5597. + * FIQ interrupts definitions are the same as the INT definitions.
  5598. + */
  5599. +#define FIQ_TIMER0 (FIQ_START+INTERRUPT_TIMER0)
  5600. +#define FIQ_TIMER1 (FIQ_START+INTERRUPT_TIMER1)
  5601. +#define FIQ_TIMER2 (FIQ_START+INTERRUPT_TIMER2)
  5602. +#define FIQ_TIMER3 (FIQ_START+INTERRUPT_TIMER3)
  5603. +#define FIQ_CODEC0 (FIQ_START+INTERRUPT_CODEC0)
  5604. +#define FIQ_CODEC1 (FIQ_START+INTERRUPT_CODEC1)
  5605. +#define FIQ_CODEC2 (FIQ_START+INTERRUPT_CODEC2)
  5606. +#define FIQ_JPEG (FIQ_START+INTERRUPT_JPEG)
  5607. +#define FIQ_ISP (FIQ_START+INTERRUPT_ISP)
  5608. +#define FIQ_USB (FIQ_START+INTERRUPT_USB)
  5609. +#define FIQ_3D (FIQ_START+INTERRUPT_3D)
  5610. +#define FIQ_TRANSPOSER (FIQ_START+INTERRUPT_TRANSPOSER)
  5611. +#define FIQ_MULTICORESYNC0 (FIQ_START+INTERRUPT_MULTICORESYNC0)
  5612. +#define FIQ_MULTICORESYNC1 (FIQ_START+INTERRUPT_MULTICORESYNC1)
  5613. +#define FIQ_MULTICORESYNC2 (FIQ_START+INTERRUPT_MULTICORESYNC2)
  5614. +#define FIQ_MULTICORESYNC3 (FIQ_START+INTERRUPT_MULTICORESYNC3)
  5615. +#define FIQ_DMA0 (FIQ_START+INTERRUPT_DMA0)
  5616. +#define FIQ_DMA1 (FIQ_START+INTERRUPT_DMA1)
  5617. +#define FIQ_DMA2 (FIQ_START+INTERRUPT_DMA2)
  5618. +#define FIQ_DMA3 (FIQ_START+INTERRUPT_DMA3)
  5619. +#define FIQ_DMA4 (FIQ_START+INTERRUPT_DMA4)
  5620. +#define FIQ_DMA5 (FIQ_START+INTERRUPT_DMA5)
  5621. +#define FIQ_DMA6 (FIQ_START+INTERRUPT_DMA6)
  5622. +#define FIQ_DMA7 (FIQ_START+INTERRUPT_DMA7)
  5623. +#define FIQ_DMA8 (FIQ_START+INTERRUPT_DMA8)
  5624. +#define FIQ_DMA9 (FIQ_START+INTERRUPT_DMA9)
  5625. +#define FIQ_DMA10 (FIQ_START+INTERRUPT_DMA10)
  5626. +#define FIQ_DMA11 (FIQ_START+INTERRUPT_DMA11)
  5627. +#define FIQ_DMA12 (FIQ_START+INTERRUPT_DMA12)
  5628. +#define FIQ_AUX (FIQ_START+INTERRUPT_AUX)
  5629. +#define FIQ_ARM (FIQ_START+INTERRUPT_ARM)
  5630. +#define FIQ_VPUDMA (FIQ_START+INTERRUPT_VPUDMA)
  5631. +#define FIQ_HOSTPORT (FIQ_START+INTERRUPT_HOSTPORT)
  5632. +#define FIQ_VIDEOSCALER (FIQ_START+INTERRUPT_VIDEOSCALER)
  5633. +#define FIQ_CCP2TX (FIQ_START+INTERRUPT_CCP2TX)
  5634. +#define FIQ_SDC (FIQ_START+INTERRUPT_SDC)
  5635. +#define FIQ_DSI0 (FIQ_START+INTERRUPT_DSI0)
  5636. +#define FIQ_AVE (FIQ_START+INTERRUPT_AVE)
  5637. +#define FIQ_CAM0 (FIQ_START+INTERRUPT_CAM0)
  5638. +#define FIQ_CAM1 (FIQ_START+INTERRUPT_CAM1)
  5639. +#define FIQ_HDMI0 (FIQ_START+INTERRUPT_HDMI0)
  5640. +#define FIQ_HDMI1 (FIQ_START+INTERRUPT_HDMI1)
  5641. +#define FIQ_PIXELVALVE1 (FIQ_START+INTERRUPT_PIXELVALVE1)
  5642. +#define FIQ_I2CSPISLV (FIQ_START+INTERRUPT_I2CSPISLV)
  5643. +#define FIQ_DSI1 (FIQ_START+INTERRUPT_DSI1)
  5644. +#define FIQ_PWA0 (FIQ_START+INTERRUPT_PWA0)
  5645. +#define FIQ_PWA1 (FIQ_START+INTERRUPT_PWA1)
  5646. +#define FIQ_CPR (FIQ_START+INTERRUPT_CPR)
  5647. +#define FIQ_SMI (FIQ_START+INTERRUPT_SMI)
  5648. +#define FIQ_GPIO0 (FIQ_START+INTERRUPT_GPIO0)
  5649. +#define FIQ_GPIO1 (FIQ_START+INTERRUPT_GPIO1)
  5650. +#define FIQ_GPIO2 (FIQ_START+INTERRUPT_GPIO2)
  5651. +#define FIQ_GPIO3 (FIQ_START+INTERRUPT_GPIO3)
  5652. +#define FIQ_I2C (FIQ_START+INTERRUPT_I2C)
  5653. +#define FIQ_SPI (FIQ_START+INTERRUPT_SPI)
  5654. +#define FIQ_I2SPCM (FIQ_START+INTERRUPT_I2SPCM)
  5655. +#define FIQ_SDIO (FIQ_START+INTERRUPT_SDIO)
  5656. +#define FIQ_UART (FIQ_START+INTERRUPT_UART)
  5657. +#define FIQ_SLIMBUS (FIQ_START+INTERRUPT_SLIMBUS)
  5658. +#define FIQ_VEC (FIQ_START+INTERRUPT_VEC)
  5659. +#define FIQ_CPG (FIQ_START+INTERRUPT_CPG)
  5660. +#define FIQ_RNG (FIQ_START+INTERRUPT_RNG)
  5661. +#define FIQ_ARASANSDIO (FIQ_START+INTERRUPT_ARASANSDIO)
  5662. +#define FIQ_AVSPMON (FIQ_START+INTERRUPT_AVSPMON)
  5663. +
  5664. +#define FIQ_ARM_TIMER (FIQ_START+INTERRUPT_ARM_TIMER)
  5665. +#define FIQ_ARM_MAILBOX (FIQ_START+INTERRUPT_ARM_MAILBOX)
  5666. +#define FIQ_ARM_DOORBELL_0 (FIQ_START+INTERRUPT_ARM_DOORBELL_0)
  5667. +#define FIQ_ARM_DOORBELL_1 (FIQ_START+INTERRUPT_ARM_DOORBELL_1)
  5668. +#define FIQ_VPU0_HALTED (FIQ_START+INTERRUPT_VPU0_HALTED)
  5669. +#define FIQ_VPU1_HALTED (FIQ_START+INTERRUPT_VPU1_HALTED)
  5670. +#define FIQ_ILLEGAL_TYPE0 (FIQ_START+INTERRUPT_ILLEGAL_TYPE0)
  5671. +#define FIQ_ILLEGAL_TYPE1 (FIQ_START+INTERRUPT_ILLEGAL_TYPE1)
  5672. +#define FIQ_PENDING1 (FIQ_START+INTERRUPT_PENDING1)
  5673. +#define FIQ_PENDING2 (FIQ_START+INTERRUPT_PENDING2)
  5674. +
  5675. +#define HARD_IRQS (64 + 21)
  5676. +#define FIQ_IRQS (64 + 21)
  5677. +#define GPIO_IRQ_START (HARD_IRQS + FIQ_IRQS)
  5678. +#define GPIO_IRQS (32*5)
  5679. +#define SPARE_IRQS (64)
  5680. +#define NR_IRQS (HARD_IRQS+FIQ_IRQS+GPIO_IRQS+SPARE_IRQS)
  5681. +
  5682. +#endif /* _BCM2708_IRQS_H_ */
  5683. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/include/mach/memory.h linux-rpi/arch/arm/mach-bcm2708/include/mach/memory.h
  5684. --- linux-3.15.4/arch/arm/mach-bcm2708/include/mach/memory.h 1970-01-01 01:00:00.000000000 +0100
  5685. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/memory.h 2014-04-13 17:32:40.000000000 +0200
  5686. @@ -0,0 +1,57 @@
  5687. +/*
  5688. + * arch/arm/mach-bcm2708/include/mach/memory.h
  5689. + *
  5690. + * Copyright (C) 2010 Broadcom
  5691. + *
  5692. + * This program is free software; you can redistribute it and/or modify
  5693. + * it under the terms of the GNU General Public License as published by
  5694. + * the Free Software Foundation; either version 2 of the License, or
  5695. + * (at your option) any later version.
  5696. + *
  5697. + * This program is distributed in the hope that it will be useful,
  5698. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5699. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5700. + * GNU General Public License for more details.
  5701. + *
  5702. + * You should have received a copy of the GNU General Public License
  5703. + * along with this program; if not, write to the Free Software
  5704. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5705. + */
  5706. +#ifndef __ASM_ARCH_MEMORY_H
  5707. +#define __ASM_ARCH_MEMORY_H
  5708. +
  5709. +/* Memory overview:
  5710. +
  5711. + [ARMcore] <--virtual addr-->
  5712. + [ARMmmu] <--physical addr-->
  5713. + [GERTmap] <--bus add-->
  5714. + [VCperiph]
  5715. +
  5716. +*/
  5717. +
  5718. +/*
  5719. + * Physical DRAM offset.
  5720. + */
  5721. +#define PLAT_PHYS_OFFSET UL(0x00000000)
  5722. +#define VC_ARMMEM_OFFSET UL(0x00000000) /* offset in VC of ARM memory */
  5723. +
  5724. +#ifdef CONFIG_BCM2708_NOL2CACHE
  5725. + #define _REAL_BUS_OFFSET UL(0xC0000000) /* don't use L1 or L2 caches */
  5726. +#else
  5727. + #define _REAL_BUS_OFFSET UL(0x40000000) /* use L2 cache */
  5728. +#endif
  5729. +
  5730. +/* We're using the memory at 64M in the VideoCore for Linux - this adjustment
  5731. + * will provide the offset into this area as well as setting the bits that
  5732. + * stop the L1 and L2 cache from being used
  5733. + *
  5734. + * WARNING: this only works because the ARM is given memory at a fixed location
  5735. + * (ARMMEM_OFFSET)
  5736. + */
  5737. +#define BUS_OFFSET (VC_ARMMEM_OFFSET + _REAL_BUS_OFFSET)
  5738. +#define __virt_to_bus(x) ((x) + (BUS_OFFSET - PAGE_OFFSET))
  5739. +#define __bus_to_virt(x) ((x) - (BUS_OFFSET - PAGE_OFFSET))
  5740. +#define __pfn_to_bus(x) (__pfn_to_phys(x) + (BUS_OFFSET - PLAT_PHYS_OFFSET))
  5741. +#define __bus_to_pfn(x) __phys_to_pfn((x) - (BUS_OFFSET - PLAT_PHYS_OFFSET))
  5742. +
  5743. +#endif
  5744. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/include/mach/platform.h linux-rpi/arch/arm/mach-bcm2708/include/mach/platform.h
  5745. --- linux-3.15.4/arch/arm/mach-bcm2708/include/mach/platform.h 1970-01-01 01:00:00.000000000 +0100
  5746. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/platform.h 2014-04-13 17:32:40.000000000 +0200
  5747. @@ -0,0 +1,228 @@
  5748. +/*
  5749. + * arch/arm/mach-bcm2708/include/mach/platform.h
  5750. + *
  5751. + * Copyright (C) 2010 Broadcom
  5752. + *
  5753. + * This program is free software; you can redistribute it and/or modify
  5754. + * it under the terms of the GNU General Public License as published by
  5755. + * the Free Software Foundation; either version 2 of the License, or
  5756. + * (at your option) any later version.
  5757. + *
  5758. + * This program is distributed in the hope that it will be useful,
  5759. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5760. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5761. + * GNU General Public License for more details.
  5762. + *
  5763. + * You should have received a copy of the GNU General Public License
  5764. + * along with this program; if not, write to the Free Software
  5765. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5766. + */
  5767. +
  5768. +#ifndef _BCM2708_PLATFORM_H
  5769. +#define _BCM2708_PLATFORM_H
  5770. +
  5771. +
  5772. +/* macros to get at IO space when running virtually */
  5773. +#define IO_ADDRESS(x) (((x) & 0x0fffffff) + (((x) >> 4) & 0x0f000000) + 0xf0000000)
  5774. +
  5775. +#define __io_address(n) IOMEM(IO_ADDRESS(n))
  5776. +
  5777. +
  5778. +/*
  5779. + * SDRAM
  5780. + */
  5781. +#define BCM2708_SDRAM_BASE 0x00000000
  5782. +
  5783. +/*
  5784. + * Logic expansion modules
  5785. + *
  5786. + */
  5787. +
  5788. +
  5789. +/* ------------------------------------------------------------------------
  5790. + * BCM2708 ARMCTRL Registers
  5791. + * ------------------------------------------------------------------------
  5792. + */
  5793. +
  5794. +#define HW_REGISTER_RW(addr) (addr)
  5795. +#define HW_REGISTER_RO(addr) (addr)
  5796. +
  5797. +#include "arm_control.h"
  5798. +#undef ARM_BASE
  5799. +
  5800. +/*
  5801. + * Definitions and addresses for the ARM CONTROL logic
  5802. + * This file is manually generated.
  5803. + */
  5804. +
  5805. +#define BCM2708_PERI_BASE 0x20000000
  5806. +#define IC0_BASE (BCM2708_PERI_BASE + 0x2000)
  5807. +#define ST_BASE (BCM2708_PERI_BASE + 0x3000) /* System Timer */
  5808. +#define MPHI_BASE (BCM2708_PERI_BASE + 0x6000) /* Message -based Parallel Host Interface */
  5809. +#define DMA_BASE (BCM2708_PERI_BASE + 0x7000) /* DMA controller */
  5810. +#define ARM_BASE (BCM2708_PERI_BASE + 0xB000) /* BCM2708 ARM control block */
  5811. +#define PM_BASE (BCM2708_PERI_BASE + 0x100000) /* Power Management, Reset controller and Watchdog registers */
  5812. +#define PCM_CLOCK_BASE (BCM2708_PERI_BASE + 0x101098) /* PCM Clock */
  5813. +#define RNG_BASE (BCM2708_PERI_BASE + 0x104000) /* Hardware RNG */
  5814. +#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO */
  5815. +#define UART0_BASE (BCM2708_PERI_BASE + 0x201000) /* Uart 0 */
  5816. +#define MMCI0_BASE (BCM2708_PERI_BASE + 0x202000) /* MMC interface */
  5817. +#define I2S_BASE (BCM2708_PERI_BASE + 0x203000) /* I2S */
  5818. +#define SPI0_BASE (BCM2708_PERI_BASE + 0x204000) /* SPI0 */
  5819. +#define BSC0_BASE (BCM2708_PERI_BASE + 0x205000) /* BSC0 I2C/TWI */
  5820. +#define UART1_BASE (BCM2708_PERI_BASE + 0x215000) /* Uart 1 */
  5821. +#define EMMC_BASE (BCM2708_PERI_BASE + 0x300000) /* eMMC interface */
  5822. +#define SMI_BASE (BCM2708_PERI_BASE + 0x600000) /* SMI */
  5823. +#define BSC1_BASE (BCM2708_PERI_BASE + 0x804000) /* BSC1 I2C/TWI */
  5824. +#define USB_BASE (BCM2708_PERI_BASE + 0x980000) /* DTC_OTG USB controller */
  5825. +#define MCORE_BASE (BCM2708_PERI_BASE + 0x0000) /* Fake frame buffer device (actually the multicore sync block*/
  5826. +
  5827. +#define ARMCTRL_BASE (ARM_BASE + 0x000)
  5828. +#define ARMCTRL_IC_BASE (ARM_BASE + 0x200) /* ARM interrupt controller */
  5829. +#define ARMCTRL_TIMER0_1_BASE (ARM_BASE + 0x400) /* Timer 0 and 1 */
  5830. +#define ARMCTRL_0_SBM_BASE (ARM_BASE + 0x800) /* User 0 (ARM)'s Semaphores Doorbells and Mailboxes */
  5831. +
  5832. +
  5833. +/*
  5834. + * Interrupt assignments
  5835. + */
  5836. +
  5837. +#define ARM_IRQ1_BASE 0
  5838. +#define INTERRUPT_TIMER0 (ARM_IRQ1_BASE + 0)
  5839. +#define INTERRUPT_TIMER1 (ARM_IRQ1_BASE + 1)
  5840. +#define INTERRUPT_TIMER2 (ARM_IRQ1_BASE + 2)
  5841. +#define INTERRUPT_TIMER3 (ARM_IRQ1_BASE + 3)
  5842. +#define INTERRUPT_CODEC0 (ARM_IRQ1_BASE + 4)
  5843. +#define INTERRUPT_CODEC1 (ARM_IRQ1_BASE + 5)
  5844. +#define INTERRUPT_CODEC2 (ARM_IRQ1_BASE + 6)
  5845. +#define INTERRUPT_VC_JPEG (ARM_IRQ1_BASE + 7)
  5846. +#define INTERRUPT_ISP (ARM_IRQ1_BASE + 8)
  5847. +#define INTERRUPT_VC_USB (ARM_IRQ1_BASE + 9)
  5848. +#define INTERRUPT_VC_3D (ARM_IRQ1_BASE + 10)
  5849. +#define INTERRUPT_TRANSPOSER (ARM_IRQ1_BASE + 11)
  5850. +#define INTERRUPT_MULTICORESYNC0 (ARM_IRQ1_BASE + 12)
  5851. +#define INTERRUPT_MULTICORESYNC1 (ARM_IRQ1_BASE + 13)
  5852. +#define INTERRUPT_MULTICORESYNC2 (ARM_IRQ1_BASE + 14)
  5853. +#define INTERRUPT_MULTICORESYNC3 (ARM_IRQ1_BASE + 15)
  5854. +#define INTERRUPT_DMA0 (ARM_IRQ1_BASE + 16)
  5855. +#define INTERRUPT_DMA1 (ARM_IRQ1_BASE + 17)
  5856. +#define INTERRUPT_VC_DMA2 (ARM_IRQ1_BASE + 18)
  5857. +#define INTERRUPT_VC_DMA3 (ARM_IRQ1_BASE + 19)
  5858. +#define INTERRUPT_DMA4 (ARM_IRQ1_BASE + 20)
  5859. +#define INTERRUPT_DMA5 (ARM_IRQ1_BASE + 21)
  5860. +#define INTERRUPT_DMA6 (ARM_IRQ1_BASE + 22)
  5861. +#define INTERRUPT_DMA7 (ARM_IRQ1_BASE + 23)
  5862. +#define INTERRUPT_DMA8 (ARM_IRQ1_BASE + 24)
  5863. +#define INTERRUPT_DMA9 (ARM_IRQ1_BASE + 25)
  5864. +#define INTERRUPT_DMA10 (ARM_IRQ1_BASE + 26)
  5865. +#define INTERRUPT_DMA11 (ARM_IRQ1_BASE + 27)
  5866. +#define INTERRUPT_DMA12 (ARM_IRQ1_BASE + 28)
  5867. +#define INTERRUPT_AUX (ARM_IRQ1_BASE + 29)
  5868. +#define INTERRUPT_ARM (ARM_IRQ1_BASE + 30)
  5869. +#define INTERRUPT_VPUDMA (ARM_IRQ1_BASE + 31)
  5870. +
  5871. +#define ARM_IRQ2_BASE 32
  5872. +#define INTERRUPT_HOSTPORT (ARM_IRQ2_BASE + 0)
  5873. +#define INTERRUPT_VIDEOSCALER (ARM_IRQ2_BASE + 1)
  5874. +#define INTERRUPT_CCP2TX (ARM_IRQ2_BASE + 2)
  5875. +#define INTERRUPT_SDC (ARM_IRQ2_BASE + 3)
  5876. +#define INTERRUPT_DSI0 (ARM_IRQ2_BASE + 4)
  5877. +#define INTERRUPT_AVE (ARM_IRQ2_BASE + 5)
  5878. +#define INTERRUPT_CAM0 (ARM_IRQ2_BASE + 6)
  5879. +#define INTERRUPT_CAM1 (ARM_IRQ2_BASE + 7)
  5880. +#define INTERRUPT_HDMI0 (ARM_IRQ2_BASE + 8)
  5881. +#define INTERRUPT_HDMI1 (ARM_IRQ2_BASE + 9)
  5882. +#define INTERRUPT_PIXELVALVE1 (ARM_IRQ2_BASE + 10)
  5883. +#define INTERRUPT_I2CSPISLV (ARM_IRQ2_BASE + 11)
  5884. +#define INTERRUPT_DSI1 (ARM_IRQ2_BASE + 12)
  5885. +#define INTERRUPT_PWA0 (ARM_IRQ2_BASE + 13)
  5886. +#define INTERRUPT_PWA1 (ARM_IRQ2_BASE + 14)
  5887. +#define INTERRUPT_CPR (ARM_IRQ2_BASE + 15)
  5888. +#define INTERRUPT_SMI (ARM_IRQ2_BASE + 16)
  5889. +#define INTERRUPT_GPIO0 (ARM_IRQ2_BASE + 17)
  5890. +#define INTERRUPT_GPIO1 (ARM_IRQ2_BASE + 18)
  5891. +#define INTERRUPT_GPIO2 (ARM_IRQ2_BASE + 19)
  5892. +#define INTERRUPT_GPIO3 (ARM_IRQ2_BASE + 20)
  5893. +#define INTERRUPT_VC_I2C (ARM_IRQ2_BASE + 21)
  5894. +#define INTERRUPT_VC_SPI (ARM_IRQ2_BASE + 22)
  5895. +#define INTERRUPT_VC_I2SPCM (ARM_IRQ2_BASE + 23)
  5896. +#define INTERRUPT_VC_SDIO (ARM_IRQ2_BASE + 24)
  5897. +#define INTERRUPT_VC_UART (ARM_IRQ2_BASE + 25)
  5898. +#define INTERRUPT_SLIMBUS (ARM_IRQ2_BASE + 26)
  5899. +#define INTERRUPT_VEC (ARM_IRQ2_BASE + 27)
  5900. +#define INTERRUPT_CPG (ARM_IRQ2_BASE + 28)
  5901. +#define INTERRUPT_RNG (ARM_IRQ2_BASE + 29)
  5902. +#define INTERRUPT_VC_ARASANSDIO (ARM_IRQ2_BASE + 30)
  5903. +#define INTERRUPT_AVSPMON (ARM_IRQ2_BASE + 31)
  5904. +
  5905. +#define ARM_IRQ0_BASE 64
  5906. +#define INTERRUPT_ARM_TIMER (ARM_IRQ0_BASE + 0)
  5907. +#define INTERRUPT_ARM_MAILBOX (ARM_IRQ0_BASE + 1)
  5908. +#define INTERRUPT_ARM_DOORBELL_0 (ARM_IRQ0_BASE + 2)
  5909. +#define INTERRUPT_ARM_DOORBELL_1 (ARM_IRQ0_BASE + 3)
  5910. +#define INTERRUPT_VPU0_HALTED (ARM_IRQ0_BASE + 4)
  5911. +#define INTERRUPT_VPU1_HALTED (ARM_IRQ0_BASE + 5)
  5912. +#define INTERRUPT_ILLEGAL_TYPE0 (ARM_IRQ0_BASE + 6)
  5913. +#define INTERRUPT_ILLEGAL_TYPE1 (ARM_IRQ0_BASE + 7)
  5914. +#define INTERRUPT_PENDING1 (ARM_IRQ0_BASE + 8)
  5915. +#define INTERRUPT_PENDING2 (ARM_IRQ0_BASE + 9)
  5916. +#define INTERRUPT_JPEG (ARM_IRQ0_BASE + 10)
  5917. +#define INTERRUPT_USB (ARM_IRQ0_BASE + 11)
  5918. +#define INTERRUPT_3D (ARM_IRQ0_BASE + 12)
  5919. +#define INTERRUPT_DMA2 (ARM_IRQ0_BASE + 13)
  5920. +#define INTERRUPT_DMA3 (ARM_IRQ0_BASE + 14)
  5921. +#define INTERRUPT_I2C (ARM_IRQ0_BASE + 15)
  5922. +#define INTERRUPT_SPI (ARM_IRQ0_BASE + 16)
  5923. +#define INTERRUPT_I2SPCM (ARM_IRQ0_BASE + 17)
  5924. +#define INTERRUPT_SDIO (ARM_IRQ0_BASE + 18)
  5925. +#define INTERRUPT_UART (ARM_IRQ0_BASE + 19)
  5926. +#define INTERRUPT_ARASANSDIO (ARM_IRQ0_BASE + 20)
  5927. +
  5928. +#define MAXIRQNUM (32 + 32 + 20)
  5929. +#define MAXFIQNUM (32 + 32 + 20)
  5930. +
  5931. +#define MAX_TIMER 2
  5932. +#define MAX_PERIOD 699050
  5933. +#define TICKS_PER_uSEC 1
  5934. +
  5935. +/*
  5936. + * These are useconds NOT ticks.
  5937. + *
  5938. + */
  5939. +#define mSEC_1 1000
  5940. +#define mSEC_5 (mSEC_1 * 5)
  5941. +#define mSEC_10 (mSEC_1 * 10)
  5942. +#define mSEC_25 (mSEC_1 * 25)
  5943. +#define SEC_1 (mSEC_1 * 1000)
  5944. +
  5945. +/*
  5946. + * Watchdog
  5947. + */
  5948. +#define PM_RSTC (PM_BASE+0x1c)
  5949. +#define PM_RSTS (PM_BASE+0x20)
  5950. +#define PM_WDOG (PM_BASE+0x24)
  5951. +
  5952. +#define PM_WDOG_RESET 0000000000
  5953. +#define PM_PASSWORD 0x5a000000
  5954. +#define PM_WDOG_TIME_SET 0x000fffff
  5955. +#define PM_RSTC_WRCFG_CLR 0xffffffcf
  5956. +#define PM_RSTC_WRCFG_SET 0x00000030
  5957. +#define PM_RSTC_WRCFG_FULL_RESET 0x00000020
  5958. +#define PM_RSTC_RESET 0x00000102
  5959. +
  5960. +#define PM_RSTS_HADPOR_SET 0x00001000
  5961. +#define PM_RSTS_HADSRH_SET 0x00000400
  5962. +#define PM_RSTS_HADSRF_SET 0x00000200
  5963. +#define PM_RSTS_HADSRQ_SET 0x00000100
  5964. +#define PM_RSTS_HADWRH_SET 0x00000040
  5965. +#define PM_RSTS_HADWRF_SET 0x00000020
  5966. +#define PM_RSTS_HADWRQ_SET 0x00000010
  5967. +#define PM_RSTS_HADDRH_SET 0x00000004
  5968. +#define PM_RSTS_HADDRF_SET 0x00000002
  5969. +#define PM_RSTS_HADDRQ_SET 0x00000001
  5970. +
  5971. +#define UART0_CLOCK 3000000
  5972. +
  5973. +#endif
  5974. +
  5975. +/* END */
  5976. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/include/mach/power.h linux-rpi/arch/arm/mach-bcm2708/include/mach/power.h
  5977. --- linux-3.15.4/arch/arm/mach-bcm2708/include/mach/power.h 1970-01-01 01:00:00.000000000 +0100
  5978. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/power.h 2014-04-13 17:32:40.000000000 +0200
  5979. @@ -0,0 +1,26 @@
  5980. +/*
  5981. + * linux/arch/arm/mach-bcm2708/power.h
  5982. + *
  5983. + * Copyright (C) 2010 Broadcom
  5984. + *
  5985. + * This program is free software; you can redistribute it and/or modify
  5986. + * it under the terms of the GNU General Public License version 2 as
  5987. + * published by the Free Software Foundation.
  5988. + *
  5989. + * This device provides a shared mechanism for controlling the power to
  5990. + * VideoCore subsystems.
  5991. + */
  5992. +
  5993. +#ifndef _MACH_BCM2708_POWER_H
  5994. +#define _MACH_BCM2708_POWER_H
  5995. +
  5996. +#include <linux/types.h>
  5997. +#include <mach/arm_power.h>
  5998. +
  5999. +typedef unsigned int BCM_POWER_HANDLE_T;
  6000. +
  6001. +extern int bcm_power_open(BCM_POWER_HANDLE_T *handle);
  6002. +extern int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request);
  6003. +extern int bcm_power_close(BCM_POWER_HANDLE_T handle);
  6004. +
  6005. +#endif
  6006. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/include/mach/system.h linux-rpi/arch/arm/mach-bcm2708/include/mach/system.h
  6007. --- linux-3.15.4/arch/arm/mach-bcm2708/include/mach/system.h 1970-01-01 01:00:00.000000000 +0100
  6008. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/system.h 2014-04-13 17:32:40.000000000 +0200
  6009. @@ -0,0 +1,38 @@
  6010. +/*
  6011. + * arch/arm/mach-bcm2708/include/mach/system.h
  6012. + *
  6013. + * Copyright (C) 2010 Broadcom
  6014. + * Copyright (C) 2003 ARM Limited
  6015. + * Copyright (C) 2000 Deep Blue Solutions Ltd
  6016. + *
  6017. + * This program is free software; you can redistribute it and/or modify
  6018. + * it under the terms of the GNU General Public License as published by
  6019. + * the Free Software Foundation; either version 2 of the License, or
  6020. + * (at your option) any later version.
  6021. + *
  6022. + * This program is distributed in the hope that it will be useful,
  6023. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6024. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6025. + * GNU General Public License for more details.
  6026. + *
  6027. + * You should have received a copy of the GNU General Public License
  6028. + * along with this program; if not, write to the Free Software
  6029. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6030. + */
  6031. +#ifndef __ASM_ARCH_SYSTEM_H
  6032. +#define __ASM_ARCH_SYSTEM_H
  6033. +
  6034. +#include <linux/io.h>
  6035. +#include <mach/hardware.h>
  6036. +#include <mach/platform.h>
  6037. +
  6038. +static inline void arch_idle(void)
  6039. +{
  6040. + /*
  6041. + * This should do all the clock switching
  6042. + * and wait for interrupt tricks
  6043. + */
  6044. + cpu_do_idle();
  6045. +}
  6046. +
  6047. +#endif
  6048. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/include/mach/timex.h linux-rpi/arch/arm/mach-bcm2708/include/mach/timex.h
  6049. --- linux-3.15.4/arch/arm/mach-bcm2708/include/mach/timex.h 1970-01-01 01:00:00.000000000 +0100
  6050. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/timex.h 2014-04-13 17:32:40.000000000 +0200
  6051. @@ -0,0 +1,23 @@
  6052. +/*
  6053. + * arch/arm/mach-bcm2708/include/mach/timex.h
  6054. + *
  6055. + * BCM2708 sysem clock frequency
  6056. + *
  6057. + * Copyright (C) 2010 Broadcom
  6058. + *
  6059. + * This program is free software; you can redistribute it and/or modify
  6060. + * it under the terms of the GNU General Public License as published by
  6061. + * the Free Software Foundation; either version 2 of the License, or
  6062. + * (at your option) any later version.
  6063. + *
  6064. + * This program is distributed in the hope that it will be useful,
  6065. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6066. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6067. + * GNU General Public License for more details.
  6068. + *
  6069. + * You should have received a copy of the GNU General Public License
  6070. + * along with this program; if not, write to the Free Software
  6071. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6072. + */
  6073. +
  6074. +#define CLOCK_TICK_RATE (1000000)
  6075. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/include/mach/uncompress.h linux-rpi/arch/arm/mach-bcm2708/include/mach/uncompress.h
  6076. --- linux-3.15.4/arch/arm/mach-bcm2708/include/mach/uncompress.h 1970-01-01 01:00:00.000000000 +0100
  6077. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/uncompress.h 2014-07-07 10:44:57.000000000 +0200
  6078. @@ -0,0 +1,84 @@
  6079. +/*
  6080. + * arch/arm/mach-bcn2708/include/mach/uncompress.h
  6081. + *
  6082. + * Copyright (C) 2010 Broadcom
  6083. + * Copyright (C) 2003 ARM Limited
  6084. + *
  6085. + * This program is free software; you can redistribute it and/or modify
  6086. + * it under the terms of the GNU General Public License as published by
  6087. + * the Free Software Foundation; either version 2 of the License, or
  6088. + * (at your option) any later version.
  6089. + *
  6090. + * This program is distributed in the hope that it will be useful,
  6091. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6092. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6093. + * GNU General Public License for more details.
  6094. + *
  6095. + * You should have received a copy of the GNU General Public License
  6096. + * along with this program; if not, write to the Free Software
  6097. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6098. + */
  6099. +
  6100. +#include <linux/io.h>
  6101. +#include <linux/amba/serial.h>
  6102. +#include <mach/hardware.h>
  6103. +
  6104. +#define UART_BAUD 115200
  6105. +
  6106. +#define BCM2708_UART_DR __io(UART0_BASE + UART01x_DR)
  6107. +#define BCM2708_UART_FR __io(UART0_BASE + UART01x_FR)
  6108. +#define BCM2708_UART_IBRD __io(UART0_BASE + UART011_IBRD)
  6109. +#define BCM2708_UART_FBRD __io(UART0_BASE + UART011_FBRD)
  6110. +#define BCM2708_UART_LCRH __io(UART0_BASE + UART011_LCRH)
  6111. +#define BCM2708_UART_CR __io(UART0_BASE + UART011_CR)
  6112. +
  6113. +/*
  6114. + * This does not append a newline
  6115. + */
  6116. +static inline void putc(int c)
  6117. +{
  6118. + while (__raw_readl(BCM2708_UART_FR) & UART01x_FR_TXFF)
  6119. + barrier();
  6120. +
  6121. + __raw_writel(c, BCM2708_UART_DR);
  6122. +}
  6123. +
  6124. +static inline void flush(void)
  6125. +{
  6126. + int fr;
  6127. +
  6128. + do {
  6129. + fr = __raw_readl(BCM2708_UART_FR);
  6130. + barrier();
  6131. + } while ((fr & (UART011_FR_TXFE | UART01x_FR_BUSY)) != UART011_FR_TXFE);
  6132. +}
  6133. +
  6134. +static inline void arch_decomp_setup(void)
  6135. +{
  6136. + int temp, div, rem, frac;
  6137. +
  6138. + temp = 16 * UART_BAUD;
  6139. + div = UART0_CLOCK / temp;
  6140. + rem = UART0_CLOCK % temp;
  6141. + temp = (8 * rem) / UART_BAUD;
  6142. + frac = (temp >> 1) + (temp & 1);
  6143. +
  6144. + /* Make sure the UART is disabled before we start */
  6145. + __raw_writel(0, BCM2708_UART_CR);
  6146. +
  6147. + /* Set the baud rate */
  6148. + __raw_writel(div, BCM2708_UART_IBRD);
  6149. + __raw_writel(frac, BCM2708_UART_FBRD);
  6150. +
  6151. + /* Set the UART to 8n1, FIFO enabled */
  6152. + __raw_writel(UART01x_LCRH_WLEN_8 | UART01x_LCRH_FEN, BCM2708_UART_LCRH);
  6153. +
  6154. + /* Enable the UART */
  6155. + __raw_writel(UART01x_CR_UARTEN | UART011_CR_TXE | UART011_CR_RXE,
  6156. + BCM2708_UART_CR);
  6157. +}
  6158. +
  6159. +/*
  6160. + * nothing to do
  6161. + */
  6162. +#define arch_decomp_wdog()
  6163. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/include/mach/vcio.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vcio.h
  6164. --- linux-3.15.4/arch/arm/mach-bcm2708/include/mach/vcio.h 1970-01-01 01:00:00.000000000 +0100
  6165. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vcio.h 2014-07-07 10:44:57.000000000 +0200
  6166. @@ -0,0 +1,141 @@
  6167. +/*
  6168. + * arch/arm/mach-bcm2708/include/mach/vcio.h
  6169. + *
  6170. + * Copyright (C) 2010 Broadcom
  6171. + *
  6172. + * This program is free software; you can redistribute it and/or modify
  6173. + * it under the terms of the GNU General Public License as published by
  6174. + * the Free Software Foundation; either version 2 of the License, or
  6175. + * (at your option) any later version.
  6176. + *
  6177. + * This program is distributed in the hope that it will be useful,
  6178. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6179. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6180. + * GNU General Public License for more details.
  6181. + *
  6182. + * You should have received a copy of the GNU General Public License
  6183. + * along with this program; if not, write to the Free Software
  6184. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6185. + */
  6186. +#ifndef _MACH_BCM2708_VCIO_H
  6187. +#define _MACH_BCM2708_VCIO_H
  6188. +
  6189. +/* Routines to handle I/O via the VideoCore "ARM control" registers
  6190. + * (semaphores, doorbells, mailboxes)
  6191. + */
  6192. +
  6193. +#define BCM_VCIO_DRIVER_NAME "bcm2708_vcio"
  6194. +
  6195. +/* Constants shared with the ARM identifying separate mailbox channels */
  6196. +#define MBOX_CHAN_POWER 0 /* for use by the power management interface */
  6197. +#define MBOX_CHAN_FB 1 /* for use by the frame buffer */
  6198. +#define MBOX_CHAN_VCHIQ 3 /* for use by the VCHIQ interface */
  6199. +#define MBOX_CHAN_PROPERTY 8 /* for use by the property channel */
  6200. +#define MBOX_CHAN_COUNT 9
  6201. +
  6202. +/* Mailbox property tags */
  6203. +enum {
  6204. + VCMSG_PROPERTY_END = 0x00000000,
  6205. + VCMSG_GET_FIRMWARE_REVISION = 0x00000001,
  6206. + VCMSG_GET_BOARD_MODEL = 0x00010001,
  6207. + VCMSG_GET_BOARD_REVISION = 0x00020002,
  6208. + VCMSG_GET_BOARD_MAC_ADDRESS = 0x00020003,
  6209. + VCMSG_GET_BOARD_SERIAL = 0x00020004,
  6210. + VCMSG_GET_ARM_MEMORY = 0x00020005,
  6211. + VCMSG_GET_VC_MEMORY = 0x00020006,
  6212. + VCMSG_GET_CLOCKS = 0x00020007,
  6213. + VCMSG_GET_COMMAND_LINE = 0x00050001,
  6214. + VCMSG_GET_DMA_CHANNELS = 0x00060001,
  6215. + VCMSG_GET_POWER_STATE = 0x00020001,
  6216. + VCMSG_GET_TIMING = 0x00020002,
  6217. + VCMSG_SET_POWER_STATE = 0x00028001,
  6218. + VCMSG_GET_CLOCK_STATE = 0x00030001,
  6219. + VCMSG_SET_CLOCK_STATE = 0x00038001,
  6220. + VCMSG_GET_CLOCK_RATE = 0x00030002,
  6221. + VCMSG_SET_CLOCK_RATE = 0x00038002,
  6222. + VCMSG_GET_VOLTAGE = 0x00030003,
  6223. + VCMSG_SET_VOLTAGE = 0x00038003,
  6224. + VCMSG_GET_MAX_CLOCK = 0x00030004,
  6225. + VCMSG_GET_MAX_VOLTAGE = 0x00030005,
  6226. + VCMSG_GET_TEMPERATURE = 0x00030006,
  6227. + VCMSG_GET_MIN_CLOCK = 0x00030007,
  6228. + VCMSG_GET_MIN_VOLTAGE = 0x00030008,
  6229. + VCMSG_GET_TURBO = 0x00030009,
  6230. + VCMSG_SET_TURBO = 0x00038009,
  6231. + VCMSG_SET_ALLOCATE_BUFFER = 0x00040001,
  6232. + VCMSG_SET_RELEASE_BUFFER = 0x00048001,
  6233. + VCMSG_SET_BLANK_SCREEN = 0x00040002,
  6234. + VCMSG_TST_BLANK_SCREEN = 0x00044002,
  6235. + VCMSG_GET_PHYSICAL_WIDTH_HEIGHT = 0x00040003,
  6236. + VCMSG_TST_PHYSICAL_WIDTH_HEIGHT = 0x00044003,
  6237. + VCMSG_SET_PHYSICAL_WIDTH_HEIGHT = 0x00048003,
  6238. + VCMSG_GET_VIRTUAL_WIDTH_HEIGHT = 0x00040004,
  6239. + VCMSG_TST_VIRTUAL_WIDTH_HEIGHT = 0x00044004,
  6240. + VCMSG_SET_VIRTUAL_WIDTH_HEIGHT = 0x00048004,
  6241. + VCMSG_GET_DEPTH = 0x00040005,
  6242. + VCMSG_TST_DEPTH = 0x00044005,
  6243. + VCMSG_SET_DEPTH = 0x00048005,
  6244. + VCMSG_GET_PIXEL_ORDER = 0x00040006,
  6245. + VCMSG_TST_PIXEL_ORDER = 0x00044006,
  6246. + VCMSG_SET_PIXEL_ORDER = 0x00048006,
  6247. + VCMSG_GET_ALPHA_MODE = 0x00040007,
  6248. + VCMSG_TST_ALPHA_MODE = 0x00044007,
  6249. + VCMSG_SET_ALPHA_MODE = 0x00048007,
  6250. + VCMSG_GET_PITCH = 0x00040008,
  6251. + VCMSG_TST_PITCH = 0x00044008,
  6252. + VCMSG_SET_PITCH = 0x00048008,
  6253. + VCMSG_GET_VIRTUAL_OFFSET = 0x00040009,
  6254. + VCMSG_TST_VIRTUAL_OFFSET = 0x00044009,
  6255. + VCMSG_SET_VIRTUAL_OFFSET = 0x00048009,
  6256. + VCMSG_GET_OVERSCAN = 0x0004000a,
  6257. + VCMSG_TST_OVERSCAN = 0x0004400a,
  6258. + VCMSG_SET_OVERSCAN = 0x0004800a,
  6259. + VCMSG_GET_PALETTE = 0x0004000b,
  6260. + VCMSG_TST_PALETTE = 0x0004400b,
  6261. + VCMSG_SET_PALETTE = 0x0004800b,
  6262. + VCMSG_GET_LAYER = 0x0004000c,
  6263. + VCMSG_TST_LAYER = 0x0004400c,
  6264. + VCMSG_SET_LAYER = 0x0004800c,
  6265. + VCMSG_GET_TRANSFORM = 0x0004000d,
  6266. + VCMSG_TST_TRANSFORM = 0x0004400d,
  6267. + VCMSG_SET_TRANSFORM = 0x0004800d,
  6268. +};
  6269. +
  6270. +extern int /*rc*/ bcm_mailbox_read(unsigned chan, uint32_t *data28);
  6271. +extern int /*rc*/ bcm_mailbox_write(unsigned chan, uint32_t data28);
  6272. +extern int /*rc*/ bcm_mailbox_property(void *data, int size);
  6273. +
  6274. +#include <linux/ioctl.h>
  6275. +
  6276. +/*
  6277. + * The major device number. We can't rely on dynamic
  6278. + * registration any more, because ioctls need to know
  6279. + * it.
  6280. + */
  6281. +#define MAJOR_NUM 100
  6282. +
  6283. +/*
  6284. + * Set the message of the device driver
  6285. + */
  6286. +#define IOCTL_MBOX_PROPERTY _IOWR(MAJOR_NUM, 0, char *)
  6287. +/*
  6288. + * _IOWR means that we're creating an ioctl command
  6289. + * number for passing information from a user process
  6290. + * to the kernel module and from the kernel module to user process
  6291. + *
  6292. + * The first arguments, MAJOR_NUM, is the major device
  6293. + * number we're using.
  6294. + *
  6295. + * The second argument is the number of the command
  6296. + * (there could be several with different meanings).
  6297. + *
  6298. + * The third argument is the type we want to get from
  6299. + * the process to the kernel.
  6300. + */
  6301. +
  6302. +/*
  6303. + * The name of the device file
  6304. + */
  6305. +#define DEVICE_FILE_NAME "char_dev"
  6306. +
  6307. +#endif
  6308. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/include/mach/vc_mem.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_mem.h
  6309. --- linux-3.15.4/arch/arm/mach-bcm2708/include/mach/vc_mem.h 1970-01-01 01:00:00.000000000 +0100
  6310. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_mem.h 2014-07-07 10:44:57.000000000 +0200
  6311. @@ -0,0 +1,35 @@
  6312. +/*****************************************************************************
  6313. +* Copyright 2010 - 2011 Broadcom Corporation. All rights reserved.
  6314. +*
  6315. +* Unless you and Broadcom execute a separate written software license
  6316. +* agreement governing use of this software, this software is licensed to you
  6317. +* under the terms of the GNU General Public License version 2, available at
  6318. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  6319. +*
  6320. +* Notwithstanding the above, under no circumstances may you combine this
  6321. +* software in any way with any other Broadcom software provided under a
  6322. +* license other than the GPL, without Broadcom's express prior written
  6323. +* consent.
  6324. +*****************************************************************************/
  6325. +
  6326. +#if !defined( VC_MEM_H )
  6327. +#define VC_MEM_H
  6328. +
  6329. +#include <linux/ioctl.h>
  6330. +
  6331. +#define VC_MEM_IOC_MAGIC 'v'
  6332. +
  6333. +#define VC_MEM_IOC_MEM_PHYS_ADDR _IOR( VC_MEM_IOC_MAGIC, 0, unsigned long )
  6334. +#define VC_MEM_IOC_MEM_SIZE _IOR( VC_MEM_IOC_MAGIC, 1, unsigned int )
  6335. +#define VC_MEM_IOC_MEM_BASE _IOR( VC_MEM_IOC_MAGIC, 2, unsigned int )
  6336. +#define VC_MEM_IOC_MEM_LOAD _IOR( VC_MEM_IOC_MAGIC, 3, unsigned int )
  6337. +
  6338. +#if defined( __KERNEL__ )
  6339. +#define VC_MEM_TO_ARM_ADDR_MASK 0x3FFFFFFF
  6340. +
  6341. +extern unsigned long mm_vc_mem_phys_addr;
  6342. +extern unsigned int mm_vc_mem_size;
  6343. +extern int vc_mem_get_current_size( void );
  6344. +#endif
  6345. +
  6346. +#endif /* VC_MEM_H */
  6347. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/include/mach/vmalloc.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vmalloc.h
  6348. --- linux-3.15.4/arch/arm/mach-bcm2708/include/mach/vmalloc.h 1970-01-01 01:00:00.000000000 +0100
  6349. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vmalloc.h 2014-04-13 17:32:40.000000000 +0200
  6350. @@ -0,0 +1,20 @@
  6351. +/*
  6352. + * arch/arm/mach-bcm2708/include/mach/vmalloc.h
  6353. + *
  6354. + * Copyright (C) 2010 Broadcom
  6355. + *
  6356. + * This program is free software; you can redistribute it and/or modify
  6357. + * it under the terms of the GNU General Public License as published by
  6358. + * the Free Software Foundation; either version 2 of the License, or
  6359. + * (at your option) any later version.
  6360. + *
  6361. + * This program is distributed in the hope that it will be useful,
  6362. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6363. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6364. + * GNU General Public License for more details.
  6365. + *
  6366. + * You should have received a copy of the GNU General Public License
  6367. + * along with this program; if not, write to the Free Software
  6368. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6369. + */
  6370. +#define VMALLOC_END (0xe8000000)
  6371. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/Kconfig linux-rpi/arch/arm/mach-bcm2708/Kconfig
  6372. --- linux-3.15.4/arch/arm/mach-bcm2708/Kconfig 1970-01-01 01:00:00.000000000 +0100
  6373. +++ linux-rpi/arch/arm/mach-bcm2708/Kconfig 2014-07-07 10:44:57.000000000 +0200
  6374. @@ -0,0 +1,41 @@
  6375. +menu "Broadcom BCM2708 Implementations"
  6376. + depends on ARCH_BCM2708
  6377. +
  6378. +config MACH_BCM2708
  6379. + bool "Broadcom BCM2708 Development Platform"
  6380. + select NEED_MACH_MEMORY_H
  6381. + select NEED_MACH_IO_H
  6382. + select CPU_V6
  6383. + help
  6384. + Include support for the Broadcom(R) BCM2708 platform.
  6385. +
  6386. +config BCM2708_GPIO
  6387. + bool "BCM2708 gpio support"
  6388. + depends on MACH_BCM2708
  6389. + select ARCH_REQUIRE_GPIOLIB
  6390. + default y
  6391. + help
  6392. + Include support for the Broadcom(R) BCM2708 gpio.
  6393. +
  6394. +config BCM2708_VCMEM
  6395. + bool "Videocore Memory"
  6396. + depends on MACH_BCM2708
  6397. + default y
  6398. + help
  6399. + Helper for videocore memory access and total size allocation.
  6400. +
  6401. +config BCM2708_NOL2CACHE
  6402. + bool "Videocore L2 cache disable"
  6403. + depends on MACH_BCM2708
  6404. + default n
  6405. + help
  6406. + Do not allow ARM to use GPU's L2 cache. Requires disable_l2cache in config.txt.
  6407. +
  6408. +config BCM2708_SPIDEV
  6409. + bool "Bind spidev to SPI0 master"
  6410. + depends on MACH_BCM2708
  6411. + depends on SPI
  6412. + default y
  6413. + help
  6414. + Binds spidev driver to the SPI0 master
  6415. +endmenu
  6416. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/Makefile linux-rpi/arch/arm/mach-bcm2708/Makefile
  6417. --- linux-3.15.4/arch/arm/mach-bcm2708/Makefile 1970-01-01 01:00:00.000000000 +0100
  6418. +++ linux-rpi/arch/arm/mach-bcm2708/Makefile 2014-07-07 10:44:57.000000000 +0200
  6419. @@ -0,0 +1,7 @@
  6420. +#
  6421. +# Makefile for the linux kernel.
  6422. +#
  6423. +
  6424. +obj-$(CONFIG_MACH_BCM2708) += clock.o bcm2708.o armctrl.o vcio.o power.o dma.o
  6425. +obj-$(CONFIG_BCM2708_GPIO) += bcm2708_gpio.o
  6426. +obj-$(CONFIG_BCM2708_VCMEM) += vc_mem.o
  6427. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/Makefile.boot linux-rpi/arch/arm/mach-bcm2708/Makefile.boot
  6428. --- linux-3.15.4/arch/arm/mach-bcm2708/Makefile.boot 1970-01-01 01:00:00.000000000 +0100
  6429. +++ linux-rpi/arch/arm/mach-bcm2708/Makefile.boot 2014-04-13 17:32:40.000000000 +0200
  6430. @@ -0,0 +1,3 @@
  6431. + zreladdr-y := 0x00008000
  6432. +params_phys-y := 0x00000100
  6433. +initrd_phys-y := 0x00800000
  6434. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/power.c linux-rpi/arch/arm/mach-bcm2708/power.c
  6435. --- linux-3.15.4/arch/arm/mach-bcm2708/power.c 1970-01-01 01:00:00.000000000 +0100
  6436. +++ linux-rpi/arch/arm/mach-bcm2708/power.c 2014-04-13 17:32:40.000000000 +0200
  6437. @@ -0,0 +1,194 @@
  6438. +/*
  6439. + * linux/arch/arm/mach-bcm2708/power.c
  6440. + *
  6441. + * Copyright (C) 2010 Broadcom
  6442. + *
  6443. + * This program is free software; you can redistribute it and/or modify
  6444. + * it under the terms of the GNU General Public License version 2 as
  6445. + * published by the Free Software Foundation.
  6446. + *
  6447. + * This device provides a shared mechanism for controlling the power to
  6448. + * VideoCore subsystems.
  6449. + */
  6450. +
  6451. +#include <linux/module.h>
  6452. +#include <linux/semaphore.h>
  6453. +#include <linux/bug.h>
  6454. +#include <mach/power.h>
  6455. +#include <mach/vcio.h>
  6456. +#include <mach/arm_power.h>
  6457. +
  6458. +#define DRIVER_NAME "bcm2708_power"
  6459. +
  6460. +#define BCM_POWER_MAXCLIENTS 4
  6461. +#define BCM_POWER_NOCLIENT (1<<31)
  6462. +
  6463. +/* Some drivers expect there devices to be permanently powered */
  6464. +#define BCM_POWER_ALWAYS_ON (BCM_POWER_USB)
  6465. +
  6466. +#if 1
  6467. +#define DPRINTK printk
  6468. +#else
  6469. +#define DPRINTK if (0) printk
  6470. +#endif
  6471. +
  6472. +struct state_struct {
  6473. + uint32_t global_request;
  6474. + uint32_t client_request[BCM_POWER_MAXCLIENTS];
  6475. + struct semaphore client_mutex;
  6476. + struct semaphore mutex;
  6477. +} g_state;
  6478. +
  6479. +int bcm_power_open(BCM_POWER_HANDLE_T *handle)
  6480. +{
  6481. + BCM_POWER_HANDLE_T i;
  6482. + int ret = -EBUSY;
  6483. +
  6484. + down(&g_state.client_mutex);
  6485. +
  6486. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) {
  6487. + if (g_state.client_request[i] == BCM_POWER_NOCLIENT) {
  6488. + g_state.client_request[i] = BCM_POWER_NONE;
  6489. + *handle = i;
  6490. + ret = 0;
  6491. + break;
  6492. + }
  6493. + }
  6494. +
  6495. + up(&g_state.client_mutex);
  6496. +
  6497. + DPRINTK("bcm_power_open() -> %d\n", *handle);
  6498. +
  6499. + return ret;
  6500. +}
  6501. +EXPORT_SYMBOL_GPL(bcm_power_open);
  6502. +
  6503. +int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request)
  6504. +{
  6505. + int rc = 0;
  6506. +
  6507. + DPRINTK("bcm_power_request(%d, %x)\n", handle, request);
  6508. +
  6509. + if ((handle < BCM_POWER_MAXCLIENTS) &&
  6510. + (g_state.client_request[handle] != BCM_POWER_NOCLIENT)) {
  6511. + if (down_interruptible(&g_state.mutex) != 0) {
  6512. + DPRINTK("bcm_power_request -> interrupted\n");
  6513. + return -EINTR;
  6514. + }
  6515. +
  6516. + if (request != g_state.client_request[handle]) {
  6517. + uint32_t others_request = 0;
  6518. + uint32_t global_request;
  6519. + BCM_POWER_HANDLE_T i;
  6520. +
  6521. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) {
  6522. + if (i != handle)
  6523. + others_request |=
  6524. + g_state.client_request[i];
  6525. + }
  6526. + others_request &= ~BCM_POWER_NOCLIENT;
  6527. +
  6528. + global_request = request | others_request;
  6529. + if (global_request != g_state.global_request) {
  6530. + uint32_t actual;
  6531. +
  6532. + /* Send a request to VideoCore */
  6533. + bcm_mailbox_write(MBOX_CHAN_POWER,
  6534. + global_request << 4);
  6535. +
  6536. + /* Wait for a response during power-up */
  6537. + if (global_request & ~g_state.global_request) {
  6538. + rc = bcm_mailbox_read(MBOX_CHAN_POWER,
  6539. + &actual);
  6540. + DPRINTK
  6541. + ("bcm_mailbox_read -> %08x, %d\n",
  6542. + actual, rc);
  6543. + actual >>= 4;
  6544. + } else {
  6545. + rc = 0;
  6546. + actual = global_request;
  6547. + }
  6548. +
  6549. + if (rc == 0) {
  6550. + if (actual != global_request) {
  6551. + printk(KERN_ERR
  6552. + "%s: prev global %x, new global %x, actual %x, request %x, others_request %x\n",
  6553. + __func__,
  6554. + g_state.global_request,
  6555. + global_request, actual, request, others_request);
  6556. + /* A failure */
  6557. + BUG_ON((others_request & actual)
  6558. + != others_request);
  6559. + request &= actual;
  6560. + rc = -EIO;
  6561. + }
  6562. +
  6563. + g_state.global_request = actual;
  6564. + g_state.client_request[handle] =
  6565. + request;
  6566. + }
  6567. + }
  6568. + }
  6569. + up(&g_state.mutex);
  6570. + } else {
  6571. + rc = -EINVAL;
  6572. + }
  6573. + DPRINTK("bcm_power_request -> %d\n", rc);
  6574. + return rc;
  6575. +}
  6576. +EXPORT_SYMBOL_GPL(bcm_power_request);
  6577. +
  6578. +int bcm_power_close(BCM_POWER_HANDLE_T handle)
  6579. +{
  6580. + int rc;
  6581. +
  6582. + DPRINTK("bcm_power_close(%d)\n", handle);
  6583. +
  6584. + rc = bcm_power_request(handle, BCM_POWER_NONE);
  6585. + if (rc == 0)
  6586. + g_state.client_request[handle] = BCM_POWER_NOCLIENT;
  6587. +
  6588. + return rc;
  6589. +}
  6590. +EXPORT_SYMBOL_GPL(bcm_power_close);
  6591. +
  6592. +static int __init bcm_power_init(void)
  6593. +{
  6594. +#if defined(BCM_POWER_ALWAYS_ON)
  6595. + BCM_POWER_HANDLE_T always_on_handle;
  6596. +#endif
  6597. + int rc = 0;
  6598. + int i;
  6599. +
  6600. + printk(KERN_INFO "bcm_power: Broadcom power driver\n");
  6601. + bcm_mailbox_write(MBOX_CHAN_POWER, 0);
  6602. +
  6603. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++)
  6604. + g_state.client_request[i] = BCM_POWER_NOCLIENT;
  6605. +
  6606. + sema_init(&g_state.client_mutex, 1);
  6607. + sema_init(&g_state.mutex, 1);
  6608. +
  6609. + g_state.global_request = 0;
  6610. +
  6611. +#if defined(BCM_POWER_ALWAYS_ON)
  6612. + if (BCM_POWER_ALWAYS_ON) {
  6613. + bcm_power_open(&always_on_handle);
  6614. + bcm_power_request(always_on_handle, BCM_POWER_ALWAYS_ON);
  6615. + }
  6616. +#endif
  6617. +
  6618. + return rc;
  6619. +}
  6620. +
  6621. +static void __exit bcm_power_exit(void)
  6622. +{
  6623. + bcm_mailbox_write(MBOX_CHAN_POWER, 0);
  6624. +}
  6625. +
  6626. +arch_initcall(bcm_power_init); /* Initialize early */
  6627. +module_exit(bcm_power_exit);
  6628. +
  6629. +MODULE_AUTHOR("Phil Elwell");
  6630. +MODULE_DESCRIPTION("Interface to BCM2708 power management");
  6631. +MODULE_LICENSE("GPL");
  6632. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/vcio.c linux-rpi/arch/arm/mach-bcm2708/vcio.c
  6633. --- linux-3.15.4/arch/arm/mach-bcm2708/vcio.c 1970-01-01 01:00:00.000000000 +0100
  6634. +++ linux-rpi/arch/arm/mach-bcm2708/vcio.c 2014-07-07 10:44:57.000000000 +0200
  6635. @@ -0,0 +1,474 @@
  6636. +/*
  6637. + * linux/arch/arm/mach-bcm2708/vcio.c
  6638. + *
  6639. + * Copyright (C) 2010 Broadcom
  6640. + *
  6641. + * This program is free software; you can redistribute it and/or modify
  6642. + * it under the terms of the GNU General Public License version 2 as
  6643. + * published by the Free Software Foundation.
  6644. + *
  6645. + * This device provides a shared mechanism for writing to the mailboxes,
  6646. + * semaphores, doorbells etc. that are shared between the ARM and the
  6647. + * VideoCore processor
  6648. + */
  6649. +
  6650. +#if defined(CONFIG_SERIAL_BCM_MBOX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  6651. +#define SUPPORT_SYSRQ
  6652. +#endif
  6653. +
  6654. +#include <linux/module.h>
  6655. +#include <linux/console.h>
  6656. +#include <linux/serial_core.h>
  6657. +#include <linux/serial.h>
  6658. +#include <linux/errno.h>
  6659. +#include <linux/device.h>
  6660. +#include <linux/init.h>
  6661. +#include <linux/mm.h>
  6662. +#include <linux/dma-mapping.h>
  6663. +#include <linux/platform_device.h>
  6664. +#include <linux/sysrq.h>
  6665. +#include <linux/delay.h>
  6666. +#include <linux/slab.h>
  6667. +#include <linux/interrupt.h>
  6668. +#include <linux/irq.h>
  6669. +
  6670. +#include <linux/io.h>
  6671. +
  6672. +#include <mach/vcio.h>
  6673. +#include <mach/platform.h>
  6674. +
  6675. +#include <asm/uaccess.h>
  6676. +
  6677. +
  6678. +#define DRIVER_NAME BCM_VCIO_DRIVER_NAME
  6679. +
  6680. +/* ----------------------------------------------------------------------
  6681. + * Mailbox
  6682. + * -------------------------------------------------------------------- */
  6683. +
  6684. +/* offsets from a mail box base address */
  6685. +#define MAIL_WRT 0x00 /* write - and next 4 words */
  6686. +#define MAIL_RD 0x00 /* read - and next 4 words */
  6687. +#define MAIL_POL 0x10 /* read without popping the fifo */
  6688. +#define MAIL_SND 0x14 /* sender ID (bottom two bits) */
  6689. +#define MAIL_STA 0x18 /* status */
  6690. +#define MAIL_CNF 0x1C /* configuration */
  6691. +
  6692. +#define MBOX_MSG(chan, data28) (((data28) & ~0xf) | ((chan) & 0xf))
  6693. +#define MBOX_MSG_LSB(chan, data28) (((data28) << 4) | ((chan) & 0xf))
  6694. +#define MBOX_CHAN(msg) ((msg) & 0xf)
  6695. +#define MBOX_DATA28(msg) ((msg) & ~0xf)
  6696. +#define MBOX_DATA28_LSB(msg) (((uint32_t)msg) >> 4)
  6697. +
  6698. +#define MBOX_MAGIC 0xd0d0c0de
  6699. +
  6700. +struct vc_mailbox {
  6701. + struct device *dev; /* parent device */
  6702. + void __iomem *status;
  6703. + void __iomem *config;
  6704. + void __iomem *read;
  6705. + void __iomem *write;
  6706. + uint32_t msg[MBOX_CHAN_COUNT];
  6707. + struct semaphore sema[MBOX_CHAN_COUNT];
  6708. + uint32_t magic;
  6709. +};
  6710. +
  6711. +static void mbox_init(struct vc_mailbox *mbox_out, struct device *dev,
  6712. + uint32_t addr_mbox)
  6713. +{
  6714. + int i;
  6715. +
  6716. + mbox_out->dev = dev;
  6717. + mbox_out->status = __io_address(addr_mbox + MAIL_STA);
  6718. + mbox_out->config = __io_address(addr_mbox + MAIL_CNF);
  6719. + mbox_out->read = __io_address(addr_mbox + MAIL_RD);
  6720. + /* Write to the other mailbox */
  6721. + mbox_out->write =
  6722. + __io_address((addr_mbox ^ ARM_0_MAIL0_WRT ^ ARM_0_MAIL1_WRT) +
  6723. + MAIL_WRT);
  6724. +
  6725. + for (i = 0; i < MBOX_CHAN_COUNT; i++) {
  6726. + mbox_out->msg[i] = 0;
  6727. + sema_init(&mbox_out->sema[i], 0);
  6728. + }
  6729. +
  6730. + /* Enable the interrupt on data reception */
  6731. + writel(ARM_MC_IHAVEDATAIRQEN, mbox_out->config);
  6732. +
  6733. + mbox_out->magic = MBOX_MAGIC;
  6734. +}
  6735. +
  6736. +static int mbox_write(struct vc_mailbox *mbox, unsigned chan, uint32_t data28)
  6737. +{
  6738. + int rc;
  6739. +
  6740. + if (mbox->magic != MBOX_MAGIC)
  6741. + rc = -EINVAL;
  6742. + else {
  6743. + /* wait for the mailbox FIFO to have some space in it */
  6744. + while (0 != (readl(mbox->status) & ARM_MS_FULL))
  6745. + cpu_relax();
  6746. +
  6747. + writel(MBOX_MSG(chan, data28), mbox->write);
  6748. + rc = 0;
  6749. + }
  6750. + return rc;
  6751. +}
  6752. +
  6753. +static int mbox_read(struct vc_mailbox *mbox, unsigned chan, uint32_t *data28)
  6754. +{
  6755. + int rc;
  6756. +
  6757. + if (mbox->magic != MBOX_MAGIC)
  6758. + rc = -EINVAL;
  6759. + else {
  6760. + down(&mbox->sema[chan]);
  6761. + *data28 = MBOX_DATA28(mbox->msg[chan]);
  6762. + mbox->msg[chan] = 0;
  6763. + rc = 0;
  6764. + }
  6765. + return rc;
  6766. +}
  6767. +
  6768. +static irqreturn_t mbox_irq(int irq, void *dev_id)
  6769. +{
  6770. + /* wait for the mailbox FIFO to have some data in it */
  6771. + struct vc_mailbox *mbox = (struct vc_mailbox *) dev_id;
  6772. + int status = readl(mbox->status);
  6773. + int ret = IRQ_NONE;
  6774. +
  6775. + while (!(status & ARM_MS_EMPTY)) {
  6776. + uint32_t msg = readl(mbox->read);
  6777. + int chan = MBOX_CHAN(msg);
  6778. + if (chan < MBOX_CHAN_COUNT) {
  6779. + if (mbox->msg[chan]) {
  6780. + /* Overflow */
  6781. + printk(KERN_ERR DRIVER_NAME
  6782. + ": mbox chan %d overflow - drop %08x\n",
  6783. + chan, msg);
  6784. + } else {
  6785. + mbox->msg[chan] = (msg | 0xf);
  6786. + up(&mbox->sema[chan]);
  6787. + }
  6788. + } else {
  6789. + printk(KERN_ERR DRIVER_NAME
  6790. + ": invalid channel selector (msg %08x)\n", msg);
  6791. + }
  6792. + ret = IRQ_HANDLED;
  6793. + status = readl(mbox->status);
  6794. + }
  6795. + return ret;
  6796. +}
  6797. +
  6798. +static struct irqaction mbox_irqaction = {
  6799. + .name = "ARM Mailbox IRQ",
  6800. + .flags = IRQF_DISABLED | IRQF_IRQPOLL,
  6801. + .handler = mbox_irq,
  6802. +};
  6803. +
  6804. +/* ----------------------------------------------------------------------
  6805. + * Mailbox Methods
  6806. + * -------------------------------------------------------------------- */
  6807. +
  6808. +static struct device *mbox_dev; /* we assume there's only one! */
  6809. +
  6810. +static int dev_mbox_write(struct device *dev, unsigned chan, uint32_t data28)
  6811. +{
  6812. + int rc;
  6813. +
  6814. + struct vc_mailbox *mailbox = dev_get_drvdata(dev);
  6815. + device_lock(dev);
  6816. + rc = mbox_write(mailbox, chan, data28);
  6817. + device_unlock(dev);
  6818. +
  6819. + return rc;
  6820. +}
  6821. +
  6822. +static int dev_mbox_read(struct device *dev, unsigned chan, uint32_t *data28)
  6823. +{
  6824. + int rc;
  6825. +
  6826. + struct vc_mailbox *mailbox = dev_get_drvdata(dev);
  6827. + device_lock(dev);
  6828. + rc = mbox_read(mailbox, chan, data28);
  6829. + device_unlock(dev);
  6830. +
  6831. + return rc;
  6832. +}
  6833. +
  6834. +extern int bcm_mailbox_write(unsigned chan, uint32_t data28)
  6835. +{
  6836. + if (mbox_dev)
  6837. + return dev_mbox_write(mbox_dev, chan, data28);
  6838. + else
  6839. + return -ENODEV;
  6840. +}
  6841. +EXPORT_SYMBOL_GPL(bcm_mailbox_write);
  6842. +
  6843. +extern int bcm_mailbox_read(unsigned chan, uint32_t *data28)
  6844. +{
  6845. + if (mbox_dev)
  6846. + return dev_mbox_read(mbox_dev, chan, data28);
  6847. + else
  6848. + return -ENODEV;
  6849. +}
  6850. +EXPORT_SYMBOL_GPL(bcm_mailbox_read);
  6851. +
  6852. +static void dev_mbox_register(const char *dev_name, struct device *dev)
  6853. +{
  6854. + mbox_dev = dev;
  6855. +}
  6856. +
  6857. +static int mbox_copy_from_user(void *dst, const void *src, int size)
  6858. +{
  6859. + if ( (uint32_t)src < TASK_SIZE)
  6860. + {
  6861. + return copy_from_user(dst, src, size);
  6862. + }
  6863. + else
  6864. + {
  6865. + memcpy( dst, src, size );
  6866. + return 0;
  6867. + }
  6868. +}
  6869. +
  6870. +static int mbox_copy_to_user(void *dst, const void *src, int size)
  6871. +{
  6872. + if ( (uint32_t)dst < TASK_SIZE)
  6873. + {
  6874. + return copy_to_user(dst, src, size);
  6875. + }
  6876. + else
  6877. + {
  6878. + memcpy( dst, src, size );
  6879. + return 0;
  6880. + }
  6881. +}
  6882. +
  6883. +static DEFINE_MUTEX(mailbox_lock);
  6884. +extern int bcm_mailbox_property(void *data, int size)
  6885. +{
  6886. + uint32_t success;
  6887. + dma_addr_t mem_bus; /* the memory address accessed from videocore */
  6888. + void *mem_kern; /* the memory address accessed from driver */
  6889. + int s = 0;
  6890. +
  6891. + mutex_lock(&mailbox_lock);
  6892. + /* allocate some memory for the messages communicating with GPU */
  6893. + mem_kern = dma_alloc_coherent(NULL, PAGE_ALIGN(size), &mem_bus, GFP_ATOMIC);
  6894. + if (mem_kern) {
  6895. + /* create the message */
  6896. + mbox_copy_from_user(mem_kern, data, size);
  6897. +
  6898. + /* send the message */
  6899. + wmb();
  6900. + s = bcm_mailbox_write(MBOX_CHAN_PROPERTY, (uint32_t)mem_bus);
  6901. + if (s == 0) {
  6902. + s = bcm_mailbox_read(MBOX_CHAN_PROPERTY, &success);
  6903. + }
  6904. + if (s == 0) {
  6905. + /* copy the response */
  6906. + rmb();
  6907. + mbox_copy_to_user(data, mem_kern, size);
  6908. + }
  6909. + dma_free_coherent(NULL, PAGE_ALIGN(size), mem_kern, mem_bus);
  6910. + } else {
  6911. + s = -ENOMEM;
  6912. + }
  6913. + if (s != 0)
  6914. + printk(KERN_ERR DRIVER_NAME ": %s failed (%d)\n", __func__, s);
  6915. +
  6916. + mutex_unlock(&mailbox_lock);
  6917. + return s;
  6918. +}
  6919. +EXPORT_SYMBOL_GPL(bcm_mailbox_property);
  6920. +
  6921. +/* ----------------------------------------------------------------------
  6922. + * Platform Device for Mailbox
  6923. + * -------------------------------------------------------------------- */
  6924. +
  6925. +/*
  6926. + * Is the device open right now? Used to prevent
  6927. + * concurent access into the same device
  6928. + */
  6929. +static int Device_Open = 0;
  6930. +
  6931. +/*
  6932. + * This is called whenever a process attempts to open the device file
  6933. + */
  6934. +static int device_open(struct inode *inode, struct file *file)
  6935. +{
  6936. + /*
  6937. + * We don't want to talk to two processes at the same time
  6938. + */
  6939. + if (Device_Open)
  6940. + return -EBUSY;
  6941. +
  6942. + Device_Open++;
  6943. + /*
  6944. + * Initialize the message
  6945. + */
  6946. + try_module_get(THIS_MODULE);
  6947. + return 0;
  6948. +}
  6949. +
  6950. +static int device_release(struct inode *inode, struct file *file)
  6951. +{
  6952. + /*
  6953. + * We're now ready for our next caller
  6954. + */
  6955. + Device_Open--;
  6956. +
  6957. + module_put(THIS_MODULE);
  6958. + return 0;
  6959. +}
  6960. +
  6961. +/*
  6962. + * This function is called whenever a process tries to do an ioctl on our
  6963. + * device file. We get two extra parameters (additional to the inode and file
  6964. + * structures, which all device functions get): the number of the ioctl called
  6965. + * and the parameter given to the ioctl function.
  6966. + *
  6967. + * If the ioctl is write or read/write (meaning output is returned to the
  6968. + * calling process), the ioctl call returns the output of this function.
  6969. + *
  6970. + */
  6971. +static long device_ioctl(struct file *file, /* see include/linux/fs.h */
  6972. + unsigned int ioctl_num, /* number and param for ioctl */
  6973. + unsigned long ioctl_param)
  6974. +{
  6975. + unsigned size;
  6976. + /*
  6977. + * Switch according to the ioctl called
  6978. + */
  6979. + switch (ioctl_num) {
  6980. + case IOCTL_MBOX_PROPERTY:
  6981. + /*
  6982. + * Receive a pointer to a message (in user space) and set that
  6983. + * to be the device's message. Get the parameter given to
  6984. + * ioctl by the process.
  6985. + */
  6986. + mbox_copy_from_user(&size, (void *)ioctl_param, sizeof size);
  6987. + return bcm_mailbox_property((void *)ioctl_param, size);
  6988. + break;
  6989. + default:
  6990. + printk(KERN_ERR DRIVER_NAME "unknown ioctl: %d\n", ioctl_num);
  6991. + return -EINVAL;
  6992. + }
  6993. +
  6994. + return 0;
  6995. +}
  6996. +
  6997. +/* Module Declarations */
  6998. +
  6999. +/*
  7000. + * This structure will hold the functions to be called
  7001. + * when a process does something to the device we
  7002. + * created. Since a pointer to this structure is kept in
  7003. + * the devices table, it can't be local to
  7004. + * init_module. NULL is for unimplemented functios.
  7005. + */
  7006. +struct file_operations fops = {
  7007. + .unlocked_ioctl = device_ioctl,
  7008. + .open = device_open,
  7009. + .release = device_release, /* a.k.a. close */
  7010. +};
  7011. +
  7012. +static int bcm_vcio_probe(struct platform_device *pdev)
  7013. +{
  7014. + int ret = 0;
  7015. + struct vc_mailbox *mailbox;
  7016. +
  7017. + mailbox = kzalloc(sizeof(*mailbox), GFP_KERNEL);
  7018. + if (NULL == mailbox) {
  7019. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  7020. + "mailbox memory\n");
  7021. + ret = -ENOMEM;
  7022. + } else {
  7023. + struct resource *res;
  7024. +
  7025. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  7026. + if (res == NULL) {
  7027. + printk(KERN_ERR DRIVER_NAME ": failed to obtain memory "
  7028. + "resource\n");
  7029. + ret = -ENODEV;
  7030. + kfree(mailbox);
  7031. + } else {
  7032. + /* should be based on the registers from res really */
  7033. + mbox_init(mailbox, &pdev->dev, ARM_0_MAIL0_RD);
  7034. +
  7035. + platform_set_drvdata(pdev, mailbox);
  7036. + dev_mbox_register(DRIVER_NAME, &pdev->dev);
  7037. +
  7038. + mbox_irqaction.dev_id = mailbox;
  7039. + setup_irq(IRQ_ARM_MAILBOX, &mbox_irqaction);
  7040. + printk(KERN_INFO DRIVER_NAME ": mailbox at %p\n",
  7041. + __io_address(ARM_0_MAIL0_RD));
  7042. + }
  7043. + }
  7044. +
  7045. + if (ret == 0) {
  7046. + /*
  7047. + * Register the character device
  7048. + */
  7049. + ret = register_chrdev(MAJOR_NUM, DEVICE_FILE_NAME, &fops);
  7050. +
  7051. + /*
  7052. + * Negative values signify an error
  7053. + */
  7054. + if (ret < 0) {
  7055. + printk(KERN_ERR DRIVER_NAME
  7056. + "Failed registering the character device %d\n", ret);
  7057. + return ret;
  7058. + }
  7059. + }
  7060. + return ret;
  7061. +}
  7062. +
  7063. +static int bcm_vcio_remove(struct platform_device *pdev)
  7064. +{
  7065. + struct vc_mailbox *mailbox = platform_get_drvdata(pdev);
  7066. +
  7067. + platform_set_drvdata(pdev, NULL);
  7068. + kfree(mailbox);
  7069. +
  7070. + return 0;
  7071. +}
  7072. +
  7073. +static struct platform_driver bcm_mbox_driver = {
  7074. + .probe = bcm_vcio_probe,
  7075. + .remove = bcm_vcio_remove,
  7076. +
  7077. + .driver = {
  7078. + .name = DRIVER_NAME,
  7079. + .owner = THIS_MODULE,
  7080. + },
  7081. +};
  7082. +
  7083. +static int __init bcm_mbox_init(void)
  7084. +{
  7085. + int ret;
  7086. +
  7087. + printk(KERN_INFO "mailbox: Broadcom VideoCore Mailbox driver\n");
  7088. +
  7089. + ret = platform_driver_register(&bcm_mbox_driver);
  7090. + if (ret != 0) {
  7091. + printk(KERN_ERR DRIVER_NAME ": failed to register "
  7092. + "on platform\n");
  7093. + }
  7094. +
  7095. + return ret;
  7096. +}
  7097. +
  7098. +static void __exit bcm_mbox_exit(void)
  7099. +{
  7100. + platform_driver_unregister(&bcm_mbox_driver);
  7101. +}
  7102. +
  7103. +arch_initcall(bcm_mbox_init); /* Initialize early */
  7104. +module_exit(bcm_mbox_exit);
  7105. +
  7106. +MODULE_AUTHOR("Gray Girling");
  7107. +MODULE_DESCRIPTION("ARM I/O to VideoCore processor");
  7108. +MODULE_LICENSE("GPL");
  7109. +MODULE_ALIAS("platform:bcm-mbox");
  7110. diff -Nur linux-3.15.4/arch/arm/mach-bcm2708/vc_mem.c linux-rpi/arch/arm/mach-bcm2708/vc_mem.c
  7111. --- linux-3.15.4/arch/arm/mach-bcm2708/vc_mem.c 1970-01-01 01:00:00.000000000 +0100
  7112. +++ linux-rpi/arch/arm/mach-bcm2708/vc_mem.c 2014-04-13 17:32:40.000000000 +0200
  7113. @@ -0,0 +1,432 @@
  7114. +/*****************************************************************************
  7115. +* Copyright 2010 - 2011 Broadcom Corporation. All rights reserved.
  7116. +*
  7117. +* Unless you and Broadcom execute a separate written software license
  7118. +* agreement governing use of this software, this software is licensed to you
  7119. +* under the terms of the GNU General Public License version 2, available at
  7120. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  7121. +*
  7122. +* Notwithstanding the above, under no circumstances may you combine this
  7123. +* software in any way with any other Broadcom software provided under a
  7124. +* license other than the GPL, without Broadcom's express prior written
  7125. +* consent.
  7126. +*****************************************************************************/
  7127. +
  7128. +#include <linux/kernel.h>
  7129. +#include <linux/module.h>
  7130. +#include <linux/fs.h>
  7131. +#include <linux/device.h>
  7132. +#include <linux/cdev.h>
  7133. +#include <linux/mm.h>
  7134. +#include <linux/slab.h>
  7135. +#include <linux/debugfs.h>
  7136. +#include <asm/uaccess.h>
  7137. +#include <linux/dma-mapping.h>
  7138. +
  7139. +#ifdef CONFIG_ARCH_KONA
  7140. +#include <chal/chal_ipc.h>
  7141. +#elif CONFIG_ARCH_BCM2708
  7142. +#else
  7143. +#include <csp/chal_ipc.h>
  7144. +#endif
  7145. +
  7146. +#include "mach/vc_mem.h"
  7147. +#include <mach/vcio.h>
  7148. +
  7149. +#define DRIVER_NAME "vc-mem"
  7150. +
  7151. +// Device (/dev) related variables
  7152. +static dev_t vc_mem_devnum = 0;
  7153. +static struct class *vc_mem_class = NULL;
  7154. +static struct cdev vc_mem_cdev;
  7155. +static int vc_mem_inited = 0;
  7156. +
  7157. +#ifdef CONFIG_DEBUG_FS
  7158. +static struct dentry *vc_mem_debugfs_entry;
  7159. +#endif
  7160. +
  7161. +/*
  7162. + * Videocore memory addresses and size
  7163. + *
  7164. + * Drivers that wish to know the videocore memory addresses and sizes should
  7165. + * use these variables instead of the MM_IO_BASE and MM_ADDR_IO defines in
  7166. + * headers. This allows the other drivers to not be tied down to a a certain
  7167. + * address/size at compile time.
  7168. + *
  7169. + * In the future, the goal is to have the videocore memory virtual address and
  7170. + * size be calculated at boot time rather than at compile time. The decision of
  7171. + * where the videocore memory resides and its size would be in the hands of the
  7172. + * bootloader (and/or kernel). When that happens, the values of these variables
  7173. + * would be calculated and assigned in the init function.
  7174. + */
  7175. +// in the 2835 VC in mapped above ARM, but ARM has full access to VC space
  7176. +unsigned long mm_vc_mem_phys_addr = 0x00000000;
  7177. +unsigned int mm_vc_mem_size = 0;
  7178. +unsigned int mm_vc_mem_base = 0;
  7179. +
  7180. +EXPORT_SYMBOL(mm_vc_mem_phys_addr);
  7181. +EXPORT_SYMBOL(mm_vc_mem_size);
  7182. +EXPORT_SYMBOL(mm_vc_mem_base);
  7183. +
  7184. +static uint phys_addr = 0;
  7185. +static uint mem_size = 0;
  7186. +static uint mem_base = 0;
  7187. +
  7188. +
  7189. +/****************************************************************************
  7190. +*
  7191. +* vc_mem_open
  7192. +*
  7193. +***************************************************************************/
  7194. +
  7195. +static int
  7196. +vc_mem_open(struct inode *inode, struct file *file)
  7197. +{
  7198. + (void) inode;
  7199. + (void) file;
  7200. +
  7201. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  7202. +
  7203. + return 0;
  7204. +}
  7205. +
  7206. +/****************************************************************************
  7207. +*
  7208. +* vc_mem_release
  7209. +*
  7210. +***************************************************************************/
  7211. +
  7212. +static int
  7213. +vc_mem_release(struct inode *inode, struct file *file)
  7214. +{
  7215. + (void) inode;
  7216. + (void) file;
  7217. +
  7218. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  7219. +
  7220. + return 0;
  7221. +}
  7222. +
  7223. +/****************************************************************************
  7224. +*
  7225. +* vc_mem_get_size
  7226. +*
  7227. +***************************************************************************/
  7228. +
  7229. +static void
  7230. +vc_mem_get_size(void)
  7231. +{
  7232. +}
  7233. +
  7234. +/****************************************************************************
  7235. +*
  7236. +* vc_mem_get_base
  7237. +*
  7238. +***************************************************************************/
  7239. +
  7240. +static void
  7241. +vc_mem_get_base(void)
  7242. +{
  7243. +}
  7244. +
  7245. +/****************************************************************************
  7246. +*
  7247. +* vc_mem_get_current_size
  7248. +*
  7249. +***************************************************************************/
  7250. +
  7251. +int
  7252. +vc_mem_get_current_size(void)
  7253. +{
  7254. + return mm_vc_mem_size;
  7255. +}
  7256. +
  7257. +EXPORT_SYMBOL_GPL(vc_mem_get_current_size);
  7258. +
  7259. +/****************************************************************************
  7260. +*
  7261. +* vc_mem_ioctl
  7262. +*
  7263. +***************************************************************************/
  7264. +
  7265. +static long
  7266. +vc_mem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  7267. +{
  7268. + int rc = 0;
  7269. +
  7270. + (void) cmd;
  7271. + (void) arg;
  7272. +
  7273. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  7274. +
  7275. + switch (cmd) {
  7276. + case VC_MEM_IOC_MEM_PHYS_ADDR:
  7277. + {
  7278. + pr_debug("%s: VC_MEM_IOC_MEM_PHYS_ADDR=0x%p\n",
  7279. + __func__, (void *) mm_vc_mem_phys_addr);
  7280. +
  7281. + if (copy_to_user((void *) arg, &mm_vc_mem_phys_addr,
  7282. + sizeof (mm_vc_mem_phys_addr)) != 0) {
  7283. + rc = -EFAULT;
  7284. + }
  7285. + break;
  7286. + }
  7287. + case VC_MEM_IOC_MEM_SIZE:
  7288. + {
  7289. + // Get the videocore memory size first
  7290. + vc_mem_get_size();
  7291. +
  7292. + pr_debug("%s: VC_MEM_IOC_MEM_SIZE=%u\n", __func__,
  7293. + mm_vc_mem_size);
  7294. +
  7295. + if (copy_to_user((void *) arg, &mm_vc_mem_size,
  7296. + sizeof (mm_vc_mem_size)) != 0) {
  7297. + rc = -EFAULT;
  7298. + }
  7299. + break;
  7300. + }
  7301. + case VC_MEM_IOC_MEM_BASE:
  7302. + {
  7303. + // Get the videocore memory base
  7304. + vc_mem_get_base();
  7305. +
  7306. + pr_debug("%s: VC_MEM_IOC_MEM_BASE=%u\n", __func__,
  7307. + mm_vc_mem_base);
  7308. +
  7309. + if (copy_to_user((void *) arg, &mm_vc_mem_base,
  7310. + sizeof (mm_vc_mem_base)) != 0) {
  7311. + rc = -EFAULT;
  7312. + }
  7313. + break;
  7314. + }
  7315. + case VC_MEM_IOC_MEM_LOAD:
  7316. + {
  7317. + // Get the videocore memory base
  7318. + vc_mem_get_base();
  7319. +
  7320. + pr_debug("%s: VC_MEM_IOC_MEM_LOAD=%u\n", __func__,
  7321. + mm_vc_mem_base);
  7322. +
  7323. + if (copy_to_user((void *) arg, &mm_vc_mem_base,
  7324. + sizeof (mm_vc_mem_base)) != 0) {
  7325. + rc = -EFAULT;
  7326. + }
  7327. + break;
  7328. + }
  7329. + default:
  7330. + {
  7331. + return -ENOTTY;
  7332. + }
  7333. + }
  7334. + pr_debug("%s: file = 0x%p returning %d\n", __func__, file, rc);
  7335. +
  7336. + return rc;
  7337. +}
  7338. +
  7339. +/****************************************************************************
  7340. +*
  7341. +* vc_mem_mmap
  7342. +*
  7343. +***************************************************************************/
  7344. +
  7345. +static int
  7346. +vc_mem_mmap(struct file *filp, struct vm_area_struct *vma)
  7347. +{
  7348. + int rc = 0;
  7349. + unsigned long length = vma->vm_end - vma->vm_start;
  7350. + unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
  7351. +
  7352. + pr_debug("%s: vm_start = 0x%08lx vm_end = 0x%08lx vm_pgoff = 0x%08lx\n",
  7353. + __func__, (long) vma->vm_start, (long) vma->vm_end,
  7354. + (long) vma->vm_pgoff);
  7355. +
  7356. + if (offset + length > mm_vc_mem_size) {
  7357. + pr_err("%s: length %ld is too big\n", __func__, length);
  7358. + return -EINVAL;
  7359. + }
  7360. + // Do not cache the memory map
  7361. + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  7362. +
  7363. + rc = remap_pfn_range(vma, vma->vm_start,
  7364. + (mm_vc_mem_phys_addr >> PAGE_SHIFT) +
  7365. + vma->vm_pgoff, length, vma->vm_page_prot);
  7366. + if (rc != 0) {
  7367. + pr_err("%s: remap_pfn_range failed (rc=%d)\n", __func__, rc);
  7368. + }
  7369. +
  7370. + return rc;
  7371. +}
  7372. +
  7373. +/****************************************************************************
  7374. +*
  7375. +* File Operations for the driver.
  7376. +*
  7377. +***************************************************************************/
  7378. +
  7379. +static const struct file_operations vc_mem_fops = {
  7380. + .owner = THIS_MODULE,
  7381. + .open = vc_mem_open,
  7382. + .release = vc_mem_release,
  7383. + .unlocked_ioctl = vc_mem_ioctl,
  7384. + .mmap = vc_mem_mmap,
  7385. +};
  7386. +
  7387. +#ifdef CONFIG_DEBUG_FS
  7388. +static void vc_mem_debugfs_deinit(void)
  7389. +{
  7390. + debugfs_remove_recursive(vc_mem_debugfs_entry);
  7391. + vc_mem_debugfs_entry = NULL;
  7392. +}
  7393. +
  7394. +
  7395. +static int vc_mem_debugfs_init(
  7396. + struct device *dev)
  7397. +{
  7398. + vc_mem_debugfs_entry = debugfs_create_dir(DRIVER_NAME, NULL);
  7399. + if (!vc_mem_debugfs_entry) {
  7400. + dev_warn(dev, "could not create debugfs entry\n");
  7401. + return -EFAULT;
  7402. + }
  7403. +
  7404. + if (!debugfs_create_x32("vc_mem_phys_addr",
  7405. + 0444,
  7406. + vc_mem_debugfs_entry,
  7407. + (u32 *)&mm_vc_mem_phys_addr)) {
  7408. + dev_warn(dev, "%s:could not create vc_mem_phys entry\n",
  7409. + __func__);
  7410. + goto fail;
  7411. + }
  7412. +
  7413. + if (!debugfs_create_x32("vc_mem_size",
  7414. + 0444,
  7415. + vc_mem_debugfs_entry,
  7416. + (u32 *)&mm_vc_mem_size)) {
  7417. + dev_warn(dev, "%s:could not create vc_mem_size entry\n",
  7418. + __func__);
  7419. + goto fail;
  7420. + }
  7421. +
  7422. + if (!debugfs_create_x32("vc_mem_base",
  7423. + 0444,
  7424. + vc_mem_debugfs_entry,
  7425. + (u32 *)&mm_vc_mem_base)) {
  7426. + dev_warn(dev, "%s:could not create vc_mem_base entry\n",
  7427. + __func__);
  7428. + goto fail;
  7429. + }
  7430. +
  7431. + return 0;
  7432. +
  7433. +fail:
  7434. + vc_mem_debugfs_deinit();
  7435. + return -EFAULT;
  7436. +}
  7437. +
  7438. +#endif /* CONFIG_DEBUG_FS */
  7439. +
  7440. +
  7441. +/****************************************************************************
  7442. +*
  7443. +* vc_mem_init
  7444. +*
  7445. +***************************************************************************/
  7446. +
  7447. +static int __init
  7448. +vc_mem_init(void)
  7449. +{
  7450. + int rc = -EFAULT;
  7451. + struct device *dev;
  7452. +
  7453. + pr_debug("%s: called\n", __func__);
  7454. +
  7455. + mm_vc_mem_phys_addr = phys_addr;
  7456. + mm_vc_mem_size = mem_size;
  7457. + mm_vc_mem_base = mem_base;
  7458. +
  7459. + vc_mem_get_size();
  7460. +
  7461. + pr_info("vc-mem: phys_addr:0x%08lx mem_base=0x%08x mem_size:0x%08x(%u MiB)\n",
  7462. + mm_vc_mem_phys_addr, mm_vc_mem_base, mm_vc_mem_size, mm_vc_mem_size / (1024 * 1024));
  7463. +
  7464. + if ((rc = alloc_chrdev_region(&vc_mem_devnum, 0, 1, DRIVER_NAME)) < 0) {
  7465. + pr_err("%s: alloc_chrdev_region failed (rc=%d)\n",
  7466. + __func__, rc);
  7467. + goto out_err;
  7468. + }
  7469. +
  7470. + cdev_init(&vc_mem_cdev, &vc_mem_fops);
  7471. + if ((rc = cdev_add(&vc_mem_cdev, vc_mem_devnum, 1)) != 0) {
  7472. + pr_err("%s: cdev_add failed (rc=%d)\n", __func__, rc);
  7473. + goto out_unregister;
  7474. + }
  7475. +
  7476. + vc_mem_class = class_create(THIS_MODULE, DRIVER_NAME);
  7477. + if (IS_ERR(vc_mem_class)) {
  7478. + rc = PTR_ERR(vc_mem_class);
  7479. + pr_err("%s: class_create failed (rc=%d)\n", __func__, rc);
  7480. + goto out_cdev_del;
  7481. + }
  7482. +
  7483. + dev = device_create(vc_mem_class, NULL, vc_mem_devnum, NULL,
  7484. + DRIVER_NAME);
  7485. + if (IS_ERR(dev)) {
  7486. + rc = PTR_ERR(dev);
  7487. + pr_err("%s: device_create failed (rc=%d)\n", __func__, rc);
  7488. + goto out_class_destroy;
  7489. + }
  7490. +
  7491. +#ifdef CONFIG_DEBUG_FS
  7492. + /* don't fail if the debug entries cannot be created */
  7493. + vc_mem_debugfs_init(dev);
  7494. +#endif
  7495. +
  7496. + vc_mem_inited = 1;
  7497. + return 0;
  7498. +
  7499. + device_destroy(vc_mem_class, vc_mem_devnum);
  7500. +
  7501. + out_class_destroy:
  7502. + class_destroy(vc_mem_class);
  7503. + vc_mem_class = NULL;
  7504. +
  7505. + out_cdev_del:
  7506. + cdev_del(&vc_mem_cdev);
  7507. +
  7508. + out_unregister:
  7509. + unregister_chrdev_region(vc_mem_devnum, 1);
  7510. +
  7511. + out_err:
  7512. + return -1;
  7513. +}
  7514. +
  7515. +/****************************************************************************
  7516. +*
  7517. +* vc_mem_exit
  7518. +*
  7519. +***************************************************************************/
  7520. +
  7521. +static void __exit
  7522. +vc_mem_exit(void)
  7523. +{
  7524. + pr_debug("%s: called\n", __func__);
  7525. +
  7526. + if (vc_mem_inited) {
  7527. +#if CONFIG_DEBUG_FS
  7528. + vc_mem_debugfs_deinit();
  7529. +#endif
  7530. + device_destroy(vc_mem_class, vc_mem_devnum);
  7531. + class_destroy(vc_mem_class);
  7532. + cdev_del(&vc_mem_cdev);
  7533. + unregister_chrdev_region(vc_mem_devnum, 1);
  7534. + }
  7535. +}
  7536. +
  7537. +module_init(vc_mem_init);
  7538. +module_exit(vc_mem_exit);
  7539. +MODULE_LICENSE("GPL");
  7540. +MODULE_AUTHOR("Broadcom Corporation");
  7541. +
  7542. +module_param(phys_addr, uint, 0644);
  7543. +module_param(mem_size, uint, 0644);
  7544. +module_param(mem_base, uint, 0644);
  7545. +
  7546. diff -Nur linux-3.15.4/arch/arm/Makefile linux-rpi/arch/arm/Makefile
  7547. --- linux-3.15.4/arch/arm/Makefile 2014-07-07 03:59:25.000000000 +0200
  7548. +++ linux-rpi/arch/arm/Makefile 2014-07-07 10:44:57.000000000 +0200
  7549. @@ -143,6 +143,7 @@
  7550. # by CONFIG_* macro name.
  7551. machine-$(CONFIG_ARCH_AT91) += at91
  7552. machine-$(CONFIG_ARCH_BCM) += bcm
  7553. +machine-$(CONFIG_ARCH_BCM2708) += bcm2708
  7554. machine-$(CONFIG_ARCH_BERLIN) += berlin
  7555. machine-$(CONFIG_ARCH_CLPS711X) += clps711x
  7556. machine-$(CONFIG_ARCH_CNS3XXX) += cns3xxx
  7557. diff -Nur linux-3.15.4/arch/arm/mm/Kconfig linux-rpi/arch/arm/mm/Kconfig
  7558. --- linux-3.15.4/arch/arm/mm/Kconfig 2014-07-07 03:59:25.000000000 +0200
  7559. +++ linux-rpi/arch/arm/mm/Kconfig 2014-07-07 10:44:58.000000000 +0200
  7560. @@ -358,7 +358,7 @@
  7561. # ARMv6
  7562. config CPU_V6
  7563. - bool "Support ARM V6 processor" if ARCH_INTEGRATOR || MACH_REALVIEW_EB || MACH_REALVIEW_PBX
  7564. + bool "Support ARM V6 processor" if ARCH_INTEGRATOR || MACH_REALVIEW_EB || MACH_REALVIEW_PBX || MACH_BCM2708
  7565. select CPU_32v6
  7566. select CPU_ABRT_EV6
  7567. select CPU_CACHE_V6
  7568. diff -Nur linux-3.15.4/arch/arm/mm/proc-v6.S linux-rpi/arch/arm/mm/proc-v6.S
  7569. --- linux-3.15.4/arch/arm/mm/proc-v6.S 2014-07-07 03:59:25.000000000 +0200
  7570. +++ linux-rpi/arch/arm/mm/proc-v6.S 2014-07-07 10:44:58.000000000 +0200
  7571. @@ -73,10 +73,19 @@
  7572. *
  7573. * IRQs are already disabled.
  7574. */
  7575. +
  7576. +/* See jira SW-5991 for details of this workaround */
  7577. ENTRY(cpu_v6_do_idle)
  7578. - mov r1, #0
  7579. - mcr p15, 0, r1, c7, c10, 4 @ DWB - WFI may enter a low-power mode
  7580. - mcr p15, 0, r1, c7, c0, 4 @ wait for interrupt
  7581. + .align 5
  7582. + mov r1, #2
  7583. +1: subs r1, #1
  7584. + nop
  7585. + mcreq p15, 0, r1, c7, c10, 4 @ DWB - WFI may enter a low-power mode
  7586. + mcreq p15, 0, r1, c7, c0, 4 @ wait for interrupt
  7587. + nop
  7588. + nop
  7589. + nop
  7590. + bne 1b
  7591. mov pc, lr
  7592. ENTRY(cpu_v6_dcache_clean_area)
  7593. diff -Nur linux-3.15.4/arch/arm/tools/mach-types linux-rpi/arch/arm/tools/mach-types
  7594. --- linux-3.15.4/arch/arm/tools/mach-types 2014-07-07 03:59:25.000000000 +0200
  7595. +++ linux-rpi/arch/arm/tools/mach-types 2014-04-13 17:32:41.000000000 +0200
  7596. @@ -522,6 +522,7 @@
  7597. prima2_evb MACH_PRIMA2_EVB PRIMA2_EVB 3103
  7598. paz00 MACH_PAZ00 PAZ00 3128
  7599. acmenetusfoxg20 MACH_ACMENETUSFOXG20 ACMENETUSFOXG20 3129
  7600. +bcm2708 MACH_BCM2708 BCM2708 3138
  7601. ag5evm MACH_AG5EVM AG5EVM 3189
  7602. ics_if_voip MACH_ICS_IF_VOIP ICS_IF_VOIP 3206
  7603. wlf_cragg_6410 MACH_WLF_CRAGG_6410 WLF_CRAGG_6410 3207
  7604. diff -Nur linux-3.15.4/arch/mips/include/asm/sigcontext.h linux-rpi/arch/mips/include/asm/sigcontext.h
  7605. --- linux-3.15.4/arch/mips/include/asm/sigcontext.h 2014-07-07 03:59:25.000000000 +0200
  7606. +++ linux-rpi/arch/mips/include/asm/sigcontext.h 2014-07-07 10:44:58.000000000 +0200
  7607. @@ -32,6 +32,8 @@
  7608. __u32 sc_lo2;
  7609. __u32 sc_hi3;
  7610. __u32 sc_lo3;
  7611. + __u64 sc_msaregs[32]; /* Most significant 64 bits */
  7612. + __u32 sc_msa_csr;
  7613. };
  7614. #endif /* _MIPS_SIM == _MIPS_SIM_ABI64 || _MIPS_SIM == _MIPS_SIM_NABI32 */
  7615. #endif /* _ASM_SIGCONTEXT_H */
  7616. diff -Nur linux-3.15.4/arch/mips/include/uapi/asm/sigcontext.h linux-rpi/arch/mips/include/uapi/asm/sigcontext.h
  7617. --- linux-3.15.4/arch/mips/include/uapi/asm/sigcontext.h 2014-07-07 03:59:25.000000000 +0200
  7618. +++ linux-rpi/arch/mips/include/uapi/asm/sigcontext.h 2014-07-07 10:44:58.000000000 +0200
  7619. @@ -12,6 +12,10 @@
  7620. #include <linux/types.h>
  7621. #include <asm/sgidefs.h>
  7622. +/* Bits which may be set in sc_used_math */
  7623. +#define USEDMATH_FP (1 << 0)
  7624. +#define USEDMATH_MSA (1 << 1)
  7625. +
  7626. #if _MIPS_SIM == _MIPS_SIM_ABI32
  7627. /*
  7628. @@ -37,6 +41,8 @@
  7629. unsigned long sc_lo2;
  7630. unsigned long sc_hi3;
  7631. unsigned long sc_lo3;
  7632. + unsigned long long sc_msaregs[32]; /* Most significant 64 bits */
  7633. + unsigned long sc_msa_csr;
  7634. };
  7635. #endif /* _MIPS_SIM == _MIPS_SIM_ABI32 */
  7636. @@ -70,6 +76,8 @@
  7637. __u32 sc_used_math;
  7638. __u32 sc_dsp;
  7639. __u32 sc_reserved;
  7640. + __u64 sc_msaregs[32];
  7641. + __u32 sc_msa_csr;
  7642. };
  7643. diff -Nur linux-3.15.4/arch/mips/kernel/asm-offsets.c linux-rpi/arch/mips/kernel/asm-offsets.c
  7644. --- linux-3.15.4/arch/mips/kernel/asm-offsets.c 2014-07-07 03:59:25.000000000 +0200
  7645. +++ linux-rpi/arch/mips/kernel/asm-offsets.c 2014-07-07 10:44:58.000000000 +0200
  7646. @@ -295,6 +295,7 @@
  7647. OFFSET(SC_LO2, sigcontext, sc_lo2);
  7648. OFFSET(SC_HI3, sigcontext, sc_hi3);
  7649. OFFSET(SC_LO3, sigcontext, sc_lo3);
  7650. + OFFSET(SC_MSAREGS, sigcontext, sc_msaregs);
  7651. BLANK();
  7652. }
  7653. #endif
  7654. @@ -309,6 +310,7 @@
  7655. OFFSET(SC_MDLO, sigcontext, sc_mdlo);
  7656. OFFSET(SC_PC, sigcontext, sc_pc);
  7657. OFFSET(SC_FPC_CSR, sigcontext, sc_fpc_csr);
  7658. + OFFSET(SC_MSAREGS, sigcontext, sc_msaregs);
  7659. BLANK();
  7660. }
  7661. #endif
  7662. @@ -320,6 +322,7 @@
  7663. OFFSET(SC32_FPREGS, sigcontext32, sc_fpregs);
  7664. OFFSET(SC32_FPC_CSR, sigcontext32, sc_fpc_csr);
  7665. OFFSET(SC32_FPC_EIR, sigcontext32, sc_fpc_eir);
  7666. + OFFSET(SC32_MSAREGS, sigcontext32, sc_msaregs);
  7667. BLANK();
  7668. }
  7669. #endif
  7670. diff -Nur linux-3.15.4/arch/mips/kernel/irq-msc01.c linux-rpi/arch/mips/kernel/irq-msc01.c
  7671. --- linux-3.15.4/arch/mips/kernel/irq-msc01.c 2014-07-07 03:59:25.000000000 +0200
  7672. +++ linux-rpi/arch/mips/kernel/irq-msc01.c 2014-04-13 17:32:42.000000000 +0200
  7673. @@ -131,7 +131,7 @@
  7674. board_bind_eic_interrupt = &msc_bind_eic_interrupt;
  7675. - for (; nirq > 0; nirq--, imp++) {
  7676. + for (; nirq >= 0; nirq--, imp++) {
  7677. int n = imp->im_irq;
  7678. switch (imp->im_type) {
  7679. diff -Nur linux-3.15.4/arch/mips/kernel/r4k_fpu.S linux-rpi/arch/mips/kernel/r4k_fpu.S
  7680. --- linux-3.15.4/arch/mips/kernel/r4k_fpu.S 2014-07-07 03:59:25.000000000 +0200
  7681. +++ linux-rpi/arch/mips/kernel/r4k_fpu.S 2014-07-07 10:44:58.000000000 +0200
  7682. @@ -13,6 +13,7 @@
  7683. * Copyright (C) 1999, 2001 Silicon Graphics, Inc.
  7684. */
  7685. #include <asm/asm.h>
  7686. +#include <asm/asmmacro.h>
  7687. #include <asm/errno.h>
  7688. #include <asm/fpregdef.h>
  7689. #include <asm/mipsregs.h>
  7690. @@ -245,6 +246,218 @@
  7691. END(_restore_fp_context32)
  7692. #endif
  7693. +#ifdef CONFIG_CPU_HAS_MSA
  7694. +
  7695. + .macro save_sc_msareg wr, off, sc, tmp
  7696. +#ifdef CONFIG_64BIT
  7697. + copy_u_d \tmp, \wr, 1
  7698. + EX sd \tmp, (\off+(\wr*8))(\sc)
  7699. +#elif defined(CONFIG_CPU_LITTLE_ENDIAN)
  7700. + copy_u_w \tmp, \wr, 2
  7701. + EX sw \tmp, (\off+(\wr*8)+0)(\sc)
  7702. + copy_u_w \tmp, \wr, 3
  7703. + EX sw \tmp, (\off+(\wr*8)+4)(\sc)
  7704. +#else /* CONFIG_CPU_BIG_ENDIAN */
  7705. + copy_u_w \tmp, \wr, 2
  7706. + EX sw \tmp, (\off+(\wr*8)+4)(\sc)
  7707. + copy_u_w \tmp, \wr, 3
  7708. + EX sw \tmp, (\off+(\wr*8)+0)(\sc)
  7709. +#endif
  7710. + .endm
  7711. +
  7712. +/*
  7713. + * int _save_msa_context(struct sigcontext *sc)
  7714. + *
  7715. + * Save the upper 64 bits of each vector register along with the MSA_CSR
  7716. + * register into sc. Returns zero on success, else non-zero.
  7717. + */
  7718. +LEAF(_save_msa_context)
  7719. + save_sc_msareg 0, SC_MSAREGS, a0, t0
  7720. + save_sc_msareg 1, SC_MSAREGS, a0, t0
  7721. + save_sc_msareg 2, SC_MSAREGS, a0, t0
  7722. + save_sc_msareg 3, SC_MSAREGS, a0, t0
  7723. + save_sc_msareg 4, SC_MSAREGS, a0, t0
  7724. + save_sc_msareg 5, SC_MSAREGS, a0, t0
  7725. + save_sc_msareg 6, SC_MSAREGS, a0, t0
  7726. + save_sc_msareg 7, SC_MSAREGS, a0, t0
  7727. + save_sc_msareg 8, SC_MSAREGS, a0, t0
  7728. + save_sc_msareg 9, SC_MSAREGS, a0, t0
  7729. + save_sc_msareg 10, SC_MSAREGS, a0, t0
  7730. + save_sc_msareg 11, SC_MSAREGS, a0, t0
  7731. + save_sc_msareg 12, SC_MSAREGS, a0, t0
  7732. + save_sc_msareg 13, SC_MSAREGS, a0, t0
  7733. + save_sc_msareg 14, SC_MSAREGS, a0, t0
  7734. + save_sc_msareg 15, SC_MSAREGS, a0, t0
  7735. + save_sc_msareg 16, SC_MSAREGS, a0, t0
  7736. + save_sc_msareg 17, SC_MSAREGS, a0, t0
  7737. + save_sc_msareg 18, SC_MSAREGS, a0, t0
  7738. + save_sc_msareg 19, SC_MSAREGS, a0, t0
  7739. + save_sc_msareg 20, SC_MSAREGS, a0, t0
  7740. + save_sc_msareg 21, SC_MSAREGS, a0, t0
  7741. + save_sc_msareg 22, SC_MSAREGS, a0, t0
  7742. + save_sc_msareg 23, SC_MSAREGS, a0, t0
  7743. + save_sc_msareg 24, SC_MSAREGS, a0, t0
  7744. + save_sc_msareg 25, SC_MSAREGS, a0, t0
  7745. + save_sc_msareg 26, SC_MSAREGS, a0, t0
  7746. + save_sc_msareg 27, SC_MSAREGS, a0, t0
  7747. + save_sc_msareg 28, SC_MSAREGS, a0, t0
  7748. + save_sc_msareg 29, SC_MSAREGS, a0, t0
  7749. + save_sc_msareg 30, SC_MSAREGS, a0, t0
  7750. + save_sc_msareg 31, SC_MSAREGS, a0, t0
  7751. + jr ra
  7752. + li v0, 0
  7753. + END(_save_msa_context)
  7754. +
  7755. +#ifdef CONFIG_MIPS32_COMPAT
  7756. +
  7757. +/*
  7758. + * int _save_msa_context32(struct sigcontext32 *sc)
  7759. + *
  7760. + * Save the upper 64 bits of each vector register along with the MSA_CSR
  7761. + * register into sc. Returns zero on success, else non-zero.
  7762. + */
  7763. +LEAF(_save_msa_context32)
  7764. + save_sc_msareg 0, SC32_MSAREGS, a0, t0
  7765. + save_sc_msareg 1, SC32_MSAREGS, a0, t0
  7766. + save_sc_msareg 2, SC32_MSAREGS, a0, t0
  7767. + save_sc_msareg 3, SC32_MSAREGS, a0, t0
  7768. + save_sc_msareg 4, SC32_MSAREGS, a0, t0
  7769. + save_sc_msareg 5, SC32_MSAREGS, a0, t0
  7770. + save_sc_msareg 6, SC32_MSAREGS, a0, t0
  7771. + save_sc_msareg 7, SC32_MSAREGS, a0, t0
  7772. + save_sc_msareg 8, SC32_MSAREGS, a0, t0
  7773. + save_sc_msareg 9, SC32_MSAREGS, a0, t0
  7774. + save_sc_msareg 10, SC32_MSAREGS, a0, t0
  7775. + save_sc_msareg 11, SC32_MSAREGS, a0, t0
  7776. + save_sc_msareg 12, SC32_MSAREGS, a0, t0
  7777. + save_sc_msareg 13, SC32_MSAREGS, a0, t0
  7778. + save_sc_msareg 14, SC32_MSAREGS, a0, t0
  7779. + save_sc_msareg 15, SC32_MSAREGS, a0, t0
  7780. + save_sc_msareg 16, SC32_MSAREGS, a0, t0
  7781. + save_sc_msareg 17, SC32_MSAREGS, a0, t0
  7782. + save_sc_msareg 18, SC32_MSAREGS, a0, t0
  7783. + save_sc_msareg 19, SC32_MSAREGS, a0, t0
  7784. + save_sc_msareg 20, SC32_MSAREGS, a0, t0
  7785. + save_sc_msareg 21, SC32_MSAREGS, a0, t0
  7786. + save_sc_msareg 22, SC32_MSAREGS, a0, t0
  7787. + save_sc_msareg 23, SC32_MSAREGS, a0, t0
  7788. + save_sc_msareg 24, SC32_MSAREGS, a0, t0
  7789. + save_sc_msareg 25, SC32_MSAREGS, a0, t0
  7790. + save_sc_msareg 26, SC32_MSAREGS, a0, t0
  7791. + save_sc_msareg 27, SC32_MSAREGS, a0, t0
  7792. + save_sc_msareg 28, SC32_MSAREGS, a0, t0
  7793. + save_sc_msareg 29, SC32_MSAREGS, a0, t0
  7794. + save_sc_msareg 30, SC32_MSAREGS, a0, t0
  7795. + save_sc_msareg 31, SC32_MSAREGS, a0, t0
  7796. + jr ra
  7797. + li v0, 0
  7798. + END(_save_msa_context32)
  7799. +
  7800. +#endif /* CONFIG_MIPS32_COMPAT */
  7801. +
  7802. + .macro restore_sc_msareg wr, off, sc, tmp
  7803. +#ifdef CONFIG_64BIT
  7804. + EX ld \tmp, (\off+(\wr*8))(\sc)
  7805. + insert_d \wr, 1, \tmp
  7806. +#elif defined(CONFIG_CPU_LITTLE_ENDIAN)
  7807. + EX lw \tmp, (\off+(\wr*8)+0)(\sc)
  7808. + insert_w \wr, 2, \tmp
  7809. + EX lw \tmp, (\off+(\wr*8)+4)(\sc)
  7810. + insert_w \wr, 3, \tmp
  7811. +#else /* CONFIG_CPU_BIG_ENDIAN */
  7812. + EX lw \tmp, (\off+(\wr*8)+4)(\sc)
  7813. + insert_w \wr, 2, \tmp
  7814. + EX lw \tmp, (\off+(\wr*8)+0)(\sc)
  7815. + insert_w \wr, 3, \tmp
  7816. +#endif
  7817. + .endm
  7818. +
  7819. +/*
  7820. + * int _restore_msa_context(struct sigcontext *sc)
  7821. + */
  7822. +LEAF(_restore_msa_context)
  7823. + restore_sc_msareg 0, SC_MSAREGS, a0, t0
  7824. + restore_sc_msareg 1, SC_MSAREGS, a0, t0
  7825. + restore_sc_msareg 2, SC_MSAREGS, a0, t0
  7826. + restore_sc_msareg 3, SC_MSAREGS, a0, t0
  7827. + restore_sc_msareg 4, SC_MSAREGS, a0, t0
  7828. + restore_sc_msareg 5, SC_MSAREGS, a0, t0
  7829. + restore_sc_msareg 6, SC_MSAREGS, a0, t0
  7830. + restore_sc_msareg 7, SC_MSAREGS, a0, t0
  7831. + restore_sc_msareg 8, SC_MSAREGS, a0, t0
  7832. + restore_sc_msareg 9, SC_MSAREGS, a0, t0
  7833. + restore_sc_msareg 10, SC_MSAREGS, a0, t0
  7834. + restore_sc_msareg 11, SC_MSAREGS, a0, t0
  7835. + restore_sc_msareg 12, SC_MSAREGS, a0, t0
  7836. + restore_sc_msareg 13, SC_MSAREGS, a0, t0
  7837. + restore_sc_msareg 14, SC_MSAREGS, a0, t0
  7838. + restore_sc_msareg 15, SC_MSAREGS, a0, t0
  7839. + restore_sc_msareg 16, SC_MSAREGS, a0, t0
  7840. + restore_sc_msareg 17, SC_MSAREGS, a0, t0
  7841. + restore_sc_msareg 18, SC_MSAREGS, a0, t0
  7842. + restore_sc_msareg 19, SC_MSAREGS, a0, t0
  7843. + restore_sc_msareg 20, SC_MSAREGS, a0, t0
  7844. + restore_sc_msareg 21, SC_MSAREGS, a0, t0
  7845. + restore_sc_msareg 22, SC_MSAREGS, a0, t0
  7846. + restore_sc_msareg 23, SC_MSAREGS, a0, t0
  7847. + restore_sc_msareg 24, SC_MSAREGS, a0, t0
  7848. + restore_sc_msareg 25, SC_MSAREGS, a0, t0
  7849. + restore_sc_msareg 26, SC_MSAREGS, a0, t0
  7850. + restore_sc_msareg 27, SC_MSAREGS, a0, t0
  7851. + restore_sc_msareg 28, SC_MSAREGS, a0, t0
  7852. + restore_sc_msareg 29, SC_MSAREGS, a0, t0
  7853. + restore_sc_msareg 30, SC_MSAREGS, a0, t0
  7854. + restore_sc_msareg 31, SC_MSAREGS, a0, t0
  7855. + jr ra
  7856. + li v0, 0
  7857. + END(_restore_msa_context)
  7858. +
  7859. +#ifdef CONFIG_MIPS32_COMPAT
  7860. +
  7861. +/*
  7862. + * int _restore_msa_context32(struct sigcontext32 *sc)
  7863. + */
  7864. +LEAF(_restore_msa_context32)
  7865. + restore_sc_msareg 0, SC32_MSAREGS, a0, t0
  7866. + restore_sc_msareg 1, SC32_MSAREGS, a0, t0
  7867. + restore_sc_msareg 2, SC32_MSAREGS, a0, t0
  7868. + restore_sc_msareg 3, SC32_MSAREGS, a0, t0
  7869. + restore_sc_msareg 4, SC32_MSAREGS, a0, t0
  7870. + restore_sc_msareg 5, SC32_MSAREGS, a0, t0
  7871. + restore_sc_msareg 6, SC32_MSAREGS, a0, t0
  7872. + restore_sc_msareg 7, SC32_MSAREGS, a0, t0
  7873. + restore_sc_msareg 8, SC32_MSAREGS, a0, t0
  7874. + restore_sc_msareg 9, SC32_MSAREGS, a0, t0
  7875. + restore_sc_msareg 10, SC32_MSAREGS, a0, t0
  7876. + restore_sc_msareg 11, SC32_MSAREGS, a0, t0
  7877. + restore_sc_msareg 12, SC32_MSAREGS, a0, t0
  7878. + restore_sc_msareg 13, SC32_MSAREGS, a0, t0
  7879. + restore_sc_msareg 14, SC32_MSAREGS, a0, t0
  7880. + restore_sc_msareg 15, SC32_MSAREGS, a0, t0
  7881. + restore_sc_msareg 16, SC32_MSAREGS, a0, t0
  7882. + restore_sc_msareg 17, SC32_MSAREGS, a0, t0
  7883. + restore_sc_msareg 18, SC32_MSAREGS, a0, t0
  7884. + restore_sc_msareg 19, SC32_MSAREGS, a0, t0
  7885. + restore_sc_msareg 20, SC32_MSAREGS, a0, t0
  7886. + restore_sc_msareg 21, SC32_MSAREGS, a0, t0
  7887. + restore_sc_msareg 22, SC32_MSAREGS, a0, t0
  7888. + restore_sc_msareg 23, SC32_MSAREGS, a0, t0
  7889. + restore_sc_msareg 24, SC32_MSAREGS, a0, t0
  7890. + restore_sc_msareg 25, SC32_MSAREGS, a0, t0
  7891. + restore_sc_msareg 26, SC32_MSAREGS, a0, t0
  7892. + restore_sc_msareg 27, SC32_MSAREGS, a0, t0
  7893. + restore_sc_msareg 28, SC32_MSAREGS, a0, t0
  7894. + restore_sc_msareg 29, SC32_MSAREGS, a0, t0
  7895. + restore_sc_msareg 30, SC32_MSAREGS, a0, t0
  7896. + restore_sc_msareg 31, SC32_MSAREGS, a0, t0
  7897. + jr ra
  7898. + li v0, 0
  7899. + END(_restore_msa_context32)
  7900. +
  7901. +#endif /* CONFIG_MIPS32_COMPAT */
  7902. +
  7903. +#endif /* CONFIG_CPU_HAS_MSA */
  7904. +
  7905. .set reorder
  7906. .type fault@function
  7907. diff -Nur linux-3.15.4/arch/mips/kernel/signal32.c linux-rpi/arch/mips/kernel/signal32.c
  7908. --- linux-3.15.4/arch/mips/kernel/signal32.c 2014-07-07 03:59:25.000000000 +0200
  7909. +++ linux-rpi/arch/mips/kernel/signal32.c 2014-07-07 10:44:58.000000000 +0200
  7910. @@ -30,6 +30,7 @@
  7911. #include <asm/sim.h>
  7912. #include <asm/ucontext.h>
  7913. #include <asm/fpu.h>
  7914. +#include <asm/msa.h>
  7915. #include <asm/war.h>
  7916. #include <asm/vdso.h>
  7917. #include <asm/dsp.h>
  7918. @@ -42,6 +43,9 @@
  7919. extern asmlinkage int _save_fp_context32(struct sigcontext32 __user *sc);
  7920. extern asmlinkage int _restore_fp_context32(struct sigcontext32 __user *sc);
  7921. +extern asmlinkage int _save_msa_context32(struct sigcontext32 __user *sc);
  7922. +extern asmlinkage int _restore_msa_context32(struct sigcontext32 __user *sc);
  7923. +
  7924. /*
  7925. * Including <asm/unistd.h> would give use the 64-bit syscall numbers ...
  7926. */
  7927. @@ -111,19 +115,59 @@
  7928. }
  7929. /*
  7930. + * These functions will save only the upper 64 bits of the vector registers,
  7931. + * since the lower 64 bits have already been saved as the scalar FP context.
  7932. + */
  7933. +static int copy_msa_to_sigcontext32(struct sigcontext32 __user *sc)
  7934. +{
  7935. + int i;
  7936. + int err = 0;
  7937. +
  7938. + for (i = 0; i < NUM_FPU_REGS; i++) {
  7939. + err |=
  7940. + __put_user(get_fpr64(&current->thread.fpu.fpr[i], 1),
  7941. + &sc->sc_msaregs[i]);
  7942. + }
  7943. + err |= __put_user(current->thread.fpu.msacsr, &sc->sc_msa_csr);
  7944. +
  7945. + return err;
  7946. +}
  7947. +
  7948. +static int copy_msa_from_sigcontext32(struct sigcontext32 __user *sc)
  7949. +{
  7950. + int i;
  7951. + int err = 0;
  7952. + u64 val;
  7953. +
  7954. + for (i = 0; i < NUM_FPU_REGS; i++) {
  7955. + err |= __get_user(val, &sc->sc_msaregs[i]);
  7956. + set_fpr64(&current->thread.fpu.fpr[i], 1, val);
  7957. + }
  7958. + err |= __get_user(current->thread.fpu.msacsr, &sc->sc_msa_csr);
  7959. +
  7960. + return err;
  7961. +}
  7962. +
  7963. +/*
  7964. * sigcontext handlers
  7965. */
  7966. -static int protected_save_fp_context32(struct sigcontext32 __user *sc)
  7967. +static int protected_save_fp_context32(struct sigcontext32 __user *sc,
  7968. + unsigned used_math)
  7969. {
  7970. int err;
  7971. + bool save_msa = cpu_has_msa && (used_math & USEDMATH_MSA);
  7972. while (1) {
  7973. lock_fpu_owner();
  7974. if (is_fpu_owner()) {
  7975. err = save_fp_context32(sc);
  7976. + if (save_msa && !err)
  7977. + err = _save_msa_context32(sc);
  7978. unlock_fpu_owner();
  7979. } else {
  7980. unlock_fpu_owner();
  7981. err = copy_fp_to_sigcontext32(sc);
  7982. + if (save_msa && !err)
  7983. + err = copy_msa_to_sigcontext32(sc);
  7984. }
  7985. if (likely(!err))
  7986. break;
  7987. @@ -137,17 +181,28 @@
  7988. return err;
  7989. }
  7990. -static int protected_restore_fp_context32(struct sigcontext32 __user *sc)
  7991. +static int protected_restore_fp_context32(struct sigcontext32 __user *sc,
  7992. + unsigned used_math)
  7993. {
  7994. int err, tmp __maybe_unused;
  7995. + bool restore_msa = cpu_has_msa && (used_math & USEDMATH_MSA);
  7996. while (1) {
  7997. lock_fpu_owner();
  7998. if (is_fpu_owner()) {
  7999. err = restore_fp_context32(sc);
  8000. + if (restore_msa && !err) {
  8001. + enable_msa();
  8002. + err = _restore_msa_context32(sc);
  8003. + } else {
  8004. + /* signal handler may have used MSA */
  8005. + disable_msa();
  8006. + }
  8007. unlock_fpu_owner();
  8008. } else {
  8009. unlock_fpu_owner();
  8010. err = copy_fp_from_sigcontext32(sc);
  8011. + if (restore_msa && !err)
  8012. + err = copy_msa_from_sigcontext32(sc);
  8013. }
  8014. if (likely(!err))
  8015. break;
  8016. @@ -186,7 +241,8 @@
  8017. err |= __put_user(mflo3(), &sc->sc_lo3);
  8018. }
  8019. - used_math = !!used_math();
  8020. + used_math = used_math() ? USEDMATH_FP : 0;
  8021. + used_math |= thread_msa_context_live() ? USEDMATH_MSA : 0;
  8022. err |= __put_user(used_math, &sc->sc_used_math);
  8023. if (used_math) {
  8024. @@ -194,20 +250,21 @@
  8025. * Save FPU state to signal context. Signal handler
  8026. * will "inherit" current FPU state.
  8027. */
  8028. - err |= protected_save_fp_context32(sc);
  8029. + err |= protected_save_fp_context32(sc, used_math);
  8030. }
  8031. return err;
  8032. }
  8033. static int
  8034. -check_and_restore_fp_context32(struct sigcontext32 __user *sc)
  8035. +check_and_restore_fp_context32(struct sigcontext32 __user *sc,
  8036. + unsigned used_math)
  8037. {
  8038. int err, sig;
  8039. err = sig = fpcsr_pending(&sc->sc_fpc_csr);
  8040. if (err > 0)
  8041. err = 0;
  8042. - err |= protected_restore_fp_context32(sc);
  8043. + err |= protected_restore_fp_context32(sc, used_math);
  8044. return err ?: sig;
  8045. }
  8046. @@ -244,9 +301,10 @@
  8047. if (used_math) {
  8048. /* restore fpu context if we have used it before */
  8049. if (!err)
  8050. - err = check_and_restore_fp_context32(sc);
  8051. + err = check_and_restore_fp_context32(sc, used_math);
  8052. } else {
  8053. - /* signal handler may have used FPU. Give it up. */
  8054. + /* signal handler may have used FPU or MSA. Disable them. */
  8055. + disable_msa();
  8056. lose_fpu(0);
  8057. }
  8058. diff -Nur linux-3.15.4/arch/mips/kernel/signal.c linux-rpi/arch/mips/kernel/signal.c
  8059. --- linux-3.15.4/arch/mips/kernel/signal.c 2014-07-07 03:59:25.000000000 +0200
  8060. +++ linux-rpi/arch/mips/kernel/signal.c 2014-07-07 10:44:58.000000000 +0200
  8061. @@ -31,6 +31,7 @@
  8062. #include <linux/bitops.h>
  8063. #include <asm/cacheflush.h>
  8064. #include <asm/fpu.h>
  8065. +#include <asm/msa.h>
  8066. #include <asm/sim.h>
  8067. #include <asm/ucontext.h>
  8068. #include <asm/cpu-features.h>
  8069. @@ -47,6 +48,9 @@
  8070. extern asmlinkage int _save_fp_context(struct sigcontext __user *sc);
  8071. extern asmlinkage int _restore_fp_context(struct sigcontext __user *sc);
  8072. +extern asmlinkage int _save_msa_context(struct sigcontext __user *sc);
  8073. +extern asmlinkage int _restore_msa_context(struct sigcontext __user *sc);
  8074. +
  8075. struct sigframe {
  8076. u32 sf_ass[4]; /* argument save space for o32 */
  8077. u32 sf_pad[2]; /* Was: signal trampoline */
  8078. @@ -96,20 +100,60 @@
  8079. }
  8080. /*
  8081. + * These functions will save only the upper 64 bits of the vector registers,
  8082. + * since the lower 64 bits have already been saved as the scalar FP context.
  8083. + */
  8084. +static int copy_msa_to_sigcontext(struct sigcontext __user *sc)
  8085. +{
  8086. + int i;
  8087. + int err = 0;
  8088. +
  8089. + for (i = 0; i < NUM_FPU_REGS; i++) {
  8090. + err |=
  8091. + __put_user(get_fpr64(&current->thread.fpu.fpr[i], 1),
  8092. + &sc->sc_msaregs[i]);
  8093. + }
  8094. + err |= __put_user(current->thread.fpu.msacsr, &sc->sc_msa_csr);
  8095. +
  8096. + return err;
  8097. +}
  8098. +
  8099. +static int copy_msa_from_sigcontext(struct sigcontext __user *sc)
  8100. +{
  8101. + int i;
  8102. + int err = 0;
  8103. + u64 val;
  8104. +
  8105. + for (i = 0; i < NUM_FPU_REGS; i++) {
  8106. + err |= __get_user(val, &sc->sc_msaregs[i]);
  8107. + set_fpr64(&current->thread.fpu.fpr[i], 1, val);
  8108. + }
  8109. + err |= __get_user(current->thread.fpu.msacsr, &sc->sc_msa_csr);
  8110. +
  8111. + return err;
  8112. +}
  8113. +
  8114. +/*
  8115. * Helper routines
  8116. */
  8117. -static int protected_save_fp_context(struct sigcontext __user *sc)
  8118. +static int protected_save_fp_context(struct sigcontext __user *sc,
  8119. + unsigned used_math)
  8120. {
  8121. int err;
  8122. + bool save_msa = cpu_has_msa && (used_math & USEDMATH_MSA);
  8123. #ifndef CONFIG_EVA
  8124. while (1) {
  8125. lock_fpu_owner();
  8126. if (is_fpu_owner()) {
  8127. err = save_fp_context(sc);
  8128. + if (save_msa && !err)
  8129. + err = _save_msa_context(sc);
  8130. unlock_fpu_owner();
  8131. } else {
  8132. unlock_fpu_owner();
  8133. err = copy_fp_to_sigcontext(sc);
  8134. + if (save_msa && !err)
  8135. + err = copy_msa_to_sigcontext(sc);
  8136. }
  8137. if (likely(!err))
  8138. break;
  8139. @@ -125,24 +169,38 @@
  8140. * EVA does not have FPU EVA instructions so saving fpu context directly
  8141. * does not work.
  8142. */
  8143. + disable_msa();
  8144. lose_fpu(1);
  8145. err = save_fp_context(sc); /* this might fail */
  8146. + if (save_msa && !err)
  8147. + err = copy_msa_to_sigcontext(sc);
  8148. #endif
  8149. return err;
  8150. }
  8151. -static int protected_restore_fp_context(struct sigcontext __user *sc)
  8152. +static int protected_restore_fp_context(struct sigcontext __user *sc,
  8153. + unsigned used_math)
  8154. {
  8155. int err, tmp __maybe_unused;
  8156. + bool restore_msa = cpu_has_msa && (used_math & USEDMATH_MSA);
  8157. #ifndef CONFIG_EVA
  8158. while (1) {
  8159. lock_fpu_owner();
  8160. if (is_fpu_owner()) {
  8161. err = restore_fp_context(sc);
  8162. + if (restore_msa && !err) {
  8163. + enable_msa();
  8164. + err = _restore_msa_context(sc);
  8165. + } else {
  8166. + /* signal handler may have used MSA */
  8167. + disable_msa();
  8168. + }
  8169. unlock_fpu_owner();
  8170. } else {
  8171. unlock_fpu_owner();
  8172. err = copy_fp_from_sigcontext(sc);
  8173. + if (!err && (used_math & USEDMATH_MSA))
  8174. + err = copy_msa_from_sigcontext(sc);
  8175. }
  8176. if (likely(!err))
  8177. break;
  8178. @@ -158,8 +216,11 @@
  8179. * EVA does not have FPU EVA instructions so restoring fpu context
  8180. * directly does not work.
  8181. */
  8182. + enable_msa();
  8183. lose_fpu(0);
  8184. err = restore_fp_context(sc); /* this might fail */
  8185. + if (restore_msa && !err)
  8186. + err = copy_msa_from_sigcontext(sc);
  8187. #endif
  8188. return err;
  8189. }
  8190. @@ -191,7 +252,8 @@
  8191. err |= __put_user(rddsp(DSP_MASK), &sc->sc_dsp);
  8192. }
  8193. - used_math = !!used_math();
  8194. + used_math = used_math() ? USEDMATH_FP : 0;
  8195. + used_math |= thread_msa_context_live() ? USEDMATH_MSA : 0;
  8196. err |= __put_user(used_math, &sc->sc_used_math);
  8197. if (used_math) {
  8198. @@ -199,7 +261,7 @@
  8199. * Save FPU state to signal context. Signal handler
  8200. * will "inherit" current FPU state.
  8201. */
  8202. - err |= protected_save_fp_context(sc);
  8203. + err |= protected_save_fp_context(sc, used_math);
  8204. }
  8205. return err;
  8206. }
  8207. @@ -224,14 +286,14 @@
  8208. }
  8209. static int
  8210. -check_and_restore_fp_context(struct sigcontext __user *sc)
  8211. +check_and_restore_fp_context(struct sigcontext __user *sc, unsigned used_math)
  8212. {
  8213. int err, sig;
  8214. err = sig = fpcsr_pending(&sc->sc_fpc_csr);
  8215. if (err > 0)
  8216. err = 0;
  8217. - err |= protected_restore_fp_context(sc);
  8218. + err |= protected_restore_fp_context(sc, used_math);
  8219. return err ?: sig;
  8220. }
  8221. @@ -271,9 +333,10 @@
  8222. if (used_math) {
  8223. /* restore fpu context if we have used it before */
  8224. if (!err)
  8225. - err = check_and_restore_fp_context(sc);
  8226. + err = check_and_restore_fp_context(sc, used_math);
  8227. } else {
  8228. - /* signal handler may have used FPU. Give it up. */
  8229. + /* signal handler may have used FPU or MSA. Disable them. */
  8230. + disable_msa();
  8231. lose_fpu(0);
  8232. }
  8233. diff -Nur linux-3.15.4/arch/mips/kvm/kvm_mips.c linux-rpi/arch/mips/kvm/kvm_mips.c
  8234. --- linux-3.15.4/arch/mips/kvm/kvm_mips.c 2014-07-07 03:59:25.000000000 +0200
  8235. +++ linux-rpi/arch/mips/kvm/kvm_mips.c 2014-07-07 10:44:58.000000000 +0200
  8236. @@ -149,7 +149,9 @@
  8237. if (kvm->arch.guest_pmap[i] != KVM_INVALID_PAGE)
  8238. kvm_mips_release_pfn_clean(kvm->arch.guest_pmap[i]);
  8239. }
  8240. - kfree(kvm->arch.guest_pmap);
  8241. +
  8242. + if (kvm->arch.guest_pmap)
  8243. + kfree(kvm->arch.guest_pmap);
  8244. kvm_for_each_vcpu(i, vcpu, kvm) {
  8245. kvm_arch_vcpu_free(vcpu);
  8246. @@ -387,9 +389,12 @@
  8247. kvm_mips_dump_stats(vcpu);
  8248. - kfree(vcpu->arch.guest_ebase);
  8249. - kfree(vcpu->arch.kseg0_commpage);
  8250. - kfree(vcpu);
  8251. + if (vcpu->arch.guest_ebase)
  8252. + kfree(vcpu->arch.guest_ebase);
  8253. +
  8254. + if (vcpu->arch.kseg0_commpage)
  8255. + kfree(vcpu->arch.kseg0_commpage);
  8256. +
  8257. }
  8258. void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
  8259. diff -Nur linux-3.15.4/arch/powerpc/include/asm/switch_to.h linux-rpi/arch/powerpc/include/asm/switch_to.h
  8260. --- linux-3.15.4/arch/powerpc/include/asm/switch_to.h 2014-07-07 03:59:25.000000000 +0200
  8261. +++ linux-rpi/arch/powerpc/include/asm/switch_to.h 2014-07-07 10:44:59.000000000 +0200
  8262. @@ -84,8 +84,6 @@
  8263. {
  8264. #ifdef CONFIG_PPC_BOOK3S_64
  8265. /* EBB perf events are not inherited, so clear all EBB state. */
  8266. - t->thread.ebbrr = 0;
  8267. - t->thread.ebbhr = 0;
  8268. t->thread.bescr = 0;
  8269. t->thread.mmcr2 = 0;
  8270. t->thread.mmcr0 = 0;
  8271. diff -Nur linux-3.15.4/arch/powerpc/include/asm/systbl.h linux-rpi/arch/powerpc/include/asm/systbl.h
  8272. --- linux-3.15.4/arch/powerpc/include/asm/systbl.h 2014-07-07 03:59:25.000000000 +0200
  8273. +++ linux-rpi/arch/powerpc/include/asm/systbl.h 2014-07-07 10:44:59.000000000 +0200
  8274. @@ -190,7 +190,7 @@
  8275. SYSCALL_SPU(capget)
  8276. SYSCALL_SPU(capset)
  8277. COMPAT_SYS(sigaltstack)
  8278. -SYSX_SPU(sys_sendfile64,compat_sys_sendfile,sys_sendfile)
  8279. +COMPAT_SYS_SPU(sendfile)
  8280. SYSCALL(ni_syscall)
  8281. SYSCALL(ni_syscall)
  8282. PPC_SYS(vfork)
  8283. diff -Nur linux-3.15.4/arch/powerpc/include/uapi/asm/cputable.h linux-rpi/arch/powerpc/include/uapi/asm/cputable.h
  8284. --- linux-3.15.4/arch/powerpc/include/uapi/asm/cputable.h 2014-07-07 03:59:25.000000000 +0200
  8285. +++ linux-rpi/arch/powerpc/include/uapi/asm/cputable.h 2014-04-13 17:32:42.000000000 +0200
  8286. @@ -41,6 +41,5 @@
  8287. #define PPC_FEATURE2_EBB 0x10000000
  8288. #define PPC_FEATURE2_ISEL 0x08000000
  8289. #define PPC_FEATURE2_TAR 0x04000000
  8290. -#define PPC_FEATURE2_VEC_CRYPTO 0x02000000
  8291. #endif /* _UAPI__ASM_POWERPC_CPUTABLE_H */
  8292. diff -Nur linux-3.15.4/arch/powerpc/kernel/cputable.c linux-rpi/arch/powerpc/kernel/cputable.c
  8293. --- linux-3.15.4/arch/powerpc/kernel/cputable.c 2014-07-07 03:59:25.000000000 +0200
  8294. +++ linux-rpi/arch/powerpc/kernel/cputable.c 2014-07-07 10:44:59.000000000 +0200
  8295. @@ -109,8 +109,7 @@
  8296. PPC_FEATURE_PSERIES_PERFMON_COMPAT)
  8297. #define COMMON_USER2_POWER8 (PPC_FEATURE2_ARCH_2_07 | \
  8298. PPC_FEATURE2_HTM_COMP | PPC_FEATURE2_DSCR | \
  8299. - PPC_FEATURE2_ISEL | PPC_FEATURE2_TAR | \
  8300. - PPC_FEATURE2_VEC_CRYPTO)
  8301. + PPC_FEATURE2_ISEL | PPC_FEATURE2_TAR)
  8302. #define COMMON_USER_PA6T (COMMON_USER_PPC64 | PPC_FEATURE_PA6T |\
  8303. PPC_FEATURE_TRUE_LE | \
  8304. PPC_FEATURE_HAS_ALTIVEC_COMP)
  8305. diff -Nur linux-3.15.4/arch/powerpc/kernel/legacy_serial.c linux-rpi/arch/powerpc/kernel/legacy_serial.c
  8306. --- linux-3.15.4/arch/powerpc/kernel/legacy_serial.c 2014-07-07 03:59:25.000000000 +0200
  8307. +++ linux-rpi/arch/powerpc/kernel/legacy_serial.c 2014-07-07 10:44:59.000000000 +0200
  8308. @@ -48,9 +48,6 @@
  8309. static unsigned int legacy_serial_count;
  8310. static int legacy_serial_console = -1;
  8311. -static const upf_t legacy_port_flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST |
  8312. - UPF_SHARE_IRQ | UPF_FIXED_PORT;
  8313. -
  8314. static unsigned int tsi_serial_in(struct uart_port *p, int offset)
  8315. {
  8316. unsigned int tmp;
  8317. @@ -156,6 +153,8 @@
  8318. {
  8319. u64 addr;
  8320. const __be32 *addrp;
  8321. + upf_t flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_SHARE_IRQ
  8322. + | UPF_FIXED_PORT;
  8323. struct device_node *tsi = of_get_parent(np);
  8324. /* We only support ports that have a clock frequency properly
  8325. @@ -186,11 +185,9 @@
  8326. * IO port value. It will be fixed up later along with the irq
  8327. */
  8328. if (tsi && !strcmp(tsi->type, "tsi-bridge"))
  8329. - return add_legacy_port(np, -1, UPIO_TSI, addr, addr,
  8330. - NO_IRQ, legacy_port_flags, 0);
  8331. + return add_legacy_port(np, -1, UPIO_TSI, addr, addr, NO_IRQ, flags, 0);
  8332. else
  8333. - return add_legacy_port(np, -1, UPIO_MEM, addr, addr,
  8334. - NO_IRQ, legacy_port_flags, 0);
  8335. + return add_legacy_port(np, -1, UPIO_MEM, addr, addr, NO_IRQ, flags, 0);
  8336. }
  8337. static int __init add_legacy_isa_port(struct device_node *np,
  8338. @@ -236,7 +233,7 @@
  8339. /* Add port, irq will be dealt with later */
  8340. return add_legacy_port(np, index, UPIO_PORT, be32_to_cpu(reg[1]),
  8341. - taddr, NO_IRQ, legacy_port_flags, 0);
  8342. + taddr, NO_IRQ, UPF_BOOT_AUTOCONF, 0);
  8343. }
  8344. @@ -309,7 +306,7 @@
  8345. * IO port value. It will be fixed up later along with the irq
  8346. */
  8347. return add_legacy_port(np, index, iotype, base, addr, NO_IRQ,
  8348. - legacy_port_flags, np != pci_dev);
  8349. + UPF_BOOT_AUTOCONF, np != pci_dev);
  8350. }
  8351. #endif
  8352. diff -Nur linux-3.15.4/arch/powerpc/kernel/setup-common.c linux-rpi/arch/powerpc/kernel/setup-common.c
  8353. --- linux-3.15.4/arch/powerpc/kernel/setup-common.c 2014-07-07 03:59:25.000000000 +0200
  8354. +++ linux-rpi/arch/powerpc/kernel/setup-common.c 2014-07-07 10:44:59.000000000 +0200
  8355. @@ -459,17 +459,9 @@
  8356. }
  8357. for (j = 0; j < nthreads && cpu < nr_cpu_ids; j++) {
  8358. - bool avail;
  8359. -
  8360. DBG(" thread %d -> cpu %d (hard id %d)\n",
  8361. j, cpu, be32_to_cpu(intserv[j]));
  8362. -
  8363. - avail = of_device_is_available(dn);
  8364. - if (!avail)
  8365. - avail = !of_property_match_string(dn,
  8366. - "enable-method", "spin-table");
  8367. -
  8368. - set_cpu_present(cpu, avail);
  8369. + set_cpu_present(cpu, true);
  8370. set_hard_smp_processor_id(cpu, be32_to_cpu(intserv[j]));
  8371. set_cpu_possible(cpu, true);
  8372. cpu++;
  8373. diff -Nur linux-3.15.4/arch/powerpc/kernel/time.c linux-rpi/arch/powerpc/kernel/time.c
  8374. --- linux-3.15.4/arch/powerpc/kernel/time.c 2014-07-07 03:59:25.000000000 +0200
  8375. +++ linux-rpi/arch/powerpc/kernel/time.c 2014-07-07 10:44:59.000000000 +0200
  8376. @@ -551,7 +551,7 @@
  8377. may_hard_irq_enable();
  8378. -#if defined(CONFIG_PPC32) && defined(CONFIG_PPC_PMAC)
  8379. +#if defined(CONFIG_PPC32) && defined(CONFIG_PMAC)
  8380. if (atomic_read(&ppc_n_lost_interrupts) != 0)
  8381. do_IRQ(regs);
  8382. #endif
  8383. diff -Nur linux-3.15.4/arch/powerpc/lib/sstep.c linux-rpi/arch/powerpc/lib/sstep.c
  8384. --- linux-3.15.4/arch/powerpc/lib/sstep.c 2014-07-07 03:59:25.000000000 +0200
  8385. +++ linux-rpi/arch/powerpc/lib/sstep.c 2014-07-07 10:44:59.000000000 +0200
  8386. @@ -1470,7 +1470,7 @@
  8387. regs->gpr[rd] = byterev_4(val);
  8388. goto ldst_done;
  8389. -#ifdef CONFIG_PPC_FPU
  8390. +#ifdef CONFIG_PPC_CPU
  8391. case 535: /* lfsx */
  8392. case 567: /* lfsux */
  8393. if (!(regs->msr & MSR_FP))
  8394. diff -Nur linux-3.15.4/arch/powerpc/mm/hash_utils_64.c linux-rpi/arch/powerpc/mm/hash_utils_64.c
  8395. --- linux-3.15.4/arch/powerpc/mm/hash_utils_64.c 2014-07-07 03:59:25.000000000 +0200
  8396. +++ linux-rpi/arch/powerpc/mm/hash_utils_64.c 2014-07-07 10:44:59.000000000 +0200
  8397. @@ -964,22 +964,6 @@
  8398. trap, vsid, ssize, psize, lpsize, pte);
  8399. }
  8400. -static void check_paca_psize(unsigned long ea, struct mm_struct *mm,
  8401. - int psize, bool user_region)
  8402. -{
  8403. - if (user_region) {
  8404. - if (psize != get_paca_psize(ea)) {
  8405. - get_paca()->context = mm->context;
  8406. - slb_flush_and_rebolt();
  8407. - }
  8408. - } else if (get_paca()->vmalloc_sllp !=
  8409. - mmu_psize_defs[mmu_vmalloc_psize].sllp) {
  8410. - get_paca()->vmalloc_sllp =
  8411. - mmu_psize_defs[mmu_vmalloc_psize].sllp;
  8412. - slb_vmalloc_update();
  8413. - }
  8414. -}
  8415. -
  8416. /* Result code is:
  8417. * 0 - handled
  8418. * 1 - normal page fault
  8419. @@ -1101,8 +1085,6 @@
  8420. WARN_ON(1);
  8421. }
  8422. #endif
  8423. - check_paca_psize(ea, mm, psize, user_region);
  8424. -
  8425. goto bail;
  8426. }
  8427. @@ -1143,8 +1125,17 @@
  8428. #endif
  8429. }
  8430. }
  8431. -
  8432. - check_paca_psize(ea, mm, psize, user_region);
  8433. + if (user_region) {
  8434. + if (psize != get_paca_psize(ea)) {
  8435. + get_paca()->context = mm->context;
  8436. + slb_flush_and_rebolt();
  8437. + }
  8438. + } else if (get_paca()->vmalloc_sllp !=
  8439. + mmu_psize_defs[mmu_vmalloc_psize].sllp) {
  8440. + get_paca()->vmalloc_sllp =
  8441. + mmu_psize_defs[mmu_vmalloc_psize].sllp;
  8442. + slb_vmalloc_update();
  8443. + }
  8444. #endif /* CONFIG_PPC_64K_PAGES */
  8445. #ifdef CONFIG_PPC_HAS_HASH_64K
  8446. diff -Nur linux-3.15.4/arch/powerpc/platforms/powernv/opal-sysparam.c linux-rpi/arch/powerpc/platforms/powernv/opal-sysparam.c
  8447. --- linux-3.15.4/arch/powerpc/platforms/powernv/opal-sysparam.c 2014-07-07 03:59:25.000000000 +0200
  8448. +++ linux-rpi/arch/powerpc/platforms/powernv/opal-sysparam.c 2014-07-07 10:44:59.000000000 +0200
  8449. @@ -260,10 +260,10 @@
  8450. attr[i].kobj_attr.attr.mode = S_IRUGO;
  8451. break;
  8452. case OPAL_SYSPARAM_WRITE:
  8453. - attr[i].kobj_attr.attr.mode = S_IWUSR;
  8454. + attr[i].kobj_attr.attr.mode = S_IWUGO;
  8455. break;
  8456. case OPAL_SYSPARAM_RW:
  8457. - attr[i].kobj_attr.attr.mode = S_IRUGO | S_IWUSR;
  8458. + attr[i].kobj_attr.attr.mode = S_IRUGO | S_IWUGO;
  8459. break;
  8460. default:
  8461. break;
  8462. diff -Nur linux-3.15.4/arch/powerpc/platforms/pseries/eeh_pseries.c linux-rpi/arch/powerpc/platforms/pseries/eeh_pseries.c
  8463. --- linux-3.15.4/arch/powerpc/platforms/pseries/eeh_pseries.c 2014-07-07 03:59:25.000000000 +0200
  8464. +++ linux-rpi/arch/powerpc/platforms/pseries/eeh_pseries.c 2014-07-07 10:44:59.000000000 +0200
  8465. @@ -464,7 +464,6 @@
  8466. } else {
  8467. result = EEH_STATE_NOT_SUPPORT;
  8468. }
  8469. - break;
  8470. default:
  8471. result = EEH_STATE_NOT_SUPPORT;
  8472. }
  8473. diff -Nur linux-3.15.4/arch/x86/include/asm/ptrace.h linux-rpi/arch/x86/include/asm/ptrace.h
  8474. --- linux-3.15.4/arch/x86/include/asm/ptrace.h 2014-07-07 03:59:25.000000000 +0200
  8475. +++ linux-rpi/arch/x86/include/asm/ptrace.h 2014-07-07 10:44:59.000000000 +0200
  8476. @@ -231,22 +231,6 @@
  8477. #define ARCH_HAS_USER_SINGLE_STEP_INFO
  8478. -/*
  8479. - * When hitting ptrace_stop(), we cannot return using SYSRET because
  8480. - * that does not restore the full CPU state, only a minimal set. The
  8481. - * ptracer can change arbitrary register values, which is usually okay
  8482. - * because the usual ptrace stops run off the signal delivery path which
  8483. - * forces IRET; however, ptrace_event() stops happen in arbitrary places
  8484. - * in the kernel and don't force IRET path.
  8485. - *
  8486. - * So force IRET path after a ptrace stop.
  8487. - */
  8488. -#define arch_ptrace_stop_needed(code, info) \
  8489. -({ \
  8490. - set_thread_flag(TIF_NOTIFY_RESUME); \
  8491. - false; \
  8492. -})
  8493. -
  8494. struct user_desc;
  8495. extern int do_get_thread_area(struct task_struct *p, int idx,
  8496. struct user_desc __user *info);
  8497. diff -Nur linux-3.15.4/Documentation/sound/alsa/HD-Audio-Models.txt linux-rpi/Documentation/sound/alsa/HD-Audio-Models.txt
  8498. --- linux-3.15.4/Documentation/sound/alsa/HD-Audio-Models.txt 2014-07-07 03:59:25.000000000 +0200
  8499. +++ linux-rpi/Documentation/sound/alsa/HD-Audio-Models.txt 2014-07-07 10:44:57.000000000 +0200
  8500. @@ -286,11 +286,6 @@
  8501. hp-inv-led HP with broken BIOS for inverted mute LED
  8502. auto BIOS setup (default)
  8503. -STAC92HD95
  8504. -==========
  8505. - hp-led LED support for HP laptops
  8506. - hp-bass Bass HPF setup for HP Spectre 13
  8507. -
  8508. STAC9872
  8509. ========
  8510. vaio VAIO laptop without SPDIF
  8511. diff -Nur linux-3.15.4/Documentation/SubmittingPatches linux-rpi/Documentation/SubmittingPatches
  8512. --- linux-3.15.4/Documentation/SubmittingPatches 2014-07-07 03:59:25.000000000 +0200
  8513. +++ linux-rpi/Documentation/SubmittingPatches 2014-07-07 10:44:56.000000000 +0200
  8514. @@ -132,20 +132,6 @@
  8515. platform_set_drvdata(), but left the variable "dev" unused,
  8516. delete it.
  8517. -If your patch fixes a bug in a specific commit, e.g. you found an issue using
  8518. -git-bisect, please use the 'Fixes:' tag with the first 12 characters of the
  8519. -SHA-1 ID, and the one line summary.
  8520. -Example:
  8521. -
  8522. - Fixes: e21d2170f366 ("video: remove unnecessary platform_set_drvdata()")
  8523. -
  8524. -The following git-config settings can be used to add a pretty format for
  8525. -outputting the above style in the git log or git show commands
  8526. -
  8527. - [core]
  8528. - abbrev = 12
  8529. - [pretty]
  8530. - fixes = Fixes: %h (\"%s\")
  8531. 3) Separate your changes.
  8532. @@ -457,7 +443,7 @@
  8533. have been included in the discussion
  8534. -14) Using Reported-by:, Tested-by:, Reviewed-by:, Suggested-by: and Fixes:
  8535. +14) Using Reported-by:, Tested-by:, Reviewed-by: and Suggested-by:
  8536. If this patch fixes a problem reported by somebody else, consider adding a
  8537. Reported-by: tag to credit the reporter for their contribution. Please
  8538. @@ -512,12 +498,6 @@
  8539. idea reporters, they will, hopefully, be inspired to help us again in the
  8540. future.
  8541. -A Fixes: tag indicates that the patch fixes an issue in a previous commit. It
  8542. -is used to make it easy to determine where a bug originated, which can help
  8543. -review a bug fix. This tag also assists the stable kernel team in determining
  8544. -which stable kernel versions should receive your fix. This is the preferred
  8545. -method for indicating a bug fixed by the patch. See #2 above for more details.
  8546. -
  8547. 15) The canonical patch format
  8548. diff -Nur linux-3.15.4/Documentation/video4linux/bcm2835-v4l2.txt linux-rpi/Documentation/video4linux/bcm2835-v4l2.txt
  8549. --- linux-3.15.4/Documentation/video4linux/bcm2835-v4l2.txt 1970-01-01 01:00:00.000000000 +0100
  8550. +++ linux-rpi/Documentation/video4linux/bcm2835-v4l2.txt 2014-04-13 17:32:39.000000000 +0200
  8551. @@ -0,0 +1,60 @@
  8552. +
  8553. +BCM2835 (aka Raspberry Pi) V4L2 driver
  8554. +======================================
  8555. +
  8556. +1. Copyright
  8557. +============
  8558. +
  8559. +Copyright © 2013 Raspberry Pi (Trading) Ltd.
  8560. +
  8561. +2. License
  8562. +==========
  8563. +
  8564. +This program is free software; you can redistribute it and/or modify
  8565. +it under the terms of the GNU General Public License as published by
  8566. +the Free Software Foundation; either version 2 of the License, or
  8567. +(at your option) any later version.
  8568. +
  8569. +This program is distributed in the hope that it will be useful,
  8570. +but WITHOUT ANY WARRANTY; without even the implied warranty of
  8571. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8572. +GNU General Public License for more details.
  8573. +
  8574. +You should have received a copy of the GNU General Public License
  8575. +along with this program; if not, write to the Free Software
  8576. +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  8577. +
  8578. +3. Quick Start
  8579. +==============
  8580. +
  8581. +You need a version 1.0 or later of v4l2-ctl, available from:
  8582. + git://git.linuxtv.org/v4l-utils.git
  8583. +
  8584. +$ sudo modprobe bcm2835-v4l2
  8585. +
  8586. +Turn on the overlay:
  8587. +
  8588. +$ v4l2-ctl --overlay=1
  8589. +
  8590. +Turn off the overlay:
  8591. +
  8592. +$ v4l2-ctl --overlay=0
  8593. +
  8594. +Set the capture format for video:
  8595. +
  8596. +$ v4l2-ctl --set-fmt-video=width=1920,height=1088,pixelformat=4
  8597. +
  8598. +(Note: 1088 not 1080).
  8599. +
  8600. +Capture:
  8601. +
  8602. +$ v4l2-ctl --stream-mmap=3 --stream-count=100 --stream-to=somefile.h264
  8603. +
  8604. +Stills capture:
  8605. +
  8606. +$ v4l2-ctl --set-fmt-video=width=2592,height=1944,pixelformat=3
  8607. +$ v4l2-ctl --stream-mmap=3 --stream-count=1 --stream-to=somefile.jpg
  8608. +
  8609. +List of available formats:
  8610. +
  8611. +$ v4l2-ctl --list-formats
  8612. diff -Nur linux-3.15.4/drivers/block/mtip32xx/mtip32xx.c linux-rpi/drivers/block/mtip32xx/mtip32xx.c
  8613. --- linux-3.15.4/drivers/block/mtip32xx/mtip32xx.c 2014-07-07 03:59:25.000000000 +0200
  8614. +++ linux-rpi/drivers/block/mtip32xx/mtip32xx.c 2014-07-07 10:45:00.000000000 +0200
  8615. @@ -1529,37 +1529,6 @@
  8616. be16_to_cpus(&buf[i]);
  8617. }
  8618. -static void mtip_set_timeout(struct driver_data *dd,
  8619. - struct host_to_dev_fis *fis,
  8620. - unsigned int *timeout, u8 erasemode)
  8621. -{
  8622. - switch (fis->command) {
  8623. - case ATA_CMD_DOWNLOAD_MICRO:
  8624. - *timeout = 120000; /* 2 minutes */
  8625. - break;
  8626. - case ATA_CMD_SEC_ERASE_UNIT:
  8627. - case 0xFC:
  8628. - if (erasemode)
  8629. - *timeout = ((*(dd->port->identify + 90) * 2) * 60000);
  8630. - else
  8631. - *timeout = ((*(dd->port->identify + 89) * 2) * 60000);
  8632. - break;
  8633. - case ATA_CMD_STANDBYNOW1:
  8634. - *timeout = 120000; /* 2 minutes */
  8635. - break;
  8636. - case 0xF7:
  8637. - case 0xFA:
  8638. - *timeout = 60000; /* 60 seconds */
  8639. - break;
  8640. - case ATA_CMD_SMART:
  8641. - *timeout = 15000; /* 15 seconds */
  8642. - break;
  8643. - default:
  8644. - *timeout = MTIP_IOCTL_COMMAND_TIMEOUT_MS;
  8645. - break;
  8646. - }
  8647. -}
  8648. -
  8649. /*
  8650. * Request the device identity information.
  8651. *
  8652. @@ -1675,7 +1644,6 @@
  8653. int rv;
  8654. struct host_to_dev_fis fis;
  8655. unsigned long start;
  8656. - unsigned int timeout;
  8657. /* Build the FIS. */
  8658. memset(&fis, 0, sizeof(struct host_to_dev_fis));
  8659. @@ -1683,8 +1651,6 @@
  8660. fis.opts = 1 << 7;
  8661. fis.command = ATA_CMD_STANDBYNOW1;
  8662. - mtip_set_timeout(port->dd, &fis, &timeout, 0);
  8663. -
  8664. start = jiffies;
  8665. rv = mtip_exec_internal_command(port,
  8666. &fis,
  8667. @@ -1693,7 +1659,7 @@
  8668. 0,
  8669. 0,
  8670. GFP_ATOMIC,
  8671. - timeout);
  8672. + 15000);
  8673. dbg_printk(MTIP_DRV_NAME "Time taken to complete standby cmd: %d ms\n",
  8674. jiffies_to_msecs(jiffies - start));
  8675. if (rv)
  8676. @@ -2236,6 +2202,36 @@
  8677. }
  8678. return rv;
  8679. }
  8680. +static void mtip_set_timeout(struct driver_data *dd,
  8681. + struct host_to_dev_fis *fis,
  8682. + unsigned int *timeout, u8 erasemode)
  8683. +{
  8684. + switch (fis->command) {
  8685. + case ATA_CMD_DOWNLOAD_MICRO:
  8686. + *timeout = 120000; /* 2 minutes */
  8687. + break;
  8688. + case ATA_CMD_SEC_ERASE_UNIT:
  8689. + case 0xFC:
  8690. + if (erasemode)
  8691. + *timeout = ((*(dd->port->identify + 90) * 2) * 60000);
  8692. + else
  8693. + *timeout = ((*(dd->port->identify + 89) * 2) * 60000);
  8694. + break;
  8695. + case ATA_CMD_STANDBYNOW1:
  8696. + *timeout = 120000; /* 2 minutes */
  8697. + break;
  8698. + case 0xF7:
  8699. + case 0xFA:
  8700. + *timeout = 60000; /* 60 seconds */
  8701. + break;
  8702. + case ATA_CMD_SMART:
  8703. + *timeout = 15000; /* 15 seconds */
  8704. + break;
  8705. + default:
  8706. + *timeout = MTIP_IOCTL_COMMAND_TIMEOUT_MS;
  8707. + break;
  8708. + }
  8709. +}
  8710. /*
  8711. * Executes a taskfile
  8712. @@ -4483,57 +4479,6 @@
  8713. static DEFINE_HANDLER(6);
  8714. static DEFINE_HANDLER(7);
  8715. -static void mtip_disable_link_opts(struct driver_data *dd, struct pci_dev *pdev)
  8716. -{
  8717. - int pos;
  8718. - unsigned short pcie_dev_ctrl;
  8719. -
  8720. - pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
  8721. - if (pos) {
  8722. - pci_read_config_word(pdev,
  8723. - pos + PCI_EXP_DEVCTL,
  8724. - &pcie_dev_ctrl);
  8725. - if (pcie_dev_ctrl & (1 << 11) ||
  8726. - pcie_dev_ctrl & (1 << 4)) {
  8727. - dev_info(&dd->pdev->dev,
  8728. - "Disabling ERO/No-Snoop on bridge device %04x:%04x\n",
  8729. - pdev->vendor, pdev->device);
  8730. - pcie_dev_ctrl &= ~(PCI_EXP_DEVCTL_NOSNOOP_EN |
  8731. - PCI_EXP_DEVCTL_RELAX_EN);
  8732. - pci_write_config_word(pdev,
  8733. - pos + PCI_EXP_DEVCTL,
  8734. - pcie_dev_ctrl);
  8735. - }
  8736. - }
  8737. -}
  8738. -
  8739. -static void mtip_fix_ero_nosnoop(struct driver_data *dd, struct pci_dev *pdev)
  8740. -{
  8741. - /*
  8742. - * This workaround is specific to AMD/ATI chipset with a PCI upstream
  8743. - * device with device id 0x5aXX
  8744. - */
  8745. - if (pdev->bus && pdev->bus->self) {
  8746. - if (pdev->bus->self->vendor == PCI_VENDOR_ID_ATI &&
  8747. - ((pdev->bus->self->device & 0xff00) == 0x5a00)) {
  8748. - mtip_disable_link_opts(dd, pdev->bus->self);
  8749. - } else {
  8750. - /* Check further up the topology */
  8751. - struct pci_dev *parent_dev = pdev->bus->self;
  8752. - if (parent_dev->bus &&
  8753. - parent_dev->bus->parent &&
  8754. - parent_dev->bus->parent->self &&
  8755. - parent_dev->bus->parent->self->vendor ==
  8756. - PCI_VENDOR_ID_ATI &&
  8757. - (parent_dev->bus->parent->self->device &
  8758. - 0xff00) == 0x5a00) {
  8759. - mtip_disable_link_opts(dd,
  8760. - parent_dev->bus->parent->self);
  8761. - }
  8762. - }
  8763. - }
  8764. -}
  8765. -
  8766. /*
  8767. * Called for each supported PCI device detected.
  8768. *
  8769. @@ -4685,8 +4630,6 @@
  8770. goto msi_initialize_err;
  8771. }
  8772. - mtip_fix_ero_nosnoop(dd, pdev);
  8773. -
  8774. /* Initialize the block layer. */
  8775. rv = mtip_block_initialize(dd);
  8776. if (rv < 0) {
  8777. @@ -4992,13 +4935,13 @@
  8778. */
  8779. static void __exit mtip_exit(void)
  8780. {
  8781. + debugfs_remove_recursive(dfs_parent);
  8782. +
  8783. /* Release the allocated major block device number. */
  8784. unregister_blkdev(mtip_major, MTIP_DRV_NAME);
  8785. /* Unregister the PCI driver. */
  8786. pci_unregister_driver(&mtip_pci_driver);
  8787. -
  8788. - debugfs_remove_recursive(dfs_parent);
  8789. }
  8790. MODULE_AUTHOR("Micron Technology, Inc");
  8791. diff -Nur linux-3.15.4/drivers/char/broadcom/Kconfig linux-rpi/drivers/char/broadcom/Kconfig
  8792. --- linux-3.15.4/drivers/char/broadcom/Kconfig 1970-01-01 01:00:00.000000000 +0100
  8793. +++ linux-rpi/drivers/char/broadcom/Kconfig 2014-07-07 10:45:00.000000000 +0200
  8794. @@ -0,0 +1,16 @@
  8795. +#
  8796. +# Broadcom char driver config
  8797. +#
  8798. +
  8799. +menuconfig BRCM_CHAR_DRIVERS
  8800. + bool "Broadcom Char Drivers"
  8801. + help
  8802. + Broadcom's char drivers
  8803. +
  8804. +config BCM_VC_CMA
  8805. + bool "Videocore CMA"
  8806. + depends on CMA && BRCM_CHAR_DRIVERS && BCM2708_VCHIQ
  8807. + default n
  8808. + help
  8809. + Helper for videocore CMA access.
  8810. +
  8811. diff -Nur linux-3.15.4/drivers/char/broadcom/Makefile linux-rpi/drivers/char/broadcom/Makefile
  8812. --- linux-3.15.4/drivers/char/broadcom/Makefile 1970-01-01 01:00:00.000000000 +0100
  8813. +++ linux-rpi/drivers/char/broadcom/Makefile 2014-07-07 10:45:00.000000000 +0200
  8814. @@ -0,0 +1 @@
  8815. +obj-$(CONFIG_BCM_VC_CMA) += vc_cma/
  8816. diff -Nur linux-3.15.4/drivers/char/broadcom/vc_cma/Makefile linux-rpi/drivers/char/broadcom/vc_cma/Makefile
  8817. --- linux-3.15.4/drivers/char/broadcom/vc_cma/Makefile 1970-01-01 01:00:00.000000000 +0100
  8818. +++ linux-rpi/drivers/char/broadcom/vc_cma/Makefile 2014-07-07 10:45:00.000000000 +0200
  8819. @@ -0,0 +1,14 @@
  8820. +ccflags-y += -Wall -Wstrict-prototypes -Wno-trigraphs
  8821. +ccflags-y += -Werror
  8822. +ccflags-y += -Iinclude/linux/broadcom
  8823. +ccflags-y += -Idrivers/misc/vc04_services
  8824. +ccflags-y += -Idrivers/misc/vc04_services/interface/vchi
  8825. +ccflags-y += -Idrivers/misc/vc04_services/interface/vchiq_arm
  8826. +
  8827. +ccflags-y += -D__KERNEL__
  8828. +ccflags-y += -D__linux__
  8829. +ccflags-y += -Werror
  8830. +
  8831. +obj-$(CONFIG_BCM_VC_CMA) += vc-cma.o
  8832. +
  8833. +vc-cma-objs := vc_cma.o
  8834. diff -Nur linux-3.15.4/drivers/char/broadcom/vc_cma/vc_cma.c linux-rpi/drivers/char/broadcom/vc_cma/vc_cma.c
  8835. --- linux-3.15.4/drivers/char/broadcom/vc_cma/vc_cma.c 1970-01-01 01:00:00.000000000 +0100
  8836. +++ linux-rpi/drivers/char/broadcom/vc_cma/vc_cma.c 2014-07-07 10:45:00.000000000 +0200
  8837. @@ -0,0 +1,1143 @@
  8838. +/**
  8839. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  8840. + *
  8841. + * Redistribution and use in source and binary forms, with or without
  8842. + * modification, are permitted provided that the following conditions
  8843. + * are met:
  8844. + * 1. Redistributions of source code must retain the above copyright
  8845. + * notice, this list of conditions, and the following disclaimer,
  8846. + * without modification.
  8847. + * 2. Redistributions in binary form must reproduce the above copyright
  8848. + * notice, this list of conditions and the following disclaimer in the
  8849. + * documentation and/or other materials provided with the distribution.
  8850. + * 3. The names of the above-listed copyright holders may not be used
  8851. + * to endorse or promote products derived from this software without
  8852. + * specific prior written permission.
  8853. + *
  8854. + * ALTERNATIVELY, this software may be distributed under the terms of the
  8855. + * GNU General Public License ("GPL") version 2, as published by the Free
  8856. + * Software Foundation.
  8857. + *
  8858. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  8859. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  8860. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  8861. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  8862. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  8863. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  8864. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  8865. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  8866. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  8867. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  8868. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  8869. + */
  8870. +
  8871. +#include <linux/kernel.h>
  8872. +#include <linux/module.h>
  8873. +#include <linux/kthread.h>
  8874. +#include <linux/fs.h>
  8875. +#include <linux/device.h>
  8876. +#include <linux/cdev.h>
  8877. +#include <linux/mm.h>
  8878. +#include <linux/proc_fs.h>
  8879. +#include <linux/seq_file.h>
  8880. +#include <linux/dma-mapping.h>
  8881. +#include <linux/dma-contiguous.h>
  8882. +#include <linux/platform_device.h>
  8883. +#include <linux/uaccess.h>
  8884. +#include <asm/cacheflush.h>
  8885. +
  8886. +#include "vc_cma.h"
  8887. +
  8888. +#include "vchiq_util.h"
  8889. +#include "vchiq_connected.h"
  8890. +//#include "debug_sym.h"
  8891. +//#include "vc_mem.h"
  8892. +
  8893. +#define DRIVER_NAME "vc-cma"
  8894. +
  8895. +#define LOG_DBG(fmt, ...) \
  8896. + if (vc_cma_debug) \
  8897. + printk(KERN_INFO fmt "\n", ##__VA_ARGS__)
  8898. +#define LOG_ERR(fmt, ...) \
  8899. + printk(KERN_ERR fmt "\n", ##__VA_ARGS__)
  8900. +
  8901. +#define VC_CMA_FOURCC VCHIQ_MAKE_FOURCC('C', 'M', 'A', ' ')
  8902. +#define VC_CMA_VERSION 2
  8903. +
  8904. +#define VC_CMA_CHUNK_ORDER 6 /* 256K */
  8905. +#define VC_CMA_CHUNK_SIZE (4096 << VC_CMA_CHUNK_ORDER)
  8906. +#define VC_CMA_MAX_PARAMS_PER_MSG \
  8907. + ((VCHIQ_MAX_MSG_SIZE - sizeof(unsigned short))/sizeof(unsigned short))
  8908. +#define VC_CMA_RESERVE_COUNT_MAX 16
  8909. +
  8910. +#define PAGES_PER_CHUNK (VC_CMA_CHUNK_SIZE / PAGE_SIZE)
  8911. +
  8912. +#define VCADDR_TO_PHYSADDR(vcaddr) (mm_vc_mem_phys_addr + vcaddr)
  8913. +
  8914. +#define loud_error(...) \
  8915. + LOG_ERR("===== " __VA_ARGS__)
  8916. +
  8917. +enum {
  8918. + VC_CMA_MSG_QUIT,
  8919. + VC_CMA_MSG_OPEN,
  8920. + VC_CMA_MSG_TICK,
  8921. + VC_CMA_MSG_ALLOC, /* chunk count */
  8922. + VC_CMA_MSG_FREE, /* chunk, chunk, ... */
  8923. + VC_CMA_MSG_ALLOCATED, /* chunk, chunk, ... */
  8924. + VC_CMA_MSG_REQUEST_ALLOC, /* chunk count */
  8925. + VC_CMA_MSG_REQUEST_FREE, /* chunk count */
  8926. + VC_CMA_MSG_RESERVE, /* bytes lo, bytes hi */
  8927. + VC_CMA_MSG_UPDATE_RESERVE,
  8928. + VC_CMA_MSG_MAX
  8929. +};
  8930. +
  8931. +struct cma_msg {
  8932. + unsigned short type;
  8933. + unsigned short params[VC_CMA_MAX_PARAMS_PER_MSG];
  8934. +};
  8935. +
  8936. +struct vc_cma_reserve_user {
  8937. + unsigned int pid;
  8938. + unsigned int reserve;
  8939. +};
  8940. +
  8941. +/* Device (/dev) related variables */
  8942. +static dev_t vc_cma_devnum;
  8943. +static struct class *vc_cma_class;
  8944. +static struct cdev vc_cma_cdev;
  8945. +static int vc_cma_inited;
  8946. +static int vc_cma_debug;
  8947. +
  8948. +/* Proc entry */
  8949. +static struct proc_dir_entry *vc_cma_proc_entry;
  8950. +
  8951. +phys_addr_t vc_cma_base;
  8952. +struct page *vc_cma_base_page;
  8953. +unsigned int vc_cma_size;
  8954. +EXPORT_SYMBOL(vc_cma_size);
  8955. +unsigned int vc_cma_initial;
  8956. +unsigned int vc_cma_chunks;
  8957. +unsigned int vc_cma_chunks_used;
  8958. +unsigned int vc_cma_chunks_reserved;
  8959. +
  8960. +static int in_loud_error;
  8961. +
  8962. +unsigned int vc_cma_reserve_total;
  8963. +unsigned int vc_cma_reserve_count;
  8964. +struct vc_cma_reserve_user vc_cma_reserve_users[VC_CMA_RESERVE_COUNT_MAX];
  8965. +static DEFINE_SEMAPHORE(vc_cma_reserve_mutex);
  8966. +static DEFINE_SEMAPHORE(vc_cma_worker_queue_push_mutex);
  8967. +
  8968. +static u64 vc_cma_dma_mask = DMA_BIT_MASK(32);
  8969. +static struct platform_device vc_cma_device = {
  8970. + .name = "vc-cma",
  8971. + .id = 0,
  8972. + .dev = {
  8973. + .dma_mask = &vc_cma_dma_mask,
  8974. + .coherent_dma_mask = DMA_BIT_MASK(32),
  8975. + },
  8976. +};
  8977. +
  8978. +static VCHIQ_INSTANCE_T cma_instance;
  8979. +static VCHIQ_SERVICE_HANDLE_T cma_service;
  8980. +static VCHIU_QUEUE_T cma_msg_queue;
  8981. +static struct task_struct *cma_worker;
  8982. +
  8983. +static int vc_cma_set_reserve(unsigned int reserve, unsigned int pid);
  8984. +static int vc_cma_alloc_chunks(int num_chunks, struct cma_msg *reply);
  8985. +static VCHIQ_STATUS_T cma_service_callback(VCHIQ_REASON_T reason,
  8986. + VCHIQ_HEADER_T * header,
  8987. + VCHIQ_SERVICE_HANDLE_T service,
  8988. + void *bulk_userdata);
  8989. +static void send_vc_msg(unsigned short type,
  8990. + unsigned short param1, unsigned short param2);
  8991. +static bool send_worker_msg(VCHIQ_HEADER_T * msg);
  8992. +
  8993. +static int early_vc_cma_mem(char *p)
  8994. +{
  8995. + unsigned int new_size;
  8996. + printk(KERN_NOTICE "early_vc_cma_mem(%s)", p);
  8997. + vc_cma_size = memparse(p, &p);
  8998. + vc_cma_initial = vc_cma_size;
  8999. + if (*p == '/')
  9000. + vc_cma_size = memparse(p + 1, &p);
  9001. + if (*p == '@')
  9002. + vc_cma_base = memparse(p + 1, &p);
  9003. +
  9004. + new_size = (vc_cma_size - ((-vc_cma_base) & (VC_CMA_CHUNK_SIZE - 1)))
  9005. + & ~(VC_CMA_CHUNK_SIZE - 1);
  9006. + if (new_size > vc_cma_size)
  9007. + vc_cma_size = 0;
  9008. + vc_cma_initial = (vc_cma_initial + VC_CMA_CHUNK_SIZE - 1)
  9009. + & ~(VC_CMA_CHUNK_SIZE - 1);
  9010. + if (vc_cma_initial > vc_cma_size)
  9011. + vc_cma_initial = vc_cma_size;
  9012. + vc_cma_base = (vc_cma_base + VC_CMA_CHUNK_SIZE - 1)
  9013. + & ~(VC_CMA_CHUNK_SIZE - 1);
  9014. +
  9015. + printk(KERN_NOTICE " -> initial %x, size %x, base %x", vc_cma_initial,
  9016. + vc_cma_size, (unsigned int)vc_cma_base);
  9017. +
  9018. + return 0;
  9019. +}
  9020. +
  9021. +early_param("vc-cma-mem", early_vc_cma_mem);
  9022. +
  9023. +void vc_cma_early_init(void)
  9024. +{
  9025. + LOG_DBG("vc_cma_early_init - vc_cma_chunks = %d", vc_cma_chunks);
  9026. + if (vc_cma_size) {
  9027. + int rc = platform_device_register(&vc_cma_device);
  9028. + LOG_DBG("platform_device_register -> %d", rc);
  9029. + }
  9030. +}
  9031. +
  9032. +void vc_cma_reserve(void)
  9033. +{
  9034. + /* if vc_cma_size is set, then declare vc CMA area of the same
  9035. + * size from the end of memory
  9036. + */
  9037. + if (vc_cma_size) {
  9038. + if (dma_declare_contiguous(NULL /*&vc_cma_device.dev*/, vc_cma_size,
  9039. + vc_cma_base, 0) == 0) {
  9040. + } else {
  9041. + LOG_ERR("vc_cma: dma_declare_contiguous(%x,%x) failed",
  9042. + vc_cma_size, (unsigned int)vc_cma_base);
  9043. + vc_cma_size = 0;
  9044. + }
  9045. + }
  9046. + vc_cma_chunks = vc_cma_size / VC_CMA_CHUNK_SIZE;
  9047. +}
  9048. +
  9049. +/****************************************************************************
  9050. +*
  9051. +* vc_cma_open
  9052. +*
  9053. +***************************************************************************/
  9054. +
  9055. +static int vc_cma_open(struct inode *inode, struct file *file)
  9056. +{
  9057. + (void)inode;
  9058. + (void)file;
  9059. +
  9060. + return 0;
  9061. +}
  9062. +
  9063. +/****************************************************************************
  9064. +*
  9065. +* vc_cma_release
  9066. +*
  9067. +***************************************************************************/
  9068. +
  9069. +static int vc_cma_release(struct inode *inode, struct file *file)
  9070. +{
  9071. + (void)inode;
  9072. + (void)file;
  9073. +
  9074. + vc_cma_set_reserve(0, current->tgid);
  9075. +
  9076. + return 0;
  9077. +}
  9078. +
  9079. +/****************************************************************************
  9080. +*
  9081. +* vc_cma_ioctl
  9082. +*
  9083. +***************************************************************************/
  9084. +
  9085. +static long vc_cma_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  9086. +{
  9087. + int rc = 0;
  9088. +
  9089. + (void)cmd;
  9090. + (void)arg;
  9091. +
  9092. + switch (cmd) {
  9093. + case VC_CMA_IOC_RESERVE:
  9094. + rc = vc_cma_set_reserve((unsigned int)arg, current->tgid);
  9095. + if (rc >= 0)
  9096. + rc = 0;
  9097. + break;
  9098. + default:
  9099. + LOG_ERR("vc-cma: Unknown ioctl %x", cmd);
  9100. + return -ENOTTY;
  9101. + }
  9102. +
  9103. + return rc;
  9104. +}
  9105. +
  9106. +/****************************************************************************
  9107. +*
  9108. +* File Operations for the driver.
  9109. +*
  9110. +***************************************************************************/
  9111. +
  9112. +static const struct file_operations vc_cma_fops = {
  9113. + .owner = THIS_MODULE,
  9114. + .open = vc_cma_open,
  9115. + .release = vc_cma_release,
  9116. + .unlocked_ioctl = vc_cma_ioctl,
  9117. +};
  9118. +
  9119. +/****************************************************************************
  9120. +*
  9121. +* vc_cma_proc_open
  9122. +*
  9123. +***************************************************************************/
  9124. +
  9125. +static int vc_cma_show_info(struct seq_file *m, void *v)
  9126. +{
  9127. + int i;
  9128. +
  9129. + seq_printf(m, "Videocore CMA:\n");
  9130. + seq_printf(m, " Base : %08x\n", (unsigned int)vc_cma_base);
  9131. + seq_printf(m, " Length : %08x\n", vc_cma_size);
  9132. + seq_printf(m, " Initial : %08x\n", vc_cma_initial);
  9133. + seq_printf(m, " Chunk size : %08x\n", VC_CMA_CHUNK_SIZE);
  9134. + seq_printf(m, " Chunks : %4d (%d bytes)\n",
  9135. + (int)vc_cma_chunks,
  9136. + (int)(vc_cma_chunks * VC_CMA_CHUNK_SIZE));
  9137. + seq_printf(m, " Used : %4d (%d bytes)\n",
  9138. + (int)vc_cma_chunks_used,
  9139. + (int)(vc_cma_chunks_used * VC_CMA_CHUNK_SIZE));
  9140. + seq_printf(m, " Reserved : %4d (%d bytes)\n",
  9141. + (unsigned int)vc_cma_chunks_reserved,
  9142. + (int)(vc_cma_chunks_reserved * VC_CMA_CHUNK_SIZE));
  9143. +
  9144. + for (i = 0; i < vc_cma_reserve_count; i++) {
  9145. + struct vc_cma_reserve_user *user = &vc_cma_reserve_users[i];
  9146. + seq_printf(m, " PID %5d: %d bytes\n", user->pid,
  9147. + user->reserve);
  9148. + }
  9149. +
  9150. + seq_printf(m, "\n");
  9151. +
  9152. + return 0;
  9153. +}
  9154. +
  9155. +static int vc_cma_proc_open(struct inode *inode, struct file *file)
  9156. +{
  9157. + return single_open(file, vc_cma_show_info, NULL);
  9158. +}
  9159. +
  9160. +/****************************************************************************
  9161. +*
  9162. +* vc_cma_proc_write
  9163. +*
  9164. +***************************************************************************/
  9165. +
  9166. +static int vc_cma_proc_write(struct file *file,
  9167. + const char __user *buffer,
  9168. + size_t size, loff_t *ppos)
  9169. +{
  9170. + int rc = -EFAULT;
  9171. + char input_str[20];
  9172. +
  9173. + memset(input_str, 0, sizeof(input_str));
  9174. +
  9175. + if (size > sizeof(input_str)) {
  9176. + LOG_ERR("%s: input string length too long", __func__);
  9177. + goto out;
  9178. + }
  9179. +
  9180. + if (copy_from_user(input_str, buffer, size - 1)) {
  9181. + LOG_ERR("%s: failed to get input string", __func__);
  9182. + goto out;
  9183. + }
  9184. +#define ALLOC_STR "alloc"
  9185. +#define FREE_STR "free"
  9186. +#define DEBUG_STR "debug"
  9187. +#define RESERVE_STR "reserve"
  9188. + if (strncmp(input_str, ALLOC_STR, strlen(ALLOC_STR)) == 0) {
  9189. + int size;
  9190. + char *p = input_str + strlen(ALLOC_STR);
  9191. +
  9192. + while (*p == ' ')
  9193. + p++;
  9194. + size = memparse(p, NULL);
  9195. + LOG_ERR("/proc/vc-cma: alloc %d", size);
  9196. + if (size)
  9197. + send_vc_msg(VC_CMA_MSG_REQUEST_FREE,
  9198. + size / VC_CMA_CHUNK_SIZE, 0);
  9199. + else
  9200. + LOG_ERR("invalid size '%s'", p);
  9201. + rc = size;
  9202. + } else if (strncmp(input_str, FREE_STR, strlen(FREE_STR)) == 0) {
  9203. + int size;
  9204. + char *p = input_str + strlen(FREE_STR);
  9205. +
  9206. + while (*p == ' ')
  9207. + p++;
  9208. + size = memparse(p, NULL);
  9209. + LOG_ERR("/proc/vc-cma: free %d", size);
  9210. + if (size)
  9211. + send_vc_msg(VC_CMA_MSG_REQUEST_ALLOC,
  9212. + size / VC_CMA_CHUNK_SIZE, 0);
  9213. + else
  9214. + LOG_ERR("invalid size '%s'", p);
  9215. + rc = size;
  9216. + } else if (strncmp(input_str, DEBUG_STR, strlen(DEBUG_STR)) == 0) {
  9217. + char *p = input_str + strlen(DEBUG_STR);
  9218. + while (*p == ' ')
  9219. + p++;
  9220. + if ((strcmp(p, "on") == 0) || (strcmp(p, "1") == 0))
  9221. + vc_cma_debug = 1;
  9222. + else if ((strcmp(p, "off") == 0) || (strcmp(p, "0") == 0))
  9223. + vc_cma_debug = 0;
  9224. + LOG_ERR("/proc/vc-cma: debug %s", vc_cma_debug ? "on" : "off");
  9225. + rc = size;
  9226. + } else if (strncmp(input_str, RESERVE_STR, strlen(RESERVE_STR)) == 0) {
  9227. + int size;
  9228. + int reserved;
  9229. + char *p = input_str + strlen(RESERVE_STR);
  9230. + while (*p == ' ')
  9231. + p++;
  9232. + size = memparse(p, NULL);
  9233. +
  9234. + reserved = vc_cma_set_reserve(size, current->tgid);
  9235. + rc = (reserved >= 0) ? size : reserved;
  9236. + }
  9237. +
  9238. +out:
  9239. + return rc;
  9240. +}
  9241. +
  9242. +/****************************************************************************
  9243. +*
  9244. +* File Operations for /proc interface.
  9245. +*
  9246. +***************************************************************************/
  9247. +
  9248. +static const struct file_operations vc_cma_proc_fops = {
  9249. + .open = vc_cma_proc_open,
  9250. + .read = seq_read,
  9251. + .write = vc_cma_proc_write,
  9252. + .llseek = seq_lseek,
  9253. + .release = single_release
  9254. +};
  9255. +
  9256. +static int vc_cma_set_reserve(unsigned int reserve, unsigned int pid)
  9257. +{
  9258. + struct vc_cma_reserve_user *user = NULL;
  9259. + int delta = 0;
  9260. + int i;
  9261. +
  9262. + if (down_interruptible(&vc_cma_reserve_mutex))
  9263. + return -ERESTARTSYS;
  9264. +
  9265. + for (i = 0; i < vc_cma_reserve_count; i++) {
  9266. + if (pid == vc_cma_reserve_users[i].pid) {
  9267. + user = &vc_cma_reserve_users[i];
  9268. + delta = reserve - user->reserve;
  9269. + if (reserve)
  9270. + user->reserve = reserve;
  9271. + else {
  9272. + /* Remove this entry by copying downwards */
  9273. + while ((i + 1) < vc_cma_reserve_count) {
  9274. + user[0].pid = user[1].pid;
  9275. + user[0].reserve = user[1].reserve;
  9276. + user++;
  9277. + i++;
  9278. + }
  9279. + vc_cma_reserve_count--;
  9280. + user = NULL;
  9281. + }
  9282. + break;
  9283. + }
  9284. + }
  9285. +
  9286. + if (reserve && !user) {
  9287. + if (vc_cma_reserve_count == VC_CMA_RESERVE_COUNT_MAX) {
  9288. + LOG_ERR("vc-cma: Too many reservations - "
  9289. + "increase CMA_RESERVE_COUNT_MAX");
  9290. + up(&vc_cma_reserve_mutex);
  9291. + return -EBUSY;
  9292. + }
  9293. + user = &vc_cma_reserve_users[vc_cma_reserve_count];
  9294. + user->pid = pid;
  9295. + user->reserve = reserve;
  9296. + delta = reserve;
  9297. + vc_cma_reserve_count++;
  9298. + }
  9299. +
  9300. + vc_cma_reserve_total += delta;
  9301. +
  9302. + send_vc_msg(VC_CMA_MSG_RESERVE,
  9303. + vc_cma_reserve_total & 0xffff, vc_cma_reserve_total >> 16);
  9304. +
  9305. + send_worker_msg((VCHIQ_HEADER_T *) VC_CMA_MSG_UPDATE_RESERVE);
  9306. +
  9307. + LOG_DBG("/proc/vc-cma: reserve %d (PID %d) - total %u",
  9308. + reserve, pid, vc_cma_reserve_total);
  9309. +
  9310. + up(&vc_cma_reserve_mutex);
  9311. +
  9312. + return vc_cma_reserve_total;
  9313. +}
  9314. +
  9315. +static VCHIQ_STATUS_T cma_service_callback(VCHIQ_REASON_T reason,
  9316. + VCHIQ_HEADER_T * header,
  9317. + VCHIQ_SERVICE_HANDLE_T service,
  9318. + void *bulk_userdata)
  9319. +{
  9320. + switch (reason) {
  9321. + case VCHIQ_MESSAGE_AVAILABLE:
  9322. + if (!send_worker_msg(header))
  9323. + return VCHIQ_RETRY;
  9324. + break;
  9325. + case VCHIQ_SERVICE_CLOSED:
  9326. + LOG_DBG("CMA service closed");
  9327. + break;
  9328. + default:
  9329. + LOG_ERR("Unexpected CMA callback reason %d", reason);
  9330. + break;
  9331. + }
  9332. + return VCHIQ_SUCCESS;
  9333. +}
  9334. +
  9335. +static void send_vc_msg(unsigned short type,
  9336. + unsigned short param1, unsigned short param2)
  9337. +{
  9338. + unsigned short msg[] = { type, param1, param2 };
  9339. + VCHIQ_ELEMENT_T elem = { &msg, sizeof(msg) };
  9340. + VCHIQ_STATUS_T ret;
  9341. + vchiq_use_service(cma_service);
  9342. + ret = vchiq_queue_message(cma_service, &elem, 1);
  9343. + vchiq_release_service(cma_service);
  9344. + if (ret != VCHIQ_SUCCESS)
  9345. + LOG_ERR("vchiq_queue_message returned %x", ret);
  9346. +}
  9347. +
  9348. +static bool send_worker_msg(VCHIQ_HEADER_T * msg)
  9349. +{
  9350. + if (down_interruptible(&vc_cma_worker_queue_push_mutex))
  9351. + return false;
  9352. + vchiu_queue_push(&cma_msg_queue, msg);
  9353. + up(&vc_cma_worker_queue_push_mutex);
  9354. + return true;
  9355. +}
  9356. +
  9357. +static int vc_cma_alloc_chunks(int num_chunks, struct cma_msg *reply)
  9358. +{
  9359. + int i;
  9360. + for (i = 0; i < num_chunks; i++) {
  9361. + struct page *chunk;
  9362. + unsigned int chunk_num;
  9363. + uint8_t *chunk_addr;
  9364. + size_t chunk_size = PAGES_PER_CHUNK << PAGE_SHIFT;
  9365. +
  9366. + chunk = dma_alloc_from_contiguous(NULL /*&vc_cma_device.dev*/,
  9367. + PAGES_PER_CHUNK,
  9368. + VC_CMA_CHUNK_ORDER);
  9369. + if (!chunk)
  9370. + break;
  9371. +
  9372. + chunk_addr = page_address(chunk);
  9373. + dmac_flush_range(chunk_addr, chunk_addr + chunk_size);
  9374. + outer_inv_range(__pa(chunk_addr), __pa(chunk_addr) +
  9375. + chunk_size);
  9376. +
  9377. + chunk_num =
  9378. + (page_to_phys(chunk) - vc_cma_base) / VC_CMA_CHUNK_SIZE;
  9379. + BUG_ON(((page_to_phys(chunk) - vc_cma_base) %
  9380. + VC_CMA_CHUNK_SIZE) != 0);
  9381. + if (chunk_num >= vc_cma_chunks) {
  9382. + LOG_ERR("%s: ===============================",
  9383. + __func__);
  9384. + LOG_ERR("%s: chunk phys %x, vc_cma %x-%x - "
  9385. + "bad SPARSEMEM configuration?",
  9386. + __func__, (unsigned int)page_to_phys(chunk),
  9387. + vc_cma_base, vc_cma_base + vc_cma_size - 1);
  9388. + LOG_ERR("%s: dev->cma_area = %p\n", __func__,
  9389. + (void*)0/*vc_cma_device.dev.cma_area*/);
  9390. + LOG_ERR("%s: ===============================",
  9391. + __func__);
  9392. + break;
  9393. + }
  9394. + reply->params[i] = chunk_num;
  9395. + vc_cma_chunks_used++;
  9396. + }
  9397. +
  9398. + if (i < num_chunks) {
  9399. + LOG_ERR("%s: dma_alloc_from_contiguous failed "
  9400. + "for %x bytes (alloc %d of %d, %d free)",
  9401. + __func__, VC_CMA_CHUNK_SIZE, i,
  9402. + num_chunks, vc_cma_chunks - vc_cma_chunks_used);
  9403. + num_chunks = i;
  9404. + }
  9405. +
  9406. + LOG_DBG("CMA allocated %d chunks -> %d used",
  9407. + num_chunks, vc_cma_chunks_used);
  9408. + reply->type = VC_CMA_MSG_ALLOCATED;
  9409. +
  9410. + {
  9411. + VCHIQ_ELEMENT_T elem = {
  9412. + reply,
  9413. + offsetof(struct cma_msg, params[0]) +
  9414. + num_chunks * sizeof(reply->params[0])
  9415. + };
  9416. + VCHIQ_STATUS_T ret;
  9417. + vchiq_use_service(cma_service);
  9418. + ret = vchiq_queue_message(cma_service, &elem, 1);
  9419. + vchiq_release_service(cma_service);
  9420. + if (ret != VCHIQ_SUCCESS)
  9421. + LOG_ERR("vchiq_queue_message return " "%x", ret);
  9422. + }
  9423. +
  9424. + return num_chunks;
  9425. +}
  9426. +
  9427. +static int cma_worker_proc(void *param)
  9428. +{
  9429. + static struct cma_msg reply;
  9430. + (void)param;
  9431. +
  9432. + while (1) {
  9433. + VCHIQ_HEADER_T *msg;
  9434. + static struct cma_msg msg_copy;
  9435. + struct cma_msg *cma_msg = &msg_copy;
  9436. + int type, msg_size;
  9437. +
  9438. + msg = vchiu_queue_pop(&cma_msg_queue);
  9439. + if ((unsigned int)msg >= VC_CMA_MSG_MAX) {
  9440. + msg_size = msg->size;
  9441. + memcpy(&msg_copy, msg->data, msg_size);
  9442. + type = cma_msg->type;
  9443. + vchiq_release_message(cma_service, msg);
  9444. + } else {
  9445. + msg_size = 0;
  9446. + type = (int)msg;
  9447. + if (type == VC_CMA_MSG_QUIT)
  9448. + break;
  9449. + else if (type == VC_CMA_MSG_UPDATE_RESERVE) {
  9450. + msg = NULL;
  9451. + cma_msg = NULL;
  9452. + } else {
  9453. + BUG();
  9454. + continue;
  9455. + }
  9456. + }
  9457. +
  9458. + switch (type) {
  9459. + case VC_CMA_MSG_ALLOC:{
  9460. + int num_chunks, free_chunks;
  9461. + num_chunks = cma_msg->params[0];
  9462. + free_chunks =
  9463. + vc_cma_chunks - vc_cma_chunks_used;
  9464. + LOG_DBG("CMA_MSG_ALLOC(%d chunks)", num_chunks);
  9465. + if (num_chunks > VC_CMA_MAX_PARAMS_PER_MSG) {
  9466. + LOG_ERR
  9467. + ("CMA_MSG_ALLOC - chunk count (%d) "
  9468. + "exceeds VC_CMA_MAX_PARAMS_PER_MSG (%d)",
  9469. + num_chunks,
  9470. + VC_CMA_MAX_PARAMS_PER_MSG);
  9471. + num_chunks = VC_CMA_MAX_PARAMS_PER_MSG;
  9472. + }
  9473. +
  9474. + if (num_chunks > free_chunks) {
  9475. + LOG_ERR
  9476. + ("CMA_MSG_ALLOC - chunk count (%d) "
  9477. + "exceeds free chunks (%d)",
  9478. + num_chunks, free_chunks);
  9479. + num_chunks = free_chunks;
  9480. + }
  9481. +
  9482. + vc_cma_alloc_chunks(num_chunks, &reply);
  9483. + }
  9484. + break;
  9485. +
  9486. + case VC_CMA_MSG_FREE:{
  9487. + int chunk_count =
  9488. + (msg_size -
  9489. + offsetof(struct cma_msg,
  9490. + params)) /
  9491. + sizeof(cma_msg->params[0]);
  9492. + int i;
  9493. + BUG_ON(chunk_count <= 0);
  9494. +
  9495. + LOG_DBG("CMA_MSG_FREE(%d chunks - %x, ...)",
  9496. + chunk_count, cma_msg->params[0]);
  9497. + for (i = 0; i < chunk_count; i++) {
  9498. + int chunk_num = cma_msg->params[i];
  9499. + struct page *page = vc_cma_base_page +
  9500. + chunk_num * PAGES_PER_CHUNK;
  9501. + if (chunk_num >= vc_cma_chunks) {
  9502. + LOG_ERR
  9503. + ("CMA_MSG_FREE - chunk %d of %d"
  9504. + " (value %x) exceeds maximum "
  9505. + "(%x)", i, chunk_count,
  9506. + chunk_num,
  9507. + vc_cma_chunks - 1);
  9508. + break;
  9509. + }
  9510. +
  9511. + if (!dma_release_from_contiguous
  9512. + (NULL /*&vc_cma_device.dev*/, page,
  9513. + PAGES_PER_CHUNK)) {
  9514. + LOG_ERR
  9515. + ("CMA_MSG_FREE - failed to "
  9516. + "release chunk %d (phys %x, "
  9517. + "page %x)", chunk_num,
  9518. + page_to_phys(page),
  9519. + (unsigned int)page);
  9520. + }
  9521. + vc_cma_chunks_used--;
  9522. + }
  9523. + LOG_DBG("CMA released %d chunks -> %d used",
  9524. + i, vc_cma_chunks_used);
  9525. + }
  9526. + break;
  9527. +
  9528. + case VC_CMA_MSG_UPDATE_RESERVE:{
  9529. + int chunks_needed =
  9530. + ((vc_cma_reserve_total + VC_CMA_CHUNK_SIZE -
  9531. + 1)
  9532. + / VC_CMA_CHUNK_SIZE) -
  9533. + vc_cma_chunks_reserved;
  9534. +
  9535. + LOG_DBG
  9536. + ("CMA_MSG_UPDATE_RESERVE(%d chunks needed)",
  9537. + chunks_needed);
  9538. +
  9539. + /* Cap the reservations to what is available */
  9540. + if (chunks_needed > 0) {
  9541. + if (chunks_needed >
  9542. + (vc_cma_chunks -
  9543. + vc_cma_chunks_used))
  9544. + chunks_needed =
  9545. + (vc_cma_chunks -
  9546. + vc_cma_chunks_used);
  9547. +
  9548. + chunks_needed =
  9549. + vc_cma_alloc_chunks(chunks_needed,
  9550. + &reply);
  9551. + }
  9552. +
  9553. + LOG_DBG
  9554. + ("CMA_MSG_UPDATE_RESERVE(%d chunks allocated)",
  9555. + chunks_needed);
  9556. + vc_cma_chunks_reserved += chunks_needed;
  9557. + }
  9558. + break;
  9559. +
  9560. + default:
  9561. + LOG_ERR("unexpected msg type %d", type);
  9562. + break;
  9563. + }
  9564. + }
  9565. +
  9566. + LOG_DBG("quitting...");
  9567. + return 0;
  9568. +}
  9569. +
  9570. +/****************************************************************************
  9571. +*
  9572. +* vc_cma_connected_init
  9573. +*
  9574. +* This function is called once the videocore has been connected.
  9575. +*
  9576. +***************************************************************************/
  9577. +
  9578. +static void vc_cma_connected_init(void)
  9579. +{
  9580. + VCHIQ_SERVICE_PARAMS_T service_params;
  9581. +
  9582. + LOG_DBG("vc_cma_connected_init");
  9583. +
  9584. + if (!vchiu_queue_init(&cma_msg_queue, 16)) {
  9585. + LOG_ERR("could not create CMA msg queue");
  9586. + goto fail_queue;
  9587. + }
  9588. +
  9589. + if (vchiq_initialise(&cma_instance) != VCHIQ_SUCCESS)
  9590. + goto fail_vchiq_init;
  9591. +
  9592. + vchiq_connect(cma_instance);
  9593. +
  9594. + service_params.fourcc = VC_CMA_FOURCC;
  9595. + service_params.callback = cma_service_callback;
  9596. + service_params.userdata = NULL;
  9597. + service_params.version = VC_CMA_VERSION;
  9598. + service_params.version_min = VC_CMA_VERSION;
  9599. +
  9600. + if (vchiq_open_service(cma_instance, &service_params,
  9601. + &cma_service) != VCHIQ_SUCCESS) {
  9602. + LOG_ERR("failed to open service - already in use?");
  9603. + goto fail_vchiq_open;
  9604. + }
  9605. +
  9606. + vchiq_release_service(cma_service);
  9607. +
  9608. + cma_worker = kthread_create(cma_worker_proc, NULL, "cma_worker");
  9609. + if (!cma_worker) {
  9610. + LOG_ERR("could not create CMA worker thread");
  9611. + goto fail_worker;
  9612. + }
  9613. + set_user_nice(cma_worker, -20);
  9614. + wake_up_process(cma_worker);
  9615. +
  9616. + return;
  9617. +
  9618. +fail_worker:
  9619. + vchiq_close_service(cma_service);
  9620. +fail_vchiq_open:
  9621. + vchiq_shutdown(cma_instance);
  9622. +fail_vchiq_init:
  9623. + vchiu_queue_delete(&cma_msg_queue);
  9624. +fail_queue:
  9625. + return;
  9626. +}
  9627. +
  9628. +void
  9629. +loud_error_header(void)
  9630. +{
  9631. + if (in_loud_error)
  9632. + return;
  9633. +
  9634. + LOG_ERR("============================================================"
  9635. + "================");
  9636. + LOG_ERR("============================================================"
  9637. + "================");
  9638. + LOG_ERR("=====");
  9639. +
  9640. + in_loud_error = 1;
  9641. +}
  9642. +
  9643. +void
  9644. +loud_error_footer(void)
  9645. +{
  9646. + if (!in_loud_error)
  9647. + return;
  9648. +
  9649. + LOG_ERR("=====");
  9650. + LOG_ERR("============================================================"
  9651. + "================");
  9652. + LOG_ERR("============================================================"
  9653. + "================");
  9654. +
  9655. + in_loud_error = 0;
  9656. +}
  9657. +
  9658. +#if 1
  9659. +static int check_cma_config(void) { return 1; }
  9660. +#else
  9661. +static int
  9662. +read_vc_debug_var(VC_MEM_ACCESS_HANDLE_T handle,
  9663. + const char *symbol,
  9664. + void *buf, size_t bufsize)
  9665. +{
  9666. + VC_MEM_ADDR_T vcMemAddr;
  9667. + size_t vcMemSize;
  9668. + uint8_t *mapAddr;
  9669. + off_t vcMapAddr;
  9670. +
  9671. + if (!LookupVideoCoreSymbol(handle, symbol,
  9672. + &vcMemAddr,
  9673. + &vcMemSize)) {
  9674. + loud_error_header();
  9675. + loud_error(
  9676. + "failed to find VC symbol \"%s\".",
  9677. + symbol);
  9678. + loud_error_footer();
  9679. + return 0;
  9680. + }
  9681. +
  9682. + if (vcMemSize != bufsize) {
  9683. + loud_error_header();
  9684. + loud_error(
  9685. + "VC symbol \"%s\" is the wrong size.",
  9686. + symbol);
  9687. + loud_error_footer();
  9688. + return 0;
  9689. + }
  9690. +
  9691. + vcMapAddr = (off_t)vcMemAddr & VC_MEM_TO_ARM_ADDR_MASK;
  9692. + vcMapAddr += mm_vc_mem_phys_addr;
  9693. + mapAddr = ioremap_nocache(vcMapAddr, vcMemSize);
  9694. + if (mapAddr == 0) {
  9695. + loud_error_header();
  9696. + loud_error(
  9697. + "failed to ioremap \"%s\" @ 0x%x "
  9698. + "(phys: 0x%x, size: %u).",
  9699. + symbol,
  9700. + (unsigned int)vcMapAddr,
  9701. + (unsigned int)vcMemAddr,
  9702. + (unsigned int)vcMemSize);
  9703. + loud_error_footer();
  9704. + return 0;
  9705. + }
  9706. +
  9707. + memcpy(buf, mapAddr, bufsize);
  9708. + iounmap(mapAddr);
  9709. +
  9710. + return 1;
  9711. +}
  9712. +
  9713. +
  9714. +static int
  9715. +check_cma_config(void)
  9716. +{
  9717. + VC_MEM_ACCESS_HANDLE_T mem_hndl;
  9718. + VC_MEM_ADDR_T mempool_start;
  9719. + VC_MEM_ADDR_T mempool_end;
  9720. + VC_MEM_ADDR_T mempool_offline_start;
  9721. + VC_MEM_ADDR_T mempool_offline_end;
  9722. + VC_MEM_ADDR_T cam_alloc_base;
  9723. + VC_MEM_ADDR_T cam_alloc_size;
  9724. + VC_MEM_ADDR_T cam_alloc_end;
  9725. + int success = 0;
  9726. +
  9727. + if (OpenVideoCoreMemory(&mem_hndl) != 0)
  9728. + goto out;
  9729. +
  9730. + /* Read the relevant VideoCore variables */
  9731. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_START",
  9732. + &mempool_start,
  9733. + sizeof(mempool_start)))
  9734. + goto close;
  9735. +
  9736. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_END",
  9737. + &mempool_end,
  9738. + sizeof(mempool_end)))
  9739. + goto close;
  9740. +
  9741. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_OFFLINE_START",
  9742. + &mempool_offline_start,
  9743. + sizeof(mempool_offline_start)))
  9744. + goto close;
  9745. +
  9746. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_OFFLINE_END",
  9747. + &mempool_offline_end,
  9748. + sizeof(mempool_offline_end)))
  9749. + goto close;
  9750. +
  9751. + if (!read_vc_debug_var(mem_hndl, "cam_alloc_base",
  9752. + &cam_alloc_base,
  9753. + sizeof(cam_alloc_base)))
  9754. + goto close;
  9755. +
  9756. + if (!read_vc_debug_var(mem_hndl, "cam_alloc_size",
  9757. + &cam_alloc_size,
  9758. + sizeof(cam_alloc_size)))
  9759. + goto close;
  9760. +
  9761. + cam_alloc_end = cam_alloc_base + cam_alloc_size;
  9762. +
  9763. + success = 1;
  9764. +
  9765. + /* Now the sanity checks */
  9766. + if (!mempool_offline_start)
  9767. + mempool_offline_start = mempool_start;
  9768. + if (!mempool_offline_end)
  9769. + mempool_offline_end = mempool_end;
  9770. +
  9771. + if (VCADDR_TO_PHYSADDR(mempool_offline_start) != vc_cma_base) {
  9772. + loud_error_header();
  9773. + loud_error(
  9774. + "__MEMPOOL_OFFLINE_START(%x -> %lx) doesn't match "
  9775. + "vc_cma_base(%x)",
  9776. + mempool_offline_start,
  9777. + VCADDR_TO_PHYSADDR(mempool_offline_start),
  9778. + vc_cma_base);
  9779. + success = 0;
  9780. + }
  9781. +
  9782. + if (VCADDR_TO_PHYSADDR(mempool_offline_end) !=
  9783. + (vc_cma_base + vc_cma_size)) {
  9784. + loud_error_header();
  9785. + loud_error(
  9786. + "__MEMPOOL_OFFLINE_END(%x -> %lx) doesn't match "
  9787. + "vc_cma_base(%x) + vc_cma_size(%x) = %x",
  9788. + mempool_offline_start,
  9789. + VCADDR_TO_PHYSADDR(mempool_offline_end),
  9790. + vc_cma_base, vc_cma_size, vc_cma_base + vc_cma_size);
  9791. + success = 0;
  9792. + }
  9793. +
  9794. + if (mempool_end < mempool_start) {
  9795. + loud_error_header();
  9796. + loud_error(
  9797. + "__MEMPOOL_END(%x) must not be before "
  9798. + "__MEMPOOL_START(%x)",
  9799. + mempool_end,
  9800. + mempool_start);
  9801. + success = 0;
  9802. + }
  9803. +
  9804. + if (mempool_offline_end < mempool_offline_start) {
  9805. + loud_error_header();
  9806. + loud_error(
  9807. + "__MEMPOOL_OFFLINE_END(%x) must not be before "
  9808. + "__MEMPOOL_OFFLINE_START(%x)",
  9809. + mempool_offline_end,
  9810. + mempool_offline_start);
  9811. + success = 0;
  9812. + }
  9813. +
  9814. + if (mempool_offline_start < mempool_start) {
  9815. + loud_error_header();
  9816. + loud_error(
  9817. + "__MEMPOOL_OFFLINE_START(%x) must not be before "
  9818. + "__MEMPOOL_START(%x)",
  9819. + mempool_offline_start,
  9820. + mempool_start);
  9821. + success = 0;
  9822. + }
  9823. +
  9824. + if (mempool_offline_end > mempool_end) {
  9825. + loud_error_header();
  9826. + loud_error(
  9827. + "__MEMPOOL_OFFLINE_END(%x) must not be after "
  9828. + "__MEMPOOL_END(%x)",
  9829. + mempool_offline_end,
  9830. + mempool_end);
  9831. + success = 0;
  9832. + }
  9833. +
  9834. + if ((cam_alloc_base < mempool_end) &&
  9835. + (cam_alloc_end > mempool_start)) {
  9836. + loud_error_header();
  9837. + loud_error(
  9838. + "cam_alloc pool(%x-%x) overlaps "
  9839. + "mempool(%x-%x)",
  9840. + cam_alloc_base, cam_alloc_end,
  9841. + mempool_start, mempool_end);
  9842. + success = 0;
  9843. + }
  9844. +
  9845. + loud_error_footer();
  9846. +
  9847. +close:
  9848. + CloseVideoCoreMemory(mem_hndl);
  9849. +
  9850. +out:
  9851. + return success;
  9852. +}
  9853. +#endif
  9854. +
  9855. +static int vc_cma_init(void)
  9856. +{
  9857. + int rc = -EFAULT;
  9858. + struct device *dev;
  9859. +
  9860. + if (!check_cma_config())
  9861. + goto out_release;
  9862. +
  9863. + printk(KERN_INFO "vc-cma: Videocore CMA driver\n");
  9864. + printk(KERN_INFO "vc-cma: vc_cma_base = 0x%08x\n", vc_cma_base);
  9865. + printk(KERN_INFO "vc-cma: vc_cma_size = 0x%08x (%u MiB)\n",
  9866. + vc_cma_size, vc_cma_size / (1024 * 1024));
  9867. + printk(KERN_INFO "vc-cma: vc_cma_initial = 0x%08x (%u MiB)\n",
  9868. + vc_cma_initial, vc_cma_initial / (1024 * 1024));
  9869. +
  9870. + vc_cma_base_page = phys_to_page(vc_cma_base);
  9871. +
  9872. + if (vc_cma_chunks) {
  9873. + int chunks_needed = vc_cma_initial / VC_CMA_CHUNK_SIZE;
  9874. +
  9875. + for (vc_cma_chunks_used = 0;
  9876. + vc_cma_chunks_used < chunks_needed; vc_cma_chunks_used++) {
  9877. + struct page *chunk;
  9878. + chunk = dma_alloc_from_contiguous(NULL /*&vc_cma_device.dev*/,
  9879. + PAGES_PER_CHUNK,
  9880. + VC_CMA_CHUNK_ORDER);
  9881. + if (!chunk)
  9882. + break;
  9883. + BUG_ON(((page_to_phys(chunk) - vc_cma_base) %
  9884. + VC_CMA_CHUNK_SIZE) != 0);
  9885. + }
  9886. + if (vc_cma_chunks_used != chunks_needed) {
  9887. + LOG_ERR("%s: dma_alloc_from_contiguous failed (%d "
  9888. + "bytes, allocation %d of %d)",
  9889. + __func__, VC_CMA_CHUNK_SIZE,
  9890. + vc_cma_chunks_used, chunks_needed);
  9891. + goto out_release;
  9892. + }
  9893. +
  9894. + vchiq_add_connected_callback(vc_cma_connected_init);
  9895. + }
  9896. +
  9897. + rc = alloc_chrdev_region(&vc_cma_devnum, 0, 1, DRIVER_NAME);
  9898. + if (rc < 0) {
  9899. + LOG_ERR("%s: alloc_chrdev_region failed (rc=%d)", __func__, rc);
  9900. + goto out_release;
  9901. + }
  9902. +
  9903. + cdev_init(&vc_cma_cdev, &vc_cma_fops);
  9904. + rc = cdev_add(&vc_cma_cdev, vc_cma_devnum, 1);
  9905. + if (rc != 0) {
  9906. + LOG_ERR("%s: cdev_add failed (rc=%d)", __func__, rc);
  9907. + goto out_unregister;
  9908. + }
  9909. +
  9910. + vc_cma_class = class_create(THIS_MODULE, DRIVER_NAME);
  9911. + if (IS_ERR(vc_cma_class)) {
  9912. + rc = PTR_ERR(vc_cma_class);
  9913. + LOG_ERR("%s: class_create failed (rc=%d)", __func__, rc);
  9914. + goto out_cdev_del;
  9915. + }
  9916. +
  9917. + dev = device_create(vc_cma_class, NULL, vc_cma_devnum, NULL,
  9918. + DRIVER_NAME);
  9919. + if (IS_ERR(dev)) {
  9920. + rc = PTR_ERR(dev);
  9921. + LOG_ERR("%s: device_create failed (rc=%d)", __func__, rc);
  9922. + goto out_class_destroy;
  9923. + }
  9924. +
  9925. + vc_cma_proc_entry = proc_create(DRIVER_NAME, 0444, NULL, &vc_cma_proc_fops);
  9926. + if (vc_cma_proc_entry == NULL) {
  9927. + rc = -EFAULT;
  9928. + LOG_ERR("%s: proc_create failed", __func__);
  9929. + goto out_device_destroy;
  9930. + }
  9931. +
  9932. + vc_cma_inited = 1;
  9933. + return 0;
  9934. +
  9935. +out_device_destroy:
  9936. + device_destroy(vc_cma_class, vc_cma_devnum);
  9937. +
  9938. +out_class_destroy:
  9939. + class_destroy(vc_cma_class);
  9940. + vc_cma_class = NULL;
  9941. +
  9942. +out_cdev_del:
  9943. + cdev_del(&vc_cma_cdev);
  9944. +
  9945. +out_unregister:
  9946. + unregister_chrdev_region(vc_cma_devnum, 1);
  9947. +
  9948. +out_release:
  9949. + /* It is tempting to try to clean up by calling
  9950. + dma_release_from_contiguous for all allocated chunks, but it isn't
  9951. + a very safe thing to do. If vc_cma_initial is non-zero it is because
  9952. + VideoCore is already using that memory, so giving it back to Linux
  9953. + is likely to be fatal.
  9954. + */
  9955. + return -1;
  9956. +}
  9957. +
  9958. +/****************************************************************************
  9959. +*
  9960. +* vc_cma_exit
  9961. +*
  9962. +***************************************************************************/
  9963. +
  9964. +static void __exit vc_cma_exit(void)
  9965. +{
  9966. + LOG_DBG("%s: called", __func__);
  9967. +
  9968. + if (vc_cma_inited) {
  9969. + remove_proc_entry(DRIVER_NAME, NULL);
  9970. + device_destroy(vc_cma_class, vc_cma_devnum);
  9971. + class_destroy(vc_cma_class);
  9972. + cdev_del(&vc_cma_cdev);
  9973. + unregister_chrdev_region(vc_cma_devnum, 1);
  9974. + }
  9975. +}
  9976. +
  9977. +module_init(vc_cma_init);
  9978. +module_exit(vc_cma_exit);
  9979. +MODULE_LICENSE("GPL");
  9980. +MODULE_AUTHOR("Broadcom Corporation");
  9981. diff -Nur linux-3.15.4/drivers/char/hw_random/bcm2708-rng.c linux-rpi/drivers/char/hw_random/bcm2708-rng.c
  9982. --- linux-3.15.4/drivers/char/hw_random/bcm2708-rng.c 1970-01-01 01:00:00.000000000 +0100
  9983. +++ linux-rpi/drivers/char/hw_random/bcm2708-rng.c 2014-07-07 10:45:00.000000000 +0200
  9984. @@ -0,0 +1,118 @@
  9985. +/**
  9986. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  9987. + *
  9988. + * Redistribution and use in source and binary forms, with or without
  9989. + * modification, are permitted provided that the following conditions
  9990. + * are met:
  9991. + * 1. Redistributions of source code must retain the above copyright
  9992. + * notice, this list of conditions, and the following disclaimer,
  9993. + * without modification.
  9994. + * 2. Redistributions in binary form must reproduce the above copyright
  9995. + * notice, this list of conditions and the following disclaimer in the
  9996. + * documentation and/or other materials provided with the distribution.
  9997. + * 3. The names of the above-listed copyright holders may not be used
  9998. + * to endorse or promote products derived from this software without
  9999. + * specific prior written permission.
  10000. + *
  10001. + * ALTERNATIVELY, this software may be distributed under the terms of the
  10002. + * GNU General Public License ("GPL") version 2, as published by the Free
  10003. + * Software Foundation.
  10004. + *
  10005. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  10006. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  10007. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  10008. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  10009. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  10010. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  10011. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  10012. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  10013. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  10014. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  10015. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  10016. + */
  10017. +
  10018. +#include <linux/kernel.h>
  10019. +#include <linux/module.h>
  10020. +#include <linux/init.h>
  10021. +#include <linux/hw_random.h>
  10022. +#include <linux/printk.h>
  10023. +
  10024. +#include <asm/io.h>
  10025. +#include <mach/hardware.h>
  10026. +#include <mach/platform.h>
  10027. +
  10028. +#define RNG_CTRL (0x0)
  10029. +#define RNG_STATUS (0x4)
  10030. +#define RNG_DATA (0x8)
  10031. +#define RNG_FF_THRESHOLD (0xc)
  10032. +
  10033. +/* enable rng */
  10034. +#define RNG_RBGEN 0x1
  10035. +/* double speed, less random mode */
  10036. +#define RNG_RBG2X 0x2
  10037. +
  10038. +/* the initial numbers generated are "less random" so will be discarded */
  10039. +#define RNG_WARMUP_COUNT 0x40000
  10040. +
  10041. +static int bcm2708_rng_data_read(struct hwrng *rng, u32 *buffer)
  10042. +{
  10043. + void __iomem *rng_base = (void __iomem *)rng->priv;
  10044. + unsigned words;
  10045. + /* wait for a random number to be in fifo */
  10046. + do {
  10047. + words = __raw_readl(rng_base + RNG_STATUS)>>24;
  10048. + }
  10049. + while (words == 0);
  10050. + /* read the random number */
  10051. + *buffer = __raw_readl(rng_base + RNG_DATA);
  10052. + return 4;
  10053. +}
  10054. +
  10055. +static struct hwrng bcm2708_rng_ops = {
  10056. + .name = "bcm2708",
  10057. + .data_read = bcm2708_rng_data_read,
  10058. +};
  10059. +
  10060. +static int __init bcm2708_rng_init(void)
  10061. +{
  10062. + void __iomem *rng_base;
  10063. + int err;
  10064. +
  10065. + /* map peripheral */
  10066. + rng_base = ioremap(RNG_BASE, 0x10);
  10067. + pr_info("bcm2708_rng_init=%p\n", rng_base);
  10068. + if (!rng_base) {
  10069. + pr_err("bcm2708_rng_init failed to ioremap\n");
  10070. + return -ENOMEM;
  10071. + }
  10072. + bcm2708_rng_ops.priv = (unsigned long)rng_base;
  10073. +
  10074. + /* set warm-up count & enable */
  10075. + __raw_writel(RNG_WARMUP_COUNT, rng_base + RNG_STATUS);
  10076. + __raw_writel(RNG_RBGEN, rng_base + RNG_CTRL);
  10077. +
  10078. + /* register driver */
  10079. + err = hwrng_register(&bcm2708_rng_ops);
  10080. + if (err) {
  10081. + pr_err("bcm2708_rng_init hwrng_register()=%d\n", err);
  10082. + iounmap(rng_base);
  10083. + }
  10084. + return err;
  10085. +}
  10086. +
  10087. +static void __exit bcm2708_rng_exit(void)
  10088. +{
  10089. + void __iomem *rng_base = (void __iomem *)bcm2708_rng_ops.priv;
  10090. + pr_info("bcm2708_rng_exit\n");
  10091. + /* disable rng hardware */
  10092. + __raw_writel(0, rng_base + RNG_CTRL);
  10093. + /* unregister driver */
  10094. + hwrng_unregister(&bcm2708_rng_ops);
  10095. + iounmap(rng_base);
  10096. +}
  10097. +
  10098. +module_init(bcm2708_rng_init);
  10099. +module_exit(bcm2708_rng_exit);
  10100. +
  10101. +MODULE_DESCRIPTION("BCM2708 H/W Random Number Generator (RNG) driver");
  10102. +MODULE_LICENSE("GPL and additional rights");
  10103. diff -Nur linux-3.15.4/drivers/char/hw_random/Kconfig linux-rpi/drivers/char/hw_random/Kconfig
  10104. --- linux-3.15.4/drivers/char/hw_random/Kconfig 2014-07-07 03:59:25.000000000 +0200
  10105. +++ linux-rpi/drivers/char/hw_random/Kconfig 2014-07-07 10:45:00.000000000 +0200
  10106. @@ -341,6 +341,17 @@
  10107. If unsure, say Y.
  10108. +config HW_RANDOM_BCM2708
  10109. + tristate "BCM2708 generic true random number generator support"
  10110. + depends on HW_RANDOM && ARCH_BCM2708
  10111. + ---help---
  10112. + This driver provides the kernel-side support for the BCM2708 hardware.
  10113. +
  10114. + To compile this driver as a module, choose M here: the
  10115. + module will be called bcm2708-rng.
  10116. +
  10117. + If unsure, say N.
  10118. +
  10119. config HW_RANDOM_MSM
  10120. tristate "Qualcomm SoCs Random Number Generator support"
  10121. depends on HW_RANDOM && ARCH_QCOM
  10122. diff -Nur linux-3.15.4/drivers/char/hw_random/Makefile linux-rpi/drivers/char/hw_random/Makefile
  10123. --- linux-3.15.4/drivers/char/hw_random/Makefile 2014-07-07 03:59:25.000000000 +0200
  10124. +++ linux-rpi/drivers/char/hw_random/Makefile 2014-07-07 10:45:00.000000000 +0200
  10125. @@ -29,4 +29,5 @@
  10126. obj-$(CONFIG_HW_RANDOM_EXYNOS) += exynos-rng.o
  10127. obj-$(CONFIG_HW_RANDOM_TPM) += tpm-rng.o
  10128. obj-$(CONFIG_HW_RANDOM_BCM2835) += bcm2835-rng.o
  10129. +obj-$(CONFIG_HW_RANDOM_BCM2708) += bcm2708-rng.o
  10130. obj-$(CONFIG_HW_RANDOM_MSM) += msm-rng.o
  10131. diff -Nur linux-3.15.4/drivers/char/Kconfig linux-rpi/drivers/char/Kconfig
  10132. --- linux-3.15.4/drivers/char/Kconfig 2014-07-07 03:59:25.000000000 +0200
  10133. +++ linux-rpi/drivers/char/Kconfig 2014-07-07 10:45:00.000000000 +0200
  10134. @@ -581,6 +581,8 @@
  10135. source "drivers/s390/char/Kconfig"
  10136. +source "drivers/char/broadcom/Kconfig"
  10137. +
  10138. config MSM_SMD_PKT
  10139. bool "Enable device interface for some SMD packet ports"
  10140. default n
  10141. diff -Nur linux-3.15.4/drivers/char/Makefile linux-rpi/drivers/char/Makefile
  10142. --- linux-3.15.4/drivers/char/Makefile 2014-07-07 03:59:25.000000000 +0200
  10143. +++ linux-rpi/drivers/char/Makefile 2014-07-07 10:45:00.000000000 +0200
  10144. @@ -61,3 +61,5 @@
  10145. js-rtc-y = rtc.o
  10146. obj-$(CONFIG_TILE_SROM) += tile-srom.o
  10147. +
  10148. +obj-$(CONFIG_BRCM_CHAR_DRIVERS) += broadcom/
  10149. diff -Nur linux-3.15.4/drivers/cpufreq/bcm2835-cpufreq.c linux-rpi/drivers/cpufreq/bcm2835-cpufreq.c
  10150. --- linux-3.15.4/drivers/cpufreq/bcm2835-cpufreq.c 1970-01-01 01:00:00.000000000 +0100
  10151. +++ linux-rpi/drivers/cpufreq/bcm2835-cpufreq.c 2014-07-07 10:45:00.000000000 +0200
  10152. @@ -0,0 +1,239 @@
  10153. +/*****************************************************************************
  10154. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  10155. +*
  10156. +* Unless you and Broadcom execute a separate written software license
  10157. +* agreement governing use of this software, this software is licensed to you
  10158. +* under the terms of the GNU General Public License version 2, available at
  10159. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  10160. +*
  10161. +* Notwithstanding the above, under no circumstances may you combine this
  10162. +* software in any way with any other Broadcom software provided under a
  10163. +* license other than the GPL, without Broadcom's express prior written
  10164. +* consent.
  10165. +*****************************************************************************/
  10166. +
  10167. +/*****************************************************************************
  10168. +* FILENAME: bcm2835-cpufreq.h
  10169. +* DESCRIPTION: This driver dynamically manages the CPU Frequency of the ARM
  10170. +* processor. Messages are sent to Videocore either setting or requesting the
  10171. +* frequency of the ARM in order to match an appropiate frequency to the current
  10172. +* usage of the processor. The policy which selects the frequency to use is
  10173. +* defined in the kernel .config file, but can be changed during runtime.
  10174. +*****************************************************************************/
  10175. +
  10176. +/* ---------- INCLUDES ---------- */
  10177. +#include <linux/kernel.h>
  10178. +#include <linux/init.h>
  10179. +#include <linux/module.h>
  10180. +#include <linux/cpufreq.h>
  10181. +#include <mach/vcio.h>
  10182. +
  10183. +/* ---------- DEFINES ---------- */
  10184. +/*#define CPUFREQ_DEBUG_ENABLE*/ /* enable debugging */
  10185. +#define MODULE_NAME "bcm2835-cpufreq"
  10186. +
  10187. +#define VCMSG_ID_ARM_CLOCK 0x000000003 /* Clock/Voltage ID's */
  10188. +
  10189. +/* debug printk macros */
  10190. +#ifdef CPUFREQ_DEBUG_ENABLE
  10191. +#define print_debug(fmt,...) pr_debug("%s:%s:%d: "fmt, MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  10192. +#else
  10193. +#define print_debug(fmt,...)
  10194. +#endif
  10195. +#define print_err(fmt,...) pr_err("%s:%s:%d: "fmt, MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  10196. +#define print_info(fmt,...) pr_info("%s: "fmt, MODULE_NAME, ##__VA_ARGS__)
  10197. +
  10198. +/* tag part of the message */
  10199. +struct vc_msg_tag {
  10200. + uint32_t tag_id; /* the message id */
  10201. + uint32_t buffer_size; /* size of the buffer (which in this case is always 8 bytes) */
  10202. + uint32_t data_size; /* amount of data being sent or received */
  10203. + uint32_t dev_id; /* the ID of the clock/voltage to get or set */
  10204. + uint32_t val; /* the value (e.g. rate (in Hz)) to set */
  10205. +};
  10206. +
  10207. +/* message structure to be sent to videocore */
  10208. +struct vc_msg {
  10209. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  10210. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  10211. + struct vc_msg_tag tag; /* the tag structure above to make */
  10212. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  10213. +};
  10214. +
  10215. +/* ---------- GLOBALS ---------- */
  10216. +static struct cpufreq_driver bcm2835_cpufreq_driver; /* the cpufreq driver global */
  10217. +
  10218. +/*
  10219. + ===============================================
  10220. + clk_rate either gets or sets the clock rates.
  10221. + ===============================================
  10222. +*/
  10223. +static uint32_t bcm2835_cpufreq_set_clock(int cur_rate, int arm_rate)
  10224. +{
  10225. + int s, actual_rate=0;
  10226. + struct vc_msg msg;
  10227. +
  10228. + /* wipe all previous message data */
  10229. + memset(&msg, 0, sizeof msg);
  10230. +
  10231. + msg.msg_size = sizeof msg;
  10232. +
  10233. + msg.tag.tag_id = VCMSG_SET_CLOCK_RATE;
  10234. + msg.tag.buffer_size = 8;
  10235. + msg.tag.data_size = 8; /* we're sending the clock ID and the new rates which is a total of 2 words */
  10236. + msg.tag.dev_id = VCMSG_ID_ARM_CLOCK;
  10237. + msg.tag.val = arm_rate * 1000;
  10238. +
  10239. + /* send the message */
  10240. + s = bcm_mailbox_property(&msg, sizeof msg);
  10241. +
  10242. + /* check if it was all ok and return the rate in KHz */
  10243. + if (s == 0 && (msg.request_code & 0x80000000))
  10244. + actual_rate = msg.tag.val/1000;
  10245. +
  10246. + print_debug("Setting new frequency = %d -> %d (actual %d)\n", cur_rate, arm_rate, actual_rate);
  10247. + return actual_rate;
  10248. +}
  10249. +
  10250. +static uint32_t bcm2835_cpufreq_get_clock(int tag)
  10251. +{
  10252. + int s;
  10253. + int arm_rate = 0;
  10254. + struct vc_msg msg;
  10255. +
  10256. + /* wipe all previous message data */
  10257. + memset(&msg, 0, sizeof msg);
  10258. +
  10259. + msg.msg_size = sizeof msg;
  10260. + msg.tag.tag_id = tag;
  10261. + msg.tag.buffer_size = 8;
  10262. + msg.tag.data_size = 4; /* we're just sending the clock ID which is one word long */
  10263. + msg.tag.dev_id = VCMSG_ID_ARM_CLOCK;
  10264. +
  10265. + /* send the message */
  10266. + s = bcm_mailbox_property(&msg, sizeof msg);
  10267. +
  10268. + /* check if it was all ok and return the rate in KHz */
  10269. + if (s == 0 && (msg.request_code & 0x80000000))
  10270. + arm_rate = msg.tag.val/1000;
  10271. +
  10272. + print_debug("%s frequency = %d\n",
  10273. + tag == VCMSG_GET_CLOCK_RATE ? "Current":
  10274. + tag == VCMSG_GET_MIN_CLOCK ? "Min":
  10275. + tag == VCMSG_GET_MAX_CLOCK ? "Max":
  10276. + "Unexpected", arm_rate);
  10277. +
  10278. + return arm_rate;
  10279. +}
  10280. +
  10281. +/*
  10282. + ====================================================
  10283. + Module Initialisation registers the cpufreq driver
  10284. + ====================================================
  10285. +*/
  10286. +static int __init bcm2835_cpufreq_module_init(void)
  10287. +{
  10288. + print_debug("IN\n");
  10289. + return cpufreq_register_driver(&bcm2835_cpufreq_driver);
  10290. +}
  10291. +
  10292. +/*
  10293. + =============
  10294. + Module exit
  10295. + =============
  10296. +*/
  10297. +static void __exit bcm2835_cpufreq_module_exit(void)
  10298. +{
  10299. + print_debug("IN\n");
  10300. + cpufreq_unregister_driver(&bcm2835_cpufreq_driver);
  10301. + return;
  10302. +}
  10303. +
  10304. +/*
  10305. + ==============================================================
  10306. + Initialisation function sets up the CPU policy for first use
  10307. + ==============================================================
  10308. +*/
  10309. +static int bcm2835_cpufreq_driver_init(struct cpufreq_policy *policy)
  10310. +{
  10311. + /* measured value of how long it takes to change frequency */
  10312. + policy->cpuinfo.transition_latency = 355000; /* ns */
  10313. +
  10314. + /* now find out what the maximum and minimum frequencies are */
  10315. + policy->min = policy->cpuinfo.min_freq = bcm2835_cpufreq_get_clock(VCMSG_GET_MIN_CLOCK);
  10316. + policy->max = policy->cpuinfo.max_freq = bcm2835_cpufreq_get_clock(VCMSG_GET_MAX_CLOCK);
  10317. + policy->cur = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  10318. +
  10319. + print_info("min=%d max=%d cur=%d\n", policy->min, policy->max, policy->cur);
  10320. + return 0;
  10321. +}
  10322. +
  10323. +/*
  10324. + =================================================================================
  10325. + Target function chooses the most appropriate frequency from the table to enable
  10326. + =================================================================================
  10327. +*/
  10328. +
  10329. +static int bcm2835_cpufreq_driver_target(struct cpufreq_policy *policy, unsigned int target_freq, unsigned int relation)
  10330. +{
  10331. + unsigned int target = target_freq;
  10332. +#ifdef CPUFREQ_DEBUG_ENABLE
  10333. + unsigned int cur = policy->cur;
  10334. +#endif
  10335. + print_debug("%s: min=%d max=%d cur=%d target=%d\n",policy->governor->name,policy->min,policy->max,policy->cur,target_freq);
  10336. +
  10337. + /* if we are above min and using ondemand, then just use max */
  10338. + if (strcmp("ondemand", policy->governor->name)==0 && target > policy->min)
  10339. + target = policy->max;
  10340. + /* if the frequency is the same, just quit */
  10341. + if (target == policy->cur)
  10342. + return 0;
  10343. +
  10344. + /* otherwise were good to set the clock frequency */
  10345. + policy->cur = bcm2835_cpufreq_set_clock(policy->cur, target);
  10346. +
  10347. + if (!policy->cur)
  10348. + {
  10349. + print_err("Error occurred setting a new frequency (%d)!\n", target);
  10350. + policy->cur = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  10351. + return -EINVAL;
  10352. + }
  10353. + print_debug("Freq %d->%d (min=%d max=%d target=%d request=%d)\n", cur, policy->cur, policy->min, policy->max, target_freq, target);
  10354. + return 0;
  10355. +}
  10356. +
  10357. +static unsigned int bcm2835_cpufreq_driver_get(unsigned int cpu)
  10358. +{
  10359. + unsigned int actual_rate = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  10360. + print_debug("cpu=%d\n", actual_rate);
  10361. + return actual_rate;
  10362. +}
  10363. +
  10364. +/*
  10365. + =================================================================================
  10366. + Verify ensures that when a policy is changed, it is suitable for the CPU to use
  10367. + =================================================================================
  10368. +*/
  10369. +
  10370. +static int bcm2835_cpufreq_driver_verify(struct cpufreq_policy *policy)
  10371. +{
  10372. + print_info("switching to governor %s\n", policy->governor->name);
  10373. + return 0;
  10374. +}
  10375. +
  10376. +
  10377. +/* the CPUFreq driver */
  10378. +static struct cpufreq_driver bcm2835_cpufreq_driver = {
  10379. + .name = "BCM2835 CPUFreq",
  10380. + .init = bcm2835_cpufreq_driver_init,
  10381. + .verify = bcm2835_cpufreq_driver_verify,
  10382. + .target = bcm2835_cpufreq_driver_target,
  10383. + .get = bcm2835_cpufreq_driver_get
  10384. +};
  10385. +
  10386. +MODULE_AUTHOR("Dorian Peake and Dom Cobley");
  10387. +MODULE_DESCRIPTION("CPU frequency driver for BCM2835 chip");
  10388. +MODULE_LICENSE("GPL");
  10389. +
  10390. +module_init(bcm2835_cpufreq_module_init);
  10391. +module_exit(bcm2835_cpufreq_module_exit);
  10392. diff -Nur linux-3.15.4/drivers/cpufreq/cpufreq.c linux-rpi/drivers/cpufreq/cpufreq.c
  10393. --- linux-3.15.4/drivers/cpufreq/cpufreq.c 2014-07-07 03:59:25.000000000 +0200
  10394. +++ linux-rpi/drivers/cpufreq/cpufreq.c 2014-07-07 10:45:00.000000000 +0200
  10395. @@ -2166,8 +2166,10 @@
  10396. struct cpufreq_policy new_policy;
  10397. int ret;
  10398. - if (!policy)
  10399. - return -ENODEV;
  10400. + if (!policy) {
  10401. + ret = -ENODEV;
  10402. + goto no_policy;
  10403. + }
  10404. down_write(&policy->rwsem);
  10405. @@ -2186,7 +2188,7 @@
  10406. new_policy.cur = cpufreq_driver->get(cpu);
  10407. if (WARN_ON(!new_policy.cur)) {
  10408. ret = -EIO;
  10409. - goto unlock;
  10410. + goto no_policy;
  10411. }
  10412. if (!policy->cur) {
  10413. @@ -2201,10 +2203,10 @@
  10414. ret = cpufreq_set_policy(policy, &new_policy);
  10415. -unlock:
  10416. up_write(&policy->rwsem);
  10417. cpufreq_cpu_put(policy);
  10418. +no_policy:
  10419. return ret;
  10420. }
  10421. EXPORT_SYMBOL(cpufreq_update_policy);
  10422. diff -Nur linux-3.15.4/drivers/cpufreq/Kconfig.arm linux-rpi/drivers/cpufreq/Kconfig.arm
  10423. --- linux-3.15.4/drivers/cpufreq/Kconfig.arm 2014-07-07 03:59:25.000000000 +0200
  10424. +++ linux-rpi/drivers/cpufreq/Kconfig.arm 2014-07-07 10:45:00.000000000 +0200
  10425. @@ -240,6 +240,14 @@
  10426. help
  10427. This adds the CPUFreq driver support for SPEAr SOCs.
  10428. +config ARM_BCM2835_CPUFREQ
  10429. + bool "BCM2835 Driver"
  10430. + default y
  10431. + help
  10432. + This adds the CPUFreq driver for BCM2835
  10433. +
  10434. + If in doubt, say N.
  10435. +
  10436. config ARM_TEGRA_CPUFREQ
  10437. bool "TEGRA CPUFreq support"
  10438. depends on ARCH_TEGRA
  10439. diff -Nur linux-3.15.4/drivers/cpufreq/Makefile linux-rpi/drivers/cpufreq/Makefile
  10440. --- linux-3.15.4/drivers/cpufreq/Makefile 2014-07-07 03:59:25.000000000 +0200
  10441. +++ linux-rpi/drivers/cpufreq/Makefile 2014-07-07 10:45:00.000000000 +0200
  10442. @@ -73,6 +73,7 @@
  10443. obj-$(CONFIG_ARM_SA1100_CPUFREQ) += sa1100-cpufreq.o
  10444. obj-$(CONFIG_ARM_SA1110_CPUFREQ) += sa1110-cpufreq.o
  10445. obj-$(CONFIG_ARM_SPEAR_CPUFREQ) += spear-cpufreq.o
  10446. +obj-$(CONFIG_ARM_BCM2835_CPUFREQ) += bcm2835-cpufreq.o
  10447. obj-$(CONFIG_ARM_TEGRA_CPUFREQ) += tegra-cpufreq.o
  10448. obj-$(CONFIG_ARM_VEXPRESS_SPC_CPUFREQ) += vexpress-spc-cpufreq.o
  10449. diff -Nur linux-3.15.4/drivers/cpufreq/ppc-corenet-cpufreq.c linux-rpi/drivers/cpufreq/ppc-corenet-cpufreq.c
  10450. --- linux-3.15.4/drivers/cpufreq/ppc-corenet-cpufreq.c 2014-07-07 03:59:25.000000000 +0200
  10451. +++ linux-rpi/drivers/cpufreq/ppc-corenet-cpufreq.c 2014-07-07 10:45:01.000000000 +0200
  10452. @@ -138,7 +138,7 @@
  10453. struct cpufreq_frequency_table *table;
  10454. struct cpu_data *data;
  10455. unsigned int cpu = policy->cpu;
  10456. - u64 u64temp;
  10457. + u64 transition_latency_hz;
  10458. np = of_get_cpu_node(cpu, NULL);
  10459. if (!np)
  10460. @@ -206,10 +206,9 @@
  10461. for_each_cpu(i, per_cpu(cpu_mask, cpu))
  10462. per_cpu(cpu_data, i) = data;
  10463. - /* Minimum transition latency is 12 platform clocks */
  10464. - u64temp = 12ULL * NSEC_PER_SEC;
  10465. - do_div(u64temp, fsl_get_sys_freq());
  10466. - policy->cpuinfo.transition_latency = u64temp + 1;
  10467. + transition_latency_hz = 12ULL * NSEC_PER_SEC;
  10468. + policy->cpuinfo.transition_latency =
  10469. + do_div(transition_latency_hz, fsl_get_sys_freq());
  10470. of_node_put(np);
  10471. diff -Nur linux-3.15.4/drivers/dma/bcm2708-dmaengine.c linux-rpi/drivers/dma/bcm2708-dmaengine.c
  10472. --- linux-3.15.4/drivers/dma/bcm2708-dmaengine.c 1970-01-01 01:00:00.000000000 +0100
  10473. +++ linux-rpi/drivers/dma/bcm2708-dmaengine.c 2014-07-07 10:45:01.000000000 +0200
  10474. @@ -0,0 +1,588 @@
  10475. +/*
  10476. + * BCM2708 DMA engine support
  10477. + *
  10478. + * This driver only supports cyclic DMA transfers
  10479. + * as needed for the I2S module.
  10480. + *
  10481. + * Author: Florian Meier <florian.meier@koalo.de>
  10482. + * Copyright 2013
  10483. + *
  10484. + * Based on
  10485. + * OMAP DMAengine support by Russell King
  10486. + *
  10487. + * BCM2708 DMA Driver
  10488. + * Copyright (C) 2010 Broadcom
  10489. + *
  10490. + * Raspberry Pi PCM I2S ALSA Driver
  10491. + * Copyright (c) by Phil Poole 2013
  10492. + *
  10493. + * MARVELL MMP Peripheral DMA Driver
  10494. + * Copyright 2012 Marvell International Ltd.
  10495. + *
  10496. + * This program is free software; you can redistribute it and/or modify
  10497. + * it under the terms of the GNU General Public License as published by
  10498. + * the Free Software Foundation; either version 2 of the License, or
  10499. + * (at your option) any later version.
  10500. + *
  10501. + * This program is distributed in the hope that it will be useful,
  10502. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10503. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10504. + * GNU General Public License for more details.
  10505. + */
  10506. +#include <linux/dmaengine.h>
  10507. +#include <linux/dma-mapping.h>
  10508. +#include <linux/err.h>
  10509. +#include <linux/init.h>
  10510. +#include <linux/interrupt.h>
  10511. +#include <linux/list.h>
  10512. +#include <linux/module.h>
  10513. +#include <linux/platform_device.h>
  10514. +#include <linux/slab.h>
  10515. +#include <linux/io.h>
  10516. +#include <linux/spinlock.h>
  10517. +#include <linux/irq.h>
  10518. +
  10519. +#include "virt-dma.h"
  10520. +
  10521. +#include <mach/dma.h>
  10522. +#include <mach/irqs.h>
  10523. +
  10524. +struct bcm2708_dmadev {
  10525. + struct dma_device ddev;
  10526. + spinlock_t lock;
  10527. + void __iomem *base;
  10528. + struct device_dma_parameters dma_parms;
  10529. +};
  10530. +
  10531. +struct bcm2708_chan {
  10532. + struct virt_dma_chan vc;
  10533. + struct list_head node;
  10534. +
  10535. + struct dma_slave_config cfg;
  10536. + bool cyclic;
  10537. +
  10538. + int ch;
  10539. + struct bcm2708_desc *desc;
  10540. +
  10541. + void __iomem *chan_base;
  10542. + int irq_number;
  10543. +};
  10544. +
  10545. +struct bcm2708_desc {
  10546. + struct virt_dma_desc vd;
  10547. + enum dma_transfer_direction dir;
  10548. +
  10549. + unsigned int control_block_size;
  10550. + struct bcm2708_dma_cb *control_block_base;
  10551. + dma_addr_t control_block_base_phys;
  10552. +
  10553. + unsigned frames;
  10554. + size_t size;
  10555. +};
  10556. +
  10557. +#define BCM2708_DMA_DATA_TYPE_S8 1
  10558. +#define BCM2708_DMA_DATA_TYPE_S16 2
  10559. +#define BCM2708_DMA_DATA_TYPE_S32 4
  10560. +#define BCM2708_DMA_DATA_TYPE_S128 16
  10561. +
  10562. +static inline struct bcm2708_dmadev *to_bcm2708_dma_dev(struct dma_device *d)
  10563. +{
  10564. + return container_of(d, struct bcm2708_dmadev, ddev);
  10565. +}
  10566. +
  10567. +static inline struct bcm2708_chan *to_bcm2708_dma_chan(struct dma_chan *c)
  10568. +{
  10569. + return container_of(c, struct bcm2708_chan, vc.chan);
  10570. +}
  10571. +
  10572. +static inline struct bcm2708_desc *to_bcm2708_dma_desc(
  10573. + struct dma_async_tx_descriptor *t)
  10574. +{
  10575. + return container_of(t, struct bcm2708_desc, vd.tx);
  10576. +}
  10577. +
  10578. +static void bcm2708_dma_desc_free(struct virt_dma_desc *vd)
  10579. +{
  10580. + struct bcm2708_desc *desc = container_of(vd, struct bcm2708_desc, vd);
  10581. + dma_free_coherent(desc->vd.tx.chan->device->dev,
  10582. + desc->control_block_size,
  10583. + desc->control_block_base,
  10584. + desc->control_block_base_phys);
  10585. + kfree(desc);
  10586. +}
  10587. +
  10588. +static void bcm2708_dma_start_desc(struct bcm2708_chan *c)
  10589. +{
  10590. + struct virt_dma_desc *vd = vchan_next_desc(&c->vc);
  10591. + struct bcm2708_desc *d;
  10592. +
  10593. + if (!vd) {
  10594. + c->desc = NULL;
  10595. + return;
  10596. + }
  10597. +
  10598. + list_del(&vd->node);
  10599. +
  10600. + c->desc = d = to_bcm2708_dma_desc(&vd->tx);
  10601. +
  10602. + bcm_dma_start(c->chan_base, d->control_block_base_phys);
  10603. +}
  10604. +
  10605. +static irqreturn_t bcm2708_dma_callback(int irq, void *data)
  10606. +{
  10607. + struct bcm2708_chan *c = data;
  10608. + struct bcm2708_desc *d;
  10609. + unsigned long flags;
  10610. +
  10611. + spin_lock_irqsave(&c->vc.lock, flags);
  10612. +
  10613. + /* Acknowledge interrupt */
  10614. + writel(BCM2708_DMA_INT, c->chan_base + BCM2708_DMA_CS);
  10615. +
  10616. + d = c->desc;
  10617. +
  10618. + if (d) {
  10619. + /* TODO Only works for cyclic DMA */
  10620. + vchan_cyclic_callback(&d->vd);
  10621. + }
  10622. +
  10623. + /* Keep the DMA engine running */
  10624. + dsb(); /* ARM synchronization barrier */
  10625. + writel(BCM2708_DMA_ACTIVE, c->chan_base + BCM2708_DMA_CS);
  10626. +
  10627. + spin_unlock_irqrestore(&c->vc.lock, flags);
  10628. +
  10629. + return IRQ_HANDLED;
  10630. +}
  10631. +
  10632. +static int bcm2708_dma_alloc_chan_resources(struct dma_chan *chan)
  10633. +{
  10634. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  10635. +
  10636. + return request_irq(c->irq_number,
  10637. + bcm2708_dma_callback, 0, "DMA IRQ", c);
  10638. +}
  10639. +
  10640. +static void bcm2708_dma_free_chan_resources(struct dma_chan *chan)
  10641. +{
  10642. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  10643. +
  10644. + vchan_free_chan_resources(&c->vc);
  10645. + free_irq(c->irq_number, c);
  10646. +
  10647. + dev_dbg(c->vc.chan.device->dev, "Freeing DMA channel %u\n", c->ch);
  10648. +}
  10649. +
  10650. +static size_t bcm2708_dma_desc_size(struct bcm2708_desc *d)
  10651. +{
  10652. + return d->size;
  10653. +}
  10654. +
  10655. +static size_t bcm2708_dma_desc_size_pos(struct bcm2708_desc *d, dma_addr_t addr)
  10656. +{
  10657. + unsigned i;
  10658. + size_t size;
  10659. +
  10660. + for (size = i = 0; i < d->frames; i++) {
  10661. + struct bcm2708_dma_cb *control_block =
  10662. + &d->control_block_base[i];
  10663. + size_t this_size = control_block->length;
  10664. + dma_addr_t dma;
  10665. +
  10666. + if (d->dir == DMA_DEV_TO_MEM)
  10667. + dma = control_block->dst;
  10668. + else
  10669. + dma = control_block->src;
  10670. +
  10671. + if (size)
  10672. + size += this_size;
  10673. + else if (addr >= dma && addr < dma + this_size)
  10674. + size += dma + this_size - addr;
  10675. + }
  10676. +
  10677. + return size;
  10678. +}
  10679. +
  10680. +static enum dma_status bcm2708_dma_tx_status(struct dma_chan *chan,
  10681. + dma_cookie_t cookie, struct dma_tx_state *txstate)
  10682. +{
  10683. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  10684. + struct virt_dma_desc *vd;
  10685. + enum dma_status ret;
  10686. + unsigned long flags;
  10687. +
  10688. + ret = dma_cookie_status(chan, cookie, txstate);
  10689. + if (ret == DMA_COMPLETE || !txstate)
  10690. + return ret;
  10691. +
  10692. + spin_lock_irqsave(&c->vc.lock, flags);
  10693. + vd = vchan_find_desc(&c->vc, cookie);
  10694. + if (vd) {
  10695. + txstate->residue =
  10696. + bcm2708_dma_desc_size(to_bcm2708_dma_desc(&vd->tx));
  10697. + } else if (c->desc && c->desc->vd.tx.cookie == cookie) {
  10698. + struct bcm2708_desc *d = c->desc;
  10699. + dma_addr_t pos;
  10700. +
  10701. + if (d->dir == DMA_MEM_TO_DEV)
  10702. + pos = readl(c->chan_base + BCM2708_DMA_SOURCE_AD);
  10703. + else if (d->dir == DMA_DEV_TO_MEM)
  10704. + pos = readl(c->chan_base + BCM2708_DMA_DEST_AD);
  10705. + else
  10706. + pos = 0;
  10707. +
  10708. + txstate->residue = bcm2708_dma_desc_size_pos(d, pos);
  10709. + } else {
  10710. + txstate->residue = 0;
  10711. + }
  10712. +
  10713. + spin_unlock_irqrestore(&c->vc.lock, flags);
  10714. +
  10715. + return ret;
  10716. +}
  10717. +
  10718. +static void bcm2708_dma_issue_pending(struct dma_chan *chan)
  10719. +{
  10720. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  10721. + unsigned long flags;
  10722. +
  10723. + c->cyclic = true; /* Nothing else is implemented */
  10724. +
  10725. + spin_lock_irqsave(&c->vc.lock, flags);
  10726. + if (vchan_issue_pending(&c->vc) && !c->desc)
  10727. + bcm2708_dma_start_desc(c);
  10728. +
  10729. + spin_unlock_irqrestore(&c->vc.lock, flags);
  10730. +}
  10731. +
  10732. +static struct dma_async_tx_descriptor *bcm2708_dma_prep_dma_cyclic(
  10733. + struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
  10734. + size_t period_len, enum dma_transfer_direction direction,
  10735. + unsigned long flags, void *context)
  10736. +{
  10737. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  10738. + enum dma_slave_buswidth dev_width;
  10739. + struct bcm2708_desc *d;
  10740. + dma_addr_t dev_addr;
  10741. + unsigned es, sync_type;
  10742. + unsigned frame;
  10743. +
  10744. + /* Grab configuration */
  10745. + if (direction == DMA_DEV_TO_MEM) {
  10746. + dev_addr = c->cfg.src_addr;
  10747. + dev_width = c->cfg.src_addr_width;
  10748. + sync_type = BCM2708_DMA_S_DREQ;
  10749. + } else if (direction == DMA_MEM_TO_DEV) {
  10750. + dev_addr = c->cfg.dst_addr;
  10751. + dev_width = c->cfg.dst_addr_width;
  10752. + sync_type = BCM2708_DMA_D_DREQ;
  10753. + } else {
  10754. + dev_err(chan->device->dev, "%s: bad direction?\n", __func__);
  10755. + return NULL;
  10756. + }
  10757. +
  10758. + /* Bus width translates to the element size (ES) */
  10759. + switch (dev_width) {
  10760. + case DMA_SLAVE_BUSWIDTH_4_BYTES:
  10761. + es = BCM2708_DMA_DATA_TYPE_S32;
  10762. + break;
  10763. + default:
  10764. + return NULL;
  10765. + }
  10766. +
  10767. + /* Now allocate and setup the descriptor. */
  10768. + d = kzalloc(sizeof(*d), GFP_NOWAIT);
  10769. + if (!d)
  10770. + return NULL;
  10771. +
  10772. + d->dir = direction;
  10773. + d->frames = buf_len / period_len;
  10774. +
  10775. + /* Allocate memory for control blocks */
  10776. + d->control_block_size = d->frames * sizeof(struct bcm2708_dma_cb);
  10777. + d->control_block_base = dma_zalloc_coherent(chan->device->dev,
  10778. + d->control_block_size, &d->control_block_base_phys,
  10779. + GFP_NOWAIT);
  10780. +
  10781. + if (!d->control_block_base) {
  10782. + kfree(d);
  10783. + return NULL;
  10784. + }
  10785. +
  10786. + /*
  10787. + * Iterate over all frames, create a control block
  10788. + * for each frame and link them together.
  10789. + */
  10790. + for (frame = 0; frame < d->frames; frame++) {
  10791. + struct bcm2708_dma_cb *control_block =
  10792. + &d->control_block_base[frame];
  10793. +
  10794. + /* Setup adresses */
  10795. + if (d->dir == DMA_DEV_TO_MEM) {
  10796. + control_block->info = BCM2708_DMA_D_INC;
  10797. + control_block->src = dev_addr;
  10798. + control_block->dst = buf_addr + frame * period_len;
  10799. + } else {
  10800. + control_block->info = BCM2708_DMA_S_INC;
  10801. + control_block->src = buf_addr + frame * period_len;
  10802. + control_block->dst = dev_addr;
  10803. + }
  10804. +
  10805. + /* Enable interrupt */
  10806. + control_block->info |= BCM2708_DMA_INT_EN;
  10807. +
  10808. + /* Setup synchronization */
  10809. + if (sync_type != 0)
  10810. + control_block->info |= sync_type;
  10811. +
  10812. + /* Setup DREQ channel */
  10813. + if (c->cfg.slave_id != 0)
  10814. + control_block->info |=
  10815. + BCM2708_DMA_PER_MAP(c->cfg.slave_id);
  10816. +
  10817. + /* Length of a frame */
  10818. + control_block->length = period_len;
  10819. + d->size += control_block->length;
  10820. +
  10821. + /*
  10822. + * Next block is the next frame.
  10823. + * This DMA engine driver currently only supports cyclic DMA.
  10824. + * Therefore, wrap around at number of frames.
  10825. + */
  10826. + control_block->next = d->control_block_base_phys +
  10827. + sizeof(struct bcm2708_dma_cb)
  10828. + * ((frame + 1) % d->frames);
  10829. + }
  10830. +
  10831. + return vchan_tx_prep(&c->vc, &d->vd, flags);
  10832. +}
  10833. +
  10834. +static int bcm2708_dma_slave_config(struct bcm2708_chan *c,
  10835. + struct dma_slave_config *cfg)
  10836. +{
  10837. + if ((cfg->direction == DMA_DEV_TO_MEM &&
  10838. + cfg->src_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) ||
  10839. + (cfg->direction == DMA_MEM_TO_DEV &&
  10840. + cfg->dst_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) ||
  10841. + !is_slave_direction(cfg->direction)) {
  10842. + return -EINVAL;
  10843. + }
  10844. +
  10845. + c->cfg = *cfg;
  10846. +
  10847. + return 0;
  10848. +}
  10849. +
  10850. +static int bcm2708_dma_terminate_all(struct bcm2708_chan *c)
  10851. +{
  10852. + struct bcm2708_dmadev *d = to_bcm2708_dma_dev(c->vc.chan.device);
  10853. + unsigned long flags;
  10854. + int timeout = 10000;
  10855. + LIST_HEAD(head);
  10856. +
  10857. + spin_lock_irqsave(&c->vc.lock, flags);
  10858. +
  10859. + /* Prevent this channel being scheduled */
  10860. + spin_lock(&d->lock);
  10861. + list_del_init(&c->node);
  10862. + spin_unlock(&d->lock);
  10863. +
  10864. + /*
  10865. + * Stop DMA activity: we assume the callback will not be called
  10866. + * after bcm_dma_abort() returns (even if it does, it will see
  10867. + * c->desc is NULL and exit.)
  10868. + */
  10869. + if (c->desc) {
  10870. + c->desc = NULL;
  10871. + bcm_dma_abort(c->chan_base);
  10872. +
  10873. + /* Wait for stopping */
  10874. + while (timeout > 0) {
  10875. + timeout--;
  10876. + if (!(readl(c->chan_base + BCM2708_DMA_CS) &
  10877. + BCM2708_DMA_ACTIVE))
  10878. + break;
  10879. +
  10880. + cpu_relax();
  10881. + }
  10882. +
  10883. + if (timeout <= 0)
  10884. + dev_err(d->ddev.dev, "DMA transfer could not be terminated\n");
  10885. + }
  10886. +
  10887. + vchan_get_all_descriptors(&c->vc, &head);
  10888. + spin_unlock_irqrestore(&c->vc.lock, flags);
  10889. + vchan_dma_desc_free_list(&c->vc, &head);
  10890. +
  10891. + return 0;
  10892. +}
  10893. +
  10894. +static int bcm2708_dma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
  10895. + unsigned long arg)
  10896. +{
  10897. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  10898. +
  10899. + switch (cmd) {
  10900. + case DMA_SLAVE_CONFIG:
  10901. + return bcm2708_dma_slave_config(c,
  10902. + (struct dma_slave_config *)arg);
  10903. +
  10904. + case DMA_TERMINATE_ALL:
  10905. + return bcm2708_dma_terminate_all(c);
  10906. +
  10907. + default:
  10908. + return -ENXIO;
  10909. + }
  10910. +}
  10911. +
  10912. +static int bcm2708_dma_chan_init(struct bcm2708_dmadev *d, void __iomem* chan_base,
  10913. + int chan_id, int irq)
  10914. +{
  10915. + struct bcm2708_chan *c;
  10916. +
  10917. + c = devm_kzalloc(d->ddev.dev, sizeof(*c), GFP_KERNEL);
  10918. + if (!c)
  10919. + return -ENOMEM;
  10920. +
  10921. + c->vc.desc_free = bcm2708_dma_desc_free;
  10922. + vchan_init(&c->vc, &d->ddev);
  10923. + INIT_LIST_HEAD(&c->node);
  10924. +
  10925. + d->ddev.chancnt++;
  10926. +
  10927. + c->chan_base = chan_base;
  10928. + c->ch = chan_id;
  10929. + c->irq_number = irq;
  10930. +
  10931. + return 0;
  10932. +}
  10933. +
  10934. +static void bcm2708_dma_free(struct bcm2708_dmadev *od)
  10935. +{
  10936. + while (!list_empty(&od->ddev.channels)) {
  10937. + struct bcm2708_chan *c = list_first_entry(&od->ddev.channels,
  10938. + struct bcm2708_chan, vc.chan.device_node);
  10939. +
  10940. + list_del(&c->vc.chan.device_node);
  10941. + tasklet_kill(&c->vc.task);
  10942. + }
  10943. +}
  10944. +
  10945. +static int bcm2708_dma_probe(struct platform_device *pdev)
  10946. +{
  10947. + struct bcm2708_dmadev *od;
  10948. + int rc, i;
  10949. +
  10950. + if (!pdev->dev.dma_mask)
  10951. + pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
  10952. +
  10953. + rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
  10954. + if (rc)
  10955. + return rc;
  10956. + dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
  10957. +
  10958. + od = devm_kzalloc(&pdev->dev, sizeof(*od), GFP_KERNEL);
  10959. + if (!od)
  10960. + return -ENOMEM;
  10961. +
  10962. + pdev->dev.dma_parms = &od->dma_parms;
  10963. + dma_set_max_seg_size(&pdev->dev, 0x3FFFFFFF);
  10964. +
  10965. + dma_cap_set(DMA_SLAVE, od->ddev.cap_mask);
  10966. + dma_cap_set(DMA_CYCLIC, od->ddev.cap_mask);
  10967. + od->ddev.device_alloc_chan_resources = bcm2708_dma_alloc_chan_resources;
  10968. + od->ddev.device_free_chan_resources = bcm2708_dma_free_chan_resources;
  10969. + od->ddev.device_tx_status = bcm2708_dma_tx_status;
  10970. + od->ddev.device_issue_pending = bcm2708_dma_issue_pending;
  10971. + od->ddev.device_prep_dma_cyclic = bcm2708_dma_prep_dma_cyclic;
  10972. + od->ddev.device_control = bcm2708_dma_control;
  10973. + od->ddev.dev = &pdev->dev;
  10974. + INIT_LIST_HEAD(&od->ddev.channels);
  10975. + spin_lock_init(&od->lock);
  10976. +
  10977. + platform_set_drvdata(pdev, od);
  10978. +
  10979. + for (i = 0; i < 16; i++) {
  10980. + void __iomem* chan_base;
  10981. + int chan_id, irq;
  10982. +
  10983. + chan_id = bcm_dma_chan_alloc(BCM_DMA_FEATURE_FAST,
  10984. + &chan_base,
  10985. + &irq);
  10986. +
  10987. + if (chan_id < 0)
  10988. + break;
  10989. +
  10990. + rc = bcm2708_dma_chan_init(od, chan_base, chan_id, irq);
  10991. + if (rc) {
  10992. + bcm2708_dma_free(od);
  10993. + return rc;
  10994. + }
  10995. + }
  10996. +
  10997. + rc = dma_async_device_register(&od->ddev);
  10998. + if (rc) {
  10999. + dev_err(&pdev->dev,
  11000. + "Failed to register slave DMA engine device: %d\n", rc);
  11001. + bcm2708_dma_free(od);
  11002. + return rc;
  11003. + }
  11004. +
  11005. + dev_dbg(&pdev->dev, "Load BCM2708 DMA engine driver\n");
  11006. +
  11007. + return rc;
  11008. +}
  11009. +
  11010. +static int bcm2708_dma_remove(struct platform_device *pdev)
  11011. +{
  11012. + struct bcm2708_dmadev *od = platform_get_drvdata(pdev);
  11013. +
  11014. + dma_async_device_unregister(&od->ddev);
  11015. + bcm2708_dma_free(od);
  11016. +
  11017. + return 0;
  11018. +}
  11019. +
  11020. +static struct platform_driver bcm2708_dma_driver = {
  11021. + .probe = bcm2708_dma_probe,
  11022. + .remove = bcm2708_dma_remove,
  11023. + .driver = {
  11024. + .name = "bcm2708-dmaengine",
  11025. + .owner = THIS_MODULE,
  11026. + },
  11027. +};
  11028. +
  11029. +static struct platform_device *pdev;
  11030. +
  11031. +static const struct platform_device_info bcm2708_dma_dev_info = {
  11032. + .name = "bcm2708-dmaengine",
  11033. + .id = -1,
  11034. +};
  11035. +
  11036. +static int bcm2708_dma_init(void)
  11037. +{
  11038. + int rc = platform_driver_register(&bcm2708_dma_driver);
  11039. +
  11040. + if (rc == 0) {
  11041. + pdev = platform_device_register_full(&bcm2708_dma_dev_info);
  11042. + if (IS_ERR(pdev)) {
  11043. + platform_driver_unregister(&bcm2708_dma_driver);
  11044. + rc = PTR_ERR(pdev);
  11045. + }
  11046. + }
  11047. +
  11048. + return rc;
  11049. +}
  11050. +subsys_initcall(bcm2708_dma_init);
  11051. +
  11052. +static void __exit bcm2708_dma_exit(void)
  11053. +{
  11054. + platform_device_unregister(pdev);
  11055. + platform_driver_unregister(&bcm2708_dma_driver);
  11056. +}
  11057. +module_exit(bcm2708_dma_exit);
  11058. +
  11059. +MODULE_ALIAS("platform:bcm2708-dma");
  11060. +MODULE_DESCRIPTION("BCM2708 DMA engine driver");
  11061. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  11062. +MODULE_LICENSE("GPL v2");
  11063. diff -Nur linux-3.15.4/drivers/dma/Kconfig linux-rpi/drivers/dma/Kconfig
  11064. --- linux-3.15.4/drivers/dma/Kconfig 2014-07-07 03:59:25.000000000 +0200
  11065. +++ linux-rpi/drivers/dma/Kconfig 2014-07-07 10:45:01.000000000 +0200
  11066. @@ -312,6 +312,12 @@
  11067. select DMA_ENGINE
  11068. select DMA_VIRTUAL_CHANNELS
  11069. +config DMA_BCM2708
  11070. + tristate "BCM2708 DMA engine support"
  11071. + depends on MACH_BCM2708
  11072. + select DMA_ENGINE
  11073. + select DMA_VIRTUAL_CHANNELS
  11074. +
  11075. config TI_CPPI41
  11076. tristate "AM33xx CPPI41 DMA support"
  11077. depends on ARCH_OMAP
  11078. diff -Nur linux-3.15.4/drivers/dma/Makefile linux-rpi/drivers/dma/Makefile
  11079. --- linux-3.15.4/drivers/dma/Makefile 2014-07-07 03:59:25.000000000 +0200
  11080. +++ linux-rpi/drivers/dma/Makefile 2014-07-07 10:45:01.000000000 +0200
  11081. @@ -39,6 +39,7 @@
  11082. obj-$(CONFIG_MMP_TDMA) += mmp_tdma.o
  11083. obj-$(CONFIG_DMA_OMAP) += omap-dma.o
  11084. obj-$(CONFIG_DMA_BCM2835) += bcm2835-dma.o
  11085. +obj-$(CONFIG_DMA_BCM2708) += bcm2708-dmaengine.o
  11086. obj-$(CONFIG_MMP_PDMA) += mmp_pdma.o
  11087. obj-$(CONFIG_DMA_JZ4740) += dma-jz4740.o
  11088. obj-$(CONFIG_TI_CPPI41) += cppi41.o
  11089. diff -Nur linux-3.15.4/drivers/hwmon/bcm2835-hwmon.c linux-rpi/drivers/hwmon/bcm2835-hwmon.c
  11090. --- linux-3.15.4/drivers/hwmon/bcm2835-hwmon.c 1970-01-01 01:00:00.000000000 +0100
  11091. +++ linux-rpi/drivers/hwmon/bcm2835-hwmon.c 2014-04-13 17:32:56.000000000 +0200
  11092. @@ -0,0 +1,219 @@
  11093. +/*****************************************************************************
  11094. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  11095. +*
  11096. +* Unless you and Broadcom execute a separate written software license
  11097. +* agreement governing use of this software, this software is licensed to you
  11098. +* under the terms of the GNU General Public License version 2, available at
  11099. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  11100. +*
  11101. +* Notwithstanding the above, under no circumstances may you combine this
  11102. +* software in any way with any other Broadcom software provided under a
  11103. +* license other than the GPL, without Broadcom's express prior written
  11104. +* consent.
  11105. +*****************************************************************************/
  11106. +
  11107. +#include <linux/kernel.h>
  11108. +#include <linux/module.h>
  11109. +#include <linux/init.h>
  11110. +#include <linux/hwmon.h>
  11111. +#include <linux/hwmon-sysfs.h>
  11112. +#include <linux/platform_device.h>
  11113. +#include <linux/sysfs.h>
  11114. +#include <mach/vcio.h>
  11115. +#include <linux/slab.h>
  11116. +#include <linux/err.h>
  11117. +
  11118. +#define MODULE_NAME "bcm2835_hwmon"
  11119. +
  11120. +/*#define HWMON_DEBUG_ENABLE*/
  11121. +
  11122. +#ifdef HWMON_DEBUG_ENABLE
  11123. +#define print_debug(fmt,...) printk(KERN_INFO "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  11124. +#else
  11125. +#define print_debug(fmt,...)
  11126. +#endif
  11127. +#define print_err(fmt,...) printk(KERN_ERR "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  11128. +#define print_info(fmt,...) printk(KERN_INFO "%s: "fmt"\n", MODULE_NAME, ##__VA_ARGS__)
  11129. +
  11130. +#define VC_TAG_GET_TEMP 0x00030006
  11131. +#define VC_TAG_GET_MAX_TEMP 0x0003000A
  11132. +
  11133. +/* --- STRUCTS --- */
  11134. +struct bcm2835_hwmon_data {
  11135. + struct device *hwmon_dev;
  11136. +};
  11137. +
  11138. +/* tag part of the message */
  11139. +struct vc_msg_tag {
  11140. + uint32_t tag_id; /* the tag ID for the temperature */
  11141. + uint32_t buffer_size; /* size of the buffer (should be 8) */
  11142. + uint32_t request_code; /* identifies message as a request (should be 0) */
  11143. + uint32_t id; /* extra ID field (should be 0) */
  11144. + uint32_t val; /* returned value of the temperature */
  11145. +};
  11146. +
  11147. +/* message structure to be sent to videocore */
  11148. +struct vc_msg {
  11149. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  11150. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  11151. + struct vc_msg_tag tag; /* the tag structure above to make */
  11152. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  11153. +};
  11154. +
  11155. +typedef enum {
  11156. + TEMP,
  11157. + MAX_TEMP,
  11158. +} temp_type;
  11159. +
  11160. +/* --- PROTOTYPES --- */
  11161. +static ssize_t bcm2835_get_temp(struct device *dev, struct device_attribute *attr, char *buf);
  11162. +static ssize_t bcm2835_get_name(struct device *dev, struct device_attribute *attr, char *buf);
  11163. +
  11164. +/* --- GLOBALS --- */
  11165. +
  11166. +static struct bcm2835_hwmon_data *bcm2835_data;
  11167. +static struct platform_driver bcm2835_hwmon_driver;
  11168. +
  11169. +static SENSOR_DEVICE_ATTR(name, S_IRUGO,bcm2835_get_name,NULL,0);
  11170. +static SENSOR_DEVICE_ATTR(temp1_input,S_IRUGO,bcm2835_get_temp,NULL,TEMP);
  11171. +static SENSOR_DEVICE_ATTR(temp1_max,S_IRUGO,bcm2835_get_temp,NULL,MAX_TEMP);
  11172. +
  11173. +static struct attribute* bcm2835_attributes[] = {
  11174. + &sensor_dev_attr_name.dev_attr.attr,
  11175. + &sensor_dev_attr_temp1_input.dev_attr.attr,
  11176. + &sensor_dev_attr_temp1_max.dev_attr.attr,
  11177. + NULL,
  11178. +};
  11179. +
  11180. +static struct attribute_group bcm2835_attr_group = {
  11181. + .attrs = bcm2835_attributes,
  11182. +};
  11183. +
  11184. +/* --- FUNCTIONS --- */
  11185. +
  11186. +static ssize_t bcm2835_get_name(struct device *dev, struct device_attribute *attr, char *buf)
  11187. +{
  11188. + return sprintf(buf,"bcm2835_hwmon\n");
  11189. +}
  11190. +
  11191. +static ssize_t bcm2835_get_temp(struct device *dev, struct device_attribute *attr, char *buf)
  11192. +{
  11193. + struct vc_msg msg;
  11194. + int result;
  11195. + uint temp = 0;
  11196. + int index = ((struct sensor_device_attribute*)to_sensor_dev_attr(attr))->index;
  11197. +
  11198. + print_debug("IN");
  11199. +
  11200. + /* wipe all previous message data */
  11201. + memset(&msg, 0, sizeof msg);
  11202. +
  11203. + /* determine the message type */
  11204. + if(index == TEMP)
  11205. + msg.tag.tag_id = VC_TAG_GET_TEMP;
  11206. + else if (index == MAX_TEMP)
  11207. + msg.tag.tag_id = VC_TAG_GET_MAX_TEMP;
  11208. + else
  11209. + {
  11210. + print_debug("Unknown temperature message!");
  11211. + return -EINVAL;
  11212. + }
  11213. +
  11214. + msg.msg_size = sizeof msg;
  11215. + msg.tag.buffer_size = 8;
  11216. +
  11217. + /* send the message */
  11218. + result = bcm_mailbox_property(&msg, sizeof msg);
  11219. +
  11220. + /* check if it was all ok and return the rate in milli degrees C */
  11221. + if (result == 0 && (msg.request_code & 0x80000000))
  11222. + temp = (uint)msg.tag.val;
  11223. + #ifdef HWMON_DEBUG_ENABLE
  11224. + else
  11225. + print_debug("Failed to get temperature!");
  11226. + #endif
  11227. + print_debug("Got temperature as %u",temp);
  11228. + print_debug("OUT");
  11229. + return sprintf(buf, "%u\n", temp);
  11230. +}
  11231. +
  11232. +
  11233. +static int bcm2835_hwmon_probe(struct platform_device *pdev)
  11234. +{
  11235. + int err;
  11236. +
  11237. + print_debug("IN");
  11238. + print_debug("HWMON Driver has been probed!");
  11239. +
  11240. + /* check that the device isn't null!*/
  11241. + if(pdev == NULL)
  11242. + {
  11243. + print_debug("Platform device is empty!");
  11244. + return -ENODEV;
  11245. + }
  11246. +
  11247. + /* allocate memory for neccessary data */
  11248. + bcm2835_data = kzalloc(sizeof(struct bcm2835_hwmon_data),GFP_KERNEL);
  11249. + if(!bcm2835_data)
  11250. + {
  11251. + print_debug("Unable to allocate memory for hwmon data!");
  11252. + err = -ENOMEM;
  11253. + goto kzalloc_error;
  11254. + }
  11255. +
  11256. + /* create the sysfs files */
  11257. + if(sysfs_create_group(&pdev->dev.kobj, &bcm2835_attr_group))
  11258. + {
  11259. + print_debug("Unable to create sysfs files!");
  11260. + err = -EFAULT;
  11261. + goto sysfs_error;
  11262. + }
  11263. +
  11264. + /* register the hwmon device */
  11265. + bcm2835_data->hwmon_dev = hwmon_device_register(&pdev->dev);
  11266. + if (IS_ERR(bcm2835_data->hwmon_dev))
  11267. + {
  11268. + err = PTR_ERR(bcm2835_data->hwmon_dev);
  11269. + goto hwmon_error;
  11270. + }
  11271. + print_debug("OUT");
  11272. + return 0;
  11273. +
  11274. + /* error goto's */
  11275. + hwmon_error:
  11276. + sysfs_remove_group(&pdev->dev.kobj, &bcm2835_attr_group);
  11277. +
  11278. + sysfs_error:
  11279. + kfree(bcm2835_data);
  11280. +
  11281. + kzalloc_error:
  11282. +
  11283. + return err;
  11284. +
  11285. +}
  11286. +
  11287. +static int bcm2835_hwmon_remove(struct platform_device *pdev)
  11288. +{
  11289. + print_debug("IN");
  11290. + hwmon_device_unregister(bcm2835_data->hwmon_dev);
  11291. +
  11292. + sysfs_remove_group(&pdev->dev.kobj, &bcm2835_attr_group);
  11293. + print_debug("OUT");
  11294. + return 0;
  11295. +}
  11296. +
  11297. +/* Hwmon Driver */
  11298. +static struct platform_driver bcm2835_hwmon_driver = {
  11299. + .probe = bcm2835_hwmon_probe,
  11300. + .remove = bcm2835_hwmon_remove,
  11301. + .driver = {
  11302. + .name = "bcm2835_hwmon",
  11303. + .owner = THIS_MODULE,
  11304. + },
  11305. +};
  11306. +
  11307. +MODULE_LICENSE("GPL");
  11308. +MODULE_AUTHOR("Dorian Peake");
  11309. +MODULE_DESCRIPTION("HW Monitor driver for bcm2835 chip");
  11310. +
  11311. +module_platform_driver(bcm2835_hwmon_driver);
  11312. diff -Nur linux-3.15.4/drivers/hwmon/Kconfig linux-rpi/drivers/hwmon/Kconfig
  11313. --- linux-3.15.4/drivers/hwmon/Kconfig 2014-07-07 03:59:25.000000000 +0200
  11314. +++ linux-rpi/drivers/hwmon/Kconfig 2014-07-07 10:45:09.000000000 +0200
  11315. @@ -1602,6 +1602,16 @@
  11316. This driver provides support for the Ultra45 workstation environmental
  11317. sensors.
  11318. +config SENSORS_BCM2835
  11319. + depends on THERMAL_BCM2835=n
  11320. + tristate "Broadcom BCM2835 HWMON Driver"
  11321. + help
  11322. + If you say yes here you get support for the hardware
  11323. + monitoring features of the BCM2835 Chip
  11324. +
  11325. + This driver can also be built as a module. If so, the module
  11326. + will be called bcm2835-hwmon.
  11327. +
  11328. if ACPI
  11329. comment "ACPI drivers"
  11330. diff -Nur linux-3.15.4/drivers/hwmon/Makefile linux-rpi/drivers/hwmon/Makefile
  11331. --- linux-3.15.4/drivers/hwmon/Makefile 2014-07-07 03:59:25.000000000 +0200
  11332. +++ linux-rpi/drivers/hwmon/Makefile 2014-07-07 10:45:09.000000000 +0200
  11333. @@ -146,6 +146,7 @@
  11334. obj-$(CONFIG_SENSORS_W83L786NG) += w83l786ng.o
  11335. obj-$(CONFIG_SENSORS_WM831X) += wm831x-hwmon.o
  11336. obj-$(CONFIG_SENSORS_WM8350) += wm8350-hwmon.o
  11337. +obj-$(CONFIG_SENSORS_BCM2835) += bcm2835-hwmon.o
  11338. obj-$(CONFIG_PMBUS) += pmbus/
  11339. diff -Nur linux-3.15.4/drivers/i2c/busses/i2c-bcm2708.c linux-rpi/drivers/i2c/busses/i2c-bcm2708.c
  11340. --- linux-3.15.4/drivers/i2c/busses/i2c-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  11341. +++ linux-rpi/drivers/i2c/busses/i2c-bcm2708.c 2014-07-07 10:45:09.000000000 +0200
  11342. @@ -0,0 +1,448 @@
  11343. +/*
  11344. + * Driver for Broadcom BCM2708 BSC Controllers
  11345. + *
  11346. + * Copyright (C) 2012 Chris Boot & Frank Buss
  11347. + *
  11348. + * This driver is inspired by:
  11349. + * i2c-ocores.c, by Peter Korsgaard <jacmet@sunsite.dk>
  11350. + *
  11351. + * This program is free software; you can redistribute it and/or modify
  11352. + * it under the terms of the GNU General Public License as published by
  11353. + * the Free Software Foundation; either version 2 of the License, or
  11354. + * (at your option) any later version.
  11355. + *
  11356. + * This program is distributed in the hope that it will be useful,
  11357. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11358. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11359. + * GNU General Public License for more details.
  11360. + *
  11361. + * You should have received a copy of the GNU General Public License
  11362. + * along with this program; if not, write to the Free Software
  11363. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  11364. + */
  11365. +
  11366. +#include <linux/kernel.h>
  11367. +#include <linux/module.h>
  11368. +#include <linux/spinlock.h>
  11369. +#include <linux/clk.h>
  11370. +#include <linux/err.h>
  11371. +#include <linux/platform_device.h>
  11372. +#include <linux/io.h>
  11373. +#include <linux/slab.h>
  11374. +#include <linux/i2c.h>
  11375. +#include <linux/interrupt.h>
  11376. +#include <linux/sched.h>
  11377. +#include <linux/wait.h>
  11378. +
  11379. +/* BSC register offsets */
  11380. +#define BSC_C 0x00
  11381. +#define BSC_S 0x04
  11382. +#define BSC_DLEN 0x08
  11383. +#define BSC_A 0x0c
  11384. +#define BSC_FIFO 0x10
  11385. +#define BSC_DIV 0x14
  11386. +#define BSC_DEL 0x18
  11387. +#define BSC_CLKT 0x1c
  11388. +
  11389. +/* Bitfields in BSC_C */
  11390. +#define BSC_C_I2CEN 0x00008000
  11391. +#define BSC_C_INTR 0x00000400
  11392. +#define BSC_C_INTT 0x00000200
  11393. +#define BSC_C_INTD 0x00000100
  11394. +#define BSC_C_ST 0x00000080
  11395. +#define BSC_C_CLEAR_1 0x00000020
  11396. +#define BSC_C_CLEAR_2 0x00000010
  11397. +#define BSC_C_READ 0x00000001
  11398. +
  11399. +/* Bitfields in BSC_S */
  11400. +#define BSC_S_CLKT 0x00000200
  11401. +#define BSC_S_ERR 0x00000100
  11402. +#define BSC_S_RXF 0x00000080
  11403. +#define BSC_S_TXE 0x00000040
  11404. +#define BSC_S_RXD 0x00000020
  11405. +#define BSC_S_TXD 0x00000010
  11406. +#define BSC_S_RXR 0x00000008
  11407. +#define BSC_S_TXW 0x00000004
  11408. +#define BSC_S_DONE 0x00000002
  11409. +#define BSC_S_TA 0x00000001
  11410. +
  11411. +#define I2C_TIMEOUT_MS 150
  11412. +
  11413. +#define DRV_NAME "bcm2708_i2c"
  11414. +
  11415. +static unsigned int baudrate = CONFIG_I2C_BCM2708_BAUDRATE;
  11416. +module_param(baudrate, uint, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
  11417. +MODULE_PARM_DESC(baudrate, "The I2C baudrate");
  11418. +
  11419. +static bool combined = false;
  11420. +module_param(combined, bool, 0644);
  11421. +MODULE_PARM_DESC(combined, "Use combined transactions");
  11422. +
  11423. +struct bcm2708_i2c {
  11424. + struct i2c_adapter adapter;
  11425. +
  11426. + spinlock_t lock;
  11427. + void __iomem *base;
  11428. + int irq;
  11429. + struct clk *clk;
  11430. +
  11431. + struct completion done;
  11432. +
  11433. + struct i2c_msg *msg;
  11434. + int pos;
  11435. + int nmsgs;
  11436. + bool error;
  11437. +};
  11438. +
  11439. +/*
  11440. + * This function sets the ALT mode on the I2C pins so that we can use them with
  11441. + * the BSC hardware.
  11442. + *
  11443. + * FIXME: This is a hack. Use pinmux / pinctrl.
  11444. + */
  11445. +static void bcm2708_i2c_init_pinmode(int id)
  11446. +{
  11447. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  11448. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  11449. +
  11450. + int pin;
  11451. + u32 *gpio = ioremap(GPIO_BASE, SZ_16K);
  11452. +
  11453. + BUG_ON(id != 0 && id != 1);
  11454. + /* BSC0 is on GPIO 0 & 1, BSC1 is on GPIO 2 & 3 */
  11455. + for (pin = id*2+0; pin <= id*2+1; pin++) {
  11456. +printk("bcm2708_i2c_init_pinmode(%d,%d)\n", id, pin);
  11457. + INP_GPIO(pin); /* set mode to GPIO input first */
  11458. + SET_GPIO_ALT(pin, 0); /* set mode to ALT 0 */
  11459. + }
  11460. +
  11461. + iounmap(gpio);
  11462. +
  11463. +#undef INP_GPIO
  11464. +#undef SET_GPIO_ALT
  11465. +}
  11466. +
  11467. +static inline u32 bcm2708_rd(struct bcm2708_i2c *bi, unsigned reg)
  11468. +{
  11469. + return readl(bi->base + reg);
  11470. +}
  11471. +
  11472. +static inline void bcm2708_wr(struct bcm2708_i2c *bi, unsigned reg, u32 val)
  11473. +{
  11474. + writel(val, bi->base + reg);
  11475. +}
  11476. +
  11477. +static inline void bcm2708_bsc_reset(struct bcm2708_i2c *bi)
  11478. +{
  11479. + bcm2708_wr(bi, BSC_C, 0);
  11480. + bcm2708_wr(bi, BSC_S, BSC_S_CLKT | BSC_S_ERR | BSC_S_DONE);
  11481. +}
  11482. +
  11483. +static inline void bcm2708_bsc_fifo_drain(struct bcm2708_i2c *bi)
  11484. +{
  11485. + while ((bcm2708_rd(bi, BSC_S) & BSC_S_RXD) && (bi->pos < bi->msg->len))
  11486. + bi->msg->buf[bi->pos++] = bcm2708_rd(bi, BSC_FIFO);
  11487. +}
  11488. +
  11489. +static inline void bcm2708_bsc_fifo_fill(struct bcm2708_i2c *bi)
  11490. +{
  11491. + while ((bcm2708_rd(bi, BSC_S) & BSC_S_TXD) && (bi->pos < bi->msg->len))
  11492. + bcm2708_wr(bi, BSC_FIFO, bi->msg->buf[bi->pos++]);
  11493. +}
  11494. +
  11495. +static inline void bcm2708_bsc_setup(struct bcm2708_i2c *bi)
  11496. +{
  11497. + unsigned long bus_hz;
  11498. + u32 cdiv, s;
  11499. + u32 c = BSC_C_I2CEN | BSC_C_INTD | BSC_C_ST | BSC_C_CLEAR_1;
  11500. +
  11501. + bus_hz = clk_get_rate(bi->clk);
  11502. + cdiv = bus_hz / baudrate;
  11503. + if (cdiv > 0xffff)
  11504. + cdiv = 0xffff;
  11505. +
  11506. + if (bi->msg->flags & I2C_M_RD)
  11507. + c |= BSC_C_INTR | BSC_C_READ;
  11508. + else
  11509. + c |= BSC_C_INTT;
  11510. +
  11511. + bcm2708_wr(bi, BSC_DIV, cdiv);
  11512. + bcm2708_wr(bi, BSC_A, bi->msg->addr);
  11513. + bcm2708_wr(bi, BSC_DLEN, bi->msg->len);
  11514. + if (combined)
  11515. + {
  11516. + /* Do the next two messages meet combined transaction criteria?
  11517. + - Current message is a write, next message is a read
  11518. + - Both messages to same slave address
  11519. + - Write message can fit inside FIFO (16 bytes or less) */
  11520. + if ( (bi->nmsgs > 1) &&
  11521. + !(bi->msg[0].flags & I2C_M_RD) && (bi->msg[1].flags & I2C_M_RD) &&
  11522. + (bi->msg[0].addr == bi->msg[1].addr) && (bi->msg[0].len <= 16)) {
  11523. + /* Fill FIFO with entire write message (16 byte FIFO) */
  11524. + while (bi->pos < bi->msg->len)
  11525. + bcm2708_wr(bi, BSC_FIFO, bi->msg->buf[bi->pos++]);
  11526. + /* Start write transfer (no interrupts, don't clear FIFO) */
  11527. + bcm2708_wr(bi, BSC_C, BSC_C_I2CEN | BSC_C_ST);
  11528. + /* poll for transfer start bit (should only take 1-20 polls) */
  11529. + do {
  11530. + s = bcm2708_rd(bi, BSC_S);
  11531. + } while (!(s & (BSC_S_TA | BSC_S_ERR | BSC_S_CLKT | BSC_S_DONE)));
  11532. + /* Send next read message before the write transfer finishes. */
  11533. + bi->nmsgs--;
  11534. + bi->msg++;
  11535. + bi->pos = 0;
  11536. + bcm2708_wr(bi, BSC_DLEN, bi->msg->len);
  11537. + c = BSC_C_I2CEN | BSC_C_INTD | BSC_C_INTR | BSC_C_ST | BSC_C_READ;
  11538. + }
  11539. + }
  11540. + bcm2708_wr(bi, BSC_C, c);
  11541. +}
  11542. +
  11543. +static irqreturn_t bcm2708_i2c_interrupt(int irq, void *dev_id)
  11544. +{
  11545. + struct bcm2708_i2c *bi = dev_id;
  11546. + bool handled = true;
  11547. + u32 s;
  11548. +
  11549. + spin_lock(&bi->lock);
  11550. +
  11551. + /* we may see camera interrupts on the "other" I2C channel
  11552. + Just return if we've not sent anything */
  11553. + if (!bi->nmsgs || !bi->msg )
  11554. + goto early_exit;
  11555. +
  11556. + s = bcm2708_rd(bi, BSC_S);
  11557. +
  11558. + if (s & (BSC_S_CLKT | BSC_S_ERR)) {
  11559. + bcm2708_bsc_reset(bi);
  11560. + bi->error = true;
  11561. +
  11562. + /* wake up our bh */
  11563. + complete(&bi->done);
  11564. + } else if (s & BSC_S_DONE) {
  11565. + bi->nmsgs--;
  11566. +
  11567. + if (bi->msg->flags & I2C_M_RD)
  11568. + bcm2708_bsc_fifo_drain(bi);
  11569. +
  11570. + bcm2708_bsc_reset(bi);
  11571. +
  11572. + if (bi->nmsgs) {
  11573. + /* advance to next message */
  11574. + bi->msg++;
  11575. + bi->pos = 0;
  11576. + bcm2708_bsc_setup(bi);
  11577. + } else {
  11578. + /* wake up our bh */
  11579. + complete(&bi->done);
  11580. + }
  11581. + } else if (s & BSC_S_TXW) {
  11582. + bcm2708_bsc_fifo_fill(bi);
  11583. + } else if (s & BSC_S_RXR) {
  11584. + bcm2708_bsc_fifo_drain(bi);
  11585. + } else {
  11586. + handled = false;
  11587. + }
  11588. +
  11589. +early_exit:
  11590. + spin_unlock(&bi->lock);
  11591. +
  11592. + return handled ? IRQ_HANDLED : IRQ_NONE;
  11593. +}
  11594. +
  11595. +static int bcm2708_i2c_master_xfer(struct i2c_adapter *adap,
  11596. + struct i2c_msg *msgs, int num)
  11597. +{
  11598. + struct bcm2708_i2c *bi = adap->algo_data;
  11599. + unsigned long flags;
  11600. + int ret;
  11601. +
  11602. + spin_lock_irqsave(&bi->lock, flags);
  11603. +
  11604. + reinit_completion(&bi->done);
  11605. + bi->msg = msgs;
  11606. + bi->pos = 0;
  11607. + bi->nmsgs = num;
  11608. + bi->error = false;
  11609. +
  11610. + spin_unlock_irqrestore(&bi->lock, flags);
  11611. +
  11612. + bcm2708_bsc_setup(bi);
  11613. +
  11614. + ret = wait_for_completion_timeout(&bi->done,
  11615. + msecs_to_jiffies(I2C_TIMEOUT_MS));
  11616. + if (ret == 0) {
  11617. + dev_err(&adap->dev, "transfer timed out\n");
  11618. + spin_lock_irqsave(&bi->lock, flags);
  11619. + bcm2708_bsc_reset(bi);
  11620. + spin_unlock_irqrestore(&bi->lock, flags);
  11621. + return -ETIMEDOUT;
  11622. + }
  11623. +
  11624. + return bi->error ? -EIO : num;
  11625. +}
  11626. +
  11627. +static u32 bcm2708_i2c_functionality(struct i2c_adapter *adap)
  11628. +{
  11629. + return I2C_FUNC_I2C | /*I2C_FUNC_10BIT_ADDR |*/ I2C_FUNC_SMBUS_EMUL;
  11630. +}
  11631. +
  11632. +static struct i2c_algorithm bcm2708_i2c_algorithm = {
  11633. + .master_xfer = bcm2708_i2c_master_xfer,
  11634. + .functionality = bcm2708_i2c_functionality,
  11635. +};
  11636. +
  11637. +static int bcm2708_i2c_probe(struct platform_device *pdev)
  11638. +{
  11639. + struct resource *regs;
  11640. + int irq, err = -ENOMEM;
  11641. + struct clk *clk;
  11642. + struct bcm2708_i2c *bi;
  11643. + struct i2c_adapter *adap;
  11644. + unsigned long bus_hz;
  11645. + u32 cdiv;
  11646. +
  11647. + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  11648. + if (!regs) {
  11649. + dev_err(&pdev->dev, "could not get IO memory\n");
  11650. + return -ENXIO;
  11651. + }
  11652. +
  11653. + irq = platform_get_irq(pdev, 0);
  11654. + if (irq < 0) {
  11655. + dev_err(&pdev->dev, "could not get IRQ\n");
  11656. + return irq;
  11657. + }
  11658. +
  11659. + clk = clk_get(&pdev->dev, NULL);
  11660. + if (IS_ERR(clk)) {
  11661. + dev_err(&pdev->dev, "could not find clk: %ld\n", PTR_ERR(clk));
  11662. + return PTR_ERR(clk);
  11663. + }
  11664. +
  11665. + bcm2708_i2c_init_pinmode(pdev->id);
  11666. +
  11667. + bi = kzalloc(sizeof(*bi), GFP_KERNEL);
  11668. + if (!bi)
  11669. + goto out_clk_put;
  11670. +
  11671. + platform_set_drvdata(pdev, bi);
  11672. +
  11673. + adap = &bi->adapter;
  11674. + adap->class = I2C_CLASS_HWMON | I2C_CLASS_DDC;
  11675. + adap->algo = &bcm2708_i2c_algorithm;
  11676. + adap->algo_data = bi;
  11677. + adap->dev.parent = &pdev->dev;
  11678. + adap->nr = pdev->id;
  11679. + strlcpy(adap->name, dev_name(&pdev->dev), sizeof(adap->name));
  11680. +
  11681. + switch (pdev->id) {
  11682. + case 0:
  11683. + adap->class = I2C_CLASS_HWMON;
  11684. + break;
  11685. + case 1:
  11686. + adap->class = I2C_CLASS_DDC;
  11687. + break;
  11688. + default:
  11689. + dev_err(&pdev->dev, "can only bind to BSC 0 or 1\n");
  11690. + err = -ENXIO;
  11691. + goto out_free_bi;
  11692. + }
  11693. +
  11694. + spin_lock_init(&bi->lock);
  11695. + init_completion(&bi->done);
  11696. +
  11697. + bi->base = ioremap(regs->start, resource_size(regs));
  11698. + if (!bi->base) {
  11699. + dev_err(&pdev->dev, "could not remap memory\n");
  11700. + goto out_free_bi;
  11701. + }
  11702. +
  11703. + bi->irq = irq;
  11704. + bi->clk = clk;
  11705. +
  11706. + err = request_irq(irq, bcm2708_i2c_interrupt, IRQF_SHARED,
  11707. + dev_name(&pdev->dev), bi);
  11708. + if (err) {
  11709. + dev_err(&pdev->dev, "could not request IRQ: %d\n", err);
  11710. + goto out_iounmap;
  11711. + }
  11712. +
  11713. + bcm2708_bsc_reset(bi);
  11714. +
  11715. + err = i2c_add_numbered_adapter(adap);
  11716. + if (err < 0) {
  11717. + dev_err(&pdev->dev, "could not add I2C adapter: %d\n", err);
  11718. + goto out_free_irq;
  11719. + }
  11720. +
  11721. + bus_hz = clk_get_rate(bi->clk);
  11722. + cdiv = bus_hz / baudrate;
  11723. + if (cdiv > 0xffff) {
  11724. + cdiv = 0xffff;
  11725. + baudrate = bus_hz / cdiv;
  11726. + }
  11727. +
  11728. + dev_info(&pdev->dev, "BSC%d Controller at 0x%08lx (irq %d) (baudrate %d)\n",
  11729. + pdev->id, (unsigned long)regs->start, irq, baudrate);
  11730. +
  11731. + return 0;
  11732. +
  11733. +out_free_irq:
  11734. + free_irq(bi->irq, bi);
  11735. +out_iounmap:
  11736. + iounmap(bi->base);
  11737. +out_free_bi:
  11738. + kfree(bi);
  11739. +out_clk_put:
  11740. + clk_put(clk);
  11741. + return err;
  11742. +}
  11743. +
  11744. +static int bcm2708_i2c_remove(struct platform_device *pdev)
  11745. +{
  11746. + struct bcm2708_i2c *bi = platform_get_drvdata(pdev);
  11747. +
  11748. + platform_set_drvdata(pdev, NULL);
  11749. +
  11750. + i2c_del_adapter(&bi->adapter);
  11751. + free_irq(bi->irq, bi);
  11752. + iounmap(bi->base);
  11753. + clk_disable(bi->clk);
  11754. + clk_put(bi->clk);
  11755. + kfree(bi);
  11756. +
  11757. + return 0;
  11758. +}
  11759. +
  11760. +static struct platform_driver bcm2708_i2c_driver = {
  11761. + .driver = {
  11762. + .name = DRV_NAME,
  11763. + .owner = THIS_MODULE,
  11764. + },
  11765. + .probe = bcm2708_i2c_probe,
  11766. + .remove = bcm2708_i2c_remove,
  11767. +};
  11768. +
  11769. +// module_platform_driver(bcm2708_i2c_driver);
  11770. +
  11771. +
  11772. +static int __init bcm2708_i2c_init(void)
  11773. +{
  11774. + return platform_driver_register(&bcm2708_i2c_driver);
  11775. +}
  11776. +
  11777. +static void __exit bcm2708_i2c_exit(void)
  11778. +{
  11779. + platform_driver_unregister(&bcm2708_i2c_driver);
  11780. +}
  11781. +
  11782. +module_init(bcm2708_i2c_init);
  11783. +module_exit(bcm2708_i2c_exit);
  11784. +
  11785. +
  11786. +
  11787. +MODULE_DESCRIPTION("BSC controller driver for Broadcom BCM2708");
  11788. +MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
  11789. +MODULE_LICENSE("GPL v2");
  11790. +MODULE_ALIAS("platform:" DRV_NAME);
  11791. diff -Nur linux-3.15.4/drivers/i2c/busses/Kconfig linux-rpi/drivers/i2c/busses/Kconfig
  11792. --- linux-3.15.4/drivers/i2c/busses/Kconfig 2014-07-07 03:59:25.000000000 +0200
  11793. +++ linux-rpi/drivers/i2c/busses/Kconfig 2014-07-07 10:45:09.000000000 +0200
  11794. @@ -348,6 +348,25 @@
  11795. This support is also available as a module. If so, the module
  11796. will be called i2c-bcm2835.
  11797. +config I2C_BCM2708
  11798. + tristate "BCM2708 BSC"
  11799. + depends on MACH_BCM2708
  11800. + help
  11801. + Enabling this option will add BSC (Broadcom Serial Controller)
  11802. + support for the BCM2708. BSC is a Broadcom proprietary bus compatible
  11803. + with I2C/TWI/SMBus.
  11804. +
  11805. +config I2C_BCM2708_BAUDRATE
  11806. + prompt "BCM2708 I2C baudrate"
  11807. + depends on I2C_BCM2708
  11808. + int
  11809. + default 100000
  11810. + help
  11811. + Set the I2C baudrate. This will alter the default value. A
  11812. + different baudrate can be set by using a module parameter as well. If
  11813. + no parameter is provided when loading, this is the value that will be
  11814. + used.
  11815. +
  11816. config I2C_BCM_KONA
  11817. tristate "BCM Kona I2C adapter"
  11818. depends on ARCH_BCM_MOBILE
  11819. diff -Nur linux-3.15.4/drivers/i2c/busses/Makefile linux-rpi/drivers/i2c/busses/Makefile
  11820. --- linux-3.15.4/drivers/i2c/busses/Makefile 2014-07-07 03:59:25.000000000 +0200
  11821. +++ linux-rpi/drivers/i2c/busses/Makefile 2014-07-07 10:45:09.000000000 +0200
  11822. @@ -32,6 +32,7 @@
  11823. obj-$(CONFIG_I2C_AT91) += i2c-at91.o
  11824. obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o
  11825. obj-$(CONFIG_I2C_BCM2835) += i2c-bcm2835.o
  11826. +obj-$(CONFIG_I2C_BCM2708) += i2c-bcm2708.o
  11827. obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o
  11828. obj-$(CONFIG_I2C_CADENCE) += i2c-cadence.o
  11829. obj-$(CONFIG_I2C_CBUS_GPIO) += i2c-cbus-gpio.o
  11830. diff -Nur linux-3.15.4/drivers/infiniband/core/user_mad.c linux-rpi/drivers/infiniband/core/user_mad.c
  11831. --- linux-3.15.4/drivers/infiniband/core/user_mad.c 2014-07-07 03:59:25.000000000 +0200
  11832. +++ linux-rpi/drivers/infiniband/core/user_mad.c 2014-04-13 17:32:56.000000000 +0200
  11833. @@ -98,7 +98,7 @@
  11834. struct ib_umad_device {
  11835. int start_port, end_port;
  11836. - struct kobject kobj;
  11837. + struct kref ref;
  11838. struct ib_umad_port port[0];
  11839. };
  11840. @@ -134,18 +134,14 @@
  11841. static void ib_umad_add_one(struct ib_device *device);
  11842. static void ib_umad_remove_one(struct ib_device *device);
  11843. -static void ib_umad_release_dev(struct kobject *kobj)
  11844. +static void ib_umad_release_dev(struct kref *ref)
  11845. {
  11846. struct ib_umad_device *dev =
  11847. - container_of(kobj, struct ib_umad_device, kobj);
  11848. + container_of(ref, struct ib_umad_device, ref);
  11849. kfree(dev);
  11850. }
  11851. -static struct kobj_type ib_umad_dev_ktype = {
  11852. - .release = ib_umad_release_dev,
  11853. -};
  11854. -
  11855. static int hdr_size(struct ib_umad_file *file)
  11856. {
  11857. return file->use_pkey_index ? sizeof (struct ib_user_mad_hdr) :
  11858. @@ -784,19 +780,27 @@
  11859. {
  11860. struct ib_umad_port *port;
  11861. struct ib_umad_file *file;
  11862. - int ret = -ENXIO;
  11863. + int ret;
  11864. port = container_of(inode->i_cdev, struct ib_umad_port, cdev);
  11865. + if (port)
  11866. + kref_get(&port->umad_dev->ref);
  11867. + else
  11868. + return -ENXIO;
  11869. mutex_lock(&port->file_mutex);
  11870. - if (!port->ib_dev)
  11871. + if (!port->ib_dev) {
  11872. + ret = -ENXIO;
  11873. goto out;
  11874. + }
  11875. - ret = -ENOMEM;
  11876. file = kzalloc(sizeof *file, GFP_KERNEL);
  11877. - if (!file)
  11878. + if (!file) {
  11879. + kref_put(&port->umad_dev->ref, ib_umad_release_dev);
  11880. + ret = -ENOMEM;
  11881. goto out;
  11882. + }
  11883. mutex_init(&file->mutex);
  11884. spin_lock_init(&file->send_lock);
  11885. @@ -810,13 +814,6 @@
  11886. list_add_tail(&file->port_list, &port->file_list);
  11887. ret = nonseekable_open(inode, filp);
  11888. - if (ret) {
  11889. - list_del(&file->port_list);
  11890. - kfree(file);
  11891. - goto out;
  11892. - }
  11893. -
  11894. - kobject_get(&port->umad_dev->kobj);
  11895. out:
  11896. mutex_unlock(&port->file_mutex);
  11897. @@ -855,7 +852,7 @@
  11898. mutex_unlock(&file->port->file_mutex);
  11899. kfree(file);
  11900. - kobject_put(&dev->kobj);
  11901. + kref_put(&dev->ref, ib_umad_release_dev);
  11902. return 0;
  11903. }
  11904. @@ -883,6 +880,10 @@
  11905. int ret;
  11906. port = container_of(inode->i_cdev, struct ib_umad_port, sm_cdev);
  11907. + if (port)
  11908. + kref_get(&port->umad_dev->ref);
  11909. + else
  11910. + return -ENXIO;
  11911. if (filp->f_flags & O_NONBLOCK) {
  11912. if (down_trylock(&port->sm_sem)) {
  11913. @@ -897,27 +898,17 @@
  11914. }
  11915. ret = ib_modify_port(port->ib_dev, port->port_num, 0, &props);
  11916. - if (ret)
  11917. - goto err_up_sem;
  11918. + if (ret) {
  11919. + up(&port->sm_sem);
  11920. + goto fail;
  11921. + }
  11922. filp->private_data = port;
  11923. - ret = nonseekable_open(inode, filp);
  11924. - if (ret)
  11925. - goto err_clr_sm_cap;
  11926. -
  11927. - kobject_get(&port->umad_dev->kobj);
  11928. -
  11929. - return 0;
  11930. -
  11931. -err_clr_sm_cap:
  11932. - swap(props.set_port_cap_mask, props.clr_port_cap_mask);
  11933. - ib_modify_port(port->ib_dev, port->port_num, 0, &props);
  11934. -
  11935. -err_up_sem:
  11936. - up(&port->sm_sem);
  11937. + return nonseekable_open(inode, filp);
  11938. fail:
  11939. + kref_put(&port->umad_dev->ref, ib_umad_release_dev);
  11940. return ret;
  11941. }
  11942. @@ -936,7 +927,7 @@
  11943. up(&port->sm_sem);
  11944. - kobject_put(&port->umad_dev->kobj);
  11945. + kref_put(&port->umad_dev->ref, ib_umad_release_dev);
  11946. return ret;
  11947. }
  11948. @@ -1004,7 +995,6 @@
  11949. }
  11950. static int ib_umad_init_port(struct ib_device *device, int port_num,
  11951. - struct ib_umad_device *umad_dev,
  11952. struct ib_umad_port *port)
  11953. {
  11954. int devnum;
  11955. @@ -1037,7 +1027,6 @@
  11956. cdev_init(&port->cdev, &umad_fops);
  11957. port->cdev.owner = THIS_MODULE;
  11958. - port->cdev.kobj.parent = &umad_dev->kobj;
  11959. kobject_set_name(&port->cdev.kobj, "umad%d", port->dev_num);
  11960. if (cdev_add(&port->cdev, base, 1))
  11961. goto err_cdev;
  11962. @@ -1056,7 +1045,6 @@
  11963. base += IB_UMAD_MAX_PORTS;
  11964. cdev_init(&port->sm_cdev, &umad_sm_fops);
  11965. port->sm_cdev.owner = THIS_MODULE;
  11966. - port->sm_cdev.kobj.parent = &umad_dev->kobj;
  11967. kobject_set_name(&port->sm_cdev.kobj, "issm%d", port->dev_num);
  11968. if (cdev_add(&port->sm_cdev, base, 1))
  11969. goto err_sm_cdev;
  11970. @@ -1150,7 +1138,7 @@
  11971. if (!umad_dev)
  11972. return;
  11973. - kobject_init(&umad_dev->kobj, &ib_umad_dev_ktype);
  11974. + kref_init(&umad_dev->ref);
  11975. umad_dev->start_port = s;
  11976. umad_dev->end_port = e;
  11977. @@ -1158,8 +1146,7 @@
  11978. for (i = s; i <= e; ++i) {
  11979. umad_dev->port[i - s].umad_dev = umad_dev;
  11980. - if (ib_umad_init_port(device, i, umad_dev,
  11981. - &umad_dev->port[i - s]))
  11982. + if (ib_umad_init_port(device, i, &umad_dev->port[i - s]))
  11983. goto err;
  11984. }
  11985. @@ -1171,7 +1158,7 @@
  11986. while (--i >= s)
  11987. ib_umad_kill_port(&umad_dev->port[i - s]);
  11988. - kobject_put(&umad_dev->kobj);
  11989. + kref_put(&umad_dev->ref, ib_umad_release_dev);
  11990. }
  11991. static void ib_umad_remove_one(struct ib_device *device)
  11992. @@ -1185,7 +1172,7 @@
  11993. for (i = 0; i <= umad_dev->end_port - umad_dev->start_port; ++i)
  11994. ib_umad_kill_port(&umad_dev->port[i]);
  11995. - kobject_put(&umad_dev->kobj);
  11996. + kref_put(&umad_dev->ref, ib_umad_release_dev);
  11997. }
  11998. static char *umad_devnode(struct device *dev, umode_t *mode)
  11999. diff -Nur linux-3.15.4/drivers/infiniband/hw/cxgb4/cq.c linux-rpi/drivers/infiniband/hw/cxgb4/cq.c
  12000. --- linux-3.15.4/drivers/infiniband/hw/cxgb4/cq.c 2014-07-07 03:59:25.000000000 +0200
  12001. +++ linux-rpi/drivers/infiniband/hw/cxgb4/cq.c 2014-07-07 10:45:09.000000000 +0200
  12002. @@ -940,6 +940,7 @@
  12003. if (!mm2)
  12004. goto err4;
  12005. + memset(&uresp, 0, sizeof(uresp));
  12006. uresp.qid_mask = rhp->rdev.cqmask;
  12007. uresp.cqid = chp->cq.cqid;
  12008. uresp.size = chp->cq.size;
  12009. @@ -950,8 +951,7 @@
  12010. uresp.gts_key = ucontext->key;
  12011. ucontext->key += PAGE_SIZE;
  12012. spin_unlock(&ucontext->mmap_lock);
  12013. - ret = ib_copy_to_udata(udata, &uresp,
  12014. - sizeof(uresp) - sizeof(uresp.reserved));
  12015. + ret = ib_copy_to_udata(udata, &uresp, sizeof uresp);
  12016. if (ret)
  12017. goto err5;
  12018. diff -Nur linux-3.15.4/drivers/infiniband/hw/cxgb4/device.c linux-rpi/drivers/infiniband/hw/cxgb4/device.c
  12019. --- linux-3.15.4/drivers/infiniband/hw/cxgb4/device.c 2014-07-07 03:59:25.000000000 +0200
  12020. +++ linux-rpi/drivers/infiniband/hw/cxgb4/device.c 2014-07-07 10:45:09.000000000 +0200
  12021. @@ -736,7 +736,6 @@
  12022. pci_resource_len(devp->rdev.lldi.pdev, 2));
  12023. if (!devp->rdev.bar2_kva) {
  12024. pr_err(MOD "Unable to ioremap BAR2\n");
  12025. - ib_dealloc_device(&devp->ibdev);
  12026. return ERR_PTR(-EINVAL);
  12027. }
  12028. } else if (ocqp_supported(infop)) {
  12029. @@ -748,7 +747,6 @@
  12030. devp->rdev.lldi.vr->ocq.size);
  12031. if (!devp->rdev.oc_mw_kva) {
  12032. pr_err(MOD "Unable to ioremap onchip mem\n");
  12033. - ib_dealloc_device(&devp->ibdev);
  12034. return ERR_PTR(-EINVAL);
  12035. }
  12036. }
  12037. diff -Nur linux-3.15.4/drivers/infiniband/hw/cxgb4/provider.c linux-rpi/drivers/infiniband/hw/cxgb4/provider.c
  12038. --- linux-3.15.4/drivers/infiniband/hw/cxgb4/provider.c 2014-07-07 03:59:25.000000000 +0200
  12039. +++ linux-rpi/drivers/infiniband/hw/cxgb4/provider.c 2014-07-07 10:45:09.000000000 +0200
  12040. @@ -122,7 +122,7 @@
  12041. INIT_LIST_HEAD(&context->mmaps);
  12042. spin_lock_init(&context->mmap_lock);
  12043. - if (udata->outlen < sizeof(uresp) - sizeof(uresp.reserved)) {
  12044. + if (udata->outlen < sizeof(uresp)) {
  12045. if (!warned++)
  12046. pr_err(MOD "Warning - downlevel libcxgb4 (non-fatal), device status page disabled.");
  12047. rhp->rdev.flags |= T4_STATUS_PAGE_DISABLED;
  12048. @@ -140,8 +140,7 @@
  12049. context->key += PAGE_SIZE;
  12050. spin_unlock(&context->mmap_lock);
  12051. - ret = ib_copy_to_udata(udata, &uresp,
  12052. - sizeof(uresp) - sizeof(uresp.reserved));
  12053. + ret = ib_copy_to_udata(udata, &uresp, sizeof(uresp));
  12054. if (ret)
  12055. goto err_mm;
  12056. diff -Nur linux-3.15.4/drivers/infiniband/hw/cxgb4/user.h linux-rpi/drivers/infiniband/hw/cxgb4/user.h
  12057. --- linux-3.15.4/drivers/infiniband/hw/cxgb4/user.h 2014-07-07 03:59:25.000000000 +0200
  12058. +++ linux-rpi/drivers/infiniband/hw/cxgb4/user.h 2014-07-07 10:45:09.000000000 +0200
  12059. @@ -48,7 +48,6 @@
  12060. __u32 cqid;
  12061. __u32 size;
  12062. __u32 qid_mask;
  12063. - __u32 reserved; /* explicit padding (optional for i386) */
  12064. };
  12065. @@ -75,6 +74,5 @@
  12066. struct c4iw_alloc_ucontext_resp {
  12067. __u64 status_page_key;
  12068. __u32 status_page_size;
  12069. - __u32 reserved; /* explicit padding (optional for i386) */
  12070. };
  12071. #endif
  12072. diff -Nur linux-3.15.4/drivers/infiniband/hw/ipath/ipath_diag.c linux-rpi/drivers/infiniband/hw/ipath/ipath_diag.c
  12073. --- linux-3.15.4/drivers/infiniband/hw/ipath/ipath_diag.c 2014-07-07 03:59:25.000000000 +0200
  12074. +++ linux-rpi/drivers/infiniband/hw/ipath/ipath_diag.c 2014-07-07 10:45:09.000000000 +0200
  12075. @@ -346,10 +346,6 @@
  12076. ret = -EFAULT;
  12077. goto bail;
  12078. }
  12079. - dp.len = odp.len;
  12080. - dp.unit = odp.unit;
  12081. - dp.data = odp.data;
  12082. - dp.pbc_wd = 0;
  12083. } else {
  12084. ret = -EINVAL;
  12085. goto bail;
  12086. diff -Nur linux-3.15.4/drivers/infiniband/hw/mlx5/cq.c linux-rpi/drivers/infiniband/hw/mlx5/cq.c
  12087. --- linux-3.15.4/drivers/infiniband/hw/mlx5/cq.c 2014-07-07 03:59:25.000000000 +0200
  12088. +++ linux-rpi/drivers/infiniband/hw/mlx5/cq.c 2014-07-07 10:45:09.000000000 +0200
  12089. @@ -32,7 +32,6 @@
  12090. #include <linux/kref.h>
  12091. #include <rdma/ib_umem.h>
  12092. -#include <rdma/ib_user_verbs.h>
  12093. #include "mlx5_ib.h"
  12094. #include "user.h"
  12095. @@ -603,24 +602,14 @@
  12096. int *cqe_size, int *index, int *inlen)
  12097. {
  12098. struct mlx5_ib_create_cq ucmd;
  12099. - size_t ucmdlen;
  12100. int page_shift;
  12101. int npages;
  12102. int ncont;
  12103. int err;
  12104. - ucmdlen =
  12105. - (udata->inlen - sizeof(struct ib_uverbs_cmd_hdr) <
  12106. - sizeof(ucmd)) ? (sizeof(ucmd) -
  12107. - sizeof(ucmd.reserved)) : sizeof(ucmd);
  12108. -
  12109. - if (ib_copy_from_udata(&ucmd, udata, ucmdlen))
  12110. + if (ib_copy_from_udata(&ucmd, udata, sizeof(ucmd)))
  12111. return -EFAULT;
  12112. - if (ucmdlen == sizeof(ucmd) &&
  12113. - ucmd.reserved != 0)
  12114. - return -EINVAL;
  12115. -
  12116. if (ucmd.cqe_size != 64 && ucmd.cqe_size != 128)
  12117. return -EINVAL;
  12118. diff -Nur linux-3.15.4/drivers/infiniband/hw/mlx5/srq.c linux-rpi/drivers/infiniband/hw/mlx5/srq.c
  12119. --- linux-3.15.4/drivers/infiniband/hw/mlx5/srq.c 2014-07-07 03:59:25.000000000 +0200
  12120. +++ linux-rpi/drivers/infiniband/hw/mlx5/srq.c 2014-07-07 10:45:09.000000000 +0200
  12121. @@ -35,7 +35,6 @@
  12122. #include <linux/mlx5/srq.h>
  12123. #include <linux/slab.h>
  12124. #include <rdma/ib_umem.h>
  12125. -#include <rdma/ib_user_verbs.h>
  12126. #include "mlx5_ib.h"
  12127. #include "user.h"
  12128. @@ -79,27 +78,16 @@
  12129. {
  12130. struct mlx5_ib_dev *dev = to_mdev(pd->device);
  12131. struct mlx5_ib_create_srq ucmd;
  12132. - size_t ucmdlen;
  12133. int err;
  12134. int npages;
  12135. int page_shift;
  12136. int ncont;
  12137. u32 offset;
  12138. - ucmdlen =
  12139. - (udata->inlen - sizeof(struct ib_uverbs_cmd_hdr) <
  12140. - sizeof(ucmd)) ? (sizeof(ucmd) -
  12141. - sizeof(ucmd.reserved)) : sizeof(ucmd);
  12142. -
  12143. - if (ib_copy_from_udata(&ucmd, udata, ucmdlen)) {
  12144. + if (ib_copy_from_udata(&ucmd, udata, sizeof(ucmd))) {
  12145. mlx5_ib_dbg(dev, "failed copy udata\n");
  12146. return -EFAULT;
  12147. }
  12148. -
  12149. - if (ucmdlen == sizeof(ucmd) &&
  12150. - ucmd.reserved != 0)
  12151. - return -EINVAL;
  12152. -
  12153. srq->wq_sig = !!(ucmd.flags & MLX5_SRQ_FLAG_SIGNATURE);
  12154. srq->umem = ib_umem_get(pd->uobject->context, ucmd.buf_addr, buf_size,
  12155. diff -Nur linux-3.15.4/drivers/infiniband/hw/mlx5/user.h linux-rpi/drivers/infiniband/hw/mlx5/user.h
  12156. --- linux-3.15.4/drivers/infiniband/hw/mlx5/user.h 2014-07-07 03:59:25.000000000 +0200
  12157. +++ linux-rpi/drivers/infiniband/hw/mlx5/user.h 2014-07-07 10:45:09.000000000 +0200
  12158. @@ -91,7 +91,6 @@
  12159. __u64 buf_addr;
  12160. __u64 db_addr;
  12161. __u32 cqe_size;
  12162. - __u32 reserved; /* explicit padding (optional on i386) */
  12163. };
  12164. struct mlx5_ib_create_cq_resp {
  12165. @@ -110,7 +109,6 @@
  12166. __u64 buf_addr;
  12167. __u64 db_addr;
  12168. __u32 flags;
  12169. - __u32 reserved; /* explicit padding (optional on i386) */
  12170. };
  12171. struct mlx5_ib_create_srq_resp {
  12172. diff -Nur linux-3.15.4/drivers/infiniband/hw/qib/qib_mad.c linux-rpi/drivers/infiniband/hw/qib/qib_mad.c
  12173. --- linux-3.15.4/drivers/infiniband/hw/qib/qib_mad.c 2014-07-07 03:59:25.000000000 +0200
  12174. +++ linux-rpi/drivers/infiniband/hw/qib/qib_mad.c 2014-07-07 10:45:09.000000000 +0200
  12175. @@ -1028,7 +1028,7 @@
  12176. event.event = IB_EVENT_PKEY_CHANGE;
  12177. event.device = &dd->verbs_dev.ibdev;
  12178. - event.element.port_num = port;
  12179. + event.element.port_num = 1;
  12180. ib_dispatch_event(&event);
  12181. }
  12182. return 0;
  12183. diff -Nur linux-3.15.4/drivers/infiniband/ulp/srp/ib_srp.c linux-rpi/drivers/infiniband/ulp/srp/ib_srp.c
  12184. --- linux-3.15.4/drivers/infiniband/ulp/srp/ib_srp.c 2014-07-07 03:59:25.000000000 +0200
  12185. +++ linux-rpi/drivers/infiniband/ulp/srp/ib_srp.c 2014-07-07 10:45:09.000000000 +0200
  12186. @@ -1594,12 +1594,6 @@
  12187. err_iu:
  12188. srp_put_tx_iu(target, iu, SRP_IU_CMD);
  12189. - /*
  12190. - * Avoid that the loops that iterate over the request ring can
  12191. - * encounter a dangling SCSI command pointer.
  12192. - */
  12193. - req->scmnd = NULL;
  12194. -
  12195. spin_lock_irqsave(&target->lock, flags);
  12196. list_add(&req->list, &target->free_reqs);
  12197. diff -Nur linux-3.15.4/drivers/input/mouse/elantech.c linux-rpi/drivers/input/mouse/elantech.c
  12198. --- linux-3.15.4/drivers/input/mouse/elantech.c 2014-07-07 03:59:25.000000000 +0200
  12199. +++ linux-rpi/drivers/input/mouse/elantech.c 2014-07-07 10:45:09.000000000 +0200
  12200. @@ -473,15 +473,8 @@
  12201. input_report_key(dev, BTN_TOOL_FINGER, fingers == 1);
  12202. input_report_key(dev, BTN_TOOL_DOUBLETAP, fingers == 2);
  12203. input_report_key(dev, BTN_TOOL_TRIPLETAP, fingers == 3);
  12204. -
  12205. - /* For clickpads map both buttons to BTN_LEFT */
  12206. - if (etd->fw_version & 0x001000) {
  12207. - input_report_key(dev, BTN_LEFT, packet[0] & 0x03);
  12208. - } else {
  12209. - input_report_key(dev, BTN_LEFT, packet[0] & 0x01);
  12210. - input_report_key(dev, BTN_RIGHT, packet[0] & 0x02);
  12211. - }
  12212. -
  12213. + input_report_key(dev, BTN_LEFT, packet[0] & 0x01);
  12214. + input_report_key(dev, BTN_RIGHT, packet[0] & 0x02);
  12215. input_report_abs(dev, ABS_PRESSURE, pres);
  12216. input_report_abs(dev, ABS_TOOL_WIDTH, width);
  12217. @@ -491,17 +484,10 @@
  12218. static void elantech_input_sync_v4(struct psmouse *psmouse)
  12219. {
  12220. struct input_dev *dev = psmouse->dev;
  12221. - struct elantech_data *etd = psmouse->private;
  12222. unsigned char *packet = psmouse->packet;
  12223. - /* For clickpads map both buttons to BTN_LEFT */
  12224. - if (etd->fw_version & 0x001000) {
  12225. - input_report_key(dev, BTN_LEFT, packet[0] & 0x03);
  12226. - } else {
  12227. - input_report_key(dev, BTN_LEFT, packet[0] & 0x01);
  12228. - input_report_key(dev, BTN_RIGHT, packet[0] & 0x02);
  12229. - }
  12230. -
  12231. + input_report_key(dev, BTN_LEFT, packet[0] & 0x01);
  12232. + input_report_key(dev, BTN_RIGHT, packet[0] & 0x02);
  12233. input_mt_report_pointer_emulation(dev, true);
  12234. input_sync(dev);
  12235. }
  12236. @@ -849,7 +835,7 @@
  12237. if (etd->set_hw_resolution)
  12238. etd->reg_10 = 0x0b;
  12239. else
  12240. - etd->reg_10 = 0x01;
  12241. + etd->reg_10 = 0x03;
  12242. if (elantech_write_reg(psmouse, 0x10, etd->reg_10))
  12243. rc = -1;
  12244. @@ -1350,8 +1336,7 @@
  12245. }
  12246. /*
  12247. - * Some hw_version 3 models go into error state when we try to set
  12248. - * bit 3 and/or bit 1 of r10.
  12249. + * Some hw_version 3 models go into error state when we try to set bit 3 of r10
  12250. */
  12251. static const struct dmi_system_id no_hw_res_dmi_table[] = {
  12252. #if defined(CONFIG_DMI) && defined(CONFIG_X86)
  12253. diff -Nur linux-3.15.4/drivers/input/mouse/synaptics.c linux-rpi/drivers/input/mouse/synaptics.c
  12254. --- linux-3.15.4/drivers/input/mouse/synaptics.c 2014-07-07 03:59:25.000000000 +0200
  12255. +++ linux-rpi/drivers/input/mouse/synaptics.c 2014-07-07 10:45:09.000000000 +0200
  12256. @@ -347,6 +347,15 @@
  12257. unsigned char resp[3];
  12258. int i;
  12259. + for (i = 0; min_max_pnpid_table[i].pnp_ids; i++)
  12260. + if (matches_pnp_id(psmouse, min_max_pnpid_table[i].pnp_ids)) {
  12261. + priv->x_min = min_max_pnpid_table[i].x_min;
  12262. + priv->x_max = min_max_pnpid_table[i].x_max;
  12263. + priv->y_min = min_max_pnpid_table[i].y_min;
  12264. + priv->y_max = min_max_pnpid_table[i].y_max;
  12265. + return 0;
  12266. + }
  12267. +
  12268. if (SYN_ID_MAJOR(priv->identity) < 4)
  12269. return 0;
  12270. @@ -357,16 +366,6 @@
  12271. }
  12272. }
  12273. - for (i = 0; min_max_pnpid_table[i].pnp_ids; i++) {
  12274. - if (matches_pnp_id(psmouse, min_max_pnpid_table[i].pnp_ids)) {
  12275. - priv->x_min = min_max_pnpid_table[i].x_min;
  12276. - priv->x_max = min_max_pnpid_table[i].x_max;
  12277. - priv->y_min = min_max_pnpid_table[i].y_min;
  12278. - priv->y_max = min_max_pnpid_table[i].y_max;
  12279. - return 0;
  12280. - }
  12281. - }
  12282. -
  12283. if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 5 &&
  12284. SYN_CAP_MAX_DIMENSIONS(priv->ext_cap_0c)) {
  12285. if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_MAX_COORDS, resp)) {
  12286. diff -Nur linux-3.15.4/drivers/media/platform/bcm2835/bcm2835-camera.c linux-rpi/drivers/media/platform/bcm2835/bcm2835-camera.c
  12287. --- linux-3.15.4/drivers/media/platform/bcm2835/bcm2835-camera.c 1970-01-01 01:00:00.000000000 +0100
  12288. +++ linux-rpi/drivers/media/platform/bcm2835/bcm2835-camera.c 2014-07-07 10:45:10.000000000 +0200
  12289. @@ -0,0 +1,1827 @@
  12290. +/*
  12291. + * Broadcom BM2835 V4L2 driver
  12292. + *
  12293. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  12294. + *
  12295. + * This file is subject to the terms and conditions of the GNU General Public
  12296. + * License. See the file COPYING in the main directory of this archive
  12297. + * for more details.
  12298. + *
  12299. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  12300. + * Dave Stevenson <dsteve@broadcom.com>
  12301. + * Simon Mellor <simellor@broadcom.com>
  12302. + * Luke Diamand <luked@broadcom.com>
  12303. + */
  12304. +
  12305. +#include <linux/errno.h>
  12306. +#include <linux/kernel.h>
  12307. +#include <linux/module.h>
  12308. +#include <linux/slab.h>
  12309. +#include <media/videobuf2-vmalloc.h>
  12310. +#include <media/videobuf2-dma-contig.h>
  12311. +#include <media/v4l2-device.h>
  12312. +#include <media/v4l2-ioctl.h>
  12313. +#include <media/v4l2-ctrls.h>
  12314. +#include <media/v4l2-fh.h>
  12315. +#include <media/v4l2-event.h>
  12316. +#include <media/v4l2-common.h>
  12317. +#include <linux/delay.h>
  12318. +
  12319. +#include "mmal-common.h"
  12320. +#include "mmal-encodings.h"
  12321. +#include "mmal-vchiq.h"
  12322. +#include "mmal-msg.h"
  12323. +#include "mmal-parameters.h"
  12324. +#include "bcm2835-camera.h"
  12325. +
  12326. +#define BM2835_MMAL_VERSION "0.0.2"
  12327. +#define BM2835_MMAL_MODULE_NAME "bcm2835-v4l2"
  12328. +#define MIN_WIDTH 16
  12329. +#define MIN_HEIGHT 16
  12330. +#define MAX_WIDTH 2592
  12331. +#define MAX_HEIGHT 1944
  12332. +#define MIN_BUFFER_SIZE (80*1024)
  12333. +
  12334. +#define MAX_VIDEO_MODE_WIDTH 1280
  12335. +#define MAX_VIDEO_MODE_HEIGHT 720
  12336. +
  12337. +MODULE_DESCRIPTION("Broadcom 2835 MMAL video capture");
  12338. +MODULE_AUTHOR("Vincent Sanders");
  12339. +MODULE_LICENSE("GPL");
  12340. +MODULE_VERSION(BM2835_MMAL_VERSION);
  12341. +
  12342. +int bcm2835_v4l2_debug;
  12343. +module_param_named(debug, bcm2835_v4l2_debug, int, 0644);
  12344. +MODULE_PARM_DESC(bcm2835_v4l2_debug, "Debug level 0-2");
  12345. +
  12346. +int max_video_width = MAX_VIDEO_MODE_WIDTH;
  12347. +int max_video_height = MAX_VIDEO_MODE_HEIGHT;
  12348. +module_param(max_video_width, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  12349. +MODULE_PARM_DESC(max_video_width, "Threshold for video mode");
  12350. +module_param(max_video_height, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  12351. +MODULE_PARM_DESC(max_video_height, "Threshold for video mode");
  12352. +
  12353. +/* Gstreamer bug https://bugzilla.gnome.org/show_bug.cgi?id=726521
  12354. + * v4l2src does bad (and actually wrong) things when the vidioc_enum_framesizes
  12355. + * function says type V4L2_FRMSIZE_TYPE_STEPWISE, which we do by default.
  12356. + * It's happier if we just don't say anything at all, when it then
  12357. + * sets up a load of defaults that it thinks might work.
  12358. + * If gst_v4l2src_is_broken is non-zero, then we remove the function from
  12359. + * our function table list (actually switch to an alternate set, but same
  12360. + * result).
  12361. + */
  12362. +int gst_v4l2src_is_broken = 0;
  12363. +module_param(gst_v4l2src_is_broken, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  12364. +MODULE_PARM_DESC(gst_v4l2src_is_broken, "If non-zero, enable workaround for Gstreamer");
  12365. +
  12366. +static struct bm2835_mmal_dev *gdev; /* global device data */
  12367. +
  12368. +#define FPS_MIN 1
  12369. +#define FPS_MAX 90
  12370. +
  12371. +/* timeperframe: min/max and default */
  12372. +static const struct v4l2_fract
  12373. + tpf_min = {.numerator = 1, .denominator = FPS_MAX},
  12374. + tpf_max = {.numerator = 1, .denominator = FPS_MIN},
  12375. + tpf_default = {.numerator = 1000, .denominator = 30000};
  12376. +
  12377. +/* video formats */
  12378. +static struct mmal_fmt formats[] = {
  12379. + {
  12380. + .name = "4:2:0, packed YUV",
  12381. + .fourcc = V4L2_PIX_FMT_YUV420,
  12382. + .flags = 0,
  12383. + .mmal = MMAL_ENCODING_I420,
  12384. + .depth = 12,
  12385. + .mmal_component = MMAL_COMPONENT_CAMERA,
  12386. + },
  12387. + {
  12388. + .name = "4:2:2, packed, YUYV",
  12389. + .fourcc = V4L2_PIX_FMT_YUYV,
  12390. + .flags = 0,
  12391. + .mmal = MMAL_ENCODING_YUYV,
  12392. + .depth = 16,
  12393. + .mmal_component = MMAL_COMPONENT_CAMERA,
  12394. + },
  12395. + {
  12396. + .name = "RGB24 (LE)",
  12397. + .fourcc = V4L2_PIX_FMT_RGB24,
  12398. + .flags = 0,
  12399. + .mmal = MMAL_ENCODING_BGR24,
  12400. + .depth = 24,
  12401. + .mmal_component = MMAL_COMPONENT_CAMERA,
  12402. + },
  12403. + {
  12404. + .name = "JPEG",
  12405. + .fourcc = V4L2_PIX_FMT_JPEG,
  12406. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  12407. + .mmal = MMAL_ENCODING_JPEG,
  12408. + .depth = 8,
  12409. + .mmal_component = MMAL_COMPONENT_IMAGE_ENCODE,
  12410. + },
  12411. + {
  12412. + .name = "H264",
  12413. + .fourcc = V4L2_PIX_FMT_H264,
  12414. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  12415. + .mmal = MMAL_ENCODING_H264,
  12416. + .depth = 8,
  12417. + .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
  12418. + },
  12419. + {
  12420. + .name = "MJPEG",
  12421. + .fourcc = V4L2_PIX_FMT_MJPEG,
  12422. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  12423. + .mmal = MMAL_ENCODING_MJPEG,
  12424. + .depth = 8,
  12425. + .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
  12426. + },
  12427. + {
  12428. + .name = "4:2:2, packed, YVYU",
  12429. + .fourcc = V4L2_PIX_FMT_YVYU,
  12430. + .flags = 0,
  12431. + .mmal = MMAL_ENCODING_YVYU,
  12432. + .depth = 16,
  12433. + .mmal_component = MMAL_COMPONENT_CAMERA,
  12434. + },
  12435. + {
  12436. + .name = "4:2:2, packed, VYUY",
  12437. + .fourcc = V4L2_PIX_FMT_VYUY,
  12438. + .flags = 0,
  12439. + .mmal = MMAL_ENCODING_VYUY,
  12440. + .depth = 16,
  12441. + .mmal_component = MMAL_COMPONENT_CAMERA,
  12442. + },
  12443. + {
  12444. + .name = "4:2:2, packed, UYVY",
  12445. + .fourcc = V4L2_PIX_FMT_UYVY,
  12446. + .flags = 0,
  12447. + .mmal = MMAL_ENCODING_UYVY,
  12448. + .depth = 16,
  12449. + .mmal_component = MMAL_COMPONENT_CAMERA,
  12450. + },
  12451. + {
  12452. + .name = "4:2:0, packed, NV12",
  12453. + .fourcc = V4L2_PIX_FMT_NV12,
  12454. + .flags = 0,
  12455. + .mmal = MMAL_ENCODING_NV12,
  12456. + .depth = 12,
  12457. + .mmal_component = MMAL_COMPONENT_CAMERA,
  12458. + },
  12459. + {
  12460. + .name = "RGB24 (BE)",
  12461. + .fourcc = V4L2_PIX_FMT_BGR24,
  12462. + .flags = 0,
  12463. + .mmal = MMAL_ENCODING_RGB24,
  12464. + .depth = 24,
  12465. + .mmal_component = MMAL_COMPONENT_CAMERA,
  12466. + },
  12467. + {
  12468. + .name = "4:2:0, packed YVU",
  12469. + .fourcc = V4L2_PIX_FMT_YVU420,
  12470. + .flags = 0,
  12471. + .mmal = MMAL_ENCODING_YV12,
  12472. + .depth = 12,
  12473. + .mmal_component = MMAL_COMPONENT_CAMERA,
  12474. + },
  12475. + {
  12476. + .name = "4:2:0, packed, NV21",
  12477. + .fourcc = V4L2_PIX_FMT_NV21,
  12478. + .flags = 0,
  12479. + .mmal = MMAL_ENCODING_NV21,
  12480. + .depth = 12,
  12481. + .mmal_component = MMAL_COMPONENT_CAMERA,
  12482. + },
  12483. + {
  12484. + .name = "RGB32 (BE)",
  12485. + .fourcc = V4L2_PIX_FMT_BGR32,
  12486. + .flags = 0,
  12487. + .mmal = MMAL_ENCODING_BGRA,
  12488. + .depth = 32,
  12489. + .mmal_component = MMAL_COMPONENT_CAMERA,
  12490. + },
  12491. +};
  12492. +
  12493. +static struct mmal_fmt *get_format(struct v4l2_format *f)
  12494. +{
  12495. + struct mmal_fmt *fmt;
  12496. + unsigned int k;
  12497. +
  12498. + for (k = 0; k < ARRAY_SIZE(formats); k++) {
  12499. + fmt = &formats[k];
  12500. + if (fmt->fourcc == f->fmt.pix.pixelformat)
  12501. + break;
  12502. + }
  12503. +
  12504. + if (k == ARRAY_SIZE(formats))
  12505. + return NULL;
  12506. +
  12507. + return &formats[k];
  12508. +}
  12509. +
  12510. +/* ------------------------------------------------------------------
  12511. + Videobuf queue operations
  12512. + ------------------------------------------------------------------*/
  12513. +
  12514. +static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
  12515. + unsigned int *nbuffers, unsigned int *nplanes,
  12516. + unsigned int sizes[], void *alloc_ctxs[])
  12517. +{
  12518. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  12519. + unsigned long size;
  12520. +
  12521. + /* refuse queue setup if port is not configured */
  12522. + if (dev->capture.port == NULL) {
  12523. + v4l2_err(&dev->v4l2_dev,
  12524. + "%s: capture port not configured\n", __func__);
  12525. + return -EINVAL;
  12526. + }
  12527. +
  12528. + size = dev->capture.port->current_buffer.size;
  12529. + if (size == 0) {
  12530. + v4l2_err(&dev->v4l2_dev,
  12531. + "%s: capture port buffer size is zero\n", __func__);
  12532. + return -EINVAL;
  12533. + }
  12534. +
  12535. + if (*nbuffers < (dev->capture.port->current_buffer.num + 2))
  12536. + *nbuffers = (dev->capture.port->current_buffer.num + 2);
  12537. +
  12538. + *nplanes = 1;
  12539. +
  12540. + sizes[0] = size;
  12541. +
  12542. + /*
  12543. + * videobuf2-vmalloc allocator is context-less so no need to set
  12544. + * alloc_ctxs array.
  12545. + */
  12546. +
  12547. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  12548. + __func__, dev);
  12549. +
  12550. + return 0;
  12551. +}
  12552. +
  12553. +static int buffer_prepare(struct vb2_buffer *vb)
  12554. +{
  12555. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  12556. + unsigned long size;
  12557. +
  12558. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  12559. + __func__, dev);
  12560. +
  12561. + BUG_ON(dev->capture.port == NULL);
  12562. + BUG_ON(dev->capture.fmt == NULL);
  12563. +
  12564. + size = dev->capture.stride * dev->capture.height;
  12565. + if (vb2_plane_size(vb, 0) < size) {
  12566. + v4l2_err(&dev->v4l2_dev,
  12567. + "%s data will not fit into plane (%lu < %lu)\n",
  12568. + __func__, vb2_plane_size(vb, 0), size);
  12569. + return -EINVAL;
  12570. + }
  12571. +
  12572. + return 0;
  12573. +}
  12574. +
  12575. +static inline bool is_capturing(struct bm2835_mmal_dev *dev)
  12576. +{
  12577. + return dev->capture.camera_port ==
  12578. + &dev->
  12579. + component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_CAPTURE];
  12580. +}
  12581. +
  12582. +static void buffer_cb(struct vchiq_mmal_instance *instance,
  12583. + struct vchiq_mmal_port *port,
  12584. + int status,
  12585. + struct mmal_buffer *buf,
  12586. + unsigned long length, u32 mmal_flags, s64 dts, s64 pts)
  12587. +{
  12588. + struct bm2835_mmal_dev *dev = port->cb_ctx;
  12589. +
  12590. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12591. + "%s: status:%d, buf:%p, length:%lu, flags %u, pts %lld\n",
  12592. + __func__, status, buf, length, mmal_flags, pts);
  12593. +
  12594. + if (status != 0) {
  12595. + /* error in transfer */
  12596. + if (buf != NULL) {
  12597. + /* there was a buffer with the error so return it */
  12598. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
  12599. + }
  12600. + return;
  12601. + } else if (length == 0) {
  12602. + /* stream ended */
  12603. + if (buf != NULL) {
  12604. + /* this should only ever happen if the port is
  12605. + * disabled and there are buffers still queued
  12606. + */
  12607. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
  12608. + pr_debug("Empty buffer");
  12609. + } else if (dev->capture.frame_count) {
  12610. + /* grab another frame */
  12611. + if (is_capturing(dev)) {
  12612. + pr_debug("Grab another frame");
  12613. + vchiq_mmal_port_parameter_set(
  12614. + instance,
  12615. + dev->capture.
  12616. + camera_port,
  12617. + MMAL_PARAMETER_CAPTURE,
  12618. + &dev->capture.
  12619. + frame_count,
  12620. + sizeof(dev->capture.frame_count));
  12621. + }
  12622. + } else {
  12623. + /* signal frame completion */
  12624. + complete(&dev->capture.frame_cmplt);
  12625. + }
  12626. + } else {
  12627. + if (dev->capture.frame_count) {
  12628. + if (dev->capture.vc_start_timestamp != -1 &&
  12629. + pts != 0) {
  12630. + s64 runtime_us = pts -
  12631. + dev->capture.vc_start_timestamp;
  12632. + u32 div = 0;
  12633. + u32 rem = 0;
  12634. +
  12635. + div =
  12636. + div_u64_rem(runtime_us, USEC_PER_SEC, &rem);
  12637. + buf->vb.v4l2_buf.timestamp.tv_sec =
  12638. + dev->capture.kernel_start_ts.tv_sec - 1 +
  12639. + div;
  12640. + buf->vb.v4l2_buf.timestamp.tv_usec =
  12641. + dev->capture.kernel_start_ts.tv_usec + rem;
  12642. +
  12643. + if (buf->vb.v4l2_buf.timestamp.tv_usec >=
  12644. + USEC_PER_SEC) {
  12645. + buf->vb.v4l2_buf.timestamp.tv_sec++;
  12646. + buf->vb.v4l2_buf.timestamp.tv_usec -=
  12647. + USEC_PER_SEC;
  12648. + }
  12649. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12650. + "Convert start time %d.%06d and %llu "
  12651. + "with offset %llu to %d.%06d\n",
  12652. + (int)dev->capture.kernel_start_ts.
  12653. + tv_sec,
  12654. + (int)dev->capture.kernel_start_ts.
  12655. + tv_usec,
  12656. + dev->capture.vc_start_timestamp, pts,
  12657. + (int)buf->vb.v4l2_buf.timestamp.tv_sec,
  12658. + (int)buf->vb.v4l2_buf.timestamp.
  12659. + tv_usec);
  12660. + } else {
  12661. + v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
  12662. + }
  12663. +
  12664. + vb2_set_plane_payload(&buf->vb, 0, length);
  12665. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
  12666. +
  12667. + if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_EOS &&
  12668. + is_capturing(dev)) {
  12669. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12670. + "Grab another frame as buffer has EOS");
  12671. + vchiq_mmal_port_parameter_set(
  12672. + instance,
  12673. + dev->capture.
  12674. + camera_port,
  12675. + MMAL_PARAMETER_CAPTURE,
  12676. + &dev->capture.
  12677. + frame_count,
  12678. + sizeof(dev->capture.frame_count));
  12679. + }
  12680. + } else {
  12681. + /* signal frame completion */
  12682. + complete(&dev->capture.frame_cmplt);
  12683. + }
  12684. + }
  12685. +}
  12686. +
  12687. +static int enable_camera(struct bm2835_mmal_dev *dev)
  12688. +{
  12689. + int ret;
  12690. + if (!dev->camera_use_count) {
  12691. + ret = vchiq_mmal_component_enable(
  12692. + dev->instance,
  12693. + dev->component[MMAL_COMPONENT_CAMERA]);
  12694. + if (ret < 0) {
  12695. + v4l2_err(&dev->v4l2_dev,
  12696. + "Failed enabling camera, ret %d\n", ret);
  12697. + return -EINVAL;
  12698. + }
  12699. + }
  12700. + dev->camera_use_count++;
  12701. + v4l2_dbg(1, bcm2835_v4l2_debug,
  12702. + &dev->v4l2_dev, "enabled camera (refcount %d)\n",
  12703. + dev->camera_use_count);
  12704. + return 0;
  12705. +}
  12706. +
  12707. +static int disable_camera(struct bm2835_mmal_dev *dev)
  12708. +{
  12709. + int ret;
  12710. + if (!dev->camera_use_count) {
  12711. + v4l2_err(&dev->v4l2_dev,
  12712. + "Disabled the camera when already disabled\n");
  12713. + return -EINVAL;
  12714. + }
  12715. + dev->camera_use_count--;
  12716. + if (!dev->camera_use_count) {
  12717. + unsigned int i = 0xFFFFFFFF;
  12718. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12719. + "Disabling camera\n");
  12720. + ret =
  12721. + vchiq_mmal_component_disable(
  12722. + dev->instance,
  12723. + dev->component[MMAL_COMPONENT_CAMERA]);
  12724. + if (ret < 0) {
  12725. + v4l2_err(&dev->v4l2_dev,
  12726. + "Failed disabling camera, ret %d\n", ret);
  12727. + return -EINVAL;
  12728. + }
  12729. + vchiq_mmal_port_parameter_set(
  12730. + dev->instance,
  12731. + &dev->component[MMAL_COMPONENT_CAMERA]->control,
  12732. + MMAL_PARAMETER_CAMERA_NUM, &i,
  12733. + sizeof(i));
  12734. + }
  12735. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12736. + "Camera refcount now %d\n", dev->camera_use_count);
  12737. + return 0;
  12738. +}
  12739. +
  12740. +static void buffer_queue(struct vb2_buffer *vb)
  12741. +{
  12742. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  12743. + struct mmal_buffer *buf = container_of(vb, struct mmal_buffer, vb);
  12744. + int ret;
  12745. +
  12746. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12747. + "%s: dev:%p buf:%p\n", __func__, dev, buf);
  12748. +
  12749. + buf->buffer = vb2_plane_vaddr(&buf->vb, 0);
  12750. + buf->buffer_size = vb2_plane_size(&buf->vb, 0);
  12751. +
  12752. + ret = vchiq_mmal_submit_buffer(dev->instance, dev->capture.port, buf);
  12753. + if (ret < 0)
  12754. + v4l2_err(&dev->v4l2_dev, "%s: error submitting buffer\n",
  12755. + __func__);
  12756. +}
  12757. +
  12758. +static int start_streaming(struct vb2_queue *vq, unsigned int count)
  12759. +{
  12760. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  12761. + int ret;
  12762. + int parameter_size;
  12763. +
  12764. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  12765. + __func__, dev);
  12766. +
  12767. + /* ensure a format has actually been set */
  12768. + if (dev->capture.port == NULL)
  12769. + return -EINVAL;
  12770. +
  12771. + if (enable_camera(dev) < 0) {
  12772. + v4l2_err(&dev->v4l2_dev, "Failed to enable camera\n");
  12773. + return -EINVAL;
  12774. + }
  12775. +
  12776. + /*init_completion(&dev->capture.frame_cmplt); */
  12777. +
  12778. + /* enable frame capture */
  12779. + dev->capture.frame_count = 1;
  12780. +
  12781. + /* if the preview is not already running, wait for a few frames for AGC
  12782. + * to settle down.
  12783. + */
  12784. + if (!dev->component[MMAL_COMPONENT_PREVIEW]->enabled)
  12785. + msleep(300);
  12786. +
  12787. + /* enable the connection from camera to encoder (if applicable) */
  12788. + if (dev->capture.camera_port != dev->capture.port
  12789. + && dev->capture.camera_port) {
  12790. + ret = vchiq_mmal_port_enable(dev->instance,
  12791. + dev->capture.camera_port, NULL);
  12792. + if (ret) {
  12793. + v4l2_err(&dev->v4l2_dev,
  12794. + "Failed to enable encode tunnel - error %d\n",
  12795. + ret);
  12796. + return -1;
  12797. + }
  12798. + }
  12799. +
  12800. + /* Get VC timestamp at this point in time */
  12801. + parameter_size = sizeof(dev->capture.vc_start_timestamp);
  12802. + if (vchiq_mmal_port_parameter_get(dev->instance,
  12803. + dev->capture.camera_port,
  12804. + MMAL_PARAMETER_SYSTEM_TIME,
  12805. + &dev->capture.vc_start_timestamp,
  12806. + &parameter_size)) {
  12807. + v4l2_err(&dev->v4l2_dev,
  12808. + "Failed to get VC start time - update your VC f/w\n");
  12809. +
  12810. + /* Flag to indicate just to rely on kernel timestamps */
  12811. + dev->capture.vc_start_timestamp = -1;
  12812. + } else
  12813. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12814. + "Start time %lld size %d\n",
  12815. + dev->capture.vc_start_timestamp, parameter_size);
  12816. +
  12817. + v4l2_get_timestamp(&dev->capture.kernel_start_ts);
  12818. +
  12819. + /* enable the camera port */
  12820. + dev->capture.port->cb_ctx = dev;
  12821. + ret =
  12822. + vchiq_mmal_port_enable(dev->instance, dev->capture.port, buffer_cb);
  12823. + if (ret) {
  12824. + v4l2_err(&dev->v4l2_dev,
  12825. + "Failed to enable capture port - error %d. "
  12826. + "Disabling camera port again\n", ret);
  12827. +
  12828. + vchiq_mmal_port_disable(dev->instance,
  12829. + dev->capture.camera_port);
  12830. + if (disable_camera(dev) < 0) {
  12831. + v4l2_err(&dev->v4l2_dev, "Failed to disable camera");
  12832. + return -EINVAL;
  12833. + }
  12834. + return -1;
  12835. + }
  12836. +
  12837. + /* capture the first frame */
  12838. + vchiq_mmal_port_parameter_set(dev->instance,
  12839. + dev->capture.camera_port,
  12840. + MMAL_PARAMETER_CAPTURE,
  12841. + &dev->capture.frame_count,
  12842. + sizeof(dev->capture.frame_count));
  12843. + return 0;
  12844. +}
  12845. +
  12846. +/* abort streaming and wait for last buffer */
  12847. +static int stop_streaming(struct vb2_queue *vq)
  12848. +{
  12849. + int ret;
  12850. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  12851. +
  12852. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  12853. + __func__, dev);
  12854. +
  12855. + init_completion(&dev->capture.frame_cmplt);
  12856. + dev->capture.frame_count = 0;
  12857. +
  12858. + /* ensure a format has actually been set */
  12859. + if (dev->capture.port == NULL)
  12860. + return -EINVAL;
  12861. +
  12862. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "stopping capturing\n");
  12863. +
  12864. + /* stop capturing frames */
  12865. + vchiq_mmal_port_parameter_set(dev->instance,
  12866. + dev->capture.camera_port,
  12867. + MMAL_PARAMETER_CAPTURE,
  12868. + &dev->capture.frame_count,
  12869. + sizeof(dev->capture.frame_count));
  12870. +
  12871. + /* wait for last frame to complete */
  12872. + ret = wait_for_completion_timeout(&dev->capture.frame_cmplt, HZ);
  12873. + if (ret <= 0)
  12874. + v4l2_err(&dev->v4l2_dev,
  12875. + "error %d waiting for frame completion\n", ret);
  12876. +
  12877. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12878. + "disabling connection\n");
  12879. +
  12880. + /* disable the connection from camera to encoder */
  12881. + ret = vchiq_mmal_port_disable(dev->instance, dev->capture.camera_port);
  12882. + if (!ret && dev->capture.camera_port != dev->capture.port) {
  12883. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12884. + "disabling port\n");
  12885. + ret = vchiq_mmal_port_disable(dev->instance, dev->capture.port);
  12886. + } else if (dev->capture.camera_port != dev->capture.port) {
  12887. + v4l2_err(&dev->v4l2_dev, "port_disable failed, error %d\n",
  12888. + ret);
  12889. + }
  12890. +
  12891. + if (disable_camera(dev) < 0) {
  12892. + v4l2_err(&dev->v4l2_dev, "Failed to disable camera");
  12893. + return -EINVAL;
  12894. + }
  12895. +
  12896. + return ret;
  12897. +}
  12898. +
  12899. +static void bm2835_mmal_lock(struct vb2_queue *vq)
  12900. +{
  12901. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  12902. + mutex_lock(&dev->mutex);
  12903. +}
  12904. +
  12905. +static void bm2835_mmal_unlock(struct vb2_queue *vq)
  12906. +{
  12907. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  12908. + mutex_unlock(&dev->mutex);
  12909. +}
  12910. +
  12911. +static struct vb2_ops bm2835_mmal_video_qops = {
  12912. + .queue_setup = queue_setup,
  12913. + .buf_prepare = buffer_prepare,
  12914. + .buf_queue = buffer_queue,
  12915. + .start_streaming = start_streaming,
  12916. + .stop_streaming = stop_streaming,
  12917. + .wait_prepare = bm2835_mmal_unlock,
  12918. + .wait_finish = bm2835_mmal_lock,
  12919. +};
  12920. +
  12921. +/* ------------------------------------------------------------------
  12922. + IOCTL operations
  12923. + ------------------------------------------------------------------*/
  12924. +
  12925. +/* overlay ioctl */
  12926. +static int vidioc_enum_fmt_vid_overlay(struct file *file, void *priv,
  12927. + struct v4l2_fmtdesc *f)
  12928. +{
  12929. + struct mmal_fmt *fmt;
  12930. +
  12931. + if (f->index >= ARRAY_SIZE(formats))
  12932. + return -EINVAL;
  12933. +
  12934. + fmt = &formats[f->index];
  12935. +
  12936. + strlcpy(f->description, fmt->name, sizeof(f->description));
  12937. + f->pixelformat = fmt->fourcc;
  12938. + f->flags = fmt->flags;
  12939. +
  12940. + return 0;
  12941. +}
  12942. +
  12943. +static int vidioc_g_fmt_vid_overlay(struct file *file, void *priv,
  12944. + struct v4l2_format *f)
  12945. +{
  12946. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12947. +
  12948. + f->fmt.win = dev->overlay;
  12949. +
  12950. + return 0;
  12951. +}
  12952. +
  12953. +static int vidioc_try_fmt_vid_overlay(struct file *file, void *priv,
  12954. + struct v4l2_format *f)
  12955. +{
  12956. + /* Only support one format so get the current one. */
  12957. + vidioc_g_fmt_vid_overlay(file, priv, f);
  12958. +
  12959. + /* todo: allow the size and/or offset to be changed. */
  12960. + return 0;
  12961. +}
  12962. +
  12963. +static int vidioc_s_fmt_vid_overlay(struct file *file, void *priv,
  12964. + struct v4l2_format *f)
  12965. +{
  12966. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12967. +
  12968. + vidioc_try_fmt_vid_overlay(file, priv, f);
  12969. +
  12970. + dev->overlay = f->fmt.win;
  12971. +
  12972. + /* todo: program the preview port parameters */
  12973. + return 0;
  12974. +}
  12975. +
  12976. +static int vidioc_overlay(struct file *file, void *f, unsigned int on)
  12977. +{
  12978. + int ret;
  12979. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12980. + struct vchiq_mmal_port *src;
  12981. + struct vchiq_mmal_port *dst;
  12982. + struct mmal_parameter_displayregion prev_config = {
  12983. + .set = MMAL_DISPLAY_SET_LAYER | MMAL_DISPLAY_SET_ALPHA |
  12984. + MMAL_DISPLAY_SET_DEST_RECT | MMAL_DISPLAY_SET_FULLSCREEN,
  12985. + .layer = PREVIEW_LAYER,
  12986. + .alpha = 255,
  12987. + .fullscreen = 0,
  12988. + .dest_rect = {
  12989. + .x = dev->overlay.w.left,
  12990. + .y = dev->overlay.w.top,
  12991. + .width = dev->overlay.w.width,
  12992. + .height = dev->overlay.w.height,
  12993. + },
  12994. + };
  12995. +
  12996. + if ((on && dev->component[MMAL_COMPONENT_PREVIEW]->enabled) ||
  12997. + (!on && !dev->component[MMAL_COMPONENT_PREVIEW]->enabled))
  12998. + return 0; /* already in requested state */
  12999. +
  13000. + src =
  13001. + &dev->component[MMAL_COMPONENT_CAMERA]->
  13002. + output[MMAL_CAMERA_PORT_PREVIEW];
  13003. +
  13004. + if (!on) {
  13005. + /* disconnect preview ports and disable component */
  13006. + ret = vchiq_mmal_port_disable(dev->instance, src);
  13007. + if (!ret)
  13008. + ret =
  13009. + vchiq_mmal_port_connect_tunnel(dev->instance, src,
  13010. + NULL);
  13011. + if (ret >= 0)
  13012. + ret = vchiq_mmal_component_disable(
  13013. + dev->instance,
  13014. + dev->component[MMAL_COMPONENT_PREVIEW]);
  13015. +
  13016. + disable_camera(dev);
  13017. + return ret;
  13018. + }
  13019. +
  13020. + /* set preview port format and connect it to output */
  13021. + dst = &dev->component[MMAL_COMPONENT_PREVIEW]->input[0];
  13022. +
  13023. + ret = vchiq_mmal_port_set_format(dev->instance, src);
  13024. + if (ret < 0)
  13025. + goto error;
  13026. +
  13027. + ret = vchiq_mmal_port_parameter_set(dev->instance, dst,
  13028. + MMAL_PARAMETER_DISPLAYREGION,
  13029. + &prev_config, sizeof(prev_config));
  13030. + if (ret < 0)
  13031. + goto error;
  13032. +
  13033. + if (enable_camera(dev) < 0)
  13034. + goto error;
  13035. +
  13036. + ret = vchiq_mmal_component_enable(
  13037. + dev->instance,
  13038. + dev->component[MMAL_COMPONENT_PREVIEW]);
  13039. + if (ret < 0)
  13040. + goto error;
  13041. +
  13042. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "connecting %p to %p\n",
  13043. + src, dst);
  13044. + ret = vchiq_mmal_port_connect_tunnel(dev->instance, src, dst);
  13045. + if (!ret)
  13046. + ret = vchiq_mmal_port_enable(dev->instance, src, NULL);
  13047. +error:
  13048. + return ret;
  13049. +}
  13050. +
  13051. +static int vidioc_g_fbuf(struct file *file, void *fh,
  13052. + struct v4l2_framebuffer *a)
  13053. +{
  13054. + /* The video overlay must stay within the framebuffer and can't be
  13055. + positioned independently. */
  13056. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  13057. + struct vchiq_mmal_port *preview_port =
  13058. + &dev->component[MMAL_COMPONENT_CAMERA]->
  13059. + output[MMAL_CAMERA_PORT_PREVIEW];
  13060. + a->flags = V4L2_FBUF_FLAG_OVERLAY;
  13061. + a->fmt.width = preview_port->es.video.width;
  13062. + a->fmt.height = preview_port->es.video.height;
  13063. + a->fmt.pixelformat = V4L2_PIX_FMT_YUV420;
  13064. + a->fmt.bytesperline = (preview_port->es.video.width * 3)>>1;
  13065. + a->fmt.sizeimage = (preview_port->es.video.width *
  13066. + preview_port->es.video.height * 3)>>1;
  13067. + a->fmt.colorspace = V4L2_COLORSPACE_JPEG;
  13068. +
  13069. + return 0;
  13070. +}
  13071. +
  13072. +/* input ioctls */
  13073. +static int vidioc_enum_input(struct file *file, void *priv,
  13074. + struct v4l2_input *inp)
  13075. +{
  13076. + /* only a single camera input */
  13077. + if (inp->index != 0)
  13078. + return -EINVAL;
  13079. +
  13080. + inp->type = V4L2_INPUT_TYPE_CAMERA;
  13081. + sprintf(inp->name, "Camera %u", inp->index);
  13082. + return 0;
  13083. +}
  13084. +
  13085. +static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
  13086. +{
  13087. + *i = 0;
  13088. + return 0;
  13089. +}
  13090. +
  13091. +static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
  13092. +{
  13093. + if (i != 0)
  13094. + return -EINVAL;
  13095. +
  13096. + return 0;
  13097. +}
  13098. +
  13099. +/* capture ioctls */
  13100. +static int vidioc_querycap(struct file *file, void *priv,
  13101. + struct v4l2_capability *cap)
  13102. +{
  13103. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  13104. + u32 major;
  13105. + u32 minor;
  13106. +
  13107. + vchiq_mmal_version(dev->instance, &major, &minor);
  13108. +
  13109. + strcpy(cap->driver, "bm2835 mmal");
  13110. + snprintf(cap->card, sizeof(cap->card), "mmal service %d.%d",
  13111. + major, minor);
  13112. +
  13113. + snprintf(cap->bus_info, sizeof(cap->bus_info),
  13114. + "platform:%s", dev->v4l2_dev.name);
  13115. + cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OVERLAY |
  13116. + V4L2_CAP_STREAMING | V4L2_CAP_READWRITE;
  13117. + cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
  13118. +
  13119. + return 0;
  13120. +}
  13121. +
  13122. +static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
  13123. + struct v4l2_fmtdesc *f)
  13124. +{
  13125. + struct mmal_fmt *fmt;
  13126. +
  13127. + if (f->index >= ARRAY_SIZE(formats))
  13128. + return -EINVAL;
  13129. +
  13130. + fmt = &formats[f->index];
  13131. +
  13132. + strlcpy(f->description, fmt->name, sizeof(f->description));
  13133. + f->pixelformat = fmt->fourcc;
  13134. + f->flags = fmt->flags;
  13135. +
  13136. + return 0;
  13137. +}
  13138. +
  13139. +static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
  13140. + struct v4l2_format *f)
  13141. +{
  13142. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  13143. +
  13144. + f->fmt.pix.width = dev->capture.width;
  13145. + f->fmt.pix.height = dev->capture.height;
  13146. + f->fmt.pix.field = V4L2_FIELD_NONE;
  13147. + f->fmt.pix.pixelformat = dev->capture.fmt->fourcc;
  13148. + f->fmt.pix.bytesperline = dev->capture.stride;
  13149. + f->fmt.pix.sizeimage = dev->capture.buffersize;
  13150. +
  13151. + if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_RGB24)
  13152. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
  13153. + else
  13154. + f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
  13155. + f->fmt.pix.priv = 0;
  13156. +
  13157. + v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
  13158. + __func__);
  13159. + return 0;
  13160. +}
  13161. +
  13162. +static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
  13163. + struct v4l2_format *f)
  13164. +{
  13165. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  13166. + struct mmal_fmt *mfmt;
  13167. +
  13168. + mfmt = get_format(f);
  13169. + if (!mfmt) {
  13170. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13171. + "Fourcc format (0x%08x) unknown.\n",
  13172. + f->fmt.pix.pixelformat);
  13173. + f->fmt.pix.pixelformat = formats[0].fourcc;
  13174. + mfmt = get_format(f);
  13175. + }
  13176. +
  13177. + f->fmt.pix.field = V4L2_FIELD_NONE;
  13178. +
  13179. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13180. + "Clipping/aligning %dx%d format %08X\n",
  13181. + f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.pixelformat);
  13182. +
  13183. + v4l_bound_align_image(&f->fmt.pix.width, MIN_WIDTH, MAX_WIDTH, 1,
  13184. + &f->fmt.pix.height, MIN_HEIGHT, MAX_HEIGHT, 1, 0);
  13185. + f->fmt.pix.bytesperline = (f->fmt.pix.width * mfmt->depth)>>3;
  13186. +
  13187. + /* Image buffer has to be padded to allow for alignment, even though
  13188. + * we then remove that padding before delivering the buffer.
  13189. + */
  13190. + f->fmt.pix.sizeimage = ((f->fmt.pix.height+15)&~15) *
  13191. + (((f->fmt.pix.width+31)&~31) * mfmt->depth) >> 3;
  13192. +
  13193. + if ((mfmt->flags & V4L2_FMT_FLAG_COMPRESSED) &&
  13194. + f->fmt.pix.sizeimage < MIN_BUFFER_SIZE)
  13195. + f->fmt.pix.sizeimage = MIN_BUFFER_SIZE;
  13196. +
  13197. + if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_RGB24)
  13198. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
  13199. + else
  13200. + f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
  13201. + f->fmt.pix.priv = 0;
  13202. +
  13203. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13204. + "Now %dx%d format %08X\n",
  13205. + f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.pixelformat);
  13206. +
  13207. + v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
  13208. + __func__);
  13209. + return 0;
  13210. +}
  13211. +
  13212. +static int mmal_setup_components(struct bm2835_mmal_dev *dev,
  13213. + struct v4l2_format *f)
  13214. +{
  13215. + int ret;
  13216. + struct vchiq_mmal_port *port = NULL, *camera_port = NULL;
  13217. + struct vchiq_mmal_component *encode_component = NULL;
  13218. + struct mmal_fmt *mfmt = get_format(f);
  13219. +
  13220. + BUG_ON(!mfmt);
  13221. +
  13222. + if (dev->capture.encode_component) {
  13223. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13224. + "vid_cap - disconnect previous tunnel\n");
  13225. +
  13226. + /* Disconnect any previous connection */
  13227. + vchiq_mmal_port_connect_tunnel(dev->instance,
  13228. + dev->capture.camera_port, NULL);
  13229. + dev->capture.camera_port = NULL;
  13230. + ret = vchiq_mmal_component_disable(dev->instance,
  13231. + dev->capture.
  13232. + encode_component);
  13233. + if (ret)
  13234. + v4l2_err(&dev->v4l2_dev,
  13235. + "Failed to disable encode component %d\n",
  13236. + ret);
  13237. +
  13238. + dev->capture.encode_component = NULL;
  13239. + }
  13240. + /* format dependant port setup */
  13241. + switch (mfmt->mmal_component) {
  13242. + case MMAL_COMPONENT_CAMERA:
  13243. + /* Make a further decision on port based on resolution */
  13244. + if (f->fmt.pix.width <= max_video_width
  13245. + && f->fmt.pix.height <= max_video_height)
  13246. + camera_port = port =
  13247. + &dev->component[MMAL_COMPONENT_CAMERA]->
  13248. + output[MMAL_CAMERA_PORT_VIDEO];
  13249. + else
  13250. + camera_port = port =
  13251. + &dev->component[MMAL_COMPONENT_CAMERA]->
  13252. + output[MMAL_CAMERA_PORT_CAPTURE];
  13253. + break;
  13254. + case MMAL_COMPONENT_IMAGE_ENCODE:
  13255. + encode_component = dev->component[MMAL_COMPONENT_IMAGE_ENCODE];
  13256. + port = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
  13257. + camera_port =
  13258. + &dev->component[MMAL_COMPONENT_CAMERA]->
  13259. + output[MMAL_CAMERA_PORT_CAPTURE];
  13260. + break;
  13261. + case MMAL_COMPONENT_VIDEO_ENCODE:
  13262. + encode_component = dev->component[MMAL_COMPONENT_VIDEO_ENCODE];
  13263. + port = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  13264. + camera_port =
  13265. + &dev->component[MMAL_COMPONENT_CAMERA]->
  13266. + output[MMAL_CAMERA_PORT_VIDEO];
  13267. + break;
  13268. + default:
  13269. + break;
  13270. + }
  13271. +
  13272. + if (!port)
  13273. + return -EINVAL;
  13274. +
  13275. + if (encode_component)
  13276. + camera_port->format.encoding = MMAL_ENCODING_OPAQUE;
  13277. + else
  13278. + camera_port->format.encoding = mfmt->mmal;
  13279. +
  13280. + camera_port->format.encoding_variant = 0;
  13281. + camera_port->es.video.width = f->fmt.pix.width;
  13282. + camera_port->es.video.height = f->fmt.pix.height;
  13283. + camera_port->es.video.crop.x = 0;
  13284. + camera_port->es.video.crop.y = 0;
  13285. + camera_port->es.video.crop.width = f->fmt.pix.width;
  13286. + camera_port->es.video.crop.height = f->fmt.pix.height;
  13287. + camera_port->es.video.frame_rate.num = 0;
  13288. + camera_port->es.video.frame_rate.den = 1;
  13289. + camera_port->es.video.color_space = MMAL_COLOR_SPACE_JPEG_JFIF;
  13290. +
  13291. + ret = vchiq_mmal_port_set_format(dev->instance, camera_port);
  13292. +
  13293. + if (!ret
  13294. + && camera_port ==
  13295. + &dev->component[MMAL_COMPONENT_CAMERA]->
  13296. + output[MMAL_CAMERA_PORT_VIDEO]) {
  13297. + bool overlay_enabled =
  13298. + !!dev->component[MMAL_COMPONENT_PREVIEW]->enabled;
  13299. + struct vchiq_mmal_port *preview_port =
  13300. + &dev->component[MMAL_COMPONENT_CAMERA]->
  13301. + output[MMAL_CAMERA_PORT_PREVIEW];
  13302. + /* Preview and encode ports need to match on resolution */
  13303. + if (overlay_enabled) {
  13304. + /* Need to disable the overlay before we can update
  13305. + * the resolution
  13306. + */
  13307. + ret =
  13308. + vchiq_mmal_port_disable(dev->instance,
  13309. + preview_port);
  13310. + if (!ret)
  13311. + ret =
  13312. + vchiq_mmal_port_connect_tunnel(
  13313. + dev->instance,
  13314. + preview_port,
  13315. + NULL);
  13316. + }
  13317. + preview_port->es.video.width = f->fmt.pix.width;
  13318. + preview_port->es.video.height = f->fmt.pix.height;
  13319. + preview_port->es.video.crop.x = 0;
  13320. + preview_port->es.video.crop.y = 0;
  13321. + preview_port->es.video.crop.width = f->fmt.pix.width;
  13322. + preview_port->es.video.crop.height = f->fmt.pix.height;
  13323. + preview_port->es.video.frame_rate.num =
  13324. + dev->capture.timeperframe.denominator;
  13325. + preview_port->es.video.frame_rate.den =
  13326. + dev->capture.timeperframe.numerator;
  13327. + ret = vchiq_mmal_port_set_format(dev->instance, preview_port);
  13328. + if (overlay_enabled) {
  13329. + ret = vchiq_mmal_port_connect_tunnel(
  13330. + dev->instance,
  13331. + preview_port,
  13332. + &dev->component[MMAL_COMPONENT_PREVIEW]->input[0]);
  13333. + if (!ret)
  13334. + ret = vchiq_mmal_port_enable(dev->instance,
  13335. + preview_port,
  13336. + NULL);
  13337. + }
  13338. + }
  13339. +
  13340. + if (ret) {
  13341. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13342. + "%s failed to set format %dx%d %08X\n", __func__,
  13343. + f->fmt.pix.width, f->fmt.pix.height,
  13344. + f->fmt.pix.pixelformat);
  13345. + /* ensure capture is not going to be tried */
  13346. + dev->capture.port = NULL;
  13347. + } else {
  13348. + if (encode_component) {
  13349. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13350. + "vid_cap - set up encode comp\n");
  13351. +
  13352. + /* configure buffering */
  13353. + camera_port->current_buffer.size =
  13354. + camera_port->recommended_buffer.size;
  13355. + camera_port->current_buffer.num =
  13356. + camera_port->recommended_buffer.num;
  13357. +
  13358. + ret =
  13359. + vchiq_mmal_port_connect_tunnel(
  13360. + dev->instance,
  13361. + camera_port,
  13362. + &encode_component->input[0]);
  13363. + if (ret) {
  13364. + v4l2_dbg(1, bcm2835_v4l2_debug,
  13365. + &dev->v4l2_dev,
  13366. + "%s failed to create connection\n",
  13367. + __func__);
  13368. + /* ensure capture is not going to be tried */
  13369. + dev->capture.port = NULL;
  13370. + } else {
  13371. + port->es.video.width = f->fmt.pix.width;
  13372. + port->es.video.height = f->fmt.pix.height;
  13373. + port->es.video.crop.x = 0;
  13374. + port->es.video.crop.y = 0;
  13375. + port->es.video.crop.width = f->fmt.pix.width;
  13376. + port->es.video.crop.height = f->fmt.pix.height;
  13377. + port->es.video.frame_rate.num =
  13378. + dev->capture.timeperframe.denominator;
  13379. + port->es.video.frame_rate.den =
  13380. + dev->capture.timeperframe.numerator;
  13381. +
  13382. + port->format.encoding = mfmt->mmal;
  13383. + port->format.encoding_variant = 0;
  13384. + /* Set any encoding specific parameters */
  13385. + switch (mfmt->mmal_component) {
  13386. + case MMAL_COMPONENT_VIDEO_ENCODE:
  13387. + port->format.bitrate =
  13388. + dev->capture.encode_bitrate;
  13389. + break;
  13390. + case MMAL_COMPONENT_IMAGE_ENCODE:
  13391. + /* Could set EXIF parameters here */
  13392. + break;
  13393. + default:
  13394. + break;
  13395. + }
  13396. + ret = vchiq_mmal_port_set_format(dev->instance,
  13397. + port);
  13398. + if (ret)
  13399. + v4l2_dbg(1, bcm2835_v4l2_debug,
  13400. + &dev->v4l2_dev,
  13401. + "%s failed to set format %dx%d fmt %08X\n",
  13402. + __func__,
  13403. + f->fmt.pix.width,
  13404. + f->fmt.pix.height,
  13405. + f->fmt.pix.pixelformat
  13406. + );
  13407. + }
  13408. +
  13409. + if (!ret) {
  13410. + ret = vchiq_mmal_component_enable(
  13411. + dev->instance,
  13412. + encode_component);
  13413. + if (ret) {
  13414. + v4l2_dbg(1, bcm2835_v4l2_debug,
  13415. + &dev->v4l2_dev,
  13416. + "%s Failed to enable encode components\n",
  13417. + __func__);
  13418. + }
  13419. + }
  13420. + if (!ret) {
  13421. + /* configure buffering */
  13422. + port->current_buffer.num = 1;
  13423. + port->current_buffer.size =
  13424. + f->fmt.pix.sizeimage;
  13425. + if (port->format.encoding ==
  13426. + MMAL_ENCODING_JPEG) {
  13427. + v4l2_dbg(1, bcm2835_v4l2_debug,
  13428. + &dev->v4l2_dev,
  13429. + "JPG - buf size now %d was %d\n",
  13430. + f->fmt.pix.sizeimage,
  13431. + port->current_buffer.size);
  13432. + port->current_buffer.size =
  13433. + (f->fmt.pix.sizeimage <
  13434. + (100 << 10))
  13435. + ? (100 << 10) : f->fmt.pix.
  13436. + sizeimage;
  13437. + }
  13438. + v4l2_dbg(1, bcm2835_v4l2_debug,
  13439. + &dev->v4l2_dev,
  13440. + "vid_cap - cur_buf.size set to %d\n",
  13441. + f->fmt.pix.sizeimage);
  13442. + port->current_buffer.alignment = 0;
  13443. + }
  13444. + } else {
  13445. + /* configure buffering */
  13446. + camera_port->current_buffer.num = 1;
  13447. + camera_port->current_buffer.size = f->fmt.pix.sizeimage;
  13448. + camera_port->current_buffer.alignment = 0;
  13449. + }
  13450. +
  13451. + if (!ret) {
  13452. + dev->capture.fmt = mfmt;
  13453. + dev->capture.stride = f->fmt.pix.bytesperline;
  13454. + dev->capture.width = camera_port->es.video.crop.width;
  13455. + dev->capture.height = camera_port->es.video.crop.height;
  13456. + dev->capture.buffersize = port->current_buffer.size;
  13457. +
  13458. + /* select port for capture */
  13459. + dev->capture.port = port;
  13460. + dev->capture.camera_port = camera_port;
  13461. + dev->capture.encode_component = encode_component;
  13462. + v4l2_dbg(1, bcm2835_v4l2_debug,
  13463. + &dev->v4l2_dev,
  13464. + "Set dev->capture.fmt %08X, %dx%d, stride %d, size %d",
  13465. + port->format.encoding,
  13466. + dev->capture.width, dev->capture.height,
  13467. + dev->capture.stride, dev->capture.buffersize);
  13468. + }
  13469. + }
  13470. +
  13471. + /* todo: Need to convert the vchiq/mmal error into a v4l2 error. */
  13472. + return ret;
  13473. +}
  13474. +
  13475. +static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
  13476. + struct v4l2_format *f)
  13477. +{
  13478. + int ret;
  13479. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  13480. + struct mmal_fmt *mfmt;
  13481. +
  13482. + /* try the format to set valid parameters */
  13483. + ret = vidioc_try_fmt_vid_cap(file, priv, f);
  13484. + if (ret) {
  13485. + v4l2_err(&dev->v4l2_dev,
  13486. + "vid_cap - vidioc_try_fmt_vid_cap failed\n");
  13487. + return ret;
  13488. + }
  13489. +
  13490. + /* if a capture is running refuse to set format */
  13491. + if (vb2_is_busy(&dev->capture.vb_vidq)) {
  13492. + v4l2_info(&dev->v4l2_dev, "%s device busy\n", __func__);
  13493. + return -EBUSY;
  13494. + }
  13495. +
  13496. + /* If the format is unsupported v4l2 says we should switch to
  13497. + * a supported one and not return an error. */
  13498. + mfmt = get_format(f);
  13499. + if (!mfmt) {
  13500. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13501. + "Fourcc format (0x%08x) unknown.\n",
  13502. + f->fmt.pix.pixelformat);
  13503. + f->fmt.pix.pixelformat = formats[0].fourcc;
  13504. + mfmt = get_format(f);
  13505. + }
  13506. +
  13507. + ret = mmal_setup_components(dev, f);
  13508. + if (ret != 0) {
  13509. + v4l2_err(&dev->v4l2_dev,
  13510. + "%s: failed to setup mmal components: %d\n",
  13511. + __func__, ret);
  13512. + ret = -EINVAL;
  13513. + }
  13514. +
  13515. + return ret;
  13516. +}
  13517. +
  13518. +int vidioc_enum_framesizes(struct file *file, void *fh,
  13519. + struct v4l2_frmsizeenum *fsize)
  13520. +{
  13521. + static const struct v4l2_frmsize_stepwise sizes = {
  13522. + MIN_WIDTH, MAX_WIDTH, 2,
  13523. + MIN_HEIGHT, MAX_HEIGHT, 2
  13524. + };
  13525. + int i;
  13526. +
  13527. + if (fsize->index)
  13528. + return -EINVAL;
  13529. + for (i = 0; i < ARRAY_SIZE(formats); i++)
  13530. + if (formats[i].fourcc == fsize->pixel_format)
  13531. + break;
  13532. + if (i == ARRAY_SIZE(formats))
  13533. + return -EINVAL;
  13534. + fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
  13535. + fsize->stepwise = sizes;
  13536. + return 0;
  13537. +}
  13538. +
  13539. +/* timeperframe is arbitrary and continous */
  13540. +static int vidioc_enum_frameintervals(struct file *file, void *priv,
  13541. + struct v4l2_frmivalenum *fival)
  13542. +{
  13543. + int i;
  13544. +
  13545. + if (fival->index)
  13546. + return -EINVAL;
  13547. +
  13548. + for (i = 0; i < ARRAY_SIZE(formats); i++)
  13549. + if (formats[i].fourcc == fival->pixel_format)
  13550. + break;
  13551. + if (i == ARRAY_SIZE(formats))
  13552. + return -EINVAL;
  13553. +
  13554. + /* regarding width & height - we support any within range */
  13555. + if (fival->width < MIN_WIDTH || fival->width > MAX_WIDTH ||
  13556. + fival->height < MIN_HEIGHT || fival->height > MAX_HEIGHT)
  13557. + return -EINVAL;
  13558. +
  13559. + fival->type = V4L2_FRMIVAL_TYPE_CONTINUOUS;
  13560. +
  13561. + /* fill in stepwise (step=1.0 is requred by V4L2 spec) */
  13562. + fival->stepwise.min = tpf_min;
  13563. + fival->stepwise.max = tpf_max;
  13564. + fival->stepwise.step = (struct v4l2_fract) {1, 1};
  13565. +
  13566. + return 0;
  13567. +}
  13568. +
  13569. +static int vidioc_g_parm(struct file *file, void *priv,
  13570. + struct v4l2_streamparm *parm)
  13571. +{
  13572. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  13573. +
  13574. + if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  13575. + return -EINVAL;
  13576. +
  13577. + parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
  13578. + parm->parm.capture.timeperframe = dev->capture.timeperframe;
  13579. + parm->parm.capture.readbuffers = 1;
  13580. + return 0;
  13581. +}
  13582. +
  13583. +#define FRACT_CMP(a, OP, b) \
  13584. + ((u64)(a).numerator * (b).denominator OP \
  13585. + (u64)(b).numerator * (a).denominator)
  13586. +
  13587. +static int vidioc_s_parm(struct file *file, void *priv,
  13588. + struct v4l2_streamparm *parm)
  13589. +{
  13590. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  13591. + struct v4l2_fract tpf;
  13592. + struct mmal_parameter_rational fps_param;
  13593. +
  13594. + if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  13595. + return -EINVAL;
  13596. +
  13597. + tpf = parm->parm.capture.timeperframe;
  13598. +
  13599. + /* tpf: {*, 0} resets timing; clip to [min, max]*/
  13600. + tpf = tpf.denominator ? tpf : tpf_default;
  13601. + tpf = FRACT_CMP(tpf, <, tpf_min) ? tpf_min : tpf;
  13602. + tpf = FRACT_CMP(tpf, >, tpf_max) ? tpf_max : tpf;
  13603. +
  13604. + dev->capture.timeperframe = tpf;
  13605. + parm->parm.capture.timeperframe = tpf;
  13606. + parm->parm.capture.readbuffers = 1;
  13607. +
  13608. + fps_param.num = 0; /* Select variable fps, and then use
  13609. + * FPS_RANGE to select the actual limits.
  13610. + */
  13611. + fps_param.den = 1;
  13612. + set_framerate_params(dev);
  13613. +
  13614. + return 0;
  13615. +}
  13616. +
  13617. +static const struct v4l2_ioctl_ops camera0_ioctl_ops = {
  13618. + /* overlay */
  13619. + .vidioc_enum_fmt_vid_overlay = vidioc_enum_fmt_vid_overlay,
  13620. + .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_vid_overlay,
  13621. + .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay,
  13622. + .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay,
  13623. + .vidioc_overlay = vidioc_overlay,
  13624. + .vidioc_g_fbuf = vidioc_g_fbuf,
  13625. +
  13626. + /* inputs */
  13627. + .vidioc_enum_input = vidioc_enum_input,
  13628. + .vidioc_g_input = vidioc_g_input,
  13629. + .vidioc_s_input = vidioc_s_input,
  13630. +
  13631. + /* capture */
  13632. + .vidioc_querycap = vidioc_querycap,
  13633. + .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
  13634. + .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
  13635. + .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
  13636. + .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
  13637. +
  13638. + /* buffer management */
  13639. + .vidioc_reqbufs = vb2_ioctl_reqbufs,
  13640. + .vidioc_create_bufs = vb2_ioctl_create_bufs,
  13641. + .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
  13642. + .vidioc_querybuf = vb2_ioctl_querybuf,
  13643. + .vidioc_qbuf = vb2_ioctl_qbuf,
  13644. + .vidioc_dqbuf = vb2_ioctl_dqbuf,
  13645. + .vidioc_enum_framesizes = vidioc_enum_framesizes,
  13646. + .vidioc_enum_frameintervals = vidioc_enum_frameintervals,
  13647. + .vidioc_g_parm = vidioc_g_parm,
  13648. + .vidioc_s_parm = vidioc_s_parm,
  13649. + .vidioc_streamon = vb2_ioctl_streamon,
  13650. + .vidioc_streamoff = vb2_ioctl_streamoff,
  13651. +
  13652. + .vidioc_log_status = v4l2_ctrl_log_status,
  13653. + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
  13654. + .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
  13655. +};
  13656. +
  13657. +static const struct v4l2_ioctl_ops camera0_ioctl_ops_gstreamer = {
  13658. + /* overlay */
  13659. + .vidioc_enum_fmt_vid_overlay = vidioc_enum_fmt_vid_overlay,
  13660. + .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_vid_overlay,
  13661. + .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay,
  13662. + .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay,
  13663. + .vidioc_overlay = vidioc_overlay,
  13664. + .vidioc_g_fbuf = vidioc_g_fbuf,
  13665. +
  13666. + /* inputs */
  13667. + .vidioc_enum_input = vidioc_enum_input,
  13668. + .vidioc_g_input = vidioc_g_input,
  13669. + .vidioc_s_input = vidioc_s_input,
  13670. +
  13671. + /* capture */
  13672. + .vidioc_querycap = vidioc_querycap,
  13673. + .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
  13674. + .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
  13675. + .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
  13676. + .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
  13677. +
  13678. + /* buffer management */
  13679. + .vidioc_reqbufs = vb2_ioctl_reqbufs,
  13680. + .vidioc_create_bufs = vb2_ioctl_create_bufs,
  13681. + .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
  13682. + .vidioc_querybuf = vb2_ioctl_querybuf,
  13683. + .vidioc_qbuf = vb2_ioctl_qbuf,
  13684. + .vidioc_dqbuf = vb2_ioctl_dqbuf,
  13685. + /* Remove this function ptr to fix gstreamer bug
  13686. + .vidioc_enum_framesizes = vidioc_enum_framesizes, */
  13687. + .vidioc_enum_frameintervals = vidioc_enum_frameintervals,
  13688. + .vidioc_g_parm = vidioc_g_parm,
  13689. + .vidioc_s_parm = vidioc_s_parm,
  13690. + .vidioc_streamon = vb2_ioctl_streamon,
  13691. + .vidioc_streamoff = vb2_ioctl_streamoff,
  13692. +
  13693. + .vidioc_log_status = v4l2_ctrl_log_status,
  13694. + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
  13695. + .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
  13696. +};
  13697. +
  13698. +/* ------------------------------------------------------------------
  13699. + Driver init/finalise
  13700. + ------------------------------------------------------------------*/
  13701. +
  13702. +static const struct v4l2_file_operations camera0_fops = {
  13703. + .owner = THIS_MODULE,
  13704. + .open = v4l2_fh_open,
  13705. + .release = vb2_fop_release,
  13706. + .read = vb2_fop_read,
  13707. + .poll = vb2_fop_poll,
  13708. + .unlocked_ioctl = video_ioctl2, /* V4L2 ioctl handler */
  13709. + .mmap = vb2_fop_mmap,
  13710. +};
  13711. +
  13712. +static struct video_device vdev_template = {
  13713. + .name = "camera0",
  13714. + .fops = &camera0_fops,
  13715. + .ioctl_ops = &camera0_ioctl_ops,
  13716. + .release = video_device_release_empty,
  13717. +};
  13718. +
  13719. +static int set_camera_parameters(struct vchiq_mmal_instance *instance,
  13720. + struct vchiq_mmal_component *camera)
  13721. +{
  13722. + int ret;
  13723. + struct mmal_parameter_camera_config cam_config = {
  13724. + .max_stills_w = MAX_WIDTH,
  13725. + .max_stills_h = MAX_HEIGHT,
  13726. + .stills_yuv422 = 1,
  13727. + .one_shot_stills = 1,
  13728. + .max_preview_video_w = (max_video_width > 1920) ?
  13729. + max_video_width : 1920,
  13730. + .max_preview_video_h = (max_video_height > 1088) ?
  13731. + max_video_height : 1088,
  13732. + .num_preview_video_frames = 3,
  13733. + .stills_capture_circular_buffer_height = 0,
  13734. + .fast_preview_resume = 0,
  13735. + .use_stc_timestamp = MMAL_PARAM_TIMESTAMP_MODE_RAW_STC
  13736. + };
  13737. +
  13738. + ret = vchiq_mmal_port_parameter_set(instance, &camera->control,
  13739. + MMAL_PARAMETER_CAMERA_CONFIG,
  13740. + &cam_config, sizeof(cam_config));
  13741. + return ret;
  13742. +}
  13743. +
  13744. +/* MMAL instance and component init */
  13745. +static int __init mmal_init(struct bm2835_mmal_dev *dev)
  13746. +{
  13747. + int ret;
  13748. + struct mmal_es_format *format;
  13749. + u32 bool_true = 1;
  13750. +
  13751. + ret = vchiq_mmal_init(&dev->instance);
  13752. + if (ret < 0)
  13753. + return ret;
  13754. +
  13755. + /* get the camera component ready */
  13756. + ret = vchiq_mmal_component_init(dev->instance, "ril.camera",
  13757. + &dev->component[MMAL_COMPONENT_CAMERA]);
  13758. + if (ret < 0)
  13759. + goto unreg_mmal;
  13760. +
  13761. + if (dev->component[MMAL_COMPONENT_CAMERA]->outputs <
  13762. + MMAL_CAMERA_PORT_COUNT) {
  13763. + ret = -EINVAL;
  13764. + goto unreg_camera;
  13765. + }
  13766. +
  13767. + ret = set_camera_parameters(dev->instance,
  13768. + dev->component[MMAL_COMPONENT_CAMERA]);
  13769. + if (ret < 0)
  13770. + goto unreg_camera;
  13771. +
  13772. + format =
  13773. + &dev->component[MMAL_COMPONENT_CAMERA]->
  13774. + output[MMAL_CAMERA_PORT_PREVIEW].format;
  13775. +
  13776. + format->encoding = MMAL_ENCODING_OPAQUE;
  13777. + format->encoding_variant = MMAL_ENCODING_I420;
  13778. +
  13779. + format->es->video.width = 1024;
  13780. + format->es->video.height = 768;
  13781. + format->es->video.crop.x = 0;
  13782. + format->es->video.crop.y = 0;
  13783. + format->es->video.crop.width = 1024;
  13784. + format->es->video.crop.height = 768;
  13785. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  13786. + format->es->video.frame_rate.den = 1;
  13787. +
  13788. + format =
  13789. + &dev->component[MMAL_COMPONENT_CAMERA]->
  13790. + output[MMAL_CAMERA_PORT_VIDEO].format;
  13791. +
  13792. + format->encoding = MMAL_ENCODING_OPAQUE;
  13793. + format->encoding_variant = MMAL_ENCODING_I420;
  13794. +
  13795. + format->es->video.width = 1024;
  13796. + format->es->video.height = 768;
  13797. + format->es->video.crop.x = 0;
  13798. + format->es->video.crop.y = 0;
  13799. + format->es->video.crop.width = 1024;
  13800. + format->es->video.crop.height = 768;
  13801. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  13802. + format->es->video.frame_rate.den = 1;
  13803. +
  13804. + vchiq_mmal_port_parameter_set(dev->instance,
  13805. + &dev->component[MMAL_COMPONENT_CAMERA]->
  13806. + output[MMAL_CAMERA_PORT_VIDEO],
  13807. + MMAL_PARAMETER_NO_IMAGE_PADDING,
  13808. + &bool_true, sizeof(bool_true));
  13809. +
  13810. + format =
  13811. + &dev->component[MMAL_COMPONENT_CAMERA]->
  13812. + output[MMAL_CAMERA_PORT_CAPTURE].format;
  13813. +
  13814. + format->encoding = MMAL_ENCODING_OPAQUE;
  13815. +
  13816. + format->es->video.width = 2592;
  13817. + format->es->video.height = 1944;
  13818. + format->es->video.crop.x = 0;
  13819. + format->es->video.crop.y = 0;
  13820. + format->es->video.crop.width = 2592;
  13821. + format->es->video.crop.height = 1944;
  13822. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  13823. + format->es->video.frame_rate.den = 1;
  13824. +
  13825. + dev->capture.width = format->es->video.width;
  13826. + dev->capture.height = format->es->video.height;
  13827. + dev->capture.fmt = &formats[0];
  13828. + dev->capture.encode_component = NULL;
  13829. + dev->capture.timeperframe = tpf_default;
  13830. + dev->capture.enc_profile = V4L2_MPEG_VIDEO_H264_PROFILE_HIGH;
  13831. + dev->capture.enc_level = V4L2_MPEG_VIDEO_H264_LEVEL_4_0;
  13832. +
  13833. + vchiq_mmal_port_parameter_set(dev->instance,
  13834. + &dev->component[MMAL_COMPONENT_CAMERA]->
  13835. + output[MMAL_CAMERA_PORT_CAPTURE],
  13836. + MMAL_PARAMETER_NO_IMAGE_PADDING,
  13837. + &bool_true, sizeof(bool_true));
  13838. +
  13839. + /* get the preview component ready */
  13840. + ret = vchiq_mmal_component_init(
  13841. + dev->instance, "ril.video_render",
  13842. + &dev->component[MMAL_COMPONENT_PREVIEW]);
  13843. + if (ret < 0)
  13844. + goto unreg_camera;
  13845. +
  13846. + if (dev->component[MMAL_COMPONENT_PREVIEW]->inputs < 1) {
  13847. + ret = -EINVAL;
  13848. + pr_debug("too few input ports %d needed %d\n",
  13849. + dev->component[MMAL_COMPONENT_PREVIEW]->inputs, 1);
  13850. + goto unreg_preview;
  13851. + }
  13852. +
  13853. + /* get the image encoder component ready */
  13854. + ret = vchiq_mmal_component_init(
  13855. + dev->instance, "ril.image_encode",
  13856. + &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
  13857. + if (ret < 0)
  13858. + goto unreg_preview;
  13859. +
  13860. + if (dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs < 1) {
  13861. + ret = -EINVAL;
  13862. + v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
  13863. + dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs,
  13864. + 1);
  13865. + goto unreg_image_encoder;
  13866. + }
  13867. +
  13868. + /* get the video encoder component ready */
  13869. + ret = vchiq_mmal_component_init(dev->instance, "ril.video_encode",
  13870. + &dev->
  13871. + component[MMAL_COMPONENT_VIDEO_ENCODE]);
  13872. + if (ret < 0)
  13873. + goto unreg_image_encoder;
  13874. +
  13875. + if (dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs < 1) {
  13876. + ret = -EINVAL;
  13877. + v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
  13878. + dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs,
  13879. + 1);
  13880. + goto unreg_vid_encoder;
  13881. + }
  13882. +
  13883. + {
  13884. + struct vchiq_mmal_port *encoder_port =
  13885. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  13886. + encoder_port->format.encoding = MMAL_ENCODING_H264;
  13887. + ret = vchiq_mmal_port_set_format(dev->instance,
  13888. + encoder_port);
  13889. + }
  13890. +
  13891. + {
  13892. + unsigned int enable = 1;
  13893. + vchiq_mmal_port_parameter_set(
  13894. + dev->instance,
  13895. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
  13896. + MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
  13897. + &enable, sizeof(enable));
  13898. +
  13899. + vchiq_mmal_port_parameter_set(dev->instance,
  13900. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
  13901. + MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
  13902. + &enable,
  13903. + sizeof(enable));
  13904. + }
  13905. + ret = bm2835_mmal_set_all_camera_controls(dev);
  13906. + if (ret < 0)
  13907. + goto unreg_vid_encoder;
  13908. +
  13909. + return 0;
  13910. +
  13911. +unreg_vid_encoder:
  13912. + pr_err("Cleanup: Destroy video encoder\n");
  13913. + vchiq_mmal_component_finalise(
  13914. + dev->instance,
  13915. + dev->component[MMAL_COMPONENT_VIDEO_ENCODE]);
  13916. +
  13917. +unreg_image_encoder:
  13918. + pr_err("Cleanup: Destroy image encoder\n");
  13919. + vchiq_mmal_component_finalise(
  13920. + dev->instance,
  13921. + dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
  13922. +
  13923. +unreg_preview:
  13924. + pr_err("Cleanup: Destroy video render\n");
  13925. + vchiq_mmal_component_finalise(dev->instance,
  13926. + dev->component[MMAL_COMPONENT_PREVIEW]);
  13927. +
  13928. +unreg_camera:
  13929. + pr_err("Cleanup: Destroy camera\n");
  13930. + vchiq_mmal_component_finalise(dev->instance,
  13931. + dev->component[MMAL_COMPONENT_CAMERA]);
  13932. +
  13933. +unreg_mmal:
  13934. + vchiq_mmal_finalise(dev->instance);
  13935. + return ret;
  13936. +}
  13937. +
  13938. +static int __init bm2835_mmal_init_device(struct bm2835_mmal_dev *dev,
  13939. + struct video_device *vfd)
  13940. +{
  13941. + int ret;
  13942. +
  13943. + *vfd = vdev_template;
  13944. + if (gst_v4l2src_is_broken) {
  13945. + v4l2_info(&dev->v4l2_dev,
  13946. + "Work-around for gstreamer issue is active.\n");
  13947. + vfd->ioctl_ops = &camera0_ioctl_ops_gstreamer;
  13948. + }
  13949. +
  13950. + vfd->v4l2_dev = &dev->v4l2_dev;
  13951. +
  13952. + vfd->lock = &dev->mutex;
  13953. +
  13954. + vfd->queue = &dev->capture.vb_vidq;
  13955. +
  13956. + set_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
  13957. +
  13958. + /* video device needs to be able to access instance data */
  13959. + video_set_drvdata(vfd, dev);
  13960. +
  13961. + ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1);
  13962. + if (ret < 0)
  13963. + return ret;
  13964. +
  13965. + v4l2_info(vfd->v4l2_dev,
  13966. + "V4L2 device registered as %s - stills mode > %dx%d\n",
  13967. + video_device_node_name(vfd), max_video_width, max_video_height);
  13968. +
  13969. + return 0;
  13970. +}
  13971. +
  13972. +static struct v4l2_format default_v4l2_format = {
  13973. + .fmt.pix.pixelformat = V4L2_PIX_FMT_JPEG,
  13974. + .fmt.pix.width = 1024,
  13975. + .fmt.pix.bytesperline = 1024,
  13976. + .fmt.pix.height = 768,
  13977. + .fmt.pix.sizeimage = 1024*768,
  13978. +};
  13979. +
  13980. +static int __init bm2835_mmal_init(void)
  13981. +{
  13982. + int ret;
  13983. + struct bm2835_mmal_dev *dev;
  13984. + struct vb2_queue *q;
  13985. +
  13986. + dev = kzalloc(sizeof(*gdev), GFP_KERNEL);
  13987. + if (!dev)
  13988. + return -ENOMEM;
  13989. +
  13990. + /* setup device defaults */
  13991. + dev->overlay.w.left = 150;
  13992. + dev->overlay.w.top = 50;
  13993. + dev->overlay.w.width = 1024;
  13994. + dev->overlay.w.height = 768;
  13995. + dev->overlay.clipcount = 0;
  13996. + dev->overlay.field = V4L2_FIELD_NONE;
  13997. +
  13998. + dev->capture.fmt = &formats[3]; /* JPEG */
  13999. +
  14000. + /* v4l device registration */
  14001. + snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name),
  14002. + "%s", BM2835_MMAL_MODULE_NAME);
  14003. + ret = v4l2_device_register(NULL, &dev->v4l2_dev);
  14004. + if (ret)
  14005. + goto free_dev;
  14006. +
  14007. + /* setup v4l controls */
  14008. + ret = bm2835_mmal_init_controls(dev, &dev->ctrl_handler);
  14009. + if (ret < 0)
  14010. + goto unreg_dev;
  14011. + dev->v4l2_dev.ctrl_handler = &dev->ctrl_handler;
  14012. +
  14013. + /* mmal init */
  14014. + ret = mmal_init(dev);
  14015. + if (ret < 0)
  14016. + goto unreg_dev;
  14017. +
  14018. + /* initialize queue */
  14019. + q = &dev->capture.vb_vidq;
  14020. + memset(q, 0, sizeof(*q));
  14021. + q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  14022. + q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
  14023. + q->drv_priv = dev;
  14024. + q->buf_struct_size = sizeof(struct mmal_buffer);
  14025. + q->ops = &bm2835_mmal_video_qops;
  14026. + q->mem_ops = &vb2_vmalloc_memops;
  14027. + q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  14028. + ret = vb2_queue_init(q);
  14029. + if (ret < 0)
  14030. + goto unreg_dev;
  14031. +
  14032. + /* v4l2 core mutex used to protect all fops and v4l2 ioctls. */
  14033. + mutex_init(&dev->mutex);
  14034. +
  14035. + /* initialise video devices */
  14036. + ret = bm2835_mmal_init_device(dev, &dev->vdev);
  14037. + if (ret < 0)
  14038. + goto unreg_dev;
  14039. +
  14040. + /* Really want to call vidioc_s_fmt_vid_cap with the default
  14041. + * format, but currently the APIs don't join up.
  14042. + */
  14043. + ret = mmal_setup_components(dev, &default_v4l2_format);
  14044. + if (ret < 0) {
  14045. + v4l2_err(&dev->v4l2_dev,
  14046. + "%s: could not setup components\n", __func__);
  14047. + goto unreg_dev;
  14048. + }
  14049. +
  14050. + v4l2_info(&dev->v4l2_dev,
  14051. + "Broadcom 2835 MMAL video capture ver %s loaded.\n",
  14052. + BM2835_MMAL_VERSION);
  14053. +
  14054. + gdev = dev;
  14055. + return 0;
  14056. +
  14057. +unreg_dev:
  14058. + v4l2_ctrl_handler_free(&dev->ctrl_handler);
  14059. + v4l2_device_unregister(&dev->v4l2_dev);
  14060. +
  14061. +free_dev:
  14062. + kfree(dev);
  14063. +
  14064. + v4l2_err(&dev->v4l2_dev,
  14065. + "%s: error %d while loading driver\n",
  14066. + BM2835_MMAL_MODULE_NAME, ret);
  14067. +
  14068. + return ret;
  14069. +}
  14070. +
  14071. +static void __exit bm2835_mmal_exit(void)
  14072. +{
  14073. + if (!gdev)
  14074. + return;
  14075. +
  14076. + v4l2_info(&gdev->v4l2_dev, "unregistering %s\n",
  14077. + video_device_node_name(&gdev->vdev));
  14078. +
  14079. + video_unregister_device(&gdev->vdev);
  14080. +
  14081. + if (gdev->capture.encode_component) {
  14082. + v4l2_dbg(1, bcm2835_v4l2_debug, &gdev->v4l2_dev,
  14083. + "mmal_exit - disconnect tunnel\n");
  14084. + vchiq_mmal_port_connect_tunnel(gdev->instance,
  14085. + gdev->capture.camera_port, NULL);
  14086. + vchiq_mmal_component_disable(gdev->instance,
  14087. + gdev->capture.encode_component);
  14088. + }
  14089. + vchiq_mmal_component_disable(gdev->instance,
  14090. + gdev->component[MMAL_COMPONENT_CAMERA]);
  14091. +
  14092. + vchiq_mmal_component_finalise(gdev->instance,
  14093. + gdev->
  14094. + component[MMAL_COMPONENT_VIDEO_ENCODE]);
  14095. +
  14096. + vchiq_mmal_component_finalise(gdev->instance,
  14097. + gdev->
  14098. + component[MMAL_COMPONENT_IMAGE_ENCODE]);
  14099. +
  14100. + vchiq_mmal_component_finalise(gdev->instance,
  14101. + gdev->component[MMAL_COMPONENT_PREVIEW]);
  14102. +
  14103. + vchiq_mmal_component_finalise(gdev->instance,
  14104. + gdev->component[MMAL_COMPONENT_CAMERA]);
  14105. +
  14106. + vchiq_mmal_finalise(gdev->instance);
  14107. +
  14108. + v4l2_ctrl_handler_free(&gdev->ctrl_handler);
  14109. +
  14110. + v4l2_device_unregister(&gdev->v4l2_dev);
  14111. +
  14112. + kfree(gdev);
  14113. +}
  14114. +
  14115. +module_init(bm2835_mmal_init);
  14116. +module_exit(bm2835_mmal_exit);
  14117. diff -Nur linux-3.15.4/drivers/media/platform/bcm2835/bcm2835-camera.h linux-rpi/drivers/media/platform/bcm2835/bcm2835-camera.h
  14118. --- linux-3.15.4/drivers/media/platform/bcm2835/bcm2835-camera.h 1970-01-01 01:00:00.000000000 +0100
  14119. +++ linux-rpi/drivers/media/platform/bcm2835/bcm2835-camera.h 2014-07-07 10:45:10.000000000 +0200
  14120. @@ -0,0 +1,126 @@
  14121. +/*
  14122. + * Broadcom BM2835 V4L2 driver
  14123. + *
  14124. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14125. + *
  14126. + * This file is subject to the terms and conditions of the GNU General Public
  14127. + * License. See the file COPYING in the main directory of this archive
  14128. + * for more details.
  14129. + *
  14130. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14131. + * Dave Stevenson <dsteve@broadcom.com>
  14132. + * Simon Mellor <simellor@broadcom.com>
  14133. + * Luke Diamand <luked@broadcom.com>
  14134. + *
  14135. + * core driver device
  14136. + */
  14137. +
  14138. +#define V4L2_CTRL_COUNT 28 /* number of v4l controls */
  14139. +
  14140. +enum {
  14141. + MMAL_COMPONENT_CAMERA = 0,
  14142. + MMAL_COMPONENT_PREVIEW,
  14143. + MMAL_COMPONENT_IMAGE_ENCODE,
  14144. + MMAL_COMPONENT_VIDEO_ENCODE,
  14145. + MMAL_COMPONENT_COUNT
  14146. +};
  14147. +
  14148. +enum {
  14149. + MMAL_CAMERA_PORT_PREVIEW = 0,
  14150. + MMAL_CAMERA_PORT_VIDEO,
  14151. + MMAL_CAMERA_PORT_CAPTURE,
  14152. + MMAL_CAMERA_PORT_COUNT
  14153. +};
  14154. +
  14155. +#define PREVIEW_LAYER 2
  14156. +
  14157. +extern int bcm2835_v4l2_debug;
  14158. +
  14159. +struct bm2835_mmal_dev {
  14160. + /* v4l2 devices */
  14161. + struct v4l2_device v4l2_dev;
  14162. + struct video_device vdev;
  14163. + struct mutex mutex;
  14164. +
  14165. + /* controls */
  14166. + struct v4l2_ctrl_handler ctrl_handler;
  14167. + struct v4l2_ctrl *ctrls[V4L2_CTRL_COUNT];
  14168. + enum v4l2_scene_mode scene_mode;
  14169. + struct mmal_colourfx colourfx;
  14170. + int hflip;
  14171. + int vflip;
  14172. + int red_gain;
  14173. + int blue_gain;
  14174. + enum mmal_parameter_exposuremode exposure_mode_user;
  14175. + enum v4l2_exposure_auto_type exposure_mode_v4l2_user;
  14176. + /* active exposure mode may differ if selected via a scene mode */
  14177. + enum mmal_parameter_exposuremode exposure_mode_active;
  14178. + enum mmal_parameter_exposuremeteringmode metering_mode;
  14179. + unsigned int manual_shutter_speed;
  14180. + bool exp_auto_priority;
  14181. +
  14182. + /* allocated mmal instance and components */
  14183. + struct vchiq_mmal_instance *instance;
  14184. + struct vchiq_mmal_component *component[MMAL_COMPONENT_COUNT];
  14185. + int camera_use_count;
  14186. +
  14187. + struct v4l2_window overlay;
  14188. +
  14189. + struct {
  14190. + unsigned int width; /* width */
  14191. + unsigned int height; /* height */
  14192. + unsigned int stride; /* stride */
  14193. + unsigned int buffersize; /* buffer size with padding */
  14194. + struct mmal_fmt *fmt;
  14195. + struct v4l2_fract timeperframe;
  14196. +
  14197. + /* H264 encode bitrate */
  14198. + int encode_bitrate;
  14199. + /* H264 bitrate mode. CBR/VBR */
  14200. + int encode_bitrate_mode;
  14201. + /* H264 profile */
  14202. + enum v4l2_mpeg_video_h264_profile enc_profile;
  14203. + /* H264 level */
  14204. + enum v4l2_mpeg_video_h264_level enc_level;
  14205. + /* JPEG Q-factor */
  14206. + int q_factor;
  14207. +
  14208. + struct vb2_queue vb_vidq;
  14209. +
  14210. + /* VC start timestamp for streaming */
  14211. + s64 vc_start_timestamp;
  14212. + /* Kernel start timestamp for streaming */
  14213. + struct timeval kernel_start_ts;
  14214. +
  14215. + struct vchiq_mmal_port *port; /* port being used for capture */
  14216. + /* camera port being used for capture */
  14217. + struct vchiq_mmal_port *camera_port;
  14218. + /* component being used for encode */
  14219. + struct vchiq_mmal_component *encode_component;
  14220. + /* number of frames remaining which driver should capture */
  14221. + unsigned int frame_count;
  14222. + /* last frame completion */
  14223. + struct completion frame_cmplt;
  14224. +
  14225. + } capture;
  14226. +
  14227. +};
  14228. +
  14229. +int bm2835_mmal_init_controls(
  14230. + struct bm2835_mmal_dev *dev,
  14231. + struct v4l2_ctrl_handler *hdl);
  14232. +
  14233. +int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev);
  14234. +int set_framerate_params(struct bm2835_mmal_dev *dev);
  14235. +
  14236. +/* Debug helpers */
  14237. +
  14238. +#define v4l2_dump_pix_format(level, debug, dev, pix_fmt, desc) \
  14239. +{ \
  14240. + v4l2_dbg(level, debug, dev, \
  14241. +"%s: w %u h %u field %u pfmt 0x%x bpl %u sz_img %u colorspace 0x%x priv %u\n", \
  14242. + desc == NULL ? "" : desc, \
  14243. + (pix_fmt)->width, (pix_fmt)->height, (pix_fmt)->field, \
  14244. + (pix_fmt)->pixelformat, (pix_fmt)->bytesperline, \
  14245. + (pix_fmt)->sizeimage, (pix_fmt)->colorspace, (pix_fmt)->priv); \
  14246. +}
  14247. diff -Nur linux-3.15.4/drivers/media/platform/bcm2835/controls.c linux-rpi/drivers/media/platform/bcm2835/controls.c
  14248. --- linux-3.15.4/drivers/media/platform/bcm2835/controls.c 1970-01-01 01:00:00.000000000 +0100
  14249. +++ linux-rpi/drivers/media/platform/bcm2835/controls.c 2014-07-07 10:45:10.000000000 +0200
  14250. @@ -0,0 +1,1322 @@
  14251. +/*
  14252. + * Broadcom BM2835 V4L2 driver
  14253. + *
  14254. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14255. + *
  14256. + * This file is subject to the terms and conditions of the GNU General Public
  14257. + * License. See the file COPYING in the main directory of this archive
  14258. + * for more details.
  14259. + *
  14260. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14261. + * Dave Stevenson <dsteve@broadcom.com>
  14262. + * Simon Mellor <simellor@broadcom.com>
  14263. + * Luke Diamand <luked@broadcom.com>
  14264. + */
  14265. +
  14266. +#include <linux/errno.h>
  14267. +#include <linux/kernel.h>
  14268. +#include <linux/module.h>
  14269. +#include <linux/slab.h>
  14270. +#include <media/videobuf2-vmalloc.h>
  14271. +#include <media/v4l2-device.h>
  14272. +#include <media/v4l2-ioctl.h>
  14273. +#include <media/v4l2-ctrls.h>
  14274. +#include <media/v4l2-fh.h>
  14275. +#include <media/v4l2-event.h>
  14276. +#include <media/v4l2-common.h>
  14277. +
  14278. +#include "mmal-common.h"
  14279. +#include "mmal-vchiq.h"
  14280. +#include "mmal-parameters.h"
  14281. +#include "bcm2835-camera.h"
  14282. +
  14283. +/* The supported V4L2_CID_AUTO_EXPOSURE_BIAS values are from -4.0 to +4.0.
  14284. + * MMAL values are in 1/6th increments so the MMAL range is -24 to +24.
  14285. + * V4L2 docs say value "is expressed in terms of EV, drivers should interpret
  14286. + * the values as 0.001 EV units, where the value 1000 stands for +1 EV."
  14287. + * V4L2 is limited to a max of 32 values in a menu, so count in 1/3rds from
  14288. + * -4 to +4
  14289. + */
  14290. +static const s64 ev_bias_qmenu[] = {
  14291. + -4000, -3667, -3333,
  14292. + -3000, -2667, -2333,
  14293. + -2000, -1667, -1333,
  14294. + -1000, -667, -333,
  14295. + 0, 333, 667,
  14296. + 1000, 1333, 1667,
  14297. + 2000, 2333, 2667,
  14298. + 3000, 3333, 3667,
  14299. + 4000
  14300. +};
  14301. +
  14302. +/* Supported ISO values
  14303. + * ISOO = auto ISO
  14304. + */
  14305. +static const s64 iso_qmenu[] = {
  14306. + 0, 100, 200, 400, 800,
  14307. +};
  14308. +
  14309. +static const s64 mains_freq_qmenu[] = {
  14310. + V4L2_CID_POWER_LINE_FREQUENCY_DISABLED,
  14311. + V4L2_CID_POWER_LINE_FREQUENCY_50HZ,
  14312. + V4L2_CID_POWER_LINE_FREQUENCY_60HZ,
  14313. + V4L2_CID_POWER_LINE_FREQUENCY_AUTO
  14314. +};
  14315. +
  14316. +/* Supported video encode modes */
  14317. +static const s64 bitrate_mode_qmenu[] = {
  14318. + (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
  14319. + (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_CBR,
  14320. +};
  14321. +
  14322. +enum bm2835_mmal_ctrl_type {
  14323. + MMAL_CONTROL_TYPE_STD,
  14324. + MMAL_CONTROL_TYPE_STD_MENU,
  14325. + MMAL_CONTROL_TYPE_INT_MENU,
  14326. + MMAL_CONTROL_TYPE_CLUSTER, /* special cluster entry */
  14327. +};
  14328. +
  14329. +struct bm2835_mmal_v4l2_ctrl;
  14330. +
  14331. +typedef int(bm2835_mmal_v4l2_ctrl_cb)(
  14332. + struct bm2835_mmal_dev *dev,
  14333. + struct v4l2_ctrl *ctrl,
  14334. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl);
  14335. +
  14336. +struct bm2835_mmal_v4l2_ctrl {
  14337. + u32 id; /* v4l2 control identifier */
  14338. + enum bm2835_mmal_ctrl_type type;
  14339. + /* control minimum value or
  14340. + * mask for MMAL_CONTROL_TYPE_STD_MENU */
  14341. + s32 min;
  14342. + s32 max; /* maximum value of control */
  14343. + s32 def; /* default value of control */
  14344. + s32 step; /* step size of the control */
  14345. + const s64 *imenu; /* integer menu array */
  14346. + u32 mmal_id; /* mmal parameter id */
  14347. + bm2835_mmal_v4l2_ctrl_cb *setter;
  14348. + bool ignore_errors;
  14349. +};
  14350. +
  14351. +struct v4l2_to_mmal_effects_setting {
  14352. + u32 v4l2_effect;
  14353. + u32 mmal_effect;
  14354. + s32 col_fx_enable;
  14355. + s32 col_fx_fixed_cbcr;
  14356. + u32 u;
  14357. + u32 v;
  14358. + u32 num_effect_params;
  14359. + u32 effect_params[MMAL_MAX_IMAGEFX_PARAMETERS];
  14360. +};
  14361. +
  14362. +static const struct v4l2_to_mmal_effects_setting
  14363. + v4l2_to_mmal_effects_values[] = {
  14364. + { V4L2_COLORFX_NONE, MMAL_PARAM_IMAGEFX_NONE,
  14365. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  14366. + { V4L2_COLORFX_BW, MMAL_PARAM_IMAGEFX_NONE,
  14367. + 1, 0, 128, 128, 0, {0, 0, 0, 0, 0} },
  14368. + { V4L2_COLORFX_SEPIA, MMAL_PARAM_IMAGEFX_NONE,
  14369. + 1, 0, 87, 151, 0, {0, 0, 0, 0, 0} },
  14370. + { V4L2_COLORFX_NEGATIVE, MMAL_PARAM_IMAGEFX_NEGATIVE,
  14371. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  14372. + { V4L2_COLORFX_EMBOSS, MMAL_PARAM_IMAGEFX_EMBOSS,
  14373. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  14374. + { V4L2_COLORFX_SKETCH, MMAL_PARAM_IMAGEFX_SKETCH,
  14375. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  14376. + { V4L2_COLORFX_SKY_BLUE, MMAL_PARAM_IMAGEFX_PASTEL,
  14377. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  14378. + { V4L2_COLORFX_GRASS_GREEN, MMAL_PARAM_IMAGEFX_WATERCOLOUR,
  14379. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  14380. + { V4L2_COLORFX_SKIN_WHITEN, MMAL_PARAM_IMAGEFX_WASHEDOUT,
  14381. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  14382. + { V4L2_COLORFX_VIVID, MMAL_PARAM_IMAGEFX_SATURATION,
  14383. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  14384. + { V4L2_COLORFX_AQUA, MMAL_PARAM_IMAGEFX_NONE,
  14385. + 1, 0, 171, 121, 0, {0, 0, 0, 0, 0} },
  14386. + { V4L2_COLORFX_ART_FREEZE, MMAL_PARAM_IMAGEFX_HATCH,
  14387. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  14388. + { V4L2_COLORFX_SILHOUETTE, MMAL_PARAM_IMAGEFX_FILM,
  14389. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  14390. + { V4L2_COLORFX_SOLARIZATION, MMAL_PARAM_IMAGEFX_SOLARIZE,
  14391. + 0, 0, 0, 0, 5, {1, 128, 160, 160, 48} },
  14392. + { V4L2_COLORFX_ANTIQUE, MMAL_PARAM_IMAGEFX_COLOURBALANCE,
  14393. + 0, 0, 0, 0, 3, {108, 274, 238, 0, 0} },
  14394. + { V4L2_COLORFX_SET_CBCR, MMAL_PARAM_IMAGEFX_NONE,
  14395. + 1, 1, 0, 0, 0, {0, 0, 0, 0, 0} }
  14396. +};
  14397. +
  14398. +struct v4l2_mmal_scene_config {
  14399. + enum v4l2_scene_mode v4l2_scene;
  14400. + enum mmal_parameter_exposuremode exposure_mode;
  14401. + enum mmal_parameter_exposuremeteringmode metering_mode;
  14402. +};
  14403. +
  14404. +static const struct v4l2_mmal_scene_config scene_configs[] = {
  14405. + /* V4L2_SCENE_MODE_NONE automatically added */
  14406. + {
  14407. + V4L2_SCENE_MODE_NIGHT,
  14408. + MMAL_PARAM_EXPOSUREMODE_NIGHT,
  14409. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE
  14410. + },
  14411. + {
  14412. + V4L2_SCENE_MODE_SPORTS,
  14413. + MMAL_PARAM_EXPOSUREMODE_SPORTS,
  14414. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE
  14415. + },
  14416. +};
  14417. +
  14418. +/* control handlers*/
  14419. +
  14420. +static int ctrl_set_rational(struct bm2835_mmal_dev *dev,
  14421. + struct v4l2_ctrl *ctrl,
  14422. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14423. +{
  14424. + struct mmal_parameter_rational rational_value;
  14425. + struct vchiq_mmal_port *control;
  14426. +
  14427. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  14428. +
  14429. + rational_value.num = ctrl->val;
  14430. + rational_value.den = 100;
  14431. +
  14432. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  14433. + mmal_ctrl->mmal_id,
  14434. + &rational_value,
  14435. + sizeof(rational_value));
  14436. +}
  14437. +
  14438. +static int ctrl_set_value(struct bm2835_mmal_dev *dev,
  14439. + struct v4l2_ctrl *ctrl,
  14440. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14441. +{
  14442. + u32 u32_value;
  14443. + struct vchiq_mmal_port *control;
  14444. +
  14445. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  14446. +
  14447. + u32_value = ctrl->val;
  14448. +
  14449. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  14450. + mmal_ctrl->mmal_id,
  14451. + &u32_value, sizeof(u32_value));
  14452. +}
  14453. +
  14454. +static int ctrl_set_value_menu(struct bm2835_mmal_dev *dev,
  14455. + struct v4l2_ctrl *ctrl,
  14456. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14457. +{
  14458. + u32 u32_value;
  14459. + struct vchiq_mmal_port *control;
  14460. +
  14461. + if (ctrl->val > mmal_ctrl->max || ctrl->val < mmal_ctrl->min)
  14462. + return 1;
  14463. +
  14464. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  14465. +
  14466. + u32_value = mmal_ctrl->imenu[ctrl->val];
  14467. +
  14468. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  14469. + mmal_ctrl->mmal_id,
  14470. + &u32_value, sizeof(u32_value));
  14471. +}
  14472. +
  14473. +static int ctrl_set_value_ev(struct bm2835_mmal_dev *dev,
  14474. + struct v4l2_ctrl *ctrl,
  14475. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14476. +{
  14477. + s32 s32_value;
  14478. + struct vchiq_mmal_port *control;
  14479. +
  14480. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  14481. +
  14482. + s32_value = (ctrl->val-12)*2; /* Convert from index to 1/6ths */
  14483. +
  14484. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  14485. + mmal_ctrl->mmal_id,
  14486. + &s32_value, sizeof(s32_value));
  14487. +}
  14488. +
  14489. +static int ctrl_set_rotate(struct bm2835_mmal_dev *dev,
  14490. + struct v4l2_ctrl *ctrl,
  14491. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14492. +{
  14493. + int ret;
  14494. + u32 u32_value;
  14495. + struct vchiq_mmal_component *camera;
  14496. +
  14497. + camera = dev->component[MMAL_COMPONENT_CAMERA];
  14498. +
  14499. + u32_value = ((ctrl->val % 360) / 90) * 90;
  14500. +
  14501. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[0],
  14502. + mmal_ctrl->mmal_id,
  14503. + &u32_value, sizeof(u32_value));
  14504. + if (ret < 0)
  14505. + return ret;
  14506. +
  14507. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[1],
  14508. + mmal_ctrl->mmal_id,
  14509. + &u32_value, sizeof(u32_value));
  14510. + if (ret < 0)
  14511. + return ret;
  14512. +
  14513. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[2],
  14514. + mmal_ctrl->mmal_id,
  14515. + &u32_value, sizeof(u32_value));
  14516. +
  14517. + return ret;
  14518. +}
  14519. +
  14520. +static int ctrl_set_flip(struct bm2835_mmal_dev *dev,
  14521. + struct v4l2_ctrl *ctrl,
  14522. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14523. +{
  14524. + int ret;
  14525. + u32 u32_value;
  14526. + struct vchiq_mmal_component *camera;
  14527. +
  14528. + if (ctrl->id == V4L2_CID_HFLIP)
  14529. + dev->hflip = ctrl->val;
  14530. + else
  14531. + dev->vflip = ctrl->val;
  14532. +
  14533. + camera = dev->component[MMAL_COMPONENT_CAMERA];
  14534. +
  14535. + if (dev->hflip && dev->vflip)
  14536. + u32_value = MMAL_PARAM_MIRROR_BOTH;
  14537. + else if (dev->hflip)
  14538. + u32_value = MMAL_PARAM_MIRROR_HORIZONTAL;
  14539. + else if (dev->vflip)
  14540. + u32_value = MMAL_PARAM_MIRROR_VERTICAL;
  14541. + else
  14542. + u32_value = MMAL_PARAM_MIRROR_NONE;
  14543. +
  14544. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[0],
  14545. + mmal_ctrl->mmal_id,
  14546. + &u32_value, sizeof(u32_value));
  14547. + if (ret < 0)
  14548. + return ret;
  14549. +
  14550. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[1],
  14551. + mmal_ctrl->mmal_id,
  14552. + &u32_value, sizeof(u32_value));
  14553. + if (ret < 0)
  14554. + return ret;
  14555. +
  14556. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[2],
  14557. + mmal_ctrl->mmal_id,
  14558. + &u32_value, sizeof(u32_value));
  14559. +
  14560. + return ret;
  14561. +
  14562. +}
  14563. +
  14564. +static int ctrl_set_exposure(struct bm2835_mmal_dev *dev,
  14565. + struct v4l2_ctrl *ctrl,
  14566. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14567. +{
  14568. + enum mmal_parameter_exposuremode exp_mode = dev->exposure_mode_user;
  14569. + u32 shutter_speed = 0;
  14570. + struct vchiq_mmal_port *control;
  14571. + int ret = 0;
  14572. +
  14573. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  14574. +
  14575. + if (mmal_ctrl->mmal_id == MMAL_PARAMETER_SHUTTER_SPEED) {
  14576. + /* V4L2 is in 100usec increments.
  14577. + * MMAL is 1usec.
  14578. + */
  14579. + dev->manual_shutter_speed = ctrl->val * 100;
  14580. + } else if (mmal_ctrl->mmal_id == MMAL_PARAMETER_EXPOSURE_MODE) {
  14581. + switch (ctrl->val) {
  14582. + case V4L2_EXPOSURE_AUTO:
  14583. + exp_mode = MMAL_PARAM_EXPOSUREMODE_AUTO;
  14584. + break;
  14585. +
  14586. + case V4L2_EXPOSURE_MANUAL:
  14587. + exp_mode = MMAL_PARAM_EXPOSUREMODE_OFF;
  14588. + break;
  14589. + }
  14590. + dev->exposure_mode_user = exp_mode;
  14591. + dev->exposure_mode_v4l2_user = ctrl->val;
  14592. + } else if (mmal_ctrl->id == V4L2_CID_EXPOSURE_AUTO_PRIORITY) {
  14593. + dev->exp_auto_priority = ctrl->val;
  14594. + }
  14595. +
  14596. + if (dev->scene_mode == V4L2_SCENE_MODE_NONE) {
  14597. + if (exp_mode == MMAL_PARAM_EXPOSUREMODE_OFF)
  14598. + shutter_speed = dev->manual_shutter_speed;
  14599. +
  14600. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  14601. + control,
  14602. + MMAL_PARAMETER_SHUTTER_SPEED,
  14603. + &shutter_speed,
  14604. + sizeof(shutter_speed));
  14605. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  14606. + control,
  14607. + MMAL_PARAMETER_EXPOSURE_MODE,
  14608. + &exp_mode,
  14609. + sizeof(u32));
  14610. + dev->exposure_mode_active = exp_mode;
  14611. + }
  14612. + /* exposure_dynamic_framerate (V4L2_CID_EXPOSURE_AUTO_PRIORITY) should
  14613. + * always apply irrespective of scene mode.
  14614. + */
  14615. + ret += set_framerate_params(dev);
  14616. +
  14617. + return ret;
  14618. +}
  14619. +
  14620. +static int ctrl_set_metering_mode(struct bm2835_mmal_dev *dev,
  14621. + struct v4l2_ctrl *ctrl,
  14622. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14623. +{
  14624. + switch (ctrl->val) {
  14625. + case V4L2_EXPOSURE_METERING_AVERAGE:
  14626. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE;
  14627. + break;
  14628. +
  14629. + case V4L2_EXPOSURE_METERING_CENTER_WEIGHTED:
  14630. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT;
  14631. + break;
  14632. +
  14633. + case V4L2_EXPOSURE_METERING_SPOT:
  14634. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT;
  14635. + break;
  14636. +
  14637. + /* todo matrix weighting not added to Linux API till 3.9
  14638. + case V4L2_EXPOSURE_METERING_MATRIX:
  14639. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX;
  14640. + break;
  14641. + */
  14642. +
  14643. + }
  14644. +
  14645. + if (dev->scene_mode == V4L2_SCENE_MODE_NONE) {
  14646. + struct vchiq_mmal_port *control;
  14647. + u32 u32_value = dev->metering_mode;
  14648. +
  14649. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  14650. +
  14651. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  14652. + mmal_ctrl->mmal_id,
  14653. + &u32_value, sizeof(u32_value));
  14654. + } else
  14655. + return 0;
  14656. +}
  14657. +
  14658. +static int ctrl_set_flicker_avoidance(struct bm2835_mmal_dev *dev,
  14659. + struct v4l2_ctrl *ctrl,
  14660. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14661. +{
  14662. + u32 u32_value;
  14663. + struct vchiq_mmal_port *control;
  14664. +
  14665. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  14666. +
  14667. + switch (ctrl->val) {
  14668. + case V4L2_CID_POWER_LINE_FREQUENCY_DISABLED:
  14669. + u32_value = MMAL_PARAM_FLICKERAVOID_OFF;
  14670. + break;
  14671. + case V4L2_CID_POWER_LINE_FREQUENCY_50HZ:
  14672. + u32_value = MMAL_PARAM_FLICKERAVOID_50HZ;
  14673. + break;
  14674. + case V4L2_CID_POWER_LINE_FREQUENCY_60HZ:
  14675. + u32_value = MMAL_PARAM_FLICKERAVOID_60HZ;
  14676. + break;
  14677. + case V4L2_CID_POWER_LINE_FREQUENCY_AUTO:
  14678. + u32_value = MMAL_PARAM_FLICKERAVOID_AUTO;
  14679. + break;
  14680. + }
  14681. +
  14682. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  14683. + mmal_ctrl->mmal_id,
  14684. + &u32_value, sizeof(u32_value));
  14685. +}
  14686. +
  14687. +static int ctrl_set_awb_mode(struct bm2835_mmal_dev *dev,
  14688. + struct v4l2_ctrl *ctrl,
  14689. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14690. +{
  14691. + u32 u32_value;
  14692. + struct vchiq_mmal_port *control;
  14693. +
  14694. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  14695. +
  14696. + switch (ctrl->val) {
  14697. + case V4L2_WHITE_BALANCE_MANUAL:
  14698. + u32_value = MMAL_PARAM_AWBMODE_OFF;
  14699. + break;
  14700. +
  14701. + case V4L2_WHITE_BALANCE_AUTO:
  14702. + u32_value = MMAL_PARAM_AWBMODE_AUTO;
  14703. + break;
  14704. +
  14705. + case V4L2_WHITE_BALANCE_INCANDESCENT:
  14706. + u32_value = MMAL_PARAM_AWBMODE_INCANDESCENT;
  14707. + break;
  14708. +
  14709. + case V4L2_WHITE_BALANCE_FLUORESCENT:
  14710. + u32_value = MMAL_PARAM_AWBMODE_FLUORESCENT;
  14711. + break;
  14712. +
  14713. + case V4L2_WHITE_BALANCE_FLUORESCENT_H:
  14714. + u32_value = MMAL_PARAM_AWBMODE_TUNGSTEN;
  14715. + break;
  14716. +
  14717. + case V4L2_WHITE_BALANCE_HORIZON:
  14718. + u32_value = MMAL_PARAM_AWBMODE_HORIZON;
  14719. + break;
  14720. +
  14721. + case V4L2_WHITE_BALANCE_DAYLIGHT:
  14722. + u32_value = MMAL_PARAM_AWBMODE_SUNLIGHT;
  14723. + break;
  14724. +
  14725. + case V4L2_WHITE_BALANCE_FLASH:
  14726. + u32_value = MMAL_PARAM_AWBMODE_FLASH;
  14727. + break;
  14728. +
  14729. + case V4L2_WHITE_BALANCE_CLOUDY:
  14730. + u32_value = MMAL_PARAM_AWBMODE_CLOUDY;
  14731. + break;
  14732. +
  14733. + case V4L2_WHITE_BALANCE_SHADE:
  14734. + u32_value = MMAL_PARAM_AWBMODE_SHADE;
  14735. + break;
  14736. +
  14737. + }
  14738. +
  14739. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  14740. + mmal_ctrl->mmal_id,
  14741. + &u32_value, sizeof(u32_value));
  14742. +}
  14743. +
  14744. +static int ctrl_set_awb_gains(struct bm2835_mmal_dev *dev,
  14745. + struct v4l2_ctrl *ctrl,
  14746. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14747. +{
  14748. + struct vchiq_mmal_port *control;
  14749. + struct mmal_parameter_awbgains gains;
  14750. +
  14751. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  14752. +
  14753. + if (ctrl->id == V4L2_CID_RED_BALANCE)
  14754. + dev->red_gain = ctrl->val;
  14755. + else if (ctrl->id == V4L2_CID_BLUE_BALANCE)
  14756. + dev->blue_gain = ctrl->val;
  14757. +
  14758. + gains.r_gain.num = dev->red_gain;
  14759. + gains.b_gain.num = dev->blue_gain;
  14760. + gains.r_gain.den = gains.b_gain.den = 1000;
  14761. +
  14762. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  14763. + mmal_ctrl->mmal_id,
  14764. + &gains, sizeof(gains));
  14765. +}
  14766. +
  14767. +static int ctrl_set_image_effect(struct bm2835_mmal_dev *dev,
  14768. + struct v4l2_ctrl *ctrl,
  14769. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14770. +{
  14771. + int ret = -EINVAL;
  14772. + int i, j;
  14773. + struct vchiq_mmal_port *control;
  14774. + struct mmal_parameter_imagefx_parameters imagefx;
  14775. +
  14776. + for (i = 0; i < ARRAY_SIZE(v4l2_to_mmal_effects_values); i++) {
  14777. + if (ctrl->val == v4l2_to_mmal_effects_values[i].v4l2_effect) {
  14778. +
  14779. + imagefx.effect =
  14780. + v4l2_to_mmal_effects_values[i].mmal_effect;
  14781. + imagefx.num_effect_params =
  14782. + v4l2_to_mmal_effects_values[i].num_effect_params;
  14783. +
  14784. + if (imagefx.num_effect_params > MMAL_MAX_IMAGEFX_PARAMETERS)
  14785. + imagefx.num_effect_params = MMAL_MAX_IMAGEFX_PARAMETERS;
  14786. +
  14787. + for (j = 0; j < imagefx.num_effect_params; j++)
  14788. + imagefx.effect_parameter[j] =
  14789. + v4l2_to_mmal_effects_values[i].effect_params[j];
  14790. +
  14791. + dev->colourfx.enable =
  14792. + v4l2_to_mmal_effects_values[i].col_fx_enable;
  14793. + if (!v4l2_to_mmal_effects_values[i].col_fx_fixed_cbcr) {
  14794. + dev->colourfx.u =
  14795. + v4l2_to_mmal_effects_values[i].u;
  14796. + dev->colourfx.v =
  14797. + v4l2_to_mmal_effects_values[i].v;
  14798. + }
  14799. +
  14800. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  14801. +
  14802. + ret = vchiq_mmal_port_parameter_set(
  14803. + dev->instance, control,
  14804. + MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
  14805. + &imagefx, sizeof(imagefx));
  14806. + if (ret)
  14807. + goto exit;
  14808. +
  14809. + ret = vchiq_mmal_port_parameter_set(
  14810. + dev->instance, control,
  14811. + MMAL_PARAMETER_COLOUR_EFFECT,
  14812. + &dev->colourfx, sizeof(dev->colourfx));
  14813. + }
  14814. + }
  14815. +
  14816. +exit:
  14817. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  14818. + "mmal_ctrl:%p ctrl id:0x%x ctrl val:%d imagefx:0x%x color_effect:%s u:%d v:%d ret %d(%d)\n",
  14819. + mmal_ctrl, ctrl->id, ctrl->val, imagefx.effect,
  14820. + dev->colourfx.enable ? "true" : "false",
  14821. + dev->colourfx.u, dev->colourfx.v,
  14822. + ret, (ret == 0 ? 0 : -EINVAL));
  14823. + return (ret == 0 ? 0 : EINVAL);
  14824. +}
  14825. +
  14826. +static int ctrl_set_colfx(struct bm2835_mmal_dev *dev,
  14827. + struct v4l2_ctrl *ctrl,
  14828. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14829. +{
  14830. + int ret = -EINVAL;
  14831. + struct vchiq_mmal_port *control;
  14832. +
  14833. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  14834. +
  14835. + dev->colourfx.enable = (ctrl->val & 0xff00) >> 8;
  14836. + dev->colourfx.enable = ctrl->val & 0xff;
  14837. +
  14838. + ret = vchiq_mmal_port_parameter_set(dev->instance, control,
  14839. + MMAL_PARAMETER_COLOUR_EFFECT,
  14840. + &dev->colourfx, sizeof(dev->colourfx));
  14841. +
  14842. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  14843. + "%s: After: mmal_ctrl:%p ctrl id:0x%x ctrl val:%d ret %d(%d)\n",
  14844. + __func__, mmal_ctrl, ctrl->id, ctrl->val, ret,
  14845. + (ret == 0 ? 0 : -EINVAL));
  14846. + return (ret == 0 ? 0 : EINVAL);
  14847. +}
  14848. +
  14849. +static int ctrl_set_bitrate(struct bm2835_mmal_dev *dev,
  14850. + struct v4l2_ctrl *ctrl,
  14851. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14852. +{
  14853. + int ret;
  14854. + struct vchiq_mmal_port *encoder_out;
  14855. +
  14856. + dev->capture.encode_bitrate = ctrl->val;
  14857. +
  14858. + encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  14859. +
  14860. + ret = vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
  14861. + mmal_ctrl->mmal_id,
  14862. + &ctrl->val, sizeof(ctrl->val));
  14863. + ret = 0;
  14864. + return ret;
  14865. +}
  14866. +
  14867. +static int ctrl_set_bitrate_mode(struct bm2835_mmal_dev *dev,
  14868. + struct v4l2_ctrl *ctrl,
  14869. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14870. +{
  14871. + u32 bitrate_mode;
  14872. + struct vchiq_mmal_port *encoder_out;
  14873. +
  14874. + encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  14875. +
  14876. + dev->capture.encode_bitrate_mode = ctrl->val;
  14877. + switch (ctrl->val) {
  14878. + default:
  14879. + case V4L2_MPEG_VIDEO_BITRATE_MODE_VBR:
  14880. + bitrate_mode = MMAL_VIDEO_RATECONTROL_VARIABLE;
  14881. + break;
  14882. + case V4L2_MPEG_VIDEO_BITRATE_MODE_CBR:
  14883. + bitrate_mode = MMAL_VIDEO_RATECONTROL_CONSTANT;
  14884. + break;
  14885. + }
  14886. +
  14887. + vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
  14888. + mmal_ctrl->mmal_id,
  14889. + &bitrate_mode,
  14890. + sizeof(bitrate_mode));
  14891. + return 0;
  14892. +}
  14893. +
  14894. +static int ctrl_set_image_encode_output(struct bm2835_mmal_dev *dev,
  14895. + struct v4l2_ctrl *ctrl,
  14896. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14897. +{
  14898. + u32 u32_value;
  14899. + struct vchiq_mmal_port *jpeg_out;
  14900. +
  14901. + jpeg_out = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
  14902. +
  14903. + u32_value = ctrl->val;
  14904. +
  14905. + return vchiq_mmal_port_parameter_set(dev->instance, jpeg_out,
  14906. + mmal_ctrl->mmal_id,
  14907. + &u32_value, sizeof(u32_value));
  14908. +}
  14909. +
  14910. +static int ctrl_set_video_encode_param_output(struct bm2835_mmal_dev *dev,
  14911. + struct v4l2_ctrl *ctrl,
  14912. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14913. +{
  14914. + u32 u32_value;
  14915. + struct vchiq_mmal_port *vid_enc_ctl;
  14916. +
  14917. + vid_enc_ctl = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  14918. +
  14919. + u32_value = ctrl->val;
  14920. +
  14921. + return vchiq_mmal_port_parameter_set(dev->instance, vid_enc_ctl,
  14922. + mmal_ctrl->mmal_id,
  14923. + &u32_value, sizeof(u32_value));
  14924. +}
  14925. +
  14926. +static int ctrl_set_video_encode_profile_level(struct bm2835_mmal_dev *dev,
  14927. + struct v4l2_ctrl *ctrl,
  14928. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14929. +{
  14930. + struct mmal_parameter_video_profile param;
  14931. + int ret = 0;
  14932. +
  14933. + if (ctrl->id == V4L2_CID_MPEG_VIDEO_H264_PROFILE) {
  14934. + switch (ctrl->val) {
  14935. + case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE:
  14936. + case V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE:
  14937. + case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN:
  14938. + case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH:
  14939. + dev->capture.enc_profile = ctrl->val;
  14940. + break;
  14941. + default:
  14942. + ret = -EINVAL;
  14943. + break;
  14944. + }
  14945. + } else if (ctrl->id == V4L2_CID_MPEG_VIDEO_H264_LEVEL) {
  14946. + switch (ctrl->val) {
  14947. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_0:
  14948. + case V4L2_MPEG_VIDEO_H264_LEVEL_1B:
  14949. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_1:
  14950. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_2:
  14951. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_3:
  14952. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_0:
  14953. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_1:
  14954. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_2:
  14955. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_0:
  14956. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_1:
  14957. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_2:
  14958. + case V4L2_MPEG_VIDEO_H264_LEVEL_4_0:
  14959. + dev->capture.enc_level = ctrl->val;
  14960. + break;
  14961. + default:
  14962. + ret = -EINVAL;
  14963. + break;
  14964. + }
  14965. + }
  14966. +
  14967. + if (!ret) {
  14968. + switch (dev->capture.enc_profile) {
  14969. + case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE:
  14970. + param.profile = MMAL_VIDEO_PROFILE_H264_BASELINE;
  14971. + break;
  14972. + case V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE:
  14973. + param.profile =
  14974. + MMAL_VIDEO_PROFILE_H264_CONSTRAINED_BASELINE;
  14975. + break;
  14976. + case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN:
  14977. + param.profile = MMAL_VIDEO_PROFILE_H264_MAIN;
  14978. + break;
  14979. + case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH:
  14980. + param.profile = MMAL_VIDEO_PROFILE_H264_HIGH;
  14981. + break;
  14982. + default:
  14983. + /* Should never get here */
  14984. + break;
  14985. + }
  14986. +
  14987. + switch (dev->capture.enc_level) {
  14988. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_0:
  14989. + param.level = MMAL_VIDEO_LEVEL_H264_1;
  14990. + break;
  14991. + case V4L2_MPEG_VIDEO_H264_LEVEL_1B:
  14992. + param.level = MMAL_VIDEO_LEVEL_H264_1b;
  14993. + break;
  14994. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_1:
  14995. + param.level = MMAL_VIDEO_LEVEL_H264_11;
  14996. + break;
  14997. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_2:
  14998. + param.level = MMAL_VIDEO_LEVEL_H264_12;
  14999. + break;
  15000. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_3:
  15001. + param.level = MMAL_VIDEO_LEVEL_H264_13;
  15002. + break;
  15003. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_0:
  15004. + param.level = MMAL_VIDEO_LEVEL_H264_2;
  15005. + break;
  15006. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_1:
  15007. + param.level = MMAL_VIDEO_LEVEL_H264_21;
  15008. + break;
  15009. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_2:
  15010. + param.level = MMAL_VIDEO_LEVEL_H264_22;
  15011. + break;
  15012. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_0:
  15013. + param.level = MMAL_VIDEO_LEVEL_H264_3;
  15014. + break;
  15015. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_1:
  15016. + param.level = MMAL_VIDEO_LEVEL_H264_31;
  15017. + break;
  15018. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_2:
  15019. + param.level = MMAL_VIDEO_LEVEL_H264_32;
  15020. + break;
  15021. + case V4L2_MPEG_VIDEO_H264_LEVEL_4_0:
  15022. + param.level = MMAL_VIDEO_LEVEL_H264_4;
  15023. + break;
  15024. + default:
  15025. + /* Should never get here */
  15026. + break;
  15027. + }
  15028. +
  15029. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  15030. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0],
  15031. + mmal_ctrl->mmal_id,
  15032. + &param, sizeof(param));
  15033. + }
  15034. + return ret;
  15035. +}
  15036. +
  15037. +static int ctrl_set_scene_mode(struct bm2835_mmal_dev *dev,
  15038. + struct v4l2_ctrl *ctrl,
  15039. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  15040. +{
  15041. + int ret = 0;
  15042. + int shutter_speed;
  15043. + struct vchiq_mmal_port *control;
  15044. +
  15045. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  15046. + "scene mode selected %d, was %d\n", ctrl->val,
  15047. + dev->scene_mode);
  15048. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  15049. +
  15050. + if (ctrl->val == dev->scene_mode)
  15051. + return 0;
  15052. +
  15053. + if (ctrl->val == V4L2_SCENE_MODE_NONE) {
  15054. + /* Restore all user selections */
  15055. + dev->scene_mode = V4L2_SCENE_MODE_NONE;
  15056. +
  15057. + if (dev->exposure_mode_user == MMAL_PARAM_EXPOSUREMODE_OFF)
  15058. + shutter_speed = dev->manual_shutter_speed;
  15059. + else
  15060. + shutter_speed = 0;
  15061. +
  15062. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  15063. + "%s: scene mode none: shut_speed %d, exp_mode %d, metering %d\n",
  15064. + __func__, shutter_speed, dev->exposure_mode_user,
  15065. + dev->metering_mode);
  15066. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  15067. + control,
  15068. + MMAL_PARAMETER_SHUTTER_SPEED,
  15069. + &shutter_speed,
  15070. + sizeof(shutter_speed));
  15071. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  15072. + control,
  15073. + MMAL_PARAMETER_EXPOSURE_MODE,
  15074. + &dev->exposure_mode_user,
  15075. + sizeof(u32));
  15076. + dev->exposure_mode_active = dev->exposure_mode_user;
  15077. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  15078. + control,
  15079. + MMAL_PARAMETER_EXP_METERING_MODE,
  15080. + &dev->metering_mode,
  15081. + sizeof(u32));
  15082. + ret += set_framerate_params(dev);
  15083. + } else {
  15084. + /* Set up scene mode */
  15085. + int i;
  15086. + const struct v4l2_mmal_scene_config *scene = NULL;
  15087. + int shutter_speed;
  15088. + enum mmal_parameter_exposuremode exposure_mode;
  15089. + enum mmal_parameter_exposuremeteringmode metering_mode;
  15090. +
  15091. + for (i = 0; i < ARRAY_SIZE(scene_configs); i++) {
  15092. + if (scene_configs[i].v4l2_scene ==
  15093. + ctrl->val) {
  15094. + scene = &scene_configs[i];
  15095. + break;
  15096. + }
  15097. + }
  15098. + if (i >= ARRAY_SIZE(scene_configs))
  15099. + return -EINVAL;
  15100. +
  15101. + /* Set all the values */
  15102. + dev->scene_mode = ctrl->val;
  15103. +
  15104. + if (scene->exposure_mode == MMAL_PARAM_EXPOSUREMODE_OFF)
  15105. + shutter_speed = dev->manual_shutter_speed;
  15106. + else
  15107. + shutter_speed = 0;
  15108. + exposure_mode = scene->exposure_mode;
  15109. + metering_mode = scene->metering_mode;
  15110. +
  15111. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  15112. + "%s: scene mode none: shut_speed %d, exp_mode %d, metering %d\n",
  15113. + __func__, shutter_speed, exposure_mode, metering_mode);
  15114. +
  15115. + ret = vchiq_mmal_port_parameter_set(dev->instance, control,
  15116. + MMAL_PARAMETER_SHUTTER_SPEED,
  15117. + &shutter_speed,
  15118. + sizeof(shutter_speed));
  15119. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  15120. + control,
  15121. + MMAL_PARAMETER_EXPOSURE_MODE,
  15122. + &exposure_mode,
  15123. + sizeof(u32));
  15124. + dev->exposure_mode_active = exposure_mode;
  15125. + ret += vchiq_mmal_port_parameter_set(dev->instance, control,
  15126. + MMAL_PARAMETER_EXPOSURE_MODE,
  15127. + &exposure_mode,
  15128. + sizeof(u32));
  15129. + ret += vchiq_mmal_port_parameter_set(dev->instance, control,
  15130. + MMAL_PARAMETER_EXP_METERING_MODE,
  15131. + &metering_mode,
  15132. + sizeof(u32));
  15133. + ret += set_framerate_params(dev);
  15134. + }
  15135. + if (ret) {
  15136. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  15137. + "%s: Setting scene to %d, ret=%d\n",
  15138. + __func__, ctrl->val, ret);
  15139. + ret = -EINVAL;
  15140. + }
  15141. + return 0;
  15142. +}
  15143. +
  15144. +static int bm2835_mmal_s_ctrl(struct v4l2_ctrl *ctrl)
  15145. +{
  15146. + struct bm2835_mmal_dev *dev =
  15147. + container_of(ctrl->handler, struct bm2835_mmal_dev,
  15148. + ctrl_handler);
  15149. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl = ctrl->priv;
  15150. + int ret;
  15151. +
  15152. + if ((mmal_ctrl == NULL) ||
  15153. + (mmal_ctrl->id != ctrl->id) ||
  15154. + (mmal_ctrl->setter == NULL)) {
  15155. + pr_warn("mmal_ctrl:%p ctrl id:%d\n", mmal_ctrl, ctrl->id);
  15156. + return -EINVAL;
  15157. + }
  15158. +
  15159. + ret = mmal_ctrl->setter(dev, ctrl, mmal_ctrl);
  15160. + if (ret)
  15161. + pr_warn("ctrl id:%d/MMAL param %08X- returned ret %d\n",
  15162. + ctrl->id, mmal_ctrl->mmal_id, ret);
  15163. + if (mmal_ctrl->ignore_errors)
  15164. + ret = 0;
  15165. + return ret;
  15166. +}
  15167. +
  15168. +static const struct v4l2_ctrl_ops bm2835_mmal_ctrl_ops = {
  15169. + .s_ctrl = bm2835_mmal_s_ctrl,
  15170. +};
  15171. +
  15172. +
  15173. +
  15174. +static const struct bm2835_mmal_v4l2_ctrl v4l2_ctrls[V4L2_CTRL_COUNT] = {
  15175. + {
  15176. + V4L2_CID_SATURATION, MMAL_CONTROL_TYPE_STD,
  15177. + -100, 100, 0, 1, NULL,
  15178. + MMAL_PARAMETER_SATURATION,
  15179. + &ctrl_set_rational,
  15180. + false
  15181. + },
  15182. + {
  15183. + V4L2_CID_SHARPNESS, MMAL_CONTROL_TYPE_STD,
  15184. + -100, 100, 0, 1, NULL,
  15185. + MMAL_PARAMETER_SHARPNESS,
  15186. + &ctrl_set_rational,
  15187. + false
  15188. + },
  15189. + {
  15190. + V4L2_CID_CONTRAST, MMAL_CONTROL_TYPE_STD,
  15191. + -100, 100, 0, 1, NULL,
  15192. + MMAL_PARAMETER_CONTRAST,
  15193. + &ctrl_set_rational,
  15194. + false
  15195. + },
  15196. + {
  15197. + V4L2_CID_BRIGHTNESS, MMAL_CONTROL_TYPE_STD,
  15198. + 0, 100, 50, 1, NULL,
  15199. + MMAL_PARAMETER_BRIGHTNESS,
  15200. + &ctrl_set_rational,
  15201. + false
  15202. + },
  15203. + {
  15204. + V4L2_CID_ISO_SENSITIVITY, MMAL_CONTROL_TYPE_INT_MENU,
  15205. + 0, ARRAY_SIZE(iso_qmenu) - 1, 0, 1, iso_qmenu,
  15206. + MMAL_PARAMETER_ISO,
  15207. + &ctrl_set_value_menu,
  15208. + false
  15209. + },
  15210. + {
  15211. + V4L2_CID_IMAGE_STABILIZATION, MMAL_CONTROL_TYPE_STD,
  15212. + 0, 1, 0, 1, NULL,
  15213. + MMAL_PARAMETER_VIDEO_STABILISATION,
  15214. + &ctrl_set_value,
  15215. + false
  15216. + },
  15217. +/* {
  15218. + 0, MMAL_CONTROL_TYPE_CLUSTER, 3, 1, 0, NULL, 0, NULL
  15219. + }, */
  15220. + {
  15221. + V4L2_CID_EXPOSURE_AUTO, MMAL_CONTROL_TYPE_STD_MENU,
  15222. + ~0x03, 3, V4L2_EXPOSURE_AUTO, 0, NULL,
  15223. + MMAL_PARAMETER_EXPOSURE_MODE,
  15224. + &ctrl_set_exposure,
  15225. + false
  15226. + },
  15227. +/* todo this needs mixing in with set exposure
  15228. + {
  15229. + V4L2_CID_SCENE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  15230. + },
  15231. + */
  15232. + {
  15233. + V4L2_CID_EXPOSURE_ABSOLUTE, MMAL_CONTROL_TYPE_STD,
  15234. + /* Units of 100usecs */
  15235. + 1, 1*1000*10, 100*10, 1, NULL,
  15236. + MMAL_PARAMETER_SHUTTER_SPEED,
  15237. + &ctrl_set_exposure,
  15238. + false
  15239. + },
  15240. + {
  15241. + V4L2_CID_AUTO_EXPOSURE_BIAS, MMAL_CONTROL_TYPE_INT_MENU,
  15242. + 0, ARRAY_SIZE(ev_bias_qmenu) - 1,
  15243. + (ARRAY_SIZE(ev_bias_qmenu)+1)/2 - 1, 0, ev_bias_qmenu,
  15244. + MMAL_PARAMETER_EXPOSURE_COMP,
  15245. + &ctrl_set_value_ev,
  15246. + false
  15247. + },
  15248. + {
  15249. + V4L2_CID_EXPOSURE_AUTO_PRIORITY, MMAL_CONTROL_TYPE_STD,
  15250. + 0, 1,
  15251. + 0, 1, NULL,
  15252. + 0, /* Dummy MMAL ID as it gets mapped into FPS range*/
  15253. + &ctrl_set_exposure,
  15254. + false
  15255. + },
  15256. + {
  15257. + V4L2_CID_EXPOSURE_METERING,
  15258. + MMAL_CONTROL_TYPE_STD_MENU,
  15259. + ~0x7, 2, V4L2_EXPOSURE_METERING_AVERAGE, 0, NULL,
  15260. + MMAL_PARAMETER_EXP_METERING_MODE,
  15261. + &ctrl_set_metering_mode,
  15262. + false
  15263. + },
  15264. + {
  15265. + V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE,
  15266. + MMAL_CONTROL_TYPE_STD_MENU,
  15267. + ~0x3ff, 9, V4L2_WHITE_BALANCE_AUTO, 0, NULL,
  15268. + MMAL_PARAMETER_AWB_MODE,
  15269. + &ctrl_set_awb_mode,
  15270. + false
  15271. + },
  15272. + {
  15273. + V4L2_CID_RED_BALANCE, MMAL_CONTROL_TYPE_STD,
  15274. + 1, 7999, 1000, 1, NULL,
  15275. + MMAL_PARAMETER_CUSTOM_AWB_GAINS,
  15276. + &ctrl_set_awb_gains,
  15277. + false
  15278. + },
  15279. + {
  15280. + V4L2_CID_BLUE_BALANCE, MMAL_CONTROL_TYPE_STD,
  15281. + 1, 7999, 1000, 1, NULL,
  15282. + MMAL_PARAMETER_CUSTOM_AWB_GAINS,
  15283. + &ctrl_set_awb_gains,
  15284. + false
  15285. + },
  15286. + {
  15287. + V4L2_CID_COLORFX, MMAL_CONTROL_TYPE_STD_MENU,
  15288. + 0, 15, V4L2_COLORFX_NONE, 0, NULL,
  15289. + MMAL_PARAMETER_IMAGE_EFFECT,
  15290. + &ctrl_set_image_effect,
  15291. + false
  15292. + },
  15293. + {
  15294. + V4L2_CID_COLORFX_CBCR, MMAL_CONTROL_TYPE_STD,
  15295. + 0, 0xffff, 0x8080, 1, NULL,
  15296. + MMAL_PARAMETER_COLOUR_EFFECT,
  15297. + &ctrl_set_colfx,
  15298. + false
  15299. + },
  15300. + {
  15301. + V4L2_CID_ROTATE, MMAL_CONTROL_TYPE_STD,
  15302. + 0, 360, 0, 90, NULL,
  15303. + MMAL_PARAMETER_ROTATION,
  15304. + &ctrl_set_rotate,
  15305. + false
  15306. + },
  15307. + {
  15308. + V4L2_CID_HFLIP, MMAL_CONTROL_TYPE_STD,
  15309. + 0, 1, 0, 1, NULL,
  15310. + MMAL_PARAMETER_MIRROR,
  15311. + &ctrl_set_flip,
  15312. + false
  15313. + },
  15314. + {
  15315. + V4L2_CID_VFLIP, MMAL_CONTROL_TYPE_STD,
  15316. + 0, 1, 0, 1, NULL,
  15317. + MMAL_PARAMETER_MIRROR,
  15318. + &ctrl_set_flip,
  15319. + false
  15320. + },
  15321. + {
  15322. + V4L2_CID_MPEG_VIDEO_BITRATE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  15323. + 0, ARRAY_SIZE(bitrate_mode_qmenu) - 1,
  15324. + 0, 0, bitrate_mode_qmenu,
  15325. + MMAL_PARAMETER_RATECONTROL,
  15326. + &ctrl_set_bitrate_mode,
  15327. + false
  15328. + },
  15329. + {
  15330. + V4L2_CID_MPEG_VIDEO_BITRATE, MMAL_CONTROL_TYPE_STD,
  15331. + 25*1000, 25*1000*1000, 10*1000*1000, 25*1000, NULL,
  15332. + MMAL_PARAMETER_VIDEO_BIT_RATE,
  15333. + &ctrl_set_bitrate,
  15334. + false
  15335. + },
  15336. + {
  15337. + V4L2_CID_JPEG_COMPRESSION_QUALITY, MMAL_CONTROL_TYPE_STD,
  15338. + 1, 100,
  15339. + 30, 1, NULL,
  15340. + MMAL_PARAMETER_JPEG_Q_FACTOR,
  15341. + &ctrl_set_image_encode_output,
  15342. + false
  15343. + },
  15344. + {
  15345. + V4L2_CID_POWER_LINE_FREQUENCY, MMAL_CONTROL_TYPE_STD_MENU,
  15346. + 0, ARRAY_SIZE(mains_freq_qmenu) - 1,
  15347. + 1, 1, NULL,
  15348. + MMAL_PARAMETER_FLICKER_AVOID,
  15349. + &ctrl_set_flicker_avoidance,
  15350. + false
  15351. + },
  15352. + {
  15353. + V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER, MMAL_CONTROL_TYPE_STD,
  15354. + 0, 1,
  15355. + 0, 1, NULL,
  15356. + MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER,
  15357. + &ctrl_set_video_encode_param_output,
  15358. + true /* Errors ignored as requires latest firmware to work */
  15359. + },
  15360. + {
  15361. + V4L2_CID_MPEG_VIDEO_H264_PROFILE,
  15362. + MMAL_CONTROL_TYPE_STD_MENU,
  15363. + ~((1<<V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE) |
  15364. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE) |
  15365. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_MAIN) |
  15366. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_HIGH)),
  15367. + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH,
  15368. + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH, 1, NULL,
  15369. + MMAL_PARAMETER_PROFILE,
  15370. + &ctrl_set_video_encode_profile_level,
  15371. + false
  15372. + },
  15373. + {
  15374. + V4L2_CID_MPEG_VIDEO_H264_LEVEL, MMAL_CONTROL_TYPE_STD_MENU,
  15375. + ~((1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_0) |
  15376. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1B) |
  15377. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_1) |
  15378. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_2) |
  15379. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_3) |
  15380. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_0) |
  15381. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_1) |
  15382. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_2) |
  15383. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_0) |
  15384. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_1) |
  15385. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_2) |
  15386. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_4_0)),
  15387. + V4L2_MPEG_VIDEO_H264_LEVEL_4_0,
  15388. + V4L2_MPEG_VIDEO_H264_LEVEL_4_0, 1, NULL,
  15389. + MMAL_PARAMETER_PROFILE,
  15390. + &ctrl_set_video_encode_profile_level,
  15391. + false
  15392. + },
  15393. + {
  15394. + V4L2_CID_SCENE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  15395. + -1, /* Min is computed at runtime */
  15396. + V4L2_SCENE_MODE_TEXT,
  15397. + V4L2_SCENE_MODE_NONE, 1, NULL,
  15398. + MMAL_PARAMETER_PROFILE,
  15399. + &ctrl_set_scene_mode,
  15400. + false
  15401. + },
  15402. + {
  15403. + V4L2_CID_MPEG_VIDEO_H264_I_PERIOD, MMAL_CONTROL_TYPE_STD,
  15404. + 0, 0x7FFFFFFF, 60, 1, NULL,
  15405. + MMAL_PARAMETER_INTRAPERIOD,
  15406. + &ctrl_set_video_encode_param_output,
  15407. + false
  15408. + },
  15409. +};
  15410. +
  15411. +int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev)
  15412. +{
  15413. + int c;
  15414. + int ret = 0;
  15415. +
  15416. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  15417. + if ((dev->ctrls[c]) && (v4l2_ctrls[c].setter)) {
  15418. + ret = v4l2_ctrls[c].setter(dev, dev->ctrls[c],
  15419. + &v4l2_ctrls[c]);
  15420. + if (!v4l2_ctrls[c].ignore_errors && ret) {
  15421. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  15422. + "Failed when setting default values for ctrl %d\n",
  15423. + c);
  15424. + break;
  15425. + }
  15426. + }
  15427. + }
  15428. + return ret;
  15429. +}
  15430. +
  15431. +int set_framerate_params(struct bm2835_mmal_dev *dev)
  15432. +{
  15433. + struct mmal_parameter_fps_range fps_range;
  15434. + int ret;
  15435. +
  15436. + if ((dev->exposure_mode_active != MMAL_PARAM_EXPOSUREMODE_OFF) &&
  15437. + (dev->exp_auto_priority)) {
  15438. + /* Variable FPS. Define min FPS as 1fps.
  15439. + * Max as max defined FPS.
  15440. + */
  15441. + fps_range.fps_low.num = 1;
  15442. + fps_range.fps_low.den = 1;
  15443. + fps_range.fps_high.num = dev->capture.timeperframe.denominator;
  15444. + fps_range.fps_high.den = dev->capture.timeperframe.numerator;
  15445. + } else {
  15446. + /* Fixed FPS - set min and max to be the same */
  15447. + fps_range.fps_low.num = fps_range.fps_high.num =
  15448. + dev->capture.timeperframe.denominator;
  15449. + fps_range.fps_low.den = fps_range.fps_high.den =
  15450. + dev->capture.timeperframe.numerator;
  15451. + }
  15452. +
  15453. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  15454. + "Set fps range to %d/%d to %d/%d\n",
  15455. + fps_range.fps_low.num,
  15456. + fps_range.fps_low.den,
  15457. + fps_range.fps_high.num,
  15458. + fps_range.fps_high.den
  15459. + );
  15460. +
  15461. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  15462. + &dev->component[MMAL_COMPONENT_CAMERA]->
  15463. + output[MMAL_CAMERA_PORT_PREVIEW],
  15464. + MMAL_PARAMETER_FPS_RANGE,
  15465. + &fps_range, sizeof(fps_range));
  15466. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  15467. + &dev->component[MMAL_COMPONENT_CAMERA]->
  15468. + output[MMAL_CAMERA_PORT_VIDEO],
  15469. + MMAL_PARAMETER_FPS_RANGE,
  15470. + &fps_range, sizeof(fps_range));
  15471. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  15472. + &dev->component[MMAL_COMPONENT_CAMERA]->
  15473. + output[MMAL_CAMERA_PORT_CAPTURE],
  15474. + MMAL_PARAMETER_FPS_RANGE,
  15475. + &fps_range, sizeof(fps_range));
  15476. + if (ret)
  15477. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  15478. + "Failed to set fps ret %d\n",
  15479. + ret);
  15480. +
  15481. + return ret;
  15482. +
  15483. +}
  15484. +
  15485. +int bm2835_mmal_init_controls(struct bm2835_mmal_dev *dev,
  15486. + struct v4l2_ctrl_handler *hdl)
  15487. +{
  15488. + int c;
  15489. + const struct bm2835_mmal_v4l2_ctrl *ctrl;
  15490. +
  15491. + v4l2_ctrl_handler_init(hdl, V4L2_CTRL_COUNT);
  15492. +
  15493. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  15494. + ctrl = &v4l2_ctrls[c];
  15495. +
  15496. + switch (ctrl->type) {
  15497. + case MMAL_CONTROL_TYPE_STD:
  15498. + dev->ctrls[c] = v4l2_ctrl_new_std(hdl,
  15499. + &bm2835_mmal_ctrl_ops, ctrl->id,
  15500. + ctrl->min, ctrl->max, ctrl->step, ctrl->def);
  15501. + break;
  15502. +
  15503. + case MMAL_CONTROL_TYPE_STD_MENU:
  15504. + {
  15505. + int mask = ctrl->min;
  15506. +
  15507. + if (ctrl->id == V4L2_CID_SCENE_MODE) {
  15508. + /* Special handling to work out the mask
  15509. + * value based on the scene_configs array
  15510. + * at runtime. Reduces the chance of
  15511. + * mismatches.
  15512. + */
  15513. + int i;
  15514. + mask = 1<<V4L2_SCENE_MODE_NONE;
  15515. + for (i = 0;
  15516. + i < ARRAY_SIZE(scene_configs);
  15517. + i++) {
  15518. + mask |= 1<<scene_configs[i].v4l2_scene;
  15519. + }
  15520. + mask = ~mask;
  15521. + }
  15522. +
  15523. + dev->ctrls[c] = v4l2_ctrl_new_std_menu(hdl,
  15524. + &bm2835_mmal_ctrl_ops, ctrl->id,
  15525. + ctrl->max, mask, ctrl->def);
  15526. + break;
  15527. + }
  15528. +
  15529. + case MMAL_CONTROL_TYPE_INT_MENU:
  15530. + dev->ctrls[c] = v4l2_ctrl_new_int_menu(hdl,
  15531. + &bm2835_mmal_ctrl_ops, ctrl->id,
  15532. + ctrl->max, ctrl->def, ctrl->imenu);
  15533. + break;
  15534. +
  15535. + case MMAL_CONTROL_TYPE_CLUSTER:
  15536. + /* skip this entry when constructing controls */
  15537. + continue;
  15538. + }
  15539. +
  15540. + if (hdl->error)
  15541. + break;
  15542. +
  15543. + dev->ctrls[c]->priv = (void *)ctrl;
  15544. + }
  15545. +
  15546. + if (hdl->error) {
  15547. + pr_err("error adding control %d/%d id 0x%x\n", c,
  15548. + V4L2_CTRL_COUNT, ctrl->id);
  15549. + return hdl->error;
  15550. + }
  15551. +
  15552. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  15553. + ctrl = &v4l2_ctrls[c];
  15554. +
  15555. + switch (ctrl->type) {
  15556. + case MMAL_CONTROL_TYPE_CLUSTER:
  15557. + v4l2_ctrl_auto_cluster(ctrl->min,
  15558. + &dev->ctrls[c+1],
  15559. + ctrl->max,
  15560. + ctrl->def);
  15561. + break;
  15562. +
  15563. + case MMAL_CONTROL_TYPE_STD:
  15564. + case MMAL_CONTROL_TYPE_STD_MENU:
  15565. + case MMAL_CONTROL_TYPE_INT_MENU:
  15566. + break;
  15567. + }
  15568. +
  15569. + }
  15570. +
  15571. + return 0;
  15572. +}
  15573. diff -Nur linux-3.15.4/drivers/media/platform/bcm2835/Kconfig linux-rpi/drivers/media/platform/bcm2835/Kconfig
  15574. --- linux-3.15.4/drivers/media/platform/bcm2835/Kconfig 1970-01-01 01:00:00.000000000 +0100
  15575. +++ linux-rpi/drivers/media/platform/bcm2835/Kconfig 2014-04-13 17:32:57.000000000 +0200
  15576. @@ -0,0 +1,25 @@
  15577. +# Broadcom VideoCore IV v4l2 camera support
  15578. +
  15579. +config VIDEO_BCM2835
  15580. + bool "Broadcom BCM2835 camera interface driver"
  15581. + depends on VIDEO_V4L2 && ARCH_BCM2708
  15582. + ---help---
  15583. + Say Y here to enable camera host interface devices for
  15584. + Broadcom BCM2835 SoC. This operates over the VCHIQ interface
  15585. + to a service running on VideoCore.
  15586. +
  15587. +
  15588. +if VIDEO_BCM2835
  15589. +
  15590. +config VIDEO_BCM2835_MMAL
  15591. + tristate "Broadcom BM2835 MMAL camera interface driver"
  15592. + depends on BCM2708_VCHIQ
  15593. + select VIDEOBUF2_VMALLOC
  15594. + ---help---
  15595. + This is a V4L2 driver for the Broadcom BCM2835 MMAL camera host interface
  15596. +
  15597. + To compile this driver as a module, choose M here: the
  15598. + module will be called bcm2835-v4l2.o
  15599. +
  15600. +
  15601. +endif # VIDEO_BM2835
  15602. diff -Nur linux-3.15.4/drivers/media/platform/bcm2835/Makefile linux-rpi/drivers/media/platform/bcm2835/Makefile
  15603. --- linux-3.15.4/drivers/media/platform/bcm2835/Makefile 1970-01-01 01:00:00.000000000 +0100
  15604. +++ linux-rpi/drivers/media/platform/bcm2835/Makefile 2014-04-13 17:32:57.000000000 +0200
  15605. @@ -0,0 +1,5 @@
  15606. +bcm2835-v4l2-objs := bcm2835-camera.o controls.o mmal-vchiq.o
  15607. +
  15608. +obj-$(CONFIG_VIDEO_BCM2835_MMAL) += bcm2835-v4l2.o
  15609. +
  15610. +ccflags-$(CONFIG_VIDEO_BCM2835) += -Idrivers/misc/vc04_services -Idrivers/misc/vc04_services/interface/vcos/linuxkernel -D__VCCOREVER__=0x04000000
  15611. diff -Nur linux-3.15.4/drivers/media/platform/bcm2835/mmal-common.h linux-rpi/drivers/media/platform/bcm2835/mmal-common.h
  15612. --- linux-3.15.4/drivers/media/platform/bcm2835/mmal-common.h 1970-01-01 01:00:00.000000000 +0100
  15613. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-common.h 2014-04-13 17:32:57.000000000 +0200
  15614. @@ -0,0 +1,53 @@
  15615. +/*
  15616. + * Broadcom BM2835 V4L2 driver
  15617. + *
  15618. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  15619. + *
  15620. + * This file is subject to the terms and conditions of the GNU General Public
  15621. + * License. See the file COPYING in the main directory of this archive
  15622. + * for more details.
  15623. + *
  15624. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  15625. + * Dave Stevenson <dsteve@broadcom.com>
  15626. + * Simon Mellor <simellor@broadcom.com>
  15627. + * Luke Diamand <luked@broadcom.com>
  15628. + *
  15629. + * MMAL structures
  15630. + *
  15631. + */
  15632. +
  15633. +#define MMAL_FOURCC(a, b, c, d) ((a) | (b << 8) | (c << 16) | (d << 24))
  15634. +#define MMAL_MAGIC MMAL_FOURCC('m', 'm', 'a', 'l')
  15635. +
  15636. +/** Special value signalling that time is not known */
  15637. +#define MMAL_TIME_UNKNOWN (1LL<<63)
  15638. +
  15639. +/* mapping between v4l and mmal video modes */
  15640. +struct mmal_fmt {
  15641. + char *name;
  15642. + u32 fourcc; /* v4l2 format id */
  15643. + int flags; /* v4l2 flags field */
  15644. + u32 mmal;
  15645. + int depth;
  15646. + u32 mmal_component; /* MMAL component index to be used to encode */
  15647. +};
  15648. +
  15649. +/* buffer for one video frame */
  15650. +struct mmal_buffer {
  15651. + /* v4l buffer data -- must be first */
  15652. + struct vb2_buffer vb;
  15653. +
  15654. + /* list of buffers available */
  15655. + struct list_head list;
  15656. +
  15657. + void *buffer; /* buffer pointer */
  15658. + unsigned long buffer_size; /* size of allocated buffer */
  15659. +};
  15660. +
  15661. +/* */
  15662. +struct mmal_colourfx {
  15663. + s32 enable;
  15664. + u32 u;
  15665. + u32 v;
  15666. +};
  15667. +
  15668. diff -Nur linux-3.15.4/drivers/media/platform/bcm2835/mmal-encodings.h linux-rpi/drivers/media/platform/bcm2835/mmal-encodings.h
  15669. --- linux-3.15.4/drivers/media/platform/bcm2835/mmal-encodings.h 1970-01-01 01:00:00.000000000 +0100
  15670. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-encodings.h 2014-07-07 10:45:10.000000000 +0200
  15671. @@ -0,0 +1,127 @@
  15672. +/*
  15673. + * Broadcom BM2835 V4L2 driver
  15674. + *
  15675. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  15676. + *
  15677. + * This file is subject to the terms and conditions of the GNU General Public
  15678. + * License. See the file COPYING in the main directory of this archive
  15679. + * for more details.
  15680. + *
  15681. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  15682. + * Dave Stevenson <dsteve@broadcom.com>
  15683. + * Simon Mellor <simellor@broadcom.com>
  15684. + * Luke Diamand <luked@broadcom.com>
  15685. + */
  15686. +#ifndef MMAL_ENCODINGS_H
  15687. +#define MMAL_ENCODINGS_H
  15688. +
  15689. +#define MMAL_ENCODING_H264 MMAL_FOURCC('H', '2', '6', '4')
  15690. +#define MMAL_ENCODING_H263 MMAL_FOURCC('H', '2', '6', '3')
  15691. +#define MMAL_ENCODING_MP4V MMAL_FOURCC('M', 'P', '4', 'V')
  15692. +#define MMAL_ENCODING_MP2V MMAL_FOURCC('M', 'P', '2', 'V')
  15693. +#define MMAL_ENCODING_MP1V MMAL_FOURCC('M', 'P', '1', 'V')
  15694. +#define MMAL_ENCODING_WMV3 MMAL_FOURCC('W', 'M', 'V', '3')
  15695. +#define MMAL_ENCODING_WMV2 MMAL_FOURCC('W', 'M', 'V', '2')
  15696. +#define MMAL_ENCODING_WMV1 MMAL_FOURCC('W', 'M', 'V', '1')
  15697. +#define MMAL_ENCODING_WVC1 MMAL_FOURCC('W', 'V', 'C', '1')
  15698. +#define MMAL_ENCODING_VP8 MMAL_FOURCC('V', 'P', '8', ' ')
  15699. +#define MMAL_ENCODING_VP7 MMAL_FOURCC('V', 'P', '7', ' ')
  15700. +#define MMAL_ENCODING_VP6 MMAL_FOURCC('V', 'P', '6', ' ')
  15701. +#define MMAL_ENCODING_THEORA MMAL_FOURCC('T', 'H', 'E', 'O')
  15702. +#define MMAL_ENCODING_SPARK MMAL_FOURCC('S', 'P', 'R', 'K')
  15703. +#define MMAL_ENCODING_MJPEG MMAL_FOURCC('M', 'J', 'P', 'G')
  15704. +
  15705. +#define MMAL_ENCODING_JPEG MMAL_FOURCC('J', 'P', 'E', 'G')
  15706. +#define MMAL_ENCODING_GIF MMAL_FOURCC('G', 'I', 'F', ' ')
  15707. +#define MMAL_ENCODING_PNG MMAL_FOURCC('P', 'N', 'G', ' ')
  15708. +#define MMAL_ENCODING_PPM MMAL_FOURCC('P', 'P', 'M', ' ')
  15709. +#define MMAL_ENCODING_TGA MMAL_FOURCC('T', 'G', 'A', ' ')
  15710. +#define MMAL_ENCODING_BMP MMAL_FOURCC('B', 'M', 'P', ' ')
  15711. +
  15712. +#define MMAL_ENCODING_I420 MMAL_FOURCC('I', '4', '2', '0')
  15713. +#define MMAL_ENCODING_I420_SLICE MMAL_FOURCC('S', '4', '2', '0')
  15714. +#define MMAL_ENCODING_YV12 MMAL_FOURCC('Y', 'V', '1', '2')
  15715. +#define MMAL_ENCODING_I422 MMAL_FOURCC('I', '4', '2', '2')
  15716. +#define MMAL_ENCODING_I422_SLICE MMAL_FOURCC('S', '4', '2', '2')
  15717. +#define MMAL_ENCODING_YUYV MMAL_FOURCC('Y', 'U', 'Y', 'V')
  15718. +#define MMAL_ENCODING_YVYU MMAL_FOURCC('Y', 'V', 'Y', 'U')
  15719. +#define MMAL_ENCODING_UYVY MMAL_FOURCC('U', 'Y', 'V', 'Y')
  15720. +#define MMAL_ENCODING_VYUY MMAL_FOURCC('V', 'Y', 'U', 'Y')
  15721. +#define MMAL_ENCODING_NV12 MMAL_FOURCC('N', 'V', '1', '2')
  15722. +#define MMAL_ENCODING_NV21 MMAL_FOURCC('N', 'V', '2', '1')
  15723. +#define MMAL_ENCODING_ARGB MMAL_FOURCC('A', 'R', 'G', 'B')
  15724. +#define MMAL_ENCODING_RGBA MMAL_FOURCC('R', 'G', 'B', 'A')
  15725. +#define MMAL_ENCODING_ABGR MMAL_FOURCC('A', 'B', 'G', 'R')
  15726. +#define MMAL_ENCODING_BGRA MMAL_FOURCC('B', 'G', 'R', 'A')
  15727. +#define MMAL_ENCODING_RGB16 MMAL_FOURCC('R', 'G', 'B', '2')
  15728. +#define MMAL_ENCODING_RGB24 MMAL_FOURCC('R', 'G', 'B', '3')
  15729. +#define MMAL_ENCODING_RGB32 MMAL_FOURCC('R', 'G', 'B', '4')
  15730. +#define MMAL_ENCODING_BGR16 MMAL_FOURCC('B', 'G', 'R', '2')
  15731. +#define MMAL_ENCODING_BGR24 MMAL_FOURCC('B', 'G', 'R', '3')
  15732. +#define MMAL_ENCODING_BGR32 MMAL_FOURCC('B', 'G', 'R', '4')
  15733. +
  15734. +/** SAND Video (YUVUV128) format, native format understood by VideoCore.
  15735. + * This format is *not* opaque - if requested you will receive full frames
  15736. + * of YUV_UV video.
  15737. + */
  15738. +#define MMAL_ENCODING_YUVUV128 MMAL_FOURCC('S', 'A', 'N', 'D')
  15739. +
  15740. +/** VideoCore opaque image format, image handles are returned to
  15741. + * the host but not the actual image data.
  15742. + */
  15743. +#define MMAL_ENCODING_OPAQUE MMAL_FOURCC('O', 'P', 'Q', 'V')
  15744. +
  15745. +/** An EGL image handle
  15746. + */
  15747. +#define MMAL_ENCODING_EGL_IMAGE MMAL_FOURCC('E', 'G', 'L', 'I')
  15748. +
  15749. +/* }@ */
  15750. +
  15751. +/** \name Pre-defined audio encodings */
  15752. +/* @{ */
  15753. +#define MMAL_ENCODING_PCM_UNSIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'U')
  15754. +#define MMAL_ENCODING_PCM_UNSIGNED_LE MMAL_FOURCC('p', 'c', 'm', 'u')
  15755. +#define MMAL_ENCODING_PCM_SIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'S')
  15756. +#define MMAL_ENCODING_PCM_SIGNED_LE MMAL_FOURCC('p', 'c', 'm', 's')
  15757. +#define MMAL_ENCODING_PCM_FLOAT_BE MMAL_FOURCC('P', 'C', 'M', 'F')
  15758. +#define MMAL_ENCODING_PCM_FLOAT_LE MMAL_FOURCC('p', 'c', 'm', 'f')
  15759. +
  15760. +/* Pre-defined H264 encoding variants */
  15761. +
  15762. +/** ISO 14496-10 Annex B byte stream format */
  15763. +#define MMAL_ENCODING_VARIANT_H264_DEFAULT 0
  15764. +/** ISO 14496-15 AVC stream format */
  15765. +#define MMAL_ENCODING_VARIANT_H264_AVC1 MMAL_FOURCC('A', 'V', 'C', '1')
  15766. +/** Implicitly delineated NAL units without emulation prevention */
  15767. +#define MMAL_ENCODING_VARIANT_H264_RAW MMAL_FOURCC('R', 'A', 'W', ' ')
  15768. +
  15769. +
  15770. +/** \defgroup MmalColorSpace List of pre-defined video color spaces
  15771. + * This defines a list of common color spaces. This list isn't exhaustive and
  15772. + * is only provided as a convenience to avoid clients having to use FourCC
  15773. + * codes directly. However components are allowed to define and use their own
  15774. + * FourCC codes.
  15775. + */
  15776. +/* @{ */
  15777. +
  15778. +/** Unknown color space */
  15779. +#define MMAL_COLOR_SPACE_UNKNOWN 0
  15780. +/** ITU-R BT.601-5 [SDTV] */
  15781. +#define MMAL_COLOR_SPACE_ITUR_BT601 MMAL_FOURCC('Y', '6', '0', '1')
  15782. +/** ITU-R BT.709-3 [HDTV] */
  15783. +#define MMAL_COLOR_SPACE_ITUR_BT709 MMAL_FOURCC('Y', '7', '0', '9')
  15784. +/** JPEG JFIF */
  15785. +#define MMAL_COLOR_SPACE_JPEG_JFIF MMAL_FOURCC('Y', 'J', 'F', 'I')
  15786. +/** Title 47 Code of Federal Regulations (2003) 73.682 (a) (20) */
  15787. +#define MMAL_COLOR_SPACE_FCC MMAL_FOURCC('Y', 'F', 'C', 'C')
  15788. +/** Society of Motion Picture and Television Engineers 240M (1999) */
  15789. +#define MMAL_COLOR_SPACE_SMPTE240M MMAL_FOURCC('Y', '2', '4', '0')
  15790. +/** ITU-R BT.470-2 System M */
  15791. +#define MMAL_COLOR_SPACE_BT470_2_M MMAL_FOURCC('Y', '_', '_', 'M')
  15792. +/** ITU-R BT.470-2 System BG */
  15793. +#define MMAL_COLOR_SPACE_BT470_2_BG MMAL_FOURCC('Y', '_', 'B', 'G')
  15794. +/** JPEG JFIF, but with 16..255 luma */
  15795. +#define MMAL_COLOR_SPACE_JFIF_Y16_255 MMAL_FOURCC('Y', 'Y', '1', '6')
  15796. +/* @} MmalColorSpace List */
  15797. +
  15798. +#endif /* MMAL_ENCODINGS_H */
  15799. diff -Nur linux-3.15.4/drivers/media/platform/bcm2835/mmal-msg-common.h linux-rpi/drivers/media/platform/bcm2835/mmal-msg-common.h
  15800. --- linux-3.15.4/drivers/media/platform/bcm2835/mmal-msg-common.h 1970-01-01 01:00:00.000000000 +0100
  15801. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-msg-common.h 2014-04-13 17:32:57.000000000 +0200
  15802. @@ -0,0 +1,50 @@
  15803. +/*
  15804. + * Broadcom BM2835 V4L2 driver
  15805. + *
  15806. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  15807. + *
  15808. + * This file is subject to the terms and conditions of the GNU General Public
  15809. + * License. See the file COPYING in the main directory of this archive
  15810. + * for more details.
  15811. + *
  15812. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  15813. + * Dave Stevenson <dsteve@broadcom.com>
  15814. + * Simon Mellor <simellor@broadcom.com>
  15815. + * Luke Diamand <luked@broadcom.com>
  15816. + */
  15817. +
  15818. +#ifndef MMAL_MSG_COMMON_H
  15819. +#define MMAL_MSG_COMMON_H
  15820. +
  15821. +enum mmal_msg_status {
  15822. + MMAL_MSG_STATUS_SUCCESS = 0, /**< Success */
  15823. + MMAL_MSG_STATUS_ENOMEM, /**< Out of memory */
  15824. + MMAL_MSG_STATUS_ENOSPC, /**< Out of resources other than memory */
  15825. + MMAL_MSG_STATUS_EINVAL, /**< Argument is invalid */
  15826. + MMAL_MSG_STATUS_ENOSYS, /**< Function not implemented */
  15827. + MMAL_MSG_STATUS_ENOENT, /**< No such file or directory */
  15828. + MMAL_MSG_STATUS_ENXIO, /**< No such device or address */
  15829. + MMAL_MSG_STATUS_EIO, /**< I/O error */
  15830. + MMAL_MSG_STATUS_ESPIPE, /**< Illegal seek */
  15831. + MMAL_MSG_STATUS_ECORRUPT, /**< Data is corrupt \attention */
  15832. + MMAL_MSG_STATUS_ENOTREADY, /**< Component is not ready */
  15833. + MMAL_MSG_STATUS_ECONFIG, /**< Component is not configured */
  15834. + MMAL_MSG_STATUS_EISCONN, /**< Port is already connected */
  15835. + MMAL_MSG_STATUS_ENOTCONN, /**< Port is disconnected */
  15836. + MMAL_MSG_STATUS_EAGAIN, /**< Resource temporarily unavailable. */
  15837. + MMAL_MSG_STATUS_EFAULT, /**< Bad address */
  15838. +};
  15839. +
  15840. +struct mmal_rect {
  15841. + s32 x; /**< x coordinate (from left) */
  15842. + s32 y; /**< y coordinate (from top) */
  15843. + s32 width; /**< width */
  15844. + s32 height; /**< height */
  15845. +};
  15846. +
  15847. +struct mmal_rational {
  15848. + s32 num; /**< Numerator */
  15849. + s32 den; /**< Denominator */
  15850. +};
  15851. +
  15852. +#endif /* MMAL_MSG_COMMON_H */
  15853. diff -Nur linux-3.15.4/drivers/media/platform/bcm2835/mmal-msg-format.h linux-rpi/drivers/media/platform/bcm2835/mmal-msg-format.h
  15854. --- linux-3.15.4/drivers/media/platform/bcm2835/mmal-msg-format.h 1970-01-01 01:00:00.000000000 +0100
  15855. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-msg-format.h 2014-04-13 17:32:57.000000000 +0200
  15856. @@ -0,0 +1,81 @@
  15857. +/*
  15858. + * Broadcom BM2835 V4L2 driver
  15859. + *
  15860. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  15861. + *
  15862. + * This file is subject to the terms and conditions of the GNU General Public
  15863. + * License. See the file COPYING in the main directory of this archive
  15864. + * for more details.
  15865. + *
  15866. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  15867. + * Dave Stevenson <dsteve@broadcom.com>
  15868. + * Simon Mellor <simellor@broadcom.com>
  15869. + * Luke Diamand <luked@broadcom.com>
  15870. + */
  15871. +
  15872. +#ifndef MMAL_MSG_FORMAT_H
  15873. +#define MMAL_MSG_FORMAT_H
  15874. +
  15875. +#include "mmal-msg-common.h"
  15876. +
  15877. +/* MMAL_ES_FORMAT_T */
  15878. +
  15879. +
  15880. +struct mmal_audio_format {
  15881. + u32 channels; /**< Number of audio channels */
  15882. + u32 sample_rate; /**< Sample rate */
  15883. +
  15884. + u32 bits_per_sample; /**< Bits per sample */
  15885. + u32 block_align; /**< Size of a block of data */
  15886. +};
  15887. +
  15888. +struct mmal_video_format {
  15889. + u32 width; /**< Width of frame in pixels */
  15890. + u32 height; /**< Height of frame in rows of pixels */
  15891. + struct mmal_rect crop; /**< Visible region of the frame */
  15892. + struct mmal_rational frame_rate; /**< Frame rate */
  15893. + struct mmal_rational par; /**< Pixel aspect ratio */
  15894. +
  15895. + /* FourCC specifying the color space of the video stream. See the
  15896. + * \ref MmalColorSpace "pre-defined color spaces" for some examples.
  15897. + */
  15898. + u32 color_space;
  15899. +};
  15900. +
  15901. +struct mmal_subpicture_format {
  15902. + u32 x_offset;
  15903. + u32 y_offset;
  15904. +};
  15905. +
  15906. +union mmal_es_specific_format {
  15907. + struct mmal_audio_format audio;
  15908. + struct mmal_video_format video;
  15909. + struct mmal_subpicture_format subpicture;
  15910. +};
  15911. +
  15912. +/** Definition of an elementary stream format (MMAL_ES_FORMAT_T) */
  15913. +struct mmal_es_format {
  15914. + u32 type; /* enum mmal_es_type */
  15915. +
  15916. + u32 encoding; /* FourCC specifying encoding of the elementary stream.*/
  15917. + u32 encoding_variant; /* FourCC specifying the specific
  15918. + * encoding variant of the elementary
  15919. + * stream.
  15920. + */
  15921. +
  15922. + union mmal_es_specific_format *es; /* TODO: pointers in
  15923. + * message serialisation?!?
  15924. + */
  15925. + /* Type specific
  15926. + * information for the
  15927. + * elementary stream
  15928. + */
  15929. +
  15930. + u32 bitrate; /**< Bitrate in bits per second */
  15931. + u32 flags; /**< Flags describing properties of the elementary stream. */
  15932. +
  15933. + u32 extradata_size; /**< Size of the codec specific data */
  15934. + u8 *extradata; /**< Codec specific data */
  15935. +};
  15936. +
  15937. +#endif /* MMAL_MSG_FORMAT_H */
  15938. diff -Nur linux-3.15.4/drivers/media/platform/bcm2835/mmal-msg.h linux-rpi/drivers/media/platform/bcm2835/mmal-msg.h
  15939. --- linux-3.15.4/drivers/media/platform/bcm2835/mmal-msg.h 1970-01-01 01:00:00.000000000 +0100
  15940. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-msg.h 2014-04-13 17:32:57.000000000 +0200
  15941. @@ -0,0 +1,404 @@
  15942. +/*
  15943. + * Broadcom BM2835 V4L2 driver
  15944. + *
  15945. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  15946. + *
  15947. + * This file is subject to the terms and conditions of the GNU General Public
  15948. + * License. See the file COPYING in the main directory of this archive
  15949. + * for more details.
  15950. + *
  15951. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  15952. + * Dave Stevenson <dsteve@broadcom.com>
  15953. + * Simon Mellor <simellor@broadcom.com>
  15954. + * Luke Diamand <luked@broadcom.com>
  15955. + */
  15956. +
  15957. +/* all the data structures which serialise the MMAL protocol. note
  15958. + * these are directly mapped onto the recived message data.
  15959. + *
  15960. + * BEWARE: They seem to *assume* pointers are u32 and that there is no
  15961. + * structure padding!
  15962. + *
  15963. + * NOTE: this implementation uses kernel types to ensure sizes. Rather
  15964. + * than assigning values to enums to force their size the
  15965. + * implementation uses fixed size types and not the enums (though the
  15966. + * comments have the actual enum type
  15967. + */
  15968. +
  15969. +#define VC_MMAL_VER 15
  15970. +#define VC_MMAL_MIN_VER 10
  15971. +#define VC_MMAL_SERVER_NAME MAKE_FOURCC("mmal")
  15972. +
  15973. +/* max total message size is 512 bytes */
  15974. +#define MMAL_MSG_MAX_SIZE 512
  15975. +/* with six 32bit header elements max payload is therefore 488 bytes */
  15976. +#define MMAL_MSG_MAX_PAYLOAD 488
  15977. +
  15978. +#include "mmal-msg-common.h"
  15979. +#include "mmal-msg-format.h"
  15980. +#include "mmal-msg-port.h"
  15981. +
  15982. +enum mmal_msg_type {
  15983. + MMAL_MSG_TYPE_QUIT = 1,
  15984. + MMAL_MSG_TYPE_SERVICE_CLOSED,
  15985. + MMAL_MSG_TYPE_GET_VERSION,
  15986. + MMAL_MSG_TYPE_COMPONENT_CREATE,
  15987. + MMAL_MSG_TYPE_COMPONENT_DESTROY, /* 5 */
  15988. + MMAL_MSG_TYPE_COMPONENT_ENABLE,
  15989. + MMAL_MSG_TYPE_COMPONENT_DISABLE,
  15990. + MMAL_MSG_TYPE_PORT_INFO_GET,
  15991. + MMAL_MSG_TYPE_PORT_INFO_SET,
  15992. + MMAL_MSG_TYPE_PORT_ACTION, /* 10 */
  15993. + MMAL_MSG_TYPE_BUFFER_FROM_HOST,
  15994. + MMAL_MSG_TYPE_BUFFER_TO_HOST,
  15995. + MMAL_MSG_TYPE_GET_STATS,
  15996. + MMAL_MSG_TYPE_PORT_PARAMETER_SET,
  15997. + MMAL_MSG_TYPE_PORT_PARAMETER_GET, /* 15 */
  15998. + MMAL_MSG_TYPE_EVENT_TO_HOST,
  15999. + MMAL_MSG_TYPE_GET_CORE_STATS_FOR_PORT,
  16000. + MMAL_MSG_TYPE_OPAQUE_ALLOCATOR,
  16001. + MMAL_MSG_TYPE_CONSUME_MEM,
  16002. + MMAL_MSG_TYPE_LMK, /* 20 */
  16003. + MMAL_MSG_TYPE_OPAQUE_ALLOCATOR_DESC,
  16004. + MMAL_MSG_TYPE_DRM_GET_LHS32,
  16005. + MMAL_MSG_TYPE_DRM_GET_TIME,
  16006. + MMAL_MSG_TYPE_BUFFER_FROM_HOST_ZEROLEN,
  16007. + MMAL_MSG_TYPE_PORT_FLUSH, /* 25 */
  16008. + MMAL_MSG_TYPE_HOST_LOG,
  16009. + MMAL_MSG_TYPE_MSG_LAST
  16010. +};
  16011. +
  16012. +/* port action request messages differ depending on the action type */
  16013. +enum mmal_msg_port_action_type {
  16014. + MMAL_MSG_PORT_ACTION_TYPE_UNKNOWN = 0, /* Unkown action */
  16015. + MMAL_MSG_PORT_ACTION_TYPE_ENABLE, /* Enable a port */
  16016. + MMAL_MSG_PORT_ACTION_TYPE_DISABLE, /* Disable a port */
  16017. + MMAL_MSG_PORT_ACTION_TYPE_FLUSH, /* Flush a port */
  16018. + MMAL_MSG_PORT_ACTION_TYPE_CONNECT, /* Connect ports */
  16019. + MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT, /* Disconnect ports */
  16020. + MMAL_MSG_PORT_ACTION_TYPE_SET_REQUIREMENTS, /* Set buffer requirements*/
  16021. +};
  16022. +
  16023. +struct mmal_msg_header {
  16024. + u32 magic;
  16025. + u32 type; /** enum mmal_msg_type */
  16026. +
  16027. + /* Opaque handle to the control service */
  16028. + struct mmal_control_service *control_service;
  16029. +
  16030. + struct mmal_msg_context *context; /** a u32 per message context */
  16031. + u32 status; /** The status of the vchiq operation */
  16032. + u32 padding;
  16033. +};
  16034. +
  16035. +/* Send from VC to host to report version */
  16036. +struct mmal_msg_version {
  16037. + u32 flags;
  16038. + u32 major;
  16039. + u32 minor;
  16040. + u32 minimum;
  16041. +};
  16042. +
  16043. +/* request to VC to create component */
  16044. +struct mmal_msg_component_create {
  16045. + void *client_component; /* component context */
  16046. + char name[128];
  16047. + u32 pid; /* For debug */
  16048. +};
  16049. +
  16050. +/* reply from VC to component creation request */
  16051. +struct mmal_msg_component_create_reply {
  16052. + u32 status; /** enum mmal_msg_status - how does this differ to
  16053. + * the one in the header?
  16054. + */
  16055. + u32 component_handle; /* VideoCore handle for component */
  16056. + u32 input_num; /* Number of input ports */
  16057. + u32 output_num; /* Number of output ports */
  16058. + u32 clock_num; /* Number of clock ports */
  16059. +};
  16060. +
  16061. +/* request to VC to destroy a component */
  16062. +struct mmal_msg_component_destroy {
  16063. + u32 component_handle;
  16064. +};
  16065. +
  16066. +struct mmal_msg_component_destroy_reply {
  16067. + u32 status; /** The component destruction status */
  16068. +};
  16069. +
  16070. +
  16071. +/* request and reply to VC to enable a component */
  16072. +struct mmal_msg_component_enable {
  16073. + u32 component_handle;
  16074. +};
  16075. +
  16076. +struct mmal_msg_component_enable_reply {
  16077. + u32 status; /** The component enable status */
  16078. +};
  16079. +
  16080. +
  16081. +/* request and reply to VC to disable a component */
  16082. +struct mmal_msg_component_disable {
  16083. + u32 component_handle;
  16084. +};
  16085. +
  16086. +struct mmal_msg_component_disable_reply {
  16087. + u32 status; /** The component disable status */
  16088. +};
  16089. +
  16090. +/* request to VC to get port information */
  16091. +struct mmal_msg_port_info_get {
  16092. + u32 component_handle; /* component handle port is associated with */
  16093. + u32 port_type; /* enum mmal_msg_port_type */
  16094. + u32 index; /* port index to query */
  16095. +};
  16096. +
  16097. +/* reply from VC to get port info request */
  16098. +struct mmal_msg_port_info_get_reply {
  16099. + u32 status; /** enum mmal_msg_status */
  16100. + u32 component_handle; /* component handle port is associated with */
  16101. + u32 port_type; /* enum mmal_msg_port_type */
  16102. + u32 port_index; /* port indexed in query */
  16103. + s32 found; /* unused */
  16104. + u32 port_handle; /**< Handle to use for this port */
  16105. + struct mmal_port port;
  16106. + struct mmal_es_format format; /* elementry stream format */
  16107. + union mmal_es_specific_format es; /* es type specific data */
  16108. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE]; /* es extra data */
  16109. +};
  16110. +
  16111. +/* request to VC to set port information */
  16112. +struct mmal_msg_port_info_set {
  16113. + u32 component_handle;
  16114. + u32 port_type; /* enum mmal_msg_port_type */
  16115. + u32 port_index; /* port indexed in query */
  16116. + struct mmal_port port;
  16117. + struct mmal_es_format format;
  16118. + union mmal_es_specific_format es;
  16119. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
  16120. +};
  16121. +
  16122. +/* reply from VC to port info set request */
  16123. +struct mmal_msg_port_info_set_reply {
  16124. + u32 status;
  16125. + u32 component_handle; /* component handle port is associated with */
  16126. + u32 port_type; /* enum mmal_msg_port_type */
  16127. + u32 index; /* port indexed in query */
  16128. + s32 found; /* unused */
  16129. + u32 port_handle; /**< Handle to use for this port */
  16130. + struct mmal_port port;
  16131. + struct mmal_es_format format;
  16132. + union mmal_es_specific_format es;
  16133. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
  16134. +};
  16135. +
  16136. +
  16137. +/* port action requests that take a mmal_port as a parameter */
  16138. +struct mmal_msg_port_action_port {
  16139. + u32 component_handle;
  16140. + u32 port_handle;
  16141. + u32 action; /* enum mmal_msg_port_action_type */
  16142. + struct mmal_port port;
  16143. +};
  16144. +
  16145. +/* port action requests that take handles as a parameter */
  16146. +struct mmal_msg_port_action_handle {
  16147. + u32 component_handle;
  16148. + u32 port_handle;
  16149. + u32 action; /* enum mmal_msg_port_action_type */
  16150. + u32 connect_component_handle;
  16151. + u32 connect_port_handle;
  16152. +};
  16153. +
  16154. +struct mmal_msg_port_action_reply {
  16155. + u32 status; /** The port action operation status */
  16156. +};
  16157. +
  16158. +
  16159. +
  16160. +
  16161. +/* MMAL buffer transfer */
  16162. +
  16163. +/** Size of space reserved in a buffer message for short messages. */
  16164. +#define MMAL_VC_SHORT_DATA 128
  16165. +
  16166. +/** Signals that the current payload is the end of the stream of data */
  16167. +#define MMAL_BUFFER_HEADER_FLAG_EOS (1<<0)
  16168. +/** Signals that the start of the current payload starts a frame */
  16169. +#define MMAL_BUFFER_HEADER_FLAG_FRAME_START (1<<1)
  16170. +/** Signals that the end of the current payload ends a frame */
  16171. +#define MMAL_BUFFER_HEADER_FLAG_FRAME_END (1<<2)
  16172. +/** Signals that the current payload contains only complete frames (>1) */
  16173. +#define MMAL_BUFFER_HEADER_FLAG_FRAME \
  16174. + (MMAL_BUFFER_HEADER_FLAG_FRAME_START|MMAL_BUFFER_HEADER_FLAG_FRAME_END)
  16175. +/** Signals that the current payload is a keyframe (i.e. self decodable) */
  16176. +#define MMAL_BUFFER_HEADER_FLAG_KEYFRAME (1<<3)
  16177. +/** Signals a discontinuity in the stream of data (e.g. after a seek).
  16178. + * Can be used for instance by a decoder to reset its state */
  16179. +#define MMAL_BUFFER_HEADER_FLAG_DISCONTINUITY (1<<4)
  16180. +/** Signals a buffer containing some kind of config data for the component
  16181. + * (e.g. codec config data) */
  16182. +#define MMAL_BUFFER_HEADER_FLAG_CONFIG (1<<5)
  16183. +/** Signals an encrypted payload */
  16184. +#define MMAL_BUFFER_HEADER_FLAG_ENCRYPTED (1<<6)
  16185. +/** Signals a buffer containing side information */
  16186. +#define MMAL_BUFFER_HEADER_FLAG_CODECSIDEINFO (1<<7)
  16187. +/** Signals a buffer which is the snapshot/postview image from a stills
  16188. + * capture
  16189. + */
  16190. +#define MMAL_BUFFER_HEADER_FLAGS_SNAPSHOT (1<<8)
  16191. +/** Signals a buffer which contains data known to be corrupted */
  16192. +#define MMAL_BUFFER_HEADER_FLAG_CORRUPTED (1<<9)
  16193. +/** Signals that a buffer failed to be transmitted */
  16194. +#define MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED (1<<10)
  16195. +
  16196. +struct mmal_driver_buffer {
  16197. + u32 magic;
  16198. + u32 component_handle;
  16199. + u32 port_handle;
  16200. + void *client_context;
  16201. +};
  16202. +
  16203. +/* buffer header */
  16204. +struct mmal_buffer_header {
  16205. + struct mmal_buffer_header *next; /* next header */
  16206. + void *priv; /* framework private data */
  16207. + u32 cmd;
  16208. + void *data;
  16209. + u32 alloc_size;
  16210. + u32 length;
  16211. + u32 offset;
  16212. + u32 flags;
  16213. + s64 pts;
  16214. + s64 dts;
  16215. + void *type;
  16216. + void *user_data;
  16217. +};
  16218. +
  16219. +struct mmal_buffer_header_type_specific {
  16220. + union {
  16221. + struct {
  16222. + u32 planes;
  16223. + u32 offset[4];
  16224. + u32 pitch[4];
  16225. + u32 flags;
  16226. + } video;
  16227. + } u;
  16228. +};
  16229. +
  16230. +struct mmal_msg_buffer_from_host {
  16231. + /* The front 32 bytes of the buffer header are copied
  16232. + * back to us in the reply to allow for context. This
  16233. + * area is used to store two mmal_driver_buffer structures to
  16234. + * allow for multiple concurrent service users.
  16235. + */
  16236. + /* control data */
  16237. + struct mmal_driver_buffer drvbuf;
  16238. +
  16239. + /* referenced control data for passthrough buffer management */
  16240. + struct mmal_driver_buffer drvbuf_ref;
  16241. + struct mmal_buffer_header buffer_header; /* buffer header itself */
  16242. + struct mmal_buffer_header_type_specific buffer_header_type_specific;
  16243. + s32 is_zero_copy;
  16244. + s32 has_reference;
  16245. +
  16246. + /** allows short data to be xfered in control message */
  16247. + u32 payload_in_message;
  16248. + u8 short_data[MMAL_VC_SHORT_DATA];
  16249. +};
  16250. +
  16251. +
  16252. +/* port parameter setting */
  16253. +
  16254. +#define MMAL_WORKER_PORT_PARAMETER_SPACE 96
  16255. +
  16256. +struct mmal_msg_port_parameter_set {
  16257. + u32 component_handle; /* component */
  16258. + u32 port_handle; /* port */
  16259. + u32 id; /* Parameter ID */
  16260. + u32 size; /* Parameter size */
  16261. + uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
  16262. +};
  16263. +
  16264. +struct mmal_msg_port_parameter_set_reply {
  16265. + u32 status; /** enum mmal_msg_status todo: how does this
  16266. + * differ to the one in the header?
  16267. + */
  16268. +};
  16269. +
  16270. +/* port parameter getting */
  16271. +
  16272. +struct mmal_msg_port_parameter_get {
  16273. + u32 component_handle; /* component */
  16274. + u32 port_handle; /* port */
  16275. + u32 id; /* Parameter ID */
  16276. + u32 size; /* Parameter size */
  16277. +};
  16278. +
  16279. +struct mmal_msg_port_parameter_get_reply {
  16280. + u32 status; /* Status of mmal_port_parameter_get call */
  16281. + u32 id; /* Parameter ID */
  16282. + u32 size; /* Parameter size */
  16283. + uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
  16284. +};
  16285. +
  16286. +/* event messages */
  16287. +#define MMAL_WORKER_EVENT_SPACE 256
  16288. +
  16289. +struct mmal_msg_event_to_host {
  16290. + void *client_component; /* component context */
  16291. +
  16292. + u32 port_type;
  16293. + u32 port_num;
  16294. +
  16295. + u32 cmd;
  16296. + u32 length;
  16297. + u8 data[MMAL_WORKER_EVENT_SPACE];
  16298. + struct mmal_buffer_header *delayed_buffer;
  16299. +};
  16300. +
  16301. +/* all mmal messages are serialised through this structure */
  16302. +struct mmal_msg {
  16303. + /* header */
  16304. + struct mmal_msg_header h;
  16305. + /* payload */
  16306. + union {
  16307. + struct mmal_msg_version version;
  16308. +
  16309. + struct mmal_msg_component_create component_create;
  16310. + struct mmal_msg_component_create_reply component_create_reply;
  16311. +
  16312. + struct mmal_msg_component_destroy component_destroy;
  16313. + struct mmal_msg_component_destroy_reply component_destroy_reply;
  16314. +
  16315. + struct mmal_msg_component_enable component_enable;
  16316. + struct mmal_msg_component_enable_reply component_enable_reply;
  16317. +
  16318. + struct mmal_msg_component_disable component_disable;
  16319. + struct mmal_msg_component_disable_reply component_disable_reply;
  16320. +
  16321. + struct mmal_msg_port_info_get port_info_get;
  16322. + struct mmal_msg_port_info_get_reply port_info_get_reply;
  16323. +
  16324. + struct mmal_msg_port_info_set port_info_set;
  16325. + struct mmal_msg_port_info_set_reply port_info_set_reply;
  16326. +
  16327. + struct mmal_msg_port_action_port port_action_port;
  16328. + struct mmal_msg_port_action_handle port_action_handle;
  16329. + struct mmal_msg_port_action_reply port_action_reply;
  16330. +
  16331. + struct mmal_msg_buffer_from_host buffer_from_host;
  16332. +
  16333. + struct mmal_msg_port_parameter_set port_parameter_set;
  16334. + struct mmal_msg_port_parameter_set_reply
  16335. + port_parameter_set_reply;
  16336. + struct mmal_msg_port_parameter_get
  16337. + port_parameter_get;
  16338. + struct mmal_msg_port_parameter_get_reply
  16339. + port_parameter_get_reply;
  16340. +
  16341. + struct mmal_msg_event_to_host event_to_host;
  16342. +
  16343. + u8 payload[MMAL_MSG_MAX_PAYLOAD];
  16344. + } u;
  16345. +};
  16346. diff -Nur linux-3.15.4/drivers/media/platform/bcm2835/mmal-msg-port.h linux-rpi/drivers/media/platform/bcm2835/mmal-msg-port.h
  16347. --- linux-3.15.4/drivers/media/platform/bcm2835/mmal-msg-port.h 1970-01-01 01:00:00.000000000 +0100
  16348. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-msg-port.h 2014-04-13 17:32:57.000000000 +0200
  16349. @@ -0,0 +1,107 @@
  16350. +/*
  16351. + * Broadcom BM2835 V4L2 driver
  16352. + *
  16353. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  16354. + *
  16355. + * This file is subject to the terms and conditions of the GNU General Public
  16356. + * License. See the file COPYING in the main directory of this archive
  16357. + * for more details.
  16358. + *
  16359. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  16360. + * Dave Stevenson <dsteve@broadcom.com>
  16361. + * Simon Mellor <simellor@broadcom.com>
  16362. + * Luke Diamand <luked@broadcom.com>
  16363. + */
  16364. +
  16365. +/* MMAL_PORT_TYPE_T */
  16366. +enum mmal_port_type {
  16367. + MMAL_PORT_TYPE_UNKNOWN = 0, /**< Unknown port type */
  16368. + MMAL_PORT_TYPE_CONTROL, /**< Control port */
  16369. + MMAL_PORT_TYPE_INPUT, /**< Input port */
  16370. + MMAL_PORT_TYPE_OUTPUT, /**< Output port */
  16371. + MMAL_PORT_TYPE_CLOCK, /**< Clock port */
  16372. +};
  16373. +
  16374. +/** The port is pass-through and doesn't need buffer headers allocated */
  16375. +#define MMAL_PORT_CAPABILITY_PASSTHROUGH 0x01
  16376. +/** The port wants to allocate the buffer payloads.
  16377. + * This signals a preference that payload allocation should be done
  16378. + * on this port for efficiency reasons. */
  16379. +#define MMAL_PORT_CAPABILITY_ALLOCATION 0x02
  16380. +/** The port supports format change events.
  16381. + * This applies to input ports and is used to let the client know
  16382. + * whether the port supports being reconfigured via a format
  16383. + * change event (i.e. without having to disable the port). */
  16384. +#define MMAL_PORT_CAPABILITY_SUPPORTS_EVENT_FORMAT_CHANGE 0x04
  16385. +
  16386. +/* mmal port structure (MMAL_PORT_T)
  16387. + *
  16388. + * most elements are informational only, the pointer values for
  16389. + * interogation messages are generally provided as additional
  16390. + * strucures within the message. When used to set values only teh
  16391. + * buffer_num, buffer_size and userdata parameters are writable.
  16392. + */
  16393. +struct mmal_port {
  16394. + void *priv; /* Private member used by the framework */
  16395. + const char *name; /* Port name. Used for debugging purposes (RO) */
  16396. +
  16397. + u32 type; /* Type of the port (RO) enum mmal_port_type */
  16398. + u16 index; /* Index of the port in its type list (RO) */
  16399. + u16 index_all; /* Index of the port in the list of all ports (RO) */
  16400. +
  16401. + u32 is_enabled; /* Indicates whether the port is enabled or not (RO) */
  16402. + struct mmal_es_format *format; /* Format of the elementary stream */
  16403. +
  16404. + u32 buffer_num_min; /* Minimum number of buffers the port
  16405. + * requires (RO). This is set by the
  16406. + * component.
  16407. + */
  16408. +
  16409. + u32 buffer_size_min; /* Minimum size of buffers the port
  16410. + * requires (RO). This is set by the
  16411. + * component.
  16412. + */
  16413. +
  16414. + u32 buffer_alignment_min; /* Minimum alignment requirement for
  16415. + * the buffers (RO). A value of
  16416. + * zero means no special alignment
  16417. + * requirements. This is set by the
  16418. + * component.
  16419. + */
  16420. +
  16421. + u32 buffer_num_recommended; /* Number of buffers the port
  16422. + * recommends for optimal
  16423. + * performance (RO). A value of
  16424. + * zero means no special
  16425. + * recommendation. This is set
  16426. + * by the component.
  16427. + */
  16428. +
  16429. + u32 buffer_size_recommended; /* Size of buffers the port
  16430. + * recommends for optimal
  16431. + * performance (RO). A value of
  16432. + * zero means no special
  16433. + * recommendation. This is set
  16434. + * by the component.
  16435. + */
  16436. +
  16437. + u32 buffer_num; /* Actual number of buffers the port will use.
  16438. + * This is set by the client.
  16439. + */
  16440. +
  16441. + u32 buffer_size; /* Actual maximum size of the buffers that
  16442. + * will be sent to the port. This is set by
  16443. + * the client.
  16444. + */
  16445. +
  16446. + void *component; /* Component this port belongs to (Read Only) */
  16447. +
  16448. + void *userdata; /* Field reserved for use by the client */
  16449. +
  16450. + u32 capabilities; /* Flags describing the capabilities of a
  16451. + * port (RO). Bitwise combination of \ref
  16452. + * portcapabilities "Port capabilities"
  16453. + * values.
  16454. + */
  16455. +
  16456. +};
  16457. diff -Nur linux-3.15.4/drivers/media/platform/bcm2835/mmal-parameters.h linux-rpi/drivers/media/platform/bcm2835/mmal-parameters.h
  16458. --- linux-3.15.4/drivers/media/platform/bcm2835/mmal-parameters.h 1970-01-01 01:00:00.000000000 +0100
  16459. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-parameters.h 2014-07-07 10:45:10.000000000 +0200
  16460. @@ -0,0 +1,656 @@
  16461. +/*
  16462. + * Broadcom BM2835 V4L2 driver
  16463. + *
  16464. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  16465. + *
  16466. + * This file is subject to the terms and conditions of the GNU General Public
  16467. + * License. See the file COPYING in the main directory of this archive
  16468. + * for more details.
  16469. + *
  16470. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  16471. + * Dave Stevenson <dsteve@broadcom.com>
  16472. + * Simon Mellor <simellor@broadcom.com>
  16473. + * Luke Diamand <luked@broadcom.com>
  16474. + */
  16475. +
  16476. +/* common parameters */
  16477. +
  16478. +/** @name Parameter groups
  16479. + * Parameters are divided into groups, and then allocated sequentially within
  16480. + * a group using an enum.
  16481. + * @{
  16482. + */
  16483. +
  16484. +/** Common parameter ID group, used with many types of component. */
  16485. +#define MMAL_PARAMETER_GROUP_COMMON (0<<16)
  16486. +/** Camera-specific parameter ID group. */
  16487. +#define MMAL_PARAMETER_GROUP_CAMERA (1<<16)
  16488. +/** Video-specific parameter ID group. */
  16489. +#define MMAL_PARAMETER_GROUP_VIDEO (2<<16)
  16490. +/** Audio-specific parameter ID group. */
  16491. +#define MMAL_PARAMETER_GROUP_AUDIO (3<<16)
  16492. +/** Clock-specific parameter ID group. */
  16493. +#define MMAL_PARAMETER_GROUP_CLOCK (4<<16)
  16494. +/** Miracast-specific parameter ID group. */
  16495. +#define MMAL_PARAMETER_GROUP_MIRACAST (5<<16)
  16496. +
  16497. +/* Common parameters */
  16498. +enum mmal_parameter_common_type {
  16499. + MMAL_PARAMETER_UNUSED /**< Never a valid parameter ID */
  16500. + = MMAL_PARAMETER_GROUP_COMMON,
  16501. + MMAL_PARAMETER_SUPPORTED_ENCODINGS, /**< MMAL_PARAMETER_ENCODING_T */
  16502. + MMAL_PARAMETER_URI, /**< MMAL_PARAMETER_URI_T */
  16503. +
  16504. + /** MMAL_PARAMETER_CHANGE_EVENT_REQUEST_T */
  16505. + MMAL_PARAMETER_CHANGE_EVENT_REQUEST,
  16506. +
  16507. + /** MMAL_PARAMETER_BOOLEAN_T */
  16508. + MMAL_PARAMETER_ZERO_COPY,
  16509. +
  16510. + /**< MMAL_PARAMETER_BUFFER_REQUIREMENTS_T */
  16511. + MMAL_PARAMETER_BUFFER_REQUIREMENTS,
  16512. +
  16513. + MMAL_PARAMETER_STATISTICS, /**< MMAL_PARAMETER_STATISTICS_T */
  16514. + MMAL_PARAMETER_CORE_STATISTICS, /**< MMAL_PARAMETER_CORE_STATISTICS_T */
  16515. + MMAL_PARAMETER_MEM_USAGE, /**< MMAL_PARAMETER_MEM_USAGE_T */
  16516. + MMAL_PARAMETER_BUFFER_FLAG_FILTER, /**< MMAL_PARAMETER_UINT32_T */
  16517. + MMAL_PARAMETER_SEEK, /**< MMAL_PARAMETER_SEEK_T */
  16518. + MMAL_PARAMETER_POWERMON_ENABLE, /**< MMAL_PARAMETER_BOOLEAN_T */
  16519. + MMAL_PARAMETER_LOGGING, /**< MMAL_PARAMETER_LOGGING_T */
  16520. + MMAL_PARAMETER_SYSTEM_TIME, /**< MMAL_PARAMETER_UINT64_T */
  16521. + MMAL_PARAMETER_NO_IMAGE_PADDING /**< MMAL_PARAMETER_BOOLEAN_T */
  16522. +};
  16523. +
  16524. +/* camera parameters */
  16525. +
  16526. +enum mmal_parameter_camera_type {
  16527. + /* 0 */
  16528. + /** @ref MMAL_PARAMETER_THUMBNAIL_CONFIG_T */
  16529. + MMAL_PARAMETER_THUMBNAIL_CONFIGURATION
  16530. + = MMAL_PARAMETER_GROUP_CAMERA,
  16531. + MMAL_PARAMETER_CAPTURE_QUALITY, /**< Unused? */
  16532. + MMAL_PARAMETER_ROTATION, /**< @ref MMAL_PARAMETER_INT32_T */
  16533. + MMAL_PARAMETER_EXIF_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16534. + MMAL_PARAMETER_EXIF, /**< @ref MMAL_PARAMETER_EXIF_T */
  16535. + MMAL_PARAMETER_AWB_MODE, /**< @ref MMAL_PARAM_AWBMODE_T */
  16536. + MMAL_PARAMETER_IMAGE_EFFECT, /**< @ref MMAL_PARAMETER_IMAGEFX_T */
  16537. + MMAL_PARAMETER_COLOUR_EFFECT, /**< @ref MMAL_PARAMETER_COLOURFX_T */
  16538. + MMAL_PARAMETER_FLICKER_AVOID, /**< @ref MMAL_PARAMETER_FLICKERAVOID_T */
  16539. + MMAL_PARAMETER_FLASH, /**< @ref MMAL_PARAMETER_FLASH_T */
  16540. + MMAL_PARAMETER_REDEYE, /**< @ref MMAL_PARAMETER_REDEYE_T */
  16541. + MMAL_PARAMETER_FOCUS, /**< @ref MMAL_PARAMETER_FOCUS_T */
  16542. + MMAL_PARAMETER_FOCAL_LENGTHS, /**< Unused? */
  16543. + MMAL_PARAMETER_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
  16544. + MMAL_PARAMETER_ZOOM, /**< @ref MMAL_PARAMETER_SCALEFACTOR_T */
  16545. + MMAL_PARAMETER_MIRROR, /**< @ref MMAL_PARAMETER_MIRROR_T */
  16546. +
  16547. + /* 0x10 */
  16548. + MMAL_PARAMETER_CAMERA_NUM, /**< @ref MMAL_PARAMETER_UINT32_T */
  16549. + MMAL_PARAMETER_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16550. + MMAL_PARAMETER_EXPOSURE_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMODE_T */
  16551. + MMAL_PARAMETER_EXP_METERING_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMETERINGMODE_T */
  16552. + MMAL_PARAMETER_FOCUS_STATUS, /**< @ref MMAL_PARAMETER_FOCUS_STATUS_T */
  16553. + MMAL_PARAMETER_CAMERA_CONFIG, /**< @ref MMAL_PARAMETER_CAMERA_CONFIG_T */
  16554. + MMAL_PARAMETER_CAPTURE_STATUS, /**< @ref MMAL_PARAMETER_CAPTURE_STATUS_T */
  16555. + MMAL_PARAMETER_FACE_TRACK, /**< @ref MMAL_PARAMETER_FACE_TRACK_T */
  16556. + MMAL_PARAMETER_DRAW_BOX_FACES_AND_FOCUS, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16557. + MMAL_PARAMETER_JPEG_Q_FACTOR, /**< @ref MMAL_PARAMETER_UINT32_T */
  16558. + MMAL_PARAMETER_FRAME_RATE, /**< @ref MMAL_PARAMETER_FRAME_RATE_T */
  16559. + MMAL_PARAMETER_USE_STC, /**< @ref MMAL_PARAMETER_CAMERA_STC_MODE_T */
  16560. + MMAL_PARAMETER_CAMERA_INFO, /**< @ref MMAL_PARAMETER_CAMERA_INFO_T */
  16561. + MMAL_PARAMETER_VIDEO_STABILISATION, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16562. + MMAL_PARAMETER_FACE_TRACK_RESULTS, /**< @ref MMAL_PARAMETER_FACE_TRACK_RESULTS_T */
  16563. + MMAL_PARAMETER_ENABLE_RAW_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16564. +
  16565. + /* 0x20 */
  16566. + MMAL_PARAMETER_DPF_FILE, /**< @ref MMAL_PARAMETER_URI_T */
  16567. + MMAL_PARAMETER_ENABLE_DPF_FILE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16568. + MMAL_PARAMETER_DPF_FAIL_IS_FATAL, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16569. + MMAL_PARAMETER_CAPTURE_MODE, /**< @ref MMAL_PARAMETER_CAPTUREMODE_T */
  16570. + MMAL_PARAMETER_FOCUS_REGIONS, /**< @ref MMAL_PARAMETER_FOCUS_REGIONS_T */
  16571. + MMAL_PARAMETER_INPUT_CROP, /**< @ref MMAL_PARAMETER_INPUT_CROP_T */
  16572. + MMAL_PARAMETER_SENSOR_INFORMATION, /**< @ref MMAL_PARAMETER_SENSOR_INFORMATION_T */
  16573. + MMAL_PARAMETER_FLASH_SELECT, /**< @ref MMAL_PARAMETER_FLASH_SELECT_T */
  16574. + MMAL_PARAMETER_FIELD_OF_VIEW, /**< @ref MMAL_PARAMETER_FIELD_OF_VIEW_T */
  16575. + MMAL_PARAMETER_HIGH_DYNAMIC_RANGE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16576. + MMAL_PARAMETER_DYNAMIC_RANGE_COMPRESSION, /**< @ref MMAL_PARAMETER_DRC_T */
  16577. + MMAL_PARAMETER_ALGORITHM_CONTROL, /**< @ref MMAL_PARAMETER_ALGORITHM_CONTROL_T */
  16578. + MMAL_PARAMETER_SHARPNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  16579. + MMAL_PARAMETER_CONTRAST, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  16580. + MMAL_PARAMETER_BRIGHTNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  16581. + MMAL_PARAMETER_SATURATION, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  16582. +
  16583. + /* 0x30 */
  16584. + MMAL_PARAMETER_ISO, /**< @ref MMAL_PARAMETER_UINT32_T */
  16585. + MMAL_PARAMETER_ANTISHAKE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16586. +
  16587. + /** @ref MMAL_PARAMETER_IMAGEFX_PARAMETERS_T */
  16588. + MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
  16589. +
  16590. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  16591. + MMAL_PARAMETER_CAMERA_BURST_CAPTURE,
  16592. +
  16593. + /** @ref MMAL_PARAMETER_UINT32_T */
  16594. + MMAL_PARAMETER_CAMERA_MIN_ISO,
  16595. +
  16596. + /** @ref MMAL_PARAMETER_CAMERA_USE_CASE_T */
  16597. + MMAL_PARAMETER_CAMERA_USE_CASE,
  16598. +
  16599. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16600. + MMAL_PARAMETER_CAPTURE_STATS_PASS,
  16601. +
  16602. + /** @ref MMAL_PARAMETER_UINT32_T */
  16603. + MMAL_PARAMETER_CAMERA_CUSTOM_SENSOR_CONFIG,
  16604. +
  16605. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  16606. + MMAL_PARAMETER_ENABLE_REGISTER_FILE,
  16607. +
  16608. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  16609. + MMAL_PARAMETER_REGISTER_FAIL_IS_FATAL,
  16610. +
  16611. + /** @ref MMAL_PARAMETER_CONFIGFILE_T */
  16612. + MMAL_PARAMETER_CONFIGFILE_REGISTERS,
  16613. +
  16614. + /** @ref MMAL_PARAMETER_CONFIGFILE_CHUNK_T */
  16615. + MMAL_PARAMETER_CONFIGFILE_CHUNK_REGISTERS,
  16616. + MMAL_PARAMETER_JPEG_ATTACH_LOG, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16617. + MMAL_PARAMETER_ZERO_SHUTTER_LAG, /**< @ref MMAL_PARAMETER_ZEROSHUTTERLAG_T */
  16618. + MMAL_PARAMETER_FPS_RANGE, /**< @ref MMAL_PARAMETER_FPS_RANGE_T */
  16619. + MMAL_PARAMETER_CAPTURE_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
  16620. +
  16621. + /* 0x40 */
  16622. + MMAL_PARAMETER_SW_SHARPEN_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16623. + MMAL_PARAMETER_FLASH_REQUIRED, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16624. + MMAL_PARAMETER_SW_SATURATION_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16625. + MMAL_PARAMETER_SHUTTER_SPEED, /**< Takes a @ref MMAL_PARAMETER_UINT32_T */
  16626. + MMAL_PARAMETER_CUSTOM_AWB_GAINS, /**< Takes a @ref MMAL_PARAMETER_AWB_GAINS_T */
  16627. +};
  16628. +
  16629. +struct mmal_parameter_rational {
  16630. + s32 num; /**< Numerator */
  16631. + s32 den; /**< Denominator */
  16632. +};
  16633. +
  16634. +enum mmal_parameter_camera_config_timestamp_mode {
  16635. + MMAL_PARAM_TIMESTAMP_MODE_ZERO = 0, /* Always timestamp frames as 0 */
  16636. + MMAL_PARAM_TIMESTAMP_MODE_RAW_STC, /* Use the raw STC value
  16637. + * for the frame timestamp
  16638. + */
  16639. + MMAL_PARAM_TIMESTAMP_MODE_RESET_STC, /* Use the STC timestamp
  16640. + * but subtract the
  16641. + * timestamp of the first
  16642. + * frame sent to give a
  16643. + * zero based timestamp.
  16644. + */
  16645. +};
  16646. +
  16647. +struct mmal_parameter_fps_range {
  16648. + /**< Low end of the permitted framerate range */
  16649. + struct mmal_parameter_rational fps_low;
  16650. + /**< High end of the permitted framerate range */
  16651. + struct mmal_parameter_rational fps_high;
  16652. +};
  16653. +
  16654. +
  16655. +/* camera configuration parameter */
  16656. +struct mmal_parameter_camera_config {
  16657. + /* Parameters for setting up the image pools */
  16658. + u32 max_stills_w; /* Max size of stills capture */
  16659. + u32 max_stills_h;
  16660. + u32 stills_yuv422; /* Allow YUV422 stills capture */
  16661. + u32 one_shot_stills; /* Continuous or one shot stills captures. */
  16662. +
  16663. + u32 max_preview_video_w; /* Max size of the preview or video
  16664. + * capture frames
  16665. + */
  16666. + u32 max_preview_video_h;
  16667. + u32 num_preview_video_frames;
  16668. +
  16669. + /** Sets the height of the circular buffer for stills capture. */
  16670. + u32 stills_capture_circular_buffer_height;
  16671. +
  16672. + /** Allows preview/encode to resume as fast as possible after the stills
  16673. + * input frame has been received, and then processes the still frame in
  16674. + * the background whilst preview/encode has resumed.
  16675. + * Actual mode is controlled by MMAL_PARAMETER_CAPTURE_MODE.
  16676. + */
  16677. + u32 fast_preview_resume;
  16678. +
  16679. + /** Selects algorithm for timestamping frames if
  16680. + * there is no clock component connected.
  16681. + * enum mmal_parameter_camera_config_timestamp_mode
  16682. + */
  16683. + s32 use_stc_timestamp;
  16684. +};
  16685. +
  16686. +
  16687. +enum mmal_parameter_exposuremode {
  16688. + MMAL_PARAM_EXPOSUREMODE_OFF,
  16689. + MMAL_PARAM_EXPOSUREMODE_AUTO,
  16690. + MMAL_PARAM_EXPOSUREMODE_NIGHT,
  16691. + MMAL_PARAM_EXPOSUREMODE_NIGHTPREVIEW,
  16692. + MMAL_PARAM_EXPOSUREMODE_BACKLIGHT,
  16693. + MMAL_PARAM_EXPOSUREMODE_SPOTLIGHT,
  16694. + MMAL_PARAM_EXPOSUREMODE_SPORTS,
  16695. + MMAL_PARAM_EXPOSUREMODE_SNOW,
  16696. + MMAL_PARAM_EXPOSUREMODE_BEACH,
  16697. + MMAL_PARAM_EXPOSUREMODE_VERYLONG,
  16698. + MMAL_PARAM_EXPOSUREMODE_FIXEDFPS,
  16699. + MMAL_PARAM_EXPOSUREMODE_ANTISHAKE,
  16700. + MMAL_PARAM_EXPOSUREMODE_FIREWORKS,
  16701. +};
  16702. +
  16703. +enum mmal_parameter_exposuremeteringmode {
  16704. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE,
  16705. + MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT,
  16706. + MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT,
  16707. + MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX,
  16708. +};
  16709. +
  16710. +enum mmal_parameter_awbmode {
  16711. + MMAL_PARAM_AWBMODE_OFF,
  16712. + MMAL_PARAM_AWBMODE_AUTO,
  16713. + MMAL_PARAM_AWBMODE_SUNLIGHT,
  16714. + MMAL_PARAM_AWBMODE_CLOUDY,
  16715. + MMAL_PARAM_AWBMODE_SHADE,
  16716. + MMAL_PARAM_AWBMODE_TUNGSTEN,
  16717. + MMAL_PARAM_AWBMODE_FLUORESCENT,
  16718. + MMAL_PARAM_AWBMODE_INCANDESCENT,
  16719. + MMAL_PARAM_AWBMODE_FLASH,
  16720. + MMAL_PARAM_AWBMODE_HORIZON,
  16721. +};
  16722. +
  16723. +enum mmal_parameter_imagefx {
  16724. + MMAL_PARAM_IMAGEFX_NONE,
  16725. + MMAL_PARAM_IMAGEFX_NEGATIVE,
  16726. + MMAL_PARAM_IMAGEFX_SOLARIZE,
  16727. + MMAL_PARAM_IMAGEFX_POSTERIZE,
  16728. + MMAL_PARAM_IMAGEFX_WHITEBOARD,
  16729. + MMAL_PARAM_IMAGEFX_BLACKBOARD,
  16730. + MMAL_PARAM_IMAGEFX_SKETCH,
  16731. + MMAL_PARAM_IMAGEFX_DENOISE,
  16732. + MMAL_PARAM_IMAGEFX_EMBOSS,
  16733. + MMAL_PARAM_IMAGEFX_OILPAINT,
  16734. + MMAL_PARAM_IMAGEFX_HATCH,
  16735. + MMAL_PARAM_IMAGEFX_GPEN,
  16736. + MMAL_PARAM_IMAGEFX_PASTEL,
  16737. + MMAL_PARAM_IMAGEFX_WATERCOLOUR,
  16738. + MMAL_PARAM_IMAGEFX_FILM,
  16739. + MMAL_PARAM_IMAGEFX_BLUR,
  16740. + MMAL_PARAM_IMAGEFX_SATURATION,
  16741. + MMAL_PARAM_IMAGEFX_COLOURSWAP,
  16742. + MMAL_PARAM_IMAGEFX_WASHEDOUT,
  16743. + MMAL_PARAM_IMAGEFX_POSTERISE,
  16744. + MMAL_PARAM_IMAGEFX_COLOURPOINT,
  16745. + MMAL_PARAM_IMAGEFX_COLOURBALANCE,
  16746. + MMAL_PARAM_IMAGEFX_CARTOON,
  16747. +};
  16748. +
  16749. +enum MMAL_PARAM_FLICKERAVOID_T {
  16750. + MMAL_PARAM_FLICKERAVOID_OFF,
  16751. + MMAL_PARAM_FLICKERAVOID_AUTO,
  16752. + MMAL_PARAM_FLICKERAVOID_50HZ,
  16753. + MMAL_PARAM_FLICKERAVOID_60HZ,
  16754. + MMAL_PARAM_FLICKERAVOID_MAX = 0x7FFFFFFF
  16755. +};
  16756. +
  16757. +struct mmal_parameter_awbgains {
  16758. + struct mmal_parameter_rational r_gain; /**< Red gain */
  16759. + struct mmal_parameter_rational b_gain; /**< Blue gain */
  16760. +};
  16761. +
  16762. +/** Manner of video rate control */
  16763. +enum mmal_parameter_rate_control_mode {
  16764. + MMAL_VIDEO_RATECONTROL_DEFAULT,
  16765. + MMAL_VIDEO_RATECONTROL_VARIABLE,
  16766. + MMAL_VIDEO_RATECONTROL_CONSTANT,
  16767. + MMAL_VIDEO_RATECONTROL_VARIABLE_SKIP_FRAMES,
  16768. + MMAL_VIDEO_RATECONTROL_CONSTANT_SKIP_FRAMES
  16769. +};
  16770. +
  16771. +enum mmal_video_profile {
  16772. + MMAL_VIDEO_PROFILE_H263_BASELINE,
  16773. + MMAL_VIDEO_PROFILE_H263_H320CODING,
  16774. + MMAL_VIDEO_PROFILE_H263_BACKWARDCOMPATIBLE,
  16775. + MMAL_VIDEO_PROFILE_H263_ISWV2,
  16776. + MMAL_VIDEO_PROFILE_H263_ISWV3,
  16777. + MMAL_VIDEO_PROFILE_H263_HIGHCOMPRESSION,
  16778. + MMAL_VIDEO_PROFILE_H263_INTERNET,
  16779. + MMAL_VIDEO_PROFILE_H263_INTERLACE,
  16780. + MMAL_VIDEO_PROFILE_H263_HIGHLATENCY,
  16781. + MMAL_VIDEO_PROFILE_MP4V_SIMPLE,
  16782. + MMAL_VIDEO_PROFILE_MP4V_SIMPLESCALABLE,
  16783. + MMAL_VIDEO_PROFILE_MP4V_CORE,
  16784. + MMAL_VIDEO_PROFILE_MP4V_MAIN,
  16785. + MMAL_VIDEO_PROFILE_MP4V_NBIT,
  16786. + MMAL_VIDEO_PROFILE_MP4V_SCALABLETEXTURE,
  16787. + MMAL_VIDEO_PROFILE_MP4V_SIMPLEFACE,
  16788. + MMAL_VIDEO_PROFILE_MP4V_SIMPLEFBA,
  16789. + MMAL_VIDEO_PROFILE_MP4V_BASICANIMATED,
  16790. + MMAL_VIDEO_PROFILE_MP4V_HYBRID,
  16791. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDREALTIME,
  16792. + MMAL_VIDEO_PROFILE_MP4V_CORESCALABLE,
  16793. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDCODING,
  16794. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDCORE,
  16795. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDSCALABLE,
  16796. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDSIMPLE,
  16797. + MMAL_VIDEO_PROFILE_H264_BASELINE,
  16798. + MMAL_VIDEO_PROFILE_H264_MAIN,
  16799. + MMAL_VIDEO_PROFILE_H264_EXTENDED,
  16800. + MMAL_VIDEO_PROFILE_H264_HIGH,
  16801. + MMAL_VIDEO_PROFILE_H264_HIGH10,
  16802. + MMAL_VIDEO_PROFILE_H264_HIGH422,
  16803. + MMAL_VIDEO_PROFILE_H264_HIGH444,
  16804. + MMAL_VIDEO_PROFILE_H264_CONSTRAINED_BASELINE,
  16805. + MMAL_VIDEO_PROFILE_DUMMY = 0x7FFFFFFF
  16806. +};
  16807. +
  16808. +enum mmal_video_level {
  16809. + MMAL_VIDEO_LEVEL_H263_10,
  16810. + MMAL_VIDEO_LEVEL_H263_20,
  16811. + MMAL_VIDEO_LEVEL_H263_30,
  16812. + MMAL_VIDEO_LEVEL_H263_40,
  16813. + MMAL_VIDEO_LEVEL_H263_45,
  16814. + MMAL_VIDEO_LEVEL_H263_50,
  16815. + MMAL_VIDEO_LEVEL_H263_60,
  16816. + MMAL_VIDEO_LEVEL_H263_70,
  16817. + MMAL_VIDEO_LEVEL_MP4V_0,
  16818. + MMAL_VIDEO_LEVEL_MP4V_0b,
  16819. + MMAL_VIDEO_LEVEL_MP4V_1,
  16820. + MMAL_VIDEO_LEVEL_MP4V_2,
  16821. + MMAL_VIDEO_LEVEL_MP4V_3,
  16822. + MMAL_VIDEO_LEVEL_MP4V_4,
  16823. + MMAL_VIDEO_LEVEL_MP4V_4a,
  16824. + MMAL_VIDEO_LEVEL_MP4V_5,
  16825. + MMAL_VIDEO_LEVEL_MP4V_6,
  16826. + MMAL_VIDEO_LEVEL_H264_1,
  16827. + MMAL_VIDEO_LEVEL_H264_1b,
  16828. + MMAL_VIDEO_LEVEL_H264_11,
  16829. + MMAL_VIDEO_LEVEL_H264_12,
  16830. + MMAL_VIDEO_LEVEL_H264_13,
  16831. + MMAL_VIDEO_LEVEL_H264_2,
  16832. + MMAL_VIDEO_LEVEL_H264_21,
  16833. + MMAL_VIDEO_LEVEL_H264_22,
  16834. + MMAL_VIDEO_LEVEL_H264_3,
  16835. + MMAL_VIDEO_LEVEL_H264_31,
  16836. + MMAL_VIDEO_LEVEL_H264_32,
  16837. + MMAL_VIDEO_LEVEL_H264_4,
  16838. + MMAL_VIDEO_LEVEL_H264_41,
  16839. + MMAL_VIDEO_LEVEL_H264_42,
  16840. + MMAL_VIDEO_LEVEL_H264_5,
  16841. + MMAL_VIDEO_LEVEL_H264_51,
  16842. + MMAL_VIDEO_LEVEL_DUMMY = 0x7FFFFFFF
  16843. +};
  16844. +
  16845. +struct mmal_parameter_video_profile {
  16846. + enum mmal_video_profile profile;
  16847. + enum mmal_video_level level;
  16848. +};
  16849. +
  16850. +/* video parameters */
  16851. +
  16852. +enum mmal_parameter_video_type {
  16853. + /** @ref MMAL_DISPLAYREGION_T */
  16854. + MMAL_PARAMETER_DISPLAYREGION = MMAL_PARAMETER_GROUP_VIDEO,
  16855. +
  16856. + /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
  16857. + MMAL_PARAMETER_SUPPORTED_PROFILES,
  16858. +
  16859. + /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
  16860. + MMAL_PARAMETER_PROFILE,
  16861. +
  16862. + /** @ref MMAL_PARAMETER_UINT32_T */
  16863. + MMAL_PARAMETER_INTRAPERIOD,
  16864. +
  16865. + /** @ref MMAL_PARAMETER_VIDEO_RATECONTROL_T */
  16866. + MMAL_PARAMETER_RATECONTROL,
  16867. +
  16868. + /** @ref MMAL_PARAMETER_VIDEO_NALUNITFORMAT_T */
  16869. + MMAL_PARAMETER_NALUNITFORMAT,
  16870. +
  16871. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  16872. + MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
  16873. +
  16874. + /** @ref MMAL_PARAMETER_UINT32_T.
  16875. + * Setting the value to zero resets to the default (one slice per frame).
  16876. + */
  16877. + MMAL_PARAMETER_MB_ROWS_PER_SLICE,
  16878. +
  16879. + /** @ref MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION_T */
  16880. + MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION,
  16881. +
  16882. + /** @ref MMAL_PARAMETER_VIDEO_EEDE_ENABLE_T */
  16883. + MMAL_PARAMETER_VIDEO_EEDE_ENABLE,
  16884. +
  16885. + /** @ref MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE_T */
  16886. + MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE,
  16887. +
  16888. + /** @ref MMAL_PARAMETER_BOOLEAN_T. Request an I-frame. */
  16889. + MMAL_PARAMETER_VIDEO_REQUEST_I_FRAME,
  16890. + /** @ref MMAL_PARAMETER_VIDEO_INTRA_REFRESH_T */
  16891. + MMAL_PARAMETER_VIDEO_INTRA_REFRESH,
  16892. +
  16893. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  16894. + MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
  16895. +
  16896. + /** @ref MMAL_PARAMETER_UINT32_T. Run-time bit rate control */
  16897. + MMAL_PARAMETER_VIDEO_BIT_RATE,
  16898. +
  16899. + /** @ref MMAL_PARAMETER_FRAME_RATE_T */
  16900. + MMAL_PARAMETER_VIDEO_FRAME_RATE,
  16901. +
  16902. + /** @ref MMAL_PARAMETER_UINT32_T. */
  16903. + MMAL_PARAMETER_VIDEO_ENCODE_MIN_QUANT,
  16904. +
  16905. + /** @ref MMAL_PARAMETER_UINT32_T. */
  16906. + MMAL_PARAMETER_VIDEO_ENCODE_MAX_QUANT,
  16907. +
  16908. + /** @ref MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL_T. */
  16909. + MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL,
  16910. +
  16911. + MMAL_PARAMETER_EXTRA_BUFFERS, /**< @ref MMAL_PARAMETER_UINT32_T. */
  16912. + /** @ref MMAL_PARAMETER_UINT32_T.
  16913. + * Changing this parameter from the default can reduce frame rate
  16914. + * because image buffers need to be re-pitched.
  16915. + */
  16916. + MMAL_PARAMETER_VIDEO_ALIGN_HORIZ,
  16917. +
  16918. + /** @ref MMAL_PARAMETER_UINT32_T.
  16919. + * Changing this parameter from the default can reduce frame rate
  16920. + * because image buffers need to be re-pitched.
  16921. + */
  16922. + MMAL_PARAMETER_VIDEO_ALIGN_VERT,
  16923. +
  16924. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  16925. + MMAL_PARAMETER_VIDEO_DROPPABLE_PFRAMES,
  16926. +
  16927. + /** @ref MMAL_PARAMETER_UINT32_T. */
  16928. + MMAL_PARAMETER_VIDEO_ENCODE_INITIAL_QUANT,
  16929. +
  16930. + /**< @ref MMAL_PARAMETER_UINT32_T. */
  16931. + MMAL_PARAMETER_VIDEO_ENCODE_QP_P,
  16932. +
  16933. + /**< @ref MMAL_PARAMETER_UINT32_T. */
  16934. + MMAL_PARAMETER_VIDEO_ENCODE_RC_SLICE_DQUANT,
  16935. +
  16936. + /** @ref MMAL_PARAMETER_UINT32_T */
  16937. + MMAL_PARAMETER_VIDEO_ENCODE_FRAME_LIMIT_BITS,
  16938. +
  16939. + /** @ref MMAL_PARAMETER_UINT32_T. */
  16940. + MMAL_PARAMETER_VIDEO_ENCODE_PEAK_RATE,
  16941. +
  16942. + /* H264 specific parameters */
  16943. +
  16944. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  16945. + MMAL_PARAMETER_VIDEO_ENCODE_H264_DISABLE_CABAC,
  16946. +
  16947. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  16948. + MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_LATENCY,
  16949. +
  16950. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  16951. + MMAL_PARAMETER_VIDEO_ENCODE_H264_AU_DELIMITERS,
  16952. +
  16953. + /** @ref MMAL_PARAMETER_UINT32_T. */
  16954. + MMAL_PARAMETER_VIDEO_ENCODE_H264_DEBLOCK_IDC,
  16955. +
  16956. + /** @ref MMAL_PARAMETER_VIDEO_ENCODER_H264_MB_INTRA_MODES_T. */
  16957. + MMAL_PARAMETER_VIDEO_ENCODE_H264_MB_INTRA_MODE,
  16958. +
  16959. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  16960. + MMAL_PARAMETER_VIDEO_ENCODE_HEADER_ON_OPEN,
  16961. +
  16962. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  16963. + MMAL_PARAMETER_VIDEO_ENCODE_PRECODE_FOR_QP,
  16964. +
  16965. + /** @ref MMAL_PARAMETER_VIDEO_DRM_INIT_INFO_T. */
  16966. + MMAL_PARAMETER_VIDEO_DRM_INIT_INFO,
  16967. +
  16968. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  16969. + MMAL_PARAMETER_VIDEO_TIMESTAMP_FIFO,
  16970. +
  16971. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  16972. + MMAL_PARAMETER_VIDEO_DECODE_ERROR_CONCEALMENT,
  16973. +
  16974. + /** @ref MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER_T. */
  16975. + MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER,
  16976. +
  16977. + /** @ref MMAL_PARAMETER_BYTES_T */
  16978. + MMAL_PARAMETER_VIDEO_DECODE_CONFIG_VD3,
  16979. +
  16980. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16981. + MMAL_PARAMETER_VIDEO_ENCODE_H264_VCL_HRD_PARAMETERS,
  16982. +
  16983. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16984. + MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_DELAY_HRD_FLAG,
  16985. +
  16986. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  16987. + MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER
  16988. +};
  16989. +
  16990. +/** Valid mirror modes */
  16991. +enum mmal_parameter_mirror {
  16992. + MMAL_PARAM_MIRROR_NONE,
  16993. + MMAL_PARAM_MIRROR_VERTICAL,
  16994. + MMAL_PARAM_MIRROR_HORIZONTAL,
  16995. + MMAL_PARAM_MIRROR_BOTH,
  16996. +};
  16997. +
  16998. +enum mmal_parameter_displaytransform {
  16999. + MMAL_DISPLAY_ROT0 = 0,
  17000. + MMAL_DISPLAY_MIRROR_ROT0 = 1,
  17001. + MMAL_DISPLAY_MIRROR_ROT180 = 2,
  17002. + MMAL_DISPLAY_ROT180 = 3,
  17003. + MMAL_DISPLAY_MIRROR_ROT90 = 4,
  17004. + MMAL_DISPLAY_ROT270 = 5,
  17005. + MMAL_DISPLAY_ROT90 = 6,
  17006. + MMAL_DISPLAY_MIRROR_ROT270 = 7,
  17007. +};
  17008. +
  17009. +enum mmal_parameter_displaymode {
  17010. + MMAL_DISPLAY_MODE_FILL = 0,
  17011. + MMAL_DISPLAY_MODE_LETTERBOX = 1,
  17012. +};
  17013. +
  17014. +enum mmal_parameter_displayset {
  17015. + MMAL_DISPLAY_SET_NONE = 0,
  17016. + MMAL_DISPLAY_SET_NUM = 1,
  17017. + MMAL_DISPLAY_SET_FULLSCREEN = 2,
  17018. + MMAL_DISPLAY_SET_TRANSFORM = 4,
  17019. + MMAL_DISPLAY_SET_DEST_RECT = 8,
  17020. + MMAL_DISPLAY_SET_SRC_RECT = 0x10,
  17021. + MMAL_DISPLAY_SET_MODE = 0x20,
  17022. + MMAL_DISPLAY_SET_PIXEL = 0x40,
  17023. + MMAL_DISPLAY_SET_NOASPECT = 0x80,
  17024. + MMAL_DISPLAY_SET_LAYER = 0x100,
  17025. + MMAL_DISPLAY_SET_COPYPROTECT = 0x200,
  17026. + MMAL_DISPLAY_SET_ALPHA = 0x400,
  17027. +};
  17028. +
  17029. +struct mmal_parameter_displayregion {
  17030. + /** Bitfield that indicates which fields are set and should be
  17031. + * used. All other fields will maintain their current value.
  17032. + * \ref MMAL_DISPLAYSET_T defines the bits that can be
  17033. + * combined.
  17034. + */
  17035. + u32 set;
  17036. +
  17037. + /** Describes the display output device, with 0 typically
  17038. + * being a directly connected LCD display. The actual values
  17039. + * will depend on the hardware. Code using hard-wired numbers
  17040. + * (e.g. 2) is certain to fail.
  17041. + */
  17042. +
  17043. + u32 display_num;
  17044. + /** Indicates that we are using the full device screen area,
  17045. + * rather than a window of the display. If zero, then
  17046. + * dest_rect is used to specify a region of the display to
  17047. + * use.
  17048. + */
  17049. +
  17050. + s32 fullscreen;
  17051. + /** Indicates any rotation or flipping used to map frames onto
  17052. + * the natural display orientation.
  17053. + */
  17054. + u32 transform; /* enum mmal_parameter_displaytransform */
  17055. +
  17056. + /** Where to display the frame within the screen, if
  17057. + * fullscreen is zero.
  17058. + */
  17059. + struct vchiq_mmal_rect dest_rect;
  17060. +
  17061. + /** Indicates which area of the frame to display. If all
  17062. + * values are zero, the whole frame will be used.
  17063. + */
  17064. + struct vchiq_mmal_rect src_rect;
  17065. +
  17066. + /** If set to non-zero, indicates that any display scaling
  17067. + * should disregard the aspect ratio of the frame region being
  17068. + * displayed.
  17069. + */
  17070. + s32 noaspect;
  17071. +
  17072. + /** Indicates how the image should be scaled to fit the
  17073. + * display. \code MMAL_DISPLAY_MODE_FILL \endcode indicates
  17074. + * that the image should fill the screen by potentially
  17075. + * cropping the frames. Setting \code mode \endcode to \code
  17076. + * MMAL_DISPLAY_MODE_LETTERBOX \endcode indicates that all the
  17077. + * source region should be displayed and black bars added if
  17078. + * necessary.
  17079. + */
  17080. + u32 mode; /* enum mmal_parameter_displaymode */
  17081. +
  17082. + /** If non-zero, defines the width of a source pixel relative
  17083. + * to \code pixel_y \endcode. If zero, then pixels default to
  17084. + * being square.
  17085. + */
  17086. + u32 pixel_x;
  17087. +
  17088. + /** If non-zero, defines the height of a source pixel relative
  17089. + * to \code pixel_x \endcode. If zero, then pixels default to
  17090. + * being square.
  17091. + */
  17092. + u32 pixel_y;
  17093. +
  17094. + /** Sets the relative depth of the images, with greater values
  17095. + * being in front of smaller values.
  17096. + */
  17097. + u32 layer;
  17098. +
  17099. + /** Set to non-zero to ensure copy protection is used on
  17100. + * output.
  17101. + */
  17102. + s32 copyprotect_required;
  17103. +
  17104. + /** Level of opacity of the layer, where zero is fully
  17105. + * transparent and 255 is fully opaque.
  17106. + */
  17107. + u32 alpha;
  17108. +};
  17109. +
  17110. +#define MMAL_MAX_IMAGEFX_PARAMETERS 5
  17111. +
  17112. +struct mmal_parameter_imagefx_parameters {
  17113. + enum mmal_parameter_imagefx effect;
  17114. + u32 num_effect_params;
  17115. + u32 effect_parameter[MMAL_MAX_IMAGEFX_PARAMETERS];
  17116. +};
  17117. diff -Nur linux-3.15.4/drivers/media/platform/bcm2835/mmal-vchiq.c linux-rpi/drivers/media/platform/bcm2835/mmal-vchiq.c
  17118. --- linux-3.15.4/drivers/media/platform/bcm2835/mmal-vchiq.c 1970-01-01 01:00:00.000000000 +0100
  17119. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-vchiq.c 2014-04-13 17:32:57.000000000 +0200
  17120. @@ -0,0 +1,1916 @@
  17121. +/*
  17122. + * Broadcom BM2835 V4L2 driver
  17123. + *
  17124. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  17125. + *
  17126. + * This file is subject to the terms and conditions of the GNU General Public
  17127. + * License. See the file COPYING in the main directory of this archive
  17128. + * for more details.
  17129. + *
  17130. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  17131. + * Dave Stevenson <dsteve@broadcom.com>
  17132. + * Simon Mellor <simellor@broadcom.com>
  17133. + * Luke Diamand <luked@broadcom.com>
  17134. + *
  17135. + * V4L2 driver MMAL vchiq interface code
  17136. + */
  17137. +
  17138. +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  17139. +
  17140. +#include <linux/errno.h>
  17141. +#include <linux/kernel.h>
  17142. +#include <linux/mutex.h>
  17143. +#include <linux/mm.h>
  17144. +#include <linux/slab.h>
  17145. +#include <linux/completion.h>
  17146. +#include <linux/vmalloc.h>
  17147. +#include <asm/cacheflush.h>
  17148. +#include <media/videobuf2-vmalloc.h>
  17149. +
  17150. +#include "mmal-common.h"
  17151. +#include "mmal-vchiq.h"
  17152. +#include "mmal-msg.h"
  17153. +
  17154. +#define USE_VCHIQ_ARM
  17155. +#include "interface/vchi/vchi.h"
  17156. +
  17157. +/* maximum number of components supported */
  17158. +#define VCHIQ_MMAL_MAX_COMPONENTS 4
  17159. +
  17160. +/*#define FULL_MSG_DUMP 1*/
  17161. +
  17162. +#ifdef DEBUG
  17163. +static const char *const msg_type_names[] = {
  17164. + "UNKNOWN",
  17165. + "QUIT",
  17166. + "SERVICE_CLOSED",
  17167. + "GET_VERSION",
  17168. + "COMPONENT_CREATE",
  17169. + "COMPONENT_DESTROY",
  17170. + "COMPONENT_ENABLE",
  17171. + "COMPONENT_DISABLE",
  17172. + "PORT_INFO_GET",
  17173. + "PORT_INFO_SET",
  17174. + "PORT_ACTION",
  17175. + "BUFFER_FROM_HOST",
  17176. + "BUFFER_TO_HOST",
  17177. + "GET_STATS",
  17178. + "PORT_PARAMETER_SET",
  17179. + "PORT_PARAMETER_GET",
  17180. + "EVENT_TO_HOST",
  17181. + "GET_CORE_STATS_FOR_PORT",
  17182. + "OPAQUE_ALLOCATOR",
  17183. + "CONSUME_MEM",
  17184. + "LMK",
  17185. + "OPAQUE_ALLOCATOR_DESC",
  17186. + "DRM_GET_LHS32",
  17187. + "DRM_GET_TIME",
  17188. + "BUFFER_FROM_HOST_ZEROLEN",
  17189. + "PORT_FLUSH",
  17190. + "HOST_LOG",
  17191. +};
  17192. +#endif
  17193. +
  17194. +static const char *const port_action_type_names[] = {
  17195. + "UNKNOWN",
  17196. + "ENABLE",
  17197. + "DISABLE",
  17198. + "FLUSH",
  17199. + "CONNECT",
  17200. + "DISCONNECT",
  17201. + "SET_REQUIREMENTS",
  17202. +};
  17203. +
  17204. +#if defined(DEBUG)
  17205. +#if defined(FULL_MSG_DUMP)
  17206. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
  17207. + do { \
  17208. + pr_debug(TITLE" type:%s(%d) length:%d\n", \
  17209. + msg_type_names[(MSG)->h.type], \
  17210. + (MSG)->h.type, (MSG_LEN)); \
  17211. + print_hex_dump(KERN_DEBUG, "<<h: ", DUMP_PREFIX_OFFSET, \
  17212. + 16, 4, (MSG), \
  17213. + sizeof(struct mmal_msg_header), 1); \
  17214. + print_hex_dump(KERN_DEBUG, "<<p: ", DUMP_PREFIX_OFFSET, \
  17215. + 16, 4, \
  17216. + ((u8 *)(MSG)) + sizeof(struct mmal_msg_header),\
  17217. + (MSG_LEN) - sizeof(struct mmal_msg_header), 1); \
  17218. + } while (0)
  17219. +#else
  17220. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
  17221. + { \
  17222. + pr_debug(TITLE" type:%s(%d) length:%d\n", \
  17223. + msg_type_names[(MSG)->h.type], \
  17224. + (MSG)->h.type, (MSG_LEN)); \
  17225. + }
  17226. +#endif
  17227. +#else
  17228. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE)
  17229. +#endif
  17230. +
  17231. +/* normal message context */
  17232. +struct mmal_msg_context {
  17233. + union {
  17234. + struct {
  17235. + /* work struct for defered callback - must come first */
  17236. + struct work_struct work;
  17237. + /* mmal instance */
  17238. + struct vchiq_mmal_instance *instance;
  17239. + /* mmal port */
  17240. + struct vchiq_mmal_port *port;
  17241. + /* actual buffer used to store bulk reply */
  17242. + struct mmal_buffer *buffer;
  17243. + /* amount of buffer used */
  17244. + unsigned long buffer_used;
  17245. + /* MMAL buffer flags */
  17246. + u32 mmal_flags;
  17247. + /* Presentation and Decode timestamps */
  17248. + s64 pts;
  17249. + s64 dts;
  17250. +
  17251. + int status; /* context status */
  17252. +
  17253. + } bulk; /* bulk data */
  17254. +
  17255. + struct {
  17256. + /* message handle to release */
  17257. + VCHI_HELD_MSG_T msg_handle;
  17258. + /* pointer to received message */
  17259. + struct mmal_msg *msg;
  17260. + /* received message length */
  17261. + u32 msg_len;
  17262. + /* completion upon reply */
  17263. + struct completion cmplt;
  17264. + } sync; /* synchronous response */
  17265. + } u;
  17266. +
  17267. +};
  17268. +
  17269. +struct vchiq_mmal_instance {
  17270. + VCHI_SERVICE_HANDLE_T handle;
  17271. +
  17272. + /* ensure serialised access to service */
  17273. + struct mutex vchiq_mutex;
  17274. +
  17275. + /* ensure serialised access to bulk operations */
  17276. + struct mutex bulk_mutex;
  17277. +
  17278. + /* vmalloc page to receive scratch bulk xfers into */
  17279. + void *bulk_scratch;
  17280. +
  17281. + /* component to use next */
  17282. + int component_idx;
  17283. + struct vchiq_mmal_component component[VCHIQ_MMAL_MAX_COMPONENTS];
  17284. +};
  17285. +
  17286. +static struct mmal_msg_context *get_msg_context(struct vchiq_mmal_instance
  17287. + *instance)
  17288. +{
  17289. + struct mmal_msg_context *msg_context;
  17290. +
  17291. + /* todo: should this be allocated from a pool to avoid kmalloc */
  17292. + msg_context = kmalloc(sizeof(*msg_context), GFP_KERNEL);
  17293. + memset(msg_context, 0, sizeof(*msg_context));
  17294. +
  17295. + return msg_context;
  17296. +}
  17297. +
  17298. +static void release_msg_context(struct mmal_msg_context *msg_context)
  17299. +{
  17300. + kfree(msg_context);
  17301. +}
  17302. +
  17303. +/* deals with receipt of event to host message */
  17304. +static void event_to_host_cb(struct vchiq_mmal_instance *instance,
  17305. + struct mmal_msg *msg, u32 msg_len)
  17306. +{
  17307. + pr_debug("unhandled event\n");
  17308. + pr_debug("component:%p port type:%d num:%d cmd:0x%x length:%d\n",
  17309. + msg->u.event_to_host.client_component,
  17310. + msg->u.event_to_host.port_type,
  17311. + msg->u.event_to_host.port_num,
  17312. + msg->u.event_to_host.cmd, msg->u.event_to_host.length);
  17313. +}
  17314. +
  17315. +/* workqueue scheduled callback
  17316. + *
  17317. + * we do this because it is important we do not call any other vchiq
  17318. + * sync calls from witin the message delivery thread
  17319. + */
  17320. +static void buffer_work_cb(struct work_struct *work)
  17321. +{
  17322. + struct mmal_msg_context *msg_context = (struct mmal_msg_context *)work;
  17323. +
  17324. + msg_context->u.bulk.port->buffer_cb(msg_context->u.bulk.instance,
  17325. + msg_context->u.bulk.port,
  17326. + msg_context->u.bulk.status,
  17327. + msg_context->u.bulk.buffer,
  17328. + msg_context->u.bulk.buffer_used,
  17329. + msg_context->u.bulk.mmal_flags,
  17330. + msg_context->u.bulk.dts,
  17331. + msg_context->u.bulk.pts);
  17332. +
  17333. + /* release message context */
  17334. + release_msg_context(msg_context);
  17335. +}
  17336. +
  17337. +/* enqueue a bulk receive for a given message context */
  17338. +static int bulk_receive(struct vchiq_mmal_instance *instance,
  17339. + struct mmal_msg *msg,
  17340. + struct mmal_msg_context *msg_context)
  17341. +{
  17342. + unsigned long rd_len;
  17343. + unsigned long flags = 0;
  17344. + int ret;
  17345. +
  17346. + /* bulk mutex stops other bulk operations while we have a
  17347. + * receive in progress - released in callback
  17348. + */
  17349. + ret = mutex_lock_interruptible(&instance->bulk_mutex);
  17350. + if (ret != 0)
  17351. + return ret;
  17352. +
  17353. + rd_len = msg->u.buffer_from_host.buffer_header.length;
  17354. +
  17355. + /* take buffer from queue */
  17356. + spin_lock_irqsave(&msg_context->u.bulk.port->slock, flags);
  17357. + if (list_empty(&msg_context->u.bulk.port->buffers)) {
  17358. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  17359. + pr_err("buffer list empty trying to submit bulk receive\n");
  17360. +
  17361. + /* todo: this is a serious error, we should never have
  17362. + * commited a buffer_to_host operation to the mmal
  17363. + * port without the buffer to back it up (underflow
  17364. + * handling) and there is no obvious way to deal with
  17365. + * this - how is the mmal servie going to react when
  17366. + * we fail to do the xfer and reschedule a buffer when
  17367. + * it arrives? perhaps a starved flag to indicate a
  17368. + * waiting bulk receive?
  17369. + */
  17370. +
  17371. + mutex_unlock(&instance->bulk_mutex);
  17372. +
  17373. + return -EINVAL;
  17374. + }
  17375. +
  17376. + msg_context->u.bulk.buffer =
  17377. + list_entry(msg_context->u.bulk.port->buffers.next,
  17378. + struct mmal_buffer, list);
  17379. + list_del(&msg_context->u.bulk.buffer->list);
  17380. +
  17381. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  17382. +
  17383. + /* ensure we do not overrun the available buffer */
  17384. + if (rd_len > msg_context->u.bulk.buffer->buffer_size) {
  17385. + rd_len = msg_context->u.bulk.buffer->buffer_size;
  17386. + pr_warn("short read as not enough receive buffer space\n");
  17387. + /* todo: is this the correct response, what happens to
  17388. + * the rest of the message data?
  17389. + */
  17390. + }
  17391. +
  17392. + /* store length */
  17393. + msg_context->u.bulk.buffer_used = rd_len;
  17394. + msg_context->u.bulk.mmal_flags =
  17395. + msg->u.buffer_from_host.buffer_header.flags;
  17396. + msg_context->u.bulk.dts = msg->u.buffer_from_host.buffer_header.dts;
  17397. + msg_context->u.bulk.pts = msg->u.buffer_from_host.buffer_header.pts;
  17398. +
  17399. + // only need to flush L1 cache here, as VCHIQ takes care of the L2
  17400. + // cache.
  17401. + __cpuc_flush_dcache_area(msg_context->u.bulk.buffer->buffer, rd_len);
  17402. +
  17403. + /* queue the bulk submission */
  17404. + vchi_service_use(instance->handle);
  17405. + ret = vchi_bulk_queue_receive(instance->handle,
  17406. + msg_context->u.bulk.buffer->buffer,
  17407. + /* Actual receive needs to be a multiple
  17408. + * of 4 bytes
  17409. + */
  17410. + (rd_len + 3) & ~3,
  17411. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
  17412. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
  17413. + msg_context);
  17414. +
  17415. + vchi_service_release(instance->handle);
  17416. +
  17417. + if (ret != 0) {
  17418. + /* callback will not be clearing the mutex */
  17419. + mutex_unlock(&instance->bulk_mutex);
  17420. + }
  17421. +
  17422. + return ret;
  17423. +}
  17424. +
  17425. +/* enque a dummy bulk receive for a given message context */
  17426. +static int dummy_bulk_receive(struct vchiq_mmal_instance *instance,
  17427. + struct mmal_msg_context *msg_context)
  17428. +{
  17429. + int ret;
  17430. +
  17431. + /* bulk mutex stops other bulk operations while we have a
  17432. + * receive in progress - released in callback
  17433. + */
  17434. + ret = mutex_lock_interruptible(&instance->bulk_mutex);
  17435. + if (ret != 0)
  17436. + return ret;
  17437. +
  17438. + /* zero length indicates this was a dummy transfer */
  17439. + msg_context->u.bulk.buffer_used = 0;
  17440. +
  17441. + /* queue the bulk submission */
  17442. + vchi_service_use(instance->handle);
  17443. +
  17444. + ret = vchi_bulk_queue_receive(instance->handle,
  17445. + instance->bulk_scratch,
  17446. + 8,
  17447. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
  17448. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
  17449. + msg_context);
  17450. +
  17451. + vchi_service_release(instance->handle);
  17452. +
  17453. + if (ret != 0) {
  17454. + /* callback will not be clearing the mutex */
  17455. + mutex_unlock(&instance->bulk_mutex);
  17456. + }
  17457. +
  17458. + return ret;
  17459. +}
  17460. +
  17461. +/* data in message, memcpy from packet into output buffer */
  17462. +static int inline_receive(struct vchiq_mmal_instance *instance,
  17463. + struct mmal_msg *msg,
  17464. + struct mmal_msg_context *msg_context)
  17465. +{
  17466. + unsigned long flags = 0;
  17467. +
  17468. + /* take buffer from queue */
  17469. + spin_lock_irqsave(&msg_context->u.bulk.port->slock, flags);
  17470. + if (list_empty(&msg_context->u.bulk.port->buffers)) {
  17471. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  17472. + pr_err("buffer list empty trying to receive inline\n");
  17473. +
  17474. + /* todo: this is a serious error, we should never have
  17475. + * commited a buffer_to_host operation to the mmal
  17476. + * port without the buffer to back it up (with
  17477. + * underflow handling) and there is no obvious way to
  17478. + * deal with this. Less bad than the bulk case as we
  17479. + * can just drop this on the floor but...unhelpful
  17480. + */
  17481. + return -EINVAL;
  17482. + }
  17483. +
  17484. + msg_context->u.bulk.buffer =
  17485. + list_entry(msg_context->u.bulk.port->buffers.next,
  17486. + struct mmal_buffer, list);
  17487. + list_del(&msg_context->u.bulk.buffer->list);
  17488. +
  17489. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  17490. +
  17491. + memcpy(msg_context->u.bulk.buffer->buffer,
  17492. + msg->u.buffer_from_host.short_data,
  17493. + msg->u.buffer_from_host.payload_in_message);
  17494. +
  17495. + msg_context->u.bulk.buffer_used =
  17496. + msg->u.buffer_from_host.payload_in_message;
  17497. +
  17498. + return 0;
  17499. +}
  17500. +
  17501. +/* queue the buffer availability with MMAL_MSG_TYPE_BUFFER_FROM_HOST */
  17502. +static int
  17503. +buffer_from_host(struct vchiq_mmal_instance *instance,
  17504. + struct vchiq_mmal_port *port, struct mmal_buffer *buf)
  17505. +{
  17506. + struct mmal_msg_context *msg_context;
  17507. + struct mmal_msg m;
  17508. + int ret;
  17509. +
  17510. + pr_debug("instance:%p buffer:%p\n", instance->handle, buf);
  17511. +
  17512. + /* bulk mutex stops other bulk operations while we
  17513. + * have a receive in progress
  17514. + */
  17515. + if (mutex_lock_interruptible(&instance->bulk_mutex))
  17516. + return -EINTR;
  17517. +
  17518. + /* get context */
  17519. + msg_context = get_msg_context(instance);
  17520. + if (msg_context == NULL)
  17521. + return -ENOMEM;
  17522. +
  17523. + /* store bulk message context for when data arrives */
  17524. + msg_context->u.bulk.instance = instance;
  17525. + msg_context->u.bulk.port = port;
  17526. + msg_context->u.bulk.buffer = NULL; /* not valid until bulk xfer */
  17527. + msg_context->u.bulk.buffer_used = 0;
  17528. +
  17529. + /* initialise work structure ready to schedule callback */
  17530. + INIT_WORK(&msg_context->u.bulk.work, buffer_work_cb);
  17531. +
  17532. + /* prep the buffer from host message */
  17533. + memset(&m, 0xbc, sizeof(m)); /* just to make debug clearer */
  17534. +
  17535. + m.h.type = MMAL_MSG_TYPE_BUFFER_FROM_HOST;
  17536. + m.h.magic = MMAL_MAGIC;
  17537. + m.h.context = msg_context;
  17538. + m.h.status = 0;
  17539. +
  17540. + /* drvbuf is our private data passed back */
  17541. + m.u.buffer_from_host.drvbuf.magic = MMAL_MAGIC;
  17542. + m.u.buffer_from_host.drvbuf.component_handle = port->component->handle;
  17543. + m.u.buffer_from_host.drvbuf.port_handle = port->handle;
  17544. + m.u.buffer_from_host.drvbuf.client_context = msg_context;
  17545. +
  17546. + /* buffer header */
  17547. + m.u.buffer_from_host.buffer_header.cmd = 0;
  17548. + m.u.buffer_from_host.buffer_header.data = buf->buffer;
  17549. + m.u.buffer_from_host.buffer_header.alloc_size = buf->buffer_size;
  17550. + m.u.buffer_from_host.buffer_header.length = 0; /* nothing used yet */
  17551. + m.u.buffer_from_host.buffer_header.offset = 0; /* no offset */
  17552. + m.u.buffer_from_host.buffer_header.flags = 0; /* no flags */
  17553. + m.u.buffer_from_host.buffer_header.pts = MMAL_TIME_UNKNOWN;
  17554. + m.u.buffer_from_host.buffer_header.dts = MMAL_TIME_UNKNOWN;
  17555. +
  17556. + /* clear buffer type sepecific data */
  17557. + memset(&m.u.buffer_from_host.buffer_header_type_specific, 0,
  17558. + sizeof(m.u.buffer_from_host.buffer_header_type_specific));
  17559. +
  17560. + /* no payload in message */
  17561. + m.u.buffer_from_host.payload_in_message = 0;
  17562. +
  17563. + vchi_service_use(instance->handle);
  17564. +
  17565. + ret = vchi_msg_queue(instance->handle, &m,
  17566. + sizeof(struct mmal_msg_header) +
  17567. + sizeof(m.u.buffer_from_host),
  17568. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  17569. +
  17570. + if (ret != 0) {
  17571. + release_msg_context(msg_context);
  17572. + /* todo: is this correct error value? */
  17573. + }
  17574. +
  17575. + vchi_service_release(instance->handle);
  17576. +
  17577. + mutex_unlock(&instance->bulk_mutex);
  17578. +
  17579. + return ret;
  17580. +}
  17581. +
  17582. +/* submit a buffer to the mmal sevice
  17583. + *
  17584. + * the buffer_from_host uses size data from the ports next available
  17585. + * mmal_buffer and deals with there being no buffer available by
  17586. + * incrementing the underflow for later
  17587. + */
  17588. +static int port_buffer_from_host(struct vchiq_mmal_instance *instance,
  17589. + struct vchiq_mmal_port *port)
  17590. +{
  17591. + int ret;
  17592. + struct mmal_buffer *buf;
  17593. + unsigned long flags = 0;
  17594. +
  17595. + if (!port->enabled)
  17596. + return -EINVAL;
  17597. +
  17598. + /* peek buffer from queue */
  17599. + spin_lock_irqsave(&port->slock, flags);
  17600. + if (list_empty(&port->buffers)) {
  17601. + port->buffer_underflow++;
  17602. + spin_unlock_irqrestore(&port->slock, flags);
  17603. + return -ENOSPC;
  17604. + }
  17605. +
  17606. + buf = list_entry(port->buffers.next, struct mmal_buffer, list);
  17607. +
  17608. + spin_unlock_irqrestore(&port->slock, flags);
  17609. +
  17610. + /* issue buffer to mmal service */
  17611. + ret = buffer_from_host(instance, port, buf);
  17612. + if (ret) {
  17613. + pr_err("adding buffer header failed\n");
  17614. + /* todo: how should this be dealt with */
  17615. + }
  17616. +
  17617. + return ret;
  17618. +}
  17619. +
  17620. +/* deals with receipt of buffer to host message */
  17621. +static void buffer_to_host_cb(struct vchiq_mmal_instance *instance,
  17622. + struct mmal_msg *msg, u32 msg_len)
  17623. +{
  17624. + struct mmal_msg_context *msg_context;
  17625. +
  17626. + pr_debug("buffer_to_host_cb: instance:%p msg:%p msg_len:%d\n",
  17627. + instance, msg, msg_len);
  17628. +
  17629. + if (msg->u.buffer_from_host.drvbuf.magic == MMAL_MAGIC) {
  17630. + msg_context = msg->u.buffer_from_host.drvbuf.client_context;
  17631. + } else {
  17632. + pr_err("MMAL_MSG_TYPE_BUFFER_TO_HOST with bad magic\n");
  17633. + return;
  17634. + }
  17635. +
  17636. + if (msg->h.status != MMAL_MSG_STATUS_SUCCESS) {
  17637. + /* message reception had an error */
  17638. + pr_warn("error %d in reply\n", msg->h.status);
  17639. +
  17640. + msg_context->u.bulk.status = msg->h.status;
  17641. +
  17642. + } else if (msg->u.buffer_from_host.buffer_header.length == 0) {
  17643. + /* empty buffer */
  17644. + if (msg->u.buffer_from_host.buffer_header.flags &
  17645. + MMAL_BUFFER_HEADER_FLAG_EOS) {
  17646. + msg_context->u.bulk.status =
  17647. + dummy_bulk_receive(instance, msg_context);
  17648. + if (msg_context->u.bulk.status == 0)
  17649. + return; /* successful bulk submission, bulk
  17650. + * completion will trigger callback
  17651. + */
  17652. + } else {
  17653. + /* do callback with empty buffer - not EOS though */
  17654. + msg_context->u.bulk.status = 0;
  17655. + msg_context->u.bulk.buffer_used = 0;
  17656. + }
  17657. + } else if (msg->u.buffer_from_host.payload_in_message == 0) {
  17658. + /* data is not in message, queue a bulk receive */
  17659. + msg_context->u.bulk.status =
  17660. + bulk_receive(instance, msg, msg_context);
  17661. + if (msg_context->u.bulk.status == 0)
  17662. + return; /* successful bulk submission, bulk
  17663. + * completion will trigger callback
  17664. + */
  17665. +
  17666. + /* failed to submit buffer, this will end badly */
  17667. + pr_err("error %d on bulk submission\n",
  17668. + msg_context->u.bulk.status);
  17669. +
  17670. + } else if (msg->u.buffer_from_host.payload_in_message <=
  17671. + MMAL_VC_SHORT_DATA) {
  17672. + /* data payload within message */
  17673. + msg_context->u.bulk.status = inline_receive(instance, msg,
  17674. + msg_context);
  17675. + } else {
  17676. + pr_err("message with invalid short payload\n");
  17677. +
  17678. + /* signal error */
  17679. + msg_context->u.bulk.status = -EINVAL;
  17680. + msg_context->u.bulk.buffer_used =
  17681. + msg->u.buffer_from_host.payload_in_message;
  17682. + }
  17683. +
  17684. + /* replace the buffer header */
  17685. + port_buffer_from_host(instance, msg_context->u.bulk.port);
  17686. +
  17687. + /* schedule the port callback */
  17688. + schedule_work(&msg_context->u.bulk.work);
  17689. +}
  17690. +
  17691. +static void bulk_receive_cb(struct vchiq_mmal_instance *instance,
  17692. + struct mmal_msg_context *msg_context)
  17693. +{
  17694. + /* bulk receive operation complete */
  17695. + mutex_unlock(&msg_context->u.bulk.instance->bulk_mutex);
  17696. +
  17697. + /* replace the buffer header */
  17698. + port_buffer_from_host(msg_context->u.bulk.instance,
  17699. + msg_context->u.bulk.port);
  17700. +
  17701. + msg_context->u.bulk.status = 0;
  17702. +
  17703. + /* schedule the port callback */
  17704. + schedule_work(&msg_context->u.bulk.work);
  17705. +}
  17706. +
  17707. +static void bulk_abort_cb(struct vchiq_mmal_instance *instance,
  17708. + struct mmal_msg_context *msg_context)
  17709. +{
  17710. + pr_err("%s: bulk ABORTED msg_context:%p\n", __func__, msg_context);
  17711. +
  17712. + /* bulk receive operation complete */
  17713. + mutex_unlock(&msg_context->u.bulk.instance->bulk_mutex);
  17714. +
  17715. + /* replace the buffer header */
  17716. + port_buffer_from_host(msg_context->u.bulk.instance,
  17717. + msg_context->u.bulk.port);
  17718. +
  17719. + msg_context->u.bulk.status = -EINTR;
  17720. +
  17721. + schedule_work(&msg_context->u.bulk.work);
  17722. +}
  17723. +
  17724. +/* incoming event service callback */
  17725. +static void service_callback(void *param,
  17726. + const VCHI_CALLBACK_REASON_T reason,
  17727. + void *bulk_ctx)
  17728. +{
  17729. + struct vchiq_mmal_instance *instance = param;
  17730. + int status;
  17731. + u32 msg_len;
  17732. + struct mmal_msg *msg;
  17733. + VCHI_HELD_MSG_T msg_handle;
  17734. +
  17735. + if (!instance) {
  17736. + pr_err("Message callback passed NULL instance\n");
  17737. + return;
  17738. + }
  17739. +
  17740. + switch (reason) {
  17741. + case VCHI_CALLBACK_MSG_AVAILABLE:
  17742. + status = vchi_msg_hold(instance->handle, (void **)&msg,
  17743. + &msg_len, VCHI_FLAGS_NONE, &msg_handle);
  17744. + if (status) {
  17745. + pr_err("Unable to dequeue a message (%d)\n", status);
  17746. + break;
  17747. + }
  17748. +
  17749. + DBG_DUMP_MSG(msg, msg_len, "<<< reply message");
  17750. +
  17751. + /* handling is different for buffer messages */
  17752. + switch (msg->h.type) {
  17753. +
  17754. + case MMAL_MSG_TYPE_BUFFER_FROM_HOST:
  17755. + vchi_held_msg_release(&msg_handle);
  17756. + break;
  17757. +
  17758. + case MMAL_MSG_TYPE_EVENT_TO_HOST:
  17759. + event_to_host_cb(instance, msg, msg_len);
  17760. + vchi_held_msg_release(&msg_handle);
  17761. +
  17762. + break;
  17763. +
  17764. + case MMAL_MSG_TYPE_BUFFER_TO_HOST:
  17765. + buffer_to_host_cb(instance, msg, msg_len);
  17766. + vchi_held_msg_release(&msg_handle);
  17767. + break;
  17768. +
  17769. + default:
  17770. + /* messages dependant on header context to complete */
  17771. +
  17772. + /* todo: the msg.context really ought to be sanity
  17773. + * checked before we just use it, afaict it comes back
  17774. + * and is used raw from the videocore. Perhaps it
  17775. + * should be verified the address lies in the kernel
  17776. + * address space.
  17777. + */
  17778. + if (msg->h.context == NULL) {
  17779. + pr_err("received message context was null!\n");
  17780. + vchi_held_msg_release(&msg_handle);
  17781. + break;
  17782. + }
  17783. +
  17784. + /* fill in context values */
  17785. + msg->h.context->u.sync.msg_handle = msg_handle;
  17786. + msg->h.context->u.sync.msg = msg;
  17787. + msg->h.context->u.sync.msg_len = msg_len;
  17788. +
  17789. + /* todo: should this check (completion_done()
  17790. + * == 1) for no one waiting? or do we need a
  17791. + * flag to tell us the completion has been
  17792. + * interrupted so we can free the message and
  17793. + * its context. This probably also solves the
  17794. + * message arriving after interruption todo
  17795. + * below
  17796. + */
  17797. +
  17798. + /* complete message so caller knows it happened */
  17799. + complete(&msg->h.context->u.sync.cmplt);
  17800. + break;
  17801. + }
  17802. +
  17803. + break;
  17804. +
  17805. + case VCHI_CALLBACK_BULK_RECEIVED:
  17806. + bulk_receive_cb(instance, bulk_ctx);
  17807. + break;
  17808. +
  17809. + case VCHI_CALLBACK_BULK_RECEIVE_ABORTED:
  17810. + bulk_abort_cb(instance, bulk_ctx);
  17811. + break;
  17812. +
  17813. + case VCHI_CALLBACK_SERVICE_CLOSED:
  17814. + /* TODO: consider if this requires action if received when
  17815. + * driver is not explicitly closing the service
  17816. + */
  17817. + break;
  17818. +
  17819. + default:
  17820. + pr_err("Received unhandled message reason %d\n", reason);
  17821. + break;
  17822. + }
  17823. +}
  17824. +
  17825. +static int send_synchronous_mmal_msg(struct vchiq_mmal_instance *instance,
  17826. + struct mmal_msg *msg,
  17827. + unsigned int payload_len,
  17828. + struct mmal_msg **msg_out,
  17829. + VCHI_HELD_MSG_T *msg_handle_out)
  17830. +{
  17831. + struct mmal_msg_context msg_context;
  17832. + int ret;
  17833. +
  17834. + /* payload size must not cause message to exceed max size */
  17835. + if (payload_len >
  17836. + (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header))) {
  17837. + pr_err("payload length %d exceeds max:%d\n", payload_len,
  17838. + (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header)));
  17839. + return -EINVAL;
  17840. + }
  17841. +
  17842. + init_completion(&msg_context.u.sync.cmplt);
  17843. +
  17844. + msg->h.magic = MMAL_MAGIC;
  17845. + msg->h.context = &msg_context;
  17846. + msg->h.status = 0;
  17847. +
  17848. + DBG_DUMP_MSG(msg, (sizeof(struct mmal_msg_header) + payload_len),
  17849. + ">>> sync message");
  17850. +
  17851. + vchi_service_use(instance->handle);
  17852. +
  17853. + ret = vchi_msg_queue(instance->handle,
  17854. + msg,
  17855. + sizeof(struct mmal_msg_header) + payload_len,
  17856. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  17857. +
  17858. + vchi_service_release(instance->handle);
  17859. +
  17860. + if (ret) {
  17861. + pr_err("error %d queuing message\n", ret);
  17862. + return ret;
  17863. + }
  17864. +
  17865. + ret = wait_for_completion_timeout(&msg_context.u.sync.cmplt, 3*HZ);
  17866. + if (ret <= 0) {
  17867. + pr_err("error %d waiting for sync completion\n", ret);
  17868. + if (ret == 0)
  17869. + ret = -ETIME;
  17870. + /* todo: what happens if the message arrives after aborting */
  17871. + return ret;
  17872. + }
  17873. +
  17874. + *msg_out = msg_context.u.sync.msg;
  17875. + *msg_handle_out = msg_context.u.sync.msg_handle;
  17876. +
  17877. + return 0;
  17878. +}
  17879. +
  17880. +static void dump_port_info(struct vchiq_mmal_port *port)
  17881. +{
  17882. + pr_debug("port handle:0x%x enabled:%d\n", port->handle, port->enabled);
  17883. +
  17884. + pr_debug("buffer minimum num:%d size:%d align:%d\n",
  17885. + port->minimum_buffer.num,
  17886. + port->minimum_buffer.size, port->minimum_buffer.alignment);
  17887. +
  17888. + pr_debug("buffer recommended num:%d size:%d align:%d\n",
  17889. + port->recommended_buffer.num,
  17890. + port->recommended_buffer.size,
  17891. + port->recommended_buffer.alignment);
  17892. +
  17893. + pr_debug("buffer current values num:%d size:%d align:%d\n",
  17894. + port->current_buffer.num,
  17895. + port->current_buffer.size, port->current_buffer.alignment);
  17896. +
  17897. + pr_debug("elementry stream: type:%d encoding:0x%x varient:0x%x\n",
  17898. + port->format.type,
  17899. + port->format.encoding, port->format.encoding_variant);
  17900. +
  17901. + pr_debug(" bitrate:%d flags:0x%x\n",
  17902. + port->format.bitrate, port->format.flags);
  17903. +
  17904. + if (port->format.type == MMAL_ES_TYPE_VIDEO) {
  17905. + pr_debug
  17906. + ("es video format: width:%d height:%d colourspace:0x%x\n",
  17907. + port->es.video.width, port->es.video.height,
  17908. + port->es.video.color_space);
  17909. +
  17910. + pr_debug(" : crop xywh %d,%d,%d,%d\n",
  17911. + port->es.video.crop.x,
  17912. + port->es.video.crop.y,
  17913. + port->es.video.crop.width, port->es.video.crop.height);
  17914. + pr_debug(" : framerate %d/%d aspect %d/%d\n",
  17915. + port->es.video.frame_rate.num,
  17916. + port->es.video.frame_rate.den,
  17917. + port->es.video.par.num, port->es.video.par.den);
  17918. + }
  17919. +}
  17920. +
  17921. +static void port_to_mmal_msg(struct vchiq_mmal_port *port, struct mmal_port *p)
  17922. +{
  17923. +
  17924. + /* todo do readonly fields need setting at all? */
  17925. + p->type = port->type;
  17926. + p->index = port->index;
  17927. + p->index_all = 0;
  17928. + p->is_enabled = port->enabled;
  17929. + p->buffer_num_min = port->minimum_buffer.num;
  17930. + p->buffer_size_min = port->minimum_buffer.size;
  17931. + p->buffer_alignment_min = port->minimum_buffer.alignment;
  17932. + p->buffer_num_recommended = port->recommended_buffer.num;
  17933. + p->buffer_size_recommended = port->recommended_buffer.size;
  17934. +
  17935. + /* only three writable fields in a port */
  17936. + p->buffer_num = port->current_buffer.num;
  17937. + p->buffer_size = port->current_buffer.size;
  17938. + p->userdata = port;
  17939. +}
  17940. +
  17941. +static int port_info_set(struct vchiq_mmal_instance *instance,
  17942. + struct vchiq_mmal_port *port)
  17943. +{
  17944. + int ret;
  17945. + struct mmal_msg m;
  17946. + struct mmal_msg *rmsg;
  17947. + VCHI_HELD_MSG_T rmsg_handle;
  17948. +
  17949. + pr_debug("setting port info port %p\n", port);
  17950. + if (!port)
  17951. + return -1;
  17952. + dump_port_info(port);
  17953. +
  17954. + m.h.type = MMAL_MSG_TYPE_PORT_INFO_SET;
  17955. +
  17956. + m.u.port_info_set.component_handle = port->component->handle;
  17957. + m.u.port_info_set.port_type = port->type;
  17958. + m.u.port_info_set.port_index = port->index;
  17959. +
  17960. + port_to_mmal_msg(port, &m.u.port_info_set.port);
  17961. +
  17962. + /* elementry stream format setup */
  17963. + m.u.port_info_set.format.type = port->format.type;
  17964. + m.u.port_info_set.format.encoding = port->format.encoding;
  17965. + m.u.port_info_set.format.encoding_variant =
  17966. + port->format.encoding_variant;
  17967. + m.u.port_info_set.format.bitrate = port->format.bitrate;
  17968. + m.u.port_info_set.format.flags = port->format.flags;
  17969. +
  17970. + memcpy(&m.u.port_info_set.es, &port->es,
  17971. + sizeof(union mmal_es_specific_format));
  17972. +
  17973. + m.u.port_info_set.format.extradata_size = port->format.extradata_size;
  17974. + memcpy(rmsg->u.port_info_set.extradata, port->format.extradata,
  17975. + port->format.extradata_size);
  17976. +
  17977. + ret = send_synchronous_mmal_msg(instance, &m,
  17978. + sizeof(m.u.port_info_set),
  17979. + &rmsg, &rmsg_handle);
  17980. + if (ret)
  17981. + return ret;
  17982. +
  17983. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_SET) {
  17984. + /* got an unexpected message type in reply */
  17985. + ret = -EINVAL;
  17986. + goto release_msg;
  17987. + }
  17988. +
  17989. + /* return operation status */
  17990. + ret = -rmsg->u.port_info_get_reply.status;
  17991. +
  17992. + pr_debug("%s:result:%d component:0x%x port:%d\n", __func__, ret,
  17993. + port->component->handle, port->handle);
  17994. +
  17995. +release_msg:
  17996. + vchi_held_msg_release(&rmsg_handle);
  17997. +
  17998. + return ret;
  17999. +
  18000. +}
  18001. +
  18002. +/* use port info get message to retrive port information */
  18003. +static int port_info_get(struct vchiq_mmal_instance *instance,
  18004. + struct vchiq_mmal_port *port)
  18005. +{
  18006. + int ret;
  18007. + struct mmal_msg m;
  18008. + struct mmal_msg *rmsg;
  18009. + VCHI_HELD_MSG_T rmsg_handle;
  18010. +
  18011. + /* port info time */
  18012. + m.h.type = MMAL_MSG_TYPE_PORT_INFO_GET;
  18013. + m.u.port_info_get.component_handle = port->component->handle;
  18014. + m.u.port_info_get.port_type = port->type;
  18015. + m.u.port_info_get.index = port->index;
  18016. +
  18017. + ret = send_synchronous_mmal_msg(instance, &m,
  18018. + sizeof(m.u.port_info_get),
  18019. + &rmsg, &rmsg_handle);
  18020. + if (ret)
  18021. + return ret;
  18022. +
  18023. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_GET) {
  18024. + /* got an unexpected message type in reply */
  18025. + ret = -EINVAL;
  18026. + goto release_msg;
  18027. + }
  18028. +
  18029. + /* return operation status */
  18030. + ret = -rmsg->u.port_info_get_reply.status;
  18031. + if (ret != MMAL_MSG_STATUS_SUCCESS)
  18032. + goto release_msg;
  18033. +
  18034. + if (rmsg->u.port_info_get_reply.port.is_enabled == 0)
  18035. + port->enabled = false;
  18036. + else
  18037. + port->enabled = true;
  18038. +
  18039. + /* copy the values out of the message */
  18040. + port->handle = rmsg->u.port_info_get_reply.port_handle;
  18041. +
  18042. + /* port type and index cached to use on port info set becuase
  18043. + * it does not use a port handle
  18044. + */
  18045. + port->type = rmsg->u.port_info_get_reply.port_type;
  18046. + port->index = rmsg->u.port_info_get_reply.port_index;
  18047. +
  18048. + port->minimum_buffer.num =
  18049. + rmsg->u.port_info_get_reply.port.buffer_num_min;
  18050. + port->minimum_buffer.size =
  18051. + rmsg->u.port_info_get_reply.port.buffer_size_min;
  18052. + port->minimum_buffer.alignment =
  18053. + rmsg->u.port_info_get_reply.port.buffer_alignment_min;
  18054. +
  18055. + port->recommended_buffer.alignment =
  18056. + rmsg->u.port_info_get_reply.port.buffer_alignment_min;
  18057. + port->recommended_buffer.num =
  18058. + rmsg->u.port_info_get_reply.port.buffer_num_recommended;
  18059. +
  18060. + port->current_buffer.num = rmsg->u.port_info_get_reply.port.buffer_num;
  18061. + port->current_buffer.size =
  18062. + rmsg->u.port_info_get_reply.port.buffer_size;
  18063. +
  18064. + /* stream format */
  18065. + port->format.type = rmsg->u.port_info_get_reply.format.type;
  18066. + port->format.encoding = rmsg->u.port_info_get_reply.format.encoding;
  18067. + port->format.encoding_variant =
  18068. + rmsg->u.port_info_get_reply.format.encoding_variant;
  18069. + port->format.bitrate = rmsg->u.port_info_get_reply.format.bitrate;
  18070. + port->format.flags = rmsg->u.port_info_get_reply.format.flags;
  18071. +
  18072. + /* elementry stream format */
  18073. + memcpy(&port->es,
  18074. + &rmsg->u.port_info_get_reply.es,
  18075. + sizeof(union mmal_es_specific_format));
  18076. + port->format.es = &port->es;
  18077. +
  18078. + port->format.extradata_size =
  18079. + rmsg->u.port_info_get_reply.format.extradata_size;
  18080. + memcpy(port->format.extradata,
  18081. + rmsg->u.port_info_get_reply.extradata,
  18082. + port->format.extradata_size);
  18083. +
  18084. + pr_debug("received port info\n");
  18085. + dump_port_info(port);
  18086. +
  18087. +release_msg:
  18088. +
  18089. + pr_debug("%s:result:%d component:0x%x port:%d\n",
  18090. + __func__, ret, port->component->handle, port->handle);
  18091. +
  18092. + vchi_held_msg_release(&rmsg_handle);
  18093. +
  18094. + return ret;
  18095. +}
  18096. +
  18097. +/* create comonent on vc */
  18098. +static int create_component(struct vchiq_mmal_instance *instance,
  18099. + struct vchiq_mmal_component *component,
  18100. + const char *name)
  18101. +{
  18102. + int ret;
  18103. + struct mmal_msg m;
  18104. + struct mmal_msg *rmsg;
  18105. + VCHI_HELD_MSG_T rmsg_handle;
  18106. +
  18107. + /* build component create message */
  18108. + m.h.type = MMAL_MSG_TYPE_COMPONENT_CREATE;
  18109. + m.u.component_create.client_component = component;
  18110. + strncpy(m.u.component_create.name, name,
  18111. + sizeof(m.u.component_create.name));
  18112. +
  18113. + ret = send_synchronous_mmal_msg(instance, &m,
  18114. + sizeof(m.u.component_create),
  18115. + &rmsg, &rmsg_handle);
  18116. + if (ret)
  18117. + return ret;
  18118. +
  18119. + if (rmsg->h.type != m.h.type) {
  18120. + /* got an unexpected message type in reply */
  18121. + ret = -EINVAL;
  18122. + goto release_msg;
  18123. + }
  18124. +
  18125. + ret = -rmsg->u.component_create_reply.status;
  18126. + if (ret != MMAL_MSG_STATUS_SUCCESS)
  18127. + goto release_msg;
  18128. +
  18129. + /* a valid component response received */
  18130. + component->handle = rmsg->u.component_create_reply.component_handle;
  18131. + component->inputs = rmsg->u.component_create_reply.input_num;
  18132. + component->outputs = rmsg->u.component_create_reply.output_num;
  18133. + component->clocks = rmsg->u.component_create_reply.clock_num;
  18134. +
  18135. + pr_debug("Component handle:0x%x in:%d out:%d clock:%d\n",
  18136. + component->handle,
  18137. + component->inputs, component->outputs, component->clocks);
  18138. +
  18139. +release_msg:
  18140. + vchi_held_msg_release(&rmsg_handle);
  18141. +
  18142. + return ret;
  18143. +}
  18144. +
  18145. +/* destroys a component on vc */
  18146. +static int destroy_component(struct vchiq_mmal_instance *instance,
  18147. + struct vchiq_mmal_component *component)
  18148. +{
  18149. + int ret;
  18150. + struct mmal_msg m;
  18151. + struct mmal_msg *rmsg;
  18152. + VCHI_HELD_MSG_T rmsg_handle;
  18153. +
  18154. + m.h.type = MMAL_MSG_TYPE_COMPONENT_DESTROY;
  18155. + m.u.component_destroy.component_handle = component->handle;
  18156. +
  18157. + ret = send_synchronous_mmal_msg(instance, &m,
  18158. + sizeof(m.u.component_destroy),
  18159. + &rmsg, &rmsg_handle);
  18160. + if (ret)
  18161. + return ret;
  18162. +
  18163. + if (rmsg->h.type != m.h.type) {
  18164. + /* got an unexpected message type in reply */
  18165. + ret = -EINVAL;
  18166. + goto release_msg;
  18167. + }
  18168. +
  18169. + ret = -rmsg->u.component_destroy_reply.status;
  18170. +
  18171. +release_msg:
  18172. +
  18173. + vchi_held_msg_release(&rmsg_handle);
  18174. +
  18175. + return ret;
  18176. +}
  18177. +
  18178. +/* enable a component on vc */
  18179. +static int enable_component(struct vchiq_mmal_instance *instance,
  18180. + struct vchiq_mmal_component *component)
  18181. +{
  18182. + int ret;
  18183. + struct mmal_msg m;
  18184. + struct mmal_msg *rmsg;
  18185. + VCHI_HELD_MSG_T rmsg_handle;
  18186. +
  18187. + m.h.type = MMAL_MSG_TYPE_COMPONENT_ENABLE;
  18188. + m.u.component_enable.component_handle = component->handle;
  18189. +
  18190. + ret = send_synchronous_mmal_msg(instance, &m,
  18191. + sizeof(m.u.component_enable),
  18192. + &rmsg, &rmsg_handle);
  18193. + if (ret)
  18194. + return ret;
  18195. +
  18196. + if (rmsg->h.type != m.h.type) {
  18197. + /* got an unexpected message type in reply */
  18198. + ret = -EINVAL;
  18199. + goto release_msg;
  18200. + }
  18201. +
  18202. + ret = -rmsg->u.component_enable_reply.status;
  18203. +
  18204. +release_msg:
  18205. + vchi_held_msg_release(&rmsg_handle);
  18206. +
  18207. + return ret;
  18208. +}
  18209. +
  18210. +/* disable a component on vc */
  18211. +static int disable_component(struct vchiq_mmal_instance *instance,
  18212. + struct vchiq_mmal_component *component)
  18213. +{
  18214. + int ret;
  18215. + struct mmal_msg m;
  18216. + struct mmal_msg *rmsg;
  18217. + VCHI_HELD_MSG_T rmsg_handle;
  18218. +
  18219. + m.h.type = MMAL_MSG_TYPE_COMPONENT_DISABLE;
  18220. + m.u.component_disable.component_handle = component->handle;
  18221. +
  18222. + ret = send_synchronous_mmal_msg(instance, &m,
  18223. + sizeof(m.u.component_disable),
  18224. + &rmsg, &rmsg_handle);
  18225. + if (ret)
  18226. + return ret;
  18227. +
  18228. + if (rmsg->h.type != m.h.type) {
  18229. + /* got an unexpected message type in reply */
  18230. + ret = -EINVAL;
  18231. + goto release_msg;
  18232. + }
  18233. +
  18234. + ret = -rmsg->u.component_disable_reply.status;
  18235. +
  18236. +release_msg:
  18237. +
  18238. + vchi_held_msg_release(&rmsg_handle);
  18239. +
  18240. + return ret;
  18241. +}
  18242. +
  18243. +/* get version of mmal implementation */
  18244. +static int get_version(struct vchiq_mmal_instance *instance,
  18245. + u32 *major_out, u32 *minor_out)
  18246. +{
  18247. + int ret;
  18248. + struct mmal_msg m;
  18249. + struct mmal_msg *rmsg;
  18250. + VCHI_HELD_MSG_T rmsg_handle;
  18251. +
  18252. + m.h.type = MMAL_MSG_TYPE_GET_VERSION;
  18253. +
  18254. + ret = send_synchronous_mmal_msg(instance, &m,
  18255. + sizeof(m.u.version),
  18256. + &rmsg, &rmsg_handle);
  18257. + if (ret)
  18258. + return ret;
  18259. +
  18260. + if (rmsg->h.type != m.h.type) {
  18261. + /* got an unexpected message type in reply */
  18262. + ret = -EINVAL;
  18263. + goto release_msg;
  18264. + }
  18265. +
  18266. + *major_out = rmsg->u.version.major;
  18267. + *minor_out = rmsg->u.version.minor;
  18268. +
  18269. +release_msg:
  18270. + vchi_held_msg_release(&rmsg_handle);
  18271. +
  18272. + return ret;
  18273. +}
  18274. +
  18275. +/* do a port action with a port as a parameter */
  18276. +static int port_action_port(struct vchiq_mmal_instance *instance,
  18277. + struct vchiq_mmal_port *port,
  18278. + enum mmal_msg_port_action_type action_type)
  18279. +{
  18280. + int ret;
  18281. + struct mmal_msg m;
  18282. + struct mmal_msg *rmsg;
  18283. + VCHI_HELD_MSG_T rmsg_handle;
  18284. +
  18285. + m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
  18286. + m.u.port_action_port.component_handle = port->component->handle;
  18287. + m.u.port_action_port.port_handle = port->handle;
  18288. + m.u.port_action_port.action = action_type;
  18289. +
  18290. + port_to_mmal_msg(port, &m.u.port_action_port.port);
  18291. +
  18292. + ret = send_synchronous_mmal_msg(instance, &m,
  18293. + sizeof(m.u.port_action_port),
  18294. + &rmsg, &rmsg_handle);
  18295. + if (ret)
  18296. + return ret;
  18297. +
  18298. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
  18299. + /* got an unexpected message type in reply */
  18300. + ret = -EINVAL;
  18301. + goto release_msg;
  18302. + }
  18303. +
  18304. + ret = -rmsg->u.port_action_reply.status;
  18305. +
  18306. + pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)\n",
  18307. + __func__,
  18308. + ret, port->component->handle, port->handle,
  18309. + port_action_type_names[action_type], action_type);
  18310. +
  18311. +release_msg:
  18312. + vchi_held_msg_release(&rmsg_handle);
  18313. +
  18314. + return ret;
  18315. +}
  18316. +
  18317. +/* do a port action with handles as parameters */
  18318. +static int port_action_handle(struct vchiq_mmal_instance *instance,
  18319. + struct vchiq_mmal_port *port,
  18320. + enum mmal_msg_port_action_type action_type,
  18321. + u32 connect_component_handle,
  18322. + u32 connect_port_handle)
  18323. +{
  18324. + int ret;
  18325. + struct mmal_msg m;
  18326. + struct mmal_msg *rmsg;
  18327. + VCHI_HELD_MSG_T rmsg_handle;
  18328. +
  18329. + m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
  18330. +
  18331. + m.u.port_action_handle.component_handle = port->component->handle;
  18332. + m.u.port_action_handle.port_handle = port->handle;
  18333. + m.u.port_action_handle.action = action_type;
  18334. +
  18335. + m.u.port_action_handle.connect_component_handle =
  18336. + connect_component_handle;
  18337. + m.u.port_action_handle.connect_port_handle = connect_port_handle;
  18338. +
  18339. + ret = send_synchronous_mmal_msg(instance, &m,
  18340. + sizeof(m.u.port_action_handle),
  18341. + &rmsg, &rmsg_handle);
  18342. + if (ret)
  18343. + return ret;
  18344. +
  18345. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
  18346. + /* got an unexpected message type in reply */
  18347. + ret = -EINVAL;
  18348. + goto release_msg;
  18349. + }
  18350. +
  18351. + ret = -rmsg->u.port_action_reply.status;
  18352. +
  18353. + pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)" \
  18354. + " connect component:0x%x connect port:%d\n",
  18355. + __func__,
  18356. + ret, port->component->handle, port->handle,
  18357. + port_action_type_names[action_type],
  18358. + action_type, connect_component_handle, connect_port_handle);
  18359. +
  18360. +release_msg:
  18361. + vchi_held_msg_release(&rmsg_handle);
  18362. +
  18363. + return ret;
  18364. +}
  18365. +
  18366. +static int port_parameter_set(struct vchiq_mmal_instance *instance,
  18367. + struct vchiq_mmal_port *port,
  18368. + u32 parameter_id, void *value, u32 value_size)
  18369. +{
  18370. + int ret;
  18371. + struct mmal_msg m;
  18372. + struct mmal_msg *rmsg;
  18373. + VCHI_HELD_MSG_T rmsg_handle;
  18374. +
  18375. + m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_SET;
  18376. +
  18377. + m.u.port_parameter_set.component_handle = port->component->handle;
  18378. + m.u.port_parameter_set.port_handle = port->handle;
  18379. + m.u.port_parameter_set.id = parameter_id;
  18380. + m.u.port_parameter_set.size = (2 * sizeof(u32)) + value_size;
  18381. + memcpy(&m.u.port_parameter_set.value, value, value_size);
  18382. +
  18383. + ret = send_synchronous_mmal_msg(instance, &m,
  18384. + (4 * sizeof(u32)) + value_size,
  18385. + &rmsg, &rmsg_handle);
  18386. + if (ret)
  18387. + return ret;
  18388. +
  18389. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_SET) {
  18390. + /* got an unexpected message type in reply */
  18391. + ret = -EINVAL;
  18392. + goto release_msg;
  18393. + }
  18394. +
  18395. + ret = -rmsg->u.port_parameter_set_reply.status;
  18396. +
  18397. + pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n",
  18398. + __func__,
  18399. + ret, port->component->handle, port->handle, parameter_id);
  18400. +
  18401. +release_msg:
  18402. + vchi_held_msg_release(&rmsg_handle);
  18403. +
  18404. + return ret;
  18405. +}
  18406. +
  18407. +static int port_parameter_get(struct vchiq_mmal_instance *instance,
  18408. + struct vchiq_mmal_port *port,
  18409. + u32 parameter_id, void *value, u32 *value_size)
  18410. +{
  18411. + int ret;
  18412. + struct mmal_msg m;
  18413. + struct mmal_msg *rmsg;
  18414. + VCHI_HELD_MSG_T rmsg_handle;
  18415. +
  18416. + m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_GET;
  18417. +
  18418. + m.u.port_parameter_get.component_handle = port->component->handle;
  18419. + m.u.port_parameter_get.port_handle = port->handle;
  18420. + m.u.port_parameter_get.id = parameter_id;
  18421. + m.u.port_parameter_get.size = (2 * sizeof(u32)) + *value_size;
  18422. +
  18423. + ret = send_synchronous_mmal_msg(instance, &m,
  18424. + sizeof(struct
  18425. + mmal_msg_port_parameter_get),
  18426. + &rmsg, &rmsg_handle);
  18427. + if (ret)
  18428. + return ret;
  18429. +
  18430. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_GET) {
  18431. + /* got an unexpected message type in reply */
  18432. + pr_err("Incorrect reply type %d\n", rmsg->h.type);
  18433. + ret = -EINVAL;
  18434. + goto release_msg;
  18435. + }
  18436. +
  18437. + ret = -rmsg->u.port_parameter_get_reply.status;
  18438. + if (ret) {
  18439. + /* Copy only as much as we have space for
  18440. + * but report true size of parameter
  18441. + */
  18442. + memcpy(value, &rmsg->u.port_parameter_get_reply.value,
  18443. + *value_size);
  18444. + *value_size = rmsg->u.port_parameter_get_reply.size;
  18445. + } else
  18446. + memcpy(value, &rmsg->u.port_parameter_get_reply.value,
  18447. + rmsg->u.port_parameter_get_reply.size);
  18448. +
  18449. + pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n", __func__,
  18450. + ret, port->component->handle, port->handle, parameter_id);
  18451. +
  18452. +release_msg:
  18453. + vchi_held_msg_release(&rmsg_handle);
  18454. +
  18455. + return ret;
  18456. +}
  18457. +
  18458. +/* disables a port and drains buffers from it */
  18459. +static int port_disable(struct vchiq_mmal_instance *instance,
  18460. + struct vchiq_mmal_port *port)
  18461. +{
  18462. + int ret;
  18463. + struct list_head *q, *buf_head;
  18464. + unsigned long flags = 0;
  18465. +
  18466. + if (!port->enabled)
  18467. + return 0;
  18468. +
  18469. + port->enabled = false;
  18470. +
  18471. + ret = port_action_port(instance, port,
  18472. + MMAL_MSG_PORT_ACTION_TYPE_DISABLE);
  18473. + if (ret == 0) {
  18474. +
  18475. + /* drain all queued buffers on port */
  18476. + spin_lock_irqsave(&port->slock, flags);
  18477. +
  18478. + list_for_each_safe(buf_head, q, &port->buffers) {
  18479. + struct mmal_buffer *mmalbuf;
  18480. + mmalbuf = list_entry(buf_head, struct mmal_buffer,
  18481. + list);
  18482. + list_del(buf_head);
  18483. + if (port->buffer_cb)
  18484. + port->buffer_cb(instance,
  18485. + port, 0, mmalbuf, 0, 0,
  18486. + MMAL_TIME_UNKNOWN,
  18487. + MMAL_TIME_UNKNOWN);
  18488. + }
  18489. +
  18490. + spin_unlock_irqrestore(&port->slock, flags);
  18491. +
  18492. + ret = port_info_get(instance, port);
  18493. + }
  18494. +
  18495. + return ret;
  18496. +}
  18497. +
  18498. +/* enable a port */
  18499. +static int port_enable(struct vchiq_mmal_instance *instance,
  18500. + struct vchiq_mmal_port *port)
  18501. +{
  18502. + unsigned int hdr_count;
  18503. + struct list_head *buf_head;
  18504. + int ret;
  18505. +
  18506. + if (port->enabled)
  18507. + return 0;
  18508. +
  18509. + /* ensure there are enough buffers queued to cover the buffer headers */
  18510. + if (port->buffer_cb != NULL) {
  18511. + hdr_count = 0;
  18512. + list_for_each(buf_head, &port->buffers) {
  18513. + hdr_count++;
  18514. + }
  18515. + if (hdr_count < port->current_buffer.num)
  18516. + return -ENOSPC;
  18517. + }
  18518. +
  18519. + ret = port_action_port(instance, port,
  18520. + MMAL_MSG_PORT_ACTION_TYPE_ENABLE);
  18521. + if (ret)
  18522. + goto done;
  18523. +
  18524. + port->enabled = true;
  18525. +
  18526. + if (port->buffer_cb) {
  18527. + /* send buffer headers to videocore */
  18528. + hdr_count = 1;
  18529. + list_for_each(buf_head, &port->buffers) {
  18530. + struct mmal_buffer *mmalbuf;
  18531. + mmalbuf = list_entry(buf_head, struct mmal_buffer,
  18532. + list);
  18533. + ret = buffer_from_host(instance, port, mmalbuf);
  18534. + if (ret)
  18535. + goto done;
  18536. +
  18537. + hdr_count++;
  18538. + if (hdr_count > port->current_buffer.num)
  18539. + break;
  18540. + }
  18541. + }
  18542. +
  18543. + ret = port_info_get(instance, port);
  18544. +
  18545. +done:
  18546. + return ret;
  18547. +}
  18548. +
  18549. +/* ------------------------------------------------------------------
  18550. + * Exported API
  18551. + *------------------------------------------------------------------*/
  18552. +
  18553. +int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
  18554. + struct vchiq_mmal_port *port)
  18555. +{
  18556. + int ret;
  18557. +
  18558. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  18559. + return -EINTR;
  18560. +
  18561. + ret = port_info_set(instance, port);
  18562. + if (ret)
  18563. + goto release_unlock;
  18564. +
  18565. + /* read what has actually been set */
  18566. + ret = port_info_get(instance, port);
  18567. +
  18568. +release_unlock:
  18569. + mutex_unlock(&instance->vchiq_mutex);
  18570. +
  18571. + return ret;
  18572. +
  18573. +}
  18574. +
  18575. +int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
  18576. + struct vchiq_mmal_port *port,
  18577. + u32 parameter, void *value, u32 value_size)
  18578. +{
  18579. + int ret;
  18580. +
  18581. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  18582. + return -EINTR;
  18583. +
  18584. + ret = port_parameter_set(instance, port, parameter, value, value_size);
  18585. +
  18586. + mutex_unlock(&instance->vchiq_mutex);
  18587. +
  18588. + return ret;
  18589. +}
  18590. +
  18591. +int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
  18592. + struct vchiq_mmal_port *port,
  18593. + u32 parameter, void *value, u32 *value_size)
  18594. +{
  18595. + int ret;
  18596. +
  18597. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  18598. + return -EINTR;
  18599. +
  18600. + ret = port_parameter_get(instance, port, parameter, value, value_size);
  18601. +
  18602. + mutex_unlock(&instance->vchiq_mutex);
  18603. +
  18604. + return ret;
  18605. +}
  18606. +
  18607. +/* enable a port
  18608. + *
  18609. + * enables a port and queues buffers for satisfying callbacks if we
  18610. + * provide a callback handler
  18611. + */
  18612. +int vchiq_mmal_port_enable(struct vchiq_mmal_instance *instance,
  18613. + struct vchiq_mmal_port *port,
  18614. + vchiq_mmal_buffer_cb buffer_cb)
  18615. +{
  18616. + int ret;
  18617. +
  18618. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  18619. + return -EINTR;
  18620. +
  18621. + /* already enabled - noop */
  18622. + if (port->enabled) {
  18623. + ret = 0;
  18624. + goto unlock;
  18625. + }
  18626. +
  18627. + port->buffer_cb = buffer_cb;
  18628. +
  18629. + ret = port_enable(instance, port);
  18630. +
  18631. +unlock:
  18632. + mutex_unlock(&instance->vchiq_mutex);
  18633. +
  18634. + return ret;
  18635. +}
  18636. +
  18637. +int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
  18638. + struct vchiq_mmal_port *port)
  18639. +{
  18640. + int ret;
  18641. +
  18642. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  18643. + return -EINTR;
  18644. +
  18645. + if (!port->enabled) {
  18646. + mutex_unlock(&instance->vchiq_mutex);
  18647. + return 0;
  18648. + }
  18649. +
  18650. + ret = port_disable(instance, port);
  18651. +
  18652. + mutex_unlock(&instance->vchiq_mutex);
  18653. +
  18654. + return ret;
  18655. +}
  18656. +
  18657. +/* ports will be connected in a tunneled manner so data buffers
  18658. + * are not handled by client.
  18659. + */
  18660. +int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
  18661. + struct vchiq_mmal_port *src,
  18662. + struct vchiq_mmal_port *dst)
  18663. +{
  18664. + int ret;
  18665. +
  18666. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  18667. + return -EINTR;
  18668. +
  18669. + /* disconnect ports if connected */
  18670. + if (src->connected != NULL) {
  18671. + ret = port_disable(instance, src);
  18672. + if (ret) {
  18673. + pr_err("failed disabling src port(%d)\n", ret);
  18674. + goto release_unlock;
  18675. + }
  18676. +
  18677. + /* do not need to disable the destination port as they
  18678. + * are connected and it is done automatically
  18679. + */
  18680. +
  18681. + ret = port_action_handle(instance, src,
  18682. + MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT,
  18683. + src->connected->component->handle,
  18684. + src->connected->handle);
  18685. + if (ret < 0) {
  18686. + pr_err("failed disconnecting src port\n");
  18687. + goto release_unlock;
  18688. + }
  18689. + src->connected->enabled = false;
  18690. + src->connected = NULL;
  18691. + }
  18692. +
  18693. + if (dst == NULL) {
  18694. + /* do not make new connection */
  18695. + ret = 0;
  18696. + pr_debug("not making new connection\n");
  18697. + goto release_unlock;
  18698. + }
  18699. +
  18700. + /* copy src port format to dst */
  18701. + dst->format.encoding = src->format.encoding;
  18702. + dst->es.video.width = src->es.video.width;
  18703. + dst->es.video.height = src->es.video.height;
  18704. + dst->es.video.crop.x = src->es.video.crop.x;
  18705. + dst->es.video.crop.y = src->es.video.crop.y;
  18706. + dst->es.video.crop.width = src->es.video.crop.width;
  18707. + dst->es.video.crop.height = src->es.video.crop.height;
  18708. + dst->es.video.frame_rate.num = src->es.video.frame_rate.num;
  18709. + dst->es.video.frame_rate.den = src->es.video.frame_rate.den;
  18710. +
  18711. + /* set new format */
  18712. + ret = port_info_set(instance, dst);
  18713. + if (ret) {
  18714. + pr_debug("setting port info failed\n");
  18715. + goto release_unlock;
  18716. + }
  18717. +
  18718. + /* read what has actually been set */
  18719. + ret = port_info_get(instance, dst);
  18720. + if (ret) {
  18721. + pr_debug("read back port info failed\n");
  18722. + goto release_unlock;
  18723. + }
  18724. +
  18725. + /* connect two ports together */
  18726. + ret = port_action_handle(instance, src,
  18727. + MMAL_MSG_PORT_ACTION_TYPE_CONNECT,
  18728. + dst->component->handle, dst->handle);
  18729. + if (ret < 0) {
  18730. + pr_debug("connecting port %d:%d to %d:%d failed\n",
  18731. + src->component->handle, src->handle,
  18732. + dst->component->handle, dst->handle);
  18733. + goto release_unlock;
  18734. + }
  18735. + src->connected = dst;
  18736. +
  18737. +release_unlock:
  18738. +
  18739. + mutex_unlock(&instance->vchiq_mutex);
  18740. +
  18741. + return ret;
  18742. +}
  18743. +
  18744. +int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
  18745. + struct vchiq_mmal_port *port,
  18746. + struct mmal_buffer *buffer)
  18747. +{
  18748. + unsigned long flags = 0;
  18749. +
  18750. + spin_lock_irqsave(&port->slock, flags);
  18751. + list_add_tail(&buffer->list, &port->buffers);
  18752. + spin_unlock_irqrestore(&port->slock, flags);
  18753. +
  18754. + /* the port previously underflowed because it was missing a
  18755. + * mmal_buffer which has just been added, submit that buffer
  18756. + * to the mmal service.
  18757. + */
  18758. + if (port->buffer_underflow) {
  18759. + port_buffer_from_host(instance, port);
  18760. + port->buffer_underflow--;
  18761. + }
  18762. +
  18763. + return 0;
  18764. +}
  18765. +
  18766. +/* Initialise a mmal component and its ports
  18767. + *
  18768. + */
  18769. +int vchiq_mmal_component_init(struct vchiq_mmal_instance *instance,
  18770. + const char *name,
  18771. + struct vchiq_mmal_component **component_out)
  18772. +{
  18773. + int ret;
  18774. + int idx; /* port index */
  18775. + struct vchiq_mmal_component *component;
  18776. +
  18777. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  18778. + return -EINTR;
  18779. +
  18780. + if (instance->component_idx == VCHIQ_MMAL_MAX_COMPONENTS) {
  18781. + ret = -EINVAL; /* todo is this correct error? */
  18782. + goto unlock;
  18783. + }
  18784. +
  18785. + component = &instance->component[instance->component_idx];
  18786. +
  18787. + ret = create_component(instance, component, name);
  18788. + if (ret < 0)
  18789. + goto unlock;
  18790. +
  18791. + /* ports info needs gathering */
  18792. + component->control.type = MMAL_PORT_TYPE_CONTROL;
  18793. + component->control.index = 0;
  18794. + component->control.component = component;
  18795. + spin_lock_init(&component->control.slock);
  18796. + INIT_LIST_HEAD(&component->control.buffers);
  18797. + ret = port_info_get(instance, &component->control);
  18798. + if (ret < 0)
  18799. + goto release_component;
  18800. +
  18801. + for (idx = 0; idx < component->inputs; idx++) {
  18802. + component->input[idx].type = MMAL_PORT_TYPE_INPUT;
  18803. + component->input[idx].index = idx;
  18804. + component->input[idx].component = component;
  18805. + spin_lock_init(&component->input[idx].slock);
  18806. + INIT_LIST_HEAD(&component->input[idx].buffers);
  18807. + ret = port_info_get(instance, &component->input[idx]);
  18808. + if (ret < 0)
  18809. + goto release_component;
  18810. + }
  18811. +
  18812. + for (idx = 0; idx < component->outputs; idx++) {
  18813. + component->output[idx].type = MMAL_PORT_TYPE_OUTPUT;
  18814. + component->output[idx].index = idx;
  18815. + component->output[idx].component = component;
  18816. + spin_lock_init(&component->output[idx].slock);
  18817. + INIT_LIST_HEAD(&component->output[idx].buffers);
  18818. + ret = port_info_get(instance, &component->output[idx]);
  18819. + if (ret < 0)
  18820. + goto release_component;
  18821. + }
  18822. +
  18823. + for (idx = 0; idx < component->clocks; idx++) {
  18824. + component->clock[idx].type = MMAL_PORT_TYPE_CLOCK;
  18825. + component->clock[idx].index = idx;
  18826. + component->clock[idx].component = component;
  18827. + spin_lock_init(&component->clock[idx].slock);
  18828. + INIT_LIST_HEAD(&component->clock[idx].buffers);
  18829. + ret = port_info_get(instance, &component->clock[idx]);
  18830. + if (ret < 0)
  18831. + goto release_component;
  18832. + }
  18833. +
  18834. + instance->component_idx++;
  18835. +
  18836. + *component_out = component;
  18837. +
  18838. + mutex_unlock(&instance->vchiq_mutex);
  18839. +
  18840. + return 0;
  18841. +
  18842. +release_component:
  18843. + destroy_component(instance, component);
  18844. +unlock:
  18845. + mutex_unlock(&instance->vchiq_mutex);
  18846. +
  18847. + return ret;
  18848. +}
  18849. +
  18850. +/*
  18851. + * cause a mmal component to be destroyed
  18852. + */
  18853. +int vchiq_mmal_component_finalise(struct vchiq_mmal_instance *instance,
  18854. + struct vchiq_mmal_component *component)
  18855. +{
  18856. + int ret;
  18857. +
  18858. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  18859. + return -EINTR;
  18860. +
  18861. + if (component->enabled)
  18862. + ret = disable_component(instance, component);
  18863. +
  18864. + ret = destroy_component(instance, component);
  18865. +
  18866. + mutex_unlock(&instance->vchiq_mutex);
  18867. +
  18868. + return ret;
  18869. +}
  18870. +
  18871. +/*
  18872. + * cause a mmal component to be enabled
  18873. + */
  18874. +int vchiq_mmal_component_enable(struct vchiq_mmal_instance *instance,
  18875. + struct vchiq_mmal_component *component)
  18876. +{
  18877. + int ret;
  18878. +
  18879. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  18880. + return -EINTR;
  18881. +
  18882. + if (component->enabled) {
  18883. + mutex_unlock(&instance->vchiq_mutex);
  18884. + return 0;
  18885. + }
  18886. +
  18887. + ret = enable_component(instance, component);
  18888. + if (ret == 0)
  18889. + component->enabled = true;
  18890. +
  18891. + mutex_unlock(&instance->vchiq_mutex);
  18892. +
  18893. + return ret;
  18894. +}
  18895. +
  18896. +/*
  18897. + * cause a mmal component to be enabled
  18898. + */
  18899. +int vchiq_mmal_component_disable(struct vchiq_mmal_instance *instance,
  18900. + struct vchiq_mmal_component *component)
  18901. +{
  18902. + int ret;
  18903. +
  18904. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  18905. + return -EINTR;
  18906. +
  18907. + if (!component->enabled) {
  18908. + mutex_unlock(&instance->vchiq_mutex);
  18909. + return 0;
  18910. + }
  18911. +
  18912. + ret = disable_component(instance, component);
  18913. + if (ret == 0)
  18914. + component->enabled = false;
  18915. +
  18916. + mutex_unlock(&instance->vchiq_mutex);
  18917. +
  18918. + return ret;
  18919. +}
  18920. +
  18921. +int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
  18922. + u32 *major_out, u32 *minor_out)
  18923. +{
  18924. + int ret;
  18925. +
  18926. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  18927. + return -EINTR;
  18928. +
  18929. + ret = get_version(instance, major_out, minor_out);
  18930. +
  18931. + mutex_unlock(&instance->vchiq_mutex);
  18932. +
  18933. + return ret;
  18934. +}
  18935. +
  18936. +int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance)
  18937. +{
  18938. + int status = 0;
  18939. +
  18940. + if (instance == NULL)
  18941. + return -EINVAL;
  18942. +
  18943. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  18944. + return -EINTR;
  18945. +
  18946. + vchi_service_use(instance->handle);
  18947. +
  18948. + status = vchi_service_close(instance->handle);
  18949. + if (status != 0)
  18950. + pr_err("mmal-vchiq: VCHIQ close failed");
  18951. +
  18952. + mutex_unlock(&instance->vchiq_mutex);
  18953. +
  18954. + vfree(instance->bulk_scratch);
  18955. +
  18956. + kfree(instance);
  18957. +
  18958. + return status;
  18959. +}
  18960. +
  18961. +int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
  18962. +{
  18963. + int status;
  18964. + struct vchiq_mmal_instance *instance;
  18965. + static VCHI_CONNECTION_T *vchi_connection;
  18966. + static VCHI_INSTANCE_T vchi_instance;
  18967. + SERVICE_CREATION_T params = {
  18968. + VCHI_VERSION_EX(VC_MMAL_VER, VC_MMAL_MIN_VER),
  18969. + VC_MMAL_SERVER_NAME,
  18970. + vchi_connection,
  18971. + 0, /* rx fifo size (unused) */
  18972. + 0, /* tx fifo size (unused) */
  18973. + service_callback,
  18974. + NULL, /* service callback parameter */
  18975. + 1, /* unaligned bulk receives */
  18976. + 1, /* unaligned bulk transmits */
  18977. + 0 /* want crc check on bulk transfers */
  18978. + };
  18979. +
  18980. + /* compile time checks to ensure structure size as they are
  18981. + * directly (de)serialised from memory.
  18982. + */
  18983. +
  18984. + /* ensure the header structure has packed to the correct size */
  18985. + BUILD_BUG_ON(sizeof(struct mmal_msg_header) != 24);
  18986. +
  18987. + /* ensure message structure does not exceed maximum length */
  18988. + BUILD_BUG_ON(sizeof(struct mmal_msg) > MMAL_MSG_MAX_SIZE);
  18989. +
  18990. + /* mmal port struct is correct size */
  18991. + BUILD_BUG_ON(sizeof(struct mmal_port) != 64);
  18992. +
  18993. + /* create a vchi instance */
  18994. + status = vchi_initialise(&vchi_instance);
  18995. + if (status) {
  18996. + pr_err("Failed to initialise VCHI instance (status=%d)\n",
  18997. + status);
  18998. + return -EIO;
  18999. + }
  19000. +
  19001. + status = vchi_connect(NULL, 0, vchi_instance);
  19002. + if (status) {
  19003. + pr_err("Failed to connect VCHI instance (status=%d)\n", status);
  19004. + return -EIO;
  19005. + }
  19006. +
  19007. + instance = kmalloc(sizeof(*instance), GFP_KERNEL);
  19008. + memset(instance, 0, sizeof(*instance));
  19009. +
  19010. + mutex_init(&instance->vchiq_mutex);
  19011. + mutex_init(&instance->bulk_mutex);
  19012. +
  19013. + instance->bulk_scratch = vmalloc(PAGE_SIZE);
  19014. +
  19015. + params.callback_param = instance;
  19016. +
  19017. + status = vchi_service_open(vchi_instance, &params, &instance->handle);
  19018. + if (status) {
  19019. + pr_err("Failed to open VCHI service connection (status=%d)\n",
  19020. + status);
  19021. + goto err_close_services;
  19022. + }
  19023. +
  19024. + vchi_service_release(instance->handle);
  19025. +
  19026. + *out_instance = instance;
  19027. +
  19028. + return 0;
  19029. +
  19030. +err_close_services:
  19031. +
  19032. + vchi_service_close(instance->handle);
  19033. + vfree(instance->bulk_scratch);
  19034. + kfree(instance);
  19035. + return -ENODEV;
  19036. +}
  19037. diff -Nur linux-3.15.4/drivers/media/platform/bcm2835/mmal-vchiq.h linux-rpi/drivers/media/platform/bcm2835/mmal-vchiq.h
  19038. --- linux-3.15.4/drivers/media/platform/bcm2835/mmal-vchiq.h 1970-01-01 01:00:00.000000000 +0100
  19039. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-vchiq.h 2014-04-13 17:32:57.000000000 +0200
  19040. @@ -0,0 +1,178 @@
  19041. +/*
  19042. + * Broadcom BM2835 V4L2 driver
  19043. + *
  19044. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  19045. + *
  19046. + * This file is subject to the terms and conditions of the GNU General Public
  19047. + * License. See the file COPYING in the main directory of this archive
  19048. + * for more details.
  19049. + *
  19050. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  19051. + * Dave Stevenson <dsteve@broadcom.com>
  19052. + * Simon Mellor <simellor@broadcom.com>
  19053. + * Luke Diamand <luked@broadcom.com>
  19054. + *
  19055. + * MMAL interface to VCHIQ message passing
  19056. + */
  19057. +
  19058. +#ifndef MMAL_VCHIQ_H
  19059. +#define MMAL_VCHIQ_H
  19060. +
  19061. +#include "mmal-msg-format.h"
  19062. +
  19063. +#define MAX_PORT_COUNT 4
  19064. +
  19065. +/* Maximum size of the format extradata. */
  19066. +#define MMAL_FORMAT_EXTRADATA_MAX_SIZE 128
  19067. +
  19068. +struct vchiq_mmal_instance;
  19069. +
  19070. +enum vchiq_mmal_es_type {
  19071. + MMAL_ES_TYPE_UNKNOWN, /**< Unknown elementary stream type */
  19072. + MMAL_ES_TYPE_CONTROL, /**< Elementary stream of control commands */
  19073. + MMAL_ES_TYPE_AUDIO, /**< Audio elementary stream */
  19074. + MMAL_ES_TYPE_VIDEO, /**< Video elementary stream */
  19075. + MMAL_ES_TYPE_SUBPICTURE /**< Sub-picture elementary stream */
  19076. +};
  19077. +
  19078. +/* rectangle, used lots so it gets its own struct */
  19079. +struct vchiq_mmal_rect {
  19080. + s32 x;
  19081. + s32 y;
  19082. + s32 width;
  19083. + s32 height;
  19084. +};
  19085. +
  19086. +struct vchiq_mmal_port_buffer {
  19087. + unsigned int num; /* number of buffers */
  19088. + u32 size; /* size of buffers */
  19089. + u32 alignment; /* alignment of buffers */
  19090. +};
  19091. +
  19092. +struct vchiq_mmal_port;
  19093. +
  19094. +typedef void (*vchiq_mmal_buffer_cb)(
  19095. + struct vchiq_mmal_instance *instance,
  19096. + struct vchiq_mmal_port *port,
  19097. + int status, struct mmal_buffer *buffer,
  19098. + unsigned long length, u32 mmal_flags, s64 dts, s64 pts);
  19099. +
  19100. +struct vchiq_mmal_port {
  19101. + bool enabled;
  19102. + u32 handle;
  19103. + u32 type; /* port type, cached to use on port info set */
  19104. + u32 index; /* port index, cached to use on port info set */
  19105. +
  19106. + /* component port belongs to, allows simple deref */
  19107. + struct vchiq_mmal_component *component;
  19108. +
  19109. + struct vchiq_mmal_port *connected; /* port conencted to */
  19110. +
  19111. + /* buffer info */
  19112. + struct vchiq_mmal_port_buffer minimum_buffer;
  19113. + struct vchiq_mmal_port_buffer recommended_buffer;
  19114. + struct vchiq_mmal_port_buffer current_buffer;
  19115. +
  19116. + /* stream format */
  19117. + struct mmal_es_format format;
  19118. + /* elementry stream format */
  19119. + union mmal_es_specific_format es;
  19120. +
  19121. + /* data buffers to fill */
  19122. + struct list_head buffers;
  19123. + /* lock to serialise adding and removing buffers from list */
  19124. + spinlock_t slock;
  19125. + /* count of how many buffer header refils have failed because
  19126. + * there was no buffer to satisfy them
  19127. + */
  19128. + int buffer_underflow;
  19129. + /* callback on buffer completion */
  19130. + vchiq_mmal_buffer_cb buffer_cb;
  19131. + /* callback context */
  19132. + void *cb_ctx;
  19133. +};
  19134. +
  19135. +struct vchiq_mmal_component {
  19136. + bool enabled;
  19137. + u32 handle; /* VideoCore handle for component */
  19138. + u32 inputs; /* Number of input ports */
  19139. + u32 outputs; /* Number of output ports */
  19140. + u32 clocks; /* Number of clock ports */
  19141. + struct vchiq_mmal_port control; /* control port */
  19142. + struct vchiq_mmal_port input[MAX_PORT_COUNT]; /* input ports */
  19143. + struct vchiq_mmal_port output[MAX_PORT_COUNT]; /* output ports */
  19144. + struct vchiq_mmal_port clock[MAX_PORT_COUNT]; /* clock ports */
  19145. +};
  19146. +
  19147. +
  19148. +int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance);
  19149. +int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance);
  19150. +
  19151. +/* Initialise a mmal component and its ports
  19152. +*
  19153. +*/
  19154. +int vchiq_mmal_component_init(
  19155. + struct vchiq_mmal_instance *instance,
  19156. + const char *name,
  19157. + struct vchiq_mmal_component **component_out);
  19158. +
  19159. +int vchiq_mmal_component_finalise(
  19160. + struct vchiq_mmal_instance *instance,
  19161. + struct vchiq_mmal_component *component);
  19162. +
  19163. +int vchiq_mmal_component_enable(
  19164. + struct vchiq_mmal_instance *instance,
  19165. + struct vchiq_mmal_component *component);
  19166. +
  19167. +int vchiq_mmal_component_disable(
  19168. + struct vchiq_mmal_instance *instance,
  19169. + struct vchiq_mmal_component *component);
  19170. +
  19171. +
  19172. +
  19173. +/* enable a mmal port
  19174. + *
  19175. + * enables a port and if a buffer callback provided enque buffer
  19176. + * headers as apropriate for the port.
  19177. + */
  19178. +int vchiq_mmal_port_enable(
  19179. + struct vchiq_mmal_instance *instance,
  19180. + struct vchiq_mmal_port *port,
  19181. + vchiq_mmal_buffer_cb buffer_cb);
  19182. +
  19183. +/* disable a port
  19184. + *
  19185. + * disable a port will dequeue any pending buffers
  19186. + */
  19187. +int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
  19188. + struct vchiq_mmal_port *port);
  19189. +
  19190. +
  19191. +int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
  19192. + struct vchiq_mmal_port *port,
  19193. + u32 parameter,
  19194. + void *value,
  19195. + u32 value_size);
  19196. +
  19197. +int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
  19198. + struct vchiq_mmal_port *port,
  19199. + u32 parameter,
  19200. + void *value,
  19201. + u32 *value_size);
  19202. +
  19203. +int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
  19204. + struct vchiq_mmal_port *port);
  19205. +
  19206. +int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
  19207. + struct vchiq_mmal_port *src,
  19208. + struct vchiq_mmal_port *dst);
  19209. +
  19210. +int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
  19211. + u32 *major_out,
  19212. + u32 *minor_out);
  19213. +
  19214. +int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
  19215. + struct vchiq_mmal_port *port,
  19216. + struct mmal_buffer *buf);
  19217. +
  19218. +#endif /* MMAL_VCHIQ_H */
  19219. diff -Nur linux-3.15.4/drivers/media/platform/Kconfig linux-rpi/drivers/media/platform/Kconfig
  19220. --- linux-3.15.4/drivers/media/platform/Kconfig 2014-07-07 03:59:25.000000000 +0200
  19221. +++ linux-rpi/drivers/media/platform/Kconfig 2014-07-07 10:45:10.000000000 +0200
  19222. @@ -118,6 +118,7 @@
  19223. source "drivers/media/platform/soc_camera/Kconfig"
  19224. source "drivers/media/platform/exynos4-is/Kconfig"
  19225. source "drivers/media/platform/s5p-tv/Kconfig"
  19226. +source "drivers/media/platform/bcm2835/Kconfig"
  19227. endif # V4L_PLATFORM_DRIVERS
  19228. diff -Nur linux-3.15.4/drivers/media/platform/Makefile linux-rpi/drivers/media/platform/Makefile
  19229. --- linux-3.15.4/drivers/media/platform/Makefile 2014-07-07 03:59:25.000000000 +0200
  19230. +++ linux-rpi/drivers/media/platform/Makefile 2014-07-07 10:45:10.000000000 +0200
  19231. @@ -51,4 +51,6 @@
  19232. obj-$(CONFIG_ARCH_OMAP) += omap/
  19233. +obj-$(CONFIG_VIDEO_BCM2835) += bcm2835/
  19234. +
  19235. ccflags-y += -I$(srctree)/drivers/media/i2c
  19236. diff -Nur linux-3.15.4/drivers/media/usb/dvb-usb-v2/rtl28xxu.c linux-rpi/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
  19237. --- linux-3.15.4/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 2014-07-07 03:59:25.000000000 +0200
  19238. +++ linux-rpi/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 2014-07-07 10:45:11.000000000 +0200
  19239. @@ -1531,6 +1531,10 @@
  19240. &rtl2832u_props, "Compro VideoMate U620F", NULL) },
  19241. { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd394,
  19242. &rtl2832u_props, "MaxMedia HU394-T", NULL) },
  19243. + { DVB_USB_DEVICE(USB_VID_GTEK, 0xb803 /*USB_PID_AUGUST_DVBT205*/,
  19244. + &rtl2832u_props, "August DVB-T 205", NULL) },
  19245. + { DVB_USB_DEVICE(USB_VID_GTEK, 0xa803 /*USB_PID_AUGUST_DVBT205*/,
  19246. + &rtl2832u_props, "August DVB-T 205", NULL) },
  19247. { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6a03,
  19248. &rtl2832u_props, "Leadtek WinFast DTV Dongle mini", NULL) },
  19249. { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_CPYTO_REDI_PC50A,
  19250. diff -Nur linux-3.15.4/drivers/misc/Kconfig linux-rpi/drivers/misc/Kconfig
  19251. --- linux-3.15.4/drivers/misc/Kconfig 2014-07-07 03:59:25.000000000 +0200
  19252. +++ linux-rpi/drivers/misc/Kconfig 2014-07-07 10:45:11.000000000 +0200
  19253. @@ -524,6 +524,7 @@
  19254. source "drivers/misc/altera-stapl/Kconfig"
  19255. source "drivers/misc/mei/Kconfig"
  19256. source "drivers/misc/vmw_vmci/Kconfig"
  19257. +source "drivers/misc/vc04_services/Kconfig"
  19258. source "drivers/misc/mic/Kconfig"
  19259. source "drivers/misc/genwqe/Kconfig"
  19260. source "drivers/misc/echo/Kconfig"
  19261. diff -Nur linux-3.15.4/drivers/misc/Makefile linux-rpi/drivers/misc/Makefile
  19262. --- linux-3.15.4/drivers/misc/Makefile 2014-07-07 03:59:25.000000000 +0200
  19263. +++ linux-rpi/drivers/misc/Makefile 2014-07-07 10:45:11.000000000 +0200
  19264. @@ -52,6 +52,7 @@
  19265. obj-$(CONFIG_VMWARE_VMCI) += vmw_vmci/
  19266. obj-$(CONFIG_LATTICE_ECP3_CONFIG) += lattice-ecp3-config.o
  19267. obj-$(CONFIG_SRAM) += sram.o
  19268. +obj-$(CONFIG_BCM2708_VCHIQ) += vc04_services/
  19269. obj-y += mic/
  19270. obj-$(CONFIG_GENWQE) += genwqe/
  19271. obj-$(CONFIG_ECHO) += echo/
  19272. diff -Nur linux-3.15.4/drivers/misc/vc04_services/interface/vchi/connections/connection.h linux-rpi/drivers/misc/vc04_services/interface/vchi/connections/connection.h
  19273. --- linux-3.15.4/drivers/misc/vc04_services/interface/vchi/connections/connection.h 1970-01-01 01:00:00.000000000 +0100
  19274. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/connections/connection.h 2014-04-13 17:32:57.000000000 +0200
  19275. @@ -0,0 +1,328 @@
  19276. +/**
  19277. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  19278. + *
  19279. + * Redistribution and use in source and binary forms, with or without
  19280. + * modification, are permitted provided that the following conditions
  19281. + * are met:
  19282. + * 1. Redistributions of source code must retain the above copyright
  19283. + * notice, this list of conditions, and the following disclaimer,
  19284. + * without modification.
  19285. + * 2. Redistributions in binary form must reproduce the above copyright
  19286. + * notice, this list of conditions and the following disclaimer in the
  19287. + * documentation and/or other materials provided with the distribution.
  19288. + * 3. The names of the above-listed copyright holders may not be used
  19289. + * to endorse or promote products derived from this software without
  19290. + * specific prior written permission.
  19291. + *
  19292. + * ALTERNATIVELY, this software may be distributed under the terms of the
  19293. + * GNU General Public License ("GPL") version 2, as published by the Free
  19294. + * Software Foundation.
  19295. + *
  19296. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  19297. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19298. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19299. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19300. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19301. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19302. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19303. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19304. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19305. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19306. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19307. + */
  19308. +
  19309. +#ifndef CONNECTION_H_
  19310. +#define CONNECTION_H_
  19311. +
  19312. +#include <linux/kernel.h>
  19313. +#include <linux/types.h>
  19314. +#include <linux/semaphore.h>
  19315. +
  19316. +#include "interface/vchi/vchi_cfg_internal.h"
  19317. +#include "interface/vchi/vchi_common.h"
  19318. +#include "interface/vchi/message_drivers/message.h"
  19319. +
  19320. +/******************************************************************************
  19321. + Global defs
  19322. + *****************************************************************************/
  19323. +
  19324. +// Opaque handle for a connection / service pair
  19325. +typedef struct opaque_vchi_connection_connected_service_handle_t *VCHI_CONNECTION_SERVICE_HANDLE_T;
  19326. +
  19327. +// opaque handle to the connection state information
  19328. +typedef struct opaque_vchi_connection_info_t VCHI_CONNECTION_STATE_T;
  19329. +
  19330. +typedef struct vchi_connection_t VCHI_CONNECTION_T;
  19331. +
  19332. +
  19333. +/******************************************************************************
  19334. + API
  19335. + *****************************************************************************/
  19336. +
  19337. +// Routine to init a connection with a particular low level driver
  19338. +typedef VCHI_CONNECTION_STATE_T * (*VCHI_CONNECTION_INIT_T)( struct vchi_connection_t * connection,
  19339. + const VCHI_MESSAGE_DRIVER_T * driver );
  19340. +
  19341. +// Routine to control CRC enabling at a connection level
  19342. +typedef int32_t (*VCHI_CONNECTION_CRC_CONTROL_T)( VCHI_CONNECTION_STATE_T *state_handle,
  19343. + VCHI_CRC_CONTROL_T control );
  19344. +
  19345. +// Routine to create a service
  19346. +typedef int32_t (*VCHI_CONNECTION_SERVICE_CONNECT_T)( VCHI_CONNECTION_STATE_T *state_handle,
  19347. + int32_t service_id,
  19348. + uint32_t rx_fifo_size,
  19349. + uint32_t tx_fifo_size,
  19350. + int server,
  19351. + VCHI_CALLBACK_T callback,
  19352. + void *callback_param,
  19353. + int32_t want_crc,
  19354. + int32_t want_unaligned_bulk_rx,
  19355. + int32_t want_unaligned_bulk_tx,
  19356. + VCHI_CONNECTION_SERVICE_HANDLE_T *service_handle );
  19357. +
  19358. +// Routine to close a service
  19359. +typedef int32_t (*VCHI_CONNECTION_SERVICE_DISCONNECT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle );
  19360. +
  19361. +// Routine to queue a message
  19362. +typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  19363. + const void *data,
  19364. + uint32_t data_size,
  19365. + VCHI_FLAGS_T flags,
  19366. + void *msg_handle );
  19367. +
  19368. +// scatter-gather (vector) message queueing
  19369. +typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  19370. + VCHI_MSG_VECTOR_T *vector,
  19371. + uint32_t count,
  19372. + VCHI_FLAGS_T flags,
  19373. + void *msg_handle );
  19374. +
  19375. +// Routine to dequeue a message
  19376. +typedef int32_t (*VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  19377. + void *data,
  19378. + uint32_t max_data_size_to_read,
  19379. + uint32_t *actual_msg_size,
  19380. + VCHI_FLAGS_T flags );
  19381. +
  19382. +// Routine to peek at a message
  19383. +typedef int32_t (*VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  19384. + void **data,
  19385. + uint32_t *msg_size,
  19386. + VCHI_FLAGS_T flags );
  19387. +
  19388. +// Routine to hold a message
  19389. +typedef int32_t (*VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  19390. + void **data,
  19391. + uint32_t *msg_size,
  19392. + VCHI_FLAGS_T flags,
  19393. + void **message_handle );
  19394. +
  19395. +// Routine to initialise a received message iterator
  19396. +typedef int32_t (*VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  19397. + VCHI_MSG_ITER_T *iter,
  19398. + VCHI_FLAGS_T flags );
  19399. +
  19400. +// Routine to release a held message
  19401. +typedef int32_t (*VCHI_CONNECTION_HELD_MSG_RELEASE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  19402. + void *message_handle );
  19403. +
  19404. +// Routine to get info on a held message
  19405. +typedef int32_t (*VCHI_CONNECTION_HELD_MSG_INFO_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  19406. + void *message_handle,
  19407. + void **data,
  19408. + int32_t *msg_size,
  19409. + uint32_t *tx_timestamp,
  19410. + uint32_t *rx_timestamp );
  19411. +
  19412. +// Routine to check whether the iterator has a next message
  19413. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  19414. + const VCHI_MSG_ITER_T *iter );
  19415. +
  19416. +// Routine to advance the iterator
  19417. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  19418. + VCHI_MSG_ITER_T *iter,
  19419. + void **data,
  19420. + uint32_t *msg_size );
  19421. +
  19422. +// Routine to remove the last message returned by the iterator
  19423. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_REMOVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  19424. + VCHI_MSG_ITER_T *iter );
  19425. +
  19426. +// Routine to hold the last message returned by the iterator
  19427. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HOLD_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  19428. + VCHI_MSG_ITER_T *iter,
  19429. + void **msg_handle );
  19430. +
  19431. +// Routine to transmit bulk data
  19432. +typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  19433. + const void *data_src,
  19434. + uint32_t data_size,
  19435. + VCHI_FLAGS_T flags,
  19436. + void *bulk_handle );
  19437. +
  19438. +// Routine to receive data
  19439. +typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  19440. + void *data_dst,
  19441. + uint32_t data_size,
  19442. + VCHI_FLAGS_T flags,
  19443. + void *bulk_handle );
  19444. +
  19445. +// Routine to report if a server is available
  19446. +typedef int32_t (*VCHI_CONNECTION_SERVER_PRESENT)( VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t peer_flags );
  19447. +
  19448. +// Routine to report the number of RX slots available
  19449. +typedef int (*VCHI_CONNECTION_RX_SLOTS_AVAILABLE)( const VCHI_CONNECTION_STATE_T *state );
  19450. +
  19451. +// Routine to report the RX slot size
  19452. +typedef uint32_t (*VCHI_CONNECTION_RX_SLOT_SIZE)( const VCHI_CONNECTION_STATE_T *state );
  19453. +
  19454. +// Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO
  19455. +typedef void (*VCHI_CONNECTION_RX_BULK_BUFFER_ADDED)(VCHI_CONNECTION_STATE_T *state,
  19456. + int32_t service,
  19457. + uint32_t length,
  19458. + MESSAGE_TX_CHANNEL_T channel,
  19459. + uint32_t channel_params,
  19460. + uint32_t data_length,
  19461. + uint32_t data_offset);
  19462. +
  19463. +// Callback to inform a service that a Xon or Xoff message has been received
  19464. +typedef void (*VCHI_CONNECTION_FLOW_CONTROL)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t xoff);
  19465. +
  19466. +// Callback to inform a service that a server available reply message has been received
  19467. +typedef void (*VCHI_CONNECTION_SERVER_AVAILABLE_REPLY)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, uint32_t flags);
  19468. +
  19469. +// Callback to indicate that bulk auxiliary messages have arrived
  19470. +typedef void (*VCHI_CONNECTION_BULK_AUX_RECEIVED)(VCHI_CONNECTION_STATE_T *state);
  19471. +
  19472. +// Callback to indicate that bulk auxiliary messages have arrived
  19473. +typedef void (*VCHI_CONNECTION_BULK_AUX_TRANSMITTED)(VCHI_CONNECTION_STATE_T *state, void *handle);
  19474. +
  19475. +// Callback with all the connection info you require
  19476. +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);
  19477. +
  19478. +// Callback to inform of a disconnect
  19479. +typedef void (*VCHI_CONNECTION_DISCONNECT)(VCHI_CONNECTION_STATE_T *state, uint32_t flags);
  19480. +
  19481. +// Callback to inform of a power control request
  19482. +typedef void (*VCHI_CONNECTION_POWER_CONTROL)(VCHI_CONNECTION_STATE_T *state, MESSAGE_TX_CHANNEL_T channel, int32_t enable);
  19483. +
  19484. +// allocate memory suitably aligned for this connection
  19485. +typedef void * (*VCHI_BUFFER_ALLOCATE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, uint32_t * length);
  19486. +
  19487. +// free memory allocated by buffer_allocate
  19488. +typedef void (*VCHI_BUFFER_FREE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, void * address);
  19489. +
  19490. +
  19491. +/******************************************************************************
  19492. + System driver struct
  19493. + *****************************************************************************/
  19494. +
  19495. +struct opaque_vchi_connection_api_t
  19496. +{
  19497. + // Routine to init the connection
  19498. + VCHI_CONNECTION_INIT_T init;
  19499. +
  19500. + // Connection-level CRC control
  19501. + VCHI_CONNECTION_CRC_CONTROL_T crc_control;
  19502. +
  19503. + // Routine to connect to or create service
  19504. + VCHI_CONNECTION_SERVICE_CONNECT_T service_connect;
  19505. +
  19506. + // Routine to disconnect from a service
  19507. + VCHI_CONNECTION_SERVICE_DISCONNECT_T service_disconnect;
  19508. +
  19509. + // Routine to queue a message
  19510. + VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T service_queue_msg;
  19511. +
  19512. + // scatter-gather (vector) message queue
  19513. + VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T service_queue_msgv;
  19514. +
  19515. + // Routine to dequeue a message
  19516. + VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T service_dequeue_msg;
  19517. +
  19518. + // Routine to peek at a message
  19519. + VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T service_peek_msg;
  19520. +
  19521. + // Routine to hold a message
  19522. + VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T service_hold_msg;
  19523. +
  19524. + // Routine to initialise a received message iterator
  19525. + VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T service_look_ahead_msg;
  19526. +
  19527. + // Routine to release a message
  19528. + VCHI_CONNECTION_HELD_MSG_RELEASE_T held_msg_release;
  19529. +
  19530. + // Routine to get information on a held message
  19531. + VCHI_CONNECTION_HELD_MSG_INFO_T held_msg_info;
  19532. +
  19533. + // Routine to check for next message on iterator
  19534. + VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T msg_iter_has_next;
  19535. +
  19536. + // Routine to get next message on iterator
  19537. + VCHI_CONNECTION_MSG_ITER_NEXT_T msg_iter_next;
  19538. +
  19539. + // Routine to remove the last message returned by iterator
  19540. + VCHI_CONNECTION_MSG_ITER_REMOVE_T msg_iter_remove;
  19541. +
  19542. + // Routine to hold the last message returned by iterator
  19543. + VCHI_CONNECTION_MSG_ITER_HOLD_T msg_iter_hold;
  19544. +
  19545. + // Routine to transmit bulk data
  19546. + VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T bulk_queue_transmit;
  19547. +
  19548. + // Routine to receive data
  19549. + VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T bulk_queue_receive;
  19550. +
  19551. + // Routine to report the available servers
  19552. + VCHI_CONNECTION_SERVER_PRESENT server_present;
  19553. +
  19554. + // Routine to report the number of RX slots available
  19555. + VCHI_CONNECTION_RX_SLOTS_AVAILABLE connection_rx_slots_available;
  19556. +
  19557. + // Routine to report the RX slot size
  19558. + VCHI_CONNECTION_RX_SLOT_SIZE connection_rx_slot_size;
  19559. +
  19560. + // Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO
  19561. + VCHI_CONNECTION_RX_BULK_BUFFER_ADDED rx_bulk_buffer_added;
  19562. +
  19563. + // Callback to inform a service that a Xon or Xoff message has been received
  19564. + VCHI_CONNECTION_FLOW_CONTROL flow_control;
  19565. +
  19566. + // Callback to inform a service that a server available reply message has been received
  19567. + VCHI_CONNECTION_SERVER_AVAILABLE_REPLY server_available_reply;
  19568. +
  19569. + // Callback to indicate that bulk auxiliary messages have arrived
  19570. + VCHI_CONNECTION_BULK_AUX_RECEIVED bulk_aux_received;
  19571. +
  19572. + // Callback to indicate that a bulk auxiliary message has been transmitted
  19573. + VCHI_CONNECTION_BULK_AUX_TRANSMITTED bulk_aux_transmitted;
  19574. +
  19575. + // Callback to provide information about the connection
  19576. + VCHI_CONNECTION_INFO connection_info;
  19577. +
  19578. + // Callback to notify that peer has requested disconnect
  19579. + VCHI_CONNECTION_DISCONNECT disconnect;
  19580. +
  19581. + // Callback to notify that peer has requested power change
  19582. + VCHI_CONNECTION_POWER_CONTROL power_control;
  19583. +
  19584. + // allocate memory suitably aligned for this connection
  19585. + VCHI_BUFFER_ALLOCATE buffer_allocate;
  19586. +
  19587. + // free memory allocated by buffer_allocate
  19588. + VCHI_BUFFER_FREE buffer_free;
  19589. +
  19590. +};
  19591. +
  19592. +struct vchi_connection_t {
  19593. + const VCHI_CONNECTION_API_T *api;
  19594. + VCHI_CONNECTION_STATE_T *state;
  19595. +#ifdef VCHI_COARSE_LOCKING
  19596. + struct semaphore sem;
  19597. +#endif
  19598. +};
  19599. +
  19600. +
  19601. +#endif /* CONNECTION_H_ */
  19602. +
  19603. +/****************************** End of file **********************************/
  19604. diff -Nur linux-3.15.4/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h linux-rpi/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h
  19605. --- linux-3.15.4/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h 1970-01-01 01:00:00.000000000 +0100
  19606. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h 2014-04-13 17:32:57.000000000 +0200
  19607. @@ -0,0 +1,204 @@
  19608. +/**
  19609. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  19610. + *
  19611. + * Redistribution and use in source and binary forms, with or without
  19612. + * modification, are permitted provided that the following conditions
  19613. + * are met:
  19614. + * 1. Redistributions of source code must retain the above copyright
  19615. + * notice, this list of conditions, and the following disclaimer,
  19616. + * without modification.
  19617. + * 2. Redistributions in binary form must reproduce the above copyright
  19618. + * notice, this list of conditions and the following disclaimer in the
  19619. + * documentation and/or other materials provided with the distribution.
  19620. + * 3. The names of the above-listed copyright holders may not be used
  19621. + * to endorse or promote products derived from this software without
  19622. + * specific prior written permission.
  19623. + *
  19624. + * ALTERNATIVELY, this software may be distributed under the terms of the
  19625. + * GNU General Public License ("GPL") version 2, as published by the Free
  19626. + * Software Foundation.
  19627. + *
  19628. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  19629. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19630. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19631. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19632. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19633. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19634. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19635. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19636. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19637. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19638. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19639. + */
  19640. +
  19641. +#ifndef _VCHI_MESSAGE_H_
  19642. +#define _VCHI_MESSAGE_H_
  19643. +
  19644. +#include <linux/kernel.h>
  19645. +#include <linux/types.h>
  19646. +#include <linux/semaphore.h>
  19647. +
  19648. +#include "interface/vchi/vchi_cfg_internal.h"
  19649. +#include "interface/vchi/vchi_common.h"
  19650. +
  19651. +
  19652. +typedef enum message_event_type {
  19653. + MESSAGE_EVENT_NONE,
  19654. + MESSAGE_EVENT_NOP,
  19655. + MESSAGE_EVENT_MESSAGE,
  19656. + MESSAGE_EVENT_SLOT_COMPLETE,
  19657. + MESSAGE_EVENT_RX_BULK_PAUSED,
  19658. + MESSAGE_EVENT_RX_BULK_COMPLETE,
  19659. + MESSAGE_EVENT_TX_COMPLETE,
  19660. + MESSAGE_EVENT_MSG_DISCARDED
  19661. +} MESSAGE_EVENT_TYPE_T;
  19662. +
  19663. +typedef enum vchi_msg_flags
  19664. +{
  19665. + VCHI_MSG_FLAGS_NONE = 0x0,
  19666. + VCHI_MSG_FLAGS_TERMINATE_DMA = 0x1
  19667. +} VCHI_MSG_FLAGS_T;
  19668. +
  19669. +typedef enum message_tx_channel
  19670. +{
  19671. + MESSAGE_TX_CHANNEL_MESSAGE = 0,
  19672. + MESSAGE_TX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
  19673. +} MESSAGE_TX_CHANNEL_T;
  19674. +
  19675. +// Macros used for cycling through bulk channels
  19676. +#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)
  19677. +#define MESSAGE_TX_CHANNEL_BULK_NEXT(c) (MESSAGE_TX_CHANNEL_BULK+((c)-MESSAGE_TX_CHANNEL_BULK+1)%VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION)
  19678. +
  19679. +typedef enum message_rx_channel
  19680. +{
  19681. + MESSAGE_RX_CHANNEL_MESSAGE = 0,
  19682. + MESSAGE_RX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
  19683. +} MESSAGE_RX_CHANNEL_T;
  19684. +
  19685. +// Message receive slot information
  19686. +typedef struct rx_msg_slot_info {
  19687. +
  19688. + struct rx_msg_slot_info *next;
  19689. + //struct slot_info *prev;
  19690. +#if !defined VCHI_COARSE_LOCKING
  19691. + struct semaphore sem;
  19692. +#endif
  19693. +
  19694. + uint8_t *addr; // base address of slot
  19695. + uint32_t len; // length of slot in bytes
  19696. +
  19697. + uint32_t write_ptr; // hardware causes this to advance
  19698. + uint32_t read_ptr; // this module does the reading
  19699. + int active; // is this slot in the hardware dma fifo?
  19700. + uint32_t msgs_parsed; // count how many messages are in this slot
  19701. + uint32_t msgs_released; // how many messages have been released
  19702. + void *state; // connection state information
  19703. + uint8_t ref_count[VCHI_MAX_SERVICES_PER_CONNECTION]; // reference count for slots held by services
  19704. +} RX_MSG_SLOTINFO_T;
  19705. +
  19706. +// The message driver no longer needs to know about the fields of RX_BULK_SLOTINFO_T - sort this out.
  19707. +// In particular, it mustn't use addr and len - they're the client buffer, but the message
  19708. +// driver will be tasked with sending the aligned core section.
  19709. +typedef struct rx_bulk_slotinfo_t {
  19710. + struct rx_bulk_slotinfo_t *next;
  19711. +
  19712. + struct semaphore *blocking;
  19713. +
  19714. + // needed by DMA
  19715. + void *addr;
  19716. + uint32_t len;
  19717. +
  19718. + // needed for the callback
  19719. + void *service;
  19720. + void *handle;
  19721. + VCHI_FLAGS_T flags;
  19722. +} RX_BULK_SLOTINFO_T;
  19723. +
  19724. +
  19725. +/* ----------------------------------------------------------------------
  19726. + * each connection driver will have a pool of the following struct.
  19727. + *
  19728. + * the pool will be managed by vchi_qman_*
  19729. + * this means there will be multiple queues (single linked lists)
  19730. + * a given struct message_info will be on exactly one of these queues
  19731. + * at any one time
  19732. + * -------------------------------------------------------------------- */
  19733. +typedef struct rx_message_info {
  19734. +
  19735. + struct message_info *next;
  19736. + //struct message_info *prev;
  19737. +
  19738. + uint8_t *addr;
  19739. + uint32_t len;
  19740. + RX_MSG_SLOTINFO_T *slot; // points to whichever slot contains this message
  19741. + uint32_t tx_timestamp;
  19742. + uint32_t rx_timestamp;
  19743. +
  19744. +} RX_MESSAGE_INFO_T;
  19745. +
  19746. +typedef struct {
  19747. + MESSAGE_EVENT_TYPE_T type;
  19748. +
  19749. + struct {
  19750. + // for messages
  19751. + void *addr; // address of message
  19752. + uint16_t slot_delta; // whether this message indicated slot delta
  19753. + uint32_t len; // length of message
  19754. + RX_MSG_SLOTINFO_T *slot; // slot this message is in
  19755. + int32_t service; // service id this message is destined for
  19756. + uint32_t tx_timestamp; // timestamp from the header
  19757. + uint32_t rx_timestamp; // timestamp when we parsed it
  19758. + } message;
  19759. +
  19760. + // FIXME: cleanup slot reporting...
  19761. + RX_MSG_SLOTINFO_T *rx_msg;
  19762. + RX_BULK_SLOTINFO_T *rx_bulk;
  19763. + void *tx_handle;
  19764. + MESSAGE_TX_CHANNEL_T tx_channel;
  19765. +
  19766. +} MESSAGE_EVENT_T;
  19767. +
  19768. +
  19769. +// callbacks
  19770. +typedef void VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T( void *state );
  19771. +
  19772. +typedef struct {
  19773. + VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T *event_callback;
  19774. +} VCHI_MESSAGE_DRIVER_OPEN_T;
  19775. +
  19776. +
  19777. +// handle to this instance of message driver (as returned by ->open)
  19778. +typedef struct opaque_mhandle_t *VCHI_MDRIVER_HANDLE_T;
  19779. +
  19780. +struct opaque_vchi_message_driver_t {
  19781. + VCHI_MDRIVER_HANDLE_T *(*open)( VCHI_MESSAGE_DRIVER_OPEN_T *params, void *state );
  19782. + int32_t (*suspending)( VCHI_MDRIVER_HANDLE_T *handle );
  19783. + int32_t (*resumed)( VCHI_MDRIVER_HANDLE_T *handle );
  19784. + int32_t (*power_control)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T, int32_t enable );
  19785. + int32_t (*add_msg_rx_slot)( VCHI_MDRIVER_HANDLE_T *handle, RX_MSG_SLOTINFO_T *slot ); // rx message
  19786. + int32_t (*add_bulk_rx)( VCHI_MDRIVER_HANDLE_T *handle, void *data, uint32_t len, RX_BULK_SLOTINFO_T *slot ); // rx data (bulk)
  19787. + 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)
  19788. + void (*next_event)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_EVENT_T *event ); // get the next event from message_driver
  19789. + int32_t (*enable)( VCHI_MDRIVER_HANDLE_T *handle );
  19790. + int32_t (*form_message)( VCHI_MDRIVER_HANDLE_T *handle, int32_t service_id, VCHI_MSG_VECTOR_T *vector, uint32_t count, void
  19791. + *address, uint32_t length_avail, uint32_t max_total_length, int32_t pad_to_fill, int32_t allow_partial );
  19792. +
  19793. + int32_t (*update_message)( VCHI_MDRIVER_HANDLE_T *handle, void *dest, int16_t *slot_count );
  19794. + int32_t (*buffer_aligned)( VCHI_MDRIVER_HANDLE_T *handle, int tx, int uncached, const void *address, const uint32_t length );
  19795. + void * (*allocate_buffer)( VCHI_MDRIVER_HANDLE_T *handle, uint32_t *length );
  19796. + void (*free_buffer)( VCHI_MDRIVER_HANDLE_T *handle, void *address );
  19797. + int (*rx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
  19798. + int (*tx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
  19799. +
  19800. + int32_t (*tx_supports_terminate)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  19801. + uint32_t (*tx_bulk_chunk_size)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  19802. + int (*tx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  19803. + int (*rx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_RX_CHANNEL_T channel );
  19804. + 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 );
  19805. + void (*debug)( VCHI_MDRIVER_HANDLE_T *handle );
  19806. +};
  19807. +
  19808. +
  19809. +#endif // _VCHI_MESSAGE_H_
  19810. +
  19811. +/****************************** End of file ***********************************/
  19812. diff -Nur linux-3.15.4/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h
  19813. --- linux-3.15.4/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h 1970-01-01 01:00:00.000000000 +0100
  19814. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h 2014-04-13 17:32:57.000000000 +0200
  19815. @@ -0,0 +1,224 @@
  19816. +/**
  19817. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  19818. + *
  19819. + * Redistribution and use in source and binary forms, with or without
  19820. + * modification, are permitted provided that the following conditions
  19821. + * are met:
  19822. + * 1. Redistributions of source code must retain the above copyright
  19823. + * notice, this list of conditions, and the following disclaimer,
  19824. + * without modification.
  19825. + * 2. Redistributions in binary form must reproduce the above copyright
  19826. + * notice, this list of conditions and the following disclaimer in the
  19827. + * documentation and/or other materials provided with the distribution.
  19828. + * 3. The names of the above-listed copyright holders may not be used
  19829. + * to endorse or promote products derived from this software without
  19830. + * specific prior written permission.
  19831. + *
  19832. + * ALTERNATIVELY, this software may be distributed under the terms of the
  19833. + * GNU General Public License ("GPL") version 2, as published by the Free
  19834. + * Software Foundation.
  19835. + *
  19836. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  19837. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19838. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19839. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19840. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19841. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19842. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19843. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19844. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19845. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19846. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19847. + */
  19848. +
  19849. +#ifndef VCHI_CFG_H_
  19850. +#define VCHI_CFG_H_
  19851. +
  19852. +/****************************************************************************************
  19853. + * Defines in this first section are part of the VCHI API and may be examined by VCHI
  19854. + * services.
  19855. + ***************************************************************************************/
  19856. +
  19857. +/* Required alignment of base addresses for bulk transfer, if unaligned transfers are not enabled */
  19858. +/* Really determined by the message driver, and should be available from a run-time call. */
  19859. +#ifndef VCHI_BULK_ALIGN
  19860. +# if __VCCOREVER__ >= 0x04000000
  19861. +# define VCHI_BULK_ALIGN 32 // Allows for the need to do cache cleans
  19862. +# else
  19863. +# define VCHI_BULK_ALIGN 16
  19864. +# endif
  19865. +#endif
  19866. +
  19867. +/* Required length multiple for bulk transfers, if unaligned transfers are not enabled */
  19868. +/* May be less than or greater than VCHI_BULK_ALIGN */
  19869. +/* Really determined by the message driver, and should be available from a run-time call. */
  19870. +#ifndef VCHI_BULK_GRANULARITY
  19871. +# if __VCCOREVER__ >= 0x04000000
  19872. +# define VCHI_BULK_GRANULARITY 32 // Allows for the need to do cache cleans
  19873. +# else
  19874. +# define VCHI_BULK_GRANULARITY 16
  19875. +# endif
  19876. +#endif
  19877. +
  19878. +/* The largest possible message to be queued with vchi_msg_queue. */
  19879. +#ifndef VCHI_MAX_MSG_SIZE
  19880. +# if defined VCHI_LOCAL_HOST_PORT
  19881. +# define VCHI_MAX_MSG_SIZE 16384 // makes file transfers fast, but should they be using bulk?
  19882. +# else
  19883. +# define VCHI_MAX_MSG_SIZE 4096 // NOTE: THIS MUST BE LARGER THAN OR EQUAL TO THE SIZE OF THE KHRONOS MERGE BUFFER!!
  19884. +# endif
  19885. +#endif
  19886. +
  19887. +/******************************************************************************************
  19888. + * Defines below are system configuration options, and should not be used by VCHI services.
  19889. + *****************************************************************************************/
  19890. +
  19891. +/* How many connections can we support? A localhost implementation uses 2 connections,
  19892. + * 1 for host-app, 1 for VMCS, and these are hooked together by a loopback MPHI VCFW
  19893. + * driver. */
  19894. +#ifndef VCHI_MAX_NUM_CONNECTIONS
  19895. +# define VCHI_MAX_NUM_CONNECTIONS 3
  19896. +#endif
  19897. +
  19898. +/* How many services can we open per connection? Extending this doesn't cost processing time, just a small
  19899. + * amount of static memory. */
  19900. +#ifndef VCHI_MAX_SERVICES_PER_CONNECTION
  19901. +# define VCHI_MAX_SERVICES_PER_CONNECTION 36
  19902. +#endif
  19903. +
  19904. +/* Adjust if using a message driver that supports more logical TX channels */
  19905. +#ifndef VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION
  19906. +# define VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION 9 // 1 MPHI + 8 CCP2 logical channels
  19907. +#endif
  19908. +
  19909. +/* Adjust if using a message driver that supports more logical RX channels */
  19910. +#ifndef VCHI_MAX_BULK_RX_CHANNELS_PER_CONNECTION
  19911. +# define VCHI_MAX_BULK_RX_CHANNELS_PER_CONNECTION 1 // 1 MPHI
  19912. +#endif
  19913. +
  19914. +/* How many receive slots do we use. This times VCHI_MAX_MSG_SIZE gives the effective
  19915. + * receive queue space, less message headers. */
  19916. +#ifndef VCHI_NUM_READ_SLOTS
  19917. +# if defined(VCHI_LOCAL_HOST_PORT)
  19918. +# define VCHI_NUM_READ_SLOTS 4
  19919. +# else
  19920. +# define VCHI_NUM_READ_SLOTS 48
  19921. +# endif
  19922. +#endif
  19923. +
  19924. +/* Do we utilise overrun facility for receive message slots? Can aid peer transmit
  19925. + * performance. Only define on VideoCore end, talking to host.
  19926. + */
  19927. +//#define VCHI_MSG_RX_OVERRUN
  19928. +
  19929. +/* How many transmit slots do we use. Generally don't need many, as the hardware driver
  19930. + * underneath VCHI will usually have its own buffering. */
  19931. +#ifndef VCHI_NUM_WRITE_SLOTS
  19932. +# define VCHI_NUM_WRITE_SLOTS 4
  19933. +#endif
  19934. +
  19935. +/* If a service has held or queued received messages in VCHI_XOFF_THRESHOLD or more slots,
  19936. + * then it's taking up too much buffer space, and the peer service will be told to stop
  19937. + * transmitting with an XOFF message. For this to be effective, the VCHI_NUM_READ_SLOTS
  19938. + * needs to be considerably bigger than VCHI_NUM_WRITE_SLOTS, or the transmit latency
  19939. + * is too high. */
  19940. +#ifndef VCHI_XOFF_THRESHOLD
  19941. +# define VCHI_XOFF_THRESHOLD (VCHI_NUM_READ_SLOTS / 2)
  19942. +#endif
  19943. +
  19944. +/* After we've sent an XOFF, the peer will be told to resume transmission once the local
  19945. + * service has dequeued/released enough messages that it's now occupying
  19946. + * VCHI_XON_THRESHOLD slots or fewer. */
  19947. +#ifndef VCHI_XON_THRESHOLD
  19948. +# define VCHI_XON_THRESHOLD (VCHI_NUM_READ_SLOTS / 4)
  19949. +#endif
  19950. +
  19951. +/* A size below which a bulk transfer omits the handshake completely and always goes
  19952. + * via the message channel, if bulk auxiliary is being sent on that service. (The user
  19953. + * can guarantee this by enabling unaligned transmits).
  19954. + * Not API. */
  19955. +#ifndef VCHI_MIN_BULK_SIZE
  19956. +# define VCHI_MIN_BULK_SIZE ( VCHI_MAX_MSG_SIZE / 2 < 4096 ? VCHI_MAX_MSG_SIZE / 2 : 4096 )
  19957. +#endif
  19958. +
  19959. +/* Maximum size of bulk transmission chunks, for each interface type. A trade-off between
  19960. + * speed and latency; the smaller the chunk size the better change of messages and other
  19961. + * bulk transmissions getting in when big bulk transfers are happening. Set to 0 to not
  19962. + * break transmissions into chunks.
  19963. + */
  19964. +#ifndef VCHI_MAX_BULK_CHUNK_SIZE_MPHI
  19965. +# define VCHI_MAX_BULK_CHUNK_SIZE_MPHI (16 * 1024)
  19966. +#endif
  19967. +
  19968. +/* NB Chunked CCP2 transmissions violate the letter of the CCP2 spec by using "JPEG8" mode
  19969. + * with multiple-line frames. Only use if the receiver can cope. */
  19970. +#ifndef VCHI_MAX_BULK_CHUNK_SIZE_CCP2
  19971. +# define VCHI_MAX_BULK_CHUNK_SIZE_CCP2 0
  19972. +#endif
  19973. +
  19974. +/* How many TX messages can we have pending in our transmit slots. Once exhausted,
  19975. + * vchi_msg_queue will be blocked. */
  19976. +#ifndef VCHI_TX_MSG_QUEUE_SIZE
  19977. +# define VCHI_TX_MSG_QUEUE_SIZE 256
  19978. +#endif
  19979. +
  19980. +/* How many RX messages can we have parsed in the receive slots. Once exhausted, parsing
  19981. + * will be suspended until older messages are dequeued/released. */
  19982. +#ifndef VCHI_RX_MSG_QUEUE_SIZE
  19983. +# define VCHI_RX_MSG_QUEUE_SIZE 256
  19984. +#endif
  19985. +
  19986. +/* Really should be able to cope if we run out of received message descriptors, by
  19987. + * suspending parsing as the comment above says, but we don't. This sweeps the issue
  19988. + * under the carpet. */
  19989. +#if VCHI_RX_MSG_QUEUE_SIZE < (VCHI_MAX_MSG_SIZE/16 + 1) * VCHI_NUM_READ_SLOTS
  19990. +# undef VCHI_RX_MSG_QUEUE_SIZE
  19991. +# define VCHI_RX_MSG_QUEUE_SIZE (VCHI_MAX_MSG_SIZE/16 + 1) * VCHI_NUM_READ_SLOTS
  19992. +#endif
  19993. +
  19994. +/* How many bulk transmits can we have pending. Once exhausted, vchi_bulk_queue_transmit
  19995. + * will be blocked. */
  19996. +#ifndef VCHI_TX_BULK_QUEUE_SIZE
  19997. +# define VCHI_TX_BULK_QUEUE_SIZE 64
  19998. +#endif
  19999. +
  20000. +/* How many bulk receives can we have pending. Once exhausted, vchi_bulk_queue_receive
  20001. + * will be blocked. */
  20002. +#ifndef VCHI_RX_BULK_QUEUE_SIZE
  20003. +# define VCHI_RX_BULK_QUEUE_SIZE 64
  20004. +#endif
  20005. +
  20006. +/* A limit on how many outstanding bulk requests we expect the peer to give us. If
  20007. + * the peer asks for more than this, VCHI will fail and assert. The number is determined
  20008. + * by the peer's hardware - it's the number of outstanding requests that can be queued
  20009. + * on all bulk channels. VC3's MPHI peripheral allows 16. */
  20010. +#ifndef VCHI_MAX_PEER_BULK_REQUESTS
  20011. +# define VCHI_MAX_PEER_BULK_REQUESTS 32
  20012. +#endif
  20013. +
  20014. +/* Define VCHI_CCP2TX_MANUAL_POWER if the host tells us when to turn the CCP2
  20015. + * transmitter on and off.
  20016. + */
  20017. +/*#define VCHI_CCP2TX_MANUAL_POWER*/
  20018. +
  20019. +#ifndef VCHI_CCP2TX_MANUAL_POWER
  20020. +
  20021. +/* Timeout (in milliseconds) for putting the CCP2TX interface into IDLE state. Set
  20022. + * negative for no IDLE.
  20023. + */
  20024. +# ifndef VCHI_CCP2TX_IDLE_TIMEOUT
  20025. +# define VCHI_CCP2TX_IDLE_TIMEOUT 5
  20026. +# endif
  20027. +
  20028. +/* Timeout (in milliseconds) for putting the CCP2TX interface into OFF state. Set
  20029. + * negative for no OFF.
  20030. + */
  20031. +# ifndef VCHI_CCP2TX_OFF_TIMEOUT
  20032. +# define VCHI_CCP2TX_OFF_TIMEOUT 1000
  20033. +# endif
  20034. +
  20035. +#endif /* VCHI_CCP2TX_MANUAL_POWER */
  20036. +
  20037. +#endif /* VCHI_CFG_H_ */
  20038. +
  20039. +/****************************** End of file **********************************/
  20040. diff -Nur linux-3.15.4/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h
  20041. --- linux-3.15.4/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h 1970-01-01 01:00:00.000000000 +0100
  20042. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h 2014-04-13 17:32:57.000000000 +0200
  20043. @@ -0,0 +1,71 @@
  20044. +/**
  20045. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  20046. + *
  20047. + * Redistribution and use in source and binary forms, with or without
  20048. + * modification, are permitted provided that the following conditions
  20049. + * are met:
  20050. + * 1. Redistributions of source code must retain the above copyright
  20051. + * notice, this list of conditions, and the following disclaimer,
  20052. + * without modification.
  20053. + * 2. Redistributions in binary form must reproduce the above copyright
  20054. + * notice, this list of conditions and the following disclaimer in the
  20055. + * documentation and/or other materials provided with the distribution.
  20056. + * 3. The names of the above-listed copyright holders may not be used
  20057. + * to endorse or promote products derived from this software without
  20058. + * specific prior written permission.
  20059. + *
  20060. + * ALTERNATIVELY, this software may be distributed under the terms of the
  20061. + * GNU General Public License ("GPL") version 2, as published by the Free
  20062. + * Software Foundation.
  20063. + *
  20064. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  20065. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  20066. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20067. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  20068. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  20069. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20070. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20071. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  20072. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  20073. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  20074. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20075. + */
  20076. +
  20077. +#ifndef VCHI_CFG_INTERNAL_H_
  20078. +#define VCHI_CFG_INTERNAL_H_
  20079. +
  20080. +/****************************************************************************************
  20081. + * Control optimisation attempts.
  20082. + ***************************************************************************************/
  20083. +
  20084. +// Don't use lots of short-term locks - use great long ones, reducing the overall locks-per-second
  20085. +#define VCHI_COARSE_LOCKING
  20086. +
  20087. +// Avoid lock then unlock on exit from blocking queue operations (msg tx, bulk rx/tx)
  20088. +// (only relevant if VCHI_COARSE_LOCKING)
  20089. +#define VCHI_ELIDE_BLOCK_EXIT_LOCK
  20090. +
  20091. +// Avoid lock on non-blocking peek
  20092. +// (only relevant if VCHI_COARSE_LOCKING)
  20093. +#define VCHI_AVOID_PEEK_LOCK
  20094. +
  20095. +// Use one slot-handler thread per connection, rather than 1 thread dealing with all connections in rotation.
  20096. +#define VCHI_MULTIPLE_HANDLER_THREADS
  20097. +
  20098. +// Put free descriptors onto the head of the free queue, rather than the tail, so that we don't thrash
  20099. +// our way through the pool of descriptors.
  20100. +#define VCHI_PUSH_FREE_DESCRIPTORS_ONTO_HEAD
  20101. +
  20102. +// Don't issue a MSG_AVAILABLE callback for every single message. Possibly only safe if VCHI_COARSE_LOCKING.
  20103. +#define VCHI_FEWER_MSG_AVAILABLE_CALLBACKS
  20104. +
  20105. +// Don't use message descriptors for TX messages that don't need them
  20106. +#define VCHI_MINIMISE_TX_MSG_DESCRIPTORS
  20107. +
  20108. +// Nano-locks for multiqueue
  20109. +//#define VCHI_MQUEUE_NANOLOCKS
  20110. +
  20111. +// Lock-free(er) dequeuing
  20112. +//#define VCHI_RX_NANOLOCKS
  20113. +
  20114. +#endif /*VCHI_CFG_INTERNAL_H_*/
  20115. diff -Nur linux-3.15.4/drivers/misc/vc04_services/interface/vchi/vchi_common.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_common.h
  20116. --- linux-3.15.4/drivers/misc/vc04_services/interface/vchi/vchi_common.h 1970-01-01 01:00:00.000000000 +0100
  20117. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_common.h 2014-04-13 17:32:57.000000000 +0200
  20118. @@ -0,0 +1,163 @@
  20119. +/**
  20120. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  20121. + *
  20122. + * Redistribution and use in source and binary forms, with or without
  20123. + * modification, are permitted provided that the following conditions
  20124. + * are met:
  20125. + * 1. Redistributions of source code must retain the above copyright
  20126. + * notice, this list of conditions, and the following disclaimer,
  20127. + * without modification.
  20128. + * 2. Redistributions in binary form must reproduce the above copyright
  20129. + * notice, this list of conditions and the following disclaimer in the
  20130. + * documentation and/or other materials provided with the distribution.
  20131. + * 3. The names of the above-listed copyright holders may not be used
  20132. + * to endorse or promote products derived from this software without
  20133. + * specific prior written permission.
  20134. + *
  20135. + * ALTERNATIVELY, this software may be distributed under the terms of the
  20136. + * GNU General Public License ("GPL") version 2, as published by the Free
  20137. + * Software Foundation.
  20138. + *
  20139. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  20140. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  20141. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20142. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  20143. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  20144. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20145. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20146. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  20147. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  20148. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  20149. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20150. + */
  20151. +
  20152. +#ifndef VCHI_COMMON_H_
  20153. +#define VCHI_COMMON_H_
  20154. +
  20155. +
  20156. +//flags used when sending messages (must be bitmapped)
  20157. +typedef enum
  20158. +{
  20159. + VCHI_FLAGS_NONE = 0x0,
  20160. + 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)
  20161. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE = 0x2, // run a callback when message sent
  20162. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED = 0x4, // return once the transfer is in a queue ready to go
  20163. + VCHI_FLAGS_ALLOW_PARTIAL = 0x8,
  20164. + VCHI_FLAGS_BLOCK_UNTIL_DATA_READ = 0x10,
  20165. + VCHI_FLAGS_CALLBACK_WHEN_DATA_READ = 0x20,
  20166. +
  20167. + VCHI_FLAGS_ALIGN_SLOT = 0x000080, // internal use only
  20168. + VCHI_FLAGS_BULK_AUX_QUEUED = 0x010000, // internal use only
  20169. + VCHI_FLAGS_BULK_AUX_COMPLETE = 0x020000, // internal use only
  20170. + VCHI_FLAGS_BULK_DATA_QUEUED = 0x040000, // internal use only
  20171. + VCHI_FLAGS_BULK_DATA_COMPLETE = 0x080000, // internal use only
  20172. + VCHI_FLAGS_INTERNAL = 0xFF0000
  20173. +} VCHI_FLAGS_T;
  20174. +
  20175. +// constants for vchi_crc_control()
  20176. +typedef enum {
  20177. + VCHI_CRC_NOTHING = -1,
  20178. + VCHI_CRC_PER_SERVICE = 0,
  20179. + VCHI_CRC_EVERYTHING = 1,
  20180. +} VCHI_CRC_CONTROL_T;
  20181. +
  20182. +//callback reasons when an event occurs on a service
  20183. +typedef enum
  20184. +{
  20185. + VCHI_CALLBACK_REASON_MIN,
  20186. +
  20187. + //This indicates that there is data available
  20188. + //handle is the msg id that was transmitted with the data
  20189. + // When a message is received and there was no FULL message available previously, send callback
  20190. + // Tasks get kicked by the callback, reset their event and try and read from the fifo until it fails
  20191. + VCHI_CALLBACK_MSG_AVAILABLE,
  20192. + VCHI_CALLBACK_MSG_SENT,
  20193. + VCHI_CALLBACK_MSG_SPACE_AVAILABLE, // XXX not yet implemented
  20194. +
  20195. + // This indicates that a transfer from the other side has completed
  20196. + VCHI_CALLBACK_BULK_RECEIVED,
  20197. + //This indicates that data queued up to be sent has now gone
  20198. + //handle is the msg id that was used when sending the data
  20199. + VCHI_CALLBACK_BULK_SENT,
  20200. + VCHI_CALLBACK_BULK_RX_SPACE_AVAILABLE, // XXX not yet implemented
  20201. + VCHI_CALLBACK_BULK_TX_SPACE_AVAILABLE, // XXX not yet implemented
  20202. +
  20203. + VCHI_CALLBACK_SERVICE_CLOSED,
  20204. +
  20205. + // this side has sent XOFF to peer due to lack of data consumption by service
  20206. + // (suggests the service may need to take some recovery action if it has
  20207. + // been deliberately holding off consuming data)
  20208. + VCHI_CALLBACK_SENT_XOFF,
  20209. + VCHI_CALLBACK_SENT_XON,
  20210. +
  20211. + // indicates that a bulk transfer has finished reading the source buffer
  20212. + VCHI_CALLBACK_BULK_DATA_READ,
  20213. +
  20214. + // power notification events (currently host side only)
  20215. + VCHI_CALLBACK_PEER_OFF,
  20216. + VCHI_CALLBACK_PEER_SUSPENDED,
  20217. + VCHI_CALLBACK_PEER_ON,
  20218. + VCHI_CALLBACK_PEER_RESUMED,
  20219. + VCHI_CALLBACK_FORCED_POWER_OFF,
  20220. +
  20221. +#ifdef USE_VCHIQ_ARM
  20222. + // some extra notifications provided by vchiq_arm
  20223. + VCHI_CALLBACK_SERVICE_OPENED,
  20224. + VCHI_CALLBACK_BULK_RECEIVE_ABORTED,
  20225. + VCHI_CALLBACK_BULK_TRANSMIT_ABORTED,
  20226. +#endif
  20227. +
  20228. + VCHI_CALLBACK_REASON_MAX
  20229. +} VCHI_CALLBACK_REASON_T;
  20230. +
  20231. +//Calback used by all services / bulk transfers
  20232. +typedef void (*VCHI_CALLBACK_T)( void *callback_param, //my service local param
  20233. + VCHI_CALLBACK_REASON_T reason,
  20234. + void *handle ); //for transmitting msg's only
  20235. +
  20236. +
  20237. +
  20238. +/*
  20239. + * Define vector struct for scatter-gather (vector) operations
  20240. + * Vectors can be nested - if a vector element has negative length, then
  20241. + * the data pointer is treated as pointing to another vector array, with
  20242. + * '-vec_len' elements. Thus to append a header onto an existing vector,
  20243. + * you can do this:
  20244. + *
  20245. + * void foo(const VCHI_MSG_VECTOR_T *v, int n)
  20246. + * {
  20247. + * VCHI_MSG_VECTOR_T nv[2];
  20248. + * nv[0].vec_base = my_header;
  20249. + * nv[0].vec_len = sizeof my_header;
  20250. + * nv[1].vec_base = v;
  20251. + * nv[1].vec_len = -n;
  20252. + * ...
  20253. + *
  20254. + */
  20255. +typedef struct vchi_msg_vector {
  20256. + const void *vec_base;
  20257. + int32_t vec_len;
  20258. +} VCHI_MSG_VECTOR_T;
  20259. +
  20260. +// Opaque type for a connection API
  20261. +typedef struct opaque_vchi_connection_api_t VCHI_CONNECTION_API_T;
  20262. +
  20263. +// Opaque type for a message driver
  20264. +typedef struct opaque_vchi_message_driver_t VCHI_MESSAGE_DRIVER_T;
  20265. +
  20266. +
  20267. +// Iterator structure for reading ahead through received message queue. Allocated by client,
  20268. +// initialised by vchi_msg_look_ahead. Fields are for internal VCHI use only.
  20269. +// Iterates over messages in queue at the instant of the call to vchi_msg_lookahead -
  20270. +// will not proceed to messages received since. Behaviour is undefined if an iterator
  20271. +// is used again after messages for that service are removed/dequeued by any
  20272. +// means other than vchi_msg_iter_... calls on the iterator itself.
  20273. +typedef struct {
  20274. + struct opaque_vchi_service_t *service;
  20275. + void *last;
  20276. + void *next;
  20277. + void *remove;
  20278. +} VCHI_MSG_ITER_T;
  20279. +
  20280. +
  20281. +#endif // VCHI_COMMON_H_
  20282. diff -Nur linux-3.15.4/drivers/misc/vc04_services/interface/vchi/vchi.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi.h
  20283. --- linux-3.15.4/drivers/misc/vc04_services/interface/vchi/vchi.h 1970-01-01 01:00:00.000000000 +0100
  20284. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi.h 2014-04-13 17:32:57.000000000 +0200
  20285. @@ -0,0 +1,373 @@
  20286. +/**
  20287. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  20288. + *
  20289. + * Redistribution and use in source and binary forms, with or without
  20290. + * modification, are permitted provided that the following conditions
  20291. + * are met:
  20292. + * 1. Redistributions of source code must retain the above copyright
  20293. + * notice, this list of conditions, and the following disclaimer,
  20294. + * without modification.
  20295. + * 2. Redistributions in binary form must reproduce the above copyright
  20296. + * notice, this list of conditions and the following disclaimer in the
  20297. + * documentation and/or other materials provided with the distribution.
  20298. + * 3. The names of the above-listed copyright holders may not be used
  20299. + * to endorse or promote products derived from this software without
  20300. + * specific prior written permission.
  20301. + *
  20302. + * ALTERNATIVELY, this software may be distributed under the terms of the
  20303. + * GNU General Public License ("GPL") version 2, as published by the Free
  20304. + * Software Foundation.
  20305. + *
  20306. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  20307. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  20308. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20309. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  20310. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  20311. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20312. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20313. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  20314. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  20315. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  20316. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20317. + */
  20318. +
  20319. +#ifndef VCHI_H_
  20320. +#define VCHI_H_
  20321. +
  20322. +#include "interface/vchi/vchi_cfg.h"
  20323. +#include "interface/vchi/vchi_common.h"
  20324. +#include "interface/vchi/connections/connection.h"
  20325. +#include "vchi_mh.h"
  20326. +
  20327. +
  20328. +/******************************************************************************
  20329. + Global defs
  20330. + *****************************************************************************/
  20331. +
  20332. +#define VCHI_BULK_ROUND_UP(x) ((((unsigned long)(x))+VCHI_BULK_ALIGN-1) & ~(VCHI_BULK_ALIGN-1))
  20333. +#define VCHI_BULK_ROUND_DOWN(x) (((unsigned long)(x)) & ~(VCHI_BULK_ALIGN-1))
  20334. +#define VCHI_BULK_ALIGN_NBYTES(x) (VCHI_BULK_ALIGNED(x) ? 0 : (VCHI_BULK_ALIGN - ((unsigned long)(x) & (VCHI_BULK_ALIGN-1))))
  20335. +
  20336. +#ifdef USE_VCHIQ_ARM
  20337. +#define VCHI_BULK_ALIGNED(x) 1
  20338. +#else
  20339. +#define VCHI_BULK_ALIGNED(x) (((unsigned long)(x) & (VCHI_BULK_ALIGN-1)) == 0)
  20340. +#endif
  20341. +
  20342. +struct vchi_version {
  20343. + uint32_t version;
  20344. + uint32_t version_min;
  20345. +};
  20346. +#define VCHI_VERSION(v_) { v_, v_ }
  20347. +#define VCHI_VERSION_EX(v_, m_) { v_, m_ }
  20348. +
  20349. +typedef enum
  20350. +{
  20351. + VCHI_VEC_POINTER,
  20352. + VCHI_VEC_HANDLE,
  20353. + VCHI_VEC_LIST
  20354. +} VCHI_MSG_VECTOR_TYPE_T;
  20355. +
  20356. +typedef struct vchi_msg_vector_ex {
  20357. +
  20358. + VCHI_MSG_VECTOR_TYPE_T type;
  20359. + union
  20360. + {
  20361. + // a memory handle
  20362. + struct
  20363. + {
  20364. + VCHI_MEM_HANDLE_T handle;
  20365. + uint32_t offset;
  20366. + int32_t vec_len;
  20367. + } handle;
  20368. +
  20369. + // an ordinary data pointer
  20370. + struct
  20371. + {
  20372. + const void *vec_base;
  20373. + int32_t vec_len;
  20374. + } ptr;
  20375. +
  20376. + // a nested vector list
  20377. + struct
  20378. + {
  20379. + struct vchi_msg_vector_ex *vec;
  20380. + uint32_t vec_len;
  20381. + } list;
  20382. + } u;
  20383. +} VCHI_MSG_VECTOR_EX_T;
  20384. +
  20385. +
  20386. +// Construct an entry in a msg vector for a pointer (p) of length (l)
  20387. +#define VCHI_VEC_POINTER(p,l) VCHI_VEC_POINTER, { { (VCHI_MEM_HANDLE_T)(p), (l) } }
  20388. +
  20389. +// Construct an entry in a msg vector for a message handle (h), starting at offset (o) of length (l)
  20390. +#define VCHI_VEC_HANDLE(h,o,l) VCHI_VEC_HANDLE, { { (h), (o), (l) } }
  20391. +
  20392. +// Macros to manipulate 'FOURCC' values
  20393. +#define MAKE_FOURCC(x) ((int32_t)( (x[0] << 24) | (x[1] << 16) | (x[2] << 8) | x[3] ))
  20394. +#define FOURCC_TO_CHAR(x) (x >> 24) & 0xFF,(x >> 16) & 0xFF,(x >> 8) & 0xFF, x & 0xFF
  20395. +
  20396. +
  20397. +// Opaque service information
  20398. +struct opaque_vchi_service_t;
  20399. +
  20400. +// Descriptor for a held message. Allocated by client, initialised by vchi_msg_hold,
  20401. +// vchi_msg_iter_hold or vchi_msg_iter_hold_next. Fields are for internal VCHI use only.
  20402. +typedef struct
  20403. +{
  20404. + struct opaque_vchi_service_t *service;
  20405. + void *message;
  20406. +} VCHI_HELD_MSG_T;
  20407. +
  20408. +
  20409. +
  20410. +// structure used to provide the information needed to open a server or a client
  20411. +typedef struct {
  20412. + struct vchi_version version;
  20413. + int32_t service_id;
  20414. + VCHI_CONNECTION_T *connection;
  20415. + uint32_t rx_fifo_size;
  20416. + uint32_t tx_fifo_size;
  20417. + VCHI_CALLBACK_T callback;
  20418. + void *callback_param;
  20419. + /* client intends to receive bulk transfers of
  20420. + odd lengths or into unaligned buffers */
  20421. + int32_t want_unaligned_bulk_rx;
  20422. + /* client intends to transmit bulk transfers of
  20423. + odd lengths or out of unaligned buffers */
  20424. + int32_t want_unaligned_bulk_tx;
  20425. + /* client wants to check CRCs on (bulk) xfers.
  20426. + Only needs to be set at 1 end - will do both directions. */
  20427. + int32_t want_crc;
  20428. +} SERVICE_CREATION_T;
  20429. +
  20430. +// Opaque handle for a VCHI instance
  20431. +typedef struct opaque_vchi_instance_handle_t *VCHI_INSTANCE_T;
  20432. +
  20433. +// Opaque handle for a server or client
  20434. +typedef struct opaque_vchi_service_handle_t *VCHI_SERVICE_HANDLE_T;
  20435. +
  20436. +// Service registration & startup
  20437. +typedef void (*VCHI_SERVICE_INIT)(VCHI_INSTANCE_T initialise_instance, VCHI_CONNECTION_T **connections, uint32_t num_connections);
  20438. +
  20439. +typedef struct service_info_tag {
  20440. + const char * const vll_filename; /* VLL to load to start this service. This is an empty string if VLL is "static" */
  20441. + VCHI_SERVICE_INIT init; /* Service initialisation function */
  20442. + void *vll_handle; /* VLL handle; NULL when unloaded or a "static VLL" in build */
  20443. +} SERVICE_INFO_T;
  20444. +
  20445. +/******************************************************************************
  20446. + Global funcs - implementation is specific to which side you are on (local / remote)
  20447. + *****************************************************************************/
  20448. +
  20449. +#ifdef __cplusplus
  20450. +extern "C" {
  20451. +#endif
  20452. +
  20453. +extern /*@observer@*/ VCHI_CONNECTION_T * vchi_create_connection( const VCHI_CONNECTION_API_T * function_table,
  20454. + const VCHI_MESSAGE_DRIVER_T * low_level);
  20455. +
  20456. +
  20457. +// Routine used to initialise the vchi on both local + remote connections
  20458. +extern int32_t vchi_initialise( VCHI_INSTANCE_T *instance_handle );
  20459. +
  20460. +extern int32_t vchi_exit( void );
  20461. +
  20462. +extern int32_t vchi_connect( VCHI_CONNECTION_T **connections,
  20463. + const uint32_t num_connections,
  20464. + VCHI_INSTANCE_T instance_handle );
  20465. +
  20466. +//When this is called, ensure that all services have no data pending.
  20467. +//Bulk transfers can remain 'queued'
  20468. +extern int32_t vchi_disconnect( VCHI_INSTANCE_T instance_handle );
  20469. +
  20470. +// Global control over bulk CRC checking
  20471. +extern int32_t vchi_crc_control( VCHI_CONNECTION_T *connection,
  20472. + VCHI_CRC_CONTROL_T control );
  20473. +
  20474. +// helper functions
  20475. +extern void * vchi_allocate_buffer(VCHI_SERVICE_HANDLE_T handle, uint32_t *length);
  20476. +extern void vchi_free_buffer(VCHI_SERVICE_HANDLE_T handle, void *address);
  20477. +extern uint32_t vchi_current_time(VCHI_INSTANCE_T instance_handle);
  20478. +
  20479. +
  20480. +/******************************************************************************
  20481. + Global service API
  20482. + *****************************************************************************/
  20483. +// Routine to create a named service
  20484. +extern int32_t vchi_service_create( VCHI_INSTANCE_T instance_handle,
  20485. + SERVICE_CREATION_T *setup,
  20486. + VCHI_SERVICE_HANDLE_T *handle );
  20487. +
  20488. +// Routine to destory a service
  20489. +extern int32_t vchi_service_destroy( const VCHI_SERVICE_HANDLE_T handle );
  20490. +
  20491. +// Routine to open a named service
  20492. +extern int32_t vchi_service_open( VCHI_INSTANCE_T instance_handle,
  20493. + SERVICE_CREATION_T *setup,
  20494. + VCHI_SERVICE_HANDLE_T *handle);
  20495. +
  20496. +extern int32_t vchi_get_peer_version( const VCHI_SERVICE_HANDLE_T handle,
  20497. + short *peer_version );
  20498. +
  20499. +// Routine to close a named service
  20500. +extern int32_t vchi_service_close( const VCHI_SERVICE_HANDLE_T handle );
  20501. +
  20502. +// Routine to increment ref count on a named service
  20503. +extern int32_t vchi_service_use( const VCHI_SERVICE_HANDLE_T handle );
  20504. +
  20505. +// Routine to decrement ref count on a named service
  20506. +extern int32_t vchi_service_release( const VCHI_SERVICE_HANDLE_T handle );
  20507. +
  20508. +// Routine to send a message accross a service
  20509. +extern int32_t vchi_msg_queue( VCHI_SERVICE_HANDLE_T handle,
  20510. + const void *data,
  20511. + uint32_t data_size,
  20512. + VCHI_FLAGS_T flags,
  20513. + void *msg_handle );
  20514. +
  20515. +// scatter-gather (vector) and send message
  20516. +int32_t vchi_msg_queuev_ex( VCHI_SERVICE_HANDLE_T handle,
  20517. + VCHI_MSG_VECTOR_EX_T *vector,
  20518. + uint32_t count,
  20519. + VCHI_FLAGS_T flags,
  20520. + void *msg_handle );
  20521. +
  20522. +// legacy scatter-gather (vector) and send message, only handles pointers
  20523. +int32_t vchi_msg_queuev( VCHI_SERVICE_HANDLE_T handle,
  20524. + VCHI_MSG_VECTOR_T *vector,
  20525. + uint32_t count,
  20526. + VCHI_FLAGS_T flags,
  20527. + void *msg_handle );
  20528. +
  20529. +// Routine to receive a msg from a service
  20530. +// Dequeue is equivalent to hold, copy into client buffer, release
  20531. +extern int32_t vchi_msg_dequeue( VCHI_SERVICE_HANDLE_T handle,
  20532. + void *data,
  20533. + uint32_t max_data_size_to_read,
  20534. + uint32_t *actual_msg_size,
  20535. + VCHI_FLAGS_T flags );
  20536. +
  20537. +// Routine to look at a message in place.
  20538. +// The message is not dequeued, so a subsequent call to peek or dequeue
  20539. +// will return the same message.
  20540. +extern int32_t vchi_msg_peek( VCHI_SERVICE_HANDLE_T handle,
  20541. + void **data,
  20542. + uint32_t *msg_size,
  20543. + VCHI_FLAGS_T flags );
  20544. +
  20545. +// Routine to remove a message after it has been read in place with peek
  20546. +// The first message on the queue is dequeued.
  20547. +extern int32_t vchi_msg_remove( VCHI_SERVICE_HANDLE_T handle );
  20548. +
  20549. +// Routine to look at a message in place.
  20550. +// The message is dequeued, so the caller is left holding it; the descriptor is
  20551. +// filled in and must be released when the user has finished with the message.
  20552. +extern int32_t vchi_msg_hold( VCHI_SERVICE_HANDLE_T handle,
  20553. + void **data, // } may be NULL, as info can be
  20554. + uint32_t *msg_size, // } obtained from HELD_MSG_T
  20555. + VCHI_FLAGS_T flags,
  20556. + VCHI_HELD_MSG_T *message_descriptor );
  20557. +
  20558. +// Initialise an iterator to look through messages in place
  20559. +extern int32_t vchi_msg_look_ahead( VCHI_SERVICE_HANDLE_T handle,
  20560. + VCHI_MSG_ITER_T *iter,
  20561. + VCHI_FLAGS_T flags );
  20562. +
  20563. +/******************************************************************************
  20564. + Global service support API - operations on held messages and message iterators
  20565. + *****************************************************************************/
  20566. +
  20567. +// Routine to get the address of a held message
  20568. +extern void *vchi_held_msg_ptr( const VCHI_HELD_MSG_T *message );
  20569. +
  20570. +// Routine to get the size of a held message
  20571. +extern int32_t vchi_held_msg_size( const VCHI_HELD_MSG_T *message );
  20572. +
  20573. +// Routine to get the transmit timestamp as written into the header by the peer
  20574. +extern uint32_t vchi_held_msg_tx_timestamp( const VCHI_HELD_MSG_T *message );
  20575. +
  20576. +// Routine to get the reception timestamp, written as we parsed the header
  20577. +extern uint32_t vchi_held_msg_rx_timestamp( const VCHI_HELD_MSG_T *message );
  20578. +
  20579. +// Routine to release a held message after it has been processed
  20580. +extern int32_t vchi_held_msg_release( VCHI_HELD_MSG_T *message );
  20581. +
  20582. +// Indicates whether the iterator has a next message.
  20583. +extern int32_t vchi_msg_iter_has_next( const VCHI_MSG_ITER_T *iter );
  20584. +
  20585. +// Return the pointer and length for the next message and advance the iterator.
  20586. +extern int32_t vchi_msg_iter_next( VCHI_MSG_ITER_T *iter,
  20587. + void **data,
  20588. + uint32_t *msg_size );
  20589. +
  20590. +// Remove the last message returned by vchi_msg_iter_next.
  20591. +// Can only be called once after each call to vchi_msg_iter_next.
  20592. +extern int32_t vchi_msg_iter_remove( VCHI_MSG_ITER_T *iter );
  20593. +
  20594. +// Hold the last message returned by vchi_msg_iter_next.
  20595. +// Can only be called once after each call to vchi_msg_iter_next.
  20596. +extern int32_t vchi_msg_iter_hold( VCHI_MSG_ITER_T *iter,
  20597. + VCHI_HELD_MSG_T *message );
  20598. +
  20599. +// Return information for the next message, and hold it, advancing the iterator.
  20600. +extern int32_t vchi_msg_iter_hold_next( VCHI_MSG_ITER_T *iter,
  20601. + void **data, // } may be NULL
  20602. + uint32_t *msg_size, // }
  20603. + VCHI_HELD_MSG_T *message );
  20604. +
  20605. +
  20606. +/******************************************************************************
  20607. + Global bulk API
  20608. + *****************************************************************************/
  20609. +
  20610. +// Routine to prepare interface for a transfer from the other side
  20611. +extern int32_t vchi_bulk_queue_receive( VCHI_SERVICE_HANDLE_T handle,
  20612. + void *data_dst,
  20613. + uint32_t data_size,
  20614. + VCHI_FLAGS_T flags,
  20615. + void *transfer_handle );
  20616. +
  20617. +
  20618. +// Prepare interface for a transfer from the other side into relocatable memory.
  20619. +int32_t vchi_bulk_queue_receive_reloc( const VCHI_SERVICE_HANDLE_T handle,
  20620. + VCHI_MEM_HANDLE_T h_dst,
  20621. + uint32_t offset,
  20622. + uint32_t data_size,
  20623. + const VCHI_FLAGS_T flags,
  20624. + void * const bulk_handle );
  20625. +
  20626. +// Routine to queue up data ready for transfer to the other (once they have signalled they are ready)
  20627. +extern int32_t vchi_bulk_queue_transmit( VCHI_SERVICE_HANDLE_T handle,
  20628. + const void *data_src,
  20629. + uint32_t data_size,
  20630. + VCHI_FLAGS_T flags,
  20631. + void *transfer_handle );
  20632. +
  20633. +
  20634. +/******************************************************************************
  20635. + Configuration plumbing
  20636. + *****************************************************************************/
  20637. +
  20638. +// function prototypes for the different mid layers (the state info gives the different physical connections)
  20639. +extern const VCHI_CONNECTION_API_T *single_get_func_table( void );
  20640. +//extern const VCHI_CONNECTION_API_T *local_server_get_func_table( void );
  20641. +//extern const VCHI_CONNECTION_API_T *local_client_get_func_table( void );
  20642. +
  20643. +// declare all message drivers here
  20644. +const VCHI_MESSAGE_DRIVER_T *vchi_mphi_message_driver_func_table( void );
  20645. +
  20646. +#ifdef __cplusplus
  20647. +}
  20648. +#endif
  20649. +
  20650. +extern int32_t vchi_bulk_queue_transmit_reloc( VCHI_SERVICE_HANDLE_T handle,
  20651. + VCHI_MEM_HANDLE_T h_src,
  20652. + uint32_t offset,
  20653. + uint32_t data_size,
  20654. + VCHI_FLAGS_T flags,
  20655. + void *transfer_handle );
  20656. +#endif /* VCHI_H_ */
  20657. +
  20658. +/****************************** End of file **********************************/
  20659. diff -Nur linux-3.15.4/drivers/misc/vc04_services/interface/vchi/vchi_mh.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_mh.h
  20660. --- linux-3.15.4/drivers/misc/vc04_services/interface/vchi/vchi_mh.h 1970-01-01 01:00:00.000000000 +0100
  20661. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_mh.h 2014-04-13 17:32:57.000000000 +0200
  20662. @@ -0,0 +1,42 @@
  20663. +/**
  20664. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  20665. + *
  20666. + * Redistribution and use in source and binary forms, with or without
  20667. + * modification, are permitted provided that the following conditions
  20668. + * are met:
  20669. + * 1. Redistributions of source code must retain the above copyright
  20670. + * notice, this list of conditions, and the following disclaimer,
  20671. + * without modification.
  20672. + * 2. Redistributions in binary form must reproduce the above copyright
  20673. + * notice, this list of conditions and the following disclaimer in the
  20674. + * documentation and/or other materials provided with the distribution.
  20675. + * 3. The names of the above-listed copyright holders may not be used
  20676. + * to endorse or promote products derived from this software without
  20677. + * specific prior written permission.
  20678. + *
  20679. + * ALTERNATIVELY, this software may be distributed under the terms of the
  20680. + * GNU General Public License ("GPL") version 2, as published by the Free
  20681. + * Software Foundation.
  20682. + *
  20683. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  20684. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  20685. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20686. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  20687. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  20688. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20689. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20690. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  20691. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  20692. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  20693. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20694. + */
  20695. +
  20696. +#ifndef VCHI_MH_H_
  20697. +#define VCHI_MH_H_
  20698. +
  20699. +#include <linux/types.h>
  20700. +
  20701. +typedef int32_t VCHI_MEM_HANDLE_T;
  20702. +#define VCHI_MEM_HANDLE_INVALID 0
  20703. +
  20704. +#endif
  20705. diff -Nur linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
  20706. --- linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c 1970-01-01 01:00:00.000000000 +0100
  20707. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c 2014-07-07 10:45:11.000000000 +0200
  20708. @@ -0,0 +1,562 @@
  20709. +/**
  20710. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  20711. + *
  20712. + * Redistribution and use in source and binary forms, with or without
  20713. + * modification, are permitted provided that the following conditions
  20714. + * are met:
  20715. + * 1. Redistributions of source code must retain the above copyright
  20716. + * notice, this list of conditions, and the following disclaimer,
  20717. + * without modification.
  20718. + * 2. Redistributions in binary form must reproduce the above copyright
  20719. + * notice, this list of conditions and the following disclaimer in the
  20720. + * documentation and/or other materials provided with the distribution.
  20721. + * 3. The names of the above-listed copyright holders may not be used
  20722. + * to endorse or promote products derived from this software without
  20723. + * specific prior written permission.
  20724. + *
  20725. + * ALTERNATIVELY, this software may be distributed under the terms of the
  20726. + * GNU General Public License ("GPL") version 2, as published by the Free
  20727. + * Software Foundation.
  20728. + *
  20729. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  20730. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  20731. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20732. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  20733. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  20734. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20735. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20736. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  20737. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  20738. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  20739. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20740. + */
  20741. +
  20742. +#include <linux/kernel.h>
  20743. +#include <linux/types.h>
  20744. +#include <linux/errno.h>
  20745. +#include <linux/interrupt.h>
  20746. +#include <linux/irq.h>
  20747. +#include <linux/pagemap.h>
  20748. +#include <linux/dma-mapping.h>
  20749. +#include <linux/version.h>
  20750. +#include <linux/io.h>
  20751. +#include <linux/uaccess.h>
  20752. +#include <asm/pgtable.h>
  20753. +
  20754. +#include <mach/irqs.h>
  20755. +
  20756. +#include <mach/platform.h>
  20757. +#include <mach/vcio.h>
  20758. +
  20759. +#define TOTAL_SLOTS (VCHIQ_SLOT_ZERO_SLOTS + 2 * 32)
  20760. +
  20761. +#define VCHIQ_DOORBELL_IRQ IRQ_ARM_DOORBELL_0
  20762. +#define VCHIQ_ARM_ADDRESS(x) ((void *)__virt_to_bus((unsigned)x))
  20763. +
  20764. +#include "vchiq_arm.h"
  20765. +#include "vchiq_2835.h"
  20766. +#include "vchiq_connected.h"
  20767. +#include "vchiq_killable.h"
  20768. +
  20769. +#define MAX_FRAGMENTS (VCHIQ_NUM_CURRENT_BULKS * 2)
  20770. +
  20771. +typedef struct vchiq_2835_state_struct {
  20772. + int inited;
  20773. + VCHIQ_ARM_STATE_T arm_state;
  20774. +} VCHIQ_2835_ARM_STATE_T;
  20775. +
  20776. +static char *g_slot_mem;
  20777. +static int g_slot_mem_size;
  20778. +dma_addr_t g_slot_phys;
  20779. +static FRAGMENTS_T *g_fragments_base;
  20780. +static FRAGMENTS_T *g_free_fragments;
  20781. +struct semaphore g_free_fragments_sema;
  20782. +
  20783. +extern int vchiq_arm_log_level;
  20784. +
  20785. +static DEFINE_SEMAPHORE(g_free_fragments_mutex);
  20786. +
  20787. +static irqreturn_t
  20788. +vchiq_doorbell_irq(int irq, void *dev_id);
  20789. +
  20790. +static int
  20791. +create_pagelist(char __user *buf, size_t count, unsigned short type,
  20792. + struct task_struct *task, PAGELIST_T ** ppagelist);
  20793. +
  20794. +static void
  20795. +free_pagelist(PAGELIST_T *pagelist, int actual);
  20796. +
  20797. +int __init
  20798. +vchiq_platform_init(VCHIQ_STATE_T *state)
  20799. +{
  20800. + VCHIQ_SLOT_ZERO_T *vchiq_slot_zero;
  20801. + int frag_mem_size;
  20802. + int err;
  20803. + int i;
  20804. +
  20805. + /* Allocate space for the channels in coherent memory */
  20806. + g_slot_mem_size = PAGE_ALIGN(TOTAL_SLOTS * VCHIQ_SLOT_SIZE);
  20807. + frag_mem_size = PAGE_ALIGN(sizeof(FRAGMENTS_T) * MAX_FRAGMENTS);
  20808. +
  20809. + g_slot_mem = dma_alloc_coherent(NULL, g_slot_mem_size + frag_mem_size,
  20810. + &g_slot_phys, GFP_ATOMIC);
  20811. +
  20812. + if (!g_slot_mem) {
  20813. + vchiq_log_error(vchiq_arm_log_level,
  20814. + "Unable to allocate channel memory");
  20815. + err = -ENOMEM;
  20816. + goto failed_alloc;
  20817. + }
  20818. +
  20819. + WARN_ON(((int)g_slot_mem & (PAGE_SIZE - 1)) != 0);
  20820. +
  20821. + vchiq_slot_zero = vchiq_init_slots(g_slot_mem, g_slot_mem_size);
  20822. + if (!vchiq_slot_zero) {
  20823. + err = -EINVAL;
  20824. + goto failed_init_slots;
  20825. + }
  20826. +
  20827. + vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX] =
  20828. + (int)g_slot_phys + g_slot_mem_size;
  20829. + vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX] =
  20830. + MAX_FRAGMENTS;
  20831. +
  20832. + g_fragments_base = (FRAGMENTS_T *)(g_slot_mem + g_slot_mem_size);
  20833. + g_slot_mem_size += frag_mem_size;
  20834. +
  20835. + g_free_fragments = g_fragments_base;
  20836. + for (i = 0; i < (MAX_FRAGMENTS - 1); i++) {
  20837. + *(FRAGMENTS_T **)&g_fragments_base[i] =
  20838. + &g_fragments_base[i + 1];
  20839. + }
  20840. + *(FRAGMENTS_T **)&g_fragments_base[i] = NULL;
  20841. + sema_init(&g_free_fragments_sema, MAX_FRAGMENTS);
  20842. +
  20843. + if (vchiq_init_state(state, vchiq_slot_zero, 0/*slave*/) !=
  20844. + VCHIQ_SUCCESS) {
  20845. + err = -EINVAL;
  20846. + goto failed_vchiq_init;
  20847. + }
  20848. +
  20849. + err = request_irq(VCHIQ_DOORBELL_IRQ, vchiq_doorbell_irq,
  20850. + IRQF_IRQPOLL, "VCHIQ doorbell",
  20851. + state);
  20852. + if (err < 0) {
  20853. + vchiq_log_error(vchiq_arm_log_level, "%s: failed to register "
  20854. + "irq=%d err=%d", __func__,
  20855. + VCHIQ_DOORBELL_IRQ, err);
  20856. + goto failed_request_irq;
  20857. + }
  20858. +
  20859. + /* Send the base address of the slots to VideoCore */
  20860. +
  20861. + dsb(); /* Ensure all writes have completed */
  20862. +
  20863. + bcm_mailbox_write(MBOX_CHAN_VCHIQ, (unsigned int)g_slot_phys);
  20864. +
  20865. + vchiq_log_info(vchiq_arm_log_level,
  20866. + "vchiq_init - done (slots %x, phys %x)",
  20867. + (unsigned int)vchiq_slot_zero, g_slot_phys);
  20868. +
  20869. + vchiq_call_connected_callbacks();
  20870. +
  20871. + return 0;
  20872. +
  20873. +failed_request_irq:
  20874. +failed_vchiq_init:
  20875. +failed_init_slots:
  20876. + dma_free_coherent(NULL, g_slot_mem_size, g_slot_mem, g_slot_phys);
  20877. +
  20878. +failed_alloc:
  20879. + return err;
  20880. +}
  20881. +
  20882. +void __exit
  20883. +vchiq_platform_exit(VCHIQ_STATE_T *state)
  20884. +{
  20885. + free_irq(VCHIQ_DOORBELL_IRQ, state);
  20886. + dma_free_coherent(NULL, g_slot_mem_size,
  20887. + g_slot_mem, g_slot_phys);
  20888. +}
  20889. +
  20890. +
  20891. +VCHIQ_STATUS_T
  20892. +vchiq_platform_init_state(VCHIQ_STATE_T *state)
  20893. +{
  20894. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  20895. + state->platform_state = kzalloc(sizeof(VCHIQ_2835_ARM_STATE_T), GFP_KERNEL);
  20896. + ((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited = 1;
  20897. + status = vchiq_arm_init_state(state, &((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->arm_state);
  20898. + if(status != VCHIQ_SUCCESS)
  20899. + {
  20900. + ((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited = 0;
  20901. + }
  20902. + return status;
  20903. +}
  20904. +
  20905. +VCHIQ_ARM_STATE_T*
  20906. +vchiq_platform_get_arm_state(VCHIQ_STATE_T *state)
  20907. +{
  20908. + if(!((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited)
  20909. + {
  20910. + BUG();
  20911. + }
  20912. + return &((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->arm_state;
  20913. +}
  20914. +
  20915. +void
  20916. +remote_event_signal(REMOTE_EVENT_T *event)
  20917. +{
  20918. + wmb();
  20919. +
  20920. + event->fired = 1;
  20921. +
  20922. + dsb(); /* data barrier operation */
  20923. +
  20924. + if (event->armed) {
  20925. + /* trigger vc interrupt */
  20926. +
  20927. + writel(0, __io_address(ARM_0_BELL2));
  20928. + }
  20929. +}
  20930. +
  20931. +int
  20932. +vchiq_copy_from_user(void *dst, const void *src, int size)
  20933. +{
  20934. + if ((uint32_t)src < TASK_SIZE) {
  20935. + return copy_from_user(dst, src, size);
  20936. + } else {
  20937. + memcpy(dst, src, size);
  20938. + return 0;
  20939. + }
  20940. +}
  20941. +
  20942. +VCHIQ_STATUS_T
  20943. +vchiq_prepare_bulk_data(VCHIQ_BULK_T *bulk, VCHI_MEM_HANDLE_T memhandle,
  20944. + void *offset, int size, int dir)
  20945. +{
  20946. + PAGELIST_T *pagelist;
  20947. + int ret;
  20948. +
  20949. + WARN_ON(memhandle != VCHI_MEM_HANDLE_INVALID);
  20950. +
  20951. + ret = create_pagelist((char __user *)offset, size,
  20952. + (dir == VCHIQ_BULK_RECEIVE)
  20953. + ? PAGELIST_READ
  20954. + : PAGELIST_WRITE,
  20955. + current,
  20956. + &pagelist);
  20957. + if (ret != 0)
  20958. + return VCHIQ_ERROR;
  20959. +
  20960. + bulk->handle = memhandle;
  20961. + bulk->data = VCHIQ_ARM_ADDRESS(pagelist);
  20962. +
  20963. + /* Store the pagelist address in remote_data, which isn't used by the
  20964. + slave. */
  20965. + bulk->remote_data = pagelist;
  20966. +
  20967. + return VCHIQ_SUCCESS;
  20968. +}
  20969. +
  20970. +void
  20971. +vchiq_complete_bulk(VCHIQ_BULK_T *bulk)
  20972. +{
  20973. + if (bulk && bulk->remote_data && bulk->actual)
  20974. + free_pagelist((PAGELIST_T *)bulk->remote_data, bulk->actual);
  20975. +}
  20976. +
  20977. +void
  20978. +vchiq_transfer_bulk(VCHIQ_BULK_T *bulk)
  20979. +{
  20980. + /*
  20981. + * This should only be called on the master (VideoCore) side, but
  20982. + * provide an implementation to avoid the need for ifdefery.
  20983. + */
  20984. + BUG();
  20985. +}
  20986. +
  20987. +void
  20988. +vchiq_dump_platform_state(void *dump_context)
  20989. +{
  20990. + char buf[80];
  20991. + int len;
  20992. + len = snprintf(buf, sizeof(buf),
  20993. + " Platform: 2835 (VC master)");
  20994. + vchiq_dump(dump_context, buf, len + 1);
  20995. +}
  20996. +
  20997. +VCHIQ_STATUS_T
  20998. +vchiq_platform_suspend(VCHIQ_STATE_T *state)
  20999. +{
  21000. + return VCHIQ_ERROR;
  21001. +}
  21002. +
  21003. +VCHIQ_STATUS_T
  21004. +vchiq_platform_resume(VCHIQ_STATE_T *state)
  21005. +{
  21006. + return VCHIQ_SUCCESS;
  21007. +}
  21008. +
  21009. +void
  21010. +vchiq_platform_paused(VCHIQ_STATE_T *state)
  21011. +{
  21012. +}
  21013. +
  21014. +void
  21015. +vchiq_platform_resumed(VCHIQ_STATE_T *state)
  21016. +{
  21017. +}
  21018. +
  21019. +int
  21020. +vchiq_platform_videocore_wanted(VCHIQ_STATE_T* state)
  21021. +{
  21022. + return 1; // autosuspend not supported - videocore always wanted
  21023. +}
  21024. +
  21025. +int
  21026. +vchiq_platform_use_suspend_timer(void)
  21027. +{
  21028. + return 0;
  21029. +}
  21030. +void
  21031. +vchiq_dump_platform_use_state(VCHIQ_STATE_T *state)
  21032. +{
  21033. + vchiq_log_info((vchiq_arm_log_level>=VCHIQ_LOG_INFO),"Suspend timer not in use");
  21034. +}
  21035. +void
  21036. +vchiq_platform_handle_timeout(VCHIQ_STATE_T *state)
  21037. +{
  21038. + (void)state;
  21039. +}
  21040. +/*
  21041. + * Local functions
  21042. + */
  21043. +
  21044. +static irqreturn_t
  21045. +vchiq_doorbell_irq(int irq, void *dev_id)
  21046. +{
  21047. + VCHIQ_STATE_T *state = dev_id;
  21048. + irqreturn_t ret = IRQ_NONE;
  21049. + unsigned int status;
  21050. +
  21051. + /* Read (and clear) the doorbell */
  21052. + status = readl(__io_address(ARM_0_BELL0));
  21053. +
  21054. + if (status & 0x4) { /* Was the doorbell rung? */
  21055. + remote_event_pollall(state);
  21056. + ret = IRQ_HANDLED;
  21057. + }
  21058. +
  21059. + return ret;
  21060. +}
  21061. +
  21062. +/* There is a potential problem with partial cache lines (pages?)
  21063. +** at the ends of the block when reading. If the CPU accessed anything in
  21064. +** the same line (page?) then it may have pulled old data into the cache,
  21065. +** obscuring the new data underneath. We can solve this by transferring the
  21066. +** partial cache lines separately, and allowing the ARM to copy into the
  21067. +** cached area.
  21068. +
  21069. +** N.B. This implementation plays slightly fast and loose with the Linux
  21070. +** driver programming rules, e.g. its use of __virt_to_bus instead of
  21071. +** dma_map_single, but it isn't a multi-platform driver and it benefits
  21072. +** from increased speed as a result.
  21073. +*/
  21074. +
  21075. +static int
  21076. +create_pagelist(char __user *buf, size_t count, unsigned short type,
  21077. + struct task_struct *task, PAGELIST_T ** ppagelist)
  21078. +{
  21079. + PAGELIST_T *pagelist;
  21080. + struct page **pages;
  21081. + struct page *page;
  21082. + unsigned long *addrs;
  21083. + unsigned int num_pages, offset, i;
  21084. + char *addr, *base_addr, *next_addr;
  21085. + int run, addridx, actual_pages;
  21086. + unsigned long *need_release;
  21087. +
  21088. + offset = (unsigned int)buf & (PAGE_SIZE - 1);
  21089. + num_pages = (count + offset + PAGE_SIZE - 1) / PAGE_SIZE;
  21090. +
  21091. + *ppagelist = NULL;
  21092. +
  21093. + /* Allocate enough storage to hold the page pointers and the page
  21094. + ** list
  21095. + */
  21096. + pagelist = kmalloc(sizeof(PAGELIST_T) +
  21097. + (num_pages * sizeof(unsigned long)) +
  21098. + sizeof(unsigned long) +
  21099. + (num_pages * sizeof(pages[0])),
  21100. + GFP_KERNEL);
  21101. +
  21102. + vchiq_log_trace(vchiq_arm_log_level,
  21103. + "create_pagelist - %x", (unsigned int)pagelist);
  21104. + if (!pagelist)
  21105. + return -ENOMEM;
  21106. +
  21107. + addrs = pagelist->addrs;
  21108. + need_release = (unsigned long *)(addrs + num_pages);
  21109. + pages = (struct page **)(addrs + num_pages + 1);
  21110. +
  21111. + if (is_vmalloc_addr(buf)) {
  21112. + for (actual_pages = 0; actual_pages < num_pages; actual_pages++) {
  21113. + pages[actual_pages] = vmalloc_to_page(buf + (actual_pages * PAGE_SIZE));
  21114. + }
  21115. + *need_release = 0; /* do not try and release vmalloc pages */
  21116. + } else {
  21117. + down_read(&task->mm->mmap_sem);
  21118. + actual_pages = get_user_pages(task, task->mm,
  21119. + (unsigned long)buf & ~(PAGE_SIZE - 1),
  21120. + num_pages,
  21121. + (type == PAGELIST_READ) /*Write */ ,
  21122. + 0 /*Force */ ,
  21123. + pages,
  21124. + NULL /*vmas */);
  21125. + up_read(&task->mm->mmap_sem);
  21126. +
  21127. + if (actual_pages != num_pages) {
  21128. + vchiq_log_info(vchiq_arm_log_level,
  21129. + "create_pagelist - only %d/%d pages locked",
  21130. + actual_pages,
  21131. + num_pages);
  21132. +
  21133. + /* This is probably due to the process being killed */
  21134. + while (actual_pages > 0)
  21135. + {
  21136. + actual_pages--;
  21137. + page_cache_release(pages[actual_pages]);
  21138. + }
  21139. + kfree(pagelist);
  21140. + if (actual_pages == 0)
  21141. + actual_pages = -ENOMEM;
  21142. + return actual_pages;
  21143. + }
  21144. + *need_release = 1; /* release user pages */
  21145. + }
  21146. +
  21147. + pagelist->length = count;
  21148. + pagelist->type = type;
  21149. + pagelist->offset = offset;
  21150. +
  21151. + /* Group the pages into runs of contiguous pages */
  21152. +
  21153. + base_addr = VCHIQ_ARM_ADDRESS(page_address(pages[0]));
  21154. + next_addr = base_addr + PAGE_SIZE;
  21155. + addridx = 0;
  21156. + run = 0;
  21157. +
  21158. + for (i = 1; i < num_pages; i++) {
  21159. + addr = VCHIQ_ARM_ADDRESS(page_address(pages[i]));
  21160. + if ((addr == next_addr) && (run < (PAGE_SIZE - 1))) {
  21161. + next_addr += PAGE_SIZE;
  21162. + run++;
  21163. + } else {
  21164. + addrs[addridx] = (unsigned long)base_addr + run;
  21165. + addridx++;
  21166. + base_addr = addr;
  21167. + next_addr = addr + PAGE_SIZE;
  21168. + run = 0;
  21169. + }
  21170. + }
  21171. +
  21172. + addrs[addridx] = (unsigned long)base_addr + run;
  21173. + addridx++;
  21174. +
  21175. + /* Partial cache lines (fragments) require special measures */
  21176. + if ((type == PAGELIST_READ) &&
  21177. + ((pagelist->offset & (CACHE_LINE_SIZE - 1)) ||
  21178. + ((pagelist->offset + pagelist->length) &
  21179. + (CACHE_LINE_SIZE - 1)))) {
  21180. + FRAGMENTS_T *fragments;
  21181. +
  21182. + if (down_interruptible(&g_free_fragments_sema) != 0) {
  21183. + kfree(pagelist);
  21184. + return -EINTR;
  21185. + }
  21186. +
  21187. + WARN_ON(g_free_fragments == NULL);
  21188. +
  21189. + down(&g_free_fragments_mutex);
  21190. + fragments = (FRAGMENTS_T *) g_free_fragments;
  21191. + WARN_ON(fragments == NULL);
  21192. + g_free_fragments = *(FRAGMENTS_T **) g_free_fragments;
  21193. + up(&g_free_fragments_mutex);
  21194. + pagelist->type =
  21195. + PAGELIST_READ_WITH_FRAGMENTS + (fragments -
  21196. + g_fragments_base);
  21197. + }
  21198. +
  21199. + for (page = virt_to_page(pagelist);
  21200. + page <= virt_to_page(addrs + num_pages - 1); page++) {
  21201. + flush_dcache_page(page);
  21202. + }
  21203. +
  21204. + *ppagelist = pagelist;
  21205. +
  21206. + return 0;
  21207. +}
  21208. +
  21209. +static void
  21210. +free_pagelist(PAGELIST_T *pagelist, int actual)
  21211. +{
  21212. + unsigned long *need_release;
  21213. + struct page **pages;
  21214. + unsigned int num_pages, i;
  21215. +
  21216. + vchiq_log_trace(vchiq_arm_log_level,
  21217. + "free_pagelist - %x, %d", (unsigned int)pagelist, actual);
  21218. +
  21219. + num_pages =
  21220. + (pagelist->length + pagelist->offset + PAGE_SIZE - 1) /
  21221. + PAGE_SIZE;
  21222. +
  21223. + need_release = (unsigned long *)(pagelist->addrs + num_pages);
  21224. + pages = (struct page **)(pagelist->addrs + num_pages + 1);
  21225. +
  21226. + /* Deal with any partial cache lines (fragments) */
  21227. + if (pagelist->type >= PAGELIST_READ_WITH_FRAGMENTS) {
  21228. + FRAGMENTS_T *fragments = g_fragments_base +
  21229. + (pagelist->type - PAGELIST_READ_WITH_FRAGMENTS);
  21230. + int head_bytes, tail_bytes;
  21231. + head_bytes = (CACHE_LINE_SIZE - pagelist->offset) &
  21232. + (CACHE_LINE_SIZE - 1);
  21233. + tail_bytes = (pagelist->offset + actual) &
  21234. + (CACHE_LINE_SIZE - 1);
  21235. +
  21236. + if ((actual >= 0) && (head_bytes != 0)) {
  21237. + if (head_bytes > actual)
  21238. + head_bytes = actual;
  21239. +
  21240. + memcpy((char *)page_address(pages[0]) +
  21241. + pagelist->offset,
  21242. + fragments->headbuf,
  21243. + head_bytes);
  21244. + }
  21245. + if ((actual >= 0) && (head_bytes < actual) &&
  21246. + (tail_bytes != 0)) {
  21247. + memcpy((char *)page_address(pages[num_pages - 1]) +
  21248. + ((pagelist->offset + actual) &
  21249. + (PAGE_SIZE - 1) & ~(CACHE_LINE_SIZE - 1)),
  21250. + fragments->tailbuf, tail_bytes);
  21251. + }
  21252. +
  21253. + down(&g_free_fragments_mutex);
  21254. + *(FRAGMENTS_T **) fragments = g_free_fragments;
  21255. + g_free_fragments = fragments;
  21256. + up(&g_free_fragments_mutex);
  21257. + up(&g_free_fragments_sema);
  21258. + }
  21259. +
  21260. + if (*need_release) {
  21261. + for (i = 0; i < num_pages; i++) {
  21262. + if (pagelist->type != PAGELIST_WRITE)
  21263. + set_page_dirty(pages[i]);
  21264. +
  21265. + page_cache_release(pages[i]);
  21266. + }
  21267. + }
  21268. +
  21269. + kfree(pagelist);
  21270. +}
  21271. diff -Nur linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h
  21272. --- linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h 1970-01-01 01:00:00.000000000 +0100
  21273. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h 2014-04-13 17:32:57.000000000 +0200
  21274. @@ -0,0 +1,42 @@
  21275. +/**
  21276. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  21277. + *
  21278. + * Redistribution and use in source and binary forms, with or without
  21279. + * modification, are permitted provided that the following conditions
  21280. + * are met:
  21281. + * 1. Redistributions of source code must retain the above copyright
  21282. + * notice, this list of conditions, and the following disclaimer,
  21283. + * without modification.
  21284. + * 2. Redistributions in binary form must reproduce the above copyright
  21285. + * notice, this list of conditions and the following disclaimer in the
  21286. + * documentation and/or other materials provided with the distribution.
  21287. + * 3. The names of the above-listed copyright holders may not be used
  21288. + * to endorse or promote products derived from this software without
  21289. + * specific prior written permission.
  21290. + *
  21291. + * ALTERNATIVELY, this software may be distributed under the terms of the
  21292. + * GNU General Public License ("GPL") version 2, as published by the Free
  21293. + * Software Foundation.
  21294. + *
  21295. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  21296. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  21297. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  21298. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  21299. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  21300. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21301. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21302. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  21303. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  21304. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  21305. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21306. + */
  21307. +
  21308. +#ifndef VCHIQ_2835_H
  21309. +#define VCHIQ_2835_H
  21310. +
  21311. +#include "vchiq_pagelist.h"
  21312. +
  21313. +#define VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX 0
  21314. +#define VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX 1
  21315. +
  21316. +#endif /* VCHIQ_2835_H */
  21317. diff -Nur linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c
  21318. --- linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c 1970-01-01 01:00:00.000000000 +0100
  21319. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c 2014-07-07 10:45:11.000000000 +0200
  21320. @@ -0,0 +1,2814 @@
  21321. +/**
  21322. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  21323. + *
  21324. + * Redistribution and use in source and binary forms, with or without
  21325. + * modification, are permitted provided that the following conditions
  21326. + * are met:
  21327. + * 1. Redistributions of source code must retain the above copyright
  21328. + * notice, this list of conditions, and the following disclaimer,
  21329. + * without modification.
  21330. + * 2. Redistributions in binary form must reproduce the above copyright
  21331. + * notice, this list of conditions and the following disclaimer in the
  21332. + * documentation and/or other materials provided with the distribution.
  21333. + * 3. The names of the above-listed copyright holders may not be used
  21334. + * to endorse or promote products derived from this software without
  21335. + * specific prior written permission.
  21336. + *
  21337. + * ALTERNATIVELY, this software may be distributed under the terms of the
  21338. + * GNU General Public License ("GPL") version 2, as published by the Free
  21339. + * Software Foundation.
  21340. + *
  21341. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  21342. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  21343. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  21344. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  21345. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  21346. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21347. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21348. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  21349. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  21350. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  21351. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21352. + */
  21353. +
  21354. +#include <linux/kernel.h>
  21355. +#include <linux/module.h>
  21356. +#include <linux/types.h>
  21357. +#include <linux/errno.h>
  21358. +#include <linux/cdev.h>
  21359. +#include <linux/fs.h>
  21360. +#include <linux/device.h>
  21361. +#include <linux/mm.h>
  21362. +#include <linux/highmem.h>
  21363. +#include <linux/pagemap.h>
  21364. +#include <linux/bug.h>
  21365. +#include <linux/semaphore.h>
  21366. +#include <linux/list.h>
  21367. +#include <linux/proc_fs.h>
  21368. +
  21369. +#include "vchiq_core.h"
  21370. +#include "vchiq_ioctl.h"
  21371. +#include "vchiq_arm.h"
  21372. +#include "vchiq_killable.h"
  21373. +
  21374. +#define DEVICE_NAME "vchiq"
  21375. +
  21376. +/* Override the default prefix, which would be vchiq_arm (from the filename) */
  21377. +#undef MODULE_PARAM_PREFIX
  21378. +#define MODULE_PARAM_PREFIX DEVICE_NAME "."
  21379. +
  21380. +#define VCHIQ_MINOR 0
  21381. +
  21382. +/* Some per-instance constants */
  21383. +#define MAX_COMPLETIONS 16
  21384. +#define MAX_SERVICES 64
  21385. +#define MAX_ELEMENTS 8
  21386. +#define MSG_QUEUE_SIZE 64
  21387. +
  21388. +#define KEEPALIVE_VER 1
  21389. +#define KEEPALIVE_VER_MIN KEEPALIVE_VER
  21390. +
  21391. +/* Run time control of log level, based on KERN_XXX level. */
  21392. +int vchiq_arm_log_level = VCHIQ_LOG_DEFAULT;
  21393. +int vchiq_susp_log_level = VCHIQ_LOG_ERROR;
  21394. +
  21395. +#define SUSPEND_TIMER_TIMEOUT_MS 100
  21396. +#define SUSPEND_RETRY_TIMER_TIMEOUT_MS 1000
  21397. +
  21398. +#define VC_SUSPEND_NUM_OFFSET 3 /* number of values before idle which are -ve */
  21399. +static const char *const suspend_state_names[] = {
  21400. + "VC_SUSPEND_FORCE_CANCELED",
  21401. + "VC_SUSPEND_REJECTED",
  21402. + "VC_SUSPEND_FAILED",
  21403. + "VC_SUSPEND_IDLE",
  21404. + "VC_SUSPEND_REQUESTED",
  21405. + "VC_SUSPEND_IN_PROGRESS",
  21406. + "VC_SUSPEND_SUSPENDED"
  21407. +};
  21408. +#define VC_RESUME_NUM_OFFSET 1 /* number of values before idle which are -ve */
  21409. +static const char *const resume_state_names[] = {
  21410. + "VC_RESUME_FAILED",
  21411. + "VC_RESUME_IDLE",
  21412. + "VC_RESUME_REQUESTED",
  21413. + "VC_RESUME_IN_PROGRESS",
  21414. + "VC_RESUME_RESUMED"
  21415. +};
  21416. +/* The number of times we allow force suspend to timeout before actually
  21417. +** _forcing_ suspend. This is to cater for SW which fails to release vchiq
  21418. +** correctly - we don't want to prevent ARM suspend indefinitely in this case.
  21419. +*/
  21420. +#define FORCE_SUSPEND_FAIL_MAX 8
  21421. +
  21422. +/* The time in ms allowed for videocore to go idle when force suspend has been
  21423. + * requested */
  21424. +#define FORCE_SUSPEND_TIMEOUT_MS 200
  21425. +
  21426. +
  21427. +static void suspend_timer_callback(unsigned long context);
  21428. +static int vchiq_proc_add_instance(VCHIQ_INSTANCE_T instance);
  21429. +static void vchiq_proc_remove_instance(VCHIQ_INSTANCE_T instance);
  21430. +
  21431. +
  21432. +typedef struct user_service_struct {
  21433. + VCHIQ_SERVICE_T *service;
  21434. + void *userdata;
  21435. + VCHIQ_INSTANCE_T instance;
  21436. + int is_vchi;
  21437. + int dequeue_pending;
  21438. + int message_available_pos;
  21439. + int msg_insert;
  21440. + int msg_remove;
  21441. + struct semaphore insert_event;
  21442. + struct semaphore remove_event;
  21443. + VCHIQ_HEADER_T * msg_queue[MSG_QUEUE_SIZE];
  21444. +} USER_SERVICE_T;
  21445. +
  21446. +struct bulk_waiter_node {
  21447. + struct bulk_waiter bulk_waiter;
  21448. + int pid;
  21449. + struct list_head list;
  21450. +};
  21451. +
  21452. +struct vchiq_instance_struct {
  21453. + VCHIQ_STATE_T *state;
  21454. + VCHIQ_COMPLETION_DATA_T completions[MAX_COMPLETIONS];
  21455. + int completion_insert;
  21456. + int completion_remove;
  21457. + struct semaphore insert_event;
  21458. + struct semaphore remove_event;
  21459. + struct mutex completion_mutex;
  21460. +
  21461. + int connected;
  21462. + int closing;
  21463. + int pid;
  21464. + int mark;
  21465. +
  21466. + struct list_head bulk_waiter_list;
  21467. + struct mutex bulk_waiter_list_mutex;
  21468. +
  21469. + struct proc_dir_entry *proc_entry;
  21470. +};
  21471. +
  21472. +typedef struct dump_context_struct {
  21473. + char __user *buf;
  21474. + size_t actual;
  21475. + size_t space;
  21476. + loff_t offset;
  21477. +} DUMP_CONTEXT_T;
  21478. +
  21479. +static struct cdev vchiq_cdev;
  21480. +static dev_t vchiq_devid;
  21481. +static VCHIQ_STATE_T g_state;
  21482. +static struct class *vchiq_class;
  21483. +static struct device *vchiq_dev;
  21484. +static DEFINE_SPINLOCK(msg_queue_spinlock);
  21485. +
  21486. +static const char *const ioctl_names[] = {
  21487. + "CONNECT",
  21488. + "SHUTDOWN",
  21489. + "CREATE_SERVICE",
  21490. + "REMOVE_SERVICE",
  21491. + "QUEUE_MESSAGE",
  21492. + "QUEUE_BULK_TRANSMIT",
  21493. + "QUEUE_BULK_RECEIVE",
  21494. + "AWAIT_COMPLETION",
  21495. + "DEQUEUE_MESSAGE",
  21496. + "GET_CLIENT_ID",
  21497. + "GET_CONFIG",
  21498. + "CLOSE_SERVICE",
  21499. + "USE_SERVICE",
  21500. + "RELEASE_SERVICE",
  21501. + "SET_SERVICE_OPTION",
  21502. + "DUMP_PHYS_MEM"
  21503. +};
  21504. +
  21505. +vchiq_static_assert((sizeof(ioctl_names)/sizeof(ioctl_names[0])) ==
  21506. + (VCHIQ_IOC_MAX + 1));
  21507. +
  21508. +static void
  21509. +dump_phys_mem(void *virt_addr, uint32_t num_bytes);
  21510. +
  21511. +/****************************************************************************
  21512. +*
  21513. +* add_completion
  21514. +*
  21515. +***************************************************************************/
  21516. +
  21517. +static VCHIQ_STATUS_T
  21518. +add_completion(VCHIQ_INSTANCE_T instance, VCHIQ_REASON_T reason,
  21519. + VCHIQ_HEADER_T *header, USER_SERVICE_T *user_service,
  21520. + void *bulk_userdata)
  21521. +{
  21522. + VCHIQ_COMPLETION_DATA_T *completion;
  21523. + DEBUG_INITIALISE(g_state.local)
  21524. +
  21525. + while (instance->completion_insert ==
  21526. + (instance->completion_remove + MAX_COMPLETIONS)) {
  21527. + /* Out of space - wait for the client */
  21528. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  21529. + vchiq_log_trace(vchiq_arm_log_level,
  21530. + "add_completion - completion queue full");
  21531. + DEBUG_COUNT(COMPLETION_QUEUE_FULL_COUNT);
  21532. + if (down_interruptible(&instance->remove_event) != 0) {
  21533. + vchiq_log_info(vchiq_arm_log_level,
  21534. + "service_callback interrupted");
  21535. + return VCHIQ_RETRY;
  21536. + } else if (instance->closing) {
  21537. + vchiq_log_info(vchiq_arm_log_level,
  21538. + "service_callback closing");
  21539. + return VCHIQ_ERROR;
  21540. + }
  21541. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  21542. + }
  21543. +
  21544. + completion =
  21545. + &instance->completions[instance->completion_insert &
  21546. + (MAX_COMPLETIONS - 1)];
  21547. +
  21548. + completion->header = header;
  21549. + completion->reason = reason;
  21550. + /* N.B. service_userdata is updated while processing AWAIT_COMPLETION */
  21551. + completion->service_userdata = user_service->service;
  21552. + completion->bulk_userdata = bulk_userdata;
  21553. +
  21554. + if (reason == VCHIQ_SERVICE_CLOSED)
  21555. + /* Take an extra reference, to be held until
  21556. + this CLOSED notification is delivered. */
  21557. + lock_service(user_service->service);
  21558. +
  21559. + /* A write barrier is needed here to ensure that the entire completion
  21560. + record is written out before the insert point. */
  21561. + wmb();
  21562. +
  21563. + if (reason == VCHIQ_MESSAGE_AVAILABLE)
  21564. + user_service->message_available_pos =
  21565. + instance->completion_insert;
  21566. + instance->completion_insert++;
  21567. +
  21568. + up(&instance->insert_event);
  21569. +
  21570. + return VCHIQ_SUCCESS;
  21571. +}
  21572. +
  21573. +/****************************************************************************
  21574. +*
  21575. +* service_callback
  21576. +*
  21577. +***************************************************************************/
  21578. +
  21579. +static VCHIQ_STATUS_T
  21580. +service_callback(VCHIQ_REASON_T reason, VCHIQ_HEADER_T *header,
  21581. + VCHIQ_SERVICE_HANDLE_T handle, void *bulk_userdata)
  21582. +{
  21583. + /* How do we ensure the callback goes to the right client?
  21584. + ** The service_user data points to a USER_SERVICE_T record containing
  21585. + ** the original callback and the user state structure, which contains a
  21586. + ** circular buffer for completion records.
  21587. + */
  21588. + USER_SERVICE_T *user_service;
  21589. + VCHIQ_SERVICE_T *service;
  21590. + VCHIQ_INSTANCE_T instance;
  21591. + DEBUG_INITIALISE(g_state.local)
  21592. +
  21593. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  21594. +
  21595. + service = handle_to_service(handle);
  21596. + BUG_ON(!service);
  21597. + user_service = (USER_SERVICE_T *)service->base.userdata;
  21598. + instance = user_service->instance;
  21599. +
  21600. + if (!instance || instance->closing)
  21601. + return VCHIQ_SUCCESS;
  21602. +
  21603. + vchiq_log_trace(vchiq_arm_log_level,
  21604. + "service_callback - service %lx(%d), reason %d, header %lx, "
  21605. + "instance %lx, bulk_userdata %lx",
  21606. + (unsigned long)user_service,
  21607. + service->localport,
  21608. + reason, (unsigned long)header,
  21609. + (unsigned long)instance, (unsigned long)bulk_userdata);
  21610. +
  21611. + if (header && user_service->is_vchi) {
  21612. + spin_lock(&msg_queue_spinlock);
  21613. + while (user_service->msg_insert ==
  21614. + (user_service->msg_remove + MSG_QUEUE_SIZE)) {
  21615. + spin_unlock(&msg_queue_spinlock);
  21616. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  21617. + DEBUG_COUNT(MSG_QUEUE_FULL_COUNT);
  21618. + vchiq_log_trace(vchiq_arm_log_level,
  21619. + "service_callback - msg queue full");
  21620. + /* If there is no MESSAGE_AVAILABLE in the completion
  21621. + ** queue, add one
  21622. + */
  21623. + if ((user_service->message_available_pos -
  21624. + instance->completion_remove) < 0) {
  21625. + VCHIQ_STATUS_T status;
  21626. + vchiq_log_info(vchiq_arm_log_level,
  21627. + "Inserting extra MESSAGE_AVAILABLE");
  21628. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  21629. + status = add_completion(instance, reason,
  21630. + NULL, user_service, bulk_userdata);
  21631. + if (status != VCHIQ_SUCCESS) {
  21632. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  21633. + return status;
  21634. + }
  21635. + }
  21636. +
  21637. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  21638. + if (down_interruptible(&user_service->remove_event)
  21639. + != 0) {
  21640. + vchiq_log_info(vchiq_arm_log_level,
  21641. + "service_callback interrupted");
  21642. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  21643. + return VCHIQ_RETRY;
  21644. + } else if (instance->closing) {
  21645. + vchiq_log_info(vchiq_arm_log_level,
  21646. + "service_callback closing");
  21647. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  21648. + return VCHIQ_ERROR;
  21649. + }
  21650. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  21651. + spin_lock(&msg_queue_spinlock);
  21652. + }
  21653. +
  21654. + user_service->msg_queue[user_service->msg_insert &
  21655. + (MSG_QUEUE_SIZE - 1)] = header;
  21656. + user_service->msg_insert++;
  21657. + spin_unlock(&msg_queue_spinlock);
  21658. +
  21659. + up(&user_service->insert_event);
  21660. +
  21661. + /* If there is a thread waiting in DEQUEUE_MESSAGE, or if
  21662. + ** there is a MESSAGE_AVAILABLE in the completion queue then
  21663. + ** bypass the completion queue.
  21664. + */
  21665. + if (((user_service->message_available_pos -
  21666. + instance->completion_remove) >= 0) ||
  21667. + user_service->dequeue_pending) {
  21668. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  21669. + user_service->dequeue_pending = 0;
  21670. + return VCHIQ_SUCCESS;
  21671. + }
  21672. +
  21673. + header = NULL;
  21674. + }
  21675. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  21676. +
  21677. + return add_completion(instance, reason, header, user_service,
  21678. + bulk_userdata);
  21679. +}
  21680. +
  21681. +/****************************************************************************
  21682. +*
  21683. +* user_service_free
  21684. +*
  21685. +***************************************************************************/
  21686. +static void
  21687. +user_service_free(void *userdata)
  21688. +{
  21689. + kfree(userdata);
  21690. +}
  21691. +
  21692. +/****************************************************************************
  21693. +*
  21694. +* vchiq_ioctl
  21695. +*
  21696. +***************************************************************************/
  21697. +
  21698. +static long
  21699. +vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  21700. +{
  21701. + VCHIQ_INSTANCE_T instance = file->private_data;
  21702. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  21703. + VCHIQ_SERVICE_T *service = NULL;
  21704. + long ret = 0;
  21705. + int i, rc;
  21706. + DEBUG_INITIALISE(g_state.local)
  21707. +
  21708. + vchiq_log_trace(vchiq_arm_log_level,
  21709. + "vchiq_ioctl - instance %x, cmd %s, arg %lx",
  21710. + (unsigned int)instance,
  21711. + ((_IOC_TYPE(cmd) == VCHIQ_IOC_MAGIC) &&
  21712. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX)) ?
  21713. + ioctl_names[_IOC_NR(cmd)] : "<invalid>", arg);
  21714. +
  21715. + switch (cmd) {
  21716. + case VCHIQ_IOC_SHUTDOWN:
  21717. + if (!instance->connected)
  21718. + break;
  21719. +
  21720. + /* Remove all services */
  21721. + i = 0;
  21722. + while ((service = next_service_by_instance(instance->state,
  21723. + instance, &i)) != NULL) {
  21724. + status = vchiq_remove_service(service->handle);
  21725. + unlock_service(service);
  21726. + if (status != VCHIQ_SUCCESS)
  21727. + break;
  21728. + }
  21729. + service = NULL;
  21730. +
  21731. + if (status == VCHIQ_SUCCESS) {
  21732. + /* Wake the completion thread and ask it to exit */
  21733. + instance->closing = 1;
  21734. + up(&instance->insert_event);
  21735. + }
  21736. +
  21737. + break;
  21738. +
  21739. + case VCHIQ_IOC_CONNECT:
  21740. + if (instance->connected) {
  21741. + ret = -EINVAL;
  21742. + break;
  21743. + }
  21744. + rc = mutex_lock_interruptible(&instance->state->mutex);
  21745. + if (rc != 0) {
  21746. + vchiq_log_error(vchiq_arm_log_level,
  21747. + "vchiq: connect: could not lock mutex for "
  21748. + "state %d: %d",
  21749. + instance->state->id, rc);
  21750. + ret = -EINTR;
  21751. + break;
  21752. + }
  21753. + status = vchiq_connect_internal(instance->state, instance);
  21754. + mutex_unlock(&instance->state->mutex);
  21755. +
  21756. + if (status == VCHIQ_SUCCESS)
  21757. + instance->connected = 1;
  21758. + else
  21759. + vchiq_log_error(vchiq_arm_log_level,
  21760. + "vchiq: could not connect: %d", status);
  21761. + break;
  21762. +
  21763. + case VCHIQ_IOC_CREATE_SERVICE: {
  21764. + VCHIQ_CREATE_SERVICE_T args;
  21765. + USER_SERVICE_T *user_service = NULL;
  21766. + void *userdata;
  21767. + int srvstate;
  21768. +
  21769. + if (copy_from_user
  21770. + (&args, (const void __user *)arg,
  21771. + sizeof(args)) != 0) {
  21772. + ret = -EFAULT;
  21773. + break;
  21774. + }
  21775. +
  21776. + user_service = kmalloc(sizeof(USER_SERVICE_T), GFP_KERNEL);
  21777. + if (!user_service) {
  21778. + ret = -ENOMEM;
  21779. + break;
  21780. + }
  21781. +
  21782. + if (args.is_open) {
  21783. + if (!instance->connected) {
  21784. + ret = -ENOTCONN;
  21785. + kfree(user_service);
  21786. + break;
  21787. + }
  21788. + srvstate = VCHIQ_SRVSTATE_OPENING;
  21789. + } else {
  21790. + srvstate =
  21791. + instance->connected ?
  21792. + VCHIQ_SRVSTATE_LISTENING :
  21793. + VCHIQ_SRVSTATE_HIDDEN;
  21794. + }
  21795. +
  21796. + userdata = args.params.userdata;
  21797. + args.params.callback = service_callback;
  21798. + args.params.userdata = user_service;
  21799. + service = vchiq_add_service_internal(
  21800. + instance->state,
  21801. + &args.params, srvstate,
  21802. + instance, user_service_free);
  21803. +
  21804. + if (service != NULL) {
  21805. + user_service->service = service;
  21806. + user_service->userdata = userdata;
  21807. + user_service->instance = instance;
  21808. + user_service->is_vchi = args.is_vchi;
  21809. + user_service->dequeue_pending = 0;
  21810. + user_service->message_available_pos =
  21811. + instance->completion_remove - 1;
  21812. + user_service->msg_insert = 0;
  21813. + user_service->msg_remove = 0;
  21814. + sema_init(&user_service->insert_event, 0);
  21815. + sema_init(&user_service->remove_event, 0);
  21816. +
  21817. + if (args.is_open) {
  21818. + status = vchiq_open_service_internal
  21819. + (service, instance->pid);
  21820. + if (status != VCHIQ_SUCCESS) {
  21821. + vchiq_remove_service(service->handle);
  21822. + service = NULL;
  21823. + ret = (status == VCHIQ_RETRY) ?
  21824. + -EINTR : -EIO;
  21825. + break;
  21826. + }
  21827. + }
  21828. +
  21829. + if (copy_to_user((void __user *)
  21830. + &(((VCHIQ_CREATE_SERVICE_T __user *)
  21831. + arg)->handle),
  21832. + (const void *)&service->handle,
  21833. + sizeof(service->handle)) != 0) {
  21834. + ret = -EFAULT;
  21835. + vchiq_remove_service(service->handle);
  21836. + }
  21837. +
  21838. + service = NULL;
  21839. + } else {
  21840. + ret = -EEXIST;
  21841. + kfree(user_service);
  21842. + }
  21843. + } break;
  21844. +
  21845. + case VCHIQ_IOC_CLOSE_SERVICE: {
  21846. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  21847. +
  21848. + service = find_service_for_instance(instance, handle);
  21849. + if (service != NULL)
  21850. + status = vchiq_close_service(service->handle);
  21851. + else
  21852. + ret = -EINVAL;
  21853. + } break;
  21854. +
  21855. + case VCHIQ_IOC_REMOVE_SERVICE: {
  21856. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  21857. +
  21858. + service = find_service_for_instance(instance, handle);
  21859. + if (service != NULL)
  21860. + status = vchiq_remove_service(service->handle);
  21861. + else
  21862. + ret = -EINVAL;
  21863. + } break;
  21864. +
  21865. + case VCHIQ_IOC_USE_SERVICE:
  21866. + case VCHIQ_IOC_RELEASE_SERVICE: {
  21867. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  21868. +
  21869. + service = find_service_for_instance(instance, handle);
  21870. + if (service != NULL) {
  21871. + status = (cmd == VCHIQ_IOC_USE_SERVICE) ?
  21872. + vchiq_use_service_internal(service) :
  21873. + vchiq_release_service_internal(service);
  21874. + if (status != VCHIQ_SUCCESS) {
  21875. + vchiq_log_error(vchiq_susp_log_level,
  21876. + "%s: cmd %s returned error %d for "
  21877. + "service %c%c%c%c:%03d",
  21878. + __func__,
  21879. + (cmd == VCHIQ_IOC_USE_SERVICE) ?
  21880. + "VCHIQ_IOC_USE_SERVICE" :
  21881. + "VCHIQ_IOC_RELEASE_SERVICE",
  21882. + status,
  21883. + VCHIQ_FOURCC_AS_4CHARS(
  21884. + service->base.fourcc),
  21885. + service->client_id);
  21886. + ret = -EINVAL;
  21887. + }
  21888. + } else
  21889. + ret = -EINVAL;
  21890. + } break;
  21891. +
  21892. + case VCHIQ_IOC_QUEUE_MESSAGE: {
  21893. + VCHIQ_QUEUE_MESSAGE_T args;
  21894. + if (copy_from_user
  21895. + (&args, (const void __user *)arg,
  21896. + sizeof(args)) != 0) {
  21897. + ret = -EFAULT;
  21898. + break;
  21899. + }
  21900. +
  21901. + service = find_service_for_instance(instance, args.handle);
  21902. +
  21903. + if ((service != NULL) && (args.count <= MAX_ELEMENTS)) {
  21904. + /* Copy elements into kernel space */
  21905. + VCHIQ_ELEMENT_T elements[MAX_ELEMENTS];
  21906. + if (copy_from_user(elements, args.elements,
  21907. + args.count * sizeof(VCHIQ_ELEMENT_T)) == 0)
  21908. + status = vchiq_queue_message
  21909. + (args.handle,
  21910. + elements, args.count);
  21911. + else
  21912. + ret = -EFAULT;
  21913. + } else {
  21914. + ret = -EINVAL;
  21915. + }
  21916. + } break;
  21917. +
  21918. + case VCHIQ_IOC_QUEUE_BULK_TRANSMIT:
  21919. + case VCHIQ_IOC_QUEUE_BULK_RECEIVE: {
  21920. + VCHIQ_QUEUE_BULK_TRANSFER_T args;
  21921. + struct bulk_waiter_node *waiter = NULL;
  21922. + VCHIQ_BULK_DIR_T dir =
  21923. + (cmd == VCHIQ_IOC_QUEUE_BULK_TRANSMIT) ?
  21924. + VCHIQ_BULK_TRANSMIT : VCHIQ_BULK_RECEIVE;
  21925. +
  21926. + if (copy_from_user
  21927. + (&args, (const void __user *)arg,
  21928. + sizeof(args)) != 0) {
  21929. + ret = -EFAULT;
  21930. + break;
  21931. + }
  21932. +
  21933. + service = find_service_for_instance(instance, args.handle);
  21934. + if (!service) {
  21935. + ret = -EINVAL;
  21936. + break;
  21937. + }
  21938. +
  21939. + if (args.mode == VCHIQ_BULK_MODE_BLOCKING) {
  21940. + waiter = kzalloc(sizeof(struct bulk_waiter_node),
  21941. + GFP_KERNEL);
  21942. + if (!waiter) {
  21943. + ret = -ENOMEM;
  21944. + break;
  21945. + }
  21946. + args.userdata = &waiter->bulk_waiter;
  21947. + } else if (args.mode == VCHIQ_BULK_MODE_WAITING) {
  21948. + struct list_head *pos;
  21949. + mutex_lock(&instance->bulk_waiter_list_mutex);
  21950. + list_for_each(pos, &instance->bulk_waiter_list) {
  21951. + if (list_entry(pos, struct bulk_waiter_node,
  21952. + list)->pid == current->pid) {
  21953. + waiter = list_entry(pos,
  21954. + struct bulk_waiter_node,
  21955. + list);
  21956. + list_del(pos);
  21957. + break;
  21958. + }
  21959. +
  21960. + }
  21961. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  21962. + if (!waiter) {
  21963. + vchiq_log_error(vchiq_arm_log_level,
  21964. + "no bulk_waiter found for pid %d",
  21965. + current->pid);
  21966. + ret = -ESRCH;
  21967. + break;
  21968. + }
  21969. + vchiq_log_info(vchiq_arm_log_level,
  21970. + "found bulk_waiter %x for pid %d",
  21971. + (unsigned int)waiter, current->pid);
  21972. + args.userdata = &waiter->bulk_waiter;
  21973. + }
  21974. + status = vchiq_bulk_transfer
  21975. + (args.handle,
  21976. + VCHI_MEM_HANDLE_INVALID,
  21977. + args.data, args.size,
  21978. + args.userdata, args.mode,
  21979. + dir);
  21980. + if (!waiter)
  21981. + break;
  21982. + if ((status != VCHIQ_RETRY) || fatal_signal_pending(current) ||
  21983. + !waiter->bulk_waiter.bulk) {
  21984. + if (waiter->bulk_waiter.bulk) {
  21985. + /* Cancel the signal when the transfer
  21986. + ** completes. */
  21987. + spin_lock(&bulk_waiter_spinlock);
  21988. + waiter->bulk_waiter.bulk->userdata = NULL;
  21989. + spin_unlock(&bulk_waiter_spinlock);
  21990. + }
  21991. + kfree(waiter);
  21992. + } else {
  21993. + const VCHIQ_BULK_MODE_T mode_waiting =
  21994. + VCHIQ_BULK_MODE_WAITING;
  21995. + waiter->pid = current->pid;
  21996. + mutex_lock(&instance->bulk_waiter_list_mutex);
  21997. + list_add(&waiter->list, &instance->bulk_waiter_list);
  21998. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  21999. + vchiq_log_info(vchiq_arm_log_level,
  22000. + "saved bulk_waiter %x for pid %d",
  22001. + (unsigned int)waiter, current->pid);
  22002. +
  22003. + if (copy_to_user((void __user *)
  22004. + &(((VCHIQ_QUEUE_BULK_TRANSFER_T __user *)
  22005. + arg)->mode),
  22006. + (const void *)&mode_waiting,
  22007. + sizeof(mode_waiting)) != 0)
  22008. + ret = -EFAULT;
  22009. + }
  22010. + } break;
  22011. +
  22012. + case VCHIQ_IOC_AWAIT_COMPLETION: {
  22013. + VCHIQ_AWAIT_COMPLETION_T args;
  22014. +
  22015. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  22016. + if (!instance->connected) {
  22017. + ret = -ENOTCONN;
  22018. + break;
  22019. + }
  22020. +
  22021. + if (copy_from_user(&args, (const void __user *)arg,
  22022. + sizeof(args)) != 0) {
  22023. + ret = -EFAULT;
  22024. + break;
  22025. + }
  22026. +
  22027. + mutex_lock(&instance->completion_mutex);
  22028. +
  22029. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  22030. + while ((instance->completion_remove ==
  22031. + instance->completion_insert)
  22032. + && !instance->closing) {
  22033. + int rc;
  22034. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  22035. + mutex_unlock(&instance->completion_mutex);
  22036. + rc = down_interruptible(&instance->insert_event);
  22037. + mutex_lock(&instance->completion_mutex);
  22038. + if (rc != 0) {
  22039. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  22040. + vchiq_log_info(vchiq_arm_log_level,
  22041. + "AWAIT_COMPLETION interrupted");
  22042. + ret = -EINTR;
  22043. + break;
  22044. + }
  22045. + }
  22046. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  22047. +
  22048. + /* A read memory barrier is needed to stop prefetch of a stale
  22049. + ** completion record
  22050. + */
  22051. + rmb();
  22052. +
  22053. + if (ret == 0) {
  22054. + int msgbufcount = args.msgbufcount;
  22055. + for (ret = 0; ret < args.count; ret++) {
  22056. + VCHIQ_COMPLETION_DATA_T *completion;
  22057. + VCHIQ_SERVICE_T *service;
  22058. + USER_SERVICE_T *user_service;
  22059. + VCHIQ_HEADER_T *header;
  22060. + if (instance->completion_remove ==
  22061. + instance->completion_insert)
  22062. + break;
  22063. + completion = &instance->completions[
  22064. + instance->completion_remove &
  22065. + (MAX_COMPLETIONS - 1)];
  22066. +
  22067. + service = completion->service_userdata;
  22068. + user_service = service->base.userdata;
  22069. + completion->service_userdata =
  22070. + user_service->userdata;
  22071. +
  22072. + header = completion->header;
  22073. + if (header) {
  22074. + void __user *msgbuf;
  22075. + int msglen;
  22076. +
  22077. + msglen = header->size +
  22078. + sizeof(VCHIQ_HEADER_T);
  22079. + /* This must be a VCHIQ-style service */
  22080. + if (args.msgbufsize < msglen) {
  22081. + vchiq_log_error(
  22082. + vchiq_arm_log_level,
  22083. + "header %x: msgbufsize"
  22084. + " %x < msglen %x",
  22085. + (unsigned int)header,
  22086. + args.msgbufsize,
  22087. + msglen);
  22088. + WARN(1, "invalid message "
  22089. + "size\n");
  22090. + if (ret == 0)
  22091. + ret = -EMSGSIZE;
  22092. + break;
  22093. + }
  22094. + if (msgbufcount <= 0)
  22095. + /* Stall here for lack of a
  22096. + ** buffer for the message. */
  22097. + break;
  22098. + /* Get the pointer from user space */
  22099. + msgbufcount--;
  22100. + if (copy_from_user(&msgbuf,
  22101. + (const void __user *)
  22102. + &args.msgbufs[msgbufcount],
  22103. + sizeof(msgbuf)) != 0) {
  22104. + if (ret == 0)
  22105. + ret = -EFAULT;
  22106. + break;
  22107. + }
  22108. +
  22109. + /* Copy the message to user space */
  22110. + if (copy_to_user(msgbuf, header,
  22111. + msglen) != 0) {
  22112. + if (ret == 0)
  22113. + ret = -EFAULT;
  22114. + break;
  22115. + }
  22116. +
  22117. + /* Now it has been copied, the message
  22118. + ** can be released. */
  22119. + vchiq_release_message(service->handle,
  22120. + header);
  22121. +
  22122. + /* The completion must point to the
  22123. + ** msgbuf. */
  22124. + completion->header = msgbuf;
  22125. + }
  22126. +
  22127. + if (completion->reason ==
  22128. + VCHIQ_SERVICE_CLOSED)
  22129. + unlock_service(service);
  22130. +
  22131. + if (copy_to_user((void __user *)(
  22132. + (size_t)args.buf +
  22133. + ret * sizeof(VCHIQ_COMPLETION_DATA_T)),
  22134. + completion,
  22135. + sizeof(VCHIQ_COMPLETION_DATA_T)) != 0) {
  22136. + if (ret == 0)
  22137. + ret = -EFAULT;
  22138. + break;
  22139. + }
  22140. +
  22141. + instance->completion_remove++;
  22142. + }
  22143. +
  22144. + if (msgbufcount != args.msgbufcount) {
  22145. + if (copy_to_user((void __user *)
  22146. + &((VCHIQ_AWAIT_COMPLETION_T *)arg)->
  22147. + msgbufcount,
  22148. + &msgbufcount,
  22149. + sizeof(msgbufcount)) != 0) {
  22150. + ret = -EFAULT;
  22151. + }
  22152. + }
  22153. + }
  22154. +
  22155. + if (ret != 0)
  22156. + up(&instance->remove_event);
  22157. + mutex_unlock(&instance->completion_mutex);
  22158. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  22159. + } break;
  22160. +
  22161. + case VCHIQ_IOC_DEQUEUE_MESSAGE: {
  22162. + VCHIQ_DEQUEUE_MESSAGE_T args;
  22163. + USER_SERVICE_T *user_service;
  22164. + VCHIQ_HEADER_T *header;
  22165. +
  22166. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  22167. + if (copy_from_user
  22168. + (&args, (const void __user *)arg,
  22169. + sizeof(args)) != 0) {
  22170. + ret = -EFAULT;
  22171. + break;
  22172. + }
  22173. + service = find_service_for_instance(instance, args.handle);
  22174. + if (!service) {
  22175. + ret = -EINVAL;
  22176. + break;
  22177. + }
  22178. + user_service = (USER_SERVICE_T *)service->base.userdata;
  22179. + if (user_service->is_vchi == 0) {
  22180. + ret = -EINVAL;
  22181. + break;
  22182. + }
  22183. +
  22184. + spin_lock(&msg_queue_spinlock);
  22185. + if (user_service->msg_remove == user_service->msg_insert) {
  22186. + if (!args.blocking) {
  22187. + spin_unlock(&msg_queue_spinlock);
  22188. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  22189. + ret = -EWOULDBLOCK;
  22190. + break;
  22191. + }
  22192. + user_service->dequeue_pending = 1;
  22193. + do {
  22194. + spin_unlock(&msg_queue_spinlock);
  22195. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  22196. + if (down_interruptible(
  22197. + &user_service->insert_event) != 0) {
  22198. + vchiq_log_info(vchiq_arm_log_level,
  22199. + "DEQUEUE_MESSAGE interrupted");
  22200. + ret = -EINTR;
  22201. + break;
  22202. + }
  22203. + spin_lock(&msg_queue_spinlock);
  22204. + } while (user_service->msg_remove ==
  22205. + user_service->msg_insert);
  22206. +
  22207. + if (ret)
  22208. + break;
  22209. + }
  22210. +
  22211. + BUG_ON((int)(user_service->msg_insert -
  22212. + user_service->msg_remove) < 0);
  22213. +
  22214. + header = user_service->msg_queue[user_service->msg_remove &
  22215. + (MSG_QUEUE_SIZE - 1)];
  22216. + user_service->msg_remove++;
  22217. + spin_unlock(&msg_queue_spinlock);
  22218. +
  22219. + up(&user_service->remove_event);
  22220. + if (header == NULL)
  22221. + ret = -ENOTCONN;
  22222. + else if (header->size <= args.bufsize) {
  22223. + /* Copy to user space if msgbuf is not NULL */
  22224. + if ((args.buf == NULL) ||
  22225. + (copy_to_user((void __user *)args.buf,
  22226. + header->data,
  22227. + header->size) == 0)) {
  22228. + ret = header->size;
  22229. + vchiq_release_message(
  22230. + service->handle,
  22231. + header);
  22232. + } else
  22233. + ret = -EFAULT;
  22234. + } else {
  22235. + vchiq_log_error(vchiq_arm_log_level,
  22236. + "header %x: bufsize %x < size %x",
  22237. + (unsigned int)header, args.bufsize,
  22238. + header->size);
  22239. + WARN(1, "invalid size\n");
  22240. + ret = -EMSGSIZE;
  22241. + }
  22242. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  22243. + } break;
  22244. +
  22245. + case VCHIQ_IOC_GET_CLIENT_ID: {
  22246. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  22247. +
  22248. + ret = vchiq_get_client_id(handle);
  22249. + } break;
  22250. +
  22251. + case VCHIQ_IOC_GET_CONFIG: {
  22252. + VCHIQ_GET_CONFIG_T args;
  22253. + VCHIQ_CONFIG_T config;
  22254. +
  22255. + if (copy_from_user(&args, (const void __user *)arg,
  22256. + sizeof(args)) != 0) {
  22257. + ret = -EFAULT;
  22258. + break;
  22259. + }
  22260. + if (args.config_size > sizeof(config)) {
  22261. + ret = -EINVAL;
  22262. + break;
  22263. + }
  22264. + status = vchiq_get_config(instance, args.config_size, &config);
  22265. + if (status == VCHIQ_SUCCESS) {
  22266. + if (copy_to_user((void __user *)args.pconfig,
  22267. + &config, args.config_size) != 0) {
  22268. + ret = -EFAULT;
  22269. + break;
  22270. + }
  22271. + }
  22272. + } break;
  22273. +
  22274. + case VCHIQ_IOC_SET_SERVICE_OPTION: {
  22275. + VCHIQ_SET_SERVICE_OPTION_T args;
  22276. +
  22277. + if (copy_from_user(
  22278. + &args, (const void __user *)arg,
  22279. + sizeof(args)) != 0) {
  22280. + ret = -EFAULT;
  22281. + break;
  22282. + }
  22283. +
  22284. + service = find_service_for_instance(instance, args.handle);
  22285. + if (!service) {
  22286. + ret = -EINVAL;
  22287. + break;
  22288. + }
  22289. +
  22290. + status = vchiq_set_service_option(
  22291. + args.handle, args.option, args.value);
  22292. + } break;
  22293. +
  22294. + case VCHIQ_IOC_DUMP_PHYS_MEM: {
  22295. + VCHIQ_DUMP_MEM_T args;
  22296. +
  22297. + if (copy_from_user
  22298. + (&args, (const void __user *)arg,
  22299. + sizeof(args)) != 0) {
  22300. + ret = -EFAULT;
  22301. + break;
  22302. + }
  22303. + dump_phys_mem(args.virt_addr, args.num_bytes);
  22304. + } break;
  22305. +
  22306. + default:
  22307. + ret = -ENOTTY;
  22308. + break;
  22309. + }
  22310. +
  22311. + if (service)
  22312. + unlock_service(service);
  22313. +
  22314. + if (ret == 0) {
  22315. + if (status == VCHIQ_ERROR)
  22316. + ret = -EIO;
  22317. + else if (status == VCHIQ_RETRY)
  22318. + ret = -EINTR;
  22319. + }
  22320. +
  22321. + if ((status == VCHIQ_SUCCESS) && (ret < 0) && (ret != -EINTR) &&
  22322. + (ret != -EWOULDBLOCK))
  22323. + vchiq_log_info(vchiq_arm_log_level,
  22324. + " ioctl instance %lx, cmd %s -> status %d, %ld",
  22325. + (unsigned long)instance,
  22326. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX) ?
  22327. + ioctl_names[_IOC_NR(cmd)] :
  22328. + "<invalid>",
  22329. + status, ret);
  22330. + else
  22331. + vchiq_log_trace(vchiq_arm_log_level,
  22332. + " ioctl instance %lx, cmd %s -> status %d, %ld",
  22333. + (unsigned long)instance,
  22334. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX) ?
  22335. + ioctl_names[_IOC_NR(cmd)] :
  22336. + "<invalid>",
  22337. + status, ret);
  22338. +
  22339. + return ret;
  22340. +}
  22341. +
  22342. +/****************************************************************************
  22343. +*
  22344. +* vchiq_open
  22345. +*
  22346. +***************************************************************************/
  22347. +
  22348. +static int
  22349. +vchiq_open(struct inode *inode, struct file *file)
  22350. +{
  22351. + int dev = iminor(inode) & 0x0f;
  22352. + vchiq_log_info(vchiq_arm_log_level, "vchiq_open");
  22353. + switch (dev) {
  22354. + case VCHIQ_MINOR: {
  22355. + int ret;
  22356. + VCHIQ_STATE_T *state = vchiq_get_state();
  22357. + VCHIQ_INSTANCE_T instance;
  22358. +
  22359. + if (!state) {
  22360. + vchiq_log_error(vchiq_arm_log_level,
  22361. + "vchiq has no connection to VideoCore");
  22362. + return -ENOTCONN;
  22363. + }
  22364. +
  22365. + instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  22366. + if (!instance)
  22367. + return -ENOMEM;
  22368. +
  22369. + instance->state = state;
  22370. + instance->pid = current->tgid;
  22371. +
  22372. + ret = vchiq_proc_add_instance(instance);
  22373. + if (ret != 0) {
  22374. + kfree(instance);
  22375. + return ret;
  22376. + }
  22377. +
  22378. + sema_init(&instance->insert_event, 0);
  22379. + sema_init(&instance->remove_event, 0);
  22380. + mutex_init(&instance->completion_mutex);
  22381. + mutex_init(&instance->bulk_waiter_list_mutex);
  22382. + INIT_LIST_HEAD(&instance->bulk_waiter_list);
  22383. +
  22384. + file->private_data = instance;
  22385. + } break;
  22386. +
  22387. + default:
  22388. + vchiq_log_error(vchiq_arm_log_level,
  22389. + "Unknown minor device: %d", dev);
  22390. + return -ENXIO;
  22391. + }
  22392. +
  22393. + return 0;
  22394. +}
  22395. +
  22396. +/****************************************************************************
  22397. +*
  22398. +* vchiq_release
  22399. +*
  22400. +***************************************************************************/
  22401. +
  22402. +static int
  22403. +vchiq_release(struct inode *inode, struct file *file)
  22404. +{
  22405. + int dev = iminor(inode) & 0x0f;
  22406. + int ret = 0;
  22407. + switch (dev) {
  22408. + case VCHIQ_MINOR: {
  22409. + VCHIQ_INSTANCE_T instance = file->private_data;
  22410. + VCHIQ_STATE_T *state = vchiq_get_state();
  22411. + VCHIQ_SERVICE_T *service;
  22412. + int i;
  22413. +
  22414. + vchiq_log_info(vchiq_arm_log_level,
  22415. + "vchiq_release: instance=%lx",
  22416. + (unsigned long)instance);
  22417. +
  22418. + if (!state) {
  22419. + ret = -EPERM;
  22420. + goto out;
  22421. + }
  22422. +
  22423. + /* Ensure videocore is awake to allow termination. */
  22424. + vchiq_use_internal(instance->state, NULL,
  22425. + USE_TYPE_VCHIQ);
  22426. +
  22427. + mutex_lock(&instance->completion_mutex);
  22428. +
  22429. + /* Wake the completion thread and ask it to exit */
  22430. + instance->closing = 1;
  22431. + up(&instance->insert_event);
  22432. +
  22433. + mutex_unlock(&instance->completion_mutex);
  22434. +
  22435. + /* Wake the slot handler if the completion queue is full. */
  22436. + up(&instance->remove_event);
  22437. +
  22438. + /* Mark all services for termination... */
  22439. + i = 0;
  22440. + while ((service = next_service_by_instance(state, instance,
  22441. + &i)) != NULL) {
  22442. + USER_SERVICE_T *user_service = service->base.userdata;
  22443. +
  22444. + /* Wake the slot handler if the msg queue is full. */
  22445. + up(&user_service->remove_event);
  22446. +
  22447. + vchiq_terminate_service_internal(service);
  22448. + unlock_service(service);
  22449. + }
  22450. +
  22451. + /* ...and wait for them to die */
  22452. + i = 0;
  22453. + while ((service = next_service_by_instance(state, instance, &i))
  22454. + != NULL) {
  22455. + USER_SERVICE_T *user_service = service->base.userdata;
  22456. +
  22457. + down(&service->remove_event);
  22458. +
  22459. + BUG_ON(service->srvstate != VCHIQ_SRVSTATE_FREE);
  22460. +
  22461. + spin_lock(&msg_queue_spinlock);
  22462. +
  22463. + while (user_service->msg_remove !=
  22464. + user_service->msg_insert) {
  22465. + VCHIQ_HEADER_T *header = user_service->
  22466. + msg_queue[user_service->msg_remove &
  22467. + (MSG_QUEUE_SIZE - 1)];
  22468. + user_service->msg_remove++;
  22469. + spin_unlock(&msg_queue_spinlock);
  22470. +
  22471. + if (header)
  22472. + vchiq_release_message(
  22473. + service->handle,
  22474. + header);
  22475. + spin_lock(&msg_queue_spinlock);
  22476. + }
  22477. +
  22478. + spin_unlock(&msg_queue_spinlock);
  22479. +
  22480. + unlock_service(service);
  22481. + }
  22482. +
  22483. + /* Release any closed services */
  22484. + while (instance->completion_remove !=
  22485. + instance->completion_insert) {
  22486. + VCHIQ_COMPLETION_DATA_T *completion;
  22487. + VCHIQ_SERVICE_T *service;
  22488. + completion = &instance->completions[
  22489. + instance->completion_remove &
  22490. + (MAX_COMPLETIONS - 1)];
  22491. + service = completion->service_userdata;
  22492. + if (completion->reason == VCHIQ_SERVICE_CLOSED)
  22493. + unlock_service(service);
  22494. + instance->completion_remove++;
  22495. + }
  22496. +
  22497. + /* Release the PEER service count. */
  22498. + vchiq_release_internal(instance->state, NULL);
  22499. +
  22500. + {
  22501. + struct list_head *pos, *next;
  22502. + list_for_each_safe(pos, next,
  22503. + &instance->bulk_waiter_list) {
  22504. + struct bulk_waiter_node *waiter;
  22505. + waiter = list_entry(pos,
  22506. + struct bulk_waiter_node,
  22507. + list);
  22508. + list_del(pos);
  22509. + vchiq_log_info(vchiq_arm_log_level,
  22510. + "bulk_waiter - cleaned up %x "
  22511. + "for pid %d",
  22512. + (unsigned int)waiter, waiter->pid);
  22513. + kfree(waiter);
  22514. + }
  22515. + }
  22516. +
  22517. + vchiq_proc_remove_instance(instance);
  22518. +
  22519. + kfree(instance);
  22520. + file->private_data = NULL;
  22521. + } break;
  22522. +
  22523. + default:
  22524. + vchiq_log_error(vchiq_arm_log_level,
  22525. + "Unknown minor device: %d", dev);
  22526. + ret = -ENXIO;
  22527. + }
  22528. +
  22529. +out:
  22530. + return ret;
  22531. +}
  22532. +
  22533. +/****************************************************************************
  22534. +*
  22535. +* vchiq_dump
  22536. +*
  22537. +***************************************************************************/
  22538. +
  22539. +void
  22540. +vchiq_dump(void *dump_context, const char *str, int len)
  22541. +{
  22542. + DUMP_CONTEXT_T *context = (DUMP_CONTEXT_T *)dump_context;
  22543. +
  22544. + if (context->actual < context->space) {
  22545. + int copy_bytes;
  22546. + if (context->offset > 0) {
  22547. + int skip_bytes = min(len, (int)context->offset);
  22548. + str += skip_bytes;
  22549. + len -= skip_bytes;
  22550. + context->offset -= skip_bytes;
  22551. + if (context->offset > 0)
  22552. + return;
  22553. + }
  22554. + copy_bytes = min(len, (int)(context->space - context->actual));
  22555. + if (copy_bytes == 0)
  22556. + return;
  22557. + if (copy_to_user(context->buf + context->actual, str,
  22558. + copy_bytes))
  22559. + context->actual = -EFAULT;
  22560. + context->actual += copy_bytes;
  22561. + len -= copy_bytes;
  22562. +
  22563. + /* If tne terminating NUL is included in the length, then it
  22564. + ** marks the end of a line and should be replaced with a
  22565. + ** carriage return. */
  22566. + if ((len == 0) && (str[copy_bytes - 1] == '\0')) {
  22567. + char cr = '\n';
  22568. + if (copy_to_user(context->buf + context->actual - 1,
  22569. + &cr, 1))
  22570. + context->actual = -EFAULT;
  22571. + }
  22572. + }
  22573. +}
  22574. +
  22575. +/****************************************************************************
  22576. +*
  22577. +* vchiq_dump_platform_instance_state
  22578. +*
  22579. +***************************************************************************/
  22580. +
  22581. +void
  22582. +vchiq_dump_platform_instances(void *dump_context)
  22583. +{
  22584. + VCHIQ_STATE_T *state = vchiq_get_state();
  22585. + char buf[80];
  22586. + int len;
  22587. + int i;
  22588. +
  22589. + /* There is no list of instances, so instead scan all services,
  22590. + marking those that have been dumped. */
  22591. +
  22592. + for (i = 0; i < state->unused_service; i++) {
  22593. + VCHIQ_SERVICE_T *service = state->services[i];
  22594. + VCHIQ_INSTANCE_T instance;
  22595. +
  22596. + if (service && (service->base.callback == service_callback)) {
  22597. + instance = service->instance;
  22598. + if (instance)
  22599. + instance->mark = 0;
  22600. + }
  22601. + }
  22602. +
  22603. + for (i = 0; i < state->unused_service; i++) {
  22604. + VCHIQ_SERVICE_T *service = state->services[i];
  22605. + VCHIQ_INSTANCE_T instance;
  22606. +
  22607. + if (service && (service->base.callback == service_callback)) {
  22608. + instance = service->instance;
  22609. + if (instance && !instance->mark) {
  22610. + len = snprintf(buf, sizeof(buf),
  22611. + "Instance %x: pid %d,%s completions "
  22612. + "%d/%d",
  22613. + (unsigned int)instance, instance->pid,
  22614. + instance->connected ? " connected, " :
  22615. + "",
  22616. + instance->completion_insert -
  22617. + instance->completion_remove,
  22618. + MAX_COMPLETIONS);
  22619. +
  22620. + vchiq_dump(dump_context, buf, len + 1);
  22621. +
  22622. + instance->mark = 1;
  22623. + }
  22624. + }
  22625. + }
  22626. +}
  22627. +
  22628. +/****************************************************************************
  22629. +*
  22630. +* vchiq_dump_platform_service_state
  22631. +*
  22632. +***************************************************************************/
  22633. +
  22634. +void
  22635. +vchiq_dump_platform_service_state(void *dump_context, VCHIQ_SERVICE_T *service)
  22636. +{
  22637. + USER_SERVICE_T *user_service = (USER_SERVICE_T *)service->base.userdata;
  22638. + char buf[80];
  22639. + int len;
  22640. +
  22641. + len = snprintf(buf, sizeof(buf), " instance %x",
  22642. + (unsigned int)service->instance);
  22643. +
  22644. + if ((service->base.callback == service_callback) &&
  22645. + user_service->is_vchi) {
  22646. + len += snprintf(buf + len, sizeof(buf) - len,
  22647. + ", %d/%d messages",
  22648. + user_service->msg_insert - user_service->msg_remove,
  22649. + MSG_QUEUE_SIZE);
  22650. +
  22651. + if (user_service->dequeue_pending)
  22652. + len += snprintf(buf + len, sizeof(buf) - len,
  22653. + " (dequeue pending)");
  22654. + }
  22655. +
  22656. + vchiq_dump(dump_context, buf, len + 1);
  22657. +}
  22658. +
  22659. +/****************************************************************************
  22660. +*
  22661. +* dump_user_mem
  22662. +*
  22663. +***************************************************************************/
  22664. +
  22665. +static void
  22666. +dump_phys_mem(void *virt_addr, uint32_t num_bytes)
  22667. +{
  22668. + int rc;
  22669. + uint8_t *end_virt_addr = virt_addr + num_bytes;
  22670. + int num_pages;
  22671. + int offset;
  22672. + int end_offset;
  22673. + int page_idx;
  22674. + int prev_idx;
  22675. + struct page *page;
  22676. + struct page **pages;
  22677. + uint8_t *kmapped_virt_ptr;
  22678. +
  22679. + /* Align virtAddr and endVirtAddr to 16 byte boundaries. */
  22680. +
  22681. + virt_addr = (void *)((unsigned long)virt_addr & ~0x0fuL);
  22682. + end_virt_addr = (void *)(((unsigned long)end_virt_addr + 15uL) &
  22683. + ~0x0fuL);
  22684. +
  22685. + offset = (int)(long)virt_addr & (PAGE_SIZE - 1);
  22686. + end_offset = (int)(long)end_virt_addr & (PAGE_SIZE - 1);
  22687. +
  22688. + num_pages = (offset + num_bytes + PAGE_SIZE - 1) / PAGE_SIZE;
  22689. +
  22690. + pages = kmalloc(sizeof(struct page *) * num_pages, GFP_KERNEL);
  22691. + if (pages == NULL) {
  22692. + vchiq_log_error(vchiq_arm_log_level,
  22693. + "Unable to allocation memory for %d pages\n",
  22694. + num_pages);
  22695. + return;
  22696. + }
  22697. +
  22698. + down_read(&current->mm->mmap_sem);
  22699. + rc = get_user_pages(current, /* task */
  22700. + current->mm, /* mm */
  22701. + (unsigned long)virt_addr, /* start */
  22702. + num_pages, /* len */
  22703. + 0, /* write */
  22704. + 0, /* force */
  22705. + pages, /* pages (array of page pointers) */
  22706. + NULL); /* vmas */
  22707. + up_read(&current->mm->mmap_sem);
  22708. +
  22709. + prev_idx = -1;
  22710. + page = NULL;
  22711. +
  22712. + while (offset < end_offset) {
  22713. +
  22714. + int page_offset = offset % PAGE_SIZE;
  22715. + page_idx = offset / PAGE_SIZE;
  22716. +
  22717. + if (page_idx != prev_idx) {
  22718. +
  22719. + if (page != NULL)
  22720. + kunmap(page);
  22721. + page = pages[page_idx];
  22722. + kmapped_virt_ptr = kmap(page);
  22723. +
  22724. + prev_idx = page_idx;
  22725. + }
  22726. +
  22727. + if (vchiq_arm_log_level >= VCHIQ_LOG_TRACE)
  22728. + vchiq_log_dump_mem("ph",
  22729. + (uint32_t)(unsigned long)&kmapped_virt_ptr[
  22730. + page_offset],
  22731. + &kmapped_virt_ptr[page_offset], 16);
  22732. +
  22733. + offset += 16;
  22734. + }
  22735. + if (page != NULL)
  22736. + kunmap(page);
  22737. +
  22738. + for (page_idx = 0; page_idx < num_pages; page_idx++)
  22739. + page_cache_release(pages[page_idx]);
  22740. +
  22741. + kfree(pages);
  22742. +}
  22743. +
  22744. +/****************************************************************************
  22745. +*
  22746. +* vchiq_read
  22747. +*
  22748. +***************************************************************************/
  22749. +
  22750. +static ssize_t
  22751. +vchiq_read(struct file *file, char __user *buf,
  22752. + size_t count, loff_t *ppos)
  22753. +{
  22754. + DUMP_CONTEXT_T context;
  22755. + context.buf = buf;
  22756. + context.actual = 0;
  22757. + context.space = count;
  22758. + context.offset = *ppos;
  22759. +
  22760. + vchiq_dump_state(&context, &g_state);
  22761. +
  22762. + *ppos += context.actual;
  22763. +
  22764. + return context.actual;
  22765. +}
  22766. +
  22767. +VCHIQ_STATE_T *
  22768. +vchiq_get_state(void)
  22769. +{
  22770. +
  22771. + if (g_state.remote == NULL)
  22772. + printk(KERN_ERR "%s: g_state.remote == NULL\n", __func__);
  22773. + else if (g_state.remote->initialised != 1)
  22774. + printk(KERN_NOTICE "%s: g_state.remote->initialised != 1 (%d)\n",
  22775. + __func__, g_state.remote->initialised);
  22776. +
  22777. + return ((g_state.remote != NULL) &&
  22778. + (g_state.remote->initialised == 1)) ? &g_state : NULL;
  22779. +}
  22780. +
  22781. +static const struct file_operations
  22782. +vchiq_fops = {
  22783. + .owner = THIS_MODULE,
  22784. + .unlocked_ioctl = vchiq_ioctl,
  22785. + .open = vchiq_open,
  22786. + .release = vchiq_release,
  22787. + .read = vchiq_read
  22788. +};
  22789. +
  22790. +/*
  22791. + * Autosuspend related functionality
  22792. + */
  22793. +
  22794. +int
  22795. +vchiq_videocore_wanted(VCHIQ_STATE_T *state)
  22796. +{
  22797. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22798. + if (!arm_state)
  22799. + /* autosuspend not supported - always return wanted */
  22800. + return 1;
  22801. + else if (arm_state->blocked_count)
  22802. + return 1;
  22803. + else if (!arm_state->videocore_use_count)
  22804. + /* usage count zero - check for override unless we're forcing */
  22805. + if (arm_state->resume_blocked)
  22806. + return 0;
  22807. + else
  22808. + return vchiq_platform_videocore_wanted(state);
  22809. + else
  22810. + /* non-zero usage count - videocore still required */
  22811. + return 1;
  22812. +}
  22813. +
  22814. +static VCHIQ_STATUS_T
  22815. +vchiq_keepalive_vchiq_callback(VCHIQ_REASON_T reason,
  22816. + VCHIQ_HEADER_T *header,
  22817. + VCHIQ_SERVICE_HANDLE_T service_user,
  22818. + void *bulk_user)
  22819. +{
  22820. + vchiq_log_error(vchiq_susp_log_level,
  22821. + "%s callback reason %d", __func__, reason);
  22822. + return 0;
  22823. +}
  22824. +
  22825. +static int
  22826. +vchiq_keepalive_thread_func(void *v)
  22827. +{
  22828. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  22829. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22830. +
  22831. + VCHIQ_STATUS_T status;
  22832. + VCHIQ_INSTANCE_T instance;
  22833. + VCHIQ_SERVICE_HANDLE_T ka_handle;
  22834. +
  22835. + VCHIQ_SERVICE_PARAMS_T params = {
  22836. + .fourcc = VCHIQ_MAKE_FOURCC('K', 'E', 'E', 'P'),
  22837. + .callback = vchiq_keepalive_vchiq_callback,
  22838. + .version = KEEPALIVE_VER,
  22839. + .version_min = KEEPALIVE_VER_MIN
  22840. + };
  22841. +
  22842. + status = vchiq_initialise(&instance);
  22843. + if (status != VCHIQ_SUCCESS) {
  22844. + vchiq_log_error(vchiq_susp_log_level,
  22845. + "%s vchiq_initialise failed %d", __func__, status);
  22846. + goto exit;
  22847. + }
  22848. +
  22849. + status = vchiq_connect(instance);
  22850. + if (status != VCHIQ_SUCCESS) {
  22851. + vchiq_log_error(vchiq_susp_log_level,
  22852. + "%s vchiq_connect failed %d", __func__, status);
  22853. + goto shutdown;
  22854. + }
  22855. +
  22856. + status = vchiq_add_service(instance, &params, &ka_handle);
  22857. + if (status != VCHIQ_SUCCESS) {
  22858. + vchiq_log_error(vchiq_susp_log_level,
  22859. + "%s vchiq_open_service failed %d", __func__, status);
  22860. + goto shutdown;
  22861. + }
  22862. +
  22863. + while (1) {
  22864. + long rc = 0, uc = 0;
  22865. + if (wait_for_completion_interruptible(&arm_state->ka_evt)
  22866. + != 0) {
  22867. + vchiq_log_error(vchiq_susp_log_level,
  22868. + "%s interrupted", __func__);
  22869. + flush_signals(current);
  22870. + continue;
  22871. + }
  22872. +
  22873. + /* read and clear counters. Do release_count then use_count to
  22874. + * prevent getting more releases than uses */
  22875. + rc = atomic_xchg(&arm_state->ka_release_count, 0);
  22876. + uc = atomic_xchg(&arm_state->ka_use_count, 0);
  22877. +
  22878. + /* Call use/release service the requisite number of times.
  22879. + * Process use before release so use counts don't go negative */
  22880. + while (uc--) {
  22881. + atomic_inc(&arm_state->ka_use_ack_count);
  22882. + status = vchiq_use_service(ka_handle);
  22883. + if (status != VCHIQ_SUCCESS) {
  22884. + vchiq_log_error(vchiq_susp_log_level,
  22885. + "%s vchiq_use_service error %d",
  22886. + __func__, status);
  22887. + }
  22888. + }
  22889. + while (rc--) {
  22890. + status = vchiq_release_service(ka_handle);
  22891. + if (status != VCHIQ_SUCCESS) {
  22892. + vchiq_log_error(vchiq_susp_log_level,
  22893. + "%s vchiq_release_service error %d",
  22894. + __func__, status);
  22895. + }
  22896. + }
  22897. + }
  22898. +
  22899. +shutdown:
  22900. + vchiq_shutdown(instance);
  22901. +exit:
  22902. + return 0;
  22903. +}
  22904. +
  22905. +
  22906. +
  22907. +VCHIQ_STATUS_T
  22908. +vchiq_arm_init_state(VCHIQ_STATE_T *state, VCHIQ_ARM_STATE_T *arm_state)
  22909. +{
  22910. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  22911. +
  22912. + if (arm_state) {
  22913. + rwlock_init(&arm_state->susp_res_lock);
  22914. +
  22915. + init_completion(&arm_state->ka_evt);
  22916. + atomic_set(&arm_state->ka_use_count, 0);
  22917. + atomic_set(&arm_state->ka_use_ack_count, 0);
  22918. + atomic_set(&arm_state->ka_release_count, 0);
  22919. +
  22920. + init_completion(&arm_state->vc_suspend_complete);
  22921. +
  22922. + init_completion(&arm_state->vc_resume_complete);
  22923. + /* Initialise to 'done' state. We only want to block on resume
  22924. + * completion while videocore is suspended. */
  22925. + set_resume_state(arm_state, VC_RESUME_RESUMED);
  22926. +
  22927. + init_completion(&arm_state->resume_blocker);
  22928. + /* Initialise to 'done' state. We only want to block on this
  22929. + * completion while resume is blocked */
  22930. + complete_all(&arm_state->resume_blocker);
  22931. +
  22932. + init_completion(&arm_state->blocked_blocker);
  22933. + /* Initialise to 'done' state. We only want to block on this
  22934. + * completion while things are waiting on the resume blocker */
  22935. + complete_all(&arm_state->blocked_blocker);
  22936. +
  22937. + arm_state->suspend_timer_timeout = SUSPEND_TIMER_TIMEOUT_MS;
  22938. + arm_state->suspend_timer_running = 0;
  22939. + init_timer(&arm_state->suspend_timer);
  22940. + arm_state->suspend_timer.data = (unsigned long)(state);
  22941. + arm_state->suspend_timer.function = suspend_timer_callback;
  22942. +
  22943. + arm_state->first_connect = 0;
  22944. +
  22945. + }
  22946. + return status;
  22947. +}
  22948. +
  22949. +/*
  22950. +** Functions to modify the state variables;
  22951. +** set_suspend_state
  22952. +** set_resume_state
  22953. +**
  22954. +** There are more state variables than we might like, so ensure they remain in
  22955. +** step. Suspend and resume state are maintained separately, since most of
  22956. +** these state machines can operate independently. However, there are a few
  22957. +** states where state transitions in one state machine cause a reset to the
  22958. +** other state machine. In addition, there are some completion events which
  22959. +** need to occur on state machine reset and end-state(s), so these are also
  22960. +** dealt with in these functions.
  22961. +**
  22962. +** In all states we set the state variable according to the input, but in some
  22963. +** cases we perform additional steps outlined below;
  22964. +**
  22965. +** VC_SUSPEND_IDLE - Initialise the suspend completion at the same time.
  22966. +** The suspend completion is completed after any suspend
  22967. +** attempt. When we reset the state machine we also reset
  22968. +** the completion. This reset occurs when videocore is
  22969. +** resumed, and also if we initiate suspend after a suspend
  22970. +** failure.
  22971. +**
  22972. +** VC_SUSPEND_IN_PROGRESS - This state is considered the point of no return for
  22973. +** suspend - ie from this point on we must try to suspend
  22974. +** before resuming can occur. We therefore also reset the
  22975. +** resume state machine to VC_RESUME_IDLE in this state.
  22976. +**
  22977. +** VC_SUSPEND_SUSPENDED - Suspend has completed successfully. Also call
  22978. +** complete_all on the suspend completion to notify
  22979. +** anything waiting for suspend to happen.
  22980. +**
  22981. +** VC_SUSPEND_REJECTED - Videocore rejected suspend. Videocore will also
  22982. +** initiate resume, so no need to alter resume state.
  22983. +** We call complete_all on the suspend completion to notify
  22984. +** of suspend rejection.
  22985. +**
  22986. +** VC_SUSPEND_FAILED - We failed to initiate videocore suspend. We notify the
  22987. +** suspend completion and reset the resume state machine.
  22988. +**
  22989. +** VC_RESUME_IDLE - Initialise the resume completion at the same time. The
  22990. +** resume completion is in it's 'done' state whenever
  22991. +** videcore is running. Therfore, the VC_RESUME_IDLE state
  22992. +** implies that videocore is suspended.
  22993. +** Hence, any thread which needs to wait until videocore is
  22994. +** running can wait on this completion - it will only block
  22995. +** if videocore is suspended.
  22996. +**
  22997. +** VC_RESUME_RESUMED - Resume has completed successfully. Videocore is running.
  22998. +** Call complete_all on the resume completion to unblock
  22999. +** any threads waiting for resume. Also reset the suspend
  23000. +** state machine to it's idle state.
  23001. +**
  23002. +** VC_RESUME_FAILED - Currently unused - no mechanism to fail resume exists.
  23003. +*/
  23004. +
  23005. +inline void
  23006. +set_suspend_state(VCHIQ_ARM_STATE_T *arm_state,
  23007. + enum vc_suspend_status new_state)
  23008. +{
  23009. + /* set the state in all cases */
  23010. + arm_state->vc_suspend_state = new_state;
  23011. +
  23012. + /* state specific additional actions */
  23013. + switch (new_state) {
  23014. + case VC_SUSPEND_FORCE_CANCELED:
  23015. + complete_all(&arm_state->vc_suspend_complete);
  23016. + break;
  23017. + case VC_SUSPEND_REJECTED:
  23018. + complete_all(&arm_state->vc_suspend_complete);
  23019. + break;
  23020. + case VC_SUSPEND_FAILED:
  23021. + complete_all(&arm_state->vc_suspend_complete);
  23022. + arm_state->vc_resume_state = VC_RESUME_RESUMED;
  23023. + complete_all(&arm_state->vc_resume_complete);
  23024. + break;
  23025. + case VC_SUSPEND_IDLE:
  23026. + reinit_completion(&arm_state->vc_suspend_complete);
  23027. + break;
  23028. + case VC_SUSPEND_REQUESTED:
  23029. + break;
  23030. + case VC_SUSPEND_IN_PROGRESS:
  23031. + set_resume_state(arm_state, VC_RESUME_IDLE);
  23032. + break;
  23033. + case VC_SUSPEND_SUSPENDED:
  23034. + complete_all(&arm_state->vc_suspend_complete);
  23035. + break;
  23036. + default:
  23037. + BUG();
  23038. + break;
  23039. + }
  23040. +}
  23041. +
  23042. +inline void
  23043. +set_resume_state(VCHIQ_ARM_STATE_T *arm_state,
  23044. + enum vc_resume_status new_state)
  23045. +{
  23046. + /* set the state in all cases */
  23047. + arm_state->vc_resume_state = new_state;
  23048. +
  23049. + /* state specific additional actions */
  23050. + switch (new_state) {
  23051. + case VC_RESUME_FAILED:
  23052. + break;
  23053. + case VC_RESUME_IDLE:
  23054. + reinit_completion(&arm_state->vc_resume_complete);
  23055. + break;
  23056. + case VC_RESUME_REQUESTED:
  23057. + break;
  23058. + case VC_RESUME_IN_PROGRESS:
  23059. + break;
  23060. + case VC_RESUME_RESUMED:
  23061. + complete_all(&arm_state->vc_resume_complete);
  23062. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  23063. + break;
  23064. + default:
  23065. + BUG();
  23066. + break;
  23067. + }
  23068. +}
  23069. +
  23070. +
  23071. +/* should be called with the write lock held */
  23072. +inline void
  23073. +start_suspend_timer(VCHIQ_ARM_STATE_T *arm_state)
  23074. +{
  23075. + del_timer(&arm_state->suspend_timer);
  23076. + arm_state->suspend_timer.expires = jiffies +
  23077. + msecs_to_jiffies(arm_state->
  23078. + suspend_timer_timeout);
  23079. + add_timer(&arm_state->suspend_timer);
  23080. + arm_state->suspend_timer_running = 1;
  23081. +}
  23082. +
  23083. +/* should be called with the write lock held */
  23084. +static inline void
  23085. +stop_suspend_timer(VCHIQ_ARM_STATE_T *arm_state)
  23086. +{
  23087. + if (arm_state->suspend_timer_running) {
  23088. + del_timer(&arm_state->suspend_timer);
  23089. + arm_state->suspend_timer_running = 0;
  23090. + }
  23091. +}
  23092. +
  23093. +static inline int
  23094. +need_resume(VCHIQ_STATE_T *state)
  23095. +{
  23096. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  23097. + return (arm_state->vc_suspend_state > VC_SUSPEND_IDLE) &&
  23098. + (arm_state->vc_resume_state < VC_RESUME_REQUESTED) &&
  23099. + vchiq_videocore_wanted(state);
  23100. +}
  23101. +
  23102. +static int
  23103. +block_resume(VCHIQ_ARM_STATE_T *arm_state)
  23104. +{
  23105. + int status = VCHIQ_SUCCESS;
  23106. + const unsigned long timeout_val =
  23107. + msecs_to_jiffies(FORCE_SUSPEND_TIMEOUT_MS);
  23108. + int resume_count = 0;
  23109. +
  23110. + /* Allow any threads which were blocked by the last force suspend to
  23111. + * complete if they haven't already. Only give this one shot; if
  23112. + * blocked_count is incremented after blocked_blocker is completed
  23113. + * (which only happens when blocked_count hits 0) then those threads
  23114. + * will have to wait until next time around */
  23115. + if (arm_state->blocked_count) {
  23116. + reinit_completion(&arm_state->blocked_blocker);
  23117. + write_unlock_bh(&arm_state->susp_res_lock);
  23118. + vchiq_log_info(vchiq_susp_log_level, "%s wait for previously "
  23119. + "blocked clients", __func__);
  23120. + if (wait_for_completion_interruptible_timeout(
  23121. + &arm_state->blocked_blocker, timeout_val)
  23122. + <= 0) {
  23123. + vchiq_log_error(vchiq_susp_log_level, "%s wait for "
  23124. + "previously blocked clients failed" , __func__);
  23125. + status = VCHIQ_ERROR;
  23126. + write_lock_bh(&arm_state->susp_res_lock);
  23127. + goto out;
  23128. + }
  23129. + vchiq_log_info(vchiq_susp_log_level, "%s previously blocked "
  23130. + "clients resumed", __func__);
  23131. + write_lock_bh(&arm_state->susp_res_lock);
  23132. + }
  23133. +
  23134. + /* We need to wait for resume to complete if it's in process */
  23135. + while (arm_state->vc_resume_state != VC_RESUME_RESUMED &&
  23136. + arm_state->vc_resume_state > VC_RESUME_IDLE) {
  23137. + if (resume_count > 1) {
  23138. + status = VCHIQ_ERROR;
  23139. + vchiq_log_error(vchiq_susp_log_level, "%s waited too "
  23140. + "many times for resume" , __func__);
  23141. + goto out;
  23142. + }
  23143. + write_unlock_bh(&arm_state->susp_res_lock);
  23144. + vchiq_log_info(vchiq_susp_log_level, "%s wait for resume",
  23145. + __func__);
  23146. + if (wait_for_completion_interruptible_timeout(
  23147. + &arm_state->vc_resume_complete, timeout_val)
  23148. + <= 0) {
  23149. + vchiq_log_error(vchiq_susp_log_level, "%s wait for "
  23150. + "resume failed (%s)", __func__,
  23151. + resume_state_names[arm_state->vc_resume_state +
  23152. + VC_RESUME_NUM_OFFSET]);
  23153. + status = VCHIQ_ERROR;
  23154. + write_lock_bh(&arm_state->susp_res_lock);
  23155. + goto out;
  23156. + }
  23157. + vchiq_log_info(vchiq_susp_log_level, "%s resumed", __func__);
  23158. + write_lock_bh(&arm_state->susp_res_lock);
  23159. + resume_count++;
  23160. + }
  23161. + reinit_completion(&arm_state->resume_blocker);
  23162. + arm_state->resume_blocked = 1;
  23163. +
  23164. +out:
  23165. + return status;
  23166. +}
  23167. +
  23168. +static inline void
  23169. +unblock_resume(VCHIQ_ARM_STATE_T *arm_state)
  23170. +{
  23171. + complete_all(&arm_state->resume_blocker);
  23172. + arm_state->resume_blocked = 0;
  23173. +}
  23174. +
  23175. +/* Initiate suspend via slot handler. Should be called with the write lock
  23176. + * held */
  23177. +VCHIQ_STATUS_T
  23178. +vchiq_arm_vcsuspend(VCHIQ_STATE_T *state)
  23179. +{
  23180. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  23181. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  23182. +
  23183. + if (!arm_state)
  23184. + goto out;
  23185. +
  23186. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  23187. + status = VCHIQ_SUCCESS;
  23188. +
  23189. +
  23190. + switch (arm_state->vc_suspend_state) {
  23191. + case VC_SUSPEND_REQUESTED:
  23192. + vchiq_log_info(vchiq_susp_log_level, "%s: suspend already "
  23193. + "requested", __func__);
  23194. + break;
  23195. + case VC_SUSPEND_IN_PROGRESS:
  23196. + vchiq_log_info(vchiq_susp_log_level, "%s: suspend already in "
  23197. + "progress", __func__);
  23198. + break;
  23199. +
  23200. + default:
  23201. + /* We don't expect to be in other states, so log but continue
  23202. + * anyway */
  23203. + vchiq_log_error(vchiq_susp_log_level,
  23204. + "%s unexpected suspend state %s", __func__,
  23205. + suspend_state_names[arm_state->vc_suspend_state +
  23206. + VC_SUSPEND_NUM_OFFSET]);
  23207. + /* fall through */
  23208. + case VC_SUSPEND_REJECTED:
  23209. + case VC_SUSPEND_FAILED:
  23210. + /* Ensure any idle state actions have been run */
  23211. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  23212. + /* fall through */
  23213. + case VC_SUSPEND_IDLE:
  23214. + vchiq_log_info(vchiq_susp_log_level,
  23215. + "%s: suspending", __func__);
  23216. + set_suspend_state(arm_state, VC_SUSPEND_REQUESTED);
  23217. + /* kick the slot handler thread to initiate suspend */
  23218. + request_poll(state, NULL, 0);
  23219. + break;
  23220. + }
  23221. +
  23222. +out:
  23223. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, status);
  23224. + return status;
  23225. +}
  23226. +
  23227. +void
  23228. +vchiq_platform_check_suspend(VCHIQ_STATE_T *state)
  23229. +{
  23230. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  23231. + int susp = 0;
  23232. +
  23233. + if (!arm_state)
  23234. + goto out;
  23235. +
  23236. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  23237. +
  23238. + write_lock_bh(&arm_state->susp_res_lock);
  23239. + if (arm_state->vc_suspend_state == VC_SUSPEND_REQUESTED &&
  23240. + arm_state->vc_resume_state == VC_RESUME_RESUMED) {
  23241. + set_suspend_state(arm_state, VC_SUSPEND_IN_PROGRESS);
  23242. + susp = 1;
  23243. + }
  23244. + write_unlock_bh(&arm_state->susp_res_lock);
  23245. +
  23246. + if (susp)
  23247. + vchiq_platform_suspend(state);
  23248. +
  23249. +out:
  23250. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  23251. + return;
  23252. +}
  23253. +
  23254. +
  23255. +static void
  23256. +output_timeout_error(VCHIQ_STATE_T *state)
  23257. +{
  23258. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  23259. + char service_err[50] = "";
  23260. + int vc_use_count = arm_state->videocore_use_count;
  23261. + int active_services = state->unused_service;
  23262. + int i;
  23263. +
  23264. + if (!arm_state->videocore_use_count) {
  23265. + snprintf(service_err, 50, " Videocore usecount is 0");
  23266. + goto output_msg;
  23267. + }
  23268. + for (i = 0; i < active_services; i++) {
  23269. + VCHIQ_SERVICE_T *service_ptr = state->services[i];
  23270. + if (service_ptr && service_ptr->service_use_count &&
  23271. + (service_ptr->srvstate != VCHIQ_SRVSTATE_FREE)) {
  23272. + snprintf(service_err, 50, " %c%c%c%c(%d) service has "
  23273. + "use count %d%s", VCHIQ_FOURCC_AS_4CHARS(
  23274. + service_ptr->base.fourcc),
  23275. + service_ptr->client_id,
  23276. + service_ptr->service_use_count,
  23277. + service_ptr->service_use_count ==
  23278. + vc_use_count ? "" : " (+ more)");
  23279. + break;
  23280. + }
  23281. + }
  23282. +
  23283. +output_msg:
  23284. + vchiq_log_error(vchiq_susp_log_level,
  23285. + "timed out waiting for vc suspend (%d).%s",
  23286. + arm_state->autosuspend_override, service_err);
  23287. +
  23288. +}
  23289. +
  23290. +/* Try to get videocore into suspended state, regardless of autosuspend state.
  23291. +** We don't actually force suspend, since videocore may get into a bad state
  23292. +** if we force suspend at a bad time. Instead, we wait for autosuspend to
  23293. +** determine a good point to suspend. If this doesn't happen within 100ms we
  23294. +** report failure.
  23295. +**
  23296. +** Returns VCHIQ_SUCCESS if videocore suspended successfully, VCHIQ_RETRY if
  23297. +** videocore failed to suspend in time or VCHIQ_ERROR if interrupted.
  23298. +*/
  23299. +VCHIQ_STATUS_T
  23300. +vchiq_arm_force_suspend(VCHIQ_STATE_T *state)
  23301. +{
  23302. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  23303. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  23304. + long rc = 0;
  23305. + int repeat = -1;
  23306. +
  23307. + if (!arm_state)
  23308. + goto out;
  23309. +
  23310. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  23311. +
  23312. + write_lock_bh(&arm_state->susp_res_lock);
  23313. +
  23314. + status = block_resume(arm_state);
  23315. + if (status != VCHIQ_SUCCESS)
  23316. + goto unlock;
  23317. + if (arm_state->vc_suspend_state == VC_SUSPEND_SUSPENDED) {
  23318. + /* Already suspended - just block resume and exit */
  23319. + vchiq_log_info(vchiq_susp_log_level, "%s already suspended",
  23320. + __func__);
  23321. + status = VCHIQ_SUCCESS;
  23322. + goto unlock;
  23323. + } else if (arm_state->vc_suspend_state <= VC_SUSPEND_IDLE) {
  23324. + /* initiate suspend immediately in the case that we're waiting
  23325. + * for the timeout */
  23326. + stop_suspend_timer(arm_state);
  23327. + if (!vchiq_videocore_wanted(state)) {
  23328. + vchiq_log_info(vchiq_susp_log_level, "%s videocore "
  23329. + "idle, initiating suspend", __func__);
  23330. + status = vchiq_arm_vcsuspend(state);
  23331. + } else if (arm_state->autosuspend_override <
  23332. + FORCE_SUSPEND_FAIL_MAX) {
  23333. + vchiq_log_info(vchiq_susp_log_level, "%s letting "
  23334. + "videocore go idle", __func__);
  23335. + status = VCHIQ_SUCCESS;
  23336. + } else {
  23337. + vchiq_log_warning(vchiq_susp_log_level, "%s failed too "
  23338. + "many times - attempting suspend", __func__);
  23339. + status = vchiq_arm_vcsuspend(state);
  23340. + }
  23341. + } else {
  23342. + vchiq_log_info(vchiq_susp_log_level, "%s videocore suspend "
  23343. + "in progress - wait for completion", __func__);
  23344. + status = VCHIQ_SUCCESS;
  23345. + }
  23346. +
  23347. + /* Wait for suspend to happen due to system idle (not forced..) */
  23348. + if (status != VCHIQ_SUCCESS)
  23349. + goto unblock_resume;
  23350. +
  23351. + do {
  23352. + write_unlock_bh(&arm_state->susp_res_lock);
  23353. +
  23354. + rc = wait_for_completion_interruptible_timeout(
  23355. + &arm_state->vc_suspend_complete,
  23356. + msecs_to_jiffies(FORCE_SUSPEND_TIMEOUT_MS));
  23357. +
  23358. + write_lock_bh(&arm_state->susp_res_lock);
  23359. + if (rc < 0) {
  23360. + vchiq_log_warning(vchiq_susp_log_level, "%s "
  23361. + "interrupted waiting for suspend", __func__);
  23362. + status = VCHIQ_ERROR;
  23363. + goto unblock_resume;
  23364. + } else if (rc == 0) {
  23365. + if (arm_state->vc_suspend_state > VC_SUSPEND_IDLE) {
  23366. + /* Repeat timeout once if in progress */
  23367. + if (repeat < 0) {
  23368. + repeat = 1;
  23369. + continue;
  23370. + }
  23371. + }
  23372. + arm_state->autosuspend_override++;
  23373. + output_timeout_error(state);
  23374. +
  23375. + status = VCHIQ_RETRY;
  23376. + goto unblock_resume;
  23377. + }
  23378. + } while (0 < (repeat--));
  23379. +
  23380. + /* Check and report state in case we need to abort ARM suspend */
  23381. + if (arm_state->vc_suspend_state != VC_SUSPEND_SUSPENDED) {
  23382. + status = VCHIQ_RETRY;
  23383. + vchiq_log_error(vchiq_susp_log_level,
  23384. + "%s videocore suspend failed (state %s)", __func__,
  23385. + suspend_state_names[arm_state->vc_suspend_state +
  23386. + VC_SUSPEND_NUM_OFFSET]);
  23387. + /* Reset the state only if it's still in an error state.
  23388. + * Something could have already initiated another suspend. */
  23389. + if (arm_state->vc_suspend_state < VC_SUSPEND_IDLE)
  23390. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  23391. +
  23392. + goto unblock_resume;
  23393. + }
  23394. +
  23395. + /* successfully suspended - unlock and exit */
  23396. + goto unlock;
  23397. +
  23398. +unblock_resume:
  23399. + /* all error states need to unblock resume before exit */
  23400. + unblock_resume(arm_state);
  23401. +
  23402. +unlock:
  23403. + write_unlock_bh(&arm_state->susp_res_lock);
  23404. +
  23405. +out:
  23406. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, status);
  23407. + return status;
  23408. +}
  23409. +
  23410. +void
  23411. +vchiq_check_suspend(VCHIQ_STATE_T *state)
  23412. +{
  23413. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  23414. +
  23415. + if (!arm_state)
  23416. + goto out;
  23417. +
  23418. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  23419. +
  23420. + write_lock_bh(&arm_state->susp_res_lock);
  23421. + if (arm_state->vc_suspend_state != VC_SUSPEND_SUSPENDED &&
  23422. + arm_state->first_connect &&
  23423. + !vchiq_videocore_wanted(state)) {
  23424. + vchiq_arm_vcsuspend(state);
  23425. + }
  23426. + write_unlock_bh(&arm_state->susp_res_lock);
  23427. +
  23428. +out:
  23429. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  23430. + return;
  23431. +}
  23432. +
  23433. +
  23434. +int
  23435. +vchiq_arm_allow_resume(VCHIQ_STATE_T *state)
  23436. +{
  23437. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  23438. + int resume = 0;
  23439. + int ret = -1;
  23440. +
  23441. + if (!arm_state)
  23442. + goto out;
  23443. +
  23444. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  23445. +
  23446. + write_lock_bh(&arm_state->susp_res_lock);
  23447. + unblock_resume(arm_state);
  23448. + resume = vchiq_check_resume(state);
  23449. + write_unlock_bh(&arm_state->susp_res_lock);
  23450. +
  23451. + if (resume) {
  23452. + if (wait_for_completion_interruptible(
  23453. + &arm_state->vc_resume_complete) < 0) {
  23454. + vchiq_log_error(vchiq_susp_log_level,
  23455. + "%s interrupted", __func__);
  23456. + /* failed, cannot accurately derive suspend
  23457. + * state, so exit early. */
  23458. + goto out;
  23459. + }
  23460. + }
  23461. +
  23462. + read_lock_bh(&arm_state->susp_res_lock);
  23463. + if (arm_state->vc_suspend_state == VC_SUSPEND_SUSPENDED) {
  23464. + vchiq_log_info(vchiq_susp_log_level,
  23465. + "%s: Videocore remains suspended", __func__);
  23466. + } else {
  23467. + vchiq_log_info(vchiq_susp_log_level,
  23468. + "%s: Videocore resumed", __func__);
  23469. + ret = 0;
  23470. + }
  23471. + read_unlock_bh(&arm_state->susp_res_lock);
  23472. +out:
  23473. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  23474. + return ret;
  23475. +}
  23476. +
  23477. +/* This function should be called with the write lock held */
  23478. +int
  23479. +vchiq_check_resume(VCHIQ_STATE_T *state)
  23480. +{
  23481. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  23482. + int resume = 0;
  23483. +
  23484. + if (!arm_state)
  23485. + goto out;
  23486. +
  23487. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  23488. +
  23489. + if (need_resume(state)) {
  23490. + set_resume_state(arm_state, VC_RESUME_REQUESTED);
  23491. + request_poll(state, NULL, 0);
  23492. + resume = 1;
  23493. + }
  23494. +
  23495. +out:
  23496. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  23497. + return resume;
  23498. +}
  23499. +
  23500. +void
  23501. +vchiq_platform_check_resume(VCHIQ_STATE_T *state)
  23502. +{
  23503. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  23504. + int res = 0;
  23505. +
  23506. + if (!arm_state)
  23507. + goto out;
  23508. +
  23509. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  23510. +
  23511. + write_lock_bh(&arm_state->susp_res_lock);
  23512. + if (arm_state->wake_address == 0) {
  23513. + vchiq_log_info(vchiq_susp_log_level,
  23514. + "%s: already awake", __func__);
  23515. + goto unlock;
  23516. + }
  23517. + if (arm_state->vc_resume_state == VC_RESUME_IN_PROGRESS) {
  23518. + vchiq_log_info(vchiq_susp_log_level,
  23519. + "%s: already resuming", __func__);
  23520. + goto unlock;
  23521. + }
  23522. +
  23523. + if (arm_state->vc_resume_state == VC_RESUME_REQUESTED) {
  23524. + set_resume_state(arm_state, VC_RESUME_IN_PROGRESS);
  23525. + res = 1;
  23526. + } else
  23527. + vchiq_log_trace(vchiq_susp_log_level,
  23528. + "%s: not resuming (resume state %s)", __func__,
  23529. + resume_state_names[arm_state->vc_resume_state +
  23530. + VC_RESUME_NUM_OFFSET]);
  23531. +
  23532. +unlock:
  23533. + write_unlock_bh(&arm_state->susp_res_lock);
  23534. +
  23535. + if (res)
  23536. + vchiq_platform_resume(state);
  23537. +
  23538. +out:
  23539. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  23540. + return;
  23541. +
  23542. +}
  23543. +
  23544. +
  23545. +
  23546. +VCHIQ_STATUS_T
  23547. +vchiq_use_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  23548. + enum USE_TYPE_E use_type)
  23549. +{
  23550. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  23551. + VCHIQ_STATUS_T ret = VCHIQ_SUCCESS;
  23552. + char entity[16];
  23553. + int *entity_uc;
  23554. + int local_uc, local_entity_uc;
  23555. +
  23556. + if (!arm_state)
  23557. + goto out;
  23558. +
  23559. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  23560. +
  23561. + if (use_type == USE_TYPE_VCHIQ) {
  23562. + sprintf(entity, "VCHIQ: ");
  23563. + entity_uc = &arm_state->peer_use_count;
  23564. + } else if (service) {
  23565. + sprintf(entity, "%c%c%c%c:%03d",
  23566. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  23567. + service->client_id);
  23568. + entity_uc = &service->service_use_count;
  23569. + } else {
  23570. + vchiq_log_error(vchiq_susp_log_level, "%s null service "
  23571. + "ptr", __func__);
  23572. + ret = VCHIQ_ERROR;
  23573. + goto out;
  23574. + }
  23575. +
  23576. + write_lock_bh(&arm_state->susp_res_lock);
  23577. + while (arm_state->resume_blocked) {
  23578. + /* If we call 'use' while force suspend is waiting for suspend,
  23579. + * then we're about to block the thread which the force is
  23580. + * waiting to complete, so we're bound to just time out. In this
  23581. + * case, set the suspend state such that the wait will be
  23582. + * canceled, so we can complete as quickly as possible. */
  23583. + if (arm_state->resume_blocked && arm_state->vc_suspend_state ==
  23584. + VC_SUSPEND_IDLE) {
  23585. + set_suspend_state(arm_state, VC_SUSPEND_FORCE_CANCELED);
  23586. + break;
  23587. + }
  23588. + /* If suspend is already in progress then we need to block */
  23589. + if (!try_wait_for_completion(&arm_state->resume_blocker)) {
  23590. + /* Indicate that there are threads waiting on the resume
  23591. + * blocker. These need to be allowed to complete before
  23592. + * a _second_ call to force suspend can complete,
  23593. + * otherwise low priority threads might never actually
  23594. + * continue */
  23595. + arm_state->blocked_count++;
  23596. + write_unlock_bh(&arm_state->susp_res_lock);
  23597. + vchiq_log_info(vchiq_susp_log_level, "%s %s resume "
  23598. + "blocked - waiting...", __func__, entity);
  23599. + if (wait_for_completion_killable(
  23600. + &arm_state->resume_blocker) != 0) {
  23601. + vchiq_log_error(vchiq_susp_log_level, "%s %s "
  23602. + "wait for resume blocker interrupted",
  23603. + __func__, entity);
  23604. + ret = VCHIQ_ERROR;
  23605. + write_lock_bh(&arm_state->susp_res_lock);
  23606. + arm_state->blocked_count--;
  23607. + write_unlock_bh(&arm_state->susp_res_lock);
  23608. + goto out;
  23609. + }
  23610. + vchiq_log_info(vchiq_susp_log_level, "%s %s resume "
  23611. + "unblocked", __func__, entity);
  23612. + write_lock_bh(&arm_state->susp_res_lock);
  23613. + if (--arm_state->blocked_count == 0)
  23614. + complete_all(&arm_state->blocked_blocker);
  23615. + }
  23616. + }
  23617. +
  23618. + stop_suspend_timer(arm_state);
  23619. +
  23620. + local_uc = ++arm_state->videocore_use_count;
  23621. + local_entity_uc = ++(*entity_uc);
  23622. +
  23623. + /* If there's a pending request which hasn't yet been serviced then
  23624. + * just clear it. If we're past VC_SUSPEND_REQUESTED state then
  23625. + * vc_resume_complete will block until we either resume or fail to
  23626. + * suspend */
  23627. + if (arm_state->vc_suspend_state <= VC_SUSPEND_REQUESTED)
  23628. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  23629. +
  23630. + if ((use_type != USE_TYPE_SERVICE_NO_RESUME) && need_resume(state)) {
  23631. + set_resume_state(arm_state, VC_RESUME_REQUESTED);
  23632. + vchiq_log_info(vchiq_susp_log_level,
  23633. + "%s %s count %d, state count %d",
  23634. + __func__, entity, local_entity_uc, local_uc);
  23635. + request_poll(state, NULL, 0);
  23636. + } else
  23637. + vchiq_log_trace(vchiq_susp_log_level,
  23638. + "%s %s count %d, state count %d",
  23639. + __func__, entity, *entity_uc, local_uc);
  23640. +
  23641. +
  23642. + write_unlock_bh(&arm_state->susp_res_lock);
  23643. +
  23644. + /* Completion is in a done state when we're not suspended, so this won't
  23645. + * block for the non-suspended case. */
  23646. + if (!try_wait_for_completion(&arm_state->vc_resume_complete)) {
  23647. + vchiq_log_info(vchiq_susp_log_level, "%s %s wait for resume",
  23648. + __func__, entity);
  23649. + if (wait_for_completion_killable(
  23650. + &arm_state->vc_resume_complete) != 0) {
  23651. + vchiq_log_error(vchiq_susp_log_level, "%s %s wait for "
  23652. + "resume interrupted", __func__, entity);
  23653. + ret = VCHIQ_ERROR;
  23654. + goto out;
  23655. + }
  23656. + vchiq_log_info(vchiq_susp_log_level, "%s %s resumed", __func__,
  23657. + entity);
  23658. + }
  23659. +
  23660. + if (ret == VCHIQ_SUCCESS) {
  23661. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  23662. + long ack_cnt = atomic_xchg(&arm_state->ka_use_ack_count, 0);
  23663. + while (ack_cnt && (status == VCHIQ_SUCCESS)) {
  23664. + /* Send the use notify to videocore */
  23665. + status = vchiq_send_remote_use_active(state);
  23666. + if (status == VCHIQ_SUCCESS)
  23667. + ack_cnt--;
  23668. + else
  23669. + atomic_add(ack_cnt,
  23670. + &arm_state->ka_use_ack_count);
  23671. + }
  23672. + }
  23673. +
  23674. +out:
  23675. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  23676. + return ret;
  23677. +}
  23678. +
  23679. +VCHIQ_STATUS_T
  23680. +vchiq_release_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service)
  23681. +{
  23682. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  23683. + VCHIQ_STATUS_T ret = VCHIQ_SUCCESS;
  23684. + char entity[16];
  23685. + int *entity_uc;
  23686. + int local_uc, local_entity_uc;
  23687. +
  23688. + if (!arm_state)
  23689. + goto out;
  23690. +
  23691. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  23692. +
  23693. + if (service) {
  23694. + sprintf(entity, "%c%c%c%c:%03d",
  23695. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  23696. + service->client_id);
  23697. + entity_uc = &service->service_use_count;
  23698. + } else {
  23699. + sprintf(entity, "PEER: ");
  23700. + entity_uc = &arm_state->peer_use_count;
  23701. + }
  23702. +
  23703. + write_lock_bh(&arm_state->susp_res_lock);
  23704. + if (!arm_state->videocore_use_count || !(*entity_uc)) {
  23705. + /* Don't use BUG_ON - don't allow user thread to crash kernel */
  23706. + WARN_ON(!arm_state->videocore_use_count);
  23707. + WARN_ON(!(*entity_uc));
  23708. + ret = VCHIQ_ERROR;
  23709. + goto unlock;
  23710. + }
  23711. + local_uc = --arm_state->videocore_use_count;
  23712. + local_entity_uc = --(*entity_uc);
  23713. +
  23714. + if (!vchiq_videocore_wanted(state)) {
  23715. + if (vchiq_platform_use_suspend_timer() &&
  23716. + !arm_state->resume_blocked) {
  23717. + /* Only use the timer if we're not trying to force
  23718. + * suspend (=> resume_blocked) */
  23719. + start_suspend_timer(arm_state);
  23720. + } else {
  23721. + vchiq_log_info(vchiq_susp_log_level,
  23722. + "%s %s count %d, state count %d - suspending",
  23723. + __func__, entity, *entity_uc,
  23724. + arm_state->videocore_use_count);
  23725. + vchiq_arm_vcsuspend(state);
  23726. + }
  23727. + } else
  23728. + vchiq_log_trace(vchiq_susp_log_level,
  23729. + "%s %s count %d, state count %d",
  23730. + __func__, entity, *entity_uc,
  23731. + arm_state->videocore_use_count);
  23732. +
  23733. +unlock:
  23734. + write_unlock_bh(&arm_state->susp_res_lock);
  23735. +
  23736. +out:
  23737. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  23738. + return ret;
  23739. +}
  23740. +
  23741. +void
  23742. +vchiq_on_remote_use(VCHIQ_STATE_T *state)
  23743. +{
  23744. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  23745. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  23746. + atomic_inc(&arm_state->ka_use_count);
  23747. + complete(&arm_state->ka_evt);
  23748. +}
  23749. +
  23750. +void
  23751. +vchiq_on_remote_release(VCHIQ_STATE_T *state)
  23752. +{
  23753. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  23754. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  23755. + atomic_inc(&arm_state->ka_release_count);
  23756. + complete(&arm_state->ka_evt);
  23757. +}
  23758. +
  23759. +VCHIQ_STATUS_T
  23760. +vchiq_use_service_internal(VCHIQ_SERVICE_T *service)
  23761. +{
  23762. + return vchiq_use_internal(service->state, service, USE_TYPE_SERVICE);
  23763. +}
  23764. +
  23765. +VCHIQ_STATUS_T
  23766. +vchiq_release_service_internal(VCHIQ_SERVICE_T *service)
  23767. +{
  23768. + return vchiq_release_internal(service->state, service);
  23769. +}
  23770. +
  23771. +static void suspend_timer_callback(unsigned long context)
  23772. +{
  23773. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *)context;
  23774. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  23775. + if (!arm_state)
  23776. + goto out;
  23777. + vchiq_log_info(vchiq_susp_log_level,
  23778. + "%s - suspend timer expired - check suspend", __func__);
  23779. + vchiq_check_suspend(state);
  23780. +out:
  23781. + return;
  23782. +}
  23783. +
  23784. +VCHIQ_STATUS_T
  23785. +vchiq_use_service_no_resume(VCHIQ_SERVICE_HANDLE_T handle)
  23786. +{
  23787. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  23788. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  23789. + if (service) {
  23790. + ret = vchiq_use_internal(service->state, service,
  23791. + USE_TYPE_SERVICE_NO_RESUME);
  23792. + unlock_service(service);
  23793. + }
  23794. + return ret;
  23795. +}
  23796. +
  23797. +VCHIQ_STATUS_T
  23798. +vchiq_use_service(VCHIQ_SERVICE_HANDLE_T handle)
  23799. +{
  23800. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  23801. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  23802. + if (service) {
  23803. + ret = vchiq_use_internal(service->state, service,
  23804. + USE_TYPE_SERVICE);
  23805. + unlock_service(service);
  23806. + }
  23807. + return ret;
  23808. +}
  23809. +
  23810. +VCHIQ_STATUS_T
  23811. +vchiq_release_service(VCHIQ_SERVICE_HANDLE_T handle)
  23812. +{
  23813. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  23814. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  23815. + if (service) {
  23816. + ret = vchiq_release_internal(service->state, service);
  23817. + unlock_service(service);
  23818. + }
  23819. + return ret;
  23820. +}
  23821. +
  23822. +void
  23823. +vchiq_dump_service_use_state(VCHIQ_STATE_T *state)
  23824. +{
  23825. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  23826. + int i, j = 0;
  23827. + /* Only dump 64 services */
  23828. + static const int local_max_services = 64;
  23829. + /* If there's more than 64 services, only dump ones with
  23830. + * non-zero counts */
  23831. + int only_nonzero = 0;
  23832. + static const char *nz = "<-- preventing suspend";
  23833. +
  23834. + enum vc_suspend_status vc_suspend_state;
  23835. + enum vc_resume_status vc_resume_state;
  23836. + int peer_count;
  23837. + int vc_use_count;
  23838. + int active_services;
  23839. + struct service_data_struct {
  23840. + int fourcc;
  23841. + int clientid;
  23842. + int use_count;
  23843. + } service_data[local_max_services];
  23844. +
  23845. + if (!arm_state)
  23846. + return;
  23847. +
  23848. + read_lock_bh(&arm_state->susp_res_lock);
  23849. + vc_suspend_state = arm_state->vc_suspend_state;
  23850. + vc_resume_state = arm_state->vc_resume_state;
  23851. + peer_count = arm_state->peer_use_count;
  23852. + vc_use_count = arm_state->videocore_use_count;
  23853. + active_services = state->unused_service;
  23854. + if (active_services > local_max_services)
  23855. + only_nonzero = 1;
  23856. +
  23857. + for (i = 0; (i < active_services) && (j < local_max_services); i++) {
  23858. + VCHIQ_SERVICE_T *service_ptr = state->services[i];
  23859. + if (!service_ptr)
  23860. + continue;
  23861. +
  23862. + if (only_nonzero && !service_ptr->service_use_count)
  23863. + continue;
  23864. +
  23865. + if (service_ptr->srvstate != VCHIQ_SRVSTATE_FREE) {
  23866. + service_data[j].fourcc = service_ptr->base.fourcc;
  23867. + service_data[j].clientid = service_ptr->client_id;
  23868. + service_data[j++].use_count = service_ptr->
  23869. + service_use_count;
  23870. + }
  23871. + }
  23872. +
  23873. + read_unlock_bh(&arm_state->susp_res_lock);
  23874. +
  23875. + vchiq_log_warning(vchiq_susp_log_level,
  23876. + "-- Videcore suspend state: %s --",
  23877. + suspend_state_names[vc_suspend_state + VC_SUSPEND_NUM_OFFSET]);
  23878. + vchiq_log_warning(vchiq_susp_log_level,
  23879. + "-- Videcore resume state: %s --",
  23880. + resume_state_names[vc_resume_state + VC_RESUME_NUM_OFFSET]);
  23881. +
  23882. + if (only_nonzero)
  23883. + vchiq_log_warning(vchiq_susp_log_level, "Too many active "
  23884. + "services (%d). Only dumping up to first %d services "
  23885. + "with non-zero use-count", active_services,
  23886. + local_max_services);
  23887. +
  23888. + for (i = 0; i < j; i++) {
  23889. + vchiq_log_warning(vchiq_susp_log_level,
  23890. + "----- %c%c%c%c:%d service count %d %s",
  23891. + VCHIQ_FOURCC_AS_4CHARS(service_data[i].fourcc),
  23892. + service_data[i].clientid,
  23893. + service_data[i].use_count,
  23894. + service_data[i].use_count ? nz : "");
  23895. + }
  23896. + vchiq_log_warning(vchiq_susp_log_level,
  23897. + "----- VCHIQ use count count %d", peer_count);
  23898. + vchiq_log_warning(vchiq_susp_log_level,
  23899. + "--- Overall vchiq instance use count %d", vc_use_count);
  23900. +
  23901. + vchiq_dump_platform_use_state(state);
  23902. +}
  23903. +
  23904. +VCHIQ_STATUS_T
  23905. +vchiq_check_service(VCHIQ_SERVICE_T *service)
  23906. +{
  23907. + VCHIQ_ARM_STATE_T *arm_state;
  23908. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  23909. +
  23910. + if (!service || !service->state)
  23911. + goto out;
  23912. +
  23913. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  23914. +
  23915. + arm_state = vchiq_platform_get_arm_state(service->state);
  23916. +
  23917. + read_lock_bh(&arm_state->susp_res_lock);
  23918. + if (service->service_use_count)
  23919. + ret = VCHIQ_SUCCESS;
  23920. + read_unlock_bh(&arm_state->susp_res_lock);
  23921. +
  23922. + if (ret == VCHIQ_ERROR) {
  23923. + vchiq_log_error(vchiq_susp_log_level,
  23924. + "%s ERROR - %c%c%c%c:%d service count %d, "
  23925. + "state count %d, videocore suspend state %s", __func__,
  23926. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  23927. + service->client_id, service->service_use_count,
  23928. + arm_state->videocore_use_count,
  23929. + suspend_state_names[arm_state->vc_suspend_state +
  23930. + VC_SUSPEND_NUM_OFFSET]);
  23931. + vchiq_dump_service_use_state(service->state);
  23932. + }
  23933. +out:
  23934. + return ret;
  23935. +}
  23936. +
  23937. +/* stub functions */
  23938. +void vchiq_on_remote_use_active(VCHIQ_STATE_T *state)
  23939. +{
  23940. + (void)state;
  23941. +}
  23942. +
  23943. +void vchiq_platform_conn_state_changed(VCHIQ_STATE_T *state,
  23944. + VCHIQ_CONNSTATE_T oldstate, VCHIQ_CONNSTATE_T newstate)
  23945. +{
  23946. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  23947. + vchiq_log_info(vchiq_susp_log_level, "%d: %s->%s", state->id,
  23948. + get_conn_state_name(oldstate), get_conn_state_name(newstate));
  23949. + if (state->conn_state == VCHIQ_CONNSTATE_CONNECTED) {
  23950. + write_lock_bh(&arm_state->susp_res_lock);
  23951. + if (!arm_state->first_connect) {
  23952. + char threadname[10];
  23953. + arm_state->first_connect = 1;
  23954. + write_unlock_bh(&arm_state->susp_res_lock);
  23955. + snprintf(threadname, sizeof(threadname), "VCHIQka-%d",
  23956. + state->id);
  23957. + arm_state->ka_thread = kthread_create(
  23958. + &vchiq_keepalive_thread_func,
  23959. + (void *)state,
  23960. + threadname);
  23961. + if (arm_state->ka_thread == NULL) {
  23962. + vchiq_log_error(vchiq_susp_log_level,
  23963. + "vchiq: FATAL: couldn't create thread %s",
  23964. + threadname);
  23965. + } else {
  23966. + wake_up_process(arm_state->ka_thread);
  23967. + }
  23968. + } else
  23969. + write_unlock_bh(&arm_state->susp_res_lock);
  23970. + }
  23971. +}
  23972. +
  23973. +
  23974. +/****************************************************************************
  23975. +*
  23976. +* vchiq_init - called when the module is loaded.
  23977. +*
  23978. +***************************************************************************/
  23979. +
  23980. +static int __init
  23981. +vchiq_init(void)
  23982. +{
  23983. + int err;
  23984. + void *ptr_err;
  23985. +
  23986. + /* create proc entries */
  23987. + err = vchiq_proc_init();
  23988. + if (err != 0)
  23989. + goto failed_proc_init;
  23990. +
  23991. + err = alloc_chrdev_region(&vchiq_devid, VCHIQ_MINOR, 1, DEVICE_NAME);
  23992. + if (err != 0) {
  23993. + vchiq_log_error(vchiq_arm_log_level,
  23994. + "Unable to allocate device number");
  23995. + goto failed_alloc_chrdev;
  23996. + }
  23997. + cdev_init(&vchiq_cdev, &vchiq_fops);
  23998. + vchiq_cdev.owner = THIS_MODULE;
  23999. + err = cdev_add(&vchiq_cdev, vchiq_devid, 1);
  24000. + if (err != 0) {
  24001. + vchiq_log_error(vchiq_arm_log_level,
  24002. + "Unable to register device");
  24003. + goto failed_cdev_add;
  24004. + }
  24005. +
  24006. + /* create sysfs entries */
  24007. + vchiq_class = class_create(THIS_MODULE, DEVICE_NAME);
  24008. + ptr_err = vchiq_class;
  24009. + if (IS_ERR(ptr_err))
  24010. + goto failed_class_create;
  24011. +
  24012. + vchiq_dev = device_create(vchiq_class, NULL,
  24013. + vchiq_devid, NULL, "vchiq");
  24014. + ptr_err = vchiq_dev;
  24015. + if (IS_ERR(ptr_err))
  24016. + goto failed_device_create;
  24017. +
  24018. + err = vchiq_platform_init(&g_state);
  24019. + if (err != 0)
  24020. + goto failed_platform_init;
  24021. +
  24022. + vchiq_log_info(vchiq_arm_log_level,
  24023. + "vchiq: initialised - version %d (min %d), device %d.%d",
  24024. + VCHIQ_VERSION, VCHIQ_VERSION_MIN,
  24025. + MAJOR(vchiq_devid), MINOR(vchiq_devid));
  24026. +
  24027. + return 0;
  24028. +
  24029. +failed_platform_init:
  24030. + device_destroy(vchiq_class, vchiq_devid);
  24031. +failed_device_create:
  24032. + class_destroy(vchiq_class);
  24033. +failed_class_create:
  24034. + cdev_del(&vchiq_cdev);
  24035. + err = PTR_ERR(ptr_err);
  24036. +failed_cdev_add:
  24037. + unregister_chrdev_region(vchiq_devid, 1);
  24038. +failed_alloc_chrdev:
  24039. + vchiq_proc_deinit();
  24040. +failed_proc_init:
  24041. + vchiq_log_warning(vchiq_arm_log_level, "could not load vchiq");
  24042. + return err;
  24043. +}
  24044. +
  24045. +static int vchiq_instance_get_use_count(VCHIQ_INSTANCE_T instance)
  24046. +{
  24047. + VCHIQ_SERVICE_T *service;
  24048. + int use_count = 0, i;
  24049. + i = 0;
  24050. + while ((service = next_service_by_instance(instance->state,
  24051. + instance, &i)) != NULL) {
  24052. + use_count += service->service_use_count;
  24053. + unlock_service(service);
  24054. + }
  24055. + return use_count;
  24056. +}
  24057. +
  24058. +/* read the per-process use-count */
  24059. +static int proc_read_use_count(char *page, char **start,
  24060. + off_t off, int count,
  24061. + int *eof, void *data)
  24062. +{
  24063. + VCHIQ_INSTANCE_T instance = data;
  24064. + int len, use_count;
  24065. +
  24066. + use_count = vchiq_instance_get_use_count(instance);
  24067. + len = snprintf(page+off, count, "%d\n", use_count);
  24068. +
  24069. + return len;
  24070. +}
  24071. +
  24072. +/* add an instance (process) to the proc entries */
  24073. +static int vchiq_proc_add_instance(VCHIQ_INSTANCE_T instance)
  24074. +{
  24075. +#if 1
  24076. + return 0;
  24077. +#else
  24078. + char pidstr[32];
  24079. + struct proc_dir_entry *top, *use_count;
  24080. + struct proc_dir_entry *clients = vchiq_clients_top();
  24081. + int pid = instance->pid;
  24082. +
  24083. + snprintf(pidstr, sizeof(pidstr), "%d", pid);
  24084. + top = proc_mkdir(pidstr, clients);
  24085. + if (!top)
  24086. + goto fail_top;
  24087. +
  24088. + use_count = create_proc_read_entry("use_count",
  24089. + 0444, top,
  24090. + proc_read_use_count,
  24091. + instance);
  24092. + if (!use_count)
  24093. + goto fail_use_count;
  24094. +
  24095. + instance->proc_entry = top;
  24096. +
  24097. + return 0;
  24098. +
  24099. +fail_use_count:
  24100. + remove_proc_entry(top->name, clients);
  24101. +fail_top:
  24102. + return -ENOMEM;
  24103. +#endif
  24104. +}
  24105. +
  24106. +static void vchiq_proc_remove_instance(VCHIQ_INSTANCE_T instance)
  24107. +{
  24108. +#if 0
  24109. + struct proc_dir_entry *clients = vchiq_clients_top();
  24110. + remove_proc_entry("use_count", instance->proc_entry);
  24111. + remove_proc_entry(instance->proc_entry->name, clients);
  24112. +#endif
  24113. +}
  24114. +
  24115. +/****************************************************************************
  24116. +*
  24117. +* vchiq_exit - called when the module is unloaded.
  24118. +*
  24119. +***************************************************************************/
  24120. +
  24121. +static void __exit
  24122. +vchiq_exit(void)
  24123. +{
  24124. + vchiq_platform_exit(&g_state);
  24125. + device_destroy(vchiq_class, vchiq_devid);
  24126. + class_destroy(vchiq_class);
  24127. + cdev_del(&vchiq_cdev);
  24128. + unregister_chrdev_region(vchiq_devid, 1);
  24129. +}
  24130. +
  24131. +module_init(vchiq_init);
  24132. +module_exit(vchiq_exit);
  24133. +MODULE_LICENSE("GPL");
  24134. +MODULE_AUTHOR("Broadcom Corporation");
  24135. diff -Nur linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h
  24136. --- linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h 1970-01-01 01:00:00.000000000 +0100
  24137. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h 2014-04-13 17:32:57.000000000 +0200
  24138. @@ -0,0 +1,212 @@
  24139. +/**
  24140. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  24141. + *
  24142. + * Redistribution and use in source and binary forms, with or without
  24143. + * modification, are permitted provided that the following conditions
  24144. + * are met:
  24145. + * 1. Redistributions of source code must retain the above copyright
  24146. + * notice, this list of conditions, and the following disclaimer,
  24147. + * without modification.
  24148. + * 2. Redistributions in binary form must reproduce the above copyright
  24149. + * notice, this list of conditions and the following disclaimer in the
  24150. + * documentation and/or other materials provided with the distribution.
  24151. + * 3. The names of the above-listed copyright holders may not be used
  24152. + * to endorse or promote products derived from this software without
  24153. + * specific prior written permission.
  24154. + *
  24155. + * ALTERNATIVELY, this software may be distributed under the terms of the
  24156. + * GNU General Public License ("GPL") version 2, as published by the Free
  24157. + * Software Foundation.
  24158. + *
  24159. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  24160. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  24161. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  24162. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24163. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24164. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24165. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24166. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  24167. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24168. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24169. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24170. + */
  24171. +
  24172. +#ifndef VCHIQ_ARM_H
  24173. +#define VCHIQ_ARM_H
  24174. +
  24175. +#include <linux/mutex.h>
  24176. +#include <linux/semaphore.h>
  24177. +#include <linux/atomic.h>
  24178. +#include "vchiq_core.h"
  24179. +
  24180. +
  24181. +enum vc_suspend_status {
  24182. + VC_SUSPEND_FORCE_CANCELED = -3, /* Force suspend canceled, too busy */
  24183. + VC_SUSPEND_REJECTED = -2, /* Videocore rejected suspend request */
  24184. + VC_SUSPEND_FAILED = -1, /* Videocore suspend failed */
  24185. + VC_SUSPEND_IDLE = 0, /* VC active, no suspend actions */
  24186. + VC_SUSPEND_REQUESTED, /* User has requested suspend */
  24187. + VC_SUSPEND_IN_PROGRESS, /* Slot handler has recvd suspend request */
  24188. + VC_SUSPEND_SUSPENDED /* Videocore suspend succeeded */
  24189. +};
  24190. +
  24191. +enum vc_resume_status {
  24192. + VC_RESUME_FAILED = -1, /* Videocore resume failed */
  24193. + VC_RESUME_IDLE = 0, /* VC suspended, no resume actions */
  24194. + VC_RESUME_REQUESTED, /* User has requested resume */
  24195. + VC_RESUME_IN_PROGRESS, /* Slot handler has received resume request */
  24196. + VC_RESUME_RESUMED /* Videocore resumed successfully (active) */
  24197. +};
  24198. +
  24199. +
  24200. +enum USE_TYPE_E {
  24201. + USE_TYPE_SERVICE,
  24202. + USE_TYPE_SERVICE_NO_RESUME,
  24203. + USE_TYPE_VCHIQ
  24204. +};
  24205. +
  24206. +
  24207. +
  24208. +typedef struct vchiq_arm_state_struct {
  24209. + /* Keepalive-related data */
  24210. + struct task_struct *ka_thread;
  24211. + struct completion ka_evt;
  24212. + atomic_t ka_use_count;
  24213. + atomic_t ka_use_ack_count;
  24214. + atomic_t ka_release_count;
  24215. +
  24216. + struct completion vc_suspend_complete;
  24217. + struct completion vc_resume_complete;
  24218. +
  24219. + rwlock_t susp_res_lock;
  24220. + enum vc_suspend_status vc_suspend_state;
  24221. + enum vc_resume_status vc_resume_state;
  24222. +
  24223. + unsigned int wake_address;
  24224. +
  24225. + struct timer_list suspend_timer;
  24226. + int suspend_timer_timeout;
  24227. + int suspend_timer_running;
  24228. +
  24229. + /* Global use count for videocore.
  24230. + ** This is equal to the sum of the use counts for all services. When
  24231. + ** this hits zero the videocore suspend procedure will be initiated.
  24232. + */
  24233. + int videocore_use_count;
  24234. +
  24235. + /* Use count to track requests from videocore peer.
  24236. + ** This use count is not associated with a service, so needs to be
  24237. + ** tracked separately with the state.
  24238. + */
  24239. + int peer_use_count;
  24240. +
  24241. + /* Flag to indicate whether resume is blocked. This happens when the
  24242. + ** ARM is suspending
  24243. + */
  24244. + struct completion resume_blocker;
  24245. + int resume_blocked;
  24246. + struct completion blocked_blocker;
  24247. + int blocked_count;
  24248. +
  24249. + int autosuspend_override;
  24250. +
  24251. + /* Flag to indicate that the first vchiq connect has made it through.
  24252. + ** This means that both sides should be fully ready, and we should
  24253. + ** be able to suspend after this point.
  24254. + */
  24255. + int first_connect;
  24256. +
  24257. + unsigned long long suspend_start_time;
  24258. + unsigned long long sleep_start_time;
  24259. + unsigned long long resume_start_time;
  24260. + unsigned long long last_wake_time;
  24261. +
  24262. +} VCHIQ_ARM_STATE_T;
  24263. +
  24264. +extern int vchiq_arm_log_level;
  24265. +extern int vchiq_susp_log_level;
  24266. +
  24267. +extern int __init
  24268. +vchiq_platform_init(VCHIQ_STATE_T *state);
  24269. +
  24270. +extern void __exit
  24271. +vchiq_platform_exit(VCHIQ_STATE_T *state);
  24272. +
  24273. +extern VCHIQ_STATE_T *
  24274. +vchiq_get_state(void);
  24275. +
  24276. +extern VCHIQ_STATUS_T
  24277. +vchiq_arm_vcsuspend(VCHIQ_STATE_T *state);
  24278. +
  24279. +extern VCHIQ_STATUS_T
  24280. +vchiq_arm_force_suspend(VCHIQ_STATE_T *state);
  24281. +
  24282. +extern int
  24283. +vchiq_arm_allow_resume(VCHIQ_STATE_T *state);
  24284. +
  24285. +extern VCHIQ_STATUS_T
  24286. +vchiq_arm_vcresume(VCHIQ_STATE_T *state);
  24287. +
  24288. +extern VCHIQ_STATUS_T
  24289. +vchiq_arm_init_state(VCHIQ_STATE_T *state, VCHIQ_ARM_STATE_T *arm_state);
  24290. +
  24291. +extern int
  24292. +vchiq_check_resume(VCHIQ_STATE_T *state);
  24293. +
  24294. +extern void
  24295. +vchiq_check_suspend(VCHIQ_STATE_T *state);
  24296. +
  24297. +extern VCHIQ_STATUS_T
  24298. +vchiq_use_service(VCHIQ_SERVICE_HANDLE_T handle);
  24299. +
  24300. +extern VCHIQ_STATUS_T
  24301. +vchiq_release_service(VCHIQ_SERVICE_HANDLE_T handle);
  24302. +
  24303. +extern VCHIQ_STATUS_T
  24304. +vchiq_check_service(VCHIQ_SERVICE_T *service);
  24305. +
  24306. +extern VCHIQ_STATUS_T
  24307. +vchiq_platform_suspend(VCHIQ_STATE_T *state);
  24308. +
  24309. +extern int
  24310. +vchiq_platform_videocore_wanted(VCHIQ_STATE_T *state);
  24311. +
  24312. +extern int
  24313. +vchiq_platform_use_suspend_timer(void);
  24314. +
  24315. +extern void
  24316. +vchiq_dump_platform_use_state(VCHIQ_STATE_T *state);
  24317. +
  24318. +extern void
  24319. +vchiq_dump_service_use_state(VCHIQ_STATE_T *state);
  24320. +
  24321. +extern VCHIQ_ARM_STATE_T*
  24322. +vchiq_platform_get_arm_state(VCHIQ_STATE_T *state);
  24323. +
  24324. +extern int
  24325. +vchiq_videocore_wanted(VCHIQ_STATE_T *state);
  24326. +
  24327. +extern VCHIQ_STATUS_T
  24328. +vchiq_use_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  24329. + enum USE_TYPE_E use_type);
  24330. +extern VCHIQ_STATUS_T
  24331. +vchiq_release_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service);
  24332. +
  24333. +void
  24334. +set_suspend_state(VCHIQ_ARM_STATE_T *arm_state,
  24335. + enum vc_suspend_status new_state);
  24336. +
  24337. +void
  24338. +set_resume_state(VCHIQ_ARM_STATE_T *arm_state,
  24339. + enum vc_resume_status new_state);
  24340. +
  24341. +void
  24342. +start_suspend_timer(VCHIQ_ARM_STATE_T *arm_state);
  24343. +
  24344. +extern int vchiq_proc_init(void);
  24345. +extern void vchiq_proc_deinit(void);
  24346. +extern struct proc_dir_entry *vchiq_proc_top(void);
  24347. +extern struct proc_dir_entry *vchiq_clients_top(void);
  24348. +
  24349. +
  24350. +#endif /* VCHIQ_ARM_H */
  24351. diff -Nur linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h
  24352. --- linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h 1970-01-01 01:00:00.000000000 +0100
  24353. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h 2014-04-13 17:32:57.000000000 +0200
  24354. @@ -0,0 +1,37 @@
  24355. +/**
  24356. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  24357. + *
  24358. + * Redistribution and use in source and binary forms, with or without
  24359. + * modification, are permitted provided that the following conditions
  24360. + * are met:
  24361. + * 1. Redistributions of source code must retain the above copyright
  24362. + * notice, this list of conditions, and the following disclaimer,
  24363. + * without modification.
  24364. + * 2. Redistributions in binary form must reproduce the above copyright
  24365. + * notice, this list of conditions and the following disclaimer in the
  24366. + * documentation and/or other materials provided with the distribution.
  24367. + * 3. The names of the above-listed copyright holders may not be used
  24368. + * to endorse or promote products derived from this software without
  24369. + * specific prior written permission.
  24370. + *
  24371. + * ALTERNATIVELY, this software may be distributed under the terms of the
  24372. + * GNU General Public License ("GPL") version 2, as published by the Free
  24373. + * Software Foundation.
  24374. + *
  24375. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  24376. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  24377. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  24378. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24379. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24380. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24381. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24382. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  24383. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24384. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24385. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24386. + */
  24387. +
  24388. +const char *vchiq_get_build_hostname(void);
  24389. +const char *vchiq_get_build_version(void);
  24390. +const char *vchiq_get_build_time(void);
  24391. +const char *vchiq_get_build_date(void);
  24392. diff -Nur linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h
  24393. --- linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h 1970-01-01 01:00:00.000000000 +0100
  24394. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h 2014-04-13 17:32:57.000000000 +0200
  24395. @@ -0,0 +1,60 @@
  24396. +/**
  24397. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  24398. + *
  24399. + * Redistribution and use in source and binary forms, with or without
  24400. + * modification, are permitted provided that the following conditions
  24401. + * are met:
  24402. + * 1. Redistributions of source code must retain the above copyright
  24403. + * notice, this list of conditions, and the following disclaimer,
  24404. + * without modification.
  24405. + * 2. Redistributions in binary form must reproduce the above copyright
  24406. + * notice, this list of conditions and the following disclaimer in the
  24407. + * documentation and/or other materials provided with the distribution.
  24408. + * 3. The names of the above-listed copyright holders may not be used
  24409. + * to endorse or promote products derived from this software without
  24410. + * specific prior written permission.
  24411. + *
  24412. + * ALTERNATIVELY, this software may be distributed under the terms of the
  24413. + * GNU General Public License ("GPL") version 2, as published by the Free
  24414. + * Software Foundation.
  24415. + *
  24416. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  24417. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  24418. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  24419. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24420. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24421. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24422. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24423. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  24424. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24425. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24426. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24427. + */
  24428. +
  24429. +#ifndef VCHIQ_CFG_H
  24430. +#define VCHIQ_CFG_H
  24431. +
  24432. +#define VCHIQ_MAGIC VCHIQ_MAKE_FOURCC('V', 'C', 'H', 'I')
  24433. +/* The version of VCHIQ - change with any non-trivial change */
  24434. +#define VCHIQ_VERSION 6
  24435. +/* The minimum compatible version - update to match VCHIQ_VERSION with any
  24436. +** incompatible change */
  24437. +#define VCHIQ_VERSION_MIN 3
  24438. +
  24439. +#define VCHIQ_MAX_STATES 1
  24440. +#define VCHIQ_MAX_SERVICES 4096
  24441. +#define VCHIQ_MAX_SLOTS 128
  24442. +#define VCHIQ_MAX_SLOTS_PER_SIDE 64
  24443. +
  24444. +#define VCHIQ_NUM_CURRENT_BULKS 32
  24445. +#define VCHIQ_NUM_SERVICE_BULKS 4
  24446. +
  24447. +#ifndef VCHIQ_ENABLE_DEBUG
  24448. +#define VCHIQ_ENABLE_DEBUG 1
  24449. +#endif
  24450. +
  24451. +#ifndef VCHIQ_ENABLE_STATS
  24452. +#define VCHIQ_ENABLE_STATS 1
  24453. +#endif
  24454. +
  24455. +#endif /* VCHIQ_CFG_H */
  24456. diff -Nur linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c
  24457. --- linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c 1970-01-01 01:00:00.000000000 +0100
  24458. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c 2014-07-07 10:45:11.000000000 +0200
  24459. @@ -0,0 +1,120 @@
  24460. +/**
  24461. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  24462. + *
  24463. + * Redistribution and use in source and binary forms, with or without
  24464. + * modification, are permitted provided that the following conditions
  24465. + * are met:
  24466. + * 1. Redistributions of source code must retain the above copyright
  24467. + * notice, this list of conditions, and the following disclaimer,
  24468. + * without modification.
  24469. + * 2. Redistributions in binary form must reproduce the above copyright
  24470. + * notice, this list of conditions and the following disclaimer in the
  24471. + * documentation and/or other materials provided with the distribution.
  24472. + * 3. The names of the above-listed copyright holders may not be used
  24473. + * to endorse or promote products derived from this software without
  24474. + * specific prior written permission.
  24475. + *
  24476. + * ALTERNATIVELY, this software may be distributed under the terms of the
  24477. + * GNU General Public License ("GPL") version 2, as published by the Free
  24478. + * Software Foundation.
  24479. + *
  24480. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  24481. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  24482. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  24483. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24484. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24485. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24486. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24487. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  24488. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24489. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24490. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24491. + */
  24492. +
  24493. +#include "vchiq_connected.h"
  24494. +#include "vchiq_core.h"
  24495. +#include "vchiq_killable.h"
  24496. +#include <linux/module.h>
  24497. +#include <linux/mutex.h>
  24498. +
  24499. +#define MAX_CALLBACKS 10
  24500. +
  24501. +static int g_connected;
  24502. +static int g_num_deferred_callbacks;
  24503. +static VCHIQ_CONNECTED_CALLBACK_T g_deferred_callback[MAX_CALLBACKS];
  24504. +static int g_once_init;
  24505. +static struct mutex g_connected_mutex;
  24506. +
  24507. +/****************************************************************************
  24508. +*
  24509. +* Function to initialize our lock.
  24510. +*
  24511. +***************************************************************************/
  24512. +
  24513. +static void connected_init(void)
  24514. +{
  24515. + if (!g_once_init) {
  24516. + mutex_init(&g_connected_mutex);
  24517. + g_once_init = 1;
  24518. + }
  24519. +}
  24520. +
  24521. +/****************************************************************************
  24522. +*
  24523. +* This function is used to defer initialization until the vchiq stack is
  24524. +* initialized. If the stack is already initialized, then the callback will
  24525. +* be made immediately, otherwise it will be deferred until
  24526. +* vchiq_call_connected_callbacks is called.
  24527. +*
  24528. +***************************************************************************/
  24529. +
  24530. +void vchiq_add_connected_callback(VCHIQ_CONNECTED_CALLBACK_T callback)
  24531. +{
  24532. + connected_init();
  24533. +
  24534. + if (mutex_lock_interruptible(&g_connected_mutex) != 0)
  24535. + return;
  24536. +
  24537. + if (g_connected)
  24538. + /* We're already connected. Call the callback immediately. */
  24539. +
  24540. + callback();
  24541. + else {
  24542. + if (g_num_deferred_callbacks >= MAX_CALLBACKS)
  24543. + vchiq_log_error(vchiq_core_log_level,
  24544. + "There already %d callback registered - "
  24545. + "please increase MAX_CALLBACKS",
  24546. + g_num_deferred_callbacks);
  24547. + else {
  24548. + g_deferred_callback[g_num_deferred_callbacks] =
  24549. + callback;
  24550. + g_num_deferred_callbacks++;
  24551. + }
  24552. + }
  24553. + mutex_unlock(&g_connected_mutex);
  24554. +}
  24555. +
  24556. +/****************************************************************************
  24557. +*
  24558. +* This function is called by the vchiq stack once it has been connected to
  24559. +* the videocore and clients can start to use the stack.
  24560. +*
  24561. +***************************************************************************/
  24562. +
  24563. +void vchiq_call_connected_callbacks(void)
  24564. +{
  24565. + int i;
  24566. +
  24567. + connected_init();
  24568. +
  24569. + if (mutex_lock_interruptible(&g_connected_mutex) != 0)
  24570. + return;
  24571. +
  24572. + for (i = 0; i < g_num_deferred_callbacks; i++)
  24573. + g_deferred_callback[i]();
  24574. +
  24575. + g_num_deferred_callbacks = 0;
  24576. + g_connected = 1;
  24577. + mutex_unlock(&g_connected_mutex);
  24578. +}
  24579. +EXPORT_SYMBOL(vchiq_add_connected_callback);
  24580. diff -Nur linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h
  24581. --- linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h 1970-01-01 01:00:00.000000000 +0100
  24582. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h 2014-07-07 10:45:11.000000000 +0200
  24583. @@ -0,0 +1,50 @@
  24584. +/**
  24585. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  24586. + *
  24587. + * Redistribution and use in source and binary forms, with or without
  24588. + * modification, are permitted provided that the following conditions
  24589. + * are met:
  24590. + * 1. Redistributions of source code must retain the above copyright
  24591. + * notice, this list of conditions, and the following disclaimer,
  24592. + * without modification.
  24593. + * 2. Redistributions in binary form must reproduce the above copyright
  24594. + * notice, this list of conditions and the following disclaimer in the
  24595. + * documentation and/or other materials provided with the distribution.
  24596. + * 3. The names of the above-listed copyright holders may not be used
  24597. + * to endorse or promote products derived from this software without
  24598. + * specific prior written permission.
  24599. + *
  24600. + * ALTERNATIVELY, this software may be distributed under the terms of the
  24601. + * GNU General Public License ("GPL") version 2, as published by the Free
  24602. + * Software Foundation.
  24603. + *
  24604. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  24605. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  24606. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  24607. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24608. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24609. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24610. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24611. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  24612. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24613. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24614. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24615. + */
  24616. +
  24617. +#ifndef VCHIQ_CONNECTED_H
  24618. +#define VCHIQ_CONNECTED_H
  24619. +
  24620. +/* ---- Include Files ----------------------------------------------------- */
  24621. +
  24622. +/* ---- Constants and Types ---------------------------------------------- */
  24623. +
  24624. +typedef void (*VCHIQ_CONNECTED_CALLBACK_T)(void);
  24625. +
  24626. +/* ---- Variable Externs ------------------------------------------------- */
  24627. +
  24628. +/* ---- Function Prototypes ---------------------------------------------- */
  24629. +
  24630. +void vchiq_add_connected_callback(VCHIQ_CONNECTED_CALLBACK_T callback);
  24631. +void vchiq_call_connected_callbacks(void);
  24632. +
  24633. +#endif /* VCHIQ_CONNECTED_H */
  24634. diff -Nur linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c
  24635. --- linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c 1970-01-01 01:00:00.000000000 +0100
  24636. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c 2014-07-07 10:45:11.000000000 +0200
  24637. @@ -0,0 +1,3825 @@
  24638. +/**
  24639. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  24640. + *
  24641. + * Redistribution and use in source and binary forms, with or without
  24642. + * modification, are permitted provided that the following conditions
  24643. + * are met:
  24644. + * 1. Redistributions of source code must retain the above copyright
  24645. + * notice, this list of conditions, and the following disclaimer,
  24646. + * without modification.
  24647. + * 2. Redistributions in binary form must reproduce the above copyright
  24648. + * notice, this list of conditions and the following disclaimer in the
  24649. + * documentation and/or other materials provided with the distribution.
  24650. + * 3. The names of the above-listed copyright holders may not be used
  24651. + * to endorse or promote products derived from this software without
  24652. + * specific prior written permission.
  24653. + *
  24654. + * ALTERNATIVELY, this software may be distributed under the terms of the
  24655. + * GNU General Public License ("GPL") version 2, as published by the Free
  24656. + * Software Foundation.
  24657. + *
  24658. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  24659. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  24660. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  24661. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24662. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24663. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24664. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24665. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  24666. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24667. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24668. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24669. + */
  24670. +
  24671. +#include "vchiq_core.h"
  24672. +#include "vchiq_killable.h"
  24673. +
  24674. +#define VCHIQ_SLOT_HANDLER_STACK 8192
  24675. +
  24676. +#define HANDLE_STATE_SHIFT 12
  24677. +
  24678. +#define SLOT_INFO_FROM_INDEX(state, index) (state->slot_info + (index))
  24679. +#define SLOT_DATA_FROM_INDEX(state, index) (state->slot_data + (index))
  24680. +#define SLOT_INDEX_FROM_DATA(state, data) \
  24681. + (((unsigned int)((char *)data - (char *)state->slot_data)) / \
  24682. + VCHIQ_SLOT_SIZE)
  24683. +#define SLOT_INDEX_FROM_INFO(state, info) \
  24684. + ((unsigned int)(info - state->slot_info))
  24685. +#define SLOT_QUEUE_INDEX_FROM_POS(pos) \
  24686. + ((int)((unsigned int)(pos) / VCHIQ_SLOT_SIZE))
  24687. +
  24688. +
  24689. +#define BULK_INDEX(x) (x & (VCHIQ_NUM_SERVICE_BULKS - 1))
  24690. +
  24691. +
  24692. +struct vchiq_open_payload {
  24693. + int fourcc;
  24694. + int client_id;
  24695. + short version;
  24696. + short version_min;
  24697. +};
  24698. +
  24699. +struct vchiq_openack_payload {
  24700. + short version;
  24701. +};
  24702. +
  24703. +/* we require this for consistency between endpoints */
  24704. +vchiq_static_assert(sizeof(VCHIQ_HEADER_T) == 8);
  24705. +vchiq_static_assert(IS_POW2(sizeof(VCHIQ_HEADER_T)));
  24706. +vchiq_static_assert(IS_POW2(VCHIQ_NUM_CURRENT_BULKS));
  24707. +vchiq_static_assert(IS_POW2(VCHIQ_NUM_SERVICE_BULKS));
  24708. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SERVICES));
  24709. +vchiq_static_assert(VCHIQ_VERSION >= VCHIQ_VERSION_MIN);
  24710. +
  24711. +/* Run time control of log level, based on KERN_XXX level. */
  24712. +int vchiq_core_log_level = VCHIQ_LOG_DEFAULT;
  24713. +int vchiq_core_msg_log_level = VCHIQ_LOG_DEFAULT;
  24714. +int vchiq_sync_log_level = VCHIQ_LOG_DEFAULT;
  24715. +
  24716. +static atomic_t pause_bulks_count = ATOMIC_INIT(0);
  24717. +
  24718. +static DEFINE_SPINLOCK(service_spinlock);
  24719. +DEFINE_SPINLOCK(bulk_waiter_spinlock);
  24720. +DEFINE_SPINLOCK(quota_spinlock);
  24721. +
  24722. +VCHIQ_STATE_T *vchiq_states[VCHIQ_MAX_STATES];
  24723. +static unsigned int handle_seq;
  24724. +
  24725. +static const char *const srvstate_names[] = {
  24726. + "FREE",
  24727. + "HIDDEN",
  24728. + "LISTENING",
  24729. + "OPENING",
  24730. + "OPEN",
  24731. + "OPENSYNC",
  24732. + "CLOSESENT",
  24733. + "CLOSERECVD",
  24734. + "CLOSEWAIT",
  24735. + "CLOSED"
  24736. +};
  24737. +
  24738. +static const char *const reason_names[] = {
  24739. + "SERVICE_OPENED",
  24740. + "SERVICE_CLOSED",
  24741. + "MESSAGE_AVAILABLE",
  24742. + "BULK_TRANSMIT_DONE",
  24743. + "BULK_RECEIVE_DONE",
  24744. + "BULK_TRANSMIT_ABORTED",
  24745. + "BULK_RECEIVE_ABORTED"
  24746. +};
  24747. +
  24748. +static const char *const conn_state_names[] = {
  24749. + "DISCONNECTED",
  24750. + "CONNECTING",
  24751. + "CONNECTED",
  24752. + "PAUSING",
  24753. + "PAUSE_SENT",
  24754. + "PAUSED",
  24755. + "RESUMING",
  24756. + "PAUSE_TIMEOUT",
  24757. + "RESUME_TIMEOUT"
  24758. +};
  24759. +
  24760. +
  24761. +static void
  24762. +release_message_sync(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header);
  24763. +
  24764. +static const char *msg_type_str(unsigned int msg_type)
  24765. +{
  24766. + switch (msg_type) {
  24767. + case VCHIQ_MSG_PADDING: return "PADDING";
  24768. + case VCHIQ_MSG_CONNECT: return "CONNECT";
  24769. + case VCHIQ_MSG_OPEN: return "OPEN";
  24770. + case VCHIQ_MSG_OPENACK: return "OPENACK";
  24771. + case VCHIQ_MSG_CLOSE: return "CLOSE";
  24772. + case VCHIQ_MSG_DATA: return "DATA";
  24773. + case VCHIQ_MSG_BULK_RX: return "BULK_RX";
  24774. + case VCHIQ_MSG_BULK_TX: return "BULK_TX";
  24775. + case VCHIQ_MSG_BULK_RX_DONE: return "BULK_RX_DONE";
  24776. + case VCHIQ_MSG_BULK_TX_DONE: return "BULK_TX_DONE";
  24777. + case VCHIQ_MSG_PAUSE: return "PAUSE";
  24778. + case VCHIQ_MSG_RESUME: return "RESUME";
  24779. + case VCHIQ_MSG_REMOTE_USE: return "REMOTE_USE";
  24780. + case VCHIQ_MSG_REMOTE_RELEASE: return "REMOTE_RELEASE";
  24781. + case VCHIQ_MSG_REMOTE_USE_ACTIVE: return "REMOTE_USE_ACTIVE";
  24782. + }
  24783. + return "???";
  24784. +}
  24785. +
  24786. +static inline void
  24787. +vchiq_set_service_state(VCHIQ_SERVICE_T *service, int newstate)
  24788. +{
  24789. + vchiq_log_info(vchiq_core_log_level, "%d: srv:%d %s->%s",
  24790. + service->state->id, service->localport,
  24791. + srvstate_names[service->srvstate],
  24792. + srvstate_names[newstate]);
  24793. + service->srvstate = newstate;
  24794. +}
  24795. +
  24796. +VCHIQ_SERVICE_T *
  24797. +find_service_by_handle(VCHIQ_SERVICE_HANDLE_T handle)
  24798. +{
  24799. + VCHIQ_SERVICE_T *service;
  24800. +
  24801. + spin_lock(&service_spinlock);
  24802. + service = handle_to_service(handle);
  24803. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  24804. + (service->handle == handle)) {
  24805. + BUG_ON(service->ref_count == 0);
  24806. + service->ref_count++;
  24807. + } else
  24808. + service = NULL;
  24809. + spin_unlock(&service_spinlock);
  24810. +
  24811. + if (!service)
  24812. + vchiq_log_info(vchiq_core_log_level,
  24813. + "Invalid service handle 0x%x", handle);
  24814. +
  24815. + return service;
  24816. +}
  24817. +
  24818. +VCHIQ_SERVICE_T *
  24819. +find_service_by_port(VCHIQ_STATE_T *state, int localport)
  24820. +{
  24821. + VCHIQ_SERVICE_T *service = NULL;
  24822. + if ((unsigned int)localport <= VCHIQ_PORT_MAX) {
  24823. + spin_lock(&service_spinlock);
  24824. + service = state->services[localport];
  24825. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE)) {
  24826. + BUG_ON(service->ref_count == 0);
  24827. + service->ref_count++;
  24828. + } else
  24829. + service = NULL;
  24830. + spin_unlock(&service_spinlock);
  24831. + }
  24832. +
  24833. + if (!service)
  24834. + vchiq_log_info(vchiq_core_log_level,
  24835. + "Invalid port %d", localport);
  24836. +
  24837. + return service;
  24838. +}
  24839. +
  24840. +VCHIQ_SERVICE_T *
  24841. +find_service_for_instance(VCHIQ_INSTANCE_T instance,
  24842. + VCHIQ_SERVICE_HANDLE_T handle) {
  24843. + VCHIQ_SERVICE_T *service;
  24844. +
  24845. + spin_lock(&service_spinlock);
  24846. + service = handle_to_service(handle);
  24847. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  24848. + (service->handle == handle) &&
  24849. + (service->instance == instance)) {
  24850. + BUG_ON(service->ref_count == 0);
  24851. + service->ref_count++;
  24852. + } else
  24853. + service = NULL;
  24854. + spin_unlock(&service_spinlock);
  24855. +
  24856. + if (!service)
  24857. + vchiq_log_info(vchiq_core_log_level,
  24858. + "Invalid service handle 0x%x", handle);
  24859. +
  24860. + return service;
  24861. +}
  24862. +
  24863. +VCHIQ_SERVICE_T *
  24864. +next_service_by_instance(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance,
  24865. + int *pidx)
  24866. +{
  24867. + VCHIQ_SERVICE_T *service = NULL;
  24868. + int idx = *pidx;
  24869. +
  24870. + spin_lock(&service_spinlock);
  24871. + while (idx < state->unused_service) {
  24872. + VCHIQ_SERVICE_T *srv = state->services[idx++];
  24873. + if (srv && (srv->srvstate != VCHIQ_SRVSTATE_FREE) &&
  24874. + (srv->instance == instance)) {
  24875. + service = srv;
  24876. + BUG_ON(service->ref_count == 0);
  24877. + service->ref_count++;
  24878. + break;
  24879. + }
  24880. + }
  24881. + spin_unlock(&service_spinlock);
  24882. +
  24883. + *pidx = idx;
  24884. +
  24885. + return service;
  24886. +}
  24887. +
  24888. +void
  24889. +lock_service(VCHIQ_SERVICE_T *service)
  24890. +{
  24891. + spin_lock(&service_spinlock);
  24892. + BUG_ON(!service || (service->ref_count == 0));
  24893. + if (service)
  24894. + service->ref_count++;
  24895. + spin_unlock(&service_spinlock);
  24896. +}
  24897. +
  24898. +void
  24899. +unlock_service(VCHIQ_SERVICE_T *service)
  24900. +{
  24901. + VCHIQ_STATE_T *state = service->state;
  24902. + spin_lock(&service_spinlock);
  24903. + BUG_ON(!service || (service->ref_count == 0));
  24904. + if (service && service->ref_count) {
  24905. + service->ref_count--;
  24906. + if (!service->ref_count) {
  24907. + BUG_ON(service->srvstate != VCHIQ_SRVSTATE_FREE);
  24908. + state->services[service->localport] = NULL;
  24909. + } else
  24910. + service = NULL;
  24911. + }
  24912. + spin_unlock(&service_spinlock);
  24913. +
  24914. + if (service && service->userdata_term)
  24915. + service->userdata_term(service->base.userdata);
  24916. +
  24917. + kfree(service);
  24918. +}
  24919. +
  24920. +int
  24921. +vchiq_get_client_id(VCHIQ_SERVICE_HANDLE_T handle)
  24922. +{
  24923. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  24924. + int id;
  24925. +
  24926. + id = service ? service->client_id : 0;
  24927. + if (service)
  24928. + unlock_service(service);
  24929. +
  24930. + return id;
  24931. +}
  24932. +
  24933. +void *
  24934. +vchiq_get_service_userdata(VCHIQ_SERVICE_HANDLE_T handle)
  24935. +{
  24936. + VCHIQ_SERVICE_T *service = handle_to_service(handle);
  24937. +
  24938. + return service ? service->base.userdata : NULL;
  24939. +}
  24940. +
  24941. +int
  24942. +vchiq_get_service_fourcc(VCHIQ_SERVICE_HANDLE_T handle)
  24943. +{
  24944. + VCHIQ_SERVICE_T *service = handle_to_service(handle);
  24945. +
  24946. + return service ? service->base.fourcc : 0;
  24947. +}
  24948. +
  24949. +static void
  24950. +mark_service_closing_internal(VCHIQ_SERVICE_T *service, int sh_thread)
  24951. +{
  24952. + VCHIQ_STATE_T *state = service->state;
  24953. + VCHIQ_SERVICE_QUOTA_T *service_quota;
  24954. +
  24955. + service->closing = 1;
  24956. +
  24957. + /* Synchronise with other threads. */
  24958. + mutex_lock(&state->recycle_mutex);
  24959. + mutex_unlock(&state->recycle_mutex);
  24960. + if (!sh_thread || (state->conn_state != VCHIQ_CONNSTATE_PAUSE_SENT)) {
  24961. + /* If we're pausing then the slot_mutex is held until resume
  24962. + * by the slot handler. Therefore don't try to acquire this
  24963. + * mutex if we're the slot handler and in the pause sent state.
  24964. + * We don't need to in this case anyway. */
  24965. + mutex_lock(&state->slot_mutex);
  24966. + mutex_unlock(&state->slot_mutex);
  24967. + }
  24968. +
  24969. + /* Unblock any sending thread. */
  24970. + service_quota = &state->service_quotas[service->localport];
  24971. + up(&service_quota->quota_event);
  24972. +}
  24973. +
  24974. +static void
  24975. +mark_service_closing(VCHIQ_SERVICE_T *service)
  24976. +{
  24977. + mark_service_closing_internal(service, 0);
  24978. +}
  24979. +
  24980. +static inline VCHIQ_STATUS_T
  24981. +make_service_callback(VCHIQ_SERVICE_T *service, VCHIQ_REASON_T reason,
  24982. + VCHIQ_HEADER_T *header, void *bulk_userdata)
  24983. +{
  24984. + VCHIQ_STATUS_T status;
  24985. + vchiq_log_trace(vchiq_core_log_level, "%d: callback:%d (%s, %x, %x)",
  24986. + service->state->id, service->localport, reason_names[reason],
  24987. + (unsigned int)header, (unsigned int)bulk_userdata);
  24988. + status = service->base.callback(reason, header, service->handle,
  24989. + bulk_userdata);
  24990. + if (status == VCHIQ_ERROR) {
  24991. + vchiq_log_warning(vchiq_core_log_level,
  24992. + "%d: ignoring ERROR from callback to service %x",
  24993. + service->state->id, service->handle);
  24994. + status = VCHIQ_SUCCESS;
  24995. + }
  24996. + return status;
  24997. +}
  24998. +
  24999. +inline void
  25000. +vchiq_set_conn_state(VCHIQ_STATE_T *state, VCHIQ_CONNSTATE_T newstate)
  25001. +{
  25002. + VCHIQ_CONNSTATE_T oldstate = state->conn_state;
  25003. + vchiq_log_info(vchiq_core_log_level, "%d: %s->%s", state->id,
  25004. + conn_state_names[oldstate],
  25005. + conn_state_names[newstate]);
  25006. + state->conn_state = newstate;
  25007. + vchiq_platform_conn_state_changed(state, oldstate, newstate);
  25008. +}
  25009. +
  25010. +static inline void
  25011. +remote_event_create(REMOTE_EVENT_T *event)
  25012. +{
  25013. + event->armed = 0;
  25014. + /* Don't clear the 'fired' flag because it may already have been set
  25015. + ** by the other side. */
  25016. + sema_init(event->event, 0);
  25017. +}
  25018. +
  25019. +static inline void
  25020. +remote_event_destroy(REMOTE_EVENT_T *event)
  25021. +{
  25022. + (void)event;
  25023. +}
  25024. +
  25025. +static inline int
  25026. +remote_event_wait(REMOTE_EVENT_T *event)
  25027. +{
  25028. + if (!event->fired) {
  25029. + event->armed = 1;
  25030. + dsb();
  25031. + if (!event->fired) {
  25032. + if (down_interruptible(event->event) != 0) {
  25033. + event->armed = 0;
  25034. + return 0;
  25035. + }
  25036. + }
  25037. + event->armed = 0;
  25038. + wmb();
  25039. + }
  25040. +
  25041. + event->fired = 0;
  25042. + return 1;
  25043. +}
  25044. +
  25045. +static inline void
  25046. +remote_event_signal_local(REMOTE_EVENT_T *event)
  25047. +{
  25048. + event->armed = 0;
  25049. + up(event->event);
  25050. +}
  25051. +
  25052. +static inline void
  25053. +remote_event_poll(REMOTE_EVENT_T *event)
  25054. +{
  25055. + if (event->fired && event->armed)
  25056. + remote_event_signal_local(event);
  25057. +}
  25058. +
  25059. +void
  25060. +remote_event_pollall(VCHIQ_STATE_T *state)
  25061. +{
  25062. + remote_event_poll(&state->local->sync_trigger);
  25063. + remote_event_poll(&state->local->sync_release);
  25064. + remote_event_poll(&state->local->trigger);
  25065. + remote_event_poll(&state->local->recycle);
  25066. +}
  25067. +
  25068. +/* Round up message sizes so that any space at the end of a slot is always big
  25069. +** enough for a header. This relies on header size being a power of two, which
  25070. +** has been verified earlier by a static assertion. */
  25071. +
  25072. +static inline unsigned int
  25073. +calc_stride(unsigned int size)
  25074. +{
  25075. + /* Allow room for the header */
  25076. + size += sizeof(VCHIQ_HEADER_T);
  25077. +
  25078. + /* Round up */
  25079. + return (size + sizeof(VCHIQ_HEADER_T) - 1) & ~(sizeof(VCHIQ_HEADER_T)
  25080. + - 1);
  25081. +}
  25082. +
  25083. +/* Called by the slot handler thread */
  25084. +static VCHIQ_SERVICE_T *
  25085. +get_listening_service(VCHIQ_STATE_T *state, int fourcc)
  25086. +{
  25087. + int i;
  25088. +
  25089. + WARN_ON(fourcc == VCHIQ_FOURCC_INVALID);
  25090. +
  25091. + for (i = 0; i < state->unused_service; i++) {
  25092. + VCHIQ_SERVICE_T *service = state->services[i];
  25093. + if (service &&
  25094. + (service->public_fourcc == fourcc) &&
  25095. + ((service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  25096. + ((service->srvstate == VCHIQ_SRVSTATE_OPEN) &&
  25097. + (service->remoteport == VCHIQ_PORT_FREE)))) {
  25098. + lock_service(service);
  25099. + return service;
  25100. + }
  25101. + }
  25102. +
  25103. + return NULL;
  25104. +}
  25105. +
  25106. +/* Called by the slot handler thread */
  25107. +static VCHIQ_SERVICE_T *
  25108. +get_connected_service(VCHIQ_STATE_T *state, unsigned int port)
  25109. +{
  25110. + int i;
  25111. + for (i = 0; i < state->unused_service; i++) {
  25112. + VCHIQ_SERVICE_T *service = state->services[i];
  25113. + if (service && (service->srvstate == VCHIQ_SRVSTATE_OPEN)
  25114. + && (service->remoteport == port)) {
  25115. + lock_service(service);
  25116. + return service;
  25117. + }
  25118. + }
  25119. + return NULL;
  25120. +}
  25121. +
  25122. +inline void
  25123. +request_poll(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service, int poll_type)
  25124. +{
  25125. + uint32_t value;
  25126. +
  25127. + if (service) {
  25128. + do {
  25129. + value = atomic_read(&service->poll_flags);
  25130. + } while (atomic_cmpxchg(&service->poll_flags, value,
  25131. + value | (1 << poll_type)) != value);
  25132. +
  25133. + do {
  25134. + value = atomic_read(&state->poll_services[
  25135. + service->localport>>5]);
  25136. + } while (atomic_cmpxchg(
  25137. + &state->poll_services[service->localport>>5],
  25138. + value, value | (1 << (service->localport & 0x1f)))
  25139. + != value);
  25140. + }
  25141. +
  25142. + state->poll_needed = 1;
  25143. + wmb();
  25144. +
  25145. + /* ... and ensure the slot handler runs. */
  25146. + remote_event_signal_local(&state->local->trigger);
  25147. +}
  25148. +
  25149. +/* Called from queue_message, by the slot handler and application threads,
  25150. +** with slot_mutex held */
  25151. +static VCHIQ_HEADER_T *
  25152. +reserve_space(VCHIQ_STATE_T *state, int space, int is_blocking)
  25153. +{
  25154. + VCHIQ_SHARED_STATE_T *local = state->local;
  25155. + int tx_pos = state->local_tx_pos;
  25156. + int slot_space = VCHIQ_SLOT_SIZE - (tx_pos & VCHIQ_SLOT_MASK);
  25157. +
  25158. + if (space > slot_space) {
  25159. + VCHIQ_HEADER_T *header;
  25160. + /* Fill the remaining space with padding */
  25161. + WARN_ON(state->tx_data == NULL);
  25162. + header = (VCHIQ_HEADER_T *)
  25163. + (state->tx_data + (tx_pos & VCHIQ_SLOT_MASK));
  25164. + header->msgid = VCHIQ_MSGID_PADDING;
  25165. + header->size = slot_space - sizeof(VCHIQ_HEADER_T);
  25166. +
  25167. + tx_pos += slot_space;
  25168. + }
  25169. +
  25170. + /* If necessary, get the next slot. */
  25171. + if ((tx_pos & VCHIQ_SLOT_MASK) == 0) {
  25172. + int slot_index;
  25173. +
  25174. + /* If there is no free slot... */
  25175. +
  25176. + if (down_trylock(&state->slot_available_event) != 0) {
  25177. + /* ...wait for one. */
  25178. +
  25179. + VCHIQ_STATS_INC(state, slot_stalls);
  25180. +
  25181. + /* But first, flush through the last slot. */
  25182. + state->local_tx_pos = tx_pos;
  25183. + local->tx_pos = tx_pos;
  25184. + remote_event_signal(&state->remote->trigger);
  25185. +
  25186. + if (!is_blocking ||
  25187. + (down_interruptible(
  25188. + &state->slot_available_event) != 0))
  25189. + return NULL; /* No space available */
  25190. + }
  25191. +
  25192. + BUG_ON(tx_pos ==
  25193. + (state->slot_queue_available * VCHIQ_SLOT_SIZE));
  25194. +
  25195. + slot_index = local->slot_queue[
  25196. + SLOT_QUEUE_INDEX_FROM_POS(tx_pos) &
  25197. + VCHIQ_SLOT_QUEUE_MASK];
  25198. + state->tx_data =
  25199. + (char *)SLOT_DATA_FROM_INDEX(state, slot_index);
  25200. + }
  25201. +
  25202. + state->local_tx_pos = tx_pos + space;
  25203. +
  25204. + return (VCHIQ_HEADER_T *)(state->tx_data + (tx_pos & VCHIQ_SLOT_MASK));
  25205. +}
  25206. +
  25207. +/* Called by the recycle thread. */
  25208. +static void
  25209. +process_free_queue(VCHIQ_STATE_T *state)
  25210. +{
  25211. + VCHIQ_SHARED_STATE_T *local = state->local;
  25212. + BITSET_T service_found[BITSET_SIZE(VCHIQ_MAX_SERVICES)];
  25213. + int slot_queue_available;
  25214. +
  25215. + /* Use a read memory barrier to ensure that any state that may have
  25216. + ** been modified by another thread is not masked by stale prefetched
  25217. + ** values. */
  25218. + rmb();
  25219. +
  25220. + /* Find slots which have been freed by the other side, and return them
  25221. + ** to the available queue. */
  25222. + slot_queue_available = state->slot_queue_available;
  25223. +
  25224. + while (slot_queue_available != local->slot_queue_recycle) {
  25225. + unsigned int pos;
  25226. + int slot_index = local->slot_queue[slot_queue_available++ &
  25227. + VCHIQ_SLOT_QUEUE_MASK];
  25228. + char *data = (char *)SLOT_DATA_FROM_INDEX(state, slot_index);
  25229. + int data_found = 0;
  25230. +
  25231. + vchiq_log_trace(vchiq_core_log_level, "%d: pfq %d=%x %x %x",
  25232. + state->id, slot_index, (unsigned int)data,
  25233. + local->slot_queue_recycle, slot_queue_available);
  25234. +
  25235. + /* Initialise the bitmask for services which have used this
  25236. + ** slot */
  25237. + BITSET_ZERO(service_found);
  25238. +
  25239. + pos = 0;
  25240. +
  25241. + while (pos < VCHIQ_SLOT_SIZE) {
  25242. + VCHIQ_HEADER_T *header =
  25243. + (VCHIQ_HEADER_T *)(data + pos);
  25244. + int msgid = header->msgid;
  25245. + if (VCHIQ_MSG_TYPE(msgid) == VCHIQ_MSG_DATA) {
  25246. + int port = VCHIQ_MSG_SRCPORT(msgid);
  25247. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  25248. + &state->service_quotas[port];
  25249. + int count;
  25250. + spin_lock(&quota_spinlock);
  25251. + count = service_quota->message_use_count;
  25252. + if (count > 0)
  25253. + service_quota->message_use_count =
  25254. + count - 1;
  25255. + spin_unlock(&quota_spinlock);
  25256. +
  25257. + if (count == service_quota->message_quota)
  25258. + /* Signal the service that it
  25259. + ** has dropped below its quota
  25260. + */
  25261. + up(&service_quota->quota_event);
  25262. + else if (count == 0) {
  25263. + vchiq_log_error(vchiq_core_log_level,
  25264. + "service %d "
  25265. + "message_use_count=%d "
  25266. + "(header %x, msgid %x, "
  25267. + "header->msgid %x, "
  25268. + "header->size %x)",
  25269. + port,
  25270. + service_quota->
  25271. + message_use_count,
  25272. + (unsigned int)header, msgid,
  25273. + header->msgid,
  25274. + header->size);
  25275. + WARN(1, "invalid message use count\n");
  25276. + }
  25277. + if (!BITSET_IS_SET(service_found, port)) {
  25278. + /* Set the found bit for this service */
  25279. + BITSET_SET(service_found, port);
  25280. +
  25281. + spin_lock(&quota_spinlock);
  25282. + count = service_quota->slot_use_count;
  25283. + if (count > 0)
  25284. + service_quota->slot_use_count =
  25285. + count - 1;
  25286. + spin_unlock(&quota_spinlock);
  25287. +
  25288. + if (count > 0) {
  25289. + /* Signal the service in case
  25290. + ** it has dropped below its
  25291. + ** quota */
  25292. + up(&service_quota->quota_event);
  25293. + vchiq_log_trace(
  25294. + vchiq_core_log_level,
  25295. + "%d: pfq:%d %x@%x - "
  25296. + "slot_use->%d",
  25297. + state->id, port,
  25298. + header->size,
  25299. + (unsigned int)header,
  25300. + count - 1);
  25301. + } else {
  25302. + vchiq_log_error(
  25303. + vchiq_core_log_level,
  25304. + "service %d "
  25305. + "slot_use_count"
  25306. + "=%d (header %x"
  25307. + ", msgid %x, "
  25308. + "header->msgid"
  25309. + " %x, header->"
  25310. + "size %x)",
  25311. + port, count,
  25312. + (unsigned int)header,
  25313. + msgid,
  25314. + header->msgid,
  25315. + header->size);
  25316. + WARN(1, "bad slot use count\n");
  25317. + }
  25318. + }
  25319. +
  25320. + data_found = 1;
  25321. + }
  25322. +
  25323. + pos += calc_stride(header->size);
  25324. + if (pos > VCHIQ_SLOT_SIZE) {
  25325. + vchiq_log_error(vchiq_core_log_level,
  25326. + "pfq - pos %x: header %x, msgid %x, "
  25327. + "header->msgid %x, header->size %x",
  25328. + pos, (unsigned int)header, msgid,
  25329. + header->msgid, header->size);
  25330. + WARN(1, "invalid slot position\n");
  25331. + }
  25332. + }
  25333. +
  25334. + if (data_found) {
  25335. + int count;
  25336. + spin_lock(&quota_spinlock);
  25337. + count = state->data_use_count;
  25338. + if (count > 0)
  25339. + state->data_use_count =
  25340. + count - 1;
  25341. + spin_unlock(&quota_spinlock);
  25342. + if (count == state->data_quota)
  25343. + up(&state->data_quota_event);
  25344. + }
  25345. +
  25346. + state->slot_queue_available = slot_queue_available;
  25347. + up(&state->slot_available_event);
  25348. + }
  25349. +}
  25350. +
  25351. +/* Called by the slot handler and application threads */
  25352. +static VCHIQ_STATUS_T
  25353. +queue_message(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  25354. + int msgid, const VCHIQ_ELEMENT_T *elements,
  25355. + int count, int size, int is_blocking)
  25356. +{
  25357. + VCHIQ_SHARED_STATE_T *local;
  25358. + VCHIQ_SERVICE_QUOTA_T *service_quota = NULL;
  25359. + VCHIQ_HEADER_T *header;
  25360. + int type = VCHIQ_MSG_TYPE(msgid);
  25361. +
  25362. + unsigned int stride;
  25363. +
  25364. + local = state->local;
  25365. +
  25366. + stride = calc_stride(size);
  25367. +
  25368. + WARN_ON(!(stride <= VCHIQ_SLOT_SIZE));
  25369. +
  25370. + if ((type != VCHIQ_MSG_RESUME) &&
  25371. + (mutex_lock_interruptible(&state->slot_mutex) != 0))
  25372. + return VCHIQ_RETRY;
  25373. +
  25374. + if (type == VCHIQ_MSG_DATA) {
  25375. + int tx_end_index;
  25376. +
  25377. + BUG_ON(!service);
  25378. +
  25379. + if (service->closing) {
  25380. + /* The service has been closed */
  25381. + mutex_unlock(&state->slot_mutex);
  25382. + return VCHIQ_ERROR;
  25383. + }
  25384. +
  25385. + service_quota = &state->service_quotas[service->localport];
  25386. +
  25387. + spin_lock(&quota_spinlock);
  25388. +
  25389. + /* Ensure this service doesn't use more than its quota of
  25390. + ** messages or slots */
  25391. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  25392. + state->local_tx_pos + stride - 1);
  25393. +
  25394. + /* Ensure data messages don't use more than their quota of
  25395. + ** slots */
  25396. + while ((tx_end_index != state->previous_data_index) &&
  25397. + (state->data_use_count == state->data_quota)) {
  25398. + VCHIQ_STATS_INC(state, data_stalls);
  25399. + spin_unlock(&quota_spinlock);
  25400. + mutex_unlock(&state->slot_mutex);
  25401. +
  25402. + if (down_interruptible(&state->data_quota_event)
  25403. + != 0)
  25404. + return VCHIQ_RETRY;
  25405. +
  25406. + mutex_lock(&state->slot_mutex);
  25407. + spin_lock(&quota_spinlock);
  25408. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  25409. + state->local_tx_pos + stride - 1);
  25410. + if ((tx_end_index == state->previous_data_index) ||
  25411. + (state->data_use_count < state->data_quota)) {
  25412. + /* Pass the signal on to other waiters */
  25413. + up(&state->data_quota_event);
  25414. + break;
  25415. + }
  25416. + }
  25417. +
  25418. + while ((service_quota->message_use_count ==
  25419. + service_quota->message_quota) ||
  25420. + ((tx_end_index != service_quota->previous_tx_index) &&
  25421. + (service_quota->slot_use_count ==
  25422. + service_quota->slot_quota))) {
  25423. + spin_unlock(&quota_spinlock);
  25424. + vchiq_log_trace(vchiq_core_log_level,
  25425. + "%d: qm:%d %s,%x - quota stall "
  25426. + "(msg %d, slot %d)",
  25427. + state->id, service->localport,
  25428. + msg_type_str(type), size,
  25429. + service_quota->message_use_count,
  25430. + service_quota->slot_use_count);
  25431. + VCHIQ_SERVICE_STATS_INC(service, quota_stalls);
  25432. + mutex_unlock(&state->slot_mutex);
  25433. + if (down_interruptible(&service_quota->quota_event)
  25434. + != 0)
  25435. + return VCHIQ_RETRY;
  25436. + if (service->closing)
  25437. + return VCHIQ_ERROR;
  25438. + if (mutex_lock_interruptible(&state->slot_mutex) != 0)
  25439. + return VCHIQ_RETRY;
  25440. + if (service->srvstate != VCHIQ_SRVSTATE_OPEN) {
  25441. + /* The service has been closed */
  25442. + mutex_unlock(&state->slot_mutex);
  25443. + return VCHIQ_ERROR;
  25444. + }
  25445. + spin_lock(&quota_spinlock);
  25446. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  25447. + state->local_tx_pos + stride - 1);
  25448. + }
  25449. +
  25450. + spin_unlock(&quota_spinlock);
  25451. + }
  25452. +
  25453. + header = reserve_space(state, stride, is_blocking);
  25454. +
  25455. + if (!header) {
  25456. + if (service)
  25457. + VCHIQ_SERVICE_STATS_INC(service, slot_stalls);
  25458. + mutex_unlock(&state->slot_mutex);
  25459. + return VCHIQ_RETRY;
  25460. + }
  25461. +
  25462. + if (type == VCHIQ_MSG_DATA) {
  25463. + int i, pos;
  25464. + int tx_end_index;
  25465. + int slot_use_count;
  25466. +
  25467. + vchiq_log_info(vchiq_core_log_level,
  25468. + "%d: qm %s@%x,%x (%d->%d)",
  25469. + state->id,
  25470. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  25471. + (unsigned int)header, size,
  25472. + VCHIQ_MSG_SRCPORT(msgid),
  25473. + VCHIQ_MSG_DSTPORT(msgid));
  25474. +
  25475. + BUG_ON(!service);
  25476. +
  25477. + for (i = 0, pos = 0; i < (unsigned int)count;
  25478. + pos += elements[i++].size)
  25479. + if (elements[i].size) {
  25480. + if (vchiq_copy_from_user
  25481. + (header->data + pos, elements[i].data,
  25482. + (size_t) elements[i].size) !=
  25483. + VCHIQ_SUCCESS) {
  25484. + mutex_unlock(&state->slot_mutex);
  25485. + VCHIQ_SERVICE_STATS_INC(service,
  25486. + error_count);
  25487. + return VCHIQ_ERROR;
  25488. + }
  25489. + if (i == 0) {
  25490. + if (vchiq_core_msg_log_level >=
  25491. + VCHIQ_LOG_INFO)
  25492. + vchiq_log_dump_mem("Sent", 0,
  25493. + header->data + pos,
  25494. + min(64u,
  25495. + elements[0].size));
  25496. + }
  25497. + }
  25498. +
  25499. + spin_lock(&quota_spinlock);
  25500. + service_quota->message_use_count++;
  25501. +
  25502. + tx_end_index =
  25503. + SLOT_QUEUE_INDEX_FROM_POS(state->local_tx_pos - 1);
  25504. +
  25505. + /* If this transmission can't fit in the last slot used by any
  25506. + ** service, the data_use_count must be increased. */
  25507. + if (tx_end_index != state->previous_data_index) {
  25508. + state->previous_data_index = tx_end_index;
  25509. + state->data_use_count++;
  25510. + }
  25511. +
  25512. + /* If this isn't the same slot last used by this service,
  25513. + ** the service's slot_use_count must be increased. */
  25514. + if (tx_end_index != service_quota->previous_tx_index) {
  25515. + service_quota->previous_tx_index = tx_end_index;
  25516. + slot_use_count = ++service_quota->slot_use_count;
  25517. + } else {
  25518. + slot_use_count = 0;
  25519. + }
  25520. +
  25521. + spin_unlock(&quota_spinlock);
  25522. +
  25523. + if (slot_use_count)
  25524. + vchiq_log_trace(vchiq_core_log_level,
  25525. + "%d: qm:%d %s,%x - slot_use->%d (hdr %p)",
  25526. + state->id, service->localport,
  25527. + msg_type_str(VCHIQ_MSG_TYPE(msgid)), size,
  25528. + slot_use_count, header);
  25529. +
  25530. + VCHIQ_SERVICE_STATS_INC(service, ctrl_tx_count);
  25531. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_tx_bytes, size);
  25532. + } else {
  25533. + vchiq_log_info(vchiq_core_log_level,
  25534. + "%d: qm %s@%x,%x (%d->%d)", state->id,
  25535. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  25536. + (unsigned int)header, size,
  25537. + VCHIQ_MSG_SRCPORT(msgid),
  25538. + VCHIQ_MSG_DSTPORT(msgid));
  25539. + if (size != 0) {
  25540. + WARN_ON(!((count == 1) && (size == elements[0].size)));
  25541. + memcpy(header->data, elements[0].data,
  25542. + elements[0].size);
  25543. + }
  25544. + VCHIQ_STATS_INC(state, ctrl_tx_count);
  25545. + }
  25546. +
  25547. + header->msgid = msgid;
  25548. + header->size = size;
  25549. +
  25550. + {
  25551. + int svc_fourcc;
  25552. +
  25553. + svc_fourcc = service
  25554. + ? service->base.fourcc
  25555. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  25556. +
  25557. + vchiq_log_info(vchiq_core_msg_log_level,
  25558. + "Sent Msg %s(%u) to %c%c%c%c s:%u d:%d len:%d",
  25559. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  25560. + VCHIQ_MSG_TYPE(msgid),
  25561. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  25562. + VCHIQ_MSG_SRCPORT(msgid),
  25563. + VCHIQ_MSG_DSTPORT(msgid),
  25564. + size);
  25565. + }
  25566. +
  25567. + /* Make sure the new header is visible to the peer. */
  25568. + wmb();
  25569. +
  25570. + /* Make the new tx_pos visible to the peer. */
  25571. + local->tx_pos = state->local_tx_pos;
  25572. + wmb();
  25573. +
  25574. + if (service && (type == VCHIQ_MSG_CLOSE))
  25575. + vchiq_set_service_state(service, VCHIQ_SRVSTATE_CLOSESENT);
  25576. +
  25577. + if (VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_PAUSE)
  25578. + mutex_unlock(&state->slot_mutex);
  25579. +
  25580. + remote_event_signal(&state->remote->trigger);
  25581. +
  25582. + return VCHIQ_SUCCESS;
  25583. +}
  25584. +
  25585. +/* Called by the slot handler and application threads */
  25586. +static VCHIQ_STATUS_T
  25587. +queue_message_sync(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  25588. + int msgid, const VCHIQ_ELEMENT_T *elements,
  25589. + int count, int size, int is_blocking)
  25590. +{
  25591. + VCHIQ_SHARED_STATE_T *local;
  25592. + VCHIQ_HEADER_T *header;
  25593. +
  25594. + local = state->local;
  25595. +
  25596. + if ((VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_RESUME) &&
  25597. + (mutex_lock_interruptible(&state->sync_mutex) != 0))
  25598. + return VCHIQ_RETRY;
  25599. +
  25600. + remote_event_wait(&local->sync_release);
  25601. +
  25602. + rmb();
  25603. +
  25604. + header = (VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state,
  25605. + local->slot_sync);
  25606. +
  25607. + {
  25608. + int oldmsgid = header->msgid;
  25609. + if (oldmsgid != VCHIQ_MSGID_PADDING)
  25610. + vchiq_log_error(vchiq_core_log_level,
  25611. + "%d: qms - msgid %x, not PADDING",
  25612. + state->id, oldmsgid);
  25613. + }
  25614. +
  25615. + if (service) {
  25616. + int i, pos;
  25617. +
  25618. + vchiq_log_info(vchiq_sync_log_level,
  25619. + "%d: qms %s@%x,%x (%d->%d)", state->id,
  25620. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  25621. + (unsigned int)header, size,
  25622. + VCHIQ_MSG_SRCPORT(msgid),
  25623. + VCHIQ_MSG_DSTPORT(msgid));
  25624. +
  25625. + for (i = 0, pos = 0; i < (unsigned int)count;
  25626. + pos += elements[i++].size)
  25627. + if (elements[i].size) {
  25628. + if (vchiq_copy_from_user
  25629. + (header->data + pos, elements[i].data,
  25630. + (size_t) elements[i].size) !=
  25631. + VCHIQ_SUCCESS) {
  25632. + mutex_unlock(&state->sync_mutex);
  25633. + VCHIQ_SERVICE_STATS_INC(service,
  25634. + error_count);
  25635. + return VCHIQ_ERROR;
  25636. + }
  25637. + if (i == 0) {
  25638. + if (vchiq_sync_log_level >=
  25639. + VCHIQ_LOG_TRACE)
  25640. + vchiq_log_dump_mem("Sent Sync",
  25641. + 0, header->data + pos,
  25642. + min(64u,
  25643. + elements[0].size));
  25644. + }
  25645. + }
  25646. +
  25647. + VCHIQ_SERVICE_STATS_INC(service, ctrl_tx_count);
  25648. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_tx_bytes, size);
  25649. + } else {
  25650. + vchiq_log_info(vchiq_sync_log_level,
  25651. + "%d: qms %s@%x,%x (%d->%d)", state->id,
  25652. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  25653. + (unsigned int)header, size,
  25654. + VCHIQ_MSG_SRCPORT(msgid),
  25655. + VCHIQ_MSG_DSTPORT(msgid));
  25656. + if (size != 0) {
  25657. + WARN_ON(!((count == 1) && (size == elements[0].size)));
  25658. + memcpy(header->data, elements[0].data,
  25659. + elements[0].size);
  25660. + }
  25661. + VCHIQ_STATS_INC(state, ctrl_tx_count);
  25662. + }
  25663. +
  25664. + header->size = size;
  25665. + header->msgid = msgid;
  25666. +
  25667. + if (vchiq_sync_log_level >= VCHIQ_LOG_TRACE) {
  25668. + int svc_fourcc;
  25669. +
  25670. + svc_fourcc = service
  25671. + ? service->base.fourcc
  25672. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  25673. +
  25674. + vchiq_log_trace(vchiq_sync_log_level,
  25675. + "Sent Sync Msg %s(%u) to %c%c%c%c s:%u d:%d len:%d",
  25676. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  25677. + VCHIQ_MSG_TYPE(msgid),
  25678. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  25679. + VCHIQ_MSG_SRCPORT(msgid),
  25680. + VCHIQ_MSG_DSTPORT(msgid),
  25681. + size);
  25682. + }
  25683. +
  25684. + /* Make sure the new header is visible to the peer. */
  25685. + wmb();
  25686. +
  25687. + remote_event_signal(&state->remote->sync_trigger);
  25688. +
  25689. + if (VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_PAUSE)
  25690. + mutex_unlock(&state->sync_mutex);
  25691. +
  25692. + return VCHIQ_SUCCESS;
  25693. +}
  25694. +
  25695. +static inline void
  25696. +claim_slot(VCHIQ_SLOT_INFO_T *slot)
  25697. +{
  25698. + slot->use_count++;
  25699. +}
  25700. +
  25701. +static void
  25702. +release_slot(VCHIQ_STATE_T *state, VCHIQ_SLOT_INFO_T *slot_info,
  25703. + VCHIQ_HEADER_T *header, VCHIQ_SERVICE_T *service)
  25704. +{
  25705. + int release_count;
  25706. +
  25707. + mutex_lock(&state->recycle_mutex);
  25708. +
  25709. + if (header) {
  25710. + int msgid = header->msgid;
  25711. + if (((msgid & VCHIQ_MSGID_CLAIMED) == 0) ||
  25712. + (service && service->closing)) {
  25713. + mutex_unlock(&state->recycle_mutex);
  25714. + return;
  25715. + }
  25716. +
  25717. + /* Rewrite the message header to prevent a double
  25718. + ** release */
  25719. + header->msgid = msgid & ~VCHIQ_MSGID_CLAIMED;
  25720. + }
  25721. +
  25722. + release_count = slot_info->release_count;
  25723. + slot_info->release_count = ++release_count;
  25724. +
  25725. + if (release_count == slot_info->use_count) {
  25726. + int slot_queue_recycle;
  25727. + /* Add to the freed queue */
  25728. +
  25729. + /* A read barrier is necessary here to prevent speculative
  25730. + ** fetches of remote->slot_queue_recycle from overtaking the
  25731. + ** mutex. */
  25732. + rmb();
  25733. +
  25734. + slot_queue_recycle = state->remote->slot_queue_recycle;
  25735. + state->remote->slot_queue[slot_queue_recycle &
  25736. + VCHIQ_SLOT_QUEUE_MASK] =
  25737. + SLOT_INDEX_FROM_INFO(state, slot_info);
  25738. + state->remote->slot_queue_recycle = slot_queue_recycle + 1;
  25739. + vchiq_log_info(vchiq_core_log_level,
  25740. + "%d: release_slot %d - recycle->%x",
  25741. + state->id, SLOT_INDEX_FROM_INFO(state, slot_info),
  25742. + state->remote->slot_queue_recycle);
  25743. +
  25744. + /* A write barrier is necessary, but remote_event_signal
  25745. + ** contains one. */
  25746. + remote_event_signal(&state->remote->recycle);
  25747. + }
  25748. +
  25749. + mutex_unlock(&state->recycle_mutex);
  25750. +}
  25751. +
  25752. +/* Called by the slot handler - don't hold the bulk mutex */
  25753. +static VCHIQ_STATUS_T
  25754. +notify_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue,
  25755. + int retry_poll)
  25756. +{
  25757. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  25758. +
  25759. + vchiq_log_trace(vchiq_core_log_level,
  25760. + "%d: nb:%d %cx - p=%x rn=%x r=%x",
  25761. + service->state->id, service->localport,
  25762. + (queue == &service->bulk_tx) ? 't' : 'r',
  25763. + queue->process, queue->remote_notify, queue->remove);
  25764. +
  25765. + if (service->state->is_master) {
  25766. + while (queue->remote_notify != queue->process) {
  25767. + VCHIQ_BULK_T *bulk =
  25768. + &queue->bulks[BULK_INDEX(queue->remote_notify)];
  25769. + int msgtype = (bulk->dir == VCHIQ_BULK_TRANSMIT) ?
  25770. + VCHIQ_MSG_BULK_RX_DONE : VCHIQ_MSG_BULK_TX_DONE;
  25771. + int msgid = VCHIQ_MAKE_MSG(msgtype, service->localport,
  25772. + service->remoteport);
  25773. + VCHIQ_ELEMENT_T element = { &bulk->actual, 4 };
  25774. + /* Only reply to non-dummy bulk requests */
  25775. + if (bulk->remote_data) {
  25776. + status = queue_message(service->state, NULL,
  25777. + msgid, &element, 1, 4, 0);
  25778. + if (status != VCHIQ_SUCCESS)
  25779. + break;
  25780. + }
  25781. + queue->remote_notify++;
  25782. + }
  25783. + } else {
  25784. + queue->remote_notify = queue->process;
  25785. + }
  25786. +
  25787. + if (status == VCHIQ_SUCCESS) {
  25788. + while (queue->remove != queue->remote_notify) {
  25789. + VCHIQ_BULK_T *bulk =
  25790. + &queue->bulks[BULK_INDEX(queue->remove)];
  25791. +
  25792. + /* Only generate callbacks for non-dummy bulk
  25793. + ** requests, and non-terminated services */
  25794. + if (bulk->data && service->instance) {
  25795. + if (bulk->actual != VCHIQ_BULK_ACTUAL_ABORTED) {
  25796. + if (bulk->dir == VCHIQ_BULK_TRANSMIT) {
  25797. + VCHIQ_SERVICE_STATS_INC(service,
  25798. + bulk_tx_count);
  25799. + VCHIQ_SERVICE_STATS_ADD(service,
  25800. + bulk_tx_bytes,
  25801. + bulk->actual);
  25802. + } else {
  25803. + VCHIQ_SERVICE_STATS_INC(service,
  25804. + bulk_rx_count);
  25805. + VCHIQ_SERVICE_STATS_ADD(service,
  25806. + bulk_rx_bytes,
  25807. + bulk->actual);
  25808. + }
  25809. + } else {
  25810. + VCHIQ_SERVICE_STATS_INC(service,
  25811. + bulk_aborted_count);
  25812. + }
  25813. + if (bulk->mode == VCHIQ_BULK_MODE_BLOCKING) {
  25814. + struct bulk_waiter *waiter;
  25815. + spin_lock(&bulk_waiter_spinlock);
  25816. + waiter = bulk->userdata;
  25817. + if (waiter) {
  25818. + waiter->actual = bulk->actual;
  25819. + up(&waiter->event);
  25820. + }
  25821. + spin_unlock(&bulk_waiter_spinlock);
  25822. + } else if (bulk->mode ==
  25823. + VCHIQ_BULK_MODE_CALLBACK) {
  25824. + VCHIQ_REASON_T reason = (bulk->dir ==
  25825. + VCHIQ_BULK_TRANSMIT) ?
  25826. + ((bulk->actual ==
  25827. + VCHIQ_BULK_ACTUAL_ABORTED) ?
  25828. + VCHIQ_BULK_TRANSMIT_ABORTED :
  25829. + VCHIQ_BULK_TRANSMIT_DONE) :
  25830. + ((bulk->actual ==
  25831. + VCHIQ_BULK_ACTUAL_ABORTED) ?
  25832. + VCHIQ_BULK_RECEIVE_ABORTED :
  25833. + VCHIQ_BULK_RECEIVE_DONE);
  25834. + status = make_service_callback(service,
  25835. + reason, NULL, bulk->userdata);
  25836. + if (status == VCHIQ_RETRY)
  25837. + break;
  25838. + }
  25839. + }
  25840. +
  25841. + queue->remove++;
  25842. + up(&service->bulk_remove_event);
  25843. + }
  25844. + if (!retry_poll)
  25845. + status = VCHIQ_SUCCESS;
  25846. + }
  25847. +
  25848. + if (status == VCHIQ_RETRY)
  25849. + request_poll(service->state, service,
  25850. + (queue == &service->bulk_tx) ?
  25851. + VCHIQ_POLL_TXNOTIFY : VCHIQ_POLL_RXNOTIFY);
  25852. +
  25853. + return status;
  25854. +}
  25855. +
  25856. +/* Called by the slot handler thread */
  25857. +static void
  25858. +poll_services(VCHIQ_STATE_T *state)
  25859. +{
  25860. + int group, i;
  25861. +
  25862. + for (group = 0; group < BITSET_SIZE(state->unused_service); group++) {
  25863. + uint32_t flags;
  25864. + flags = atomic_xchg(&state->poll_services[group], 0);
  25865. + for (i = 0; flags; i++) {
  25866. + if (flags & (1 << i)) {
  25867. + VCHIQ_SERVICE_T *service =
  25868. + find_service_by_port(state,
  25869. + (group<<5) + i);
  25870. + uint32_t service_flags;
  25871. + flags &= ~(1 << i);
  25872. + if (!service)
  25873. + continue;
  25874. + service_flags =
  25875. + atomic_xchg(&service->poll_flags, 0);
  25876. + if (service_flags &
  25877. + (1 << VCHIQ_POLL_REMOVE)) {
  25878. + vchiq_log_info(vchiq_core_log_level,
  25879. + "%d: ps - remove %d<->%d",
  25880. + state->id, service->localport,
  25881. + service->remoteport);
  25882. +
  25883. + /* Make it look like a client, because
  25884. + it must be removed and not left in
  25885. + the LISTENING state. */
  25886. + service->public_fourcc =
  25887. + VCHIQ_FOURCC_INVALID;
  25888. +
  25889. + if (vchiq_close_service_internal(
  25890. + service, 0/*!close_recvd*/) !=
  25891. + VCHIQ_SUCCESS)
  25892. + request_poll(state, service,
  25893. + VCHIQ_POLL_REMOVE);
  25894. + } else if (service_flags &
  25895. + (1 << VCHIQ_POLL_TERMINATE)) {
  25896. + vchiq_log_info(vchiq_core_log_level,
  25897. + "%d: ps - terminate %d<->%d",
  25898. + state->id, service->localport,
  25899. + service->remoteport);
  25900. + if (vchiq_close_service_internal(
  25901. + service, 0/*!close_recvd*/) !=
  25902. + VCHIQ_SUCCESS)
  25903. + request_poll(state, service,
  25904. + VCHIQ_POLL_TERMINATE);
  25905. + }
  25906. + if (service_flags & (1 << VCHIQ_POLL_TXNOTIFY))
  25907. + notify_bulks(service,
  25908. + &service->bulk_tx,
  25909. + 1/*retry_poll*/);
  25910. + if (service_flags & (1 << VCHIQ_POLL_RXNOTIFY))
  25911. + notify_bulks(service,
  25912. + &service->bulk_rx,
  25913. + 1/*retry_poll*/);
  25914. + unlock_service(service);
  25915. + }
  25916. + }
  25917. + }
  25918. +}
  25919. +
  25920. +/* Called by the slot handler or application threads, holding the bulk mutex. */
  25921. +static int
  25922. +resolve_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue)
  25923. +{
  25924. + VCHIQ_STATE_T *state = service->state;
  25925. + int resolved = 0;
  25926. + int rc;
  25927. +
  25928. + while ((queue->process != queue->local_insert) &&
  25929. + (queue->process != queue->remote_insert)) {
  25930. + VCHIQ_BULK_T *bulk = &queue->bulks[BULK_INDEX(queue->process)];
  25931. +
  25932. + vchiq_log_trace(vchiq_core_log_level,
  25933. + "%d: rb:%d %cx - li=%x ri=%x p=%x",
  25934. + state->id, service->localport,
  25935. + (queue == &service->bulk_tx) ? 't' : 'r',
  25936. + queue->local_insert, queue->remote_insert,
  25937. + queue->process);
  25938. +
  25939. + WARN_ON(!((int)(queue->local_insert - queue->process) > 0));
  25940. + WARN_ON(!((int)(queue->remote_insert - queue->process) > 0));
  25941. +
  25942. + rc = mutex_lock_interruptible(&state->bulk_transfer_mutex);
  25943. + if (rc != 0)
  25944. + break;
  25945. +
  25946. + vchiq_transfer_bulk(bulk);
  25947. + mutex_unlock(&state->bulk_transfer_mutex);
  25948. +
  25949. + if (vchiq_core_msg_log_level >= VCHIQ_LOG_INFO) {
  25950. + const char *header = (queue == &service->bulk_tx) ?
  25951. + "Send Bulk to" : "Recv Bulk from";
  25952. + if (bulk->actual != VCHIQ_BULK_ACTUAL_ABORTED)
  25953. + vchiq_log_info(vchiq_core_msg_log_level,
  25954. + "%s %c%c%c%c d:%d len:%d %x<->%x",
  25955. + header,
  25956. + VCHIQ_FOURCC_AS_4CHARS(
  25957. + service->base.fourcc),
  25958. + service->remoteport,
  25959. + bulk->size,
  25960. + (unsigned int)bulk->data,
  25961. + (unsigned int)bulk->remote_data);
  25962. + else
  25963. + vchiq_log_info(vchiq_core_msg_log_level,
  25964. + "%s %c%c%c%c d:%d ABORTED - tx len:%d,"
  25965. + " rx len:%d %x<->%x",
  25966. + header,
  25967. + VCHIQ_FOURCC_AS_4CHARS(
  25968. + service->base.fourcc),
  25969. + service->remoteport,
  25970. + bulk->size,
  25971. + bulk->remote_size,
  25972. + (unsigned int)bulk->data,
  25973. + (unsigned int)bulk->remote_data);
  25974. + }
  25975. +
  25976. + vchiq_complete_bulk(bulk);
  25977. + queue->process++;
  25978. + resolved++;
  25979. + }
  25980. + return resolved;
  25981. +}
  25982. +
  25983. +/* Called with the bulk_mutex held */
  25984. +static void
  25985. +abort_outstanding_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue)
  25986. +{
  25987. + int is_tx = (queue == &service->bulk_tx);
  25988. + vchiq_log_trace(vchiq_core_log_level,
  25989. + "%d: aob:%d %cx - li=%x ri=%x p=%x",
  25990. + service->state->id, service->localport, is_tx ? 't' : 'r',
  25991. + queue->local_insert, queue->remote_insert, queue->process);
  25992. +
  25993. + WARN_ON(!((int)(queue->local_insert - queue->process) >= 0));
  25994. + WARN_ON(!((int)(queue->remote_insert - queue->process) >= 0));
  25995. +
  25996. + while ((queue->process != queue->local_insert) ||
  25997. + (queue->process != queue->remote_insert)) {
  25998. + VCHIQ_BULK_T *bulk = &queue->bulks[BULK_INDEX(queue->process)];
  25999. +
  26000. + if (queue->process == queue->remote_insert) {
  26001. + /* fabricate a matching dummy bulk */
  26002. + bulk->remote_data = NULL;
  26003. + bulk->remote_size = 0;
  26004. + queue->remote_insert++;
  26005. + }
  26006. +
  26007. + if (queue->process != queue->local_insert) {
  26008. + vchiq_complete_bulk(bulk);
  26009. +
  26010. + vchiq_log_info(vchiq_core_msg_log_level,
  26011. + "%s %c%c%c%c d:%d ABORTED - tx len:%d, "
  26012. + "rx len:%d",
  26013. + is_tx ? "Send Bulk to" : "Recv Bulk from",
  26014. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  26015. + service->remoteport,
  26016. + bulk->size,
  26017. + bulk->remote_size);
  26018. + } else {
  26019. + /* fabricate a matching dummy bulk */
  26020. + bulk->data = NULL;
  26021. + bulk->size = 0;
  26022. + bulk->actual = VCHIQ_BULK_ACTUAL_ABORTED;
  26023. + bulk->dir = is_tx ? VCHIQ_BULK_TRANSMIT :
  26024. + VCHIQ_BULK_RECEIVE;
  26025. + queue->local_insert++;
  26026. + }
  26027. +
  26028. + queue->process++;
  26029. + }
  26030. +}
  26031. +
  26032. +/* Called from the slot handler thread */
  26033. +static void
  26034. +pause_bulks(VCHIQ_STATE_T *state)
  26035. +{
  26036. + if (unlikely(atomic_inc_return(&pause_bulks_count) != 1)) {
  26037. + WARN_ON_ONCE(1);
  26038. + atomic_set(&pause_bulks_count, 1);
  26039. + return;
  26040. + }
  26041. +
  26042. + /* Block bulk transfers from all services */
  26043. + mutex_lock(&state->bulk_transfer_mutex);
  26044. +}
  26045. +
  26046. +/* Called from the slot handler thread */
  26047. +static void
  26048. +resume_bulks(VCHIQ_STATE_T *state)
  26049. +{
  26050. + int i;
  26051. + if (unlikely(atomic_dec_return(&pause_bulks_count) != 0)) {
  26052. + WARN_ON_ONCE(1);
  26053. + atomic_set(&pause_bulks_count, 0);
  26054. + return;
  26055. + }
  26056. +
  26057. + /* Allow bulk transfers from all services */
  26058. + mutex_unlock(&state->bulk_transfer_mutex);
  26059. +
  26060. + if (state->deferred_bulks == 0)
  26061. + return;
  26062. +
  26063. + /* Deal with any bulks which had to be deferred due to being in
  26064. + * paused state. Don't try to match up to number of deferred bulks
  26065. + * in case we've had something come and close the service in the
  26066. + * interim - just process all bulk queues for all services */
  26067. + vchiq_log_info(vchiq_core_log_level, "%s: processing %d deferred bulks",
  26068. + __func__, state->deferred_bulks);
  26069. +
  26070. + for (i = 0; i < state->unused_service; i++) {
  26071. + VCHIQ_SERVICE_T *service = state->services[i];
  26072. + int resolved_rx = 0;
  26073. + int resolved_tx = 0;
  26074. + if (!service || (service->srvstate != VCHIQ_SRVSTATE_OPEN))
  26075. + continue;
  26076. +
  26077. + mutex_lock(&service->bulk_mutex);
  26078. + resolved_rx = resolve_bulks(service, &service->bulk_rx);
  26079. + resolved_tx = resolve_bulks(service, &service->bulk_tx);
  26080. + mutex_unlock(&service->bulk_mutex);
  26081. + if (resolved_rx)
  26082. + notify_bulks(service, &service->bulk_rx, 1);
  26083. + if (resolved_tx)
  26084. + notify_bulks(service, &service->bulk_tx, 1);
  26085. + }
  26086. + state->deferred_bulks = 0;
  26087. +}
  26088. +
  26089. +static int
  26090. +parse_open(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header)
  26091. +{
  26092. + VCHIQ_SERVICE_T *service = NULL;
  26093. + int msgid, size;
  26094. + int type;
  26095. + unsigned int localport, remoteport;
  26096. +
  26097. + msgid = header->msgid;
  26098. + size = header->size;
  26099. + type = VCHIQ_MSG_TYPE(msgid);
  26100. + localport = VCHIQ_MSG_DSTPORT(msgid);
  26101. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  26102. + if (size >= sizeof(struct vchiq_open_payload)) {
  26103. + const struct vchiq_open_payload *payload =
  26104. + (struct vchiq_open_payload *)header->data;
  26105. + unsigned int fourcc;
  26106. +
  26107. + fourcc = payload->fourcc;
  26108. + vchiq_log_info(vchiq_core_log_level,
  26109. + "%d: prs OPEN@%x (%d->'%c%c%c%c')",
  26110. + state->id, (unsigned int)header,
  26111. + localport,
  26112. + VCHIQ_FOURCC_AS_4CHARS(fourcc));
  26113. +
  26114. + service = get_listening_service(state, fourcc);
  26115. +
  26116. + if (service) {
  26117. + /* A matching service exists */
  26118. + short version = payload->version;
  26119. + short version_min = payload->version_min;
  26120. + if ((service->version < version_min) ||
  26121. + (version < service->version_min)) {
  26122. + /* Version mismatch */
  26123. + vchiq_loud_error_header();
  26124. + vchiq_loud_error("%d: service %d (%c%c%c%c) "
  26125. + "version mismatch - local (%d, min %d)"
  26126. + " vs. remote (%d, min %d)",
  26127. + state->id, service->localport,
  26128. + VCHIQ_FOURCC_AS_4CHARS(fourcc),
  26129. + service->version, service->version_min,
  26130. + version, version_min);
  26131. + vchiq_loud_error_footer();
  26132. + unlock_service(service);
  26133. + service = NULL;
  26134. + goto fail_open;
  26135. + }
  26136. + service->peer_version = version;
  26137. +
  26138. + if (service->srvstate == VCHIQ_SRVSTATE_LISTENING) {
  26139. + struct vchiq_openack_payload ack_payload = {
  26140. + service->version
  26141. + };
  26142. + VCHIQ_ELEMENT_T body = {
  26143. + &ack_payload,
  26144. + sizeof(ack_payload)
  26145. + };
  26146. +
  26147. + /* Acknowledge the OPEN */
  26148. + if (service->sync) {
  26149. + if (queue_message_sync(state, NULL,
  26150. + VCHIQ_MAKE_MSG(
  26151. + VCHIQ_MSG_OPENACK,
  26152. + service->localport,
  26153. + remoteport),
  26154. + &body, 1, sizeof(ack_payload),
  26155. + 0) == VCHIQ_RETRY)
  26156. + goto bail_not_ready;
  26157. + } else {
  26158. + if (queue_message(state, NULL,
  26159. + VCHIQ_MAKE_MSG(
  26160. + VCHIQ_MSG_OPENACK,
  26161. + service->localport,
  26162. + remoteport),
  26163. + &body, 1, sizeof(ack_payload),
  26164. + 0) == VCHIQ_RETRY)
  26165. + goto bail_not_ready;
  26166. + }
  26167. +
  26168. + /* The service is now open */
  26169. + vchiq_set_service_state(service,
  26170. + service->sync ? VCHIQ_SRVSTATE_OPENSYNC
  26171. + : VCHIQ_SRVSTATE_OPEN);
  26172. + }
  26173. +
  26174. + service->remoteport = remoteport;
  26175. + service->client_id = ((int *)header->data)[1];
  26176. + if (make_service_callback(service, VCHIQ_SERVICE_OPENED,
  26177. + NULL, NULL) == VCHIQ_RETRY) {
  26178. + /* Bail out if not ready */
  26179. + service->remoteport = VCHIQ_PORT_FREE;
  26180. + goto bail_not_ready;
  26181. + }
  26182. +
  26183. + /* Success - the message has been dealt with */
  26184. + unlock_service(service);
  26185. + return 1;
  26186. + }
  26187. + }
  26188. +
  26189. +fail_open:
  26190. + /* No available service, or an invalid request - send a CLOSE */
  26191. + if (queue_message(state, NULL,
  26192. + VCHIQ_MAKE_MSG(VCHIQ_MSG_CLOSE, 0, VCHIQ_MSG_SRCPORT(msgid)),
  26193. + NULL, 0, 0, 0) == VCHIQ_RETRY)
  26194. + goto bail_not_ready;
  26195. +
  26196. + return 1;
  26197. +
  26198. +bail_not_ready:
  26199. + if (service)
  26200. + unlock_service(service);
  26201. +
  26202. + return 0;
  26203. +}
  26204. +
  26205. +/* Called by the slot handler thread */
  26206. +static void
  26207. +parse_rx_slots(VCHIQ_STATE_T *state)
  26208. +{
  26209. + VCHIQ_SHARED_STATE_T *remote = state->remote;
  26210. + VCHIQ_SERVICE_T *service = NULL;
  26211. + int tx_pos;
  26212. + DEBUG_INITIALISE(state->local)
  26213. +
  26214. + tx_pos = remote->tx_pos;
  26215. +
  26216. + while (state->rx_pos != tx_pos) {
  26217. + VCHIQ_HEADER_T *header;
  26218. + int msgid, size;
  26219. + int type;
  26220. + unsigned int localport, remoteport;
  26221. +
  26222. + DEBUG_TRACE(PARSE_LINE);
  26223. + if (!state->rx_data) {
  26224. + int rx_index;
  26225. + WARN_ON(!((state->rx_pos & VCHIQ_SLOT_MASK) == 0));
  26226. + rx_index = remote->slot_queue[
  26227. + SLOT_QUEUE_INDEX_FROM_POS(state->rx_pos) &
  26228. + VCHIQ_SLOT_QUEUE_MASK];
  26229. + state->rx_data = (char *)SLOT_DATA_FROM_INDEX(state,
  26230. + rx_index);
  26231. + state->rx_info = SLOT_INFO_FROM_INDEX(state, rx_index);
  26232. +
  26233. + /* Initialise use_count to one, and increment
  26234. + ** release_count at the end of the slot to avoid
  26235. + ** releasing the slot prematurely. */
  26236. + state->rx_info->use_count = 1;
  26237. + state->rx_info->release_count = 0;
  26238. + }
  26239. +
  26240. + header = (VCHIQ_HEADER_T *)(state->rx_data +
  26241. + (state->rx_pos & VCHIQ_SLOT_MASK));
  26242. + DEBUG_VALUE(PARSE_HEADER, (int)header);
  26243. + msgid = header->msgid;
  26244. + DEBUG_VALUE(PARSE_MSGID, msgid);
  26245. + size = header->size;
  26246. + type = VCHIQ_MSG_TYPE(msgid);
  26247. + localport = VCHIQ_MSG_DSTPORT(msgid);
  26248. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  26249. +
  26250. + if (type != VCHIQ_MSG_DATA)
  26251. + VCHIQ_STATS_INC(state, ctrl_rx_count);
  26252. +
  26253. + switch (type) {
  26254. + case VCHIQ_MSG_OPENACK:
  26255. + case VCHIQ_MSG_CLOSE:
  26256. + case VCHIQ_MSG_DATA:
  26257. + case VCHIQ_MSG_BULK_RX:
  26258. + case VCHIQ_MSG_BULK_TX:
  26259. + case VCHIQ_MSG_BULK_RX_DONE:
  26260. + case VCHIQ_MSG_BULK_TX_DONE:
  26261. + service = find_service_by_port(state, localport);
  26262. + if ((!service || service->remoteport != remoteport) &&
  26263. + (localport == 0) &&
  26264. + (type == VCHIQ_MSG_CLOSE)) {
  26265. + /* This could be a CLOSE from a client which
  26266. + hadn't yet received the OPENACK - look for
  26267. + the connected service */
  26268. + if (service)
  26269. + unlock_service(service);
  26270. + service = get_connected_service(state,
  26271. + remoteport);
  26272. + if (service)
  26273. + vchiq_log_warning(vchiq_core_log_level,
  26274. + "%d: prs %s@%x (%d->%d) - "
  26275. + "found connected service %d",
  26276. + state->id, msg_type_str(type),
  26277. + (unsigned int)header,
  26278. + remoteport, localport,
  26279. + service->localport);
  26280. + }
  26281. +
  26282. + if (!service) {
  26283. + vchiq_log_error(vchiq_core_log_level,
  26284. + "%d: prs %s@%x (%d->%d) - "
  26285. + "invalid/closed service %d",
  26286. + state->id, msg_type_str(type),
  26287. + (unsigned int)header,
  26288. + remoteport, localport, localport);
  26289. + goto skip_message;
  26290. + }
  26291. + break;
  26292. + default:
  26293. + break;
  26294. + }
  26295. +
  26296. + if (vchiq_core_msg_log_level >= VCHIQ_LOG_INFO) {
  26297. + int svc_fourcc;
  26298. +
  26299. + svc_fourcc = service
  26300. + ? service->base.fourcc
  26301. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  26302. + vchiq_log_info(vchiq_core_msg_log_level,
  26303. + "Rcvd Msg %s(%u) from %c%c%c%c s:%d d:%d "
  26304. + "len:%d",
  26305. + msg_type_str(type), type,
  26306. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  26307. + remoteport, localport, size);
  26308. + if (size > 0)
  26309. + vchiq_log_dump_mem("Rcvd", 0, header->data,
  26310. + min(64, size));
  26311. + }
  26312. +
  26313. + if (((unsigned int)header & VCHIQ_SLOT_MASK) + calc_stride(size)
  26314. + > VCHIQ_SLOT_SIZE) {
  26315. + vchiq_log_error(vchiq_core_log_level,
  26316. + "header %x (msgid %x) - size %x too big for "
  26317. + "slot",
  26318. + (unsigned int)header, (unsigned int)msgid,
  26319. + (unsigned int)size);
  26320. + WARN(1, "oversized for slot\n");
  26321. + }
  26322. +
  26323. + switch (type) {
  26324. + case VCHIQ_MSG_OPEN:
  26325. + WARN_ON(!(VCHIQ_MSG_DSTPORT(msgid) == 0));
  26326. + if (!parse_open(state, header))
  26327. + goto bail_not_ready;
  26328. + break;
  26329. + case VCHIQ_MSG_OPENACK:
  26330. + if (size >= sizeof(struct vchiq_openack_payload)) {
  26331. + const struct vchiq_openack_payload *payload =
  26332. + (struct vchiq_openack_payload *)
  26333. + header->data;
  26334. + service->peer_version = payload->version;
  26335. + }
  26336. + vchiq_log_info(vchiq_core_log_level,
  26337. + "%d: prs OPENACK@%x,%x (%d->%d) v:%d",
  26338. + state->id, (unsigned int)header, size,
  26339. + remoteport, localport, service->peer_version);
  26340. + if (service->srvstate ==
  26341. + VCHIQ_SRVSTATE_OPENING) {
  26342. + service->remoteport = remoteport;
  26343. + vchiq_set_service_state(service,
  26344. + VCHIQ_SRVSTATE_OPEN);
  26345. + up(&service->remove_event);
  26346. + } else
  26347. + vchiq_log_error(vchiq_core_log_level,
  26348. + "OPENACK received in state %s",
  26349. + srvstate_names[service->srvstate]);
  26350. + break;
  26351. + case VCHIQ_MSG_CLOSE:
  26352. + WARN_ON(size != 0); /* There should be no data */
  26353. +
  26354. + vchiq_log_info(vchiq_core_log_level,
  26355. + "%d: prs CLOSE@%x (%d->%d)",
  26356. + state->id, (unsigned int)header,
  26357. + remoteport, localport);
  26358. +
  26359. + mark_service_closing_internal(service, 1);
  26360. +
  26361. + if (vchiq_close_service_internal(service,
  26362. + 1/*close_recvd*/) == VCHIQ_RETRY)
  26363. + goto bail_not_ready;
  26364. +
  26365. + vchiq_log_info(vchiq_core_log_level,
  26366. + "Close Service %c%c%c%c s:%u d:%d",
  26367. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  26368. + service->localport,
  26369. + service->remoteport);
  26370. + break;
  26371. + case VCHIQ_MSG_DATA:
  26372. + vchiq_log_trace(vchiq_core_log_level,
  26373. + "%d: prs DATA@%x,%x (%d->%d)",
  26374. + state->id, (unsigned int)header, size,
  26375. + remoteport, localport);
  26376. +
  26377. + if ((service->remoteport == remoteport)
  26378. + && (service->srvstate ==
  26379. + VCHIQ_SRVSTATE_OPEN)) {
  26380. + header->msgid = msgid | VCHIQ_MSGID_CLAIMED;
  26381. + claim_slot(state->rx_info);
  26382. + DEBUG_TRACE(PARSE_LINE);
  26383. + if (make_service_callback(service,
  26384. + VCHIQ_MESSAGE_AVAILABLE, header,
  26385. + NULL) == VCHIQ_RETRY) {
  26386. + DEBUG_TRACE(PARSE_LINE);
  26387. + goto bail_not_ready;
  26388. + }
  26389. + VCHIQ_SERVICE_STATS_INC(service, ctrl_rx_count);
  26390. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_rx_bytes,
  26391. + size);
  26392. + } else {
  26393. + VCHIQ_STATS_INC(state, error_count);
  26394. + }
  26395. + break;
  26396. + case VCHIQ_MSG_CONNECT:
  26397. + vchiq_log_info(vchiq_core_log_level,
  26398. + "%d: prs CONNECT@%x",
  26399. + state->id, (unsigned int)header);
  26400. + up(&state->connect);
  26401. + break;
  26402. + case VCHIQ_MSG_BULK_RX:
  26403. + case VCHIQ_MSG_BULK_TX: {
  26404. + VCHIQ_BULK_QUEUE_T *queue;
  26405. + WARN_ON(!state->is_master);
  26406. + queue = (type == VCHIQ_MSG_BULK_RX) ?
  26407. + &service->bulk_tx : &service->bulk_rx;
  26408. + if ((service->remoteport == remoteport)
  26409. + && (service->srvstate ==
  26410. + VCHIQ_SRVSTATE_OPEN)) {
  26411. + VCHIQ_BULK_T *bulk;
  26412. + int resolved = 0;
  26413. +
  26414. + DEBUG_TRACE(PARSE_LINE);
  26415. + if (mutex_lock_interruptible(
  26416. + &service->bulk_mutex) != 0) {
  26417. + DEBUG_TRACE(PARSE_LINE);
  26418. + goto bail_not_ready;
  26419. + }
  26420. +
  26421. + WARN_ON(!(queue->remote_insert < queue->remove +
  26422. + VCHIQ_NUM_SERVICE_BULKS));
  26423. + bulk = &queue->bulks[
  26424. + BULK_INDEX(queue->remote_insert)];
  26425. + bulk->remote_data =
  26426. + (void *)((int *)header->data)[0];
  26427. + bulk->remote_size = ((int *)header->data)[1];
  26428. + wmb();
  26429. +
  26430. + vchiq_log_info(vchiq_core_log_level,
  26431. + "%d: prs %s@%x (%d->%d) %x@%x",
  26432. + state->id, msg_type_str(type),
  26433. + (unsigned int)header,
  26434. + remoteport, localport,
  26435. + bulk->remote_size,
  26436. + (unsigned int)bulk->remote_data);
  26437. +
  26438. + queue->remote_insert++;
  26439. +
  26440. + if (atomic_read(&pause_bulks_count)) {
  26441. + state->deferred_bulks++;
  26442. + vchiq_log_info(vchiq_core_log_level,
  26443. + "%s: deferring bulk (%d)",
  26444. + __func__,
  26445. + state->deferred_bulks);
  26446. + if (state->conn_state !=
  26447. + VCHIQ_CONNSTATE_PAUSE_SENT)
  26448. + vchiq_log_error(
  26449. + vchiq_core_log_level,
  26450. + "%s: bulks paused in "
  26451. + "unexpected state %s",
  26452. + __func__,
  26453. + conn_state_names[
  26454. + state->conn_state]);
  26455. + } else if (state->conn_state ==
  26456. + VCHIQ_CONNSTATE_CONNECTED) {
  26457. + DEBUG_TRACE(PARSE_LINE);
  26458. + resolved = resolve_bulks(service,
  26459. + queue);
  26460. + }
  26461. +
  26462. + mutex_unlock(&service->bulk_mutex);
  26463. + if (resolved)
  26464. + notify_bulks(service, queue,
  26465. + 1/*retry_poll*/);
  26466. + }
  26467. + } break;
  26468. + case VCHIQ_MSG_BULK_RX_DONE:
  26469. + case VCHIQ_MSG_BULK_TX_DONE:
  26470. + WARN_ON(state->is_master);
  26471. + if ((service->remoteport == remoteport)
  26472. + && (service->srvstate !=
  26473. + VCHIQ_SRVSTATE_FREE)) {
  26474. + VCHIQ_BULK_QUEUE_T *queue;
  26475. + VCHIQ_BULK_T *bulk;
  26476. +
  26477. + queue = (type == VCHIQ_MSG_BULK_RX_DONE) ?
  26478. + &service->bulk_rx : &service->bulk_tx;
  26479. +
  26480. + DEBUG_TRACE(PARSE_LINE);
  26481. + if (mutex_lock_interruptible(
  26482. + &service->bulk_mutex) != 0) {
  26483. + DEBUG_TRACE(PARSE_LINE);
  26484. + goto bail_not_ready;
  26485. + }
  26486. + if ((int)(queue->remote_insert -
  26487. + queue->local_insert) >= 0) {
  26488. + vchiq_log_error(vchiq_core_log_level,
  26489. + "%d: prs %s@%x (%d->%d) "
  26490. + "unexpected (ri=%d,li=%d)",
  26491. + state->id, msg_type_str(type),
  26492. + (unsigned int)header,
  26493. + remoteport, localport,
  26494. + queue->remote_insert,
  26495. + queue->local_insert);
  26496. + mutex_unlock(&service->bulk_mutex);
  26497. + break;
  26498. + }
  26499. +
  26500. + BUG_ON(queue->process == queue->local_insert);
  26501. + BUG_ON(queue->process != queue->remote_insert);
  26502. +
  26503. + bulk = &queue->bulks[
  26504. + BULK_INDEX(queue->remote_insert)];
  26505. + bulk->actual = *(int *)header->data;
  26506. + queue->remote_insert++;
  26507. +
  26508. + vchiq_log_info(vchiq_core_log_level,
  26509. + "%d: prs %s@%x (%d->%d) %x@%x",
  26510. + state->id, msg_type_str(type),
  26511. + (unsigned int)header,
  26512. + remoteport, localport,
  26513. + bulk->actual, (unsigned int)bulk->data);
  26514. +
  26515. + vchiq_log_trace(vchiq_core_log_level,
  26516. + "%d: prs:%d %cx li=%x ri=%x p=%x",
  26517. + state->id, localport,
  26518. + (type == VCHIQ_MSG_BULK_RX_DONE) ?
  26519. + 'r' : 't',
  26520. + queue->local_insert,
  26521. + queue->remote_insert, queue->process);
  26522. +
  26523. + DEBUG_TRACE(PARSE_LINE);
  26524. + WARN_ON(queue->process == queue->local_insert);
  26525. + vchiq_complete_bulk(bulk);
  26526. + queue->process++;
  26527. + mutex_unlock(&service->bulk_mutex);
  26528. + DEBUG_TRACE(PARSE_LINE);
  26529. + notify_bulks(service, queue, 1/*retry_poll*/);
  26530. + DEBUG_TRACE(PARSE_LINE);
  26531. + }
  26532. + break;
  26533. + case VCHIQ_MSG_PADDING:
  26534. + vchiq_log_trace(vchiq_core_log_level,
  26535. + "%d: prs PADDING@%x,%x",
  26536. + state->id, (unsigned int)header, size);
  26537. + break;
  26538. + case VCHIQ_MSG_PAUSE:
  26539. + /* If initiated, signal the application thread */
  26540. + vchiq_log_trace(vchiq_core_log_level,
  26541. + "%d: prs PAUSE@%x,%x",
  26542. + state->id, (unsigned int)header, size);
  26543. + if (state->conn_state == VCHIQ_CONNSTATE_PAUSED) {
  26544. + vchiq_log_error(vchiq_core_log_level,
  26545. + "%d: PAUSE received in state PAUSED",
  26546. + state->id);
  26547. + break;
  26548. + }
  26549. + if (state->conn_state != VCHIQ_CONNSTATE_PAUSE_SENT) {
  26550. + /* Send a PAUSE in response */
  26551. + if (queue_message(state, NULL,
  26552. + VCHIQ_MAKE_MSG(VCHIQ_MSG_PAUSE, 0, 0),
  26553. + NULL, 0, 0, 0) == VCHIQ_RETRY)
  26554. + goto bail_not_ready;
  26555. + if (state->is_master)
  26556. + pause_bulks(state);
  26557. + }
  26558. + /* At this point slot_mutex is held */
  26559. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_PAUSED);
  26560. + vchiq_platform_paused(state);
  26561. + break;
  26562. + case VCHIQ_MSG_RESUME:
  26563. + vchiq_log_trace(vchiq_core_log_level,
  26564. + "%d: prs RESUME@%x,%x",
  26565. + state->id, (unsigned int)header, size);
  26566. + /* Release the slot mutex */
  26567. + mutex_unlock(&state->slot_mutex);
  26568. + if (state->is_master)
  26569. + resume_bulks(state);
  26570. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTED);
  26571. + vchiq_platform_resumed(state);
  26572. + break;
  26573. +
  26574. + case VCHIQ_MSG_REMOTE_USE:
  26575. + vchiq_on_remote_use(state);
  26576. + break;
  26577. + case VCHIQ_MSG_REMOTE_RELEASE:
  26578. + vchiq_on_remote_release(state);
  26579. + break;
  26580. + case VCHIQ_MSG_REMOTE_USE_ACTIVE:
  26581. + vchiq_on_remote_use_active(state);
  26582. + break;
  26583. +
  26584. + default:
  26585. + vchiq_log_error(vchiq_core_log_level,
  26586. + "%d: prs invalid msgid %x@%x,%x",
  26587. + state->id, msgid, (unsigned int)header, size);
  26588. + WARN(1, "invalid message\n");
  26589. + break;
  26590. + }
  26591. +
  26592. +skip_message:
  26593. + if (service) {
  26594. + unlock_service(service);
  26595. + service = NULL;
  26596. + }
  26597. +
  26598. + state->rx_pos += calc_stride(size);
  26599. +
  26600. + DEBUG_TRACE(PARSE_LINE);
  26601. + /* Perform some housekeeping when the end of the slot is
  26602. + ** reached. */
  26603. + if ((state->rx_pos & VCHIQ_SLOT_MASK) == 0) {
  26604. + /* Remove the extra reference count. */
  26605. + release_slot(state, state->rx_info, NULL, NULL);
  26606. + state->rx_data = NULL;
  26607. + }
  26608. + }
  26609. +
  26610. +bail_not_ready:
  26611. + if (service)
  26612. + unlock_service(service);
  26613. +}
  26614. +
  26615. +/* Called by the slot handler thread */
  26616. +static int
  26617. +slot_handler_func(void *v)
  26618. +{
  26619. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  26620. + VCHIQ_SHARED_STATE_T *local = state->local;
  26621. + DEBUG_INITIALISE(local)
  26622. +
  26623. + while (1) {
  26624. + DEBUG_COUNT(SLOT_HANDLER_COUNT);
  26625. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  26626. + remote_event_wait(&local->trigger);
  26627. +
  26628. + rmb();
  26629. +
  26630. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  26631. + if (state->poll_needed) {
  26632. + /* Check if we need to suspend - may change our
  26633. + * conn_state */
  26634. + vchiq_platform_check_suspend(state);
  26635. +
  26636. + state->poll_needed = 0;
  26637. +
  26638. + /* Handle service polling and other rare conditions here
  26639. + ** out of the mainline code */
  26640. + switch (state->conn_state) {
  26641. + case VCHIQ_CONNSTATE_CONNECTED:
  26642. + /* Poll the services as requested */
  26643. + poll_services(state);
  26644. + break;
  26645. +
  26646. + case VCHIQ_CONNSTATE_PAUSING:
  26647. + if (state->is_master)
  26648. + pause_bulks(state);
  26649. + if (queue_message(state, NULL,
  26650. + VCHIQ_MAKE_MSG(VCHIQ_MSG_PAUSE, 0, 0),
  26651. + NULL, 0, 0, 0) != VCHIQ_RETRY) {
  26652. + vchiq_set_conn_state(state,
  26653. + VCHIQ_CONNSTATE_PAUSE_SENT);
  26654. + } else {
  26655. + if (state->is_master)
  26656. + resume_bulks(state);
  26657. + /* Retry later */
  26658. + state->poll_needed = 1;
  26659. + }
  26660. + break;
  26661. +
  26662. + case VCHIQ_CONNSTATE_PAUSED:
  26663. + vchiq_platform_resume(state);
  26664. + break;
  26665. +
  26666. + case VCHIQ_CONNSTATE_RESUMING:
  26667. + if (queue_message(state, NULL,
  26668. + VCHIQ_MAKE_MSG(VCHIQ_MSG_RESUME, 0, 0),
  26669. + NULL, 0, 0, 0) != VCHIQ_RETRY) {
  26670. + if (state->is_master)
  26671. + resume_bulks(state);
  26672. + vchiq_set_conn_state(state,
  26673. + VCHIQ_CONNSTATE_CONNECTED);
  26674. + vchiq_platform_resumed(state);
  26675. + } else {
  26676. + /* This should really be impossible,
  26677. + ** since the PAUSE should have flushed
  26678. + ** through outstanding messages. */
  26679. + vchiq_log_error(vchiq_core_log_level,
  26680. + "Failed to send RESUME "
  26681. + "message");
  26682. + BUG();
  26683. + }
  26684. + break;
  26685. +
  26686. + case VCHIQ_CONNSTATE_PAUSE_TIMEOUT:
  26687. + case VCHIQ_CONNSTATE_RESUME_TIMEOUT:
  26688. + vchiq_platform_handle_timeout(state);
  26689. + break;
  26690. + default:
  26691. + break;
  26692. + }
  26693. +
  26694. +
  26695. + }
  26696. +
  26697. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  26698. + parse_rx_slots(state);
  26699. + }
  26700. + return 0;
  26701. +}
  26702. +
  26703. +
  26704. +/* Called by the recycle thread */
  26705. +static int
  26706. +recycle_func(void *v)
  26707. +{
  26708. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  26709. + VCHIQ_SHARED_STATE_T *local = state->local;
  26710. +
  26711. + while (1) {
  26712. + remote_event_wait(&local->recycle);
  26713. +
  26714. + process_free_queue(state);
  26715. + }
  26716. + return 0;
  26717. +}
  26718. +
  26719. +
  26720. +/* Called by the sync thread */
  26721. +static int
  26722. +sync_func(void *v)
  26723. +{
  26724. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  26725. + VCHIQ_SHARED_STATE_T *local = state->local;
  26726. + VCHIQ_HEADER_T *header = (VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state,
  26727. + state->remote->slot_sync);
  26728. +
  26729. + while (1) {
  26730. + VCHIQ_SERVICE_T *service;
  26731. + int msgid, size;
  26732. + int type;
  26733. + unsigned int localport, remoteport;
  26734. +
  26735. + remote_event_wait(&local->sync_trigger);
  26736. +
  26737. + rmb();
  26738. +
  26739. + msgid = header->msgid;
  26740. + size = header->size;
  26741. + type = VCHIQ_MSG_TYPE(msgid);
  26742. + localport = VCHIQ_MSG_DSTPORT(msgid);
  26743. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  26744. +
  26745. + service = find_service_by_port(state, localport);
  26746. +
  26747. + if (!service) {
  26748. + vchiq_log_error(vchiq_sync_log_level,
  26749. + "%d: sf %s@%x (%d->%d) - "
  26750. + "invalid/closed service %d",
  26751. + state->id, msg_type_str(type),
  26752. + (unsigned int)header,
  26753. + remoteport, localport, localport);
  26754. + release_message_sync(state, header);
  26755. + continue;
  26756. + }
  26757. +
  26758. + if (vchiq_sync_log_level >= VCHIQ_LOG_TRACE) {
  26759. + int svc_fourcc;
  26760. +
  26761. + svc_fourcc = service
  26762. + ? service->base.fourcc
  26763. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  26764. + vchiq_log_trace(vchiq_sync_log_level,
  26765. + "Rcvd Msg %s from %c%c%c%c s:%d d:%d len:%d",
  26766. + msg_type_str(type),
  26767. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  26768. + remoteport, localport, size);
  26769. + if (size > 0)
  26770. + vchiq_log_dump_mem("Rcvd", 0, header->data,
  26771. + min(64, size));
  26772. + }
  26773. +
  26774. + switch (type) {
  26775. + case VCHIQ_MSG_OPENACK:
  26776. + if (size >= sizeof(struct vchiq_openack_payload)) {
  26777. + const struct vchiq_openack_payload *payload =
  26778. + (struct vchiq_openack_payload *)
  26779. + header->data;
  26780. + service->peer_version = payload->version;
  26781. + }
  26782. + vchiq_log_info(vchiq_sync_log_level,
  26783. + "%d: sf OPENACK@%x,%x (%d->%d) v:%d",
  26784. + state->id, (unsigned int)header, size,
  26785. + remoteport, localport, service->peer_version);
  26786. + if (service->srvstate == VCHIQ_SRVSTATE_OPENING) {
  26787. + service->remoteport = remoteport;
  26788. + vchiq_set_service_state(service,
  26789. + VCHIQ_SRVSTATE_OPENSYNC);
  26790. + up(&service->remove_event);
  26791. + }
  26792. + release_message_sync(state, header);
  26793. + break;
  26794. +
  26795. + case VCHIQ_MSG_DATA:
  26796. + vchiq_log_trace(vchiq_sync_log_level,
  26797. + "%d: sf DATA@%x,%x (%d->%d)",
  26798. + state->id, (unsigned int)header, size,
  26799. + remoteport, localport);
  26800. +
  26801. + if ((service->remoteport == remoteport) &&
  26802. + (service->srvstate ==
  26803. + VCHIQ_SRVSTATE_OPENSYNC)) {
  26804. + if (make_service_callback(service,
  26805. + VCHIQ_MESSAGE_AVAILABLE, header,
  26806. + NULL) == VCHIQ_RETRY)
  26807. + vchiq_log_error(vchiq_sync_log_level,
  26808. + "synchronous callback to "
  26809. + "service %d returns "
  26810. + "VCHIQ_RETRY",
  26811. + localport);
  26812. + }
  26813. + break;
  26814. +
  26815. + default:
  26816. + vchiq_log_error(vchiq_sync_log_level,
  26817. + "%d: sf unexpected msgid %x@%x,%x",
  26818. + state->id, msgid, (unsigned int)header, size);
  26819. + release_message_sync(state, header);
  26820. + break;
  26821. + }
  26822. +
  26823. + unlock_service(service);
  26824. + }
  26825. +
  26826. + return 0;
  26827. +}
  26828. +
  26829. +
  26830. +static void
  26831. +init_bulk_queue(VCHIQ_BULK_QUEUE_T *queue)
  26832. +{
  26833. + queue->local_insert = 0;
  26834. + queue->remote_insert = 0;
  26835. + queue->process = 0;
  26836. + queue->remote_notify = 0;
  26837. + queue->remove = 0;
  26838. +}
  26839. +
  26840. +
  26841. +inline const char *
  26842. +get_conn_state_name(VCHIQ_CONNSTATE_T conn_state)
  26843. +{
  26844. + return conn_state_names[conn_state];
  26845. +}
  26846. +
  26847. +
  26848. +VCHIQ_SLOT_ZERO_T *
  26849. +vchiq_init_slots(void *mem_base, int mem_size)
  26850. +{
  26851. + int mem_align = (VCHIQ_SLOT_SIZE - (int)mem_base) & VCHIQ_SLOT_MASK;
  26852. + VCHIQ_SLOT_ZERO_T *slot_zero =
  26853. + (VCHIQ_SLOT_ZERO_T *)((char *)mem_base + mem_align);
  26854. + int num_slots = (mem_size - mem_align)/VCHIQ_SLOT_SIZE;
  26855. + int first_data_slot = VCHIQ_SLOT_ZERO_SLOTS;
  26856. +
  26857. + /* Ensure there is enough memory to run an absolutely minimum system */
  26858. + num_slots -= first_data_slot;
  26859. +
  26860. + if (num_slots < 4) {
  26861. + vchiq_log_error(vchiq_core_log_level,
  26862. + "vchiq_init_slots - insufficient memory %x bytes",
  26863. + mem_size);
  26864. + return NULL;
  26865. + }
  26866. +
  26867. + memset(slot_zero, 0, sizeof(VCHIQ_SLOT_ZERO_T));
  26868. +
  26869. + slot_zero->magic = VCHIQ_MAGIC;
  26870. + slot_zero->version = VCHIQ_VERSION;
  26871. + slot_zero->version_min = VCHIQ_VERSION_MIN;
  26872. + slot_zero->slot_zero_size = sizeof(VCHIQ_SLOT_ZERO_T);
  26873. + slot_zero->slot_size = VCHIQ_SLOT_SIZE;
  26874. + slot_zero->max_slots = VCHIQ_MAX_SLOTS;
  26875. + slot_zero->max_slots_per_side = VCHIQ_MAX_SLOTS_PER_SIDE;
  26876. +
  26877. + slot_zero->master.slot_sync = first_data_slot;
  26878. + slot_zero->master.slot_first = first_data_slot + 1;
  26879. + slot_zero->master.slot_last = first_data_slot + (num_slots/2) - 1;
  26880. + slot_zero->slave.slot_sync = first_data_slot + (num_slots/2);
  26881. + slot_zero->slave.slot_first = first_data_slot + (num_slots/2) + 1;
  26882. + slot_zero->slave.slot_last = first_data_slot + num_slots - 1;
  26883. +
  26884. + return slot_zero;
  26885. +}
  26886. +
  26887. +VCHIQ_STATUS_T
  26888. +vchiq_init_state(VCHIQ_STATE_T *state, VCHIQ_SLOT_ZERO_T *slot_zero,
  26889. + int is_master)
  26890. +{
  26891. + VCHIQ_SHARED_STATE_T *local;
  26892. + VCHIQ_SHARED_STATE_T *remote;
  26893. + VCHIQ_STATUS_T status;
  26894. + char threadname[10];
  26895. + static int id;
  26896. + int i;
  26897. +
  26898. + vchiq_log_warning(vchiq_core_log_level,
  26899. + "%s: slot_zero = 0x%08lx, is_master = %d",
  26900. + __func__, (unsigned long)slot_zero, is_master);
  26901. +
  26902. + /* Check the input configuration */
  26903. +
  26904. + if (slot_zero->magic != VCHIQ_MAGIC) {
  26905. + vchiq_loud_error_header();
  26906. + vchiq_loud_error("Invalid VCHIQ magic value found.");
  26907. + vchiq_loud_error("slot_zero=%x: magic=%x (expected %x)",
  26908. + (unsigned int)slot_zero, slot_zero->magic, VCHIQ_MAGIC);
  26909. + vchiq_loud_error_footer();
  26910. + return VCHIQ_ERROR;
  26911. + }
  26912. +
  26913. + if (slot_zero->version < VCHIQ_VERSION_MIN) {
  26914. + vchiq_loud_error_header();
  26915. + vchiq_loud_error("Incompatible VCHIQ versions found.");
  26916. + vchiq_loud_error("slot_zero=%x: VideoCore version=%d "
  26917. + "(minimum %d)",
  26918. + (unsigned int)slot_zero, slot_zero->version,
  26919. + VCHIQ_VERSION_MIN);
  26920. + vchiq_loud_error("Restart with a newer VideoCore image.");
  26921. + vchiq_loud_error_footer();
  26922. + return VCHIQ_ERROR;
  26923. + }
  26924. +
  26925. + if (VCHIQ_VERSION < slot_zero->version_min) {
  26926. + vchiq_loud_error_header();
  26927. + vchiq_loud_error("Incompatible VCHIQ versions found.");
  26928. + vchiq_loud_error("slot_zero=%x: version=%d (VideoCore "
  26929. + "minimum %d)",
  26930. + (unsigned int)slot_zero, VCHIQ_VERSION,
  26931. + slot_zero->version_min);
  26932. + vchiq_loud_error("Restart with a newer kernel.");
  26933. + vchiq_loud_error_footer();
  26934. + return VCHIQ_ERROR;
  26935. + }
  26936. +
  26937. + if ((slot_zero->slot_zero_size != sizeof(VCHIQ_SLOT_ZERO_T)) ||
  26938. + (slot_zero->slot_size != VCHIQ_SLOT_SIZE) ||
  26939. + (slot_zero->max_slots != VCHIQ_MAX_SLOTS) ||
  26940. + (slot_zero->max_slots_per_side != VCHIQ_MAX_SLOTS_PER_SIDE)) {
  26941. + vchiq_loud_error_header();
  26942. + if (slot_zero->slot_zero_size != sizeof(VCHIQ_SLOT_ZERO_T))
  26943. + vchiq_loud_error("slot_zero=%x: slot_zero_size=%x "
  26944. + "(expected %x)",
  26945. + (unsigned int)slot_zero,
  26946. + slot_zero->slot_zero_size,
  26947. + sizeof(VCHIQ_SLOT_ZERO_T));
  26948. + if (slot_zero->slot_size != VCHIQ_SLOT_SIZE)
  26949. + vchiq_loud_error("slot_zero=%x: slot_size=%d "
  26950. + "(expected %d",
  26951. + (unsigned int)slot_zero, slot_zero->slot_size,
  26952. + VCHIQ_SLOT_SIZE);
  26953. + if (slot_zero->max_slots != VCHIQ_MAX_SLOTS)
  26954. + vchiq_loud_error("slot_zero=%x: max_slots=%d "
  26955. + "(expected %d)",
  26956. + (unsigned int)slot_zero, slot_zero->max_slots,
  26957. + VCHIQ_MAX_SLOTS);
  26958. + if (slot_zero->max_slots_per_side != VCHIQ_MAX_SLOTS_PER_SIDE)
  26959. + vchiq_loud_error("slot_zero=%x: max_slots_per_side=%d "
  26960. + "(expected %d)",
  26961. + (unsigned int)slot_zero,
  26962. + slot_zero->max_slots_per_side,
  26963. + VCHIQ_MAX_SLOTS_PER_SIDE);
  26964. + vchiq_loud_error_footer();
  26965. + return VCHIQ_ERROR;
  26966. + }
  26967. +
  26968. + if (is_master) {
  26969. + local = &slot_zero->master;
  26970. + remote = &slot_zero->slave;
  26971. + } else {
  26972. + local = &slot_zero->slave;
  26973. + remote = &slot_zero->master;
  26974. + }
  26975. +
  26976. + if (local->initialised) {
  26977. + vchiq_loud_error_header();
  26978. + if (remote->initialised)
  26979. + vchiq_loud_error("local state has already been "
  26980. + "initialised");
  26981. + else
  26982. + vchiq_loud_error("master/slave mismatch - two %ss",
  26983. + is_master ? "master" : "slave");
  26984. + vchiq_loud_error_footer();
  26985. + return VCHIQ_ERROR;
  26986. + }
  26987. +
  26988. + memset(state, 0, sizeof(VCHIQ_STATE_T));
  26989. +
  26990. + state->id = id++;
  26991. + state->is_master = is_master;
  26992. +
  26993. + /*
  26994. + initialize shared state pointers
  26995. + */
  26996. +
  26997. + state->local = local;
  26998. + state->remote = remote;
  26999. + state->slot_data = (VCHIQ_SLOT_T *)slot_zero;
  27000. +
  27001. + /*
  27002. + initialize events and mutexes
  27003. + */
  27004. +
  27005. + sema_init(&state->connect, 0);
  27006. + mutex_init(&state->mutex);
  27007. + sema_init(&state->trigger_event, 0);
  27008. + sema_init(&state->recycle_event, 0);
  27009. + sema_init(&state->sync_trigger_event, 0);
  27010. + sema_init(&state->sync_release_event, 0);
  27011. +
  27012. + mutex_init(&state->slot_mutex);
  27013. + mutex_init(&state->recycle_mutex);
  27014. + mutex_init(&state->sync_mutex);
  27015. + mutex_init(&state->bulk_transfer_mutex);
  27016. +
  27017. + sema_init(&state->slot_available_event, 0);
  27018. + sema_init(&state->slot_remove_event, 0);
  27019. + sema_init(&state->data_quota_event, 0);
  27020. +
  27021. + state->slot_queue_available = 0;
  27022. +
  27023. + for (i = 0; i < VCHIQ_MAX_SERVICES; i++) {
  27024. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  27025. + &state->service_quotas[i];
  27026. + sema_init(&service_quota->quota_event, 0);
  27027. + }
  27028. +
  27029. + for (i = local->slot_first; i <= local->slot_last; i++) {
  27030. + local->slot_queue[state->slot_queue_available++] = i;
  27031. + up(&state->slot_available_event);
  27032. + }
  27033. +
  27034. + state->default_slot_quota = state->slot_queue_available/2;
  27035. + state->default_message_quota =
  27036. + min((unsigned short)(state->default_slot_quota * 256),
  27037. + (unsigned short)~0);
  27038. +
  27039. + state->previous_data_index = -1;
  27040. + state->data_use_count = 0;
  27041. + state->data_quota = state->slot_queue_available - 1;
  27042. +
  27043. + local->trigger.event = &state->trigger_event;
  27044. + remote_event_create(&local->trigger);
  27045. + local->tx_pos = 0;
  27046. +
  27047. + local->recycle.event = &state->recycle_event;
  27048. + remote_event_create(&local->recycle);
  27049. + local->slot_queue_recycle = state->slot_queue_available;
  27050. +
  27051. + local->sync_trigger.event = &state->sync_trigger_event;
  27052. + remote_event_create(&local->sync_trigger);
  27053. +
  27054. + local->sync_release.event = &state->sync_release_event;
  27055. + remote_event_create(&local->sync_release);
  27056. +
  27057. + /* At start-of-day, the slot is empty and available */
  27058. + ((VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state, local->slot_sync))->msgid
  27059. + = VCHIQ_MSGID_PADDING;
  27060. + remote_event_signal_local(&local->sync_release);
  27061. +
  27062. + local->debug[DEBUG_ENTRIES] = DEBUG_MAX;
  27063. +
  27064. + status = vchiq_platform_init_state(state);
  27065. +
  27066. + /*
  27067. + bring up slot handler thread
  27068. + */
  27069. + snprintf(threadname, sizeof(threadname), "VCHIQ-%d", state->id);
  27070. + state->slot_handler_thread = kthread_create(&slot_handler_func,
  27071. + (void *)state,
  27072. + threadname);
  27073. +
  27074. + if (state->slot_handler_thread == NULL) {
  27075. + vchiq_loud_error_header();
  27076. + vchiq_loud_error("couldn't create thread %s", threadname);
  27077. + vchiq_loud_error_footer();
  27078. + return VCHIQ_ERROR;
  27079. + }
  27080. + set_user_nice(state->slot_handler_thread, -19);
  27081. + wake_up_process(state->slot_handler_thread);
  27082. +
  27083. + snprintf(threadname, sizeof(threadname), "VCHIQr-%d", state->id);
  27084. + state->recycle_thread = kthread_create(&recycle_func,
  27085. + (void *)state,
  27086. + threadname);
  27087. + if (state->recycle_thread == NULL) {
  27088. + vchiq_loud_error_header();
  27089. + vchiq_loud_error("couldn't create thread %s", threadname);
  27090. + vchiq_loud_error_footer();
  27091. + return VCHIQ_ERROR;
  27092. + }
  27093. + set_user_nice(state->recycle_thread, -19);
  27094. + wake_up_process(state->recycle_thread);
  27095. +
  27096. + snprintf(threadname, sizeof(threadname), "VCHIQs-%d", state->id);
  27097. + state->sync_thread = kthread_create(&sync_func,
  27098. + (void *)state,
  27099. + threadname);
  27100. + if (state->sync_thread == NULL) {
  27101. + vchiq_loud_error_header();
  27102. + vchiq_loud_error("couldn't create thread %s", threadname);
  27103. + vchiq_loud_error_footer();
  27104. + return VCHIQ_ERROR;
  27105. + }
  27106. + set_user_nice(state->sync_thread, -20);
  27107. + wake_up_process(state->sync_thread);
  27108. +
  27109. + BUG_ON(state->id >= VCHIQ_MAX_STATES);
  27110. + vchiq_states[state->id] = state;
  27111. +
  27112. + /* Indicate readiness to the other side */
  27113. + local->initialised = 1;
  27114. +
  27115. + return status;
  27116. +}
  27117. +
  27118. +/* Called from application thread when a client or server service is created. */
  27119. +VCHIQ_SERVICE_T *
  27120. +vchiq_add_service_internal(VCHIQ_STATE_T *state,
  27121. + const VCHIQ_SERVICE_PARAMS_T *params, int srvstate,
  27122. + VCHIQ_INSTANCE_T instance, VCHIQ_USERDATA_TERM_T userdata_term)
  27123. +{
  27124. + VCHIQ_SERVICE_T *service;
  27125. +
  27126. + service = kmalloc(sizeof(VCHIQ_SERVICE_T), GFP_KERNEL);
  27127. + if (service) {
  27128. + service->base.fourcc = params->fourcc;
  27129. + service->base.callback = params->callback;
  27130. + service->base.userdata = params->userdata;
  27131. + service->handle = VCHIQ_SERVICE_HANDLE_INVALID;
  27132. + service->ref_count = 1;
  27133. + service->srvstate = VCHIQ_SRVSTATE_FREE;
  27134. + service->userdata_term = userdata_term;
  27135. + service->localport = VCHIQ_PORT_FREE;
  27136. + service->remoteport = VCHIQ_PORT_FREE;
  27137. +
  27138. + service->public_fourcc = (srvstate == VCHIQ_SRVSTATE_OPENING) ?
  27139. + VCHIQ_FOURCC_INVALID : params->fourcc;
  27140. + service->client_id = 0;
  27141. + service->auto_close = 1;
  27142. + service->sync = 0;
  27143. + service->closing = 0;
  27144. + atomic_set(&service->poll_flags, 0);
  27145. + service->version = params->version;
  27146. + service->version_min = params->version_min;
  27147. + service->state = state;
  27148. + service->instance = instance;
  27149. + service->service_use_count = 0;
  27150. + init_bulk_queue(&service->bulk_tx);
  27151. + init_bulk_queue(&service->bulk_rx);
  27152. + sema_init(&service->remove_event, 0);
  27153. + sema_init(&service->bulk_remove_event, 0);
  27154. + mutex_init(&service->bulk_mutex);
  27155. + memset(&service->stats, 0, sizeof(service->stats));
  27156. + } else {
  27157. + vchiq_log_error(vchiq_core_log_level,
  27158. + "Out of memory");
  27159. + }
  27160. +
  27161. + if (service) {
  27162. + VCHIQ_SERVICE_T **pservice = NULL;
  27163. + int i;
  27164. +
  27165. + /* Although it is perfectly possible to use service_spinlock
  27166. + ** to protect the creation of services, it is overkill as it
  27167. + ** disables interrupts while the array is searched.
  27168. + ** The only danger is of another thread trying to create a
  27169. + ** service - service deletion is safe.
  27170. + ** Therefore it is preferable to use state->mutex which,
  27171. + ** although slower to claim, doesn't block interrupts while
  27172. + ** it is held.
  27173. + */
  27174. +
  27175. + mutex_lock(&state->mutex);
  27176. +
  27177. + /* Prepare to use a previously unused service */
  27178. + if (state->unused_service < VCHIQ_MAX_SERVICES)
  27179. + pservice = &state->services[state->unused_service];
  27180. +
  27181. + if (srvstate == VCHIQ_SRVSTATE_OPENING) {
  27182. + for (i = 0; i < state->unused_service; i++) {
  27183. + VCHIQ_SERVICE_T *srv = state->services[i];
  27184. + if (!srv) {
  27185. + pservice = &state->services[i];
  27186. + break;
  27187. + }
  27188. + }
  27189. + } else {
  27190. + for (i = (state->unused_service - 1); i >= 0; i--) {
  27191. + VCHIQ_SERVICE_T *srv = state->services[i];
  27192. + if (!srv)
  27193. + pservice = &state->services[i];
  27194. + else if ((srv->public_fourcc == params->fourcc)
  27195. + && ((srv->instance != instance) ||
  27196. + (srv->base.callback !=
  27197. + params->callback))) {
  27198. + /* There is another server using this
  27199. + ** fourcc which doesn't match. */
  27200. + pservice = NULL;
  27201. + break;
  27202. + }
  27203. + }
  27204. + }
  27205. +
  27206. + if (pservice) {
  27207. + service->localport = (pservice - state->services);
  27208. + if (!handle_seq)
  27209. + handle_seq = VCHIQ_MAX_STATES *
  27210. + VCHIQ_MAX_SERVICES;
  27211. + service->handle = handle_seq |
  27212. + (state->id * VCHIQ_MAX_SERVICES) |
  27213. + service->localport;
  27214. + handle_seq += VCHIQ_MAX_STATES * VCHIQ_MAX_SERVICES;
  27215. + *pservice = service;
  27216. + if (pservice == &state->services[state->unused_service])
  27217. + state->unused_service++;
  27218. + }
  27219. +
  27220. + mutex_unlock(&state->mutex);
  27221. +
  27222. + if (!pservice) {
  27223. + kfree(service);
  27224. + service = NULL;
  27225. + }
  27226. + }
  27227. +
  27228. + if (service) {
  27229. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  27230. + &state->service_quotas[service->localport];
  27231. + service_quota->slot_quota = state->default_slot_quota;
  27232. + service_quota->message_quota = state->default_message_quota;
  27233. + if (service_quota->slot_use_count == 0)
  27234. + service_quota->previous_tx_index =
  27235. + SLOT_QUEUE_INDEX_FROM_POS(state->local_tx_pos)
  27236. + - 1;
  27237. +
  27238. + /* Bring this service online */
  27239. + vchiq_set_service_state(service, srvstate);
  27240. +
  27241. + vchiq_log_info(vchiq_core_msg_log_level,
  27242. + "%s Service %c%c%c%c SrcPort:%d",
  27243. + (srvstate == VCHIQ_SRVSTATE_OPENING)
  27244. + ? "Open" : "Add",
  27245. + VCHIQ_FOURCC_AS_4CHARS(params->fourcc),
  27246. + service->localport);
  27247. + }
  27248. +
  27249. + /* Don't unlock the service - leave it with a ref_count of 1. */
  27250. +
  27251. + return service;
  27252. +}
  27253. +
  27254. +VCHIQ_STATUS_T
  27255. +vchiq_open_service_internal(VCHIQ_SERVICE_T *service, int client_id)
  27256. +{
  27257. + struct vchiq_open_payload payload = {
  27258. + service->base.fourcc,
  27259. + client_id,
  27260. + service->version,
  27261. + service->version_min
  27262. + };
  27263. + VCHIQ_ELEMENT_T body = { &payload, sizeof(payload) };
  27264. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  27265. +
  27266. + service->client_id = client_id;
  27267. + vchiq_use_service_internal(service);
  27268. + status = queue_message(service->state, NULL,
  27269. + VCHIQ_MAKE_MSG(VCHIQ_MSG_OPEN, service->localport, 0),
  27270. + &body, 1, sizeof(payload), 1);
  27271. + if (status == VCHIQ_SUCCESS) {
  27272. + if (down_interruptible(&service->remove_event) != 0) {
  27273. + status = VCHIQ_RETRY;
  27274. + vchiq_release_service_internal(service);
  27275. + } else if ((service->srvstate != VCHIQ_SRVSTATE_OPEN) &&
  27276. + (service->srvstate != VCHIQ_SRVSTATE_OPENSYNC)) {
  27277. + if (service->srvstate != VCHIQ_SRVSTATE_CLOSEWAIT)
  27278. + vchiq_log_error(vchiq_core_log_level,
  27279. + "%d: osi - srvstate = %s (ref %d)",
  27280. + service->state->id,
  27281. + srvstate_names[service->srvstate],
  27282. + service->ref_count);
  27283. + status = VCHIQ_ERROR;
  27284. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  27285. + vchiq_release_service_internal(service);
  27286. + }
  27287. + }
  27288. + return status;
  27289. +}
  27290. +
  27291. +static void
  27292. +release_service_messages(VCHIQ_SERVICE_T *service)
  27293. +{
  27294. + VCHIQ_STATE_T *state = service->state;
  27295. + int slot_last = state->remote->slot_last;
  27296. + int i;
  27297. +
  27298. + /* Release any claimed messages */
  27299. + for (i = state->remote->slot_first; i <= slot_last; i++) {
  27300. + VCHIQ_SLOT_INFO_T *slot_info =
  27301. + SLOT_INFO_FROM_INDEX(state, i);
  27302. + if (slot_info->release_count != slot_info->use_count) {
  27303. + char *data =
  27304. + (char *)SLOT_DATA_FROM_INDEX(state, i);
  27305. + unsigned int pos, end;
  27306. +
  27307. + end = VCHIQ_SLOT_SIZE;
  27308. + if (data == state->rx_data)
  27309. + /* This buffer is still being read from - stop
  27310. + ** at the current read position */
  27311. + end = state->rx_pos & VCHIQ_SLOT_MASK;
  27312. +
  27313. + pos = 0;
  27314. +
  27315. + while (pos < end) {
  27316. + VCHIQ_HEADER_T *header =
  27317. + (VCHIQ_HEADER_T *)(data + pos);
  27318. + int msgid = header->msgid;
  27319. + int port = VCHIQ_MSG_DSTPORT(msgid);
  27320. + if ((port == service->localport) &&
  27321. + (msgid & VCHIQ_MSGID_CLAIMED)) {
  27322. + vchiq_log_info(vchiq_core_log_level,
  27323. + " fsi - hdr %x",
  27324. + (unsigned int)header);
  27325. + release_slot(state, slot_info, header,
  27326. + NULL);
  27327. + }
  27328. + pos += calc_stride(header->size);
  27329. + if (pos > VCHIQ_SLOT_SIZE) {
  27330. + vchiq_log_error(vchiq_core_log_level,
  27331. + "fsi - pos %x: header %x, "
  27332. + "msgid %x, header->msgid %x, "
  27333. + "header->size %x",
  27334. + pos, (unsigned int)header,
  27335. + msgid, header->msgid,
  27336. + header->size);
  27337. + WARN(1, "invalid slot position\n");
  27338. + }
  27339. + }
  27340. + }
  27341. + }
  27342. +}
  27343. +
  27344. +static int
  27345. +do_abort_bulks(VCHIQ_SERVICE_T *service)
  27346. +{
  27347. + VCHIQ_STATUS_T status;
  27348. +
  27349. + /* Abort any outstanding bulk transfers */
  27350. + if (mutex_lock_interruptible(&service->bulk_mutex) != 0)
  27351. + return 0;
  27352. + abort_outstanding_bulks(service, &service->bulk_tx);
  27353. + abort_outstanding_bulks(service, &service->bulk_rx);
  27354. + mutex_unlock(&service->bulk_mutex);
  27355. +
  27356. + status = notify_bulks(service, &service->bulk_tx, 0/*!retry_poll*/);
  27357. + if (status == VCHIQ_SUCCESS)
  27358. + status = notify_bulks(service, &service->bulk_rx,
  27359. + 0/*!retry_poll*/);
  27360. + return (status == VCHIQ_SUCCESS);
  27361. +}
  27362. +
  27363. +static VCHIQ_STATUS_T
  27364. +close_service_complete(VCHIQ_SERVICE_T *service, int failstate)
  27365. +{
  27366. + VCHIQ_STATUS_T status;
  27367. + int is_server = (service->public_fourcc != VCHIQ_FOURCC_INVALID);
  27368. + int newstate;
  27369. +
  27370. + switch (service->srvstate) {
  27371. + case VCHIQ_SRVSTATE_OPEN:
  27372. + case VCHIQ_SRVSTATE_CLOSESENT:
  27373. + case VCHIQ_SRVSTATE_CLOSERECVD:
  27374. + if (is_server) {
  27375. + if (service->auto_close) {
  27376. + service->client_id = 0;
  27377. + service->remoteport = VCHIQ_PORT_FREE;
  27378. + newstate = VCHIQ_SRVSTATE_LISTENING;
  27379. + } else
  27380. + newstate = VCHIQ_SRVSTATE_CLOSEWAIT;
  27381. + } else
  27382. + newstate = VCHIQ_SRVSTATE_CLOSED;
  27383. + vchiq_set_service_state(service, newstate);
  27384. + break;
  27385. + case VCHIQ_SRVSTATE_LISTENING:
  27386. + break;
  27387. + default:
  27388. + vchiq_log_error(vchiq_core_log_level,
  27389. + "close_service_complete(%x) called in state %s",
  27390. + service->handle, srvstate_names[service->srvstate]);
  27391. + WARN(1, "close_service_complete in unexpected state\n");
  27392. + return VCHIQ_ERROR;
  27393. + }
  27394. +
  27395. + status = make_service_callback(service,
  27396. + VCHIQ_SERVICE_CLOSED, NULL, NULL);
  27397. +
  27398. + if (status != VCHIQ_RETRY) {
  27399. + int uc = service->service_use_count;
  27400. + int i;
  27401. + /* Complete the close process */
  27402. + for (i = 0; i < uc; i++)
  27403. + /* cater for cases where close is forced and the
  27404. + ** client may not close all it's handles */
  27405. + vchiq_release_service_internal(service);
  27406. +
  27407. + service->client_id = 0;
  27408. + service->remoteport = VCHIQ_PORT_FREE;
  27409. +
  27410. + if (service->srvstate == VCHIQ_SRVSTATE_CLOSED)
  27411. + vchiq_free_service_internal(service);
  27412. + else if (service->srvstate != VCHIQ_SRVSTATE_CLOSEWAIT) {
  27413. + if (is_server)
  27414. + service->closing = 0;
  27415. +
  27416. + up(&service->remove_event);
  27417. + }
  27418. + } else
  27419. + vchiq_set_service_state(service, failstate);
  27420. +
  27421. + return status;
  27422. +}
  27423. +
  27424. +/* Called by the slot handler */
  27425. +VCHIQ_STATUS_T
  27426. +vchiq_close_service_internal(VCHIQ_SERVICE_T *service, int close_recvd)
  27427. +{
  27428. + VCHIQ_STATE_T *state = service->state;
  27429. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  27430. + int is_server = (service->public_fourcc != VCHIQ_FOURCC_INVALID);
  27431. +
  27432. + vchiq_log_info(vchiq_core_log_level, "%d: csi:%d,%d (%s)",
  27433. + service->state->id, service->localport, close_recvd,
  27434. + srvstate_names[service->srvstate]);
  27435. +
  27436. + switch (service->srvstate) {
  27437. + case VCHIQ_SRVSTATE_CLOSED:
  27438. + case VCHIQ_SRVSTATE_HIDDEN:
  27439. + case VCHIQ_SRVSTATE_LISTENING:
  27440. + case VCHIQ_SRVSTATE_CLOSEWAIT:
  27441. + if (close_recvd)
  27442. + vchiq_log_error(vchiq_core_log_level,
  27443. + "vchiq_close_service_internal(1) called "
  27444. + "in state %s",
  27445. + srvstate_names[service->srvstate]);
  27446. + else if (is_server) {
  27447. + if (service->srvstate == VCHIQ_SRVSTATE_LISTENING) {
  27448. + status = VCHIQ_ERROR;
  27449. + } else {
  27450. + service->client_id = 0;
  27451. + service->remoteport = VCHIQ_PORT_FREE;
  27452. + if (service->srvstate ==
  27453. + VCHIQ_SRVSTATE_CLOSEWAIT)
  27454. + vchiq_set_service_state(service,
  27455. + VCHIQ_SRVSTATE_LISTENING);
  27456. + }
  27457. + up(&service->remove_event);
  27458. + } else
  27459. + vchiq_free_service_internal(service);
  27460. + break;
  27461. + case VCHIQ_SRVSTATE_OPENING:
  27462. + if (close_recvd) {
  27463. + /* The open was rejected - tell the user */
  27464. + vchiq_set_service_state(service,
  27465. + VCHIQ_SRVSTATE_CLOSEWAIT);
  27466. + up(&service->remove_event);
  27467. + } else {
  27468. + /* Shutdown mid-open - let the other side know */
  27469. + status = queue_message(state, service,
  27470. + VCHIQ_MAKE_MSG
  27471. + (VCHIQ_MSG_CLOSE,
  27472. + service->localport,
  27473. + VCHIQ_MSG_DSTPORT(service->remoteport)),
  27474. + NULL, 0, 0, 0);
  27475. + }
  27476. + break;
  27477. +
  27478. + case VCHIQ_SRVSTATE_OPENSYNC:
  27479. + mutex_lock(&state->sync_mutex);
  27480. + /* Drop through */
  27481. +
  27482. + case VCHIQ_SRVSTATE_OPEN:
  27483. + if (state->is_master || close_recvd) {
  27484. + if (!do_abort_bulks(service))
  27485. + status = VCHIQ_RETRY;
  27486. + }
  27487. +
  27488. + release_service_messages(service);
  27489. +
  27490. + if (status == VCHIQ_SUCCESS)
  27491. + status = queue_message(state, service,
  27492. + VCHIQ_MAKE_MSG
  27493. + (VCHIQ_MSG_CLOSE,
  27494. + service->localport,
  27495. + VCHIQ_MSG_DSTPORT(service->remoteport)),
  27496. + NULL, 0, 0, 0);
  27497. +
  27498. + if (status == VCHIQ_SUCCESS) {
  27499. + if (!close_recvd)
  27500. + break;
  27501. + } else if (service->srvstate == VCHIQ_SRVSTATE_OPENSYNC) {
  27502. + mutex_unlock(&state->sync_mutex);
  27503. + break;
  27504. + } else
  27505. + break;
  27506. +
  27507. + status = close_service_complete(service,
  27508. + VCHIQ_SRVSTATE_CLOSERECVD);
  27509. + break;
  27510. +
  27511. + case VCHIQ_SRVSTATE_CLOSESENT:
  27512. + if (!close_recvd)
  27513. + /* This happens when a process is killed mid-close */
  27514. + break;
  27515. +
  27516. + if (!state->is_master) {
  27517. + if (!do_abort_bulks(service)) {
  27518. + status = VCHIQ_RETRY;
  27519. + break;
  27520. + }
  27521. + }
  27522. +
  27523. + if (status == VCHIQ_SUCCESS)
  27524. + status = close_service_complete(service,
  27525. + VCHIQ_SRVSTATE_CLOSERECVD);
  27526. + break;
  27527. +
  27528. + case VCHIQ_SRVSTATE_CLOSERECVD:
  27529. + if (!close_recvd && is_server)
  27530. + /* Force into LISTENING mode */
  27531. + vchiq_set_service_state(service,
  27532. + VCHIQ_SRVSTATE_LISTENING);
  27533. + status = close_service_complete(service,
  27534. + VCHIQ_SRVSTATE_CLOSERECVD);
  27535. + break;
  27536. +
  27537. + default:
  27538. + vchiq_log_error(vchiq_core_log_level,
  27539. + "vchiq_close_service_internal(%d) called in state %s",
  27540. + close_recvd, srvstate_names[service->srvstate]);
  27541. + break;
  27542. + }
  27543. +
  27544. + return status;
  27545. +}
  27546. +
  27547. +/* Called from the application process upon process death */
  27548. +void
  27549. +vchiq_terminate_service_internal(VCHIQ_SERVICE_T *service)
  27550. +{
  27551. + VCHIQ_STATE_T *state = service->state;
  27552. +
  27553. + vchiq_log_info(vchiq_core_log_level, "%d: tsi - (%d<->%d)",
  27554. + state->id, service->localport, service->remoteport);
  27555. +
  27556. + mark_service_closing(service);
  27557. +
  27558. + /* Mark the service for removal by the slot handler */
  27559. + request_poll(state, service, VCHIQ_POLL_REMOVE);
  27560. +}
  27561. +
  27562. +/* Called from the slot handler */
  27563. +void
  27564. +vchiq_free_service_internal(VCHIQ_SERVICE_T *service)
  27565. +{
  27566. + VCHIQ_STATE_T *state = service->state;
  27567. +
  27568. + vchiq_log_info(vchiq_core_log_level, "%d: fsi - (%d)",
  27569. + state->id, service->localport);
  27570. +
  27571. + switch (service->srvstate) {
  27572. + case VCHIQ_SRVSTATE_OPENING:
  27573. + case VCHIQ_SRVSTATE_CLOSED:
  27574. + case VCHIQ_SRVSTATE_HIDDEN:
  27575. + case VCHIQ_SRVSTATE_LISTENING:
  27576. + case VCHIQ_SRVSTATE_CLOSEWAIT:
  27577. + break;
  27578. + default:
  27579. + vchiq_log_error(vchiq_core_log_level,
  27580. + "%d: fsi - (%d) in state %s",
  27581. + state->id, service->localport,
  27582. + srvstate_names[service->srvstate]);
  27583. + return;
  27584. + }
  27585. +
  27586. + vchiq_set_service_state(service, VCHIQ_SRVSTATE_FREE);
  27587. +
  27588. + up(&service->remove_event);
  27589. +
  27590. + /* Release the initial lock */
  27591. + unlock_service(service);
  27592. +}
  27593. +
  27594. +VCHIQ_STATUS_T
  27595. +vchiq_connect_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance)
  27596. +{
  27597. + VCHIQ_SERVICE_T *service;
  27598. + int i;
  27599. +
  27600. + /* Find all services registered to this client and enable them. */
  27601. + i = 0;
  27602. + while ((service = next_service_by_instance(state, instance,
  27603. + &i)) != NULL) {
  27604. + if (service->srvstate == VCHIQ_SRVSTATE_HIDDEN)
  27605. + vchiq_set_service_state(service,
  27606. + VCHIQ_SRVSTATE_LISTENING);
  27607. + unlock_service(service);
  27608. + }
  27609. +
  27610. + if (state->conn_state == VCHIQ_CONNSTATE_DISCONNECTED) {
  27611. + if (queue_message(state, NULL,
  27612. + VCHIQ_MAKE_MSG(VCHIQ_MSG_CONNECT, 0, 0), NULL, 0,
  27613. + 0, 1) == VCHIQ_RETRY)
  27614. + return VCHIQ_RETRY;
  27615. +
  27616. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTING);
  27617. + }
  27618. +
  27619. + if (state->conn_state == VCHIQ_CONNSTATE_CONNECTING) {
  27620. + if (down_interruptible(&state->connect) != 0)
  27621. + return VCHIQ_RETRY;
  27622. +
  27623. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTED);
  27624. + up(&state->connect);
  27625. + }
  27626. +
  27627. + return VCHIQ_SUCCESS;
  27628. +}
  27629. +
  27630. +VCHIQ_STATUS_T
  27631. +vchiq_shutdown_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance)
  27632. +{
  27633. + VCHIQ_SERVICE_T *service;
  27634. + int i;
  27635. +
  27636. + /* Find all services registered to this client and enable them. */
  27637. + i = 0;
  27638. + while ((service = next_service_by_instance(state, instance,
  27639. + &i)) != NULL) {
  27640. + (void)vchiq_remove_service(service->handle);
  27641. + unlock_service(service);
  27642. + }
  27643. +
  27644. + return VCHIQ_SUCCESS;
  27645. +}
  27646. +
  27647. +VCHIQ_STATUS_T
  27648. +vchiq_pause_internal(VCHIQ_STATE_T *state)
  27649. +{
  27650. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  27651. +
  27652. + switch (state->conn_state) {
  27653. + case VCHIQ_CONNSTATE_CONNECTED:
  27654. + /* Request a pause */
  27655. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_PAUSING);
  27656. + request_poll(state, NULL, 0);
  27657. + break;
  27658. + default:
  27659. + vchiq_log_error(vchiq_core_log_level,
  27660. + "vchiq_pause_internal in state %s\n",
  27661. + conn_state_names[state->conn_state]);
  27662. + status = VCHIQ_ERROR;
  27663. + VCHIQ_STATS_INC(state, error_count);
  27664. + break;
  27665. + }
  27666. +
  27667. + return status;
  27668. +}
  27669. +
  27670. +VCHIQ_STATUS_T
  27671. +vchiq_resume_internal(VCHIQ_STATE_T *state)
  27672. +{
  27673. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  27674. +
  27675. + if (state->conn_state == VCHIQ_CONNSTATE_PAUSED) {
  27676. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_RESUMING);
  27677. + request_poll(state, NULL, 0);
  27678. + } else {
  27679. + status = VCHIQ_ERROR;
  27680. + VCHIQ_STATS_INC(state, error_count);
  27681. + }
  27682. +
  27683. + return status;
  27684. +}
  27685. +
  27686. +VCHIQ_STATUS_T
  27687. +vchiq_close_service(VCHIQ_SERVICE_HANDLE_T handle)
  27688. +{
  27689. + /* Unregister the service */
  27690. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  27691. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  27692. +
  27693. + if (!service)
  27694. + return VCHIQ_ERROR;
  27695. +
  27696. + vchiq_log_info(vchiq_core_log_level,
  27697. + "%d: close_service:%d",
  27698. + service->state->id, service->localport);
  27699. +
  27700. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  27701. + (service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  27702. + (service->srvstate == VCHIQ_SRVSTATE_HIDDEN)) {
  27703. + unlock_service(service);
  27704. + return VCHIQ_ERROR;
  27705. + }
  27706. +
  27707. + mark_service_closing(service);
  27708. +
  27709. + if (current == service->state->slot_handler_thread) {
  27710. + status = vchiq_close_service_internal(service,
  27711. + 0/*!close_recvd*/);
  27712. + BUG_ON(status == VCHIQ_RETRY);
  27713. + } else {
  27714. + /* Mark the service for termination by the slot handler */
  27715. + request_poll(service->state, service, VCHIQ_POLL_TERMINATE);
  27716. + }
  27717. +
  27718. + while (1) {
  27719. + if (down_interruptible(&service->remove_event) != 0) {
  27720. + status = VCHIQ_RETRY;
  27721. + break;
  27722. + }
  27723. +
  27724. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  27725. + (service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  27726. + (service->srvstate == VCHIQ_SRVSTATE_OPEN))
  27727. + break;
  27728. +
  27729. + vchiq_log_warning(vchiq_core_log_level,
  27730. + "%d: close_service:%d - waiting in state %s",
  27731. + service->state->id, service->localport,
  27732. + srvstate_names[service->srvstate]);
  27733. + }
  27734. +
  27735. + if ((status == VCHIQ_SUCCESS) &&
  27736. + (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  27737. + (service->srvstate != VCHIQ_SRVSTATE_LISTENING))
  27738. + status = VCHIQ_ERROR;
  27739. +
  27740. + unlock_service(service);
  27741. +
  27742. + return status;
  27743. +}
  27744. +
  27745. +VCHIQ_STATUS_T
  27746. +vchiq_remove_service(VCHIQ_SERVICE_HANDLE_T handle)
  27747. +{
  27748. + /* Unregister the service */
  27749. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  27750. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  27751. +
  27752. + if (!service)
  27753. + return VCHIQ_ERROR;
  27754. +
  27755. + vchiq_log_info(vchiq_core_log_level,
  27756. + "%d: remove_service:%d",
  27757. + service->state->id, service->localport);
  27758. +
  27759. + if (service->srvstate == VCHIQ_SRVSTATE_FREE) {
  27760. + unlock_service(service);
  27761. + return VCHIQ_ERROR;
  27762. + }
  27763. +
  27764. + mark_service_closing(service);
  27765. +
  27766. + if ((service->srvstate == VCHIQ_SRVSTATE_HIDDEN) ||
  27767. + (current == service->state->slot_handler_thread)) {
  27768. + /* Make it look like a client, because it must be removed and
  27769. + not left in the LISTENING state. */
  27770. + service->public_fourcc = VCHIQ_FOURCC_INVALID;
  27771. +
  27772. + status = vchiq_close_service_internal(service,
  27773. + 0/*!close_recvd*/);
  27774. + BUG_ON(status == VCHIQ_RETRY);
  27775. + } else {
  27776. + /* Mark the service for removal by the slot handler */
  27777. + request_poll(service->state, service, VCHIQ_POLL_REMOVE);
  27778. + }
  27779. + while (1) {
  27780. + if (down_interruptible(&service->remove_event) != 0) {
  27781. + status = VCHIQ_RETRY;
  27782. + break;
  27783. + }
  27784. +
  27785. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  27786. + (service->srvstate == VCHIQ_SRVSTATE_OPEN))
  27787. + break;
  27788. +
  27789. + vchiq_log_warning(vchiq_core_log_level,
  27790. + "%d: remove_service:%d - waiting in state %s",
  27791. + service->state->id, service->localport,
  27792. + srvstate_names[service->srvstate]);
  27793. + }
  27794. +
  27795. + if ((status == VCHIQ_SUCCESS) &&
  27796. + (service->srvstate != VCHIQ_SRVSTATE_FREE))
  27797. + status = VCHIQ_ERROR;
  27798. +
  27799. + unlock_service(service);
  27800. +
  27801. + return status;
  27802. +}
  27803. +
  27804. +
  27805. +/* This function may be called by kernel threads or user threads.
  27806. + * User threads may receive VCHIQ_RETRY to indicate that a signal has been
  27807. + * received and the call should be retried after being returned to user
  27808. + * context.
  27809. + * When called in blocking mode, the userdata field points to a bulk_waiter
  27810. + * structure.
  27811. + */
  27812. +VCHIQ_STATUS_T
  27813. +vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle,
  27814. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, void *userdata,
  27815. + VCHIQ_BULK_MODE_T mode, VCHIQ_BULK_DIR_T dir)
  27816. +{
  27817. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  27818. + VCHIQ_BULK_QUEUE_T *queue;
  27819. + VCHIQ_BULK_T *bulk;
  27820. + VCHIQ_STATE_T *state;
  27821. + struct bulk_waiter *bulk_waiter = NULL;
  27822. + const char dir_char = (dir == VCHIQ_BULK_TRANSMIT) ? 't' : 'r';
  27823. + const int dir_msgtype = (dir == VCHIQ_BULK_TRANSMIT) ?
  27824. + VCHIQ_MSG_BULK_TX : VCHIQ_MSG_BULK_RX;
  27825. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  27826. +
  27827. + if (!service ||
  27828. + (service->srvstate != VCHIQ_SRVSTATE_OPEN) ||
  27829. + ((memhandle == VCHI_MEM_HANDLE_INVALID) && (offset == NULL)) ||
  27830. + (vchiq_check_service(service) != VCHIQ_SUCCESS))
  27831. + goto error_exit;
  27832. +
  27833. + switch (mode) {
  27834. + case VCHIQ_BULK_MODE_NOCALLBACK:
  27835. + case VCHIQ_BULK_MODE_CALLBACK:
  27836. + break;
  27837. + case VCHIQ_BULK_MODE_BLOCKING:
  27838. + bulk_waiter = (struct bulk_waiter *)userdata;
  27839. + sema_init(&bulk_waiter->event, 0);
  27840. + bulk_waiter->actual = 0;
  27841. + bulk_waiter->bulk = NULL;
  27842. + break;
  27843. + case VCHIQ_BULK_MODE_WAITING:
  27844. + bulk_waiter = (struct bulk_waiter *)userdata;
  27845. + bulk = bulk_waiter->bulk;
  27846. + goto waiting;
  27847. + default:
  27848. + goto error_exit;
  27849. + }
  27850. +
  27851. + state = service->state;
  27852. +
  27853. + queue = (dir == VCHIQ_BULK_TRANSMIT) ?
  27854. + &service->bulk_tx : &service->bulk_rx;
  27855. +
  27856. + if (mutex_lock_interruptible(&service->bulk_mutex) != 0) {
  27857. + status = VCHIQ_RETRY;
  27858. + goto error_exit;
  27859. + }
  27860. +
  27861. + if (queue->local_insert == queue->remove + VCHIQ_NUM_SERVICE_BULKS) {
  27862. + VCHIQ_SERVICE_STATS_INC(service, bulk_stalls);
  27863. + do {
  27864. + mutex_unlock(&service->bulk_mutex);
  27865. + if (down_interruptible(&service->bulk_remove_event)
  27866. + != 0) {
  27867. + status = VCHIQ_RETRY;
  27868. + goto error_exit;
  27869. + }
  27870. + if (mutex_lock_interruptible(&service->bulk_mutex)
  27871. + != 0) {
  27872. + status = VCHIQ_RETRY;
  27873. + goto error_exit;
  27874. + }
  27875. + } while (queue->local_insert == queue->remove +
  27876. + VCHIQ_NUM_SERVICE_BULKS);
  27877. + }
  27878. +
  27879. + bulk = &queue->bulks[BULK_INDEX(queue->local_insert)];
  27880. +
  27881. + bulk->mode = mode;
  27882. + bulk->dir = dir;
  27883. + bulk->userdata = userdata;
  27884. + bulk->size = size;
  27885. + bulk->actual = VCHIQ_BULK_ACTUAL_ABORTED;
  27886. +
  27887. + if (vchiq_prepare_bulk_data(bulk, memhandle, offset, size, dir) !=
  27888. + VCHIQ_SUCCESS)
  27889. + goto unlock_error_exit;
  27890. +
  27891. + wmb();
  27892. +
  27893. + vchiq_log_info(vchiq_core_log_level,
  27894. + "%d: bt (%d->%d) %cx %x@%x %x",
  27895. + state->id,
  27896. + service->localport, service->remoteport, dir_char,
  27897. + size, (unsigned int)bulk->data, (unsigned int)userdata);
  27898. +
  27899. + if (state->is_master) {
  27900. + queue->local_insert++;
  27901. + if (resolve_bulks(service, queue))
  27902. + request_poll(state, service,
  27903. + (dir == VCHIQ_BULK_TRANSMIT) ?
  27904. + VCHIQ_POLL_TXNOTIFY : VCHIQ_POLL_RXNOTIFY);
  27905. + } else {
  27906. + int payload[2] = { (int)bulk->data, bulk->size };
  27907. + VCHIQ_ELEMENT_T element = { payload, sizeof(payload) };
  27908. +
  27909. + status = queue_message(state, NULL,
  27910. + VCHIQ_MAKE_MSG(dir_msgtype,
  27911. + service->localport, service->remoteport),
  27912. + &element, 1, sizeof(payload), 1);
  27913. + if (status != VCHIQ_SUCCESS) {
  27914. + vchiq_complete_bulk(bulk);
  27915. + goto unlock_error_exit;
  27916. + }
  27917. + queue->local_insert++;
  27918. + }
  27919. +
  27920. + mutex_unlock(&service->bulk_mutex);
  27921. +
  27922. + vchiq_log_trace(vchiq_core_log_level,
  27923. + "%d: bt:%d %cx li=%x ri=%x p=%x",
  27924. + state->id,
  27925. + service->localport, dir_char,
  27926. + queue->local_insert, queue->remote_insert, queue->process);
  27927. +
  27928. +waiting:
  27929. + unlock_service(service);
  27930. +
  27931. + status = VCHIQ_SUCCESS;
  27932. +
  27933. + if (bulk_waiter) {
  27934. + bulk_waiter->bulk = bulk;
  27935. + if (down_interruptible(&bulk_waiter->event) != 0)
  27936. + status = VCHIQ_RETRY;
  27937. + else if (bulk_waiter->actual == VCHIQ_BULK_ACTUAL_ABORTED)
  27938. + status = VCHIQ_ERROR;
  27939. + }
  27940. +
  27941. + return status;
  27942. +
  27943. +unlock_error_exit:
  27944. + mutex_unlock(&service->bulk_mutex);
  27945. +
  27946. +error_exit:
  27947. + if (service)
  27948. + unlock_service(service);
  27949. + return status;
  27950. +}
  27951. +
  27952. +VCHIQ_STATUS_T
  27953. +vchiq_queue_message(VCHIQ_SERVICE_HANDLE_T handle,
  27954. + const VCHIQ_ELEMENT_T *elements, unsigned int count)
  27955. +{
  27956. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  27957. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  27958. +
  27959. + unsigned int size = 0;
  27960. + unsigned int i;
  27961. +
  27962. + if (!service ||
  27963. + (vchiq_check_service(service) != VCHIQ_SUCCESS))
  27964. + goto error_exit;
  27965. +
  27966. + for (i = 0; i < (unsigned int)count; i++) {
  27967. + if (elements[i].size) {
  27968. + if (elements[i].data == NULL) {
  27969. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  27970. + goto error_exit;
  27971. + }
  27972. + size += elements[i].size;
  27973. + }
  27974. + }
  27975. +
  27976. + if (size > VCHIQ_MAX_MSG_SIZE) {
  27977. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  27978. + goto error_exit;
  27979. + }
  27980. +
  27981. + switch (service->srvstate) {
  27982. + case VCHIQ_SRVSTATE_OPEN:
  27983. + status = queue_message(service->state, service,
  27984. + VCHIQ_MAKE_MSG(VCHIQ_MSG_DATA,
  27985. + service->localport,
  27986. + service->remoteport),
  27987. + elements, count, size, 1);
  27988. + break;
  27989. + case VCHIQ_SRVSTATE_OPENSYNC:
  27990. + status = queue_message_sync(service->state, service,
  27991. + VCHIQ_MAKE_MSG(VCHIQ_MSG_DATA,
  27992. + service->localport,
  27993. + service->remoteport),
  27994. + elements, count, size, 1);
  27995. + break;
  27996. + default:
  27997. + status = VCHIQ_ERROR;
  27998. + break;
  27999. + }
  28000. +
  28001. +error_exit:
  28002. + if (service)
  28003. + unlock_service(service);
  28004. +
  28005. + return status;
  28006. +}
  28007. +
  28008. +void
  28009. +vchiq_release_message(VCHIQ_SERVICE_HANDLE_T handle, VCHIQ_HEADER_T *header)
  28010. +{
  28011. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  28012. + VCHIQ_SHARED_STATE_T *remote;
  28013. + VCHIQ_STATE_T *state;
  28014. + int slot_index;
  28015. +
  28016. + if (!service)
  28017. + return;
  28018. +
  28019. + state = service->state;
  28020. + remote = state->remote;
  28021. +
  28022. + slot_index = SLOT_INDEX_FROM_DATA(state, (void *)header);
  28023. +
  28024. + if ((slot_index >= remote->slot_first) &&
  28025. + (slot_index <= remote->slot_last)) {
  28026. + int msgid = header->msgid;
  28027. + if (msgid & VCHIQ_MSGID_CLAIMED) {
  28028. + VCHIQ_SLOT_INFO_T *slot_info =
  28029. + SLOT_INFO_FROM_INDEX(state, slot_index);
  28030. +
  28031. + release_slot(state, slot_info, header, service);
  28032. + }
  28033. + } else if (slot_index == remote->slot_sync)
  28034. + release_message_sync(state, header);
  28035. +
  28036. + unlock_service(service);
  28037. +}
  28038. +
  28039. +static void
  28040. +release_message_sync(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header)
  28041. +{
  28042. + header->msgid = VCHIQ_MSGID_PADDING;
  28043. + wmb();
  28044. + remote_event_signal(&state->remote->sync_release);
  28045. +}
  28046. +
  28047. +VCHIQ_STATUS_T
  28048. +vchiq_get_peer_version(VCHIQ_SERVICE_HANDLE_T handle, short *peer_version)
  28049. +{
  28050. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  28051. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  28052. +
  28053. + if (!service ||
  28054. + (vchiq_check_service(service) != VCHIQ_SUCCESS) ||
  28055. + !peer_version)
  28056. + goto exit;
  28057. + *peer_version = service->peer_version;
  28058. + status = VCHIQ_SUCCESS;
  28059. +
  28060. +exit:
  28061. + if (service)
  28062. + unlock_service(service);
  28063. + return status;
  28064. +}
  28065. +
  28066. +VCHIQ_STATUS_T
  28067. +vchiq_get_config(VCHIQ_INSTANCE_T instance,
  28068. + int config_size, VCHIQ_CONFIG_T *pconfig)
  28069. +{
  28070. + VCHIQ_CONFIG_T config;
  28071. +
  28072. + (void)instance;
  28073. +
  28074. + config.max_msg_size = VCHIQ_MAX_MSG_SIZE;
  28075. + config.bulk_threshold = VCHIQ_MAX_MSG_SIZE;
  28076. + config.max_outstanding_bulks = VCHIQ_NUM_SERVICE_BULKS;
  28077. + config.max_services = VCHIQ_MAX_SERVICES;
  28078. + config.version = VCHIQ_VERSION;
  28079. + config.version_min = VCHIQ_VERSION_MIN;
  28080. +
  28081. + if (config_size > sizeof(VCHIQ_CONFIG_T))
  28082. + return VCHIQ_ERROR;
  28083. +
  28084. + memcpy(pconfig, &config,
  28085. + min(config_size, (int)(sizeof(VCHIQ_CONFIG_T))));
  28086. +
  28087. + return VCHIQ_SUCCESS;
  28088. +}
  28089. +
  28090. +VCHIQ_STATUS_T
  28091. +vchiq_set_service_option(VCHIQ_SERVICE_HANDLE_T handle,
  28092. + VCHIQ_SERVICE_OPTION_T option, int value)
  28093. +{
  28094. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  28095. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  28096. +
  28097. + if (service) {
  28098. + switch (option) {
  28099. + case VCHIQ_SERVICE_OPTION_AUTOCLOSE:
  28100. + service->auto_close = value;
  28101. + status = VCHIQ_SUCCESS;
  28102. + break;
  28103. +
  28104. + case VCHIQ_SERVICE_OPTION_SLOT_QUOTA: {
  28105. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  28106. + &service->state->service_quotas[
  28107. + service->localport];
  28108. + if (value == 0)
  28109. + value = service->state->default_slot_quota;
  28110. + if ((value >= service_quota->slot_use_count) &&
  28111. + (value < (unsigned short)~0)) {
  28112. + service_quota->slot_quota = value;
  28113. + if ((value >= service_quota->slot_use_count) &&
  28114. + (service_quota->message_quota >=
  28115. + service_quota->message_use_count)) {
  28116. + /* Signal the service that it may have
  28117. + ** dropped below its quota */
  28118. + up(&service_quota->quota_event);
  28119. + }
  28120. + status = VCHIQ_SUCCESS;
  28121. + }
  28122. + } break;
  28123. +
  28124. + case VCHIQ_SERVICE_OPTION_MESSAGE_QUOTA: {
  28125. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  28126. + &service->state->service_quotas[
  28127. + service->localport];
  28128. + if (value == 0)
  28129. + value = service->state->default_message_quota;
  28130. + if ((value >= service_quota->message_use_count) &&
  28131. + (value < (unsigned short)~0)) {
  28132. + service_quota->message_quota = value;
  28133. + if ((value >=
  28134. + service_quota->message_use_count) &&
  28135. + (service_quota->slot_quota >=
  28136. + service_quota->slot_use_count))
  28137. + /* Signal the service that it may have
  28138. + ** dropped below its quota */
  28139. + up(&service_quota->quota_event);
  28140. + status = VCHIQ_SUCCESS;
  28141. + }
  28142. + } break;
  28143. +
  28144. + case VCHIQ_SERVICE_OPTION_SYNCHRONOUS:
  28145. + if ((service->srvstate == VCHIQ_SRVSTATE_HIDDEN) ||
  28146. + (service->srvstate ==
  28147. + VCHIQ_SRVSTATE_LISTENING)) {
  28148. + service->sync = value;
  28149. + status = VCHIQ_SUCCESS;
  28150. + }
  28151. + break;
  28152. +
  28153. + default:
  28154. + break;
  28155. + }
  28156. + unlock_service(service);
  28157. + }
  28158. +
  28159. + return status;
  28160. +}
  28161. +
  28162. +void
  28163. +vchiq_dump_shared_state(void *dump_context, VCHIQ_STATE_T *state,
  28164. + VCHIQ_SHARED_STATE_T *shared, const char *label)
  28165. +{
  28166. + static const char *const debug_names[] = {
  28167. + "<entries>",
  28168. + "SLOT_HANDLER_COUNT",
  28169. + "SLOT_HANDLER_LINE",
  28170. + "PARSE_LINE",
  28171. + "PARSE_HEADER",
  28172. + "PARSE_MSGID",
  28173. + "AWAIT_COMPLETION_LINE",
  28174. + "DEQUEUE_MESSAGE_LINE",
  28175. + "SERVICE_CALLBACK_LINE",
  28176. + "MSG_QUEUE_FULL_COUNT",
  28177. + "COMPLETION_QUEUE_FULL_COUNT"
  28178. + };
  28179. + int i;
  28180. +
  28181. + char buf[80];
  28182. + int len;
  28183. + len = snprintf(buf, sizeof(buf),
  28184. + " %s: slots %d-%d tx_pos=%x recycle=%x",
  28185. + label, shared->slot_first, shared->slot_last,
  28186. + shared->tx_pos, shared->slot_queue_recycle);
  28187. + vchiq_dump(dump_context, buf, len + 1);
  28188. +
  28189. + len = snprintf(buf, sizeof(buf),
  28190. + " Slots claimed:");
  28191. + vchiq_dump(dump_context, buf, len + 1);
  28192. +
  28193. + for (i = shared->slot_first; i <= shared->slot_last; i++) {
  28194. + VCHIQ_SLOT_INFO_T slot_info = *SLOT_INFO_FROM_INDEX(state, i);
  28195. + if (slot_info.use_count != slot_info.release_count) {
  28196. + len = snprintf(buf, sizeof(buf),
  28197. + " %d: %d/%d", i, slot_info.use_count,
  28198. + slot_info.release_count);
  28199. + vchiq_dump(dump_context, buf, len + 1);
  28200. + }
  28201. + }
  28202. +
  28203. + for (i = 1; i < shared->debug[DEBUG_ENTRIES]; i++) {
  28204. + len = snprintf(buf, sizeof(buf), " DEBUG: %s = %d(%x)",
  28205. + debug_names[i], shared->debug[i], shared->debug[i]);
  28206. + vchiq_dump(dump_context, buf, len + 1);
  28207. + }
  28208. +}
  28209. +
  28210. +void
  28211. +vchiq_dump_state(void *dump_context, VCHIQ_STATE_T *state)
  28212. +{
  28213. + char buf[80];
  28214. + int len;
  28215. + int i;
  28216. +
  28217. + len = snprintf(buf, sizeof(buf), "State %d: %s", state->id,
  28218. + conn_state_names[state->conn_state]);
  28219. + vchiq_dump(dump_context, buf, len + 1);
  28220. +
  28221. + len = snprintf(buf, sizeof(buf),
  28222. + " tx_pos=%x(@%x), rx_pos=%x(@%x)",
  28223. + state->local->tx_pos,
  28224. + (uint32_t)state->tx_data +
  28225. + (state->local_tx_pos & VCHIQ_SLOT_MASK),
  28226. + state->rx_pos,
  28227. + (uint32_t)state->rx_data +
  28228. + (state->rx_pos & VCHIQ_SLOT_MASK));
  28229. + vchiq_dump(dump_context, buf, len + 1);
  28230. +
  28231. + len = snprintf(buf, sizeof(buf),
  28232. + " Version: %d (min %d)",
  28233. + VCHIQ_VERSION, VCHIQ_VERSION_MIN);
  28234. + vchiq_dump(dump_context, buf, len + 1);
  28235. +
  28236. + if (VCHIQ_ENABLE_STATS) {
  28237. + len = snprintf(buf, sizeof(buf),
  28238. + " Stats: ctrl_tx_count=%d, ctrl_rx_count=%d, "
  28239. + "error_count=%d",
  28240. + state->stats.ctrl_tx_count, state->stats.ctrl_rx_count,
  28241. + state->stats.error_count);
  28242. + vchiq_dump(dump_context, buf, len + 1);
  28243. + }
  28244. +
  28245. + len = snprintf(buf, sizeof(buf),
  28246. + " Slots: %d available (%d data), %d recyclable, %d stalls "
  28247. + "(%d data)",
  28248. + ((state->slot_queue_available * VCHIQ_SLOT_SIZE) -
  28249. + state->local_tx_pos) / VCHIQ_SLOT_SIZE,
  28250. + state->data_quota - state->data_use_count,
  28251. + state->local->slot_queue_recycle - state->slot_queue_available,
  28252. + state->stats.slot_stalls, state->stats.data_stalls);
  28253. + vchiq_dump(dump_context, buf, len + 1);
  28254. +
  28255. + vchiq_dump_platform_state(dump_context);
  28256. +
  28257. + vchiq_dump_shared_state(dump_context, state, state->local, "Local");
  28258. + vchiq_dump_shared_state(dump_context, state, state->remote, "Remote");
  28259. +
  28260. + vchiq_dump_platform_instances(dump_context);
  28261. +
  28262. + for (i = 0; i < state->unused_service; i++) {
  28263. + VCHIQ_SERVICE_T *service = find_service_by_port(state, i);
  28264. +
  28265. + if (service) {
  28266. + vchiq_dump_service_state(dump_context, service);
  28267. + unlock_service(service);
  28268. + }
  28269. + }
  28270. +}
  28271. +
  28272. +void
  28273. +vchiq_dump_service_state(void *dump_context, VCHIQ_SERVICE_T *service)
  28274. +{
  28275. + char buf[80];
  28276. + int len;
  28277. +
  28278. + len = snprintf(buf, sizeof(buf), "Service %d: %s (ref %u)",
  28279. + service->localport, srvstate_names[service->srvstate],
  28280. + service->ref_count - 1); /*Don't include the lock just taken*/
  28281. +
  28282. + if (service->srvstate != VCHIQ_SRVSTATE_FREE) {
  28283. + char remoteport[30];
  28284. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  28285. + &service->state->service_quotas[service->localport];
  28286. + int fourcc = service->base.fourcc;
  28287. + int tx_pending, rx_pending;
  28288. + if (service->remoteport != VCHIQ_PORT_FREE) {
  28289. + int len2 = snprintf(remoteport, sizeof(remoteport),
  28290. + "%d", service->remoteport);
  28291. + if (service->public_fourcc != VCHIQ_FOURCC_INVALID)
  28292. + snprintf(remoteport + len2,
  28293. + sizeof(remoteport) - len2,
  28294. + " (client %x)", service->client_id);
  28295. + } else
  28296. + strcpy(remoteport, "n/a");
  28297. +
  28298. + len += snprintf(buf + len, sizeof(buf) - len,
  28299. + " '%c%c%c%c' remote %s (msg use %d/%d, slot use %d/%d)",
  28300. + VCHIQ_FOURCC_AS_4CHARS(fourcc),
  28301. + remoteport,
  28302. + service_quota->message_use_count,
  28303. + service_quota->message_quota,
  28304. + service_quota->slot_use_count,
  28305. + service_quota->slot_quota);
  28306. +
  28307. + vchiq_dump(dump_context, buf, len + 1);
  28308. +
  28309. + tx_pending = service->bulk_tx.local_insert -
  28310. + service->bulk_tx.remote_insert;
  28311. +
  28312. + rx_pending = service->bulk_rx.local_insert -
  28313. + service->bulk_rx.remote_insert;
  28314. +
  28315. + len = snprintf(buf, sizeof(buf),
  28316. + " Bulk: tx_pending=%d (size %d),"
  28317. + " rx_pending=%d (size %d)",
  28318. + tx_pending,
  28319. + tx_pending ? service->bulk_tx.bulks[
  28320. + BULK_INDEX(service->bulk_tx.remove)].size : 0,
  28321. + rx_pending,
  28322. + rx_pending ? service->bulk_rx.bulks[
  28323. + BULK_INDEX(service->bulk_rx.remove)].size : 0);
  28324. +
  28325. + if (VCHIQ_ENABLE_STATS) {
  28326. + vchiq_dump(dump_context, buf, len + 1);
  28327. +
  28328. + len = snprintf(buf, sizeof(buf),
  28329. + " Ctrl: tx_count=%d, tx_bytes=%llu, "
  28330. + "rx_count=%d, rx_bytes=%llu",
  28331. + service->stats.ctrl_tx_count,
  28332. + service->stats.ctrl_tx_bytes,
  28333. + service->stats.ctrl_rx_count,
  28334. + service->stats.ctrl_rx_bytes);
  28335. + vchiq_dump(dump_context, buf, len + 1);
  28336. +
  28337. + len = snprintf(buf, sizeof(buf),
  28338. + " Bulk: tx_count=%d, tx_bytes=%llu, "
  28339. + "rx_count=%d, rx_bytes=%llu",
  28340. + service->stats.bulk_tx_count,
  28341. + service->stats.bulk_tx_bytes,
  28342. + service->stats.bulk_rx_count,
  28343. + service->stats.bulk_rx_bytes);
  28344. + vchiq_dump(dump_context, buf, len + 1);
  28345. +
  28346. + len = snprintf(buf, sizeof(buf),
  28347. + " %d quota stalls, %d slot stalls, "
  28348. + "%d bulk stalls, %d aborted, %d errors",
  28349. + service->stats.quota_stalls,
  28350. + service->stats.slot_stalls,
  28351. + service->stats.bulk_stalls,
  28352. + service->stats.bulk_aborted_count,
  28353. + service->stats.error_count);
  28354. + }
  28355. + }
  28356. +
  28357. + vchiq_dump(dump_context, buf, len + 1);
  28358. +
  28359. + if (service->srvstate != VCHIQ_SRVSTATE_FREE)
  28360. + vchiq_dump_platform_service_state(dump_context, service);
  28361. +}
  28362. +
  28363. +
  28364. +void
  28365. +vchiq_loud_error_header(void)
  28366. +{
  28367. + vchiq_log_error(vchiq_core_log_level,
  28368. + "============================================================"
  28369. + "================");
  28370. + vchiq_log_error(vchiq_core_log_level,
  28371. + "============================================================"
  28372. + "================");
  28373. + vchiq_log_error(vchiq_core_log_level, "=====");
  28374. +}
  28375. +
  28376. +void
  28377. +vchiq_loud_error_footer(void)
  28378. +{
  28379. + vchiq_log_error(vchiq_core_log_level, "=====");
  28380. + vchiq_log_error(vchiq_core_log_level,
  28381. + "============================================================"
  28382. + "================");
  28383. + vchiq_log_error(vchiq_core_log_level,
  28384. + "============================================================"
  28385. + "================");
  28386. +}
  28387. +
  28388. +
  28389. +VCHIQ_STATUS_T vchiq_send_remote_use(VCHIQ_STATE_T *state)
  28390. +{
  28391. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  28392. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  28393. + status = queue_message(state, NULL,
  28394. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_USE, 0, 0),
  28395. + NULL, 0, 0, 0);
  28396. + return status;
  28397. +}
  28398. +
  28399. +VCHIQ_STATUS_T vchiq_send_remote_release(VCHIQ_STATE_T *state)
  28400. +{
  28401. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  28402. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  28403. + status = queue_message(state, NULL,
  28404. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_RELEASE, 0, 0),
  28405. + NULL, 0, 0, 0);
  28406. + return status;
  28407. +}
  28408. +
  28409. +VCHIQ_STATUS_T vchiq_send_remote_use_active(VCHIQ_STATE_T *state)
  28410. +{
  28411. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  28412. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  28413. + status = queue_message(state, NULL,
  28414. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_USE_ACTIVE, 0, 0),
  28415. + NULL, 0, 0, 0);
  28416. + return status;
  28417. +}
  28418. +
  28419. +void vchiq_log_dump_mem(const char *label, uint32_t addr, const void *voidMem,
  28420. + size_t numBytes)
  28421. +{
  28422. + const uint8_t *mem = (const uint8_t *)voidMem;
  28423. + size_t offset;
  28424. + char lineBuf[100];
  28425. + char *s;
  28426. +
  28427. + while (numBytes > 0) {
  28428. + s = lineBuf;
  28429. +
  28430. + for (offset = 0; offset < 16; offset++) {
  28431. + if (offset < numBytes)
  28432. + s += snprintf(s, 4, "%02x ", mem[offset]);
  28433. + else
  28434. + s += snprintf(s, 4, " ");
  28435. + }
  28436. +
  28437. + for (offset = 0; offset < 16; offset++) {
  28438. + if (offset < numBytes) {
  28439. + uint8_t ch = mem[offset];
  28440. +
  28441. + if ((ch < ' ') || (ch > '~'))
  28442. + ch = '.';
  28443. + *s++ = (char)ch;
  28444. + }
  28445. + }
  28446. + *s++ = '\0';
  28447. +
  28448. + if ((label != NULL) && (*label != '\0'))
  28449. + vchiq_log_trace(VCHIQ_LOG_TRACE,
  28450. + "%s: %08x: %s", label, addr, lineBuf);
  28451. + else
  28452. + vchiq_log_trace(VCHIQ_LOG_TRACE,
  28453. + "%08x: %s", addr, lineBuf);
  28454. +
  28455. + addr += 16;
  28456. + mem += 16;
  28457. + if (numBytes > 16)
  28458. + numBytes -= 16;
  28459. + else
  28460. + numBytes = 0;
  28461. + }
  28462. +}
  28463. diff -Nur linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h
  28464. --- linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h 1970-01-01 01:00:00.000000000 +0100
  28465. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h 2014-04-13 17:32:57.000000000 +0200
  28466. @@ -0,0 +1,706 @@
  28467. +/**
  28468. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  28469. + *
  28470. + * Redistribution and use in source and binary forms, with or without
  28471. + * modification, are permitted provided that the following conditions
  28472. + * are met:
  28473. + * 1. Redistributions of source code must retain the above copyright
  28474. + * notice, this list of conditions, and the following disclaimer,
  28475. + * without modification.
  28476. + * 2. Redistributions in binary form must reproduce the above copyright
  28477. + * notice, this list of conditions and the following disclaimer in the
  28478. + * documentation and/or other materials provided with the distribution.
  28479. + * 3. The names of the above-listed copyright holders may not be used
  28480. + * to endorse or promote products derived from this software without
  28481. + * specific prior written permission.
  28482. + *
  28483. + * ALTERNATIVELY, this software may be distributed under the terms of the
  28484. + * GNU General Public License ("GPL") version 2, as published by the Free
  28485. + * Software Foundation.
  28486. + *
  28487. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28488. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28489. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28490. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28491. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28492. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28493. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28494. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28495. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28496. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28497. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28498. + */
  28499. +
  28500. +#ifndef VCHIQ_CORE_H
  28501. +#define VCHIQ_CORE_H
  28502. +
  28503. +#include <linux/mutex.h>
  28504. +#include <linux/semaphore.h>
  28505. +#include <linux/kthread.h>
  28506. +
  28507. +#include "vchiq_cfg.h"
  28508. +
  28509. +#include "vchiq.h"
  28510. +
  28511. +/* Run time control of log level, based on KERN_XXX level. */
  28512. +#define VCHIQ_LOG_DEFAULT 4
  28513. +#define VCHIQ_LOG_ERROR 3
  28514. +#define VCHIQ_LOG_WARNING 4
  28515. +#define VCHIQ_LOG_INFO 6
  28516. +#define VCHIQ_LOG_TRACE 7
  28517. +
  28518. +#define VCHIQ_LOG_PREFIX KERN_INFO "vchiq: "
  28519. +
  28520. +#ifndef vchiq_log_error
  28521. +#define vchiq_log_error(cat, fmt, ...) \
  28522. + do { if (cat >= VCHIQ_LOG_ERROR) \
  28523. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  28524. +#endif
  28525. +#ifndef vchiq_log_warning
  28526. +#define vchiq_log_warning(cat, fmt, ...) \
  28527. + do { if (cat >= VCHIQ_LOG_WARNING) \
  28528. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  28529. +#endif
  28530. +#ifndef vchiq_log_info
  28531. +#define vchiq_log_info(cat, fmt, ...) \
  28532. + do { if (cat >= VCHIQ_LOG_INFO) \
  28533. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  28534. +#endif
  28535. +#ifndef vchiq_log_trace
  28536. +#define vchiq_log_trace(cat, fmt, ...) \
  28537. + do { if (cat >= VCHIQ_LOG_TRACE) \
  28538. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  28539. +#endif
  28540. +
  28541. +#define vchiq_loud_error(...) \
  28542. + vchiq_log_error(vchiq_core_log_level, "===== " __VA_ARGS__)
  28543. +
  28544. +#ifndef vchiq_static_assert
  28545. +#define vchiq_static_assert(cond) __attribute__((unused)) \
  28546. + extern int vchiq_static_assert[(cond) ? 1 : -1]
  28547. +#endif
  28548. +
  28549. +#define IS_POW2(x) (x && ((x & (x - 1)) == 0))
  28550. +
  28551. +/* Ensure that the slot size and maximum number of slots are powers of 2 */
  28552. +vchiq_static_assert(IS_POW2(VCHIQ_SLOT_SIZE));
  28553. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SLOTS));
  28554. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SLOTS_PER_SIDE));
  28555. +
  28556. +#define VCHIQ_SLOT_MASK (VCHIQ_SLOT_SIZE - 1)
  28557. +#define VCHIQ_SLOT_QUEUE_MASK (VCHIQ_MAX_SLOTS_PER_SIDE - 1)
  28558. +#define VCHIQ_SLOT_ZERO_SLOTS ((sizeof(VCHIQ_SLOT_ZERO_T) + \
  28559. + VCHIQ_SLOT_SIZE - 1) / VCHIQ_SLOT_SIZE)
  28560. +
  28561. +#define VCHIQ_MSG_PADDING 0 /* - */
  28562. +#define VCHIQ_MSG_CONNECT 1 /* - */
  28563. +#define VCHIQ_MSG_OPEN 2 /* + (srcport, -), fourcc, client_id */
  28564. +#define VCHIQ_MSG_OPENACK 3 /* + (srcport, dstport) */
  28565. +#define VCHIQ_MSG_CLOSE 4 /* + (srcport, dstport) */
  28566. +#define VCHIQ_MSG_DATA 5 /* + (srcport, dstport) */
  28567. +#define VCHIQ_MSG_BULK_RX 6 /* + (srcport, dstport), data, size */
  28568. +#define VCHIQ_MSG_BULK_TX 7 /* + (srcport, dstport), data, size */
  28569. +#define VCHIQ_MSG_BULK_RX_DONE 8 /* + (srcport, dstport), actual */
  28570. +#define VCHIQ_MSG_BULK_TX_DONE 9 /* + (srcport, dstport), actual */
  28571. +#define VCHIQ_MSG_PAUSE 10 /* - */
  28572. +#define VCHIQ_MSG_RESUME 11 /* - */
  28573. +#define VCHIQ_MSG_REMOTE_USE 12 /* - */
  28574. +#define VCHIQ_MSG_REMOTE_RELEASE 13 /* - */
  28575. +#define VCHIQ_MSG_REMOTE_USE_ACTIVE 14 /* - */
  28576. +
  28577. +#define VCHIQ_PORT_MAX (VCHIQ_MAX_SERVICES - 1)
  28578. +#define VCHIQ_PORT_FREE 0x1000
  28579. +#define VCHIQ_PORT_IS_VALID(port) (port < VCHIQ_PORT_FREE)
  28580. +#define VCHIQ_MAKE_MSG(type, srcport, dstport) \
  28581. + ((type<<24) | (srcport<<12) | (dstport<<0))
  28582. +#define VCHIQ_MSG_TYPE(msgid) ((unsigned int)msgid >> 24)
  28583. +#define VCHIQ_MSG_SRCPORT(msgid) \
  28584. + (unsigned short)(((unsigned int)msgid >> 12) & 0xfff)
  28585. +#define VCHIQ_MSG_DSTPORT(msgid) \
  28586. + ((unsigned short)msgid & 0xfff)
  28587. +
  28588. +#define VCHIQ_FOURCC_AS_4CHARS(fourcc) \
  28589. + ((fourcc) >> 24) & 0xff, \
  28590. + ((fourcc) >> 16) & 0xff, \
  28591. + ((fourcc) >> 8) & 0xff, \
  28592. + (fourcc) & 0xff
  28593. +
  28594. +/* Ensure the fields are wide enough */
  28595. +vchiq_static_assert(VCHIQ_MSG_SRCPORT(VCHIQ_MAKE_MSG(0, 0, VCHIQ_PORT_MAX))
  28596. + == 0);
  28597. +vchiq_static_assert(VCHIQ_MSG_TYPE(VCHIQ_MAKE_MSG(0, VCHIQ_PORT_MAX, 0)) == 0);
  28598. +vchiq_static_assert((unsigned int)VCHIQ_PORT_MAX <
  28599. + (unsigned int)VCHIQ_PORT_FREE);
  28600. +
  28601. +#define VCHIQ_MSGID_PADDING VCHIQ_MAKE_MSG(VCHIQ_MSG_PADDING, 0, 0)
  28602. +#define VCHIQ_MSGID_CLAIMED 0x40000000
  28603. +
  28604. +#define VCHIQ_FOURCC_INVALID 0x00000000
  28605. +#define VCHIQ_FOURCC_IS_LEGAL(fourcc) (fourcc != VCHIQ_FOURCC_INVALID)
  28606. +
  28607. +#define VCHIQ_BULK_ACTUAL_ABORTED -1
  28608. +
  28609. +typedef uint32_t BITSET_T;
  28610. +
  28611. +vchiq_static_assert((sizeof(BITSET_T) * 8) == 32);
  28612. +
  28613. +#define BITSET_SIZE(b) ((b + 31) >> 5)
  28614. +#define BITSET_WORD(b) (b >> 5)
  28615. +#define BITSET_BIT(b) (1 << (b & 31))
  28616. +#define BITSET_ZERO(bs) memset(bs, 0, sizeof(bs))
  28617. +#define BITSET_IS_SET(bs, b) (bs[BITSET_WORD(b)] & BITSET_BIT(b))
  28618. +#define BITSET_SET(bs, b) (bs[BITSET_WORD(b)] |= BITSET_BIT(b))
  28619. +#define BITSET_CLR(bs, b) (bs[BITSET_WORD(b)] &= ~BITSET_BIT(b))
  28620. +
  28621. +#if VCHIQ_ENABLE_STATS
  28622. +#define VCHIQ_STATS_INC(state, stat) (state->stats. stat++)
  28623. +#define VCHIQ_SERVICE_STATS_INC(service, stat) (service->stats. stat++)
  28624. +#define VCHIQ_SERVICE_STATS_ADD(service, stat, addend) \
  28625. + (service->stats. stat += addend)
  28626. +#else
  28627. +#define VCHIQ_STATS_INC(state, stat) ((void)0)
  28628. +#define VCHIQ_SERVICE_STATS_INC(service, stat) ((void)0)
  28629. +#define VCHIQ_SERVICE_STATS_ADD(service, stat, addend) ((void)0)
  28630. +#endif
  28631. +
  28632. +enum {
  28633. + DEBUG_ENTRIES,
  28634. +#if VCHIQ_ENABLE_DEBUG
  28635. + DEBUG_SLOT_HANDLER_COUNT,
  28636. + DEBUG_SLOT_HANDLER_LINE,
  28637. + DEBUG_PARSE_LINE,
  28638. + DEBUG_PARSE_HEADER,
  28639. + DEBUG_PARSE_MSGID,
  28640. + DEBUG_AWAIT_COMPLETION_LINE,
  28641. + DEBUG_DEQUEUE_MESSAGE_LINE,
  28642. + DEBUG_SERVICE_CALLBACK_LINE,
  28643. + DEBUG_MSG_QUEUE_FULL_COUNT,
  28644. + DEBUG_COMPLETION_QUEUE_FULL_COUNT,
  28645. +#endif
  28646. + DEBUG_MAX
  28647. +};
  28648. +
  28649. +#if VCHIQ_ENABLE_DEBUG
  28650. +
  28651. +#define DEBUG_INITIALISE(local) int *debug_ptr = (local)->debug;
  28652. +#define DEBUG_TRACE(d) \
  28653. + do { debug_ptr[DEBUG_ ## d] = __LINE__; dsb(); } while (0)
  28654. +#define DEBUG_VALUE(d, v) \
  28655. + do { debug_ptr[DEBUG_ ## d] = (v); dsb(); } while (0)
  28656. +#define DEBUG_COUNT(d) \
  28657. + do { debug_ptr[DEBUG_ ## d]++; dsb(); } while (0)
  28658. +
  28659. +#else /* VCHIQ_ENABLE_DEBUG */
  28660. +
  28661. +#define DEBUG_INITIALISE(local)
  28662. +#define DEBUG_TRACE(d)
  28663. +#define DEBUG_VALUE(d, v)
  28664. +#define DEBUG_COUNT(d)
  28665. +
  28666. +#endif /* VCHIQ_ENABLE_DEBUG */
  28667. +
  28668. +typedef enum {
  28669. + VCHIQ_CONNSTATE_DISCONNECTED,
  28670. + VCHIQ_CONNSTATE_CONNECTING,
  28671. + VCHIQ_CONNSTATE_CONNECTED,
  28672. + VCHIQ_CONNSTATE_PAUSING,
  28673. + VCHIQ_CONNSTATE_PAUSE_SENT,
  28674. + VCHIQ_CONNSTATE_PAUSED,
  28675. + VCHIQ_CONNSTATE_RESUMING,
  28676. + VCHIQ_CONNSTATE_PAUSE_TIMEOUT,
  28677. + VCHIQ_CONNSTATE_RESUME_TIMEOUT
  28678. +} VCHIQ_CONNSTATE_T;
  28679. +
  28680. +enum {
  28681. + VCHIQ_SRVSTATE_FREE,
  28682. + VCHIQ_SRVSTATE_HIDDEN,
  28683. + VCHIQ_SRVSTATE_LISTENING,
  28684. + VCHIQ_SRVSTATE_OPENING,
  28685. + VCHIQ_SRVSTATE_OPEN,
  28686. + VCHIQ_SRVSTATE_OPENSYNC,
  28687. + VCHIQ_SRVSTATE_CLOSESENT,
  28688. + VCHIQ_SRVSTATE_CLOSERECVD,
  28689. + VCHIQ_SRVSTATE_CLOSEWAIT,
  28690. + VCHIQ_SRVSTATE_CLOSED
  28691. +};
  28692. +
  28693. +enum {
  28694. + VCHIQ_POLL_TERMINATE,
  28695. + VCHIQ_POLL_REMOVE,
  28696. + VCHIQ_POLL_TXNOTIFY,
  28697. + VCHIQ_POLL_RXNOTIFY,
  28698. + VCHIQ_POLL_COUNT
  28699. +};
  28700. +
  28701. +typedef enum {
  28702. + VCHIQ_BULK_TRANSMIT,
  28703. + VCHIQ_BULK_RECEIVE
  28704. +} VCHIQ_BULK_DIR_T;
  28705. +
  28706. +typedef void (*VCHIQ_USERDATA_TERM_T)(void *userdata);
  28707. +
  28708. +typedef struct vchiq_bulk_struct {
  28709. + short mode;
  28710. + short dir;
  28711. + void *userdata;
  28712. + VCHI_MEM_HANDLE_T handle;
  28713. + void *data;
  28714. + int size;
  28715. + void *remote_data;
  28716. + int remote_size;
  28717. + int actual;
  28718. +} VCHIQ_BULK_T;
  28719. +
  28720. +typedef struct vchiq_bulk_queue_struct {
  28721. + int local_insert; /* Where to insert the next local bulk */
  28722. + int remote_insert; /* Where to insert the next remote bulk (master) */
  28723. + int process; /* Bulk to transfer next */
  28724. + int remote_notify; /* Bulk to notify the remote client of next (mstr) */
  28725. + int remove; /* Bulk to notify the local client of, and remove,
  28726. + ** next */
  28727. + VCHIQ_BULK_T bulks[VCHIQ_NUM_SERVICE_BULKS];
  28728. +} VCHIQ_BULK_QUEUE_T;
  28729. +
  28730. +typedef struct remote_event_struct {
  28731. + int armed;
  28732. + int fired;
  28733. + struct semaphore *event;
  28734. +} REMOTE_EVENT_T;
  28735. +
  28736. +typedef struct opaque_platform_state_t *VCHIQ_PLATFORM_STATE_T;
  28737. +
  28738. +typedef struct vchiq_state_struct VCHIQ_STATE_T;
  28739. +
  28740. +typedef struct vchiq_slot_struct {
  28741. + char data[VCHIQ_SLOT_SIZE];
  28742. +} VCHIQ_SLOT_T;
  28743. +
  28744. +typedef struct vchiq_slot_info_struct {
  28745. + /* Use two counters rather than one to avoid the need for a mutex. */
  28746. + short use_count;
  28747. + short release_count;
  28748. +} VCHIQ_SLOT_INFO_T;
  28749. +
  28750. +typedef struct vchiq_service_struct {
  28751. + VCHIQ_SERVICE_BASE_T base;
  28752. + VCHIQ_SERVICE_HANDLE_T handle;
  28753. + unsigned int ref_count;
  28754. + int srvstate;
  28755. + VCHIQ_USERDATA_TERM_T userdata_term;
  28756. + unsigned int localport;
  28757. + unsigned int remoteport;
  28758. + int public_fourcc;
  28759. + int client_id;
  28760. + char auto_close;
  28761. + char sync;
  28762. + char closing;
  28763. + atomic_t poll_flags;
  28764. + short version;
  28765. + short version_min;
  28766. + short peer_version;
  28767. +
  28768. + VCHIQ_STATE_T *state;
  28769. + VCHIQ_INSTANCE_T instance;
  28770. +
  28771. + int service_use_count;
  28772. +
  28773. + VCHIQ_BULK_QUEUE_T bulk_tx;
  28774. + VCHIQ_BULK_QUEUE_T bulk_rx;
  28775. +
  28776. + struct semaphore remove_event;
  28777. + struct semaphore bulk_remove_event;
  28778. + struct mutex bulk_mutex;
  28779. +
  28780. + struct service_stats_struct {
  28781. + int quota_stalls;
  28782. + int slot_stalls;
  28783. + int bulk_stalls;
  28784. + int error_count;
  28785. + int ctrl_tx_count;
  28786. + int ctrl_rx_count;
  28787. + int bulk_tx_count;
  28788. + int bulk_rx_count;
  28789. + int bulk_aborted_count;
  28790. + uint64_t ctrl_tx_bytes;
  28791. + uint64_t ctrl_rx_bytes;
  28792. + uint64_t bulk_tx_bytes;
  28793. + uint64_t bulk_rx_bytes;
  28794. + } stats;
  28795. +} VCHIQ_SERVICE_T;
  28796. +
  28797. +/* The quota information is outside VCHIQ_SERVICE_T so that it can be
  28798. + statically allocated, since for accounting reasons a service's slot
  28799. + usage is carried over between users of the same port number.
  28800. + */
  28801. +typedef struct vchiq_service_quota_struct {
  28802. + unsigned short slot_quota;
  28803. + unsigned short slot_use_count;
  28804. + unsigned short message_quota;
  28805. + unsigned short message_use_count;
  28806. + struct semaphore quota_event;
  28807. + int previous_tx_index;
  28808. +} VCHIQ_SERVICE_QUOTA_T;
  28809. +
  28810. +typedef struct vchiq_shared_state_struct {
  28811. +
  28812. + /* A non-zero value here indicates that the content is valid. */
  28813. + int initialised;
  28814. +
  28815. + /* The first and last (inclusive) slots allocated to the owner. */
  28816. + int slot_first;
  28817. + int slot_last;
  28818. +
  28819. + /* The slot allocated to synchronous messages from the owner. */
  28820. + int slot_sync;
  28821. +
  28822. + /* Signalling this event indicates that owner's slot handler thread
  28823. + ** should run. */
  28824. + REMOTE_EVENT_T trigger;
  28825. +
  28826. + /* Indicates the byte position within the stream where the next message
  28827. + ** will be written. The least significant bits are an index into the
  28828. + ** slot. The next bits are the index of the slot in slot_queue. */
  28829. + int tx_pos;
  28830. +
  28831. + /* This event should be signalled when a slot is recycled. */
  28832. + REMOTE_EVENT_T recycle;
  28833. +
  28834. + /* The slot_queue index where the next recycled slot will be written. */
  28835. + int slot_queue_recycle;
  28836. +
  28837. + /* This event should be signalled when a synchronous message is sent. */
  28838. + REMOTE_EVENT_T sync_trigger;
  28839. +
  28840. + /* This event should be signalled when a synchronous message has been
  28841. + ** released. */
  28842. + REMOTE_EVENT_T sync_release;
  28843. +
  28844. + /* A circular buffer of slot indexes. */
  28845. + int slot_queue[VCHIQ_MAX_SLOTS_PER_SIDE];
  28846. +
  28847. + /* Debugging state */
  28848. + int debug[DEBUG_MAX];
  28849. +} VCHIQ_SHARED_STATE_T;
  28850. +
  28851. +typedef struct vchiq_slot_zero_struct {
  28852. + int magic;
  28853. + short version;
  28854. + short version_min;
  28855. + int slot_zero_size;
  28856. + int slot_size;
  28857. + int max_slots;
  28858. + int max_slots_per_side;
  28859. + int platform_data[2];
  28860. + VCHIQ_SHARED_STATE_T master;
  28861. + VCHIQ_SHARED_STATE_T slave;
  28862. + VCHIQ_SLOT_INFO_T slots[VCHIQ_MAX_SLOTS];
  28863. +} VCHIQ_SLOT_ZERO_T;
  28864. +
  28865. +struct vchiq_state_struct {
  28866. + int id;
  28867. + int initialised;
  28868. + VCHIQ_CONNSTATE_T conn_state;
  28869. + int is_master;
  28870. +
  28871. + VCHIQ_SHARED_STATE_T *local;
  28872. + VCHIQ_SHARED_STATE_T *remote;
  28873. + VCHIQ_SLOT_T *slot_data;
  28874. +
  28875. + unsigned short default_slot_quota;
  28876. + unsigned short default_message_quota;
  28877. +
  28878. + /* Event indicating connect message received */
  28879. + struct semaphore connect;
  28880. +
  28881. + /* Mutex protecting services */
  28882. + struct mutex mutex;
  28883. + VCHIQ_INSTANCE_T *instance;
  28884. +
  28885. + /* Processes incoming messages */
  28886. + struct task_struct *slot_handler_thread;
  28887. +
  28888. + /* Processes recycled slots */
  28889. + struct task_struct *recycle_thread;
  28890. +
  28891. + /* Processes synchronous messages */
  28892. + struct task_struct *sync_thread;
  28893. +
  28894. + /* Local implementation of the trigger remote event */
  28895. + struct semaphore trigger_event;
  28896. +
  28897. + /* Local implementation of the recycle remote event */
  28898. + struct semaphore recycle_event;
  28899. +
  28900. + /* Local implementation of the sync trigger remote event */
  28901. + struct semaphore sync_trigger_event;
  28902. +
  28903. + /* Local implementation of the sync release remote event */
  28904. + struct semaphore sync_release_event;
  28905. +
  28906. + char *tx_data;
  28907. + char *rx_data;
  28908. + VCHIQ_SLOT_INFO_T *rx_info;
  28909. +
  28910. + struct mutex slot_mutex;
  28911. +
  28912. + struct mutex recycle_mutex;
  28913. +
  28914. + struct mutex sync_mutex;
  28915. +
  28916. + struct mutex bulk_transfer_mutex;
  28917. +
  28918. + /* Indicates the byte position within the stream from where the next
  28919. + ** message will be read. The least significant bits are an index into
  28920. + ** the slot.The next bits are the index of the slot in
  28921. + ** remote->slot_queue. */
  28922. + int rx_pos;
  28923. +
  28924. + /* A cached copy of local->tx_pos. Only write to local->tx_pos, and read
  28925. + from remote->tx_pos. */
  28926. + int local_tx_pos;
  28927. +
  28928. + /* The slot_queue index of the slot to become available next. */
  28929. + int slot_queue_available;
  28930. +
  28931. + /* A flag to indicate if any poll has been requested */
  28932. + int poll_needed;
  28933. +
  28934. + /* Ths index of the previous slot used for data messages. */
  28935. + int previous_data_index;
  28936. +
  28937. + /* The number of slots occupied by data messages. */
  28938. + unsigned short data_use_count;
  28939. +
  28940. + /* The maximum number of slots to be occupied by data messages. */
  28941. + unsigned short data_quota;
  28942. +
  28943. + /* An array of bit sets indicating which services must be polled. */
  28944. + atomic_t poll_services[BITSET_SIZE(VCHIQ_MAX_SERVICES)];
  28945. +
  28946. + /* The number of the first unused service */
  28947. + int unused_service;
  28948. +
  28949. + /* Signalled when a free slot becomes available. */
  28950. + struct semaphore slot_available_event;
  28951. +
  28952. + struct semaphore slot_remove_event;
  28953. +
  28954. + /* Signalled when a free data slot becomes available. */
  28955. + struct semaphore data_quota_event;
  28956. +
  28957. + /* Incremented when there are bulk transfers which cannot be processed
  28958. + * whilst paused and must be processed on resume */
  28959. + int deferred_bulks;
  28960. +
  28961. + struct state_stats_struct {
  28962. + int slot_stalls;
  28963. + int data_stalls;
  28964. + int ctrl_tx_count;
  28965. + int ctrl_rx_count;
  28966. + int error_count;
  28967. + } stats;
  28968. +
  28969. + VCHIQ_SERVICE_T * services[VCHIQ_MAX_SERVICES];
  28970. + VCHIQ_SERVICE_QUOTA_T service_quotas[VCHIQ_MAX_SERVICES];
  28971. + VCHIQ_SLOT_INFO_T slot_info[VCHIQ_MAX_SLOTS];
  28972. +
  28973. + VCHIQ_PLATFORM_STATE_T platform_state;
  28974. +};
  28975. +
  28976. +struct bulk_waiter {
  28977. + VCHIQ_BULK_T *bulk;
  28978. + struct semaphore event;
  28979. + int actual;
  28980. +};
  28981. +
  28982. +extern spinlock_t bulk_waiter_spinlock;
  28983. +
  28984. +extern int vchiq_core_log_level;
  28985. +extern int vchiq_core_msg_log_level;
  28986. +extern int vchiq_sync_log_level;
  28987. +
  28988. +extern VCHIQ_STATE_T *vchiq_states[VCHIQ_MAX_STATES];
  28989. +
  28990. +extern const char *
  28991. +get_conn_state_name(VCHIQ_CONNSTATE_T conn_state);
  28992. +
  28993. +extern VCHIQ_SLOT_ZERO_T *
  28994. +vchiq_init_slots(void *mem_base, int mem_size);
  28995. +
  28996. +extern VCHIQ_STATUS_T
  28997. +vchiq_init_state(VCHIQ_STATE_T *state, VCHIQ_SLOT_ZERO_T *slot_zero,
  28998. + int is_master);
  28999. +
  29000. +extern VCHIQ_STATUS_T
  29001. +vchiq_connect_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance);
  29002. +
  29003. +extern VCHIQ_SERVICE_T *
  29004. +vchiq_add_service_internal(VCHIQ_STATE_T *state,
  29005. + const VCHIQ_SERVICE_PARAMS_T *params, int srvstate,
  29006. + VCHIQ_INSTANCE_T instance, VCHIQ_USERDATA_TERM_T userdata_term);
  29007. +
  29008. +extern VCHIQ_STATUS_T
  29009. +vchiq_open_service_internal(VCHIQ_SERVICE_T *service, int client_id);
  29010. +
  29011. +extern VCHIQ_STATUS_T
  29012. +vchiq_close_service_internal(VCHIQ_SERVICE_T *service, int close_recvd);
  29013. +
  29014. +extern void
  29015. +vchiq_terminate_service_internal(VCHIQ_SERVICE_T *service);
  29016. +
  29017. +extern void
  29018. +vchiq_free_service_internal(VCHIQ_SERVICE_T *service);
  29019. +
  29020. +extern VCHIQ_STATUS_T
  29021. +vchiq_shutdown_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance);
  29022. +
  29023. +extern VCHIQ_STATUS_T
  29024. +vchiq_pause_internal(VCHIQ_STATE_T *state);
  29025. +
  29026. +extern VCHIQ_STATUS_T
  29027. +vchiq_resume_internal(VCHIQ_STATE_T *state);
  29028. +
  29029. +extern void
  29030. +remote_event_pollall(VCHIQ_STATE_T *state);
  29031. +
  29032. +extern VCHIQ_STATUS_T
  29033. +vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle,
  29034. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, void *userdata,
  29035. + VCHIQ_BULK_MODE_T mode, VCHIQ_BULK_DIR_T dir);
  29036. +
  29037. +extern void
  29038. +vchiq_dump_state(void *dump_context, VCHIQ_STATE_T *state);
  29039. +
  29040. +extern void
  29041. +vchiq_dump_service_state(void *dump_context, VCHIQ_SERVICE_T *service);
  29042. +
  29043. +extern void
  29044. +vchiq_loud_error_header(void);
  29045. +
  29046. +extern void
  29047. +vchiq_loud_error_footer(void);
  29048. +
  29049. +extern void
  29050. +request_poll(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service, int poll_type);
  29051. +
  29052. +static inline VCHIQ_SERVICE_T *
  29053. +handle_to_service(VCHIQ_SERVICE_HANDLE_T handle)
  29054. +{
  29055. + VCHIQ_STATE_T *state = vchiq_states[(handle / VCHIQ_MAX_SERVICES) &
  29056. + (VCHIQ_MAX_STATES - 1)];
  29057. + if (!state)
  29058. + return NULL;
  29059. +
  29060. + return state->services[handle & (VCHIQ_MAX_SERVICES - 1)];
  29061. +}
  29062. +
  29063. +extern VCHIQ_SERVICE_T *
  29064. +find_service_by_handle(VCHIQ_SERVICE_HANDLE_T handle);
  29065. +
  29066. +extern VCHIQ_SERVICE_T *
  29067. +find_service_by_port(VCHIQ_STATE_T *state, int localport);
  29068. +
  29069. +extern VCHIQ_SERVICE_T *
  29070. +find_service_for_instance(VCHIQ_INSTANCE_T instance,
  29071. + VCHIQ_SERVICE_HANDLE_T handle);
  29072. +
  29073. +extern VCHIQ_SERVICE_T *
  29074. +next_service_by_instance(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance,
  29075. + int *pidx);
  29076. +
  29077. +extern void
  29078. +lock_service(VCHIQ_SERVICE_T *service);
  29079. +
  29080. +extern void
  29081. +unlock_service(VCHIQ_SERVICE_T *service);
  29082. +
  29083. +/* The following functions are called from vchiq_core, and external
  29084. +** implementations must be provided. */
  29085. +
  29086. +extern VCHIQ_STATUS_T
  29087. +vchiq_prepare_bulk_data(VCHIQ_BULK_T *bulk,
  29088. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, int dir);
  29089. +
  29090. +extern void
  29091. +vchiq_transfer_bulk(VCHIQ_BULK_T *bulk);
  29092. +
  29093. +extern void
  29094. +vchiq_complete_bulk(VCHIQ_BULK_T *bulk);
  29095. +
  29096. +extern VCHIQ_STATUS_T
  29097. +vchiq_copy_from_user(void *dst, const void *src, int size);
  29098. +
  29099. +extern void
  29100. +remote_event_signal(REMOTE_EVENT_T *event);
  29101. +
  29102. +void
  29103. +vchiq_platform_check_suspend(VCHIQ_STATE_T *state);
  29104. +
  29105. +extern void
  29106. +vchiq_platform_paused(VCHIQ_STATE_T *state);
  29107. +
  29108. +extern VCHIQ_STATUS_T
  29109. +vchiq_platform_resume(VCHIQ_STATE_T *state);
  29110. +
  29111. +extern void
  29112. +vchiq_platform_resumed(VCHIQ_STATE_T *state);
  29113. +
  29114. +extern void
  29115. +vchiq_dump(void *dump_context, const char *str, int len);
  29116. +
  29117. +extern void
  29118. +vchiq_dump_platform_state(void *dump_context);
  29119. +
  29120. +extern void
  29121. +vchiq_dump_platform_instances(void *dump_context);
  29122. +
  29123. +extern void
  29124. +vchiq_dump_platform_service_state(void *dump_context,
  29125. + VCHIQ_SERVICE_T *service);
  29126. +
  29127. +extern VCHIQ_STATUS_T
  29128. +vchiq_use_service_internal(VCHIQ_SERVICE_T *service);
  29129. +
  29130. +extern VCHIQ_STATUS_T
  29131. +vchiq_release_service_internal(VCHIQ_SERVICE_T *service);
  29132. +
  29133. +extern void
  29134. +vchiq_on_remote_use(VCHIQ_STATE_T *state);
  29135. +
  29136. +extern void
  29137. +vchiq_on_remote_release(VCHIQ_STATE_T *state);
  29138. +
  29139. +extern VCHIQ_STATUS_T
  29140. +vchiq_platform_init_state(VCHIQ_STATE_T *state);
  29141. +
  29142. +extern VCHIQ_STATUS_T
  29143. +vchiq_check_service(VCHIQ_SERVICE_T *service);
  29144. +
  29145. +extern void
  29146. +vchiq_on_remote_use_active(VCHIQ_STATE_T *state);
  29147. +
  29148. +extern VCHIQ_STATUS_T
  29149. +vchiq_send_remote_use(VCHIQ_STATE_T *state);
  29150. +
  29151. +extern VCHIQ_STATUS_T
  29152. +vchiq_send_remote_release(VCHIQ_STATE_T *state);
  29153. +
  29154. +extern VCHIQ_STATUS_T
  29155. +vchiq_send_remote_use_active(VCHIQ_STATE_T *state);
  29156. +
  29157. +extern void
  29158. +vchiq_platform_conn_state_changed(VCHIQ_STATE_T *state,
  29159. + VCHIQ_CONNSTATE_T oldstate, VCHIQ_CONNSTATE_T newstate);
  29160. +
  29161. +extern void
  29162. +vchiq_platform_handle_timeout(VCHIQ_STATE_T *state);
  29163. +
  29164. +extern void
  29165. +vchiq_set_conn_state(VCHIQ_STATE_T *state, VCHIQ_CONNSTATE_T newstate);
  29166. +
  29167. +
  29168. +extern void
  29169. +vchiq_log_dump_mem(const char *label, uint32_t addr, const void *voidMem,
  29170. + size_t numBytes);
  29171. +
  29172. +#endif
  29173. diff -Nur linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion
  29174. --- linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion 1970-01-01 01:00:00.000000000 +0100
  29175. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion 2014-07-07 10:45:11.000000000 +0200
  29176. @@ -0,0 +1,87 @@
  29177. +#!/usr/bin/perl -w
  29178. +
  29179. +use strict;
  29180. +
  29181. +#
  29182. +# Generate a version from available information
  29183. +#
  29184. +
  29185. +my $prefix = shift @ARGV;
  29186. +my $root = shift @ARGV;
  29187. +
  29188. +
  29189. +if ( not defined $root ) {
  29190. + die "usage: $0 prefix root-dir\n";
  29191. +}
  29192. +
  29193. +if ( ! -d $root ) {
  29194. + die "root directory $root not found\n";
  29195. +}
  29196. +
  29197. +my $version = "unknown";
  29198. +my $tainted = "";
  29199. +
  29200. +if ( -d "$root/.git" ) {
  29201. + # attempt to work out git version. only do so
  29202. + # on a linux build host, as cygwin builds are
  29203. + # already slow enough
  29204. +
  29205. + if ( -f "/usr/bin/git" || -f "/usr/local/bin/git" ) {
  29206. + if (not open(F, "git --git-dir $root/.git rev-parse --verify HEAD|")) {
  29207. + $version = "no git version";
  29208. + }
  29209. + else {
  29210. + $version = <F>;
  29211. + $version =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  29212. + $version =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  29213. + }
  29214. +
  29215. + if (open(G, "git --git-dir $root/.git status --porcelain|")) {
  29216. + $tainted = <G>;
  29217. + $tainted =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  29218. + $tainted =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  29219. + if (length $tainted) {
  29220. + $version = join ' ', $version, "(tainted)";
  29221. + }
  29222. + else {
  29223. + $version = join ' ', $version, "(clean)";
  29224. + }
  29225. + }
  29226. + }
  29227. +}
  29228. +
  29229. +my $hostname = `hostname`;
  29230. +$hostname =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  29231. +$hostname =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  29232. +
  29233. +
  29234. +print STDERR "Version $version\n";
  29235. +print <<EOF;
  29236. +#include "${prefix}_build_info.h"
  29237. +#include <linux/broadcom/vc_debug_sym.h>
  29238. +
  29239. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_hostname, "$hostname" );
  29240. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_version, "$version" );
  29241. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_time, __TIME__ );
  29242. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_date, __DATE__ );
  29243. +
  29244. +const char *vchiq_get_build_hostname( void )
  29245. +{
  29246. + return vchiq_build_hostname;
  29247. +}
  29248. +
  29249. +const char *vchiq_get_build_version( void )
  29250. +{
  29251. + return vchiq_build_version;
  29252. +}
  29253. +
  29254. +const char *vchiq_get_build_date( void )
  29255. +{
  29256. + return vchiq_build_date;
  29257. +}
  29258. +
  29259. +const char *vchiq_get_build_time( void )
  29260. +{
  29261. + return vchiq_build_time;
  29262. +}
  29263. +EOF
  29264. diff -Nur linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h
  29265. --- linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h 1970-01-01 01:00:00.000000000 +0100
  29266. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h 2014-07-07 10:45:11.000000000 +0200
  29267. @@ -0,0 +1,40 @@
  29268. +/**
  29269. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  29270. + *
  29271. + * Redistribution and use in source and binary forms, with or without
  29272. + * modification, are permitted provided that the following conditions
  29273. + * are met:
  29274. + * 1. Redistributions of source code must retain the above copyright
  29275. + * notice, this list of conditions, and the following disclaimer,
  29276. + * without modification.
  29277. + * 2. Redistributions in binary form must reproduce the above copyright
  29278. + * notice, this list of conditions and the following disclaimer in the
  29279. + * documentation and/or other materials provided with the distribution.
  29280. + * 3. The names of the above-listed copyright holders may not be used
  29281. + * to endorse or promote products derived from this software without
  29282. + * specific prior written permission.
  29283. + *
  29284. + * ALTERNATIVELY, this software may be distributed under the terms of the
  29285. + * GNU General Public License ("GPL") version 2, as published by the Free
  29286. + * Software Foundation.
  29287. + *
  29288. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29289. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29290. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29291. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29292. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29293. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29294. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29295. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29296. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29297. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29298. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29299. + */
  29300. +
  29301. +#ifndef VCHIQ_VCHIQ_H
  29302. +#define VCHIQ_VCHIQ_H
  29303. +
  29304. +#include "vchiq_if.h"
  29305. +#include "vchiq_util.h"
  29306. +
  29307. +#endif
  29308. diff -Nur linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h
  29309. --- linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h 1970-01-01 01:00:00.000000000 +0100
  29310. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h 2014-04-13 17:32:57.000000000 +0200
  29311. @@ -0,0 +1,188 @@
  29312. +/**
  29313. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  29314. + *
  29315. + * Redistribution and use in source and binary forms, with or without
  29316. + * modification, are permitted provided that the following conditions
  29317. + * are met:
  29318. + * 1. Redistributions of source code must retain the above copyright
  29319. + * notice, this list of conditions, and the following disclaimer,
  29320. + * without modification.
  29321. + * 2. Redistributions in binary form must reproduce the above copyright
  29322. + * notice, this list of conditions and the following disclaimer in the
  29323. + * documentation and/or other materials provided with the distribution.
  29324. + * 3. The names of the above-listed copyright holders may not be used
  29325. + * to endorse or promote products derived from this software without
  29326. + * specific prior written permission.
  29327. + *
  29328. + * ALTERNATIVELY, this software may be distributed under the terms of the
  29329. + * GNU General Public License ("GPL") version 2, as published by the Free
  29330. + * Software Foundation.
  29331. + *
  29332. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29333. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29334. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29335. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29336. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29337. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29338. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29339. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29340. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29341. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29342. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29343. + */
  29344. +
  29345. +#ifndef VCHIQ_IF_H
  29346. +#define VCHIQ_IF_H
  29347. +
  29348. +#include "interface/vchi/vchi_mh.h"
  29349. +
  29350. +#define VCHIQ_SERVICE_HANDLE_INVALID 0
  29351. +
  29352. +#define VCHIQ_SLOT_SIZE 4096
  29353. +#define VCHIQ_MAX_MSG_SIZE (VCHIQ_SLOT_SIZE - sizeof(VCHIQ_HEADER_T))
  29354. +#define VCHIQ_CHANNEL_SIZE VCHIQ_MAX_MSG_SIZE /* For backwards compatibility */
  29355. +
  29356. +#define VCHIQ_MAKE_FOURCC(x0, x1, x2, x3) \
  29357. + (((x0) << 24) | ((x1) << 16) | ((x2) << 8) | (x3))
  29358. +#define VCHIQ_GET_SERVICE_USERDATA(service) vchiq_get_service_userdata(service)
  29359. +#define VCHIQ_GET_SERVICE_FOURCC(service) vchiq_get_service_fourcc(service)
  29360. +
  29361. +typedef enum {
  29362. + VCHIQ_SERVICE_OPENED, /* service, -, - */
  29363. + VCHIQ_SERVICE_CLOSED, /* service, -, - */
  29364. + VCHIQ_MESSAGE_AVAILABLE, /* service, header, - */
  29365. + VCHIQ_BULK_TRANSMIT_DONE, /* service, -, bulk_userdata */
  29366. + VCHIQ_BULK_RECEIVE_DONE, /* service, -, bulk_userdata */
  29367. + VCHIQ_BULK_TRANSMIT_ABORTED, /* service, -, bulk_userdata */
  29368. + VCHIQ_BULK_RECEIVE_ABORTED /* service, -, bulk_userdata */
  29369. +} VCHIQ_REASON_T;
  29370. +
  29371. +typedef enum {
  29372. + VCHIQ_ERROR = -1,
  29373. + VCHIQ_SUCCESS = 0,
  29374. + VCHIQ_RETRY = 1
  29375. +} VCHIQ_STATUS_T;
  29376. +
  29377. +typedef enum {
  29378. + VCHIQ_BULK_MODE_CALLBACK,
  29379. + VCHIQ_BULK_MODE_BLOCKING,
  29380. + VCHIQ_BULK_MODE_NOCALLBACK,
  29381. + VCHIQ_BULK_MODE_WAITING /* Reserved for internal use */
  29382. +} VCHIQ_BULK_MODE_T;
  29383. +
  29384. +typedef enum {
  29385. + VCHIQ_SERVICE_OPTION_AUTOCLOSE,
  29386. + VCHIQ_SERVICE_OPTION_SLOT_QUOTA,
  29387. + VCHIQ_SERVICE_OPTION_MESSAGE_QUOTA,
  29388. + VCHIQ_SERVICE_OPTION_SYNCHRONOUS
  29389. +} VCHIQ_SERVICE_OPTION_T;
  29390. +
  29391. +typedef struct vchiq_header_struct {
  29392. + /* The message identifier - opaque to applications. */
  29393. + int msgid;
  29394. +
  29395. + /* Size of message data. */
  29396. + unsigned int size;
  29397. +
  29398. + char data[0]; /* message */
  29399. +} VCHIQ_HEADER_T;
  29400. +
  29401. +typedef struct {
  29402. + const void *data;
  29403. + unsigned int size;
  29404. +} VCHIQ_ELEMENT_T;
  29405. +
  29406. +typedef unsigned int VCHIQ_SERVICE_HANDLE_T;
  29407. +
  29408. +typedef VCHIQ_STATUS_T (*VCHIQ_CALLBACK_T)(VCHIQ_REASON_T, VCHIQ_HEADER_T *,
  29409. + VCHIQ_SERVICE_HANDLE_T, void *);
  29410. +
  29411. +typedef struct vchiq_service_base_struct {
  29412. + int fourcc;
  29413. + VCHIQ_CALLBACK_T callback;
  29414. + void *userdata;
  29415. +} VCHIQ_SERVICE_BASE_T;
  29416. +
  29417. +typedef struct vchiq_service_params_struct {
  29418. + int fourcc;
  29419. + VCHIQ_CALLBACK_T callback;
  29420. + void *userdata;
  29421. + short version; /* Increment for non-trivial changes */
  29422. + short version_min; /* Update for incompatible changes */
  29423. +} VCHIQ_SERVICE_PARAMS_T;
  29424. +
  29425. +typedef struct vchiq_config_struct {
  29426. + unsigned int max_msg_size;
  29427. + unsigned int bulk_threshold; /* The message size above which it
  29428. + is better to use a bulk transfer
  29429. + (<= max_msg_size) */
  29430. + unsigned int max_outstanding_bulks;
  29431. + unsigned int max_services;
  29432. + short version; /* The version of VCHIQ */
  29433. + short version_min; /* The minimum compatible version of VCHIQ */
  29434. +} VCHIQ_CONFIG_T;
  29435. +
  29436. +typedef struct vchiq_instance_struct *VCHIQ_INSTANCE_T;
  29437. +typedef void (*VCHIQ_REMOTE_USE_CALLBACK_T)(void *cb_arg);
  29438. +
  29439. +extern VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *pinstance);
  29440. +extern VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance);
  29441. +extern VCHIQ_STATUS_T vchiq_connect(VCHIQ_INSTANCE_T instance);
  29442. +extern VCHIQ_STATUS_T vchiq_add_service(VCHIQ_INSTANCE_T instance,
  29443. + const VCHIQ_SERVICE_PARAMS_T *params,
  29444. + VCHIQ_SERVICE_HANDLE_T *pservice);
  29445. +extern VCHIQ_STATUS_T vchiq_open_service(VCHIQ_INSTANCE_T instance,
  29446. + const VCHIQ_SERVICE_PARAMS_T *params,
  29447. + VCHIQ_SERVICE_HANDLE_T *pservice);
  29448. +extern VCHIQ_STATUS_T vchiq_close_service(VCHIQ_SERVICE_HANDLE_T service);
  29449. +extern VCHIQ_STATUS_T vchiq_remove_service(VCHIQ_SERVICE_HANDLE_T service);
  29450. +extern VCHIQ_STATUS_T vchiq_use_service(VCHIQ_SERVICE_HANDLE_T service);
  29451. +extern VCHIQ_STATUS_T vchiq_use_service_no_resume(
  29452. + VCHIQ_SERVICE_HANDLE_T service);
  29453. +extern VCHIQ_STATUS_T vchiq_release_service(VCHIQ_SERVICE_HANDLE_T service);
  29454. +
  29455. +extern VCHIQ_STATUS_T vchiq_queue_message(VCHIQ_SERVICE_HANDLE_T service,
  29456. + const VCHIQ_ELEMENT_T *elements, unsigned int count);
  29457. +extern void vchiq_release_message(VCHIQ_SERVICE_HANDLE_T service,
  29458. + VCHIQ_HEADER_T *header);
  29459. +extern VCHIQ_STATUS_T vchiq_queue_bulk_transmit(VCHIQ_SERVICE_HANDLE_T service,
  29460. + const void *data, unsigned int size, void *userdata);
  29461. +extern VCHIQ_STATUS_T vchiq_queue_bulk_receive(VCHIQ_SERVICE_HANDLE_T service,
  29462. + void *data, unsigned int size, void *userdata);
  29463. +extern VCHIQ_STATUS_T vchiq_queue_bulk_transmit_handle(
  29464. + VCHIQ_SERVICE_HANDLE_T service, VCHI_MEM_HANDLE_T handle,
  29465. + const void *offset, unsigned int size, void *userdata);
  29466. +extern VCHIQ_STATUS_T vchiq_queue_bulk_receive_handle(
  29467. + VCHIQ_SERVICE_HANDLE_T service, VCHI_MEM_HANDLE_T handle,
  29468. + void *offset, unsigned int size, void *userdata);
  29469. +extern VCHIQ_STATUS_T vchiq_bulk_transmit(VCHIQ_SERVICE_HANDLE_T service,
  29470. + const void *data, unsigned int size, void *userdata,
  29471. + VCHIQ_BULK_MODE_T mode);
  29472. +extern VCHIQ_STATUS_T vchiq_bulk_receive(VCHIQ_SERVICE_HANDLE_T service,
  29473. + void *data, unsigned int size, void *userdata,
  29474. + VCHIQ_BULK_MODE_T mode);
  29475. +extern VCHIQ_STATUS_T vchiq_bulk_transmit_handle(VCHIQ_SERVICE_HANDLE_T service,
  29476. + VCHI_MEM_HANDLE_T handle, const void *offset, unsigned int size,
  29477. + void *userdata, VCHIQ_BULK_MODE_T mode);
  29478. +extern VCHIQ_STATUS_T vchiq_bulk_receive_handle(VCHIQ_SERVICE_HANDLE_T service,
  29479. + VCHI_MEM_HANDLE_T handle, void *offset, unsigned int size,
  29480. + void *userdata, VCHIQ_BULK_MODE_T mode);
  29481. +extern int vchiq_get_client_id(VCHIQ_SERVICE_HANDLE_T service);
  29482. +extern void *vchiq_get_service_userdata(VCHIQ_SERVICE_HANDLE_T service);
  29483. +extern int vchiq_get_service_fourcc(VCHIQ_SERVICE_HANDLE_T service);
  29484. +extern VCHIQ_STATUS_T vchiq_get_config(VCHIQ_INSTANCE_T instance,
  29485. + int config_size, VCHIQ_CONFIG_T *pconfig);
  29486. +extern VCHIQ_STATUS_T vchiq_set_service_option(VCHIQ_SERVICE_HANDLE_T service,
  29487. + VCHIQ_SERVICE_OPTION_T option, int value);
  29488. +
  29489. +extern VCHIQ_STATUS_T vchiq_remote_use(VCHIQ_INSTANCE_T instance,
  29490. + VCHIQ_REMOTE_USE_CALLBACK_T callback, void *cb_arg);
  29491. +extern VCHIQ_STATUS_T vchiq_remote_release(VCHIQ_INSTANCE_T instance);
  29492. +
  29493. +extern VCHIQ_STATUS_T vchiq_dump_phys_mem(VCHIQ_SERVICE_HANDLE_T service,
  29494. + void *ptr, size_t num_bytes);
  29495. +
  29496. +extern VCHIQ_STATUS_T vchiq_get_peer_version(VCHIQ_SERVICE_HANDLE_T handle,
  29497. + short *peer_version);
  29498. +
  29499. +#endif /* VCHIQ_IF_H */
  29500. diff -Nur linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h
  29501. --- linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h 1970-01-01 01:00:00.000000000 +0100
  29502. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h 2014-04-13 17:32:57.000000000 +0200
  29503. @@ -0,0 +1,129 @@
  29504. +/**
  29505. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  29506. + *
  29507. + * Redistribution and use in source and binary forms, with or without
  29508. + * modification, are permitted provided that the following conditions
  29509. + * are met:
  29510. + * 1. Redistributions of source code must retain the above copyright
  29511. + * notice, this list of conditions, and the following disclaimer,
  29512. + * without modification.
  29513. + * 2. Redistributions in binary form must reproduce the above copyright
  29514. + * notice, this list of conditions and the following disclaimer in the
  29515. + * documentation and/or other materials provided with the distribution.
  29516. + * 3. The names of the above-listed copyright holders may not be used
  29517. + * to endorse or promote products derived from this software without
  29518. + * specific prior written permission.
  29519. + *
  29520. + * ALTERNATIVELY, this software may be distributed under the terms of the
  29521. + * GNU General Public License ("GPL") version 2, as published by the Free
  29522. + * Software Foundation.
  29523. + *
  29524. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29525. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29526. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29527. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29528. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29529. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29530. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29531. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29532. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29533. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29534. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29535. + */
  29536. +
  29537. +#ifndef VCHIQ_IOCTLS_H
  29538. +#define VCHIQ_IOCTLS_H
  29539. +
  29540. +#include <linux/ioctl.h>
  29541. +#include "vchiq_if.h"
  29542. +
  29543. +#define VCHIQ_IOC_MAGIC 0xc4
  29544. +#define VCHIQ_INVALID_HANDLE (~0)
  29545. +
  29546. +typedef struct {
  29547. + VCHIQ_SERVICE_PARAMS_T params;
  29548. + int is_open;
  29549. + int is_vchi;
  29550. + unsigned int handle; /* OUT */
  29551. +} VCHIQ_CREATE_SERVICE_T;
  29552. +
  29553. +typedef struct {
  29554. + unsigned int handle;
  29555. + unsigned int count;
  29556. + const VCHIQ_ELEMENT_T *elements;
  29557. +} VCHIQ_QUEUE_MESSAGE_T;
  29558. +
  29559. +typedef struct {
  29560. + unsigned int handle;
  29561. + void *data;
  29562. + unsigned int size;
  29563. + void *userdata;
  29564. + VCHIQ_BULK_MODE_T mode;
  29565. +} VCHIQ_QUEUE_BULK_TRANSFER_T;
  29566. +
  29567. +typedef struct {
  29568. + VCHIQ_REASON_T reason;
  29569. + VCHIQ_HEADER_T *header;
  29570. + void *service_userdata;
  29571. + void *bulk_userdata;
  29572. +} VCHIQ_COMPLETION_DATA_T;
  29573. +
  29574. +typedef struct {
  29575. + unsigned int count;
  29576. + VCHIQ_COMPLETION_DATA_T *buf;
  29577. + unsigned int msgbufsize;
  29578. + unsigned int msgbufcount; /* IN/OUT */
  29579. + void **msgbufs;
  29580. +} VCHIQ_AWAIT_COMPLETION_T;
  29581. +
  29582. +typedef struct {
  29583. + unsigned int handle;
  29584. + int blocking;
  29585. + unsigned int bufsize;
  29586. + void *buf;
  29587. +} VCHIQ_DEQUEUE_MESSAGE_T;
  29588. +
  29589. +typedef struct {
  29590. + unsigned int config_size;
  29591. + VCHIQ_CONFIG_T *pconfig;
  29592. +} VCHIQ_GET_CONFIG_T;
  29593. +
  29594. +typedef struct {
  29595. + unsigned int handle;
  29596. + VCHIQ_SERVICE_OPTION_T option;
  29597. + int value;
  29598. +} VCHIQ_SET_SERVICE_OPTION_T;
  29599. +
  29600. +typedef struct {
  29601. + void *virt_addr;
  29602. + size_t num_bytes;
  29603. +} VCHIQ_DUMP_MEM_T;
  29604. +
  29605. +#define VCHIQ_IOC_CONNECT _IO(VCHIQ_IOC_MAGIC, 0)
  29606. +#define VCHIQ_IOC_SHUTDOWN _IO(VCHIQ_IOC_MAGIC, 1)
  29607. +#define VCHIQ_IOC_CREATE_SERVICE \
  29608. + _IOWR(VCHIQ_IOC_MAGIC, 2, VCHIQ_CREATE_SERVICE_T)
  29609. +#define VCHIQ_IOC_REMOVE_SERVICE _IO(VCHIQ_IOC_MAGIC, 3)
  29610. +#define VCHIQ_IOC_QUEUE_MESSAGE \
  29611. + _IOW(VCHIQ_IOC_MAGIC, 4, VCHIQ_QUEUE_MESSAGE_T)
  29612. +#define VCHIQ_IOC_QUEUE_BULK_TRANSMIT \
  29613. + _IOWR(VCHIQ_IOC_MAGIC, 5, VCHIQ_QUEUE_BULK_TRANSFER_T)
  29614. +#define VCHIQ_IOC_QUEUE_BULK_RECEIVE \
  29615. + _IOWR(VCHIQ_IOC_MAGIC, 6, VCHIQ_QUEUE_BULK_TRANSFER_T)
  29616. +#define VCHIQ_IOC_AWAIT_COMPLETION \
  29617. + _IOWR(VCHIQ_IOC_MAGIC, 7, VCHIQ_AWAIT_COMPLETION_T)
  29618. +#define VCHIQ_IOC_DEQUEUE_MESSAGE \
  29619. + _IOWR(VCHIQ_IOC_MAGIC, 8, VCHIQ_DEQUEUE_MESSAGE_T)
  29620. +#define VCHIQ_IOC_GET_CLIENT_ID _IO(VCHIQ_IOC_MAGIC, 9)
  29621. +#define VCHIQ_IOC_GET_CONFIG \
  29622. + _IOWR(VCHIQ_IOC_MAGIC, 10, VCHIQ_GET_CONFIG_T)
  29623. +#define VCHIQ_IOC_CLOSE_SERVICE _IO(VCHIQ_IOC_MAGIC, 11)
  29624. +#define VCHIQ_IOC_USE_SERVICE _IO(VCHIQ_IOC_MAGIC, 12)
  29625. +#define VCHIQ_IOC_RELEASE_SERVICE _IO(VCHIQ_IOC_MAGIC, 13)
  29626. +#define VCHIQ_IOC_SET_SERVICE_OPTION \
  29627. + _IOW(VCHIQ_IOC_MAGIC, 14, VCHIQ_SET_SERVICE_OPTION_T)
  29628. +#define VCHIQ_IOC_DUMP_PHYS_MEM \
  29629. + _IOW(VCHIQ_IOC_MAGIC, 15, VCHIQ_DUMP_MEM_T)
  29630. +#define VCHIQ_IOC_MAX 15
  29631. +
  29632. +#endif
  29633. diff -Nur linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c
  29634. --- linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c 1970-01-01 01:00:00.000000000 +0100
  29635. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c 2014-07-07 10:45:11.000000000 +0200
  29636. @@ -0,0 +1,457 @@
  29637. +/**
  29638. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  29639. + *
  29640. + * Redistribution and use in source and binary forms, with or without
  29641. + * modification, are permitted provided that the following conditions
  29642. + * are met:
  29643. + * 1. Redistributions of source code must retain the above copyright
  29644. + * notice, this list of conditions, and the following disclaimer,
  29645. + * without modification.
  29646. + * 2. Redistributions in binary form must reproduce the above copyright
  29647. + * notice, this list of conditions and the following disclaimer in the
  29648. + * documentation and/or other materials provided with the distribution.
  29649. + * 3. The names of the above-listed copyright holders may not be used
  29650. + * to endorse or promote products derived from this software without
  29651. + * specific prior written permission.
  29652. + *
  29653. + * ALTERNATIVELY, this software may be distributed under the terms of the
  29654. + * GNU General Public License ("GPL") version 2, as published by the Free
  29655. + * Software Foundation.
  29656. + *
  29657. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29658. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29659. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29660. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29661. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29662. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29663. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29664. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29665. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29666. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29667. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29668. + */
  29669. +
  29670. +/* ---- Include Files ---------------------------------------------------- */
  29671. +
  29672. +#include <linux/kernel.h>
  29673. +#include <linux/module.h>
  29674. +#include <linux/mutex.h>
  29675. +
  29676. +#include "vchiq_core.h"
  29677. +#include "vchiq_arm.h"
  29678. +#include "vchiq_killable.h"
  29679. +
  29680. +/* ---- Public Variables ------------------------------------------------- */
  29681. +
  29682. +/* ---- Private Constants and Types -------------------------------------- */
  29683. +
  29684. +struct bulk_waiter_node {
  29685. + struct bulk_waiter bulk_waiter;
  29686. + int pid;
  29687. + struct list_head list;
  29688. +};
  29689. +
  29690. +struct vchiq_instance_struct {
  29691. + VCHIQ_STATE_T *state;
  29692. +
  29693. + int connected;
  29694. +
  29695. + struct list_head bulk_waiter_list;
  29696. + struct mutex bulk_waiter_list_mutex;
  29697. +};
  29698. +
  29699. +static VCHIQ_STATUS_T
  29700. +vchiq_blocking_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  29701. + unsigned int size, VCHIQ_BULK_DIR_T dir);
  29702. +
  29703. +/****************************************************************************
  29704. +*
  29705. +* vchiq_initialise
  29706. +*
  29707. +***************************************************************************/
  29708. +#define VCHIQ_INIT_RETRIES 10
  29709. +VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *instanceOut)
  29710. +{
  29711. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  29712. + VCHIQ_STATE_T *state;
  29713. + VCHIQ_INSTANCE_T instance = NULL;
  29714. + int i;
  29715. +
  29716. + vchiq_log_trace(vchiq_core_log_level, "%s called", __func__);
  29717. +
  29718. + /* VideoCore may not be ready due to boot up timing.
  29719. + It may never be ready if kernel and firmware are mismatched, so don't block forever. */
  29720. + for (i=0; i<VCHIQ_INIT_RETRIES; i++) {
  29721. + state = vchiq_get_state();
  29722. + if (state)
  29723. + break;
  29724. + udelay(500);
  29725. + }
  29726. + if (i==VCHIQ_INIT_RETRIES) {
  29727. + vchiq_log_error(vchiq_core_log_level,
  29728. + "%s: videocore not initialized\n", __func__);
  29729. + goto failed;
  29730. + } else if (i>0) {
  29731. + vchiq_log_warning(vchiq_core_log_level,
  29732. + "%s: videocore initialized after %d retries\n", __func__, i);
  29733. + }
  29734. +
  29735. + instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  29736. + if (!instance) {
  29737. + vchiq_log_error(vchiq_core_log_level,
  29738. + "%s: error allocating vchiq instance\n", __func__);
  29739. + goto failed;
  29740. + }
  29741. +
  29742. + instance->connected = 0;
  29743. + instance->state = state;
  29744. + mutex_init(&instance->bulk_waiter_list_mutex);
  29745. + INIT_LIST_HEAD(&instance->bulk_waiter_list);
  29746. +
  29747. + *instanceOut = instance;
  29748. +
  29749. + status = VCHIQ_SUCCESS;
  29750. +
  29751. +failed:
  29752. + vchiq_log_trace(vchiq_core_log_level,
  29753. + "%s(%p): returning %d", __func__, instance, status);
  29754. +
  29755. + return status;
  29756. +}
  29757. +EXPORT_SYMBOL(vchiq_initialise);
  29758. +
  29759. +/****************************************************************************
  29760. +*
  29761. +* vchiq_shutdown
  29762. +*
  29763. +***************************************************************************/
  29764. +
  29765. +VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance)
  29766. +{
  29767. + VCHIQ_STATUS_T status;
  29768. + VCHIQ_STATE_T *state = instance->state;
  29769. +
  29770. + vchiq_log_trace(vchiq_core_log_level,
  29771. + "%s(%p) called", __func__, instance);
  29772. +
  29773. + if (mutex_lock_interruptible(&state->mutex) != 0)
  29774. + return VCHIQ_RETRY;
  29775. +
  29776. + /* Remove all services */
  29777. + status = vchiq_shutdown_internal(state, instance);
  29778. +
  29779. + mutex_unlock(&state->mutex);
  29780. +
  29781. + vchiq_log_trace(vchiq_core_log_level,
  29782. + "%s(%p): returning %d", __func__, instance, status);
  29783. +
  29784. + if (status == VCHIQ_SUCCESS) {
  29785. + struct list_head *pos, *next;
  29786. + list_for_each_safe(pos, next,
  29787. + &instance->bulk_waiter_list) {
  29788. + struct bulk_waiter_node *waiter;
  29789. + waiter = list_entry(pos,
  29790. + struct bulk_waiter_node,
  29791. + list);
  29792. + list_del(pos);
  29793. + vchiq_log_info(vchiq_arm_log_level,
  29794. + "bulk_waiter - cleaned up %x "
  29795. + "for pid %d",
  29796. + (unsigned int)waiter, waiter->pid);
  29797. + kfree(waiter);
  29798. + }
  29799. + kfree(instance);
  29800. + }
  29801. +
  29802. + return status;
  29803. +}
  29804. +EXPORT_SYMBOL(vchiq_shutdown);
  29805. +
  29806. +/****************************************************************************
  29807. +*
  29808. +* vchiq_is_connected
  29809. +*
  29810. +***************************************************************************/
  29811. +
  29812. +int vchiq_is_connected(VCHIQ_INSTANCE_T instance)
  29813. +{
  29814. + return instance->connected;
  29815. +}
  29816. +
  29817. +/****************************************************************************
  29818. +*
  29819. +* vchiq_connect
  29820. +*
  29821. +***************************************************************************/
  29822. +
  29823. +VCHIQ_STATUS_T vchiq_connect(VCHIQ_INSTANCE_T instance)
  29824. +{
  29825. + VCHIQ_STATUS_T status;
  29826. + VCHIQ_STATE_T *state = instance->state;
  29827. +
  29828. + vchiq_log_trace(vchiq_core_log_level,
  29829. + "%s(%p) called", __func__, instance);
  29830. +
  29831. + if (mutex_lock_interruptible(&state->mutex) != 0) {
  29832. + vchiq_log_trace(vchiq_core_log_level,
  29833. + "%s: call to mutex_lock failed", __func__);
  29834. + status = VCHIQ_RETRY;
  29835. + goto failed;
  29836. + }
  29837. + status = vchiq_connect_internal(state, instance);
  29838. +
  29839. + if (status == VCHIQ_SUCCESS)
  29840. + instance->connected = 1;
  29841. +
  29842. + mutex_unlock(&state->mutex);
  29843. +
  29844. +failed:
  29845. + vchiq_log_trace(vchiq_core_log_level,
  29846. + "%s(%p): returning %d", __func__, instance, status);
  29847. +
  29848. + return status;
  29849. +}
  29850. +EXPORT_SYMBOL(vchiq_connect);
  29851. +
  29852. +/****************************************************************************
  29853. +*
  29854. +* vchiq_add_service
  29855. +*
  29856. +***************************************************************************/
  29857. +
  29858. +VCHIQ_STATUS_T vchiq_add_service(
  29859. + VCHIQ_INSTANCE_T instance,
  29860. + const VCHIQ_SERVICE_PARAMS_T *params,
  29861. + VCHIQ_SERVICE_HANDLE_T *phandle)
  29862. +{
  29863. + VCHIQ_STATUS_T status;
  29864. + VCHIQ_STATE_T *state = instance->state;
  29865. + VCHIQ_SERVICE_T *service = NULL;
  29866. + int srvstate;
  29867. +
  29868. + vchiq_log_trace(vchiq_core_log_level,
  29869. + "%s(%p) called", __func__, instance);
  29870. +
  29871. + *phandle = VCHIQ_SERVICE_HANDLE_INVALID;
  29872. +
  29873. + srvstate = vchiq_is_connected(instance)
  29874. + ? VCHIQ_SRVSTATE_LISTENING
  29875. + : VCHIQ_SRVSTATE_HIDDEN;
  29876. +
  29877. + service = vchiq_add_service_internal(
  29878. + state,
  29879. + params,
  29880. + srvstate,
  29881. + instance,
  29882. + NULL);
  29883. +
  29884. + if (service) {
  29885. + *phandle = service->handle;
  29886. + status = VCHIQ_SUCCESS;
  29887. + } else
  29888. + status = VCHIQ_ERROR;
  29889. +
  29890. + vchiq_log_trace(vchiq_core_log_level,
  29891. + "%s(%p): returning %d", __func__, instance, status);
  29892. +
  29893. + return status;
  29894. +}
  29895. +EXPORT_SYMBOL(vchiq_add_service);
  29896. +
  29897. +/****************************************************************************
  29898. +*
  29899. +* vchiq_open_service
  29900. +*
  29901. +***************************************************************************/
  29902. +
  29903. +VCHIQ_STATUS_T vchiq_open_service(
  29904. + VCHIQ_INSTANCE_T instance,
  29905. + const VCHIQ_SERVICE_PARAMS_T *params,
  29906. + VCHIQ_SERVICE_HANDLE_T *phandle)
  29907. +{
  29908. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  29909. + VCHIQ_STATE_T *state = instance->state;
  29910. + VCHIQ_SERVICE_T *service = NULL;
  29911. +
  29912. + vchiq_log_trace(vchiq_core_log_level,
  29913. + "%s(%p) called", __func__, instance);
  29914. +
  29915. + *phandle = VCHIQ_SERVICE_HANDLE_INVALID;
  29916. +
  29917. + if (!vchiq_is_connected(instance))
  29918. + goto failed;
  29919. +
  29920. + service = vchiq_add_service_internal(state,
  29921. + params,
  29922. + VCHIQ_SRVSTATE_OPENING,
  29923. + instance,
  29924. + NULL);
  29925. +
  29926. + if (service) {
  29927. + status = vchiq_open_service_internal(service, current->pid);
  29928. + if (status == VCHIQ_SUCCESS)
  29929. + *phandle = service->handle;
  29930. + else
  29931. + vchiq_remove_service(service->handle);
  29932. + }
  29933. +
  29934. +failed:
  29935. + vchiq_log_trace(vchiq_core_log_level,
  29936. + "%s(%p): returning %d", __func__, instance, status);
  29937. +
  29938. + return status;
  29939. +}
  29940. +EXPORT_SYMBOL(vchiq_open_service);
  29941. +
  29942. +VCHIQ_STATUS_T
  29943. +vchiq_queue_bulk_transmit(VCHIQ_SERVICE_HANDLE_T handle,
  29944. + const void *data, unsigned int size, void *userdata)
  29945. +{
  29946. + return vchiq_bulk_transfer(handle,
  29947. + VCHI_MEM_HANDLE_INVALID, (void *)data, size, userdata,
  29948. + VCHIQ_BULK_MODE_CALLBACK, VCHIQ_BULK_TRANSMIT);
  29949. +}
  29950. +EXPORT_SYMBOL(vchiq_queue_bulk_transmit);
  29951. +
  29952. +VCHIQ_STATUS_T
  29953. +vchiq_queue_bulk_receive(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  29954. + unsigned int size, void *userdata)
  29955. +{
  29956. + return vchiq_bulk_transfer(handle,
  29957. + VCHI_MEM_HANDLE_INVALID, data, size, userdata,
  29958. + VCHIQ_BULK_MODE_CALLBACK, VCHIQ_BULK_RECEIVE);
  29959. +}
  29960. +EXPORT_SYMBOL(vchiq_queue_bulk_receive);
  29961. +
  29962. +VCHIQ_STATUS_T
  29963. +vchiq_bulk_transmit(VCHIQ_SERVICE_HANDLE_T handle, const void *data,
  29964. + unsigned int size, void *userdata, VCHIQ_BULK_MODE_T mode)
  29965. +{
  29966. + VCHIQ_STATUS_T status;
  29967. +
  29968. + switch (mode) {
  29969. + case VCHIQ_BULK_MODE_NOCALLBACK:
  29970. + case VCHIQ_BULK_MODE_CALLBACK:
  29971. + status = vchiq_bulk_transfer(handle,
  29972. + VCHI_MEM_HANDLE_INVALID, (void *)data, size, userdata,
  29973. + mode, VCHIQ_BULK_TRANSMIT);
  29974. + break;
  29975. + case VCHIQ_BULK_MODE_BLOCKING:
  29976. + status = vchiq_blocking_bulk_transfer(handle,
  29977. + (void *)data, size, VCHIQ_BULK_TRANSMIT);
  29978. + break;
  29979. + default:
  29980. + return VCHIQ_ERROR;
  29981. + }
  29982. +
  29983. + return status;
  29984. +}
  29985. +EXPORT_SYMBOL(vchiq_bulk_transmit);
  29986. +
  29987. +VCHIQ_STATUS_T
  29988. +vchiq_bulk_receive(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  29989. + unsigned int size, void *userdata, VCHIQ_BULK_MODE_T mode)
  29990. +{
  29991. + VCHIQ_STATUS_T status;
  29992. +
  29993. + switch (mode) {
  29994. + case VCHIQ_BULK_MODE_NOCALLBACK:
  29995. + case VCHIQ_BULK_MODE_CALLBACK:
  29996. + status = vchiq_bulk_transfer(handle,
  29997. + VCHI_MEM_HANDLE_INVALID, data, size, userdata,
  29998. + mode, VCHIQ_BULK_RECEIVE);
  29999. + break;
  30000. + case VCHIQ_BULK_MODE_BLOCKING:
  30001. + status = vchiq_blocking_bulk_transfer(handle,
  30002. + (void *)data, size, VCHIQ_BULK_RECEIVE);
  30003. + break;
  30004. + default:
  30005. + return VCHIQ_ERROR;
  30006. + }
  30007. +
  30008. + return status;
  30009. +}
  30010. +EXPORT_SYMBOL(vchiq_bulk_receive);
  30011. +
  30012. +static VCHIQ_STATUS_T
  30013. +vchiq_blocking_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  30014. + unsigned int size, VCHIQ_BULK_DIR_T dir)
  30015. +{
  30016. + VCHIQ_INSTANCE_T instance;
  30017. + VCHIQ_SERVICE_T *service;
  30018. + VCHIQ_STATUS_T status;
  30019. + struct bulk_waiter_node *waiter = NULL;
  30020. + struct list_head *pos;
  30021. +
  30022. + service = find_service_by_handle(handle);
  30023. + if (!service)
  30024. + return VCHIQ_ERROR;
  30025. +
  30026. + instance = service->instance;
  30027. +
  30028. + unlock_service(service);
  30029. +
  30030. + mutex_lock(&instance->bulk_waiter_list_mutex);
  30031. + list_for_each(pos, &instance->bulk_waiter_list) {
  30032. + if (list_entry(pos, struct bulk_waiter_node,
  30033. + list)->pid == current->pid) {
  30034. + waiter = list_entry(pos,
  30035. + struct bulk_waiter_node,
  30036. + list);
  30037. + list_del(pos);
  30038. + break;
  30039. + }
  30040. + }
  30041. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  30042. +
  30043. + if (waiter) {
  30044. + VCHIQ_BULK_T *bulk = waiter->bulk_waiter.bulk;
  30045. + if (bulk) {
  30046. + /* This thread has an outstanding bulk transfer. */
  30047. + if ((bulk->data != data) ||
  30048. + (bulk->size != size)) {
  30049. + /* This is not a retry of the previous one.
  30050. + ** Cancel the signal when the transfer
  30051. + ** completes. */
  30052. + spin_lock(&bulk_waiter_spinlock);
  30053. + bulk->userdata = NULL;
  30054. + spin_unlock(&bulk_waiter_spinlock);
  30055. + }
  30056. + }
  30057. + }
  30058. +
  30059. + if (!waiter) {
  30060. + waiter = kzalloc(sizeof(struct bulk_waiter_node), GFP_KERNEL);
  30061. + if (!waiter) {
  30062. + vchiq_log_error(vchiq_core_log_level,
  30063. + "%s - out of memory", __func__);
  30064. + return VCHIQ_ERROR;
  30065. + }
  30066. + }
  30067. +
  30068. + status = vchiq_bulk_transfer(handle, VCHI_MEM_HANDLE_INVALID,
  30069. + data, size, &waiter->bulk_waiter, VCHIQ_BULK_MODE_BLOCKING,
  30070. + dir);
  30071. + if ((status != VCHIQ_RETRY) || fatal_signal_pending(current) ||
  30072. + !waiter->bulk_waiter.bulk) {
  30073. + VCHIQ_BULK_T *bulk = waiter->bulk_waiter.bulk;
  30074. + if (bulk) {
  30075. + /* Cancel the signal when the transfer
  30076. + ** completes. */
  30077. + spin_lock(&bulk_waiter_spinlock);
  30078. + bulk->userdata = NULL;
  30079. + spin_unlock(&bulk_waiter_spinlock);
  30080. + }
  30081. + kfree(waiter);
  30082. + } else {
  30083. + waiter->pid = current->pid;
  30084. + mutex_lock(&instance->bulk_waiter_list_mutex);
  30085. + list_add(&waiter->list, &instance->bulk_waiter_list);
  30086. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  30087. + vchiq_log_info(vchiq_arm_log_level,
  30088. + "saved bulk_waiter %x for pid %d",
  30089. + (unsigned int)waiter, current->pid);
  30090. + }
  30091. +
  30092. + return status;
  30093. +}
  30094. diff -Nur linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h
  30095. --- linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h 1970-01-01 01:00:00.000000000 +0100
  30096. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h 2014-07-07 10:45:11.000000000 +0200
  30097. @@ -0,0 +1,69 @@
  30098. +/**
  30099. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  30100. + *
  30101. + * Redistribution and use in source and binary forms, with or without
  30102. + * modification, are permitted provided that the following conditions
  30103. + * are met:
  30104. + * 1. Redistributions of source code must retain the above copyright
  30105. + * notice, this list of conditions, and the following disclaimer,
  30106. + * without modification.
  30107. + * 2. Redistributions in binary form must reproduce the above copyright
  30108. + * notice, this list of conditions and the following disclaimer in the
  30109. + * documentation and/or other materials provided with the distribution.
  30110. + * 3. The names of the above-listed copyright holders may not be used
  30111. + * to endorse or promote products derived from this software without
  30112. + * specific prior written permission.
  30113. + *
  30114. + * ALTERNATIVELY, this software may be distributed under the terms of the
  30115. + * GNU General Public License ("GPL") version 2, as published by the Free
  30116. + * Software Foundation.
  30117. + *
  30118. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  30119. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  30120. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30121. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  30122. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  30123. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  30124. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30125. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30126. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30127. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30128. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30129. + */
  30130. +
  30131. +#ifndef VCHIQ_KILLABLE_H
  30132. +#define VCHIQ_KILLABLE_H
  30133. +
  30134. +#include <linux/mutex.h>
  30135. +#include <linux/semaphore.h>
  30136. +
  30137. +#define SHUTDOWN_SIGS (sigmask(SIGKILL) | sigmask(SIGINT) | sigmask(SIGQUIT) | sigmask(SIGTRAP) | sigmask(SIGSTOP) | sigmask(SIGCONT))
  30138. +
  30139. +static inline int __must_check down_interruptible_killable(struct semaphore *sem)
  30140. +{
  30141. + /* Allow interception of killable signals only. We don't want to be interrupted by harmless signals like SIGALRM */
  30142. + int ret;
  30143. + sigset_t blocked, oldset;
  30144. + siginitsetinv(&blocked, SHUTDOWN_SIGS);
  30145. + sigprocmask(SIG_SETMASK, &blocked, &oldset);
  30146. + ret = down_interruptible(sem);
  30147. + sigprocmask(SIG_SETMASK, &oldset, NULL);
  30148. + return ret;
  30149. +}
  30150. +#define down_interruptible down_interruptible_killable
  30151. +
  30152. +
  30153. +static inline int __must_check mutex_lock_interruptible_killable(struct mutex *lock)
  30154. +{
  30155. + /* Allow interception of killable signals only. We don't want to be interrupted by harmless signals like SIGALRM */
  30156. + int ret;
  30157. + sigset_t blocked, oldset;
  30158. + siginitsetinv(&blocked, SHUTDOWN_SIGS);
  30159. + sigprocmask(SIG_SETMASK, &blocked, &oldset);
  30160. + ret = mutex_lock_interruptible(lock);
  30161. + sigprocmask(SIG_SETMASK, &oldset, NULL);
  30162. + return ret;
  30163. +}
  30164. +#define mutex_lock_interruptible mutex_lock_interruptible_killable
  30165. +
  30166. +#endif
  30167. diff -Nur linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h
  30168. --- linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h 1970-01-01 01:00:00.000000000 +0100
  30169. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h 2014-04-13 17:32:57.000000000 +0200
  30170. @@ -0,0 +1,71 @@
  30171. +/**
  30172. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  30173. + *
  30174. + * Redistribution and use in source and binary forms, with or without
  30175. + * modification, are permitted provided that the following conditions
  30176. + * are met:
  30177. + * 1. Redistributions of source code must retain the above copyright
  30178. + * notice, this list of conditions, and the following disclaimer,
  30179. + * without modification.
  30180. + * 2. Redistributions in binary form must reproduce the above copyright
  30181. + * notice, this list of conditions and the following disclaimer in the
  30182. + * documentation and/or other materials provided with the distribution.
  30183. + * 3. The names of the above-listed copyright holders may not be used
  30184. + * to endorse or promote products derived from this software without
  30185. + * specific prior written permission.
  30186. + *
  30187. + * ALTERNATIVELY, this software may be distributed under the terms of the
  30188. + * GNU General Public License ("GPL") version 2, as published by the Free
  30189. + * Software Foundation.
  30190. + *
  30191. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  30192. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  30193. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30194. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  30195. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  30196. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  30197. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30198. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30199. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30200. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30201. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30202. + */
  30203. +
  30204. +#ifndef VCHIQ_MEMDRV_H
  30205. +#define VCHIQ_MEMDRV_H
  30206. +
  30207. +/* ---- Include Files ----------------------------------------------------- */
  30208. +
  30209. +#include <linux/kernel.h>
  30210. +#include "vchiq_if.h"
  30211. +
  30212. +/* ---- Constants and Types ---------------------------------------------- */
  30213. +
  30214. +typedef struct {
  30215. + void *armSharedMemVirt;
  30216. + dma_addr_t armSharedMemPhys;
  30217. + size_t armSharedMemSize;
  30218. +
  30219. + void *vcSharedMemVirt;
  30220. + dma_addr_t vcSharedMemPhys;
  30221. + size_t vcSharedMemSize;
  30222. +} VCHIQ_SHARED_MEM_INFO_T;
  30223. +
  30224. +/* ---- Variable Externs ------------------------------------------------- */
  30225. +
  30226. +/* ---- Function Prototypes ---------------------------------------------- */
  30227. +
  30228. +void vchiq_get_shared_mem_info(VCHIQ_SHARED_MEM_INFO_T *info);
  30229. +
  30230. +VCHIQ_STATUS_T vchiq_memdrv_initialise(void);
  30231. +
  30232. +VCHIQ_STATUS_T vchiq_userdrv_create_instance(
  30233. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  30234. +
  30235. +VCHIQ_STATUS_T vchiq_userdrv_suspend(
  30236. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  30237. +
  30238. +VCHIQ_STATUS_T vchiq_userdrv_resume(
  30239. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  30240. +
  30241. +#endif
  30242. diff -Nur linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h
  30243. --- linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h 1970-01-01 01:00:00.000000000 +0100
  30244. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h 2014-04-13 17:32:57.000000000 +0200
  30245. @@ -0,0 +1,58 @@
  30246. +/**
  30247. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  30248. + *
  30249. + * Redistribution and use in source and binary forms, with or without
  30250. + * modification, are permitted provided that the following conditions
  30251. + * are met:
  30252. + * 1. Redistributions of source code must retain the above copyright
  30253. + * notice, this list of conditions, and the following disclaimer,
  30254. + * without modification.
  30255. + * 2. Redistributions in binary form must reproduce the above copyright
  30256. + * notice, this list of conditions and the following disclaimer in the
  30257. + * documentation and/or other materials provided with the distribution.
  30258. + * 3. The names of the above-listed copyright holders may not be used
  30259. + * to endorse or promote products derived from this software without
  30260. + * specific prior written permission.
  30261. + *
  30262. + * ALTERNATIVELY, this software may be distributed under the terms of the
  30263. + * GNU General Public License ("GPL") version 2, as published by the Free
  30264. + * Software Foundation.
  30265. + *
  30266. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  30267. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  30268. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30269. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  30270. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  30271. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  30272. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30273. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30274. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30275. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30276. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30277. + */
  30278. +
  30279. +#ifndef VCHIQ_PAGELIST_H
  30280. +#define VCHIQ_PAGELIST_H
  30281. +
  30282. +#ifndef PAGE_SIZE
  30283. +#define PAGE_SIZE 4096
  30284. +#endif
  30285. +#define CACHE_LINE_SIZE 32
  30286. +#define PAGELIST_WRITE 0
  30287. +#define PAGELIST_READ 1
  30288. +#define PAGELIST_READ_WITH_FRAGMENTS 2
  30289. +
  30290. +typedef struct pagelist_struct {
  30291. + unsigned long length;
  30292. + unsigned short type;
  30293. + unsigned short offset;
  30294. + unsigned long addrs[1]; /* N.B. 12 LSBs hold the number of following
  30295. + pages at consecutive addresses. */
  30296. +} PAGELIST_T;
  30297. +
  30298. +typedef struct fragments_struct {
  30299. + char headbuf[CACHE_LINE_SIZE];
  30300. + char tailbuf[CACHE_LINE_SIZE];
  30301. +} FRAGMENTS_T;
  30302. +
  30303. +#endif /* VCHIQ_PAGELIST_H */
  30304. diff -Nur linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c
  30305. --- linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c 1970-01-01 01:00:00.000000000 +0100
  30306. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c 2014-07-07 10:45:11.000000000 +0200
  30307. @@ -0,0 +1,253 @@
  30308. +/**
  30309. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  30310. + *
  30311. + * Redistribution and use in source and binary forms, with or without
  30312. + * modification, are permitted provided that the following conditions
  30313. + * are met:
  30314. + * 1. Redistributions of source code must retain the above copyright
  30315. + * notice, this list of conditions, and the following disclaimer,
  30316. + * without modification.
  30317. + * 2. Redistributions in binary form must reproduce the above copyright
  30318. + * notice, this list of conditions and the following disclaimer in the
  30319. + * documentation and/or other materials provided with the distribution.
  30320. + * 3. The names of the above-listed copyright holders may not be used
  30321. + * to endorse or promote products derived from this software without
  30322. + * specific prior written permission.
  30323. + *
  30324. + * ALTERNATIVELY, this software may be distributed under the terms of the
  30325. + * GNU General Public License ("GPL") version 2, as published by the Free
  30326. + * Software Foundation.
  30327. + *
  30328. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  30329. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  30330. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30331. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  30332. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  30333. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  30334. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30335. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30336. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30337. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30338. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30339. + */
  30340. +
  30341. +
  30342. +#include <linux/proc_fs.h>
  30343. +#include "vchiq_core.h"
  30344. +#include "vchiq_arm.h"
  30345. +
  30346. +#if 1
  30347. +
  30348. +int vchiq_proc_init(void)
  30349. +{
  30350. + return 0;
  30351. +}
  30352. +
  30353. +void vchiq_proc_deinit(void)
  30354. +{
  30355. +}
  30356. +
  30357. +#else
  30358. +
  30359. +struct vchiq_proc_info {
  30360. + /* Global 'vc' proc entry used by all instances */
  30361. + struct proc_dir_entry *vc_cfg_dir;
  30362. +
  30363. + /* one entry per client process */
  30364. + struct proc_dir_entry *clients;
  30365. +
  30366. + /* log categories */
  30367. + struct proc_dir_entry *log_categories;
  30368. +};
  30369. +
  30370. +static struct vchiq_proc_info proc_info;
  30371. +
  30372. +struct proc_dir_entry *vchiq_proc_top(void)
  30373. +{
  30374. + BUG_ON(proc_info.vc_cfg_dir == NULL);
  30375. + return proc_info.vc_cfg_dir;
  30376. +}
  30377. +
  30378. +/****************************************************************************
  30379. +*
  30380. +* log category entries
  30381. +*
  30382. +***************************************************************************/
  30383. +#define PROC_WRITE_BUF_SIZE 256
  30384. +
  30385. +#define VCHIQ_LOG_ERROR_STR "error"
  30386. +#define VCHIQ_LOG_WARNING_STR "warning"
  30387. +#define VCHIQ_LOG_INFO_STR "info"
  30388. +#define VCHIQ_LOG_TRACE_STR "trace"
  30389. +
  30390. +static int log_cfg_read(char *buffer,
  30391. + char **start,
  30392. + off_t off,
  30393. + int count,
  30394. + int *eof,
  30395. + void *data)
  30396. +{
  30397. + int len = 0;
  30398. + char *log_value = NULL;
  30399. +
  30400. + switch (*((int *)data)) {
  30401. + case VCHIQ_LOG_ERROR:
  30402. + log_value = VCHIQ_LOG_ERROR_STR;
  30403. + break;
  30404. + case VCHIQ_LOG_WARNING:
  30405. + log_value = VCHIQ_LOG_WARNING_STR;
  30406. + break;
  30407. + case VCHIQ_LOG_INFO:
  30408. + log_value = VCHIQ_LOG_INFO_STR;
  30409. + break;
  30410. + case VCHIQ_LOG_TRACE:
  30411. + log_value = VCHIQ_LOG_TRACE_STR;
  30412. + break;
  30413. + default:
  30414. + break;
  30415. + }
  30416. +
  30417. + len += sprintf(buffer + len,
  30418. + "%s\n",
  30419. + log_value ? log_value : "(null)");
  30420. +
  30421. + return len;
  30422. +}
  30423. +
  30424. +
  30425. +static int log_cfg_write(struct file *file,
  30426. + const char __user *buffer,
  30427. + unsigned long count,
  30428. + void *data)
  30429. +{
  30430. + int *log_module = data;
  30431. + char kbuf[PROC_WRITE_BUF_SIZE + 1];
  30432. +
  30433. + (void)file;
  30434. +
  30435. + memset(kbuf, 0, PROC_WRITE_BUF_SIZE + 1);
  30436. + if (count >= PROC_WRITE_BUF_SIZE)
  30437. + count = PROC_WRITE_BUF_SIZE;
  30438. +
  30439. + if (copy_from_user(kbuf,
  30440. + buffer,
  30441. + count) != 0)
  30442. + return -EFAULT;
  30443. + kbuf[count - 1] = 0;
  30444. +
  30445. + if (strncmp("error", kbuf, strlen("error")) == 0)
  30446. + *log_module = VCHIQ_LOG_ERROR;
  30447. + else if (strncmp("warning", kbuf, strlen("warning")) == 0)
  30448. + *log_module = VCHIQ_LOG_WARNING;
  30449. + else if (strncmp("info", kbuf, strlen("info")) == 0)
  30450. + *log_module = VCHIQ_LOG_INFO;
  30451. + else if (strncmp("trace", kbuf, strlen("trace")) == 0)
  30452. + *log_module = VCHIQ_LOG_TRACE;
  30453. + else
  30454. + *log_module = VCHIQ_LOG_DEFAULT;
  30455. +
  30456. + return count;
  30457. +}
  30458. +
  30459. +/* Log category proc entries */
  30460. +struct vchiq_proc_log_entry {
  30461. + const char *name;
  30462. + int *plevel;
  30463. + struct proc_dir_entry *dir;
  30464. +};
  30465. +
  30466. +static struct vchiq_proc_log_entry vchiq_proc_log_entries[] = {
  30467. + { "core", &vchiq_core_log_level },
  30468. + { "msg", &vchiq_core_msg_log_level },
  30469. + { "sync", &vchiq_sync_log_level },
  30470. + { "susp", &vchiq_susp_log_level },
  30471. + { "arm", &vchiq_arm_log_level },
  30472. +};
  30473. +static int n_log_entries =
  30474. + sizeof(vchiq_proc_log_entries)/sizeof(vchiq_proc_log_entries[0]);
  30475. +
  30476. +/* create an entry under /proc/vc/log for each log category */
  30477. +static int vchiq_proc_create_log_entries(struct proc_dir_entry *top)
  30478. +{
  30479. + struct proc_dir_entry *dir;
  30480. + size_t i;
  30481. + int ret = 0;
  30482. + dir = proc_mkdir("log", proc_info.vc_cfg_dir);
  30483. + if (!dir)
  30484. + return -ENOMEM;
  30485. + proc_info.log_categories = dir;
  30486. +
  30487. + for (i = 0; i < n_log_entries; i++) {
  30488. + dir = create_proc_entry(vchiq_proc_log_entries[i].name,
  30489. + 0644,
  30490. + proc_info.log_categories);
  30491. + if (!dir) {
  30492. + ret = -ENOMEM;
  30493. + break;
  30494. + }
  30495. +
  30496. + dir->read_proc = &log_cfg_read;
  30497. + dir->write_proc = &log_cfg_write;
  30498. + dir->data = (void *)vchiq_proc_log_entries[i].plevel;
  30499. +
  30500. + vchiq_proc_log_entries[i].dir = dir;
  30501. + }
  30502. + return ret;
  30503. +}
  30504. +
  30505. +
  30506. +int vchiq_proc_init(void)
  30507. +{
  30508. + BUG_ON(proc_info.vc_cfg_dir != NULL);
  30509. +
  30510. + proc_info.vc_cfg_dir = proc_mkdir("vc", NULL);
  30511. + if (proc_info.vc_cfg_dir == NULL)
  30512. + goto fail;
  30513. +
  30514. + proc_info.clients = proc_mkdir("clients",
  30515. + proc_info.vc_cfg_dir);
  30516. + if (!proc_info.clients)
  30517. + goto fail;
  30518. +
  30519. + if (vchiq_proc_create_log_entries(proc_info.vc_cfg_dir) != 0)
  30520. + goto fail;
  30521. +
  30522. + return 0;
  30523. +
  30524. +fail:
  30525. + vchiq_proc_deinit();
  30526. + vchiq_log_error(vchiq_arm_log_level,
  30527. + "%s: failed to create proc directory",
  30528. + __func__);
  30529. +
  30530. + return -ENOMEM;
  30531. +}
  30532. +
  30533. +/* remove all the proc entries */
  30534. +void vchiq_proc_deinit(void)
  30535. +{
  30536. + /* log category entries */
  30537. + if (proc_info.log_categories) {
  30538. + size_t i;
  30539. + for (i = 0; i < n_log_entries; i++)
  30540. + if (vchiq_proc_log_entries[i].dir)
  30541. + remove_proc_entry(
  30542. + vchiq_proc_log_entries[i].name,
  30543. + proc_info.log_categories);
  30544. +
  30545. + remove_proc_entry(proc_info.log_categories->name,
  30546. + proc_info.vc_cfg_dir);
  30547. + }
  30548. + if (proc_info.clients)
  30549. + remove_proc_entry(proc_info.clients->name,
  30550. + proc_info.vc_cfg_dir);
  30551. + if (proc_info.vc_cfg_dir)
  30552. + remove_proc_entry(proc_info.vc_cfg_dir->name, NULL);
  30553. +}
  30554. +
  30555. +struct proc_dir_entry *vchiq_clients_top(void)
  30556. +{
  30557. + return proc_info.clients;
  30558. +}
  30559. +
  30560. +#endif
  30561. diff -Nur linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c
  30562. --- linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c 1970-01-01 01:00:00.000000000 +0100
  30563. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c 2014-04-13 17:32:57.000000000 +0200
  30564. @@ -0,0 +1,828 @@
  30565. +/**
  30566. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  30567. + *
  30568. + * Redistribution and use in source and binary forms, with or without
  30569. + * modification, are permitted provided that the following conditions
  30570. + * are met:
  30571. + * 1. Redistributions of source code must retain the above copyright
  30572. + * notice, this list of conditions, and the following disclaimer,
  30573. + * without modification.
  30574. + * 2. Redistributions in binary form must reproduce the above copyright
  30575. + * notice, this list of conditions and the following disclaimer in the
  30576. + * documentation and/or other materials provided with the distribution.
  30577. + * 3. The names of the above-listed copyright holders may not be used
  30578. + * to endorse or promote products derived from this software without
  30579. + * specific prior written permission.
  30580. + *
  30581. + * ALTERNATIVELY, this software may be distributed under the terms of the
  30582. + * GNU General Public License ("GPL") version 2, as published by the Free
  30583. + * Software Foundation.
  30584. + *
  30585. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  30586. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  30587. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30588. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  30589. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  30590. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  30591. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30592. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30593. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30594. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30595. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30596. + */
  30597. +#include <linux/module.h>
  30598. +#include <linux/types.h>
  30599. +
  30600. +#include "interface/vchi/vchi.h"
  30601. +#include "vchiq.h"
  30602. +#include "vchiq_core.h"
  30603. +
  30604. +#include "vchiq_util.h"
  30605. +
  30606. +#include <stddef.h>
  30607. +
  30608. +#define vchiq_status_to_vchi(status) ((int32_t)status)
  30609. +
  30610. +typedef struct {
  30611. + VCHIQ_SERVICE_HANDLE_T handle;
  30612. +
  30613. + VCHIU_QUEUE_T queue;
  30614. +
  30615. + VCHI_CALLBACK_T callback;
  30616. + void *callback_param;
  30617. +} SHIM_SERVICE_T;
  30618. +
  30619. +/* ----------------------------------------------------------------------
  30620. + * return pointer to the mphi message driver function table
  30621. + * -------------------------------------------------------------------- */
  30622. +const VCHI_MESSAGE_DRIVER_T *
  30623. +vchi_mphi_message_driver_func_table(void)
  30624. +{
  30625. + return NULL;
  30626. +}
  30627. +
  30628. +/* ----------------------------------------------------------------------
  30629. + * return a pointer to the 'single' connection driver fops
  30630. + * -------------------------------------------------------------------- */
  30631. +const VCHI_CONNECTION_API_T *
  30632. +single_get_func_table(void)
  30633. +{
  30634. + return NULL;
  30635. +}
  30636. +
  30637. +VCHI_CONNECTION_T *vchi_create_connection(
  30638. + const VCHI_CONNECTION_API_T *function_table,
  30639. + const VCHI_MESSAGE_DRIVER_T *low_level)
  30640. +{
  30641. + (void)function_table;
  30642. + (void)low_level;
  30643. + return NULL;
  30644. +}
  30645. +
  30646. +/***********************************************************
  30647. + * Name: vchi_msg_peek
  30648. + *
  30649. + * Arguments: const VCHI_SERVICE_HANDLE_T handle,
  30650. + * void **data,
  30651. + * uint32_t *msg_size,
  30652. +
  30653. +
  30654. + * VCHI_FLAGS_T flags
  30655. + *
  30656. + * Description: Routine to return a pointer to the current message (to allow in
  30657. + * place processing). The message can be removed using
  30658. + * vchi_msg_remove when you're finished
  30659. + *
  30660. + * Returns: int32_t - success == 0
  30661. + *
  30662. + ***********************************************************/
  30663. +int32_t vchi_msg_peek(VCHI_SERVICE_HANDLE_T handle,
  30664. + void **data,
  30665. + uint32_t *msg_size,
  30666. + VCHI_FLAGS_T flags)
  30667. +{
  30668. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30669. + VCHIQ_HEADER_T *header;
  30670. +
  30671. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  30672. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  30673. +
  30674. + if (flags == VCHI_FLAGS_NONE)
  30675. + if (vchiu_queue_is_empty(&service->queue))
  30676. + return -1;
  30677. +
  30678. + header = vchiu_queue_peek(&service->queue);
  30679. +
  30680. + *data = header->data;
  30681. + *msg_size = header->size;
  30682. +
  30683. + return 0;
  30684. +}
  30685. +EXPORT_SYMBOL(vchi_msg_peek);
  30686. +
  30687. +/***********************************************************
  30688. + * Name: vchi_msg_remove
  30689. + *
  30690. + * Arguments: const VCHI_SERVICE_HANDLE_T handle,
  30691. + *
  30692. + * Description: Routine to remove a message (after it has been read with
  30693. + * vchi_msg_peek)
  30694. + *
  30695. + * Returns: int32_t - success == 0
  30696. + *
  30697. + ***********************************************************/
  30698. +int32_t vchi_msg_remove(VCHI_SERVICE_HANDLE_T handle)
  30699. +{
  30700. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30701. + VCHIQ_HEADER_T *header;
  30702. +
  30703. + header = vchiu_queue_pop(&service->queue);
  30704. +
  30705. + vchiq_release_message(service->handle, header);
  30706. +
  30707. + return 0;
  30708. +}
  30709. +EXPORT_SYMBOL(vchi_msg_remove);
  30710. +
  30711. +/***********************************************************
  30712. + * Name: vchi_msg_queue
  30713. + *
  30714. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  30715. + * const void *data,
  30716. + * uint32_t data_size,
  30717. + * VCHI_FLAGS_T flags,
  30718. + * void *msg_handle,
  30719. + *
  30720. + * Description: Thin wrapper to queue a message onto a connection
  30721. + *
  30722. + * Returns: int32_t - success == 0
  30723. + *
  30724. + ***********************************************************/
  30725. +int32_t vchi_msg_queue(VCHI_SERVICE_HANDLE_T handle,
  30726. + const void *data,
  30727. + uint32_t data_size,
  30728. + VCHI_FLAGS_T flags,
  30729. + void *msg_handle)
  30730. +{
  30731. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30732. + VCHIQ_ELEMENT_T element = {data, data_size};
  30733. + VCHIQ_STATUS_T status;
  30734. +
  30735. + (void)msg_handle;
  30736. +
  30737. + WARN_ON(flags != VCHI_FLAGS_BLOCK_UNTIL_QUEUED);
  30738. +
  30739. + status = vchiq_queue_message(service->handle, &element, 1);
  30740. +
  30741. + /* vchiq_queue_message() may return VCHIQ_RETRY, so we need to
  30742. + ** implement a retry mechanism since this function is supposed
  30743. + ** to block until queued
  30744. + */
  30745. + while (status == VCHIQ_RETRY) {
  30746. + msleep(1);
  30747. + status = vchiq_queue_message(service->handle, &element, 1);
  30748. + }
  30749. +
  30750. + return vchiq_status_to_vchi(status);
  30751. +}
  30752. +EXPORT_SYMBOL(vchi_msg_queue);
  30753. +
  30754. +/***********************************************************
  30755. + * Name: vchi_bulk_queue_receive
  30756. + *
  30757. + * Arguments: VCHI_BULK_HANDLE_T handle,
  30758. + * void *data_dst,
  30759. + * const uint32_t data_size,
  30760. + * VCHI_FLAGS_T flags
  30761. + * void *bulk_handle
  30762. + *
  30763. + * Description: Routine to setup a rcv buffer
  30764. + *
  30765. + * Returns: int32_t - success == 0
  30766. + *
  30767. + ***********************************************************/
  30768. +int32_t vchi_bulk_queue_receive(VCHI_SERVICE_HANDLE_T handle,
  30769. + void *data_dst,
  30770. + uint32_t data_size,
  30771. + VCHI_FLAGS_T flags,
  30772. + void *bulk_handle)
  30773. +{
  30774. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30775. + VCHIQ_BULK_MODE_T mode;
  30776. + VCHIQ_STATUS_T status;
  30777. +
  30778. + switch ((int)flags) {
  30779. + case VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE
  30780. + | VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  30781. + WARN_ON(!service->callback);
  30782. + mode = VCHIQ_BULK_MODE_CALLBACK;
  30783. + break;
  30784. + case VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE:
  30785. + mode = VCHIQ_BULK_MODE_BLOCKING;
  30786. + break;
  30787. + case VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  30788. + case VCHI_FLAGS_NONE:
  30789. + mode = VCHIQ_BULK_MODE_NOCALLBACK;
  30790. + break;
  30791. + default:
  30792. + WARN(1, "unsupported message\n");
  30793. + return vchiq_status_to_vchi(VCHIQ_ERROR);
  30794. + }
  30795. +
  30796. + status = vchiq_bulk_receive(service->handle, data_dst, data_size,
  30797. + bulk_handle, mode);
  30798. +
  30799. + /* vchiq_bulk_receive() may return VCHIQ_RETRY, so we need to
  30800. + ** implement a retry mechanism since this function is supposed
  30801. + ** to block until queued
  30802. + */
  30803. + while (status == VCHIQ_RETRY) {
  30804. + msleep(1);
  30805. + status = vchiq_bulk_receive(service->handle, data_dst,
  30806. + data_size, bulk_handle, mode);
  30807. + }
  30808. +
  30809. + return vchiq_status_to_vchi(status);
  30810. +}
  30811. +EXPORT_SYMBOL(vchi_bulk_queue_receive);
  30812. +
  30813. +/***********************************************************
  30814. + * Name: vchi_bulk_queue_transmit
  30815. + *
  30816. + * Arguments: VCHI_BULK_HANDLE_T handle,
  30817. + * const void *data_src,
  30818. + * uint32_t data_size,
  30819. + * VCHI_FLAGS_T flags,
  30820. + * void *bulk_handle
  30821. + *
  30822. + * Description: Routine to transmit some data
  30823. + *
  30824. + * Returns: int32_t - success == 0
  30825. + *
  30826. + ***********************************************************/
  30827. +int32_t vchi_bulk_queue_transmit(VCHI_SERVICE_HANDLE_T handle,
  30828. + const void *data_src,
  30829. + uint32_t data_size,
  30830. + VCHI_FLAGS_T flags,
  30831. + void *bulk_handle)
  30832. +{
  30833. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30834. + VCHIQ_BULK_MODE_T mode;
  30835. + VCHIQ_STATUS_T status;
  30836. +
  30837. + switch ((int)flags) {
  30838. + case VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE
  30839. + | VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  30840. + WARN_ON(!service->callback);
  30841. + mode = VCHIQ_BULK_MODE_CALLBACK;
  30842. + break;
  30843. + case VCHI_FLAGS_BLOCK_UNTIL_DATA_READ:
  30844. + case VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE:
  30845. + mode = VCHIQ_BULK_MODE_BLOCKING;
  30846. + break;
  30847. + case VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  30848. + case VCHI_FLAGS_NONE:
  30849. + mode = VCHIQ_BULK_MODE_NOCALLBACK;
  30850. + break;
  30851. + default:
  30852. + WARN(1, "unsupported message\n");
  30853. + return vchiq_status_to_vchi(VCHIQ_ERROR);
  30854. + }
  30855. +
  30856. + status = vchiq_bulk_transmit(service->handle, data_src, data_size,
  30857. + bulk_handle, mode);
  30858. +
  30859. + /* vchiq_bulk_transmit() may return VCHIQ_RETRY, so we need to
  30860. + ** implement a retry mechanism since this function is supposed
  30861. + ** to block until queued
  30862. + */
  30863. + while (status == VCHIQ_RETRY) {
  30864. + msleep(1);
  30865. + status = vchiq_bulk_transmit(service->handle, data_src,
  30866. + data_size, bulk_handle, mode);
  30867. + }
  30868. +
  30869. + return vchiq_status_to_vchi(status);
  30870. +}
  30871. +EXPORT_SYMBOL(vchi_bulk_queue_transmit);
  30872. +
  30873. +/***********************************************************
  30874. + * Name: vchi_msg_dequeue
  30875. + *
  30876. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  30877. + * void *data,
  30878. + * uint32_t max_data_size_to_read,
  30879. + * uint32_t *actual_msg_size
  30880. + * VCHI_FLAGS_T flags
  30881. + *
  30882. + * Description: Routine to dequeue a message into the supplied buffer
  30883. + *
  30884. + * Returns: int32_t - success == 0
  30885. + *
  30886. + ***********************************************************/
  30887. +int32_t vchi_msg_dequeue(VCHI_SERVICE_HANDLE_T handle,
  30888. + void *data,
  30889. + uint32_t max_data_size_to_read,
  30890. + uint32_t *actual_msg_size,
  30891. + VCHI_FLAGS_T flags)
  30892. +{
  30893. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30894. + VCHIQ_HEADER_T *header;
  30895. +
  30896. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  30897. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  30898. +
  30899. + if (flags == VCHI_FLAGS_NONE)
  30900. + if (vchiu_queue_is_empty(&service->queue))
  30901. + return -1;
  30902. +
  30903. + header = vchiu_queue_pop(&service->queue);
  30904. +
  30905. + memcpy(data, header->data, header->size < max_data_size_to_read ?
  30906. + header->size : max_data_size_to_read);
  30907. +
  30908. + *actual_msg_size = header->size;
  30909. +
  30910. + vchiq_release_message(service->handle, header);
  30911. +
  30912. + return 0;
  30913. +}
  30914. +EXPORT_SYMBOL(vchi_msg_dequeue);
  30915. +
  30916. +/***********************************************************
  30917. + * Name: vchi_msg_queuev
  30918. + *
  30919. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  30920. + * VCHI_MSG_VECTOR_T *vector,
  30921. + * uint32_t count,
  30922. + * VCHI_FLAGS_T flags,
  30923. + * void *msg_handle
  30924. + *
  30925. + * Description: Thin wrapper to queue a message onto a connection
  30926. + *
  30927. + * Returns: int32_t - success == 0
  30928. + *
  30929. + ***********************************************************/
  30930. +
  30931. +vchiq_static_assert(sizeof(VCHI_MSG_VECTOR_T) == sizeof(VCHIQ_ELEMENT_T));
  30932. +vchiq_static_assert(offsetof(VCHI_MSG_VECTOR_T, vec_base) ==
  30933. + offsetof(VCHIQ_ELEMENT_T, data));
  30934. +vchiq_static_assert(offsetof(VCHI_MSG_VECTOR_T, vec_len) ==
  30935. + offsetof(VCHIQ_ELEMENT_T, size));
  30936. +
  30937. +int32_t vchi_msg_queuev(VCHI_SERVICE_HANDLE_T handle,
  30938. + VCHI_MSG_VECTOR_T *vector,
  30939. + uint32_t count,
  30940. + VCHI_FLAGS_T flags,
  30941. + void *msg_handle)
  30942. +{
  30943. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30944. +
  30945. + (void)msg_handle;
  30946. +
  30947. + WARN_ON(flags != VCHI_FLAGS_BLOCK_UNTIL_QUEUED);
  30948. +
  30949. + return vchiq_status_to_vchi(vchiq_queue_message(service->handle,
  30950. + (const VCHIQ_ELEMENT_T *)vector, count));
  30951. +}
  30952. +EXPORT_SYMBOL(vchi_msg_queuev);
  30953. +
  30954. +/***********************************************************
  30955. + * Name: vchi_held_msg_release
  30956. + *
  30957. + * Arguments: VCHI_HELD_MSG_T *message
  30958. + *
  30959. + * Description: Routine to release a held message (after it has been read with
  30960. + * vchi_msg_hold)
  30961. + *
  30962. + * Returns: int32_t - success == 0
  30963. + *
  30964. + ***********************************************************/
  30965. +int32_t vchi_held_msg_release(VCHI_HELD_MSG_T *message)
  30966. +{
  30967. + vchiq_release_message((VCHIQ_SERVICE_HANDLE_T)message->service,
  30968. + (VCHIQ_HEADER_T *)message->message);
  30969. +
  30970. + return 0;
  30971. +}
  30972. +EXPORT_SYMBOL(vchi_held_msg_release);
  30973. +
  30974. +/***********************************************************
  30975. + * Name: vchi_msg_hold
  30976. + *
  30977. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  30978. + * void **data,
  30979. + * uint32_t *msg_size,
  30980. + * VCHI_FLAGS_T flags,
  30981. + * VCHI_HELD_MSG_T *message_handle
  30982. + *
  30983. + * Description: Routine to return a pointer to the current message (to allow
  30984. + * in place processing). The message is dequeued - don't forget
  30985. + * to release the message using vchi_held_msg_release when you're
  30986. + * finished.
  30987. + *
  30988. + * Returns: int32_t - success == 0
  30989. + *
  30990. + ***********************************************************/
  30991. +int32_t vchi_msg_hold(VCHI_SERVICE_HANDLE_T handle,
  30992. + void **data,
  30993. + uint32_t *msg_size,
  30994. + VCHI_FLAGS_T flags,
  30995. + VCHI_HELD_MSG_T *message_handle)
  30996. +{
  30997. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30998. + VCHIQ_HEADER_T *header;
  30999. +
  31000. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  31001. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  31002. +
  31003. + if (flags == VCHI_FLAGS_NONE)
  31004. + if (vchiu_queue_is_empty(&service->queue))
  31005. + return -1;
  31006. +
  31007. + header = vchiu_queue_pop(&service->queue);
  31008. +
  31009. + *data = header->data;
  31010. + *msg_size = header->size;
  31011. +
  31012. + message_handle->service =
  31013. + (struct opaque_vchi_service_t *)service->handle;
  31014. + message_handle->message = header;
  31015. +
  31016. + return 0;
  31017. +}
  31018. +EXPORT_SYMBOL(vchi_msg_hold);
  31019. +
  31020. +/***********************************************************
  31021. + * Name: vchi_initialise
  31022. + *
  31023. + * Arguments: VCHI_INSTANCE_T *instance_handle
  31024. + * VCHI_CONNECTION_T **connections
  31025. + * const uint32_t num_connections
  31026. + *
  31027. + * Description: Initialises the hardware but does not transmit anything
  31028. + * When run as a Host App this will be called twice hence the need
  31029. + * to malloc the state information
  31030. + *
  31031. + * Returns: 0 if successful, failure otherwise
  31032. + *
  31033. + ***********************************************************/
  31034. +
  31035. +int32_t vchi_initialise(VCHI_INSTANCE_T *instance_handle)
  31036. +{
  31037. + VCHIQ_INSTANCE_T instance;
  31038. + VCHIQ_STATUS_T status;
  31039. +
  31040. + status = vchiq_initialise(&instance);
  31041. +
  31042. + *instance_handle = (VCHI_INSTANCE_T)instance;
  31043. +
  31044. + return vchiq_status_to_vchi(status);
  31045. +}
  31046. +EXPORT_SYMBOL(vchi_initialise);
  31047. +
  31048. +/***********************************************************
  31049. + * Name: vchi_connect
  31050. + *
  31051. + * Arguments: VCHI_CONNECTION_T **connections
  31052. + * const uint32_t num_connections
  31053. + * VCHI_INSTANCE_T instance_handle)
  31054. + *
  31055. + * Description: Starts the command service on each connection,
  31056. + * causing INIT messages to be pinged back and forth
  31057. + *
  31058. + * Returns: 0 if successful, failure otherwise
  31059. + *
  31060. + ***********************************************************/
  31061. +int32_t vchi_connect(VCHI_CONNECTION_T **connections,
  31062. + const uint32_t num_connections,
  31063. + VCHI_INSTANCE_T instance_handle)
  31064. +{
  31065. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  31066. +
  31067. + (void)connections;
  31068. + (void)num_connections;
  31069. +
  31070. + return vchiq_connect(instance);
  31071. +}
  31072. +EXPORT_SYMBOL(vchi_connect);
  31073. +
  31074. +
  31075. +/***********************************************************
  31076. + * Name: vchi_disconnect
  31077. + *
  31078. + * Arguments: VCHI_INSTANCE_T instance_handle
  31079. + *
  31080. + * Description: Stops the command service on each connection,
  31081. + * causing DE-INIT messages to be pinged back and forth
  31082. + *
  31083. + * Returns: 0 if successful, failure otherwise
  31084. + *
  31085. + ***********************************************************/
  31086. +int32_t vchi_disconnect(VCHI_INSTANCE_T instance_handle)
  31087. +{
  31088. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  31089. + return vchiq_status_to_vchi(vchiq_shutdown(instance));
  31090. +}
  31091. +EXPORT_SYMBOL(vchi_disconnect);
  31092. +
  31093. +
  31094. +/***********************************************************
  31095. + * Name: vchi_service_open
  31096. + * Name: vchi_service_create
  31097. + *
  31098. + * Arguments: VCHI_INSTANCE_T *instance_handle
  31099. + * SERVICE_CREATION_T *setup,
  31100. + * VCHI_SERVICE_HANDLE_T *handle
  31101. + *
  31102. + * Description: Routine to open a service
  31103. + *
  31104. + * Returns: int32_t - success == 0
  31105. + *
  31106. + ***********************************************************/
  31107. +
  31108. +static VCHIQ_STATUS_T shim_callback(VCHIQ_REASON_T reason,
  31109. + VCHIQ_HEADER_T *header, VCHIQ_SERVICE_HANDLE_T handle, void *bulk_user)
  31110. +{
  31111. + SHIM_SERVICE_T *service =
  31112. + (SHIM_SERVICE_T *)VCHIQ_GET_SERVICE_USERDATA(handle);
  31113. +
  31114. + if (!service->callback)
  31115. + goto release;
  31116. +
  31117. + switch (reason) {
  31118. + case VCHIQ_MESSAGE_AVAILABLE:
  31119. + vchiu_queue_push(&service->queue, header);
  31120. +
  31121. + service->callback(service->callback_param,
  31122. + VCHI_CALLBACK_MSG_AVAILABLE, NULL);
  31123. +
  31124. + goto done;
  31125. + break;
  31126. +
  31127. + case VCHIQ_BULK_TRANSMIT_DONE:
  31128. + service->callback(service->callback_param,
  31129. + VCHI_CALLBACK_BULK_SENT, bulk_user);
  31130. + break;
  31131. +
  31132. + case VCHIQ_BULK_RECEIVE_DONE:
  31133. + service->callback(service->callback_param,
  31134. + VCHI_CALLBACK_BULK_RECEIVED, bulk_user);
  31135. + break;
  31136. +
  31137. + case VCHIQ_SERVICE_CLOSED:
  31138. + service->callback(service->callback_param,
  31139. + VCHI_CALLBACK_SERVICE_CLOSED, NULL);
  31140. + break;
  31141. +
  31142. + case VCHIQ_SERVICE_OPENED:
  31143. + /* No equivalent VCHI reason */
  31144. + break;
  31145. +
  31146. + case VCHIQ_BULK_TRANSMIT_ABORTED:
  31147. + service->callback(service->callback_param,
  31148. + VCHI_CALLBACK_BULK_TRANSMIT_ABORTED,
  31149. + bulk_user);
  31150. + break;
  31151. +
  31152. + case VCHIQ_BULK_RECEIVE_ABORTED:
  31153. + service->callback(service->callback_param,
  31154. + VCHI_CALLBACK_BULK_RECEIVE_ABORTED,
  31155. + bulk_user);
  31156. + break;
  31157. +
  31158. + default:
  31159. + WARN(1, "not supported\n");
  31160. + break;
  31161. + }
  31162. +
  31163. +release:
  31164. + vchiq_release_message(service->handle, header);
  31165. +done:
  31166. + return VCHIQ_SUCCESS;
  31167. +}
  31168. +
  31169. +static SHIM_SERVICE_T *service_alloc(VCHIQ_INSTANCE_T instance,
  31170. + SERVICE_CREATION_T *setup)
  31171. +{
  31172. + SHIM_SERVICE_T *service = kzalloc(sizeof(SHIM_SERVICE_T), GFP_KERNEL);
  31173. +
  31174. + (void)instance;
  31175. +
  31176. + if (service) {
  31177. + if (vchiu_queue_init(&service->queue, 64)) {
  31178. + service->callback = setup->callback;
  31179. + service->callback_param = setup->callback_param;
  31180. + } else {
  31181. + kfree(service);
  31182. + service = NULL;
  31183. + }
  31184. + }
  31185. +
  31186. + return service;
  31187. +}
  31188. +
  31189. +static void service_free(SHIM_SERVICE_T *service)
  31190. +{
  31191. + if (service) {
  31192. + vchiu_queue_delete(&service->queue);
  31193. + kfree(service);
  31194. + }
  31195. +}
  31196. +
  31197. +int32_t vchi_service_open(VCHI_INSTANCE_T instance_handle,
  31198. + SERVICE_CREATION_T *setup,
  31199. + VCHI_SERVICE_HANDLE_T *handle)
  31200. +{
  31201. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  31202. + SHIM_SERVICE_T *service = service_alloc(instance, setup);
  31203. + if (service) {
  31204. + VCHIQ_SERVICE_PARAMS_T params;
  31205. + VCHIQ_STATUS_T status;
  31206. +
  31207. + memset(&params, 0, sizeof(params));
  31208. + params.fourcc = setup->service_id;
  31209. + params.callback = shim_callback;
  31210. + params.userdata = service;
  31211. + params.version = setup->version.version;
  31212. + params.version_min = setup->version.version_min;
  31213. +
  31214. + status = vchiq_open_service(instance, &params,
  31215. + &service->handle);
  31216. + if (status != VCHIQ_SUCCESS) {
  31217. + service_free(service);
  31218. + service = NULL;
  31219. + }
  31220. + }
  31221. +
  31222. + *handle = (VCHI_SERVICE_HANDLE_T)service;
  31223. +
  31224. + return (service != NULL) ? 0 : -1;
  31225. +}
  31226. +EXPORT_SYMBOL(vchi_service_open);
  31227. +
  31228. +int32_t vchi_service_create(VCHI_INSTANCE_T instance_handle,
  31229. + SERVICE_CREATION_T *setup,
  31230. + VCHI_SERVICE_HANDLE_T *handle)
  31231. +{
  31232. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  31233. + SHIM_SERVICE_T *service = service_alloc(instance, setup);
  31234. + if (service) {
  31235. + VCHIQ_SERVICE_PARAMS_T params;
  31236. + VCHIQ_STATUS_T status;
  31237. +
  31238. + memset(&params, 0, sizeof(params));
  31239. + params.fourcc = setup->service_id;
  31240. + params.callback = shim_callback;
  31241. + params.userdata = service;
  31242. + params.version = setup->version.version;
  31243. + params.version_min = setup->version.version_min;
  31244. + status = vchiq_add_service(instance, &params, &service->handle);
  31245. +
  31246. + if (status != VCHIQ_SUCCESS) {
  31247. + service_free(service);
  31248. + service = NULL;
  31249. + }
  31250. + }
  31251. +
  31252. + *handle = (VCHI_SERVICE_HANDLE_T)service;
  31253. +
  31254. + return (service != NULL) ? 0 : -1;
  31255. +}
  31256. +EXPORT_SYMBOL(vchi_service_create);
  31257. +
  31258. +int32_t vchi_service_close(const VCHI_SERVICE_HANDLE_T handle)
  31259. +{
  31260. + int32_t ret = -1;
  31261. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  31262. + if (service) {
  31263. + VCHIQ_STATUS_T status = vchiq_close_service(service->handle);
  31264. + if (status == VCHIQ_SUCCESS) {
  31265. + service_free(service);
  31266. + service = NULL;
  31267. + }
  31268. +
  31269. + ret = vchiq_status_to_vchi(status);
  31270. + }
  31271. + return ret;
  31272. +}
  31273. +EXPORT_SYMBOL(vchi_service_close);
  31274. +
  31275. +int32_t vchi_service_destroy(const VCHI_SERVICE_HANDLE_T handle)
  31276. +{
  31277. + int32_t ret = -1;
  31278. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  31279. + if (service) {
  31280. + VCHIQ_STATUS_T status = vchiq_remove_service(service->handle);
  31281. + if (status == VCHIQ_SUCCESS) {
  31282. + service_free(service);
  31283. + service = NULL;
  31284. + }
  31285. +
  31286. + ret = vchiq_status_to_vchi(status);
  31287. + }
  31288. + return ret;
  31289. +}
  31290. +EXPORT_SYMBOL(vchi_service_destroy);
  31291. +
  31292. +int32_t vchi_get_peer_version( const VCHI_SERVICE_HANDLE_T handle, short *peer_version )
  31293. +{
  31294. + int32_t ret = -1;
  31295. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  31296. + if(service)
  31297. + {
  31298. + VCHIQ_STATUS_T status = vchiq_get_peer_version(service->handle, peer_version);
  31299. + ret = vchiq_status_to_vchi( status );
  31300. + }
  31301. + return ret;
  31302. +}
  31303. +EXPORT_SYMBOL(vchi_get_peer_version);
  31304. +
  31305. +/* ----------------------------------------------------------------------
  31306. + * read a uint32_t from buffer.
  31307. + * network format is defined to be little endian
  31308. + * -------------------------------------------------------------------- */
  31309. +uint32_t
  31310. +vchi_readbuf_uint32(const void *_ptr)
  31311. +{
  31312. + const unsigned char *ptr = _ptr;
  31313. + return ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | (ptr[3] << 24);
  31314. +}
  31315. +
  31316. +/* ----------------------------------------------------------------------
  31317. + * write a uint32_t to buffer.
  31318. + * network format is defined to be little endian
  31319. + * -------------------------------------------------------------------- */
  31320. +void
  31321. +vchi_writebuf_uint32(void *_ptr, uint32_t value)
  31322. +{
  31323. + unsigned char *ptr = _ptr;
  31324. + ptr[0] = (unsigned char)((value >> 0) & 0xFF);
  31325. + ptr[1] = (unsigned char)((value >> 8) & 0xFF);
  31326. + ptr[2] = (unsigned char)((value >> 16) & 0xFF);
  31327. + ptr[3] = (unsigned char)((value >> 24) & 0xFF);
  31328. +}
  31329. +
  31330. +/* ----------------------------------------------------------------------
  31331. + * read a uint16_t from buffer.
  31332. + * network format is defined to be little endian
  31333. + * -------------------------------------------------------------------- */
  31334. +uint16_t
  31335. +vchi_readbuf_uint16(const void *_ptr)
  31336. +{
  31337. + const unsigned char *ptr = _ptr;
  31338. + return ptr[0] | (ptr[1] << 8);
  31339. +}
  31340. +
  31341. +/* ----------------------------------------------------------------------
  31342. + * write a uint16_t into the buffer.
  31343. + * network format is defined to be little endian
  31344. + * -------------------------------------------------------------------- */
  31345. +void
  31346. +vchi_writebuf_uint16(void *_ptr, uint16_t value)
  31347. +{
  31348. + unsigned char *ptr = _ptr;
  31349. + ptr[0] = (value >> 0) & 0xFF;
  31350. + ptr[1] = (value >> 8) & 0xFF;
  31351. +}
  31352. +
  31353. +/***********************************************************
  31354. + * Name: vchi_service_use
  31355. + *
  31356. + * Arguments: const VCHI_SERVICE_HANDLE_T handle
  31357. + *
  31358. + * Description: Routine to increment refcount on a service
  31359. + *
  31360. + * Returns: void
  31361. + *
  31362. + ***********************************************************/
  31363. +int32_t vchi_service_use(const VCHI_SERVICE_HANDLE_T handle)
  31364. +{
  31365. + int32_t ret = -1;
  31366. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  31367. + if (service)
  31368. + ret = vchiq_status_to_vchi(vchiq_use_service(service->handle));
  31369. + return ret;
  31370. +}
  31371. +EXPORT_SYMBOL(vchi_service_use);
  31372. +
  31373. +/***********************************************************
  31374. + * Name: vchi_service_release
  31375. + *
  31376. + * Arguments: const VCHI_SERVICE_HANDLE_T handle
  31377. + *
  31378. + * Description: Routine to decrement refcount on a service
  31379. + *
  31380. + * Returns: void
  31381. + *
  31382. + ***********************************************************/
  31383. +int32_t vchi_service_release(const VCHI_SERVICE_HANDLE_T handle)
  31384. +{
  31385. + int32_t ret = -1;
  31386. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  31387. + if (service)
  31388. + ret = vchiq_status_to_vchi(
  31389. + vchiq_release_service(service->handle));
  31390. + return ret;
  31391. +}
  31392. +EXPORT_SYMBOL(vchi_service_release);
  31393. diff -Nur linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c
  31394. --- linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c 1970-01-01 01:00:00.000000000 +0100
  31395. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c 2014-07-07 10:45:11.000000000 +0200
  31396. @@ -0,0 +1,152 @@
  31397. +/**
  31398. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  31399. + *
  31400. + * Redistribution and use in source and binary forms, with or without
  31401. + * modification, are permitted provided that the following conditions
  31402. + * are met:
  31403. + * 1. Redistributions of source code must retain the above copyright
  31404. + * notice, this list of conditions, and the following disclaimer,
  31405. + * without modification.
  31406. + * 2. Redistributions in binary form must reproduce the above copyright
  31407. + * notice, this list of conditions and the following disclaimer in the
  31408. + * documentation and/or other materials provided with the distribution.
  31409. + * 3. The names of the above-listed copyright holders may not be used
  31410. + * to endorse or promote products derived from this software without
  31411. + * specific prior written permission.
  31412. + *
  31413. + * ALTERNATIVELY, this software may be distributed under the terms of the
  31414. + * GNU General Public License ("GPL") version 2, as published by the Free
  31415. + * Software Foundation.
  31416. + *
  31417. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  31418. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  31419. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  31420. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  31421. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  31422. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  31423. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  31424. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  31425. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  31426. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31427. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31428. + */
  31429. +
  31430. +#include "vchiq_util.h"
  31431. +#include "vchiq_killable.h"
  31432. +
  31433. +static inline int is_pow2(int i)
  31434. +{
  31435. + return i && !(i & (i - 1));
  31436. +}
  31437. +
  31438. +int vchiu_queue_init(VCHIU_QUEUE_T *queue, int size)
  31439. +{
  31440. + WARN_ON(!is_pow2(size));
  31441. +
  31442. + queue->size = size;
  31443. + queue->read = 0;
  31444. + queue->write = 0;
  31445. +
  31446. + sema_init(&queue->pop, 0);
  31447. + sema_init(&queue->push, 0);
  31448. +
  31449. + queue->storage = kzalloc(size * sizeof(VCHIQ_HEADER_T *), GFP_KERNEL);
  31450. + if (queue->storage == NULL) {
  31451. + vchiu_queue_delete(queue);
  31452. + return 0;
  31453. + }
  31454. + return 1;
  31455. +}
  31456. +
  31457. +void vchiu_queue_delete(VCHIU_QUEUE_T *queue)
  31458. +{
  31459. + if (queue->storage != NULL)
  31460. + kfree(queue->storage);
  31461. +}
  31462. +
  31463. +int vchiu_queue_is_empty(VCHIU_QUEUE_T *queue)
  31464. +{
  31465. + return queue->read == queue->write;
  31466. +}
  31467. +
  31468. +int vchiu_queue_is_full(VCHIU_QUEUE_T *queue)
  31469. +{
  31470. + return queue->write == queue->read + queue->size;
  31471. +}
  31472. +
  31473. +void vchiu_queue_push(VCHIU_QUEUE_T *queue, VCHIQ_HEADER_T *header)
  31474. +{
  31475. + while (queue->write == queue->read + queue->size) {
  31476. + if (down_interruptible(&queue->pop) != 0) {
  31477. + flush_signals(current);
  31478. + }
  31479. + }
  31480. +
  31481. + /*
  31482. + * Write to queue->storage must be visible after read from
  31483. + * queue->read
  31484. + */
  31485. + smp_mb();
  31486. +
  31487. + queue->storage[queue->write & (queue->size - 1)] = header;
  31488. +
  31489. + /*
  31490. + * Write to queue->storage must be visible before write to
  31491. + * queue->write
  31492. + */
  31493. + smp_wmb();
  31494. +
  31495. + queue->write++;
  31496. +
  31497. + up(&queue->push);
  31498. +}
  31499. +
  31500. +VCHIQ_HEADER_T *vchiu_queue_peek(VCHIU_QUEUE_T *queue)
  31501. +{
  31502. + while (queue->write == queue->read) {
  31503. + if (down_interruptible(&queue->push) != 0) {
  31504. + flush_signals(current);
  31505. + }
  31506. + }
  31507. +
  31508. + up(&queue->push); // We haven't removed anything from the queue.
  31509. +
  31510. + /*
  31511. + * Read from queue->storage must be visible after read from
  31512. + * queue->write
  31513. + */
  31514. + smp_rmb();
  31515. +
  31516. + return queue->storage[queue->read & (queue->size - 1)];
  31517. +}
  31518. +
  31519. +VCHIQ_HEADER_T *vchiu_queue_pop(VCHIU_QUEUE_T *queue)
  31520. +{
  31521. + VCHIQ_HEADER_T *header;
  31522. +
  31523. + while (queue->write == queue->read) {
  31524. + if (down_interruptible(&queue->push) != 0) {
  31525. + flush_signals(current);
  31526. + }
  31527. + }
  31528. +
  31529. + /*
  31530. + * Read from queue->storage must be visible after read from
  31531. + * queue->write
  31532. + */
  31533. + smp_rmb();
  31534. +
  31535. + header = queue->storage[queue->read & (queue->size - 1)];
  31536. +
  31537. + /*
  31538. + * Read from queue->storage must be visible before write to
  31539. + * queue->read
  31540. + */
  31541. + smp_mb();
  31542. +
  31543. + queue->read++;
  31544. +
  31545. + up(&queue->pop);
  31546. +
  31547. + return header;
  31548. +}
  31549. diff -Nur linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h
  31550. --- linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h 1970-01-01 01:00:00.000000000 +0100
  31551. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h 2014-07-07 10:45:11.000000000 +0200
  31552. @@ -0,0 +1,81 @@
  31553. +/**
  31554. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  31555. + *
  31556. + * Redistribution and use in source and binary forms, with or without
  31557. + * modification, are permitted provided that the following conditions
  31558. + * are met:
  31559. + * 1. Redistributions of source code must retain the above copyright
  31560. + * notice, this list of conditions, and the following disclaimer,
  31561. + * without modification.
  31562. + * 2. Redistributions in binary form must reproduce the above copyright
  31563. + * notice, this list of conditions and the following disclaimer in the
  31564. + * documentation and/or other materials provided with the distribution.
  31565. + * 3. The names of the above-listed copyright holders may not be used
  31566. + * to endorse or promote products derived from this software without
  31567. + * specific prior written permission.
  31568. + *
  31569. + * ALTERNATIVELY, this software may be distributed under the terms of the
  31570. + * GNU General Public License ("GPL") version 2, as published by the Free
  31571. + * Software Foundation.
  31572. + *
  31573. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  31574. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  31575. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  31576. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  31577. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  31578. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  31579. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  31580. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  31581. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  31582. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31583. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31584. + */
  31585. +
  31586. +#ifndef VCHIQ_UTIL_H
  31587. +#define VCHIQ_UTIL_H
  31588. +
  31589. +#include <linux/types.h>
  31590. +#include <linux/semaphore.h>
  31591. +#include <linux/mutex.h>
  31592. +#include <linux/bitops.h>
  31593. +#include <linux/kthread.h>
  31594. +#include <linux/wait.h>
  31595. +#include <linux/vmalloc.h>
  31596. +#include <linux/jiffies.h>
  31597. +#include <linux/delay.h>
  31598. +#include <linux/string.h>
  31599. +#include <linux/types.h>
  31600. +#include <linux/interrupt.h>
  31601. +#include <linux/random.h>
  31602. +#include <linux/sched.h>
  31603. +#include <linux/ctype.h>
  31604. +#include <linux/uaccess.h>
  31605. +#include <linux/time.h> /* for time_t */
  31606. +#include <linux/slab.h>
  31607. +#include <linux/vmalloc.h>
  31608. +
  31609. +#include "vchiq_if.h"
  31610. +
  31611. +typedef struct {
  31612. + int size;
  31613. + int read;
  31614. + int write;
  31615. +
  31616. + struct semaphore pop;
  31617. + struct semaphore push;
  31618. +
  31619. + VCHIQ_HEADER_T **storage;
  31620. +} VCHIU_QUEUE_T;
  31621. +
  31622. +extern int vchiu_queue_init(VCHIU_QUEUE_T *queue, int size);
  31623. +extern void vchiu_queue_delete(VCHIU_QUEUE_T *queue);
  31624. +
  31625. +extern int vchiu_queue_is_empty(VCHIU_QUEUE_T *queue);
  31626. +extern int vchiu_queue_is_full(VCHIU_QUEUE_T *queue);
  31627. +
  31628. +extern void vchiu_queue_push(VCHIU_QUEUE_T *queue, VCHIQ_HEADER_T *header);
  31629. +
  31630. +extern VCHIQ_HEADER_T *vchiu_queue_peek(VCHIU_QUEUE_T *queue);
  31631. +extern VCHIQ_HEADER_T *vchiu_queue_pop(VCHIU_QUEUE_T *queue);
  31632. +
  31633. +#endif
  31634. diff -Nur linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c
  31635. --- linux-3.15.4/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c 1970-01-01 01:00:00.000000000 +0100
  31636. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c 2014-04-13 17:32:57.000000000 +0200
  31637. @@ -0,0 +1,59 @@
  31638. +/**
  31639. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  31640. + *
  31641. + * Redistribution and use in source and binary forms, with or without
  31642. + * modification, are permitted provided that the following conditions
  31643. + * are met:
  31644. + * 1. Redistributions of source code must retain the above copyright
  31645. + * notice, this list of conditions, and the following disclaimer,
  31646. + * without modification.
  31647. + * 2. Redistributions in binary form must reproduce the above copyright
  31648. + * notice, this list of conditions and the following disclaimer in the
  31649. + * documentation and/or other materials provided with the distribution.
  31650. + * 3. The names of the above-listed copyright holders may not be used
  31651. + * to endorse or promote products derived from this software without
  31652. + * specific prior written permission.
  31653. + *
  31654. + * ALTERNATIVELY, this software may be distributed under the terms of the
  31655. + * GNU General Public License ("GPL") version 2, as published by the Free
  31656. + * Software Foundation.
  31657. + *
  31658. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  31659. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  31660. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  31661. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  31662. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  31663. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  31664. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  31665. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  31666. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  31667. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31668. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31669. + */
  31670. +#include "vchiq_build_info.h"
  31671. +#include <linux/broadcom/vc_debug_sym.h>
  31672. +
  31673. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_hostname, "dc4-arm-01" );
  31674. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_version, "9245b4c35b99b3870e1f7dc598c5692b3c66a6f0 (tainted)" );
  31675. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_time, __TIME__ );
  31676. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_date, __DATE__ );
  31677. +
  31678. +const char *vchiq_get_build_hostname( void )
  31679. +{
  31680. + return vchiq_build_hostname;
  31681. +}
  31682. +
  31683. +const char *vchiq_get_build_version( void )
  31684. +{
  31685. + return vchiq_build_version;
  31686. +}
  31687. +
  31688. +const char *vchiq_get_build_date( void )
  31689. +{
  31690. + return vchiq_build_date;
  31691. +}
  31692. +
  31693. +const char *vchiq_get_build_time( void )
  31694. +{
  31695. + return vchiq_build_time;
  31696. +}
  31697. diff -Nur linux-3.15.4/drivers/misc/vc04_services/Kconfig linux-rpi/drivers/misc/vc04_services/Kconfig
  31698. --- linux-3.15.4/drivers/misc/vc04_services/Kconfig 1970-01-01 01:00:00.000000000 +0100
  31699. +++ linux-rpi/drivers/misc/vc04_services/Kconfig 2014-07-07 10:45:11.000000000 +0200
  31700. @@ -0,0 +1,9 @@
  31701. +config BCM2708_VCHIQ
  31702. + tristate "Videocore VCHIQ"
  31703. + depends on MACH_BCM2708
  31704. + default y
  31705. + help
  31706. + Kernel to VideoCore communication interface for the
  31707. + BCM2708 family of products.
  31708. + Defaults to Y when the Broadcom Videocore services
  31709. + are included in the build, N otherwise.
  31710. diff -Nur linux-3.15.4/drivers/misc/vc04_services/Makefile linux-rpi/drivers/misc/vc04_services/Makefile
  31711. --- linux-3.15.4/drivers/misc/vc04_services/Makefile 1970-01-01 01:00:00.000000000 +0100
  31712. +++ linux-rpi/drivers/misc/vc04_services/Makefile 2014-07-07 10:45:11.000000000 +0200
  31713. @@ -0,0 +1,17 @@
  31714. +ifeq ($(CONFIG_MACH_BCM2708),y)
  31715. +
  31716. +obj-$(CONFIG_BCM2708_VCHIQ) += vchiq.o
  31717. +
  31718. +vchiq-objs := \
  31719. + interface/vchiq_arm/vchiq_core.o \
  31720. + interface/vchiq_arm/vchiq_arm.o \
  31721. + interface/vchiq_arm/vchiq_kern_lib.o \
  31722. + interface/vchiq_arm/vchiq_2835_arm.o \
  31723. + interface/vchiq_arm/vchiq_proc.o \
  31724. + interface/vchiq_arm/vchiq_shim.o \
  31725. + interface/vchiq_arm/vchiq_util.o \
  31726. + interface/vchiq_arm/vchiq_connected.o \
  31727. +
  31728. +ccflags-y += -DVCOS_VERIFY_BKPTS=1 -Idrivers/misc/vc04_services -DUSE_VCHIQ_ARM -D__VCCOREVER__=0x04000000
  31729. +
  31730. +endif
  31731. diff -Nur linux-3.15.4/drivers/mmc/card/block.c linux-rpi/drivers/mmc/card/block.c
  31732. --- linux-3.15.4/drivers/mmc/card/block.c 2014-07-07 03:59:25.000000000 +0200
  31733. +++ linux-rpi/drivers/mmc/card/block.c 2014-07-07 10:45:11.000000000 +0200
  31734. @@ -1404,7 +1404,7 @@
  31735. brq->data.blocks = 1;
  31736. }
  31737. - if (brq->data.blocks > 1 || do_rel_wr) {
  31738. + if (brq->data.blocks > 1 || do_rel_wr || card->host->caps2 & MMC_CAP2_FORCE_MULTIBLOCK) {
  31739. /* SPI multiblock writes terminate using a special
  31740. * token, not a STOP_TRANSMISSION request.
  31741. */
  31742. diff -Nur linux-3.15.4/drivers/mmc/core/sd.c linux-rpi/drivers/mmc/core/sd.c
  31743. --- linux-3.15.4/drivers/mmc/core/sd.c 2014-07-07 03:59:25.000000000 +0200
  31744. +++ linux-rpi/drivers/mmc/core/sd.c 2014-07-07 10:45:11.000000000 +0200
  31745. @@ -15,6 +15,8 @@
  31746. #include <linux/slab.h>
  31747. #include <linux/stat.h>
  31748. #include <linux/pm_runtime.h>
  31749. +#include <linux/jiffies.h>
  31750. +#include <linux/nmi.h>
  31751. #include <linux/mmc/host.h>
  31752. #include <linux/mmc/card.h>
  31753. @@ -67,6 +69,15 @@
  31754. __res & __mask; \
  31755. })
  31756. +// timeout for tries
  31757. +static const unsigned long retry_timeout_ms= 10*1000;
  31758. +
  31759. +// try at least 10 times, even if timeout is reached
  31760. +static const int retry_min_tries= 10;
  31761. +
  31762. +// delay between tries
  31763. +static const unsigned long retry_delay_ms= 10;
  31764. +
  31765. /*
  31766. * Given the decoded CSD structure, decode the raw CID to our CID structure.
  31767. */
  31768. @@ -219,12 +230,63 @@
  31769. }
  31770. /*
  31771. - * Fetch and process SD Status register.
  31772. + * Fetch and process SD Configuration Register.
  31773. + */
  31774. +static int mmc_read_scr(struct mmc_card *card)
  31775. +{
  31776. + unsigned long timeout_at;
  31777. + int err, tries;
  31778. +
  31779. + timeout_at= jiffies + msecs_to_jiffies( retry_timeout_ms );
  31780. + tries= 0;
  31781. +
  31782. + while( tries < retry_min_tries || time_before( jiffies, timeout_at ) )
  31783. + {
  31784. + unsigned long delay_at;
  31785. + tries++;
  31786. +
  31787. + err = mmc_app_send_scr(card, card->raw_scr);
  31788. + if( !err )
  31789. + break; // success!!!
  31790. +
  31791. + touch_nmi_watchdog(); // we are still alive!
  31792. +
  31793. + // delay
  31794. + delay_at= jiffies + msecs_to_jiffies( retry_delay_ms );
  31795. + while( time_before( jiffies, delay_at ) )
  31796. + {
  31797. + mdelay( 1 );
  31798. + touch_nmi_watchdog(); // we are still alive!
  31799. + }
  31800. + }
  31801. +
  31802. + if( err)
  31803. + {
  31804. + 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 );
  31805. + return err;
  31806. + }
  31807. +
  31808. + if( tries > 1 )
  31809. + {
  31810. + pr_info("%s: could read SD Configuration register (SCR) at the %dth attempt\n", mmc_hostname(card->host), tries );
  31811. + }
  31812. +
  31813. + err = mmc_decode_scr(card);
  31814. + if (err)
  31815. + return err;
  31816. +
  31817. + return err;
  31818. +}
  31819. +
  31820. +/*
  31821. + * Fetch and process SD Status Register.
  31822. */
  31823. static int mmc_read_ssr(struct mmc_card *card)
  31824. {
  31825. + unsigned long timeout_at;
  31826. unsigned int au, es, et, eo;
  31827. int err, i;
  31828. + int tries;
  31829. u32 *ssr;
  31830. if (!(card->csd.cmdclass & CCC_APP_SPEC)) {
  31831. @@ -237,14 +299,40 @@
  31832. if (!ssr)
  31833. return -ENOMEM;
  31834. - err = mmc_app_sd_status(card, ssr);
  31835. - if (err) {
  31836. - pr_warning("%s: problem reading SD Status "
  31837. - "register.\n", mmc_hostname(card->host));
  31838. - err = 0;
  31839. + timeout_at= jiffies + msecs_to_jiffies( retry_timeout_ms );
  31840. + tries= 0;
  31841. +
  31842. + while( tries < retry_min_tries || time_before( jiffies, timeout_at ) )
  31843. + {
  31844. + unsigned long delay_at;
  31845. + tries++;
  31846. +
  31847. + err= mmc_app_sd_status(card, ssr);
  31848. + if( !err )
  31849. + break; // sucess!!!
  31850. +
  31851. + touch_nmi_watchdog(); // we are still alive!
  31852. +
  31853. + // delay
  31854. + delay_at= jiffies + msecs_to_jiffies( retry_delay_ms );
  31855. + while( time_before( jiffies, delay_at ) )
  31856. + {
  31857. + mdelay( 1 );
  31858. + touch_nmi_watchdog(); // we are still alive!
  31859. + }
  31860. + }
  31861. +
  31862. + if( err)
  31863. + {
  31864. + 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 );
  31865. goto out;
  31866. }
  31867. + if( tries > 1 )
  31868. + {
  31869. + pr_info("%s: read SD Status register (SSR) after %d attempts\n", mmc_hostname(card->host), tries );
  31870. + }
  31871. +
  31872. for (i = 0; i < 16; i++)
  31873. ssr[i] = be32_to_cpu(ssr[i]);
  31874. @@ -826,14 +914,10 @@
  31875. if (!reinit) {
  31876. /*
  31877. - * Fetch SCR from card.
  31878. + * Fetch and decode SD Configuration register.
  31879. */
  31880. - err = mmc_app_send_scr(card, card->raw_scr);
  31881. - if (err)
  31882. - return err;
  31883. -
  31884. - err = mmc_decode_scr(card);
  31885. - if (err)
  31886. + err = mmc_read_scr(card);
  31887. + if( err )
  31888. return err;
  31889. /*
  31890. diff -Nur linux-3.15.4/drivers/mmc/host/Kconfig linux-rpi/drivers/mmc/host/Kconfig
  31891. --- linux-3.15.4/drivers/mmc/host/Kconfig 2014-07-07 03:59:25.000000000 +0200
  31892. +++ linux-rpi/drivers/mmc/host/Kconfig 2014-07-07 10:45:11.000000000 +0200
  31893. @@ -272,6 +272,27 @@
  31894. If you have a controller with this interface, say Y or M here.
  31895. +config MMC_SDHCI_BCM2708
  31896. + tristate "SDHCI support on BCM2708"
  31897. + depends on MMC_SDHCI && MACH_BCM2708
  31898. + select MMC_SDHCI_IO_ACCESSORS
  31899. + help
  31900. + This selects the Secure Digital Host Controller Interface (SDHCI)
  31901. + often referrered to as the eMMC block.
  31902. +
  31903. + If you have a controller with this interface, say Y or M here.
  31904. +
  31905. + If unsure, say N.
  31906. +
  31907. +config MMC_SDHCI_BCM2708_DMA
  31908. + bool "DMA support on BCM2708 Arasan controller"
  31909. + depends on MMC_SDHCI_BCM2708
  31910. + help
  31911. + Enable DMA support on the Arasan SDHCI controller in Broadcom 2708
  31912. + based chips.
  31913. +
  31914. + If unsure, say N.
  31915. +
  31916. config MMC_SDHCI_BCM2835
  31917. tristate "SDHCI platform support for the BCM2835 SD/MMC Controller"
  31918. depends on ARCH_BCM2835
  31919. diff -Nur linux-3.15.4/drivers/mmc/host/Makefile linux-rpi/drivers/mmc/host/Makefile
  31920. --- linux-3.15.4/drivers/mmc/host/Makefile 2014-07-07 03:59:25.000000000 +0200
  31921. +++ linux-rpi/drivers/mmc/host/Makefile 2014-07-07 10:45:11.000000000 +0200
  31922. @@ -16,6 +16,7 @@
  31923. obj-$(CONFIG_MMC_SDHCI_S3C) += sdhci-s3c.o
  31924. obj-$(CONFIG_MMC_SDHCI_SIRF) += sdhci-sirf.o
  31925. obj-$(CONFIG_MMC_SDHCI_SPEAR) += sdhci-spear.o
  31926. +obj-$(CONFIG_MMC_SDHCI_BCM2708) += sdhci-bcm2708.o
  31927. obj-$(CONFIG_MMC_WBSD) += wbsd.o
  31928. obj-$(CONFIG_MMC_AU1X) += au1xmmc.o
  31929. obj-$(CONFIG_MMC_OMAP) += omap.o
  31930. diff -Nur linux-3.15.4/drivers/mmc/host/sdhci-bcm2708.c linux-rpi/drivers/mmc/host/sdhci-bcm2708.c
  31931. --- linux-3.15.4/drivers/mmc/host/sdhci-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  31932. +++ linux-rpi/drivers/mmc/host/sdhci-bcm2708.c 2014-07-07 10:45:11.000000000 +0200
  31933. @@ -0,0 +1,1410 @@
  31934. +/*
  31935. + * sdhci-bcm2708.c Support for SDHCI device on BCM2708
  31936. + * Copyright (c) 2010 Broadcom
  31937. + *
  31938. + * This program is free software; you can redistribute it and/or modify
  31939. + * it under the terms of the GNU General Public License version 2 as
  31940. + * published by the Free Software Foundation.
  31941. + *
  31942. + * This program is distributed in the hope that it will be useful,
  31943. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  31944. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  31945. + * GNU General Public License for more details.
  31946. + *
  31947. + * You should have received a copy of the GNU General Public License
  31948. + * along with this program; if not, write to the Free Software
  31949. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  31950. + */
  31951. +
  31952. +/* Supports:
  31953. + * SDHCI platform device - Arasan SD controller in BCM2708
  31954. + *
  31955. + * Inspired by sdhci-pci.c, by Pierre Ossman
  31956. + */
  31957. +
  31958. +#include <linux/delay.h>
  31959. +#include <linux/highmem.h>
  31960. +#include <linux/platform_device.h>
  31961. +#include <linux/module.h>
  31962. +#include <linux/mmc/mmc.h>
  31963. +#include <linux/mmc/host.h>
  31964. +#include <linux/mmc/sd.h>
  31965. +
  31966. +#include <linux/io.h>
  31967. +#include <linux/dma-mapping.h>
  31968. +#include <mach/dma.h>
  31969. +
  31970. +#include "sdhci.h"
  31971. +
  31972. +/*****************************************************************************\
  31973. + * *
  31974. + * Configuration *
  31975. + * *
  31976. +\*****************************************************************************/
  31977. +
  31978. +#define DRIVER_NAME "bcm2708_sdhci"
  31979. +
  31980. +/* for the time being insist on DMA mode - PIO seems not to work */
  31981. +#ifndef CONFIG_MMC_SDHCI_BCM2708_DMA
  31982. +#warning Non-DMA (PIO) version of this driver currently unavailable
  31983. +#endif
  31984. +#undef CONFIG_MMC_SDHCI_BCM2708_DMA
  31985. +#define CONFIG_MMC_SDHCI_BCM2708_DMA y
  31986. +
  31987. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31988. +/* #define CHECK_DMA_USE */
  31989. +#endif
  31990. +//#define LOG_REGISTERS
  31991. +
  31992. +#define USE_SCHED_TIME
  31993. +#define USE_SPACED_WRITES_2CLK 1 /* space consecutive register writes */
  31994. +#define USE_SOFTWARE_TIMEOUTS 1 /* not hardware timeouts */
  31995. +#define SOFTWARE_ERASE_TIMEOUT_SEC 30
  31996. +
  31997. +#define SDHCI_BCM_DMA_CHAN 4 /* this default is normally overriden */
  31998. +#define SDHCI_BCM_DMA_WAITS 0 /* delays slowing DMA transfers: 0-31 */
  31999. +/* We are worried that SD card DMA use may be blocking the AXI bus for others */
  32000. +
  32001. +/*! TODO: obtain these from the physical address */
  32002. +#define DMA_SDHCI_BASE 0x7e300000 /* EMMC register block on Videocore */
  32003. +#define DMA_SDHCI_BUFFER (DMA_SDHCI_BASE + SDHCI_BUFFER)
  32004. +
  32005. +#define BCM2708_SDHCI_SLEEP_TIMEOUT 1000 /* msecs */
  32006. +
  32007. +/* Mhz clock that the EMMC core is running at. Should match the platform clockman settings */
  32008. +#define BCM2708_EMMC_CLOCK_FREQ 50000000
  32009. +
  32010. +#define REG_EXRDFIFO_EN 0x80
  32011. +#define REG_EXRDFIFO_CFG 0x84
  32012. +
  32013. +int cycle_delay=2;
  32014. +
  32015. +/*****************************************************************************\
  32016. + * *
  32017. + * Debug *
  32018. + * *
  32019. +\*****************************************************************************/
  32020. +
  32021. +
  32022. +
  32023. +#define DBG(f, x...) \
  32024. + pr_debug(DRIVER_NAME " [%s()]: " f, __func__,## x)
  32025. +// printk(KERN_INFO DRIVER_NAME " [%s()]: " f, __func__,## x)//GRAYG
  32026. +
  32027. +
  32028. +/*****************************************************************************\
  32029. + * *
  32030. + * High Precision Time *
  32031. + * *
  32032. +\*****************************************************************************/
  32033. +
  32034. +#ifdef USE_SCHED_TIME
  32035. +
  32036. +#include <mach/frc.h>
  32037. +
  32038. +typedef unsigned long hptime_t;
  32039. +
  32040. +#define FMT_HPT "lu"
  32041. +
  32042. +static inline hptime_t hptime(void)
  32043. +{
  32044. + return frc_clock_ticks32();
  32045. +}
  32046. +
  32047. +#define HPTIME_CLK_NS 1000ul
  32048. +
  32049. +#else
  32050. +
  32051. +typedef unsigned long hptime_t;
  32052. +
  32053. +#define FMT_HPT "lu"
  32054. +
  32055. +static inline hptime_t hptime(void)
  32056. +{
  32057. + return jiffies;
  32058. +}
  32059. +
  32060. +#define HPTIME_CLK_NS (1000000000ul/HZ)
  32061. +
  32062. +#endif
  32063. +
  32064. +static inline unsigned long int since_ns(hptime_t t)
  32065. +{
  32066. + return (unsigned long)((hptime() - t) * HPTIME_CLK_NS);
  32067. +}
  32068. +
  32069. +static bool allow_highspeed = 1;
  32070. +static int emmc_clock_freq = BCM2708_EMMC_CLOCK_FREQ;
  32071. +static bool sync_after_dma = 1;
  32072. +static bool missing_status = 1;
  32073. +static bool spurious_crc_acmd51 = 0;
  32074. +bool enable_llm = 1;
  32075. +bool extra_messages = 0;
  32076. +
  32077. +#if 0
  32078. +static void hptime_test(void)
  32079. +{
  32080. + hptime_t now;
  32081. + hptime_t later;
  32082. +
  32083. + now = hptime();
  32084. + msleep(10);
  32085. + later = hptime();
  32086. +
  32087. + printk(KERN_INFO DRIVER_NAME": 10ms = %"FMT_HPT" clks "
  32088. + "(from %"FMT_HPT" to %"FMT_HPT") = %luns\n",
  32089. + later-now, now, later,
  32090. + (unsigned long)(HPTIME_CLK_NS * (later - now)));
  32091. +
  32092. + now = hptime();
  32093. + msleep(1000);
  32094. + later = hptime();
  32095. +
  32096. + printk(KERN_INFO DRIVER_NAME": 1s = %"FMT_HPT" clks "
  32097. + "(from %"FMT_HPT" to %"FMT_HPT") = %luns\n",
  32098. + later-now, now, later,
  32099. + (unsigned long)(HPTIME_CLK_NS * (later - now)));
  32100. +}
  32101. +#endif
  32102. +
  32103. +/*****************************************************************************\
  32104. + * *
  32105. + * SDHCI core callbacks *
  32106. + * *
  32107. +\*****************************************************************************/
  32108. +
  32109. +
  32110. +#ifdef CHECK_DMA_USE
  32111. +/*#define CHECK_DMA_REG_USE*/
  32112. +#endif
  32113. +
  32114. +#ifdef CHECK_DMA_REG_USE
  32115. +/* we don't expect anything to be using these registers during a
  32116. + DMA (except the IRQ status) - so check */
  32117. +static void check_dma_reg_use(struct sdhci_host *host, int reg);
  32118. +#else
  32119. +#define check_dma_reg_use(host, reg)
  32120. +#endif
  32121. +
  32122. +
  32123. +static inline u32 sdhci_bcm2708_raw_readl(struct sdhci_host *host, int reg)
  32124. +{
  32125. + return readl(host->ioaddr + reg);
  32126. +}
  32127. +
  32128. +u32 sdhci_bcm2708_readl(struct sdhci_host *host, int reg)
  32129. +{
  32130. + u32 l = sdhci_bcm2708_raw_readl(host, reg);
  32131. +
  32132. +#ifdef LOG_REGISTERS
  32133. + printk(KERN_ERR "%s: readl from 0x%02x, value 0x%08x\n",
  32134. + mmc_hostname(host->mmc), reg, l);
  32135. +#endif
  32136. + check_dma_reg_use(host, reg);
  32137. +
  32138. + return l;
  32139. +}
  32140. +
  32141. +u16 sdhci_bcm2708_readw(struct sdhci_host *host, int reg)
  32142. +{
  32143. + u32 l = sdhci_bcm2708_raw_readl(host, reg & ~3);
  32144. + u32 w = l >> (reg << 3 & 0x18) & 0xffff;
  32145. +
  32146. +#ifdef LOG_REGISTERS
  32147. + printk(KERN_ERR "%s: readw from 0x%02x, value 0x%04x\n",
  32148. + mmc_hostname(host->mmc), reg, w);
  32149. +#endif
  32150. + check_dma_reg_use(host, reg);
  32151. +
  32152. + return (u16)w;
  32153. +}
  32154. +
  32155. +u8 sdhci_bcm2708_readb(struct sdhci_host *host, int reg)
  32156. +{
  32157. + u32 l = sdhci_bcm2708_raw_readl(host, reg & ~3);
  32158. + u32 b = l >> (reg << 3 & 0x18) & 0xff;
  32159. +
  32160. +#ifdef LOG_REGISTERS
  32161. + printk(KERN_ERR "%s: readb from 0x%02x, value 0x%02x\n",
  32162. + mmc_hostname(host->mmc), reg, b);
  32163. +#endif
  32164. + check_dma_reg_use(host, reg);
  32165. +
  32166. + return (u8)b;
  32167. +}
  32168. +
  32169. +
  32170. +static void sdhci_bcm2708_raw_writel(struct sdhci_host *host, u32 val, int reg)
  32171. +{
  32172. + u32 ier;
  32173. +
  32174. +#if USE_SPACED_WRITES_2CLK
  32175. + static bool timeout_disabled = false;
  32176. + unsigned int ns_2clk = 0;
  32177. +
  32178. + /* The Arasan has a bugette whereby it may lose the content of
  32179. + * successive writes to registers that are within two SD-card clock
  32180. + * cycles of each other (a clock domain crossing problem).
  32181. + * It seems, however, that the data register does not have this problem.
  32182. + * (Which is just as well - otherwise we'd have to nobble the DMA engine
  32183. + * too)
  32184. + */
  32185. + if (reg != SDHCI_BUFFER && host->clock != 0) {
  32186. + /* host->clock is the clock freq in Hz */
  32187. + static hptime_t last_write_hpt;
  32188. + hptime_t now = hptime();
  32189. + ns_2clk = cycle_delay*1000000/(host->clock/1000);
  32190. +
  32191. + if (now == last_write_hpt || now == last_write_hpt+1) {
  32192. + /* we can't guarantee any significant time has
  32193. + * passed - we'll have to wait anyway ! */
  32194. + ndelay(ns_2clk);
  32195. + } else
  32196. + {
  32197. + /* we must have waited at least this many ns: */
  32198. + unsigned int ns_wait = HPTIME_CLK_NS *
  32199. + (now - last_write_hpt - 1);
  32200. + if (ns_wait < ns_2clk)
  32201. + ndelay(ns_2clk - ns_wait);
  32202. + }
  32203. + last_write_hpt = now;
  32204. + }
  32205. +#if USE_SOFTWARE_TIMEOUTS
  32206. + /* The Arasan is clocked for timeouts using the SD clock which is too
  32207. + * fast for ERASE commands and causes issues. So we disable timeouts
  32208. + * for ERASE */
  32209. + if (host->cmd != NULL && host->cmd->opcode == MMC_ERASE &&
  32210. + reg == (SDHCI_COMMAND & ~3)) {
  32211. + mod_timer(&host->timer,
  32212. + jiffies + SOFTWARE_ERASE_TIMEOUT_SEC * HZ);
  32213. + ier = readl(host->ioaddr + SDHCI_SIGNAL_ENABLE);
  32214. + ier &= ~SDHCI_INT_DATA_TIMEOUT;
  32215. + writel(ier, host->ioaddr + SDHCI_SIGNAL_ENABLE);
  32216. + timeout_disabled = true;
  32217. + ndelay(ns_2clk);
  32218. + } else if (timeout_disabled) {
  32219. + ier = readl(host->ioaddr + SDHCI_SIGNAL_ENABLE);
  32220. + ier |= SDHCI_INT_DATA_TIMEOUT;
  32221. + writel(ier, host->ioaddr + SDHCI_SIGNAL_ENABLE);
  32222. + timeout_disabled = false;
  32223. + ndelay(ns_2clk);
  32224. + }
  32225. +#endif
  32226. + writel(val, host->ioaddr + reg);
  32227. +#else
  32228. + void __iomem * regaddr = host->ioaddr + reg;
  32229. +
  32230. + writel(val, regaddr);
  32231. +
  32232. + if (reg != SDHCI_BUFFER && reg != SDHCI_INT_STATUS && host->clock != 0)
  32233. + {
  32234. + int timeout = 100000;
  32235. + while (val != readl(regaddr) && --timeout > 0)
  32236. + continue;
  32237. +
  32238. + if (timeout <= 0)
  32239. + printk(KERN_ERR "%s: writing 0x%X to reg 0x%X "
  32240. + "always gives 0x%X\n",
  32241. + mmc_hostname(host->mmc),
  32242. + val, reg, readl(regaddr));
  32243. + BUG_ON(timeout <= 0);
  32244. + }
  32245. +#endif
  32246. +}
  32247. +
  32248. +
  32249. +void sdhci_bcm2708_writel(struct sdhci_host *host, u32 val, int reg)
  32250. +{
  32251. +#ifdef LOG_REGISTERS
  32252. + printk(KERN_ERR "%s: writel to 0x%02x, value 0x%08x\n",
  32253. + mmc_hostname(host->mmc), reg, val);
  32254. +#endif
  32255. + check_dma_reg_use(host, reg);
  32256. +
  32257. + sdhci_bcm2708_raw_writel(host, val, reg);
  32258. +}
  32259. +
  32260. +void sdhci_bcm2708_writew(struct sdhci_host *host, u16 val, int reg)
  32261. +{
  32262. + static u32 shadow = 0;
  32263. +
  32264. + u32 p = reg == SDHCI_COMMAND ? shadow :
  32265. + sdhci_bcm2708_raw_readl(host, reg & ~3);
  32266. + u32 s = reg << 3 & 0x18;
  32267. + u32 l = val << s;
  32268. + u32 m = 0xffff << s;
  32269. +
  32270. +#ifdef LOG_REGISTERS
  32271. + printk(KERN_ERR "%s: writew to 0x%02x, value 0x%04x\n",
  32272. + mmc_hostname(host->mmc), reg, val);
  32273. +#endif
  32274. +
  32275. + if (reg == SDHCI_TRANSFER_MODE)
  32276. + shadow = (p & ~m) | l;
  32277. + else {
  32278. + check_dma_reg_use(host, reg);
  32279. + sdhci_bcm2708_raw_writel(host, (p & ~m) | l, reg & ~3);
  32280. + }
  32281. +}
  32282. +
  32283. +void sdhci_bcm2708_writeb(struct sdhci_host *host, u8 val, int reg)
  32284. +{
  32285. + u32 p = sdhci_bcm2708_raw_readl(host, reg & ~3);
  32286. + u32 s = reg << 3 & 0x18;
  32287. + u32 l = val << s;
  32288. + u32 m = 0xff << s;
  32289. +
  32290. +#ifdef LOG_REGISTERS
  32291. + printk(KERN_ERR "%s: writeb to 0x%02x, value 0x%02x\n",
  32292. + mmc_hostname(host->mmc), reg, val);
  32293. +#endif
  32294. +
  32295. + check_dma_reg_use(host, reg);
  32296. + sdhci_bcm2708_raw_writel(host, (p & ~m) | l, reg & ~3);
  32297. +}
  32298. +
  32299. +static unsigned int sdhci_bcm2708_get_max_clock(struct sdhci_host *host)
  32300. +{
  32301. + return emmc_clock_freq;
  32302. +}
  32303. +
  32304. +/*****************************************************************************\
  32305. + * *
  32306. + * DMA Operation *
  32307. + * *
  32308. +\*****************************************************************************/
  32309. +
  32310. +struct sdhci_bcm2708_priv {
  32311. + int dma_chan;
  32312. + int dma_irq;
  32313. + void __iomem *dma_chan_base;
  32314. + struct bcm2708_dma_cb *cb_base; /* DMA control blocks */
  32315. + dma_addr_t cb_handle;
  32316. + /* tracking scatter gather progress */
  32317. + unsigned sg_ix; /* scatter gather list index */
  32318. + unsigned sg_done; /* bytes in current sg_ix done */
  32319. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  32320. + unsigned char dma_wanted; /* DMA transfer requested */
  32321. + unsigned char dma_waits; /* wait states in DMAs */
  32322. +#ifdef CHECK_DMA_USE
  32323. + unsigned char dmas_pending; /* no of unfinished DMAs */
  32324. + hptime_t when_started;
  32325. + hptime_t when_reset;
  32326. + hptime_t when_stopped;
  32327. +#endif
  32328. +#endif
  32329. + /* signalling the end of a transfer */
  32330. + void (*complete)(struct sdhci_host *);
  32331. +};
  32332. +
  32333. +#define SDHCI_HOST_PRIV(host) \
  32334. + (struct sdhci_bcm2708_priv *)((struct sdhci_host *)(host)+1)
  32335. +
  32336. +
  32337. +
  32338. +#ifdef CHECK_DMA_REG_USE
  32339. +static void check_dma_reg_use(struct sdhci_host *host, int reg)
  32340. +{
  32341. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  32342. + if (host_priv->dma_wanted && reg != SDHCI_INT_STATUS) {
  32343. + printk(KERN_INFO"%s: accessing register 0x%x during DMA\n",
  32344. + mmc_hostname(host->mmc), reg);
  32345. + }
  32346. +}
  32347. +#endif
  32348. +
  32349. +
  32350. +
  32351. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  32352. +
  32353. +static void sdhci_clear_set_irqgen(struct sdhci_host *host, u32 clear, u32 set)
  32354. +{
  32355. + u32 ier;
  32356. +
  32357. + ier = sdhci_bcm2708_raw_readl(host, SDHCI_SIGNAL_ENABLE);
  32358. + ier &= ~clear;
  32359. + ier |= set;
  32360. + /* change which requests generate IRQs - makes no difference to
  32361. + the content of SDHCI_INT_STATUS, or the need to acknowledge IRQs */
  32362. + sdhci_bcm2708_raw_writel(host, ier, SDHCI_SIGNAL_ENABLE);
  32363. +}
  32364. +
  32365. +static void sdhci_signal_irqs(struct sdhci_host *host, u32 irqs)
  32366. +{
  32367. + sdhci_clear_set_irqgen(host, 0, irqs);
  32368. +}
  32369. +
  32370. +static void sdhci_unsignal_irqs(struct sdhci_host *host, u32 irqs)
  32371. +{
  32372. + sdhci_clear_set_irqgen(host, irqs, 0);
  32373. +}
  32374. +
  32375. +
  32376. +
  32377. +static void schci_bcm2708_cb_read(struct sdhci_bcm2708_priv *host,
  32378. + int ix,
  32379. + dma_addr_t dma_addr, unsigned len,
  32380. + int /*bool*/ is_last)
  32381. +{
  32382. + struct bcm2708_dma_cb *cb = &host->cb_base[ix];
  32383. + unsigned char dmawaits = host->dma_waits;
  32384. +
  32385. + cb->info = BCM2708_DMA_PER_MAP(BCM2708_DMA_DREQ_EMMC) |
  32386. + BCM2708_DMA_WAITS(dmawaits) |
  32387. + BCM2708_DMA_S_DREQ |
  32388. + BCM2708_DMA_D_WIDTH |
  32389. + BCM2708_DMA_D_INC;
  32390. + cb->src = DMA_SDHCI_BUFFER; /* DATA register DMA address */
  32391. + cb->dst = dma_addr;
  32392. + cb->length = len;
  32393. + cb->stride = 0;
  32394. +
  32395. + if (is_last) {
  32396. + cb->info |= BCM2708_DMA_INT_EN |
  32397. + BCM2708_DMA_WAIT_RESP;
  32398. + cb->next = 0;
  32399. + } else
  32400. + cb->next = host->cb_handle +
  32401. + (ix+1)*sizeof(struct bcm2708_dma_cb);
  32402. +
  32403. + cb->pad[0] = 0;
  32404. + cb->pad[1] = 0;
  32405. +}
  32406. +
  32407. +static void schci_bcm2708_cb_write(struct sdhci_bcm2708_priv *host,
  32408. + int ix,
  32409. + dma_addr_t dma_addr, unsigned len,
  32410. + int /*bool*/ is_last)
  32411. +{
  32412. + struct bcm2708_dma_cb *cb = &host->cb_base[ix];
  32413. + unsigned char dmawaits = host->dma_waits;
  32414. +
  32415. + /* We can make arbitrarily large writes as long as we specify DREQ to
  32416. + pace the delivery of bytes to the Arasan hardware */
  32417. + cb->info = BCM2708_DMA_PER_MAP(BCM2708_DMA_DREQ_EMMC) |
  32418. + BCM2708_DMA_WAITS(dmawaits) |
  32419. + BCM2708_DMA_D_DREQ |
  32420. + BCM2708_DMA_S_WIDTH |
  32421. + BCM2708_DMA_S_INC;
  32422. + cb->src = dma_addr;
  32423. + cb->dst = DMA_SDHCI_BUFFER; /* DATA register DMA address */
  32424. + cb->length = len;
  32425. + cb->stride = 0;
  32426. +
  32427. + if (is_last) {
  32428. + cb->info |= BCM2708_DMA_INT_EN |
  32429. + BCM2708_DMA_WAIT_RESP;
  32430. + cb->next = 0;
  32431. + } else
  32432. + cb->next = host->cb_handle +
  32433. + (ix+1)*sizeof(struct bcm2708_dma_cb);
  32434. +
  32435. + cb->pad[0] = 0;
  32436. + cb->pad[1] = 0;
  32437. +}
  32438. +
  32439. +
  32440. +static void schci_bcm2708_dma_go(struct sdhci_host *host)
  32441. +{
  32442. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  32443. + void __iomem *dma_chan_base = host_priv->dma_chan_base;
  32444. +
  32445. + BUG_ON(host_priv->dma_wanted);
  32446. +#ifdef CHECK_DMA_USE
  32447. + if (host_priv->dma_wanted)
  32448. + printk(KERN_ERR "%s: DMA already in progress - "
  32449. + "now %"FMT_HPT", last started %lu "
  32450. + "reset %lu stopped %lu\n",
  32451. + mmc_hostname(host->mmc),
  32452. + hptime(), since_ns(host_priv->when_started),
  32453. + since_ns(host_priv->when_reset),
  32454. + since_ns(host_priv->when_stopped));
  32455. + else if (host_priv->dmas_pending > 0)
  32456. + printk(KERN_INFO "%s: note - new DMA when %d reset DMAs "
  32457. + "already in progress - "
  32458. + "now %"FMT_HPT", started %lu reset %lu stopped %lu\n",
  32459. + mmc_hostname(host->mmc),
  32460. + host_priv->dmas_pending,
  32461. + hptime(), since_ns(host_priv->when_started),
  32462. + since_ns(host_priv->when_reset),
  32463. + since_ns(host_priv->when_stopped));
  32464. + host_priv->dmas_pending += 1;
  32465. + host_priv->when_started = hptime();
  32466. +#endif
  32467. + host_priv->dma_wanted = 1;
  32468. + DBG("PDMA go - base %p handle %08X\n", dma_chan_base,
  32469. + host_priv->cb_handle);
  32470. + bcm_dma_start(dma_chan_base, host_priv->cb_handle);
  32471. +}
  32472. +
  32473. +
  32474. +static void
  32475. +sdhci_platdma_read(struct sdhci_host *host, dma_addr_t dma_addr, size_t len)
  32476. +{
  32477. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  32478. +
  32479. + DBG("PDMA to read %d bytes\n", len);
  32480. + host_priv->sg_done += len;
  32481. + schci_bcm2708_cb_read(host_priv, 0, dma_addr, len, 1/*TRUE*/);
  32482. + schci_bcm2708_dma_go(host);
  32483. +}
  32484. +
  32485. +
  32486. +static void
  32487. +sdhci_platdma_write(struct sdhci_host *host, dma_addr_t dma_addr, size_t len)
  32488. +{
  32489. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  32490. +
  32491. + DBG("PDMA to write %d bytes\n", len);
  32492. + //BUG_ON(0 != (len & 0x1ff));
  32493. +
  32494. + host_priv->sg_done += len;
  32495. + schci_bcm2708_cb_write(host_priv, 0, dma_addr, len, 1/*TRUE*/);
  32496. + schci_bcm2708_dma_go(host);
  32497. +}
  32498. +
  32499. +/*! space is avaiable to receive into or data is available to write
  32500. + Platform DMA exported function
  32501. +*/
  32502. +void
  32503. +sdhci_bcm2708_platdma_avail(struct sdhci_host *host, unsigned int *ref_intmask,
  32504. + void(*completion_callback)(struct sdhci_host *host))
  32505. +{
  32506. + struct mmc_data *data = host->data;
  32507. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  32508. + int sg_ix;
  32509. + size_t bytes;
  32510. + dma_addr_t addr;
  32511. +
  32512. + BUG_ON(NULL == data);
  32513. + BUG_ON(0 == data->blksz);
  32514. +
  32515. + host_priv->complete = completion_callback;
  32516. +
  32517. + sg_ix = host_priv->sg_ix;
  32518. + BUG_ON(sg_ix >= data->sg_len);
  32519. +
  32520. + /* we can DMA blocks larger than blksz - it may hang the DMA
  32521. + channel but we are its only user */
  32522. + bytes = sg_dma_len(&data->sg[sg_ix]) - host_priv->sg_done;
  32523. + addr = sg_dma_address(&data->sg[sg_ix]) + host_priv->sg_done;
  32524. +
  32525. + if (bytes > 0) {
  32526. + /* We're going to poll for read/write available state until
  32527. + we finish this DMA
  32528. + */
  32529. +
  32530. + if (data->flags & MMC_DATA_READ) {
  32531. + if (*ref_intmask & SDHCI_INT_DATA_AVAIL) {
  32532. + sdhci_unsignal_irqs(host, SDHCI_INT_DATA_AVAIL |
  32533. + SDHCI_INT_SPACE_AVAIL);
  32534. + sdhci_platdma_read(host, addr, bytes);
  32535. + }
  32536. + } else {
  32537. + if (*ref_intmask & SDHCI_INT_SPACE_AVAIL) {
  32538. + sdhci_unsignal_irqs(host, SDHCI_INT_DATA_AVAIL |
  32539. + SDHCI_INT_SPACE_AVAIL);
  32540. + sdhci_platdma_write(host, addr, bytes);
  32541. + }
  32542. + }
  32543. + }
  32544. + /* else:
  32545. + we have run out of bytes that need transferring (e.g. we may be in
  32546. + the middle of the last DMA transfer), or
  32547. + it is also possible that we've been called when another IRQ is
  32548. + signalled, even though we've turned off signalling of our own IRQ */
  32549. +
  32550. + *ref_intmask &= ~SDHCI_INT_DATA_END;
  32551. + /* don't let the main sdhci driver act on this .. we'll deal with it
  32552. + when we respond to the DMA - if one is currently in progress */
  32553. +}
  32554. +
  32555. +/* is it possible to DMA the given mmc_data structure?
  32556. + Platform DMA exported function
  32557. +*/
  32558. +int /*bool*/
  32559. +sdhci_bcm2708_platdma_dmaable(struct sdhci_host *host, struct mmc_data *data)
  32560. +{
  32561. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  32562. + int ok = bcm_sg_suitable_for_dma(data->sg, data->sg_len);
  32563. +
  32564. + if (!ok)
  32565. + DBG("Reverting to PIO - bad cache alignment\n");
  32566. +
  32567. + else {
  32568. + host_priv->sg_ix = 0; /* first SG index */
  32569. + host_priv->sg_done = 0; /* no bytes done */
  32570. + }
  32571. +
  32572. + return ok;
  32573. +}
  32574. +
  32575. +#include <mach/arm_control.h> //GRAYG
  32576. +/*! the current SD transacton has been abandonned
  32577. + We need to tidy up if we were in the middle of a DMA
  32578. + Platform DMA exported function
  32579. +*/
  32580. +void
  32581. +sdhci_bcm2708_platdma_reset(struct sdhci_host *host, struct mmc_data *data)
  32582. +{
  32583. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  32584. +// unsigned long flags;
  32585. +
  32586. + BUG_ON(NULL == host);
  32587. +
  32588. +// spin_lock_irqsave(&host->lock, flags);
  32589. +
  32590. + if (host_priv->dma_wanted) {
  32591. + if (NULL == data) {
  32592. + printk(KERN_ERR "%s: ongoing DMA reset - no data!\n",
  32593. + mmc_hostname(host->mmc));
  32594. + BUG_ON(NULL == data);
  32595. + } else {
  32596. + struct scatterlist *sg;
  32597. + int sg_len;
  32598. + int sg_todo;
  32599. + int rc;
  32600. + unsigned long cs;
  32601. +
  32602. + sg = data->sg;
  32603. + sg_len = data->sg_len;
  32604. + sg_todo = sg_dma_len(&sg[host_priv->sg_ix]);
  32605. +
  32606. + cs = readl(host_priv->dma_chan_base + BCM2708_DMA_CS);
  32607. +
  32608. + if (!(BCM2708_DMA_ACTIVE & cs))
  32609. + {
  32610. + if (extra_messages)
  32611. + printk(KERN_INFO "%s: missed completion of "
  32612. + "cmd %d DMA (%d/%d [%d]/[%d]) - "
  32613. + "ignoring it\n",
  32614. + mmc_hostname(host->mmc),
  32615. + host->last_cmdop,
  32616. + host_priv->sg_done, sg_todo,
  32617. + host_priv->sg_ix+1, sg_len);
  32618. + }
  32619. + else
  32620. + printk(KERN_INFO "%s: resetting ongoing cmd %d"
  32621. + "DMA before %d/%d [%d]/[%d] complete\n",
  32622. + mmc_hostname(host->mmc),
  32623. + host->last_cmdop,
  32624. + host_priv->sg_done, sg_todo,
  32625. + host_priv->sg_ix+1, sg_len);
  32626. +#ifdef CHECK_DMA_USE
  32627. + printk(KERN_INFO "%s: now %"FMT_HPT" started %lu "
  32628. + "last reset %lu last stopped %lu\n",
  32629. + mmc_hostname(host->mmc),
  32630. + hptime(), since_ns(host_priv->when_started),
  32631. + since_ns(host_priv->when_reset),
  32632. + since_ns(host_priv->when_stopped));
  32633. + { unsigned long info, debug;
  32634. + void __iomem *base;
  32635. + unsigned long pend0, pend1, pend2;
  32636. +
  32637. + base = host_priv->dma_chan_base;
  32638. + cs = readl(base + BCM2708_DMA_CS);
  32639. + info = readl(base + BCM2708_DMA_INFO);
  32640. + debug = readl(base + BCM2708_DMA_DEBUG);
  32641. + printk(KERN_INFO "%s: DMA%d CS=%08lX TI=%08lX "
  32642. + "DEBUG=%08lX\n",
  32643. + mmc_hostname(host->mmc),
  32644. + host_priv->dma_chan,
  32645. + cs, info, debug);
  32646. + pend0 = readl(__io_address(ARM_IRQ_PEND0));
  32647. + pend1 = readl(__io_address(ARM_IRQ_PEND1));
  32648. + pend2 = readl(__io_address(ARM_IRQ_PEND2));
  32649. +
  32650. + printk(KERN_INFO "%s: PEND0=%08lX "
  32651. + "PEND1=%08lX PEND2=%08lX\n",
  32652. + mmc_hostname(host->mmc),
  32653. + pend0, pend1, pend2);
  32654. +
  32655. + //gintsts = readl(__io_address(GINTSTS));
  32656. + //gintmsk = readl(__io_address(GINTMSK));
  32657. + //printk(KERN_INFO "%s: USB GINTSTS=%08lX"
  32658. + // "GINTMSK=%08lX\n",
  32659. + // mmc_hostname(host->mmc), gintsts, gintmsk);
  32660. + }
  32661. +#endif
  32662. + rc = bcm_dma_abort(host_priv->dma_chan_base);
  32663. + BUG_ON(rc != 0);
  32664. + }
  32665. + host_priv->dma_wanted = 0;
  32666. +#ifdef CHECK_DMA_USE
  32667. + host_priv->when_reset = hptime();
  32668. +#endif
  32669. + }
  32670. +
  32671. +// spin_unlock_irqrestore(&host->lock, flags);
  32672. +}
  32673. +
  32674. +
  32675. +static void sdhci_bcm2708_dma_complete_irq(struct sdhci_host *host,
  32676. + u32 dma_cs)
  32677. +{
  32678. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  32679. + struct mmc_data *data;
  32680. + struct scatterlist *sg;
  32681. + int sg_len;
  32682. + int sg_ix;
  32683. + int sg_todo;
  32684. +// unsigned long flags;
  32685. +
  32686. + BUG_ON(NULL == host);
  32687. +
  32688. +// spin_lock_irqsave(&host->lock, flags);
  32689. + data = host->data;
  32690. +
  32691. +#ifdef CHECK_DMA_USE
  32692. + if (host_priv->dmas_pending <= 0)
  32693. + DBG("on completion no DMA in progress - "
  32694. + "now %"FMT_HPT" started %lu reset %lu stopped %lu\n",
  32695. + hptime(), since_ns(host_priv->when_started),
  32696. + since_ns(host_priv->when_reset),
  32697. + since_ns(host_priv->when_stopped));
  32698. + else if (host_priv->dmas_pending > 1)
  32699. + DBG("still %d DMA in progress after completion - "
  32700. + "now %"FMT_HPT" started %lu reset %lu stopped %lu\n",
  32701. + host_priv->dmas_pending - 1,
  32702. + hptime(), since_ns(host_priv->when_started),
  32703. + since_ns(host_priv->when_reset),
  32704. + since_ns(host_priv->when_stopped));
  32705. + BUG_ON(host_priv->dmas_pending <= 0);
  32706. + host_priv->dmas_pending -= 1;
  32707. + host_priv->when_stopped = hptime();
  32708. +#endif
  32709. + host_priv->dma_wanted = 0;
  32710. +
  32711. + if (NULL == data) {
  32712. + DBG("PDMA unused completion - status 0x%X\n", dma_cs);
  32713. +// spin_unlock_irqrestore(&host->lock, flags);
  32714. + return;
  32715. + }
  32716. + sg = data->sg;
  32717. + sg_len = data->sg_len;
  32718. + sg_todo = sg_dma_len(&sg[host_priv->sg_ix]);
  32719. +
  32720. + DBG("PDMA complete %d/%d [%d]/[%d]..\n",
  32721. + host_priv->sg_done, sg_todo,
  32722. + host_priv->sg_ix+1, sg_len);
  32723. +
  32724. + BUG_ON(host_priv->sg_done > sg_todo);
  32725. +
  32726. + if (host_priv->sg_done >= sg_todo) {
  32727. + host_priv->sg_ix++;
  32728. + host_priv->sg_done = 0;
  32729. + }
  32730. +
  32731. + sg_ix = host_priv->sg_ix;
  32732. + if (sg_ix < sg_len) {
  32733. + u32 irq_mask;
  32734. + /* Set off next DMA if we've got the capacity */
  32735. +
  32736. + if (data->flags & MMC_DATA_READ)
  32737. + irq_mask = SDHCI_INT_DATA_AVAIL;
  32738. + else
  32739. + irq_mask = SDHCI_INT_SPACE_AVAIL;
  32740. +
  32741. + /* We have to use the interrupt status register on the BCM2708
  32742. + rather than the SDHCI_PRESENT_STATE register because latency
  32743. + in the glue logic means that the information retrieved from
  32744. + the latter is not always up-to-date w.r.t the DMA engine -
  32745. + it may not indicate that a read or a write is ready yet */
  32746. + if (sdhci_bcm2708_raw_readl(host, SDHCI_INT_STATUS) &
  32747. + irq_mask) {
  32748. + size_t bytes = sg_dma_len(&sg[sg_ix]) -
  32749. + host_priv->sg_done;
  32750. + dma_addr_t addr = sg_dma_address(&data->sg[sg_ix]) +
  32751. + host_priv->sg_done;
  32752. +
  32753. + /* acknowledge interrupt */
  32754. + sdhci_bcm2708_raw_writel(host, irq_mask,
  32755. + SDHCI_INT_STATUS);
  32756. +
  32757. + BUG_ON(0 == bytes);
  32758. +
  32759. + if (data->flags & MMC_DATA_READ)
  32760. + sdhci_platdma_read(host, addr, bytes);
  32761. + else
  32762. + sdhci_platdma_write(host, addr, bytes);
  32763. + } else {
  32764. + DBG("PDMA - wait avail\n");
  32765. + /* may generate an IRQ if already present */
  32766. + sdhci_signal_irqs(host, SDHCI_INT_DATA_AVAIL |
  32767. + SDHCI_INT_SPACE_AVAIL);
  32768. + }
  32769. + } else {
  32770. + if (sync_after_dma) {
  32771. + /* On the Arasan controller the stop command (which will be
  32772. + scheduled after this completes) does not seem to work
  32773. + properly if we allow it to be issued when we are
  32774. + transferring data to/from the SD card.
  32775. + We get CRC and DEND errors unless we wait for
  32776. + the SD controller to finish reading/writing to the card. */
  32777. + u32 state_mask;
  32778. + int timeout=3*1000*1000;
  32779. +
  32780. + DBG("PDMA over - sync card\n");
  32781. + if (data->flags & MMC_DATA_READ)
  32782. + state_mask = SDHCI_DOING_READ;
  32783. + else
  32784. + state_mask = SDHCI_DOING_WRITE;
  32785. +
  32786. + while (0 != (sdhci_bcm2708_raw_readl(host, SDHCI_PRESENT_STATE)
  32787. + & state_mask) && --timeout > 0)
  32788. + {
  32789. + udelay(1);
  32790. + continue;
  32791. + }
  32792. + if (timeout <= 0)
  32793. + printk(KERN_ERR"%s: final %s to SD card still "
  32794. + "running\n",
  32795. + mmc_hostname(host->mmc),
  32796. + data->flags & MMC_DATA_READ? "read": "write");
  32797. + }
  32798. + if (host_priv->complete) {
  32799. + (*host_priv->complete)(host);
  32800. + DBG("PDMA %s complete\n",
  32801. + data->flags & MMC_DATA_READ?"read":"write");
  32802. + sdhci_signal_irqs(host, SDHCI_INT_DATA_AVAIL |
  32803. + SDHCI_INT_SPACE_AVAIL);
  32804. + }
  32805. + }
  32806. +// spin_unlock_irqrestore(&host->lock, flags);
  32807. +}
  32808. +
  32809. +static irqreturn_t sdhci_bcm2708_dma_irq(int irq, void *dev_id)
  32810. +{
  32811. + irqreturn_t result = IRQ_NONE;
  32812. + struct sdhci_host *host = dev_id;
  32813. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  32814. + u32 dma_cs; /* control and status register */
  32815. +
  32816. + BUG_ON(NULL == dev_id);
  32817. + BUG_ON(NULL == host_priv->dma_chan_base);
  32818. +
  32819. + sdhci_spin_lock(host);
  32820. +
  32821. + dma_cs = readl(host_priv->dma_chan_base + BCM2708_DMA_CS);
  32822. +
  32823. + if (dma_cs & BCM2708_DMA_ERR) {
  32824. + unsigned long debug;
  32825. + debug = readl(host_priv->dma_chan_base +
  32826. + BCM2708_DMA_DEBUG);
  32827. + printk(KERN_ERR "%s: DMA error - CS %lX DEBUG %lX\n",
  32828. + mmc_hostname(host->mmc), (unsigned long)dma_cs,
  32829. + (unsigned long)debug);
  32830. + /* reset error */
  32831. + writel(debug, host_priv->dma_chan_base +
  32832. + BCM2708_DMA_DEBUG);
  32833. + }
  32834. + if (dma_cs & BCM2708_DMA_INT) {
  32835. + /* acknowledge interrupt */
  32836. + writel(BCM2708_DMA_INT,
  32837. + host_priv->dma_chan_base + BCM2708_DMA_CS);
  32838. +
  32839. + dsb(); /* ARM data synchronization (push) operation */
  32840. +
  32841. + if (!host_priv->dma_wanted) {
  32842. + /* ignore this interrupt - it was reset */
  32843. + if (extra_messages)
  32844. + printk(KERN_INFO "%s: DMA IRQ %X ignored - "
  32845. + "results were reset\n",
  32846. + mmc_hostname(host->mmc), dma_cs);
  32847. +#ifdef CHECK_DMA_USE
  32848. + printk(KERN_INFO "%s: now %"FMT_HPT
  32849. + " started %lu reset %lu stopped %lu\n",
  32850. + mmc_hostname(host->mmc), hptime(),
  32851. + since_ns(host_priv->when_started),
  32852. + since_ns(host_priv->when_reset),
  32853. + since_ns(host_priv->when_stopped));
  32854. + host_priv->dmas_pending--;
  32855. +#endif
  32856. + } else
  32857. + sdhci_bcm2708_dma_complete_irq(host, dma_cs);
  32858. +
  32859. + result = IRQ_HANDLED;
  32860. + }
  32861. + sdhci_spin_unlock(host);
  32862. +
  32863. + return result;
  32864. +}
  32865. +#endif /* CONFIG_MMC_SDHCI_BCM2708_DMA */
  32866. +
  32867. +
  32868. +/***************************************************************************** \
  32869. + * *
  32870. + * Device Attributes *
  32871. + * *
  32872. +\*****************************************************************************/
  32873. +
  32874. +
  32875. +/**
  32876. + * Show the DMA-using status
  32877. + */
  32878. +static ssize_t attr_dma_show(struct device *_dev,
  32879. + struct device_attribute *attr, char *buf)
  32880. +{
  32881. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  32882. +
  32883. + if (host) {
  32884. + int use_dma = (host->flags & SDHCI_USE_PLATDMA? 1:0);
  32885. + return sprintf(buf, "%d\n", use_dma);
  32886. + } else
  32887. + return -EINVAL;
  32888. +}
  32889. +
  32890. +/**
  32891. + * Set the DMA-using status
  32892. + */
  32893. +static ssize_t attr_dma_store(struct device *_dev,
  32894. + struct device_attribute *attr,
  32895. + const char *buf, size_t count)
  32896. +{
  32897. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  32898. +
  32899. + if (host) {
  32900. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  32901. + int on = simple_strtol(buf, NULL, 0);
  32902. + if (on) {
  32903. + host->flags |= SDHCI_USE_PLATDMA;
  32904. + sdhci_bcm2708_writel(host, 1, REG_EXRDFIFO_EN);
  32905. + printk(KERN_INFO "%s: DMA enabled\n",
  32906. + mmc_hostname(host->mmc));
  32907. + } else {
  32908. + host->flags &= ~(SDHCI_USE_PLATDMA | SDHCI_REQ_USE_DMA);
  32909. + sdhci_bcm2708_writel(host, 0, REG_EXRDFIFO_EN);
  32910. + printk(KERN_INFO "%s: DMA disabled\n",
  32911. + mmc_hostname(host->mmc));
  32912. + }
  32913. +#endif
  32914. + return count;
  32915. + } else
  32916. + return -EINVAL;
  32917. +}
  32918. +
  32919. +static DEVICE_ATTR(use_dma, S_IRUGO | S_IWUGO, attr_dma_show, attr_dma_store);
  32920. +
  32921. +
  32922. +/**
  32923. + * Show the DMA wait states used
  32924. + */
  32925. +static ssize_t attr_dmawait_show(struct device *_dev,
  32926. + struct device_attribute *attr, char *buf)
  32927. +{
  32928. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  32929. +
  32930. + if (host) {
  32931. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  32932. + int dmawait = host_priv->dma_waits;
  32933. + return sprintf(buf, "%d\n", dmawait);
  32934. + } else
  32935. + return -EINVAL;
  32936. +}
  32937. +
  32938. +/**
  32939. + * Set the DMA wait state used
  32940. + */
  32941. +static ssize_t attr_dmawait_store(struct device *_dev,
  32942. + struct device_attribute *attr,
  32943. + const char *buf, size_t count)
  32944. +{
  32945. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  32946. +
  32947. + if (host) {
  32948. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  32949. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  32950. + int dma_waits = simple_strtol(buf, NULL, 0);
  32951. + if (dma_waits >= 0 && dma_waits < 32)
  32952. + host_priv->dma_waits = dma_waits;
  32953. + else
  32954. + printk(KERN_ERR "%s: illegal dma_waits value - %d",
  32955. + mmc_hostname(host->mmc), dma_waits);
  32956. +#endif
  32957. + return count;
  32958. + } else
  32959. + return -EINVAL;
  32960. +}
  32961. +
  32962. +static DEVICE_ATTR(dma_wait, S_IRUGO | S_IWUGO,
  32963. + attr_dmawait_show, attr_dmawait_store);
  32964. +
  32965. +
  32966. +/**
  32967. + * Show the DMA-using status
  32968. + */
  32969. +static ssize_t attr_status_show(struct device *_dev,
  32970. + struct device_attribute *attr, char *buf)
  32971. +{
  32972. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  32973. +
  32974. + if (host) {
  32975. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  32976. + return sprintf(buf,
  32977. + "present: yes\n"
  32978. + "power: %s\n"
  32979. + "clock: %u Hz\n"
  32980. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  32981. + "dma: %s (%d waits)\n",
  32982. +#else
  32983. + "dma: unconfigured\n",
  32984. +#endif
  32985. + "always on",
  32986. + host->clock
  32987. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  32988. + , (host->flags & SDHCI_USE_PLATDMA)? "on": "off"
  32989. + , host_priv->dma_waits
  32990. +#endif
  32991. + );
  32992. + } else
  32993. + return -EINVAL;
  32994. +}
  32995. +
  32996. +static DEVICE_ATTR(status, S_IRUGO, attr_status_show, NULL);
  32997. +
  32998. +/***************************************************************************** \
  32999. + * *
  33000. + * Power Management *
  33001. + * *
  33002. +\*****************************************************************************/
  33003. +
  33004. +
  33005. +#ifdef CONFIG_PM
  33006. +static int sdhci_bcm2708_suspend(struct platform_device *dev, pm_message_t state)
  33007. +{
  33008. + struct sdhci_host *host = (struct sdhci_host *)
  33009. + platform_get_drvdata(dev);
  33010. + int ret = 0;
  33011. +
  33012. + if (host->mmc) {
  33013. + //ret = mmc_suspend_host(host->mmc);
  33014. + }
  33015. +
  33016. + return ret;
  33017. +}
  33018. +
  33019. +static int sdhci_bcm2708_resume(struct platform_device *dev)
  33020. +{
  33021. + struct sdhci_host *host = (struct sdhci_host *)
  33022. + platform_get_drvdata(dev);
  33023. + int ret = 0;
  33024. +
  33025. + if (host->mmc) {
  33026. + //ret = mmc_resume_host(host->mmc);
  33027. + }
  33028. +
  33029. + return ret;
  33030. +}
  33031. +#endif
  33032. +
  33033. +
  33034. +/*****************************************************************************\
  33035. + * *
  33036. + * Device quirk functions. Implemented as local ops because the flags *
  33037. + * field is out of space with newer kernels. This implementation can be *
  33038. + * back ported to older kernels as well. *
  33039. +\****************************************************************************/
  33040. +static unsigned int sdhci_bcm2708_quirk_extra_ints(struct sdhci_host *host)
  33041. +{
  33042. + return 1;
  33043. +}
  33044. +
  33045. +static unsigned int sdhci_bcm2708_quirk_spurious_crc_acmd51(struct sdhci_host *host)
  33046. +{
  33047. + return 1;
  33048. +}
  33049. +
  33050. +static unsigned int sdhci_bcm2708_missing_status(struct sdhci_host *host)
  33051. +{
  33052. + return 1;
  33053. +}
  33054. +
  33055. +/***************************************************************************** \
  33056. + * *
  33057. + * Device ops *
  33058. + * *
  33059. +\*****************************************************************************/
  33060. +
  33061. +static struct sdhci_ops sdhci_bcm2708_ops = {
  33062. +#ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS
  33063. + .read_l = sdhci_bcm2708_readl,
  33064. + .read_w = sdhci_bcm2708_readw,
  33065. + .read_b = sdhci_bcm2708_readb,
  33066. + .write_l = sdhci_bcm2708_writel,
  33067. + .write_w = sdhci_bcm2708_writew,
  33068. + .write_b = sdhci_bcm2708_writeb,
  33069. +#else
  33070. +#error The BCM2708 SDHCI driver needs CONFIG_MMC_SDHCI_IO_ACCESSORS to be set
  33071. +#endif
  33072. + .get_max_clock = sdhci_bcm2708_get_max_clock,
  33073. +
  33074. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  33075. + // Platform DMA operations
  33076. + .pdma_able = sdhci_bcm2708_platdma_dmaable,
  33077. + .pdma_avail = sdhci_bcm2708_platdma_avail,
  33078. + .pdma_reset = sdhci_bcm2708_platdma_reset,
  33079. +#endif
  33080. + .extra_ints = sdhci_bcm2708_quirk_extra_ints,
  33081. +};
  33082. +
  33083. +/*****************************************************************************\
  33084. + * *
  33085. + * Device probing/removal *
  33086. + * *
  33087. +\*****************************************************************************/
  33088. +
  33089. +static int sdhci_bcm2708_probe(struct platform_device *pdev)
  33090. +{
  33091. + struct sdhci_host *host;
  33092. + struct resource *iomem;
  33093. + struct sdhci_bcm2708_priv *host_priv;
  33094. + int ret;
  33095. +
  33096. + BUG_ON(pdev == NULL);
  33097. +
  33098. + iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  33099. + if (!iomem) {
  33100. + ret = -ENOMEM;
  33101. + goto err;
  33102. + }
  33103. +
  33104. + if (resource_size(iomem) != 0x100)
  33105. + dev_err(&pdev->dev, "Invalid iomem size. You may "
  33106. + "experience problems.\n");
  33107. +
  33108. + if (pdev->dev.parent)
  33109. + host = sdhci_alloc_host(pdev->dev.parent,
  33110. + sizeof(struct sdhci_bcm2708_priv));
  33111. + else
  33112. + host = sdhci_alloc_host(&pdev->dev,
  33113. + sizeof(struct sdhci_bcm2708_priv));
  33114. +
  33115. + if (IS_ERR(host)) {
  33116. + ret = PTR_ERR(host);
  33117. + goto err;
  33118. + }
  33119. + if (missing_status) {
  33120. + sdhci_bcm2708_ops.missing_status = sdhci_bcm2708_missing_status;
  33121. + }
  33122. +
  33123. + if( spurious_crc_acmd51 ) {
  33124. + sdhci_bcm2708_ops.spurious_crc_acmd51 = sdhci_bcm2708_quirk_spurious_crc_acmd51;
  33125. + }
  33126. +
  33127. +
  33128. + printk("sdhci: %s low-latency mode\n",enable_llm?"Enable":"Disable");
  33129. +
  33130. + host->hw_name = "BCM2708_Arasan";
  33131. + host->ops = &sdhci_bcm2708_ops;
  33132. + host->irq = platform_get_irq(pdev, 0);
  33133. + host->second_irq = 0;
  33134. +
  33135. + host->quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION |
  33136. + SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
  33137. + SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
  33138. + SDHCI_QUIRK_MISSING_CAPS |
  33139. + SDHCI_QUIRK_NO_HISPD_BIT |
  33140. + (sync_after_dma ? 0:SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12);
  33141. +
  33142. +
  33143. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  33144. + host->flags = SDHCI_USE_PLATDMA;
  33145. +#endif
  33146. +
  33147. + if (!request_mem_region(iomem->start, resource_size(iomem),
  33148. + mmc_hostname(host->mmc))) {
  33149. + dev_err(&pdev->dev, "cannot request region\n");
  33150. + ret = -EBUSY;
  33151. + goto err_request;
  33152. + }
  33153. +
  33154. + host->ioaddr = ioremap(iomem->start, resource_size(iomem));
  33155. + if (!host->ioaddr) {
  33156. + dev_err(&pdev->dev, "failed to remap registers\n");
  33157. + ret = -ENOMEM;
  33158. + goto err_remap;
  33159. + }
  33160. +
  33161. + host_priv = SDHCI_HOST_PRIV(host);
  33162. +
  33163. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  33164. + host_priv->dma_wanted = 0;
  33165. +#ifdef CHECK_DMA_USE
  33166. + host_priv->dmas_pending = 0;
  33167. + host_priv->when_started = 0;
  33168. + host_priv->when_reset = 0;
  33169. + host_priv->when_stopped = 0;
  33170. +#endif
  33171. + host_priv->sg_ix = 0;
  33172. + host_priv->sg_done = 0;
  33173. + host_priv->complete = NULL;
  33174. + host_priv->dma_waits = SDHCI_BCM_DMA_WAITS;
  33175. +
  33176. + host_priv->cb_base = dma_alloc_writecombine(&pdev->dev, SZ_4K,
  33177. + &host_priv->cb_handle,
  33178. + GFP_KERNEL);
  33179. + if (!host_priv->cb_base) {
  33180. + dev_err(&pdev->dev, "cannot allocate DMA CBs\n");
  33181. + ret = -ENOMEM;
  33182. + goto err_alloc_cb;
  33183. + }
  33184. +
  33185. + ret = bcm_dma_chan_alloc(BCM_DMA_FEATURE_FAST,
  33186. + &host_priv->dma_chan_base,
  33187. + &host_priv->dma_irq);
  33188. + if (ret < 0) {
  33189. + dev_err(&pdev->dev, "couldn't allocate a DMA channel\n");
  33190. + goto err_add_dma;
  33191. + }
  33192. + host_priv->dma_chan = ret;
  33193. +
  33194. + ret = request_irq(host_priv->dma_irq, sdhci_bcm2708_dma_irq,
  33195. + 0 /*IRQF_SHARED*/, DRIVER_NAME " (dma)", host);
  33196. + if (ret) {
  33197. + dev_err(&pdev->dev, "cannot set DMA IRQ\n");
  33198. + goto err_add_dma_irq;
  33199. + }
  33200. + host->second_irq = host_priv->dma_irq;
  33201. + DBG("DMA CBs %p handle %08X DMA%d %p DMA IRQ %d\n",
  33202. + host_priv->cb_base, (unsigned)host_priv->cb_handle,
  33203. + host_priv->dma_chan, host_priv->dma_chan_base,
  33204. + host_priv->dma_irq);
  33205. +
  33206. + // we support 3.3V
  33207. + host->caps |= SDHCI_CAN_VDD_330;
  33208. + if (allow_highspeed)
  33209. + host->mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
  33210. +
  33211. + /* single block writes cause data loss with some SD cards! */
  33212. + host->mmc->caps2 |= MMC_CAP2_FORCE_MULTIBLOCK;
  33213. +#endif
  33214. +
  33215. + ret = sdhci_add_host(host);
  33216. + if (ret)
  33217. + goto err_add_host;
  33218. +
  33219. + platform_set_drvdata(pdev, host);
  33220. + ret = device_create_file(&pdev->dev, &dev_attr_use_dma);
  33221. + ret = device_create_file(&pdev->dev, &dev_attr_dma_wait);
  33222. + ret = device_create_file(&pdev->dev, &dev_attr_status);
  33223. +
  33224. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  33225. + /* enable extension fifo for paced DMA transfers */
  33226. + sdhci_bcm2708_writel(host, 1, REG_EXRDFIFO_EN);
  33227. + sdhci_bcm2708_writel(host, 4, REG_EXRDFIFO_CFG);
  33228. +#endif
  33229. +
  33230. + printk(KERN_INFO "%s: BCM2708 SDHC host at 0x%08llx DMA %d IRQ %d\n",
  33231. + mmc_hostname(host->mmc), (unsigned long long)iomem->start,
  33232. + host_priv->dma_chan, host_priv->dma_irq);
  33233. +
  33234. + return 0;
  33235. +
  33236. +err_add_host:
  33237. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  33238. + free_irq(host_priv->dma_irq, host);
  33239. +err_add_dma_irq:
  33240. + bcm_dma_chan_free(host_priv->dma_chan);
  33241. +err_add_dma:
  33242. + dma_free_writecombine(&pdev->dev, SZ_4K, host_priv->cb_base,
  33243. + host_priv->cb_handle);
  33244. +err_alloc_cb:
  33245. +#endif
  33246. + iounmap(host->ioaddr);
  33247. +err_remap:
  33248. + release_mem_region(iomem->start, resource_size(iomem));
  33249. +err_request:
  33250. + sdhci_free_host(host);
  33251. +err:
  33252. + dev_err(&pdev->dev, "probe failed, err %d\n", ret);
  33253. + return ret;
  33254. +}
  33255. +
  33256. +static int sdhci_bcm2708_remove(struct platform_device *pdev)
  33257. +{
  33258. + struct sdhci_host *host = platform_get_drvdata(pdev);
  33259. + struct resource *iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  33260. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  33261. + int dead;
  33262. + u32 scratch;
  33263. +
  33264. + dead = 0;
  33265. + scratch = sdhci_bcm2708_readl(host, SDHCI_INT_STATUS);
  33266. + if (scratch == (u32)-1)
  33267. + dead = 1;
  33268. +
  33269. + device_remove_file(&pdev->dev, &dev_attr_status);
  33270. + device_remove_file(&pdev->dev, &dev_attr_dma_wait);
  33271. + device_remove_file(&pdev->dev, &dev_attr_use_dma);
  33272. +
  33273. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  33274. + free_irq(host_priv->dma_irq, host);
  33275. + dma_free_writecombine(&pdev->dev, SZ_4K, host_priv->cb_base,
  33276. + host_priv->cb_handle);
  33277. +#endif
  33278. + sdhci_remove_host(host, dead);
  33279. + iounmap(host->ioaddr);
  33280. + release_mem_region(iomem->start, resource_size(iomem));
  33281. + sdhci_free_host(host);
  33282. + platform_set_drvdata(pdev, NULL);
  33283. +
  33284. + return 0;
  33285. +}
  33286. +
  33287. +static struct platform_driver sdhci_bcm2708_driver = {
  33288. + .driver = {
  33289. + .name = DRIVER_NAME,
  33290. + .owner = THIS_MODULE,
  33291. + },
  33292. + .probe = sdhci_bcm2708_probe,
  33293. + .remove = sdhci_bcm2708_remove,
  33294. +
  33295. +#ifdef CONFIG_PM
  33296. + .suspend = sdhci_bcm2708_suspend,
  33297. + .resume = sdhci_bcm2708_resume,
  33298. +#endif
  33299. +
  33300. +};
  33301. +
  33302. +/*****************************************************************************\
  33303. + * *
  33304. + * Driver init/exit *
  33305. + * *
  33306. +\*****************************************************************************/
  33307. +
  33308. +static int __init sdhci_drv_init(void)
  33309. +{
  33310. + return platform_driver_register(&sdhci_bcm2708_driver);
  33311. +}
  33312. +
  33313. +static void __exit sdhci_drv_exit(void)
  33314. +{
  33315. + platform_driver_unregister(&sdhci_bcm2708_driver);
  33316. +}
  33317. +
  33318. +module_init(sdhci_drv_init);
  33319. +module_exit(sdhci_drv_exit);
  33320. +
  33321. +module_param(allow_highspeed, bool, 0444);
  33322. +module_param(emmc_clock_freq, int, 0444);
  33323. +module_param(sync_after_dma, bool, 0444);
  33324. +module_param(missing_status, bool, 0444);
  33325. +module_param(spurious_crc_acmd51, bool, 0444);
  33326. +module_param(enable_llm, bool, 0444);
  33327. +module_param(cycle_delay, int, 0444);
  33328. +module_param(extra_messages, bool, 0444);
  33329. +
  33330. +MODULE_DESCRIPTION("Secure Digital Host Controller Interface platform driver");
  33331. +MODULE_AUTHOR("Broadcom <info@broadcom.com>");
  33332. +MODULE_LICENSE("GPL v2");
  33333. +MODULE_ALIAS("platform:"DRIVER_NAME);
  33334. +
  33335. +MODULE_PARM_DESC(allow_highspeed, "Allow high speed transfers modes");
  33336. +MODULE_PARM_DESC(emmc_clock_freq, "Specify the speed of emmc clock");
  33337. +MODULE_PARM_DESC(sync_after_dma, "Block in driver until dma complete");
  33338. +MODULE_PARM_DESC(missing_status, "Use the missing status quirk");
  33339. +MODULE_PARM_DESC(spurious_crc_acmd51, "Use the spurious crc quirk for reading SCR (ACMD51)");
  33340. +MODULE_PARM_DESC(enable_llm, "Enable low-latency mode");
  33341. +MODULE_PARM_DESC(extra_messages, "Enable more sdcard warning messages");
  33342. +
  33343. +
  33344. diff -Nur linux-3.15.4/drivers/mmc/host/sdhci.c linux-rpi/drivers/mmc/host/sdhci.c
  33345. --- linux-3.15.4/drivers/mmc/host/sdhci.c 2014-07-07 03:59:25.000000000 +0200
  33346. +++ linux-rpi/drivers/mmc/host/sdhci.c 2014-07-07 10:45:11.000000000 +0200
  33347. @@ -28,6 +28,7 @@
  33348. #include <linux/mmc/mmc.h>
  33349. #include <linux/mmc/host.h>
  33350. #include <linux/mmc/card.h>
  33351. +#include <linux/mmc/sd.h>
  33352. #include <linux/mmc/slot-gpio.h>
  33353. #include "sdhci.h"
  33354. @@ -130,6 +131,99 @@
  33355. * Low level functions *
  33356. * *
  33357. \*****************************************************************************/
  33358. +extern bool enable_llm;
  33359. +static int sdhci_locked=0;
  33360. +void sdhci_spin_lock(struct sdhci_host *host)
  33361. +{
  33362. + spin_lock(&host->lock);
  33363. +#ifdef CONFIG_PREEMPT
  33364. + if(enable_llm)
  33365. + {
  33366. + disable_irq_nosync(host->irq);
  33367. + if(host->second_irq)
  33368. + disable_irq_nosync(host->second_irq);
  33369. + local_irq_enable();
  33370. + }
  33371. +#endif
  33372. +}
  33373. +
  33374. +void sdhci_spin_unlock(struct sdhci_host *host)
  33375. +{
  33376. +#ifdef CONFIG_PREEMPT
  33377. + if(enable_llm)
  33378. + {
  33379. + local_irq_disable();
  33380. + if(host->second_irq)
  33381. + enable_irq(host->second_irq);
  33382. + enable_irq(host->irq);
  33383. + }
  33384. +#endif
  33385. + spin_unlock(&host->lock);
  33386. +}
  33387. +
  33388. +void sdhci_spin_lock_irqsave(struct sdhci_host *host,unsigned long *flags)
  33389. +{
  33390. +#ifdef CONFIG_PREEMPT
  33391. + if(enable_llm)
  33392. + {
  33393. + while(sdhci_locked)
  33394. + {
  33395. + preempt_schedule();
  33396. + }
  33397. + spin_lock_irqsave(&host->lock,*flags);
  33398. + disable_irq(host->irq);
  33399. + if(host->second_irq)
  33400. + disable_irq(host->second_irq);
  33401. + local_irq_enable();
  33402. + }
  33403. + else
  33404. +#endif
  33405. + spin_lock_irqsave(&host->lock,*flags);
  33406. +}
  33407. +
  33408. +void sdhci_spin_unlock_irqrestore(struct sdhci_host *host,unsigned long flags)
  33409. +{
  33410. +#ifdef CONFIG_PREEMPT
  33411. + if(enable_llm)
  33412. + {
  33413. + local_irq_disable();
  33414. + if(host->second_irq)
  33415. + enable_irq(host->second_irq);
  33416. + enable_irq(host->irq);
  33417. + }
  33418. +#endif
  33419. + spin_unlock_irqrestore(&host->lock,flags);
  33420. +}
  33421. +
  33422. +static void sdhci_spin_enable_schedule(struct sdhci_host *host)
  33423. +{
  33424. +#ifdef CONFIG_PREEMPT
  33425. + if(enable_llm)
  33426. + {
  33427. + sdhci_locked = 1;
  33428. + preempt_enable();
  33429. + }
  33430. +#endif
  33431. +}
  33432. +
  33433. +static void sdhci_spin_disable_schedule(struct sdhci_host *host)
  33434. +{
  33435. +#ifdef CONFIG_PREEMPT
  33436. + if(enable_llm)
  33437. + {
  33438. + preempt_disable();
  33439. + sdhci_locked = 0;
  33440. + }
  33441. +#endif
  33442. +}
  33443. +
  33444. +
  33445. +#undef spin_lock_irqsave
  33446. +#define spin_lock_irqsave(host_lock, flags) sdhci_spin_lock_irqsave(container_of(host_lock, struct sdhci_host, lock), &flags)
  33447. +#define spin_unlock_irqrestore(host_lock, flags) sdhci_spin_unlock_irqrestore(container_of(host_lock, struct sdhci_host, lock), flags)
  33448. +
  33449. +#define spin_lock(host_lock) sdhci_spin_lock(container_of(host_lock, struct sdhci_host, lock))
  33450. +#define spin_unlock(host_lock) sdhci_spin_unlock(container_of(host_lock, struct sdhci_host, lock))
  33451. static void sdhci_clear_set_irqs(struct sdhci_host *host, u32 clear, u32 set)
  33452. {
  33453. @@ -299,7 +393,7 @@
  33454. struct sdhci_host *host = container_of(led, struct sdhci_host, led);
  33455. unsigned long flags;
  33456. - spin_lock_irqsave(&host->lock, flags);
  33457. + sdhci_spin_lock_irqsave(host, &flags);
  33458. if (host->runtime_suspended)
  33459. goto out;
  33460. @@ -309,7 +403,7 @@
  33461. else
  33462. sdhci_activate_led(host);
  33463. out:
  33464. - spin_unlock_irqrestore(&host->lock, flags);
  33465. + sdhci_spin_unlock_irqrestore(host, flags);
  33466. }
  33467. #endif
  33468. @@ -326,7 +420,7 @@
  33469. u32 uninitialized_var(scratch);
  33470. u8 *buf;
  33471. - DBG("PIO reading\n");
  33472. + DBG("PIO reading %db\n", host->data->blksz);
  33473. blksize = host->data->blksz;
  33474. chunk = 0;
  33475. @@ -371,7 +465,7 @@
  33476. u32 scratch;
  33477. u8 *buf;
  33478. - DBG("PIO writing\n");
  33479. + DBG("PIO writing %db\n", host->data->blksz);
  33480. blksize = host->data->blksz;
  33481. chunk = 0;
  33482. @@ -410,19 +504,28 @@
  33483. local_irq_restore(flags);
  33484. }
  33485. -static void sdhci_transfer_pio(struct sdhci_host *host)
  33486. +static void sdhci_transfer_pio(struct sdhci_host *host, u32 intstate)
  33487. {
  33488. u32 mask;
  33489. + u32 state = 0;
  33490. + u32 intmask;
  33491. + int available;
  33492. BUG_ON(!host->data);
  33493. if (host->blocks == 0)
  33494. return;
  33495. - if (host->data->flags & MMC_DATA_READ)
  33496. + if (host->data->flags & MMC_DATA_READ) {
  33497. mask = SDHCI_DATA_AVAILABLE;
  33498. - else
  33499. + intmask = SDHCI_INT_DATA_AVAIL;
  33500. + } else {
  33501. mask = SDHCI_SPACE_AVAILABLE;
  33502. + intmask = SDHCI_INT_SPACE_AVAIL;
  33503. + }
  33504. +
  33505. + /* initially we can see whether we can procede using intstate */
  33506. + available = (intstate & intmask);
  33507. /*
  33508. * Some controllers (JMicron JMB38x) mess up the buffer bits
  33509. @@ -433,7 +536,7 @@
  33510. (host->data->blocks == 1))
  33511. mask = ~0;
  33512. - while (sdhci_readl(host, SDHCI_PRESENT_STATE) & mask) {
  33513. + while (available) {
  33514. if (host->quirks & SDHCI_QUIRK_PIO_NEEDS_DELAY)
  33515. udelay(100);
  33516. @@ -445,9 +548,12 @@
  33517. host->blocks--;
  33518. if (host->blocks == 0)
  33519. break;
  33520. + state = sdhci_readl(host, SDHCI_PRESENT_STATE);
  33521. + available = state & mask;
  33522. + break;
  33523. }
  33524. - DBG("PIO transfer complete.\n");
  33525. + DBG("PIO transfer complete - %d blocks left.\n", host->blocks);
  33526. }
  33527. static char *sdhci_kmap_atomic(struct scatterlist *sg, unsigned long *flags)
  33528. @@ -720,7 +826,9 @@
  33529. u32 pio_irqs = SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL;
  33530. u32 dma_irqs = SDHCI_INT_DMA_END | SDHCI_INT_ADMA_ERROR;
  33531. - if (host->flags & SDHCI_REQ_USE_DMA)
  33532. + /* platform DMA will begin on receipt of PIO irqs */
  33533. + if ((host->flags & SDHCI_REQ_USE_DMA) &&
  33534. + !(host->flags & SDHCI_USE_PLATDMA))
  33535. sdhci_clear_set_irqs(host, pio_irqs, dma_irqs);
  33536. else
  33537. sdhci_clear_set_irqs(host, dma_irqs, pio_irqs);
  33538. @@ -752,44 +860,25 @@
  33539. host->data_early = 0;
  33540. host->data->bytes_xfered = 0;
  33541. - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA))
  33542. + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA | SDHCI_USE_PLATDMA))
  33543. host->flags |= SDHCI_REQ_USE_DMA;
  33544. /*
  33545. * FIXME: This doesn't account for merging when mapping the
  33546. * scatterlist.
  33547. */
  33548. - if (host->flags & SDHCI_REQ_USE_DMA) {
  33549. - int broken, i;
  33550. - struct scatterlist *sg;
  33551. -
  33552. - broken = 0;
  33553. - if (host->flags & SDHCI_USE_ADMA) {
  33554. - if (host->quirks & SDHCI_QUIRK_32BIT_ADMA_SIZE)
  33555. - broken = 1;
  33556. - } else {
  33557. - if (host->quirks & SDHCI_QUIRK_32BIT_DMA_SIZE)
  33558. - broken = 1;
  33559. - }
  33560. -
  33561. - if (unlikely(broken)) {
  33562. - for_each_sg(data->sg, sg, data->sg_len, i) {
  33563. - if (sg->length & 0x3) {
  33564. - DBG("Reverting to PIO because of "
  33565. - "transfer size (%d)\n",
  33566. - sg->length);
  33567. - host->flags &= ~SDHCI_REQ_USE_DMA;
  33568. - break;
  33569. - }
  33570. - }
  33571. - }
  33572. - }
  33573. /*
  33574. * The assumption here being that alignment is the same after
  33575. * translation to device address space.
  33576. */
  33577. - if (host->flags & SDHCI_REQ_USE_DMA) {
  33578. + if ((host->flags & (SDHCI_REQ_USE_DMA | SDHCI_USE_PLATDMA)) ==
  33579. + (SDHCI_REQ_USE_DMA | SDHCI_USE_PLATDMA)) {
  33580. +
  33581. + if (! sdhci_platdma_dmaable(host, data))
  33582. + host->flags &= ~SDHCI_REQ_USE_DMA;
  33583. +
  33584. + } else if (host->flags & SDHCI_REQ_USE_DMA) {
  33585. int broken, i;
  33586. struct scatterlist *sg;
  33587. @@ -848,7 +937,8 @@
  33588. */
  33589. WARN_ON(1);
  33590. host->flags &= ~SDHCI_REQ_USE_DMA;
  33591. - } else {
  33592. + } else
  33593. + if (!(host->flags & SDHCI_USE_PLATDMA)) {
  33594. WARN_ON(sg_cnt != 1);
  33595. sdhci_writel(host, sg_dma_address(data->sg),
  33596. SDHCI_DMA_ADDRESS);
  33597. @@ -864,11 +954,13 @@
  33598. if (host->version >= SDHCI_SPEC_200) {
  33599. ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
  33600. ctrl &= ~SDHCI_CTRL_DMA_MASK;
  33601. + if (! (host->flags & SDHCI_USE_PLATDMA)) {
  33602. if ((host->flags & SDHCI_REQ_USE_DMA) &&
  33603. (host->flags & SDHCI_USE_ADMA))
  33604. ctrl |= SDHCI_CTRL_ADMA32;
  33605. else
  33606. ctrl |= SDHCI_CTRL_SDMA;
  33607. + }
  33608. sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
  33609. }
  33610. @@ -925,7 +1017,8 @@
  33611. if (data->flags & MMC_DATA_READ)
  33612. mode |= SDHCI_TRNS_READ;
  33613. - if (host->flags & SDHCI_REQ_USE_DMA)
  33614. + if ((host->flags & SDHCI_REQ_USE_DMA) &&
  33615. + !(host->flags & SDHCI_USE_PLATDMA))
  33616. mode |= SDHCI_TRNS_DMA;
  33617. sdhci_writew(host, mode, SDHCI_TRANSFER_MODE);
  33618. @@ -941,13 +1034,16 @@
  33619. host->data = NULL;
  33620. if (host->flags & SDHCI_REQ_USE_DMA) {
  33621. - if (host->flags & SDHCI_USE_ADMA)
  33622. - sdhci_adma_table_post(host, data);
  33623. - else {
  33624. + /* we may have to abandon an ongoing platform DMA */
  33625. + if (host->flags & SDHCI_USE_PLATDMA)
  33626. + sdhci_platdma_reset(host, data);
  33627. +
  33628. + if (host->flags & (SDHCI_USE_PLATDMA | SDHCI_USE_SDMA)) {
  33629. dma_unmap_sg(mmc_dev(host->mmc), data->sg,
  33630. data->sg_len, (data->flags & MMC_DATA_READ) ?
  33631. DMA_FROM_DEVICE : DMA_TO_DEVICE);
  33632. - }
  33633. + } else if (host->flags & SDHCI_USE_ADMA)
  33634. + sdhci_adma_table_post(host, data);
  33635. }
  33636. /*
  33637. @@ -1000,6 +1096,12 @@
  33638. if ((cmd->data != NULL) || (cmd->flags & MMC_RSP_BUSY))
  33639. mask |= SDHCI_DATA_INHIBIT;
  33640. + if(host->ops->missing_status && (cmd->opcode == MMC_SEND_STATUS)) {
  33641. + timeout = 5000; // Really obscenely large delay to send the status, due to bug in controller
  33642. + // which might cause the STATUS command to get stuck when a data operation is in flow
  33643. + mask |= SDHCI_DATA_INHIBIT;
  33644. + }
  33645. +
  33646. /* We shouldn't wait for data inihibit for stop commands, even
  33647. though they might use busy signaling */
  33648. if (host->mrq->data && (cmd == host->mrq->data->stop))
  33649. @@ -1015,8 +1117,12 @@
  33650. return;
  33651. }
  33652. timeout--;
  33653. + sdhci_spin_enable_schedule(host);
  33654. mdelay(1);
  33655. + sdhci_spin_disable_schedule(host);
  33656. }
  33657. + DBG("send cmd %d - wait 0x%X irq 0x%x\n", cmd->opcode, mask,
  33658. + sdhci_readl(host, SDHCI_INT_STATUS));
  33659. timeout = jiffies;
  33660. if (!cmd->data && cmd->busy_timeout > 9000)
  33661. @@ -1026,6 +1132,10 @@
  33662. mod_timer(&host->timer, timeout);
  33663. host->cmd = cmd;
  33664. + if (host->last_cmdop == MMC_APP_CMD)
  33665. + host->last_cmdop = -cmd->opcode;
  33666. + else
  33667. + host->last_cmdop = cmd->opcode;
  33668. sdhci_prepare_data(host, cmd);
  33669. @@ -1242,7 +1352,9 @@
  33670. return;
  33671. }
  33672. timeout--;
  33673. + sdhci_spin_enable_schedule(host);
  33674. mdelay(1);
  33675. + sdhci_spin_disable_schedule(host);
  33676. }
  33677. clk |= SDHCI_CLOCK_CARD_EN;
  33678. @@ -1343,7 +1455,7 @@
  33679. sdhci_runtime_pm_get(host);
  33680. - spin_lock_irqsave(&host->lock, flags);
  33681. + sdhci_spin_lock_irqsave(host, &flags);
  33682. WARN_ON(host->mrq != NULL);
  33683. @@ -1408,9 +1520,9 @@
  33684. */
  33685. host->mrq = NULL;
  33686. - spin_unlock_irqrestore(&host->lock, flags);
  33687. + sdhci_spin_unlock_irqrestore(host, flags);
  33688. sdhci_execute_tuning(mmc, tuning_opcode);
  33689. - spin_lock_irqsave(&host->lock, flags);
  33690. + sdhci_spin_lock_irqsave(host, &flags);
  33691. /* Restore original mmc_request structure */
  33692. host->mrq = mrq;
  33693. @@ -1424,7 +1536,7 @@
  33694. }
  33695. mmiowb();
  33696. - spin_unlock_irqrestore(&host->lock, flags);
  33697. + sdhci_spin_unlock_irqrestore(host, flags);
  33698. }
  33699. static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios)
  33700. @@ -1433,10 +1545,10 @@
  33701. int vdd_bit = -1;
  33702. u8 ctrl;
  33703. - spin_lock_irqsave(&host->lock, flags);
  33704. + sdhci_spin_lock_irqsave(host, &flags);
  33705. if (host->flags & SDHCI_DEVICE_DEAD) {
  33706. - spin_unlock_irqrestore(&host->lock, flags);
  33707. + sdhci_spin_unlock_irqrestore(host, flags);
  33708. if (host->vmmc && ios->power_mode == MMC_POWER_OFF)
  33709. mmc_regulator_set_ocr(host->mmc, host->vmmc, 0);
  33710. return;
  33711. @@ -1464,9 +1576,9 @@
  33712. vdd_bit = sdhci_set_power(host, ios->vdd);
  33713. if (host->vmmc && vdd_bit != -1) {
  33714. - spin_unlock_irqrestore(&host->lock, flags);
  33715. + sdhci_spin_unlock_irqrestore(host, flags);
  33716. mmc_regulator_set_ocr(host->mmc, host->vmmc, vdd_bit);
  33717. - spin_lock_irqsave(&host->lock, flags);
  33718. + sdhci_spin_lock_irqsave(host, &flags);
  33719. }
  33720. if (host->ops->platform_send_init_74_clocks)
  33721. @@ -1603,7 +1715,7 @@
  33722. sdhci_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA);
  33723. mmiowb();
  33724. - spin_unlock_irqrestore(&host->lock, flags);
  33725. + sdhci_spin_unlock_irqrestore(host, flags);
  33726. }
  33727. static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  33728. @@ -1651,7 +1763,7 @@
  33729. unsigned long flags;
  33730. int is_readonly;
  33731. - spin_lock_irqsave(&host->lock, flags);
  33732. + sdhci_spin_lock_irqsave(host, &flags);
  33733. if (host->flags & SDHCI_DEVICE_DEAD)
  33734. is_readonly = 0;
  33735. @@ -1661,7 +1773,7 @@
  33736. is_readonly = !(sdhci_readl(host, SDHCI_PRESENT_STATE)
  33737. & SDHCI_WRITE_PROTECT);
  33738. - spin_unlock_irqrestore(&host->lock, flags);
  33739. + sdhci_spin_unlock_irqrestore(host, flags);
  33740. /* This quirk needs to be replaced by a callback-function later */
  33741. return host->quirks & SDHCI_QUIRK_INVERTED_WRITE_PROTECT ?
  33742. @@ -1734,9 +1846,9 @@
  33743. struct sdhci_host *host = mmc_priv(mmc);
  33744. unsigned long flags;
  33745. - spin_lock_irqsave(&host->lock, flags);
  33746. + sdhci_spin_lock_irqsave(host, &flags);
  33747. sdhci_enable_sdio_irq_nolock(host, enable);
  33748. - spin_unlock_irqrestore(&host->lock, flags);
  33749. + sdhci_spin_unlock_irqrestore(host, flags);
  33750. }
  33751. static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host,
  33752. @@ -2086,7 +2198,7 @@
  33753. if (host->ops->card_event)
  33754. host->ops->card_event(host);
  33755. - spin_lock_irqsave(&host->lock, flags);
  33756. + sdhci_spin_lock_irqsave(host, &flags);
  33757. /* Check host->mrq first in case we are runtime suspended */
  33758. if (host->mrq && !sdhci_do_get_cd(host)) {
  33759. @@ -2102,7 +2214,7 @@
  33760. tasklet_schedule(&host->finish_tasklet);
  33761. }
  33762. - spin_unlock_irqrestore(&host->lock, flags);
  33763. + sdhci_spin_unlock_irqrestore(host, flags);
  33764. }
  33765. static const struct mmc_host_ops sdhci_ops = {
  33766. @@ -2141,14 +2253,14 @@
  33767. host = (struct sdhci_host*)param;
  33768. - spin_lock_irqsave(&host->lock, flags);
  33769. + sdhci_spin_lock_irqsave(host, &flags);
  33770. /*
  33771. * If this tasklet gets rescheduled while running, it will
  33772. * be run again afterwards but without any active request.
  33773. */
  33774. if (!host->mrq) {
  33775. - spin_unlock_irqrestore(&host->lock, flags);
  33776. + sdhci_spin_unlock_irqrestore(host, flags);
  33777. return;
  33778. }
  33779. @@ -2186,7 +2298,7 @@
  33780. #endif
  33781. mmiowb();
  33782. - spin_unlock_irqrestore(&host->lock, flags);
  33783. + sdhci_spin_unlock_irqrestore(host, flags);
  33784. mmc_request_done(host->mmc, mrq);
  33785. sdhci_runtime_pm_put(host);
  33786. @@ -2199,11 +2311,11 @@
  33787. host = (struct sdhci_host*)data;
  33788. - spin_lock_irqsave(&host->lock, flags);
  33789. + sdhci_spin_lock_irqsave(host, &flags);
  33790. if (host->mrq) {
  33791. pr_err("%s: Timeout waiting for hardware "
  33792. - "interrupt.\n", mmc_hostname(host->mmc));
  33793. + "interrupt - cmd%d.\n", mmc_hostname(host->mmc), host->last_cmdop);
  33794. sdhci_dumpregs(host);
  33795. if (host->data) {
  33796. @@ -2220,7 +2332,7 @@
  33797. }
  33798. mmiowb();
  33799. - spin_unlock_irqrestore(&host->lock, flags);
  33800. + sdhci_spin_unlock_irqrestore(host, flags);
  33801. }
  33802. static void sdhci_tuning_timer(unsigned long data)
  33803. @@ -2230,11 +2342,11 @@
  33804. host = (struct sdhci_host *)data;
  33805. - spin_lock_irqsave(&host->lock, flags);
  33806. + sdhci_spin_lock_irqsave(host, &flags);
  33807. host->flags |= SDHCI_NEEDS_RETUNING;
  33808. - spin_unlock_irqrestore(&host->lock, flags);
  33809. + sdhci_spin_unlock_irqrestore(host, flags);
  33810. }
  33811. /*****************************************************************************\
  33812. @@ -2248,10 +2360,13 @@
  33813. BUG_ON(intmask == 0);
  33814. if (!host->cmd) {
  33815. + if (!(host->ops->extra_ints)) {
  33816. pr_err("%s: Got command interrupt 0x%08x even "
  33817. "though no command operation was in progress.\n",
  33818. mmc_hostname(host->mmc), (unsigned)intmask);
  33819. sdhci_dumpregs(host);
  33820. + } else
  33821. + DBG("cmd irq 0x%08x cmd complete\n", (unsigned)intmask);
  33822. return;
  33823. }
  33824. @@ -2321,6 +2436,19 @@
  33825. static void sdhci_show_adma_error(struct sdhci_host *host) { }
  33826. #endif
  33827. +static void sdhci_data_end(struct sdhci_host *host)
  33828. +{
  33829. + if (host->cmd) {
  33830. + /*
  33831. + * Data managed to finish before the
  33832. + * command completed. Make sure we do
  33833. + * things in the proper order.
  33834. + */
  33835. + host->data_early = 1;
  33836. + } else
  33837. + sdhci_finish_data(host);
  33838. +}
  33839. +
  33840. static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
  33841. {
  33842. u32 command;
  33843. @@ -2350,23 +2478,39 @@
  33844. }
  33845. }
  33846. + if (!(host->ops->extra_ints)) {
  33847. pr_err("%s: Got data interrupt 0x%08x even "
  33848. "though no data operation was in progress.\n",
  33849. mmc_hostname(host->mmc), (unsigned)intmask);
  33850. sdhci_dumpregs(host);
  33851. + } else
  33852. + DBG("data irq 0x%08x but no data\n", (unsigned)intmask);
  33853. return;
  33854. }
  33855. if (intmask & SDHCI_INT_DATA_TIMEOUT)
  33856. host->data->error = -ETIMEDOUT;
  33857. - else if (intmask & SDHCI_INT_DATA_END_BIT)
  33858. + else if (intmask & SDHCI_INT_DATA_END_BIT) {
  33859. + DBG("end error in cmd %d\n", host->last_cmdop);
  33860. + if (host->ops->spurious_crc_acmd51 &&
  33861. + host->last_cmdop == -SD_APP_SEND_SCR) {
  33862. + DBG("ignoring spurious data_end_bit error\n");
  33863. + intmask = SDHCI_INT_DATA_AVAIL|SDHCI_INT_DATA_END;
  33864. + } else
  33865. host->data->error = -EILSEQ;
  33866. - else if ((intmask & SDHCI_INT_DATA_CRC) &&
  33867. + } else if ((intmask & SDHCI_INT_DATA_CRC) &&
  33868. SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND))
  33869. - != MMC_BUS_TEST_R)
  33870. + != MMC_BUS_TEST_R) {
  33871. + DBG("crc error in cmd %d\n", host->last_cmdop);
  33872. + if (host->ops->spurious_crc_acmd51 &&
  33873. + host->last_cmdop == -SD_APP_SEND_SCR) {
  33874. + DBG("ignoring spurious data_crc_bit error\n");
  33875. + intmask = SDHCI_INT_DATA_AVAIL|SDHCI_INT_DATA_END;
  33876. + } else {
  33877. host->data->error = -EILSEQ;
  33878. - else if (intmask & SDHCI_INT_ADMA_ERROR) {
  33879. + }
  33880. + } else if (intmask & SDHCI_INT_ADMA_ERROR) {
  33881. pr_err("%s: ADMA error\n", mmc_hostname(host->mmc));
  33882. sdhci_show_adma_error(host);
  33883. host->data->error = -EIO;
  33884. @@ -2374,11 +2518,18 @@
  33885. host->ops->adma_workaround(host, intmask);
  33886. }
  33887. - if (host->data->error)
  33888. + if (host->data->error) {
  33889. + DBG("finish request early on error %d\n", host->data->error);
  33890. sdhci_finish_data(host);
  33891. - else {
  33892. - if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL))
  33893. - sdhci_transfer_pio(host);
  33894. + } else {
  33895. + if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL)) {
  33896. + if (host->flags & SDHCI_REQ_USE_DMA) {
  33897. + /* possible only in PLATDMA mode */
  33898. + sdhci_platdma_avail(host, &intmask,
  33899. + &sdhci_data_end);
  33900. + } else
  33901. + sdhci_transfer_pio(host, intmask);
  33902. + }
  33903. /*
  33904. * We currently don't do anything fancy with DMA
  33905. @@ -2407,18 +2558,8 @@
  33906. sdhci_writel(host, dmanow, SDHCI_DMA_ADDRESS);
  33907. }
  33908. - if (intmask & SDHCI_INT_DATA_END) {
  33909. - if (host->cmd) {
  33910. - /*
  33911. - * Data managed to finish before the
  33912. - * command completed. Make sure we do
  33913. - * things in the proper order.
  33914. - */
  33915. - host->data_early = 1;
  33916. - } else {
  33917. - sdhci_finish_data(host);
  33918. - }
  33919. - }
  33920. + if (intmask & SDHCI_INT_DATA_END)
  33921. + sdhci_data_end(host);
  33922. }
  33923. }
  33924. @@ -2429,10 +2570,10 @@
  33925. u32 intmask, unexpected = 0;
  33926. int cardint = 0, max_loops = 16;
  33927. - spin_lock(&host->lock);
  33928. + sdhci_spin_lock(host);
  33929. if (host->runtime_suspended) {
  33930. - spin_unlock(&host->lock);
  33931. + sdhci_spin_unlock(host);
  33932. return IRQ_NONE;
  33933. }
  33934. @@ -2472,6 +2613,22 @@
  33935. tasklet_schedule(&host->card_tasklet);
  33936. }
  33937. + if (intmask & SDHCI_INT_ERROR_MASK & ~SDHCI_INT_ERROR)
  33938. + DBG("controller reports error 0x%x -"
  33939. + "%s%s%s%s%s%s%s%s%s%s",
  33940. + intmask,
  33941. + intmask & SDHCI_INT_TIMEOUT? " timeout": "",
  33942. + intmask & SDHCI_INT_CRC ? " crc": "",
  33943. + intmask & SDHCI_INT_END_BIT? " endbit": "",
  33944. + intmask & SDHCI_INT_INDEX? " index": "",
  33945. + intmask & SDHCI_INT_DATA_TIMEOUT? " data_timeout": "",
  33946. + intmask & SDHCI_INT_DATA_CRC? " data_crc": "",
  33947. + intmask & SDHCI_INT_DATA_END_BIT? " data_endbit": "",
  33948. + intmask & SDHCI_INT_BUS_POWER? " buspower": "",
  33949. + intmask & SDHCI_INT_ACMD12ERR? " acmd12": "",
  33950. + intmask & SDHCI_INT_ADMA_ERROR? " adma": ""
  33951. + );
  33952. +
  33953. if (intmask & SDHCI_INT_CMD_MASK) {
  33954. sdhci_writel(host, intmask & SDHCI_INT_CMD_MASK,
  33955. SDHCI_INT_STATUS);
  33956. @@ -2486,7 +2643,13 @@
  33957. intmask &= ~(SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK);
  33958. - intmask &= ~SDHCI_INT_ERROR;
  33959. + if (intmask & SDHCI_INT_ERROR_MASK) {
  33960. + /* collect any uncovered errors */
  33961. + sdhci_writel(host, intmask & SDHCI_INT_ERROR_MASK,
  33962. + SDHCI_INT_STATUS);
  33963. + }
  33964. +
  33965. + intmask &= ~SDHCI_INT_ERROR_MASK;
  33966. if (intmask & SDHCI_INT_BUS_POWER) {
  33967. pr_err("%s: Card is consuming too much power!\n",
  33968. @@ -2520,7 +2683,7 @@
  33969. if (intmask && --max_loops)
  33970. goto again;
  33971. out:
  33972. - spin_unlock(&host->lock);
  33973. + sdhci_spin_unlock(host);
  33974. if (unexpected) {
  33975. pr_err("%s: Unexpected interrupt 0x%08x.\n",
  33976. @@ -2599,13 +2762,14 @@
  33977. {
  33978. int ret = 0;
  33979. - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
  33980. + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA |
  33981. + SDHCI_USE_PLATDMA)) {
  33982. if (host->ops->enable_dma)
  33983. host->ops->enable_dma(host);
  33984. }
  33985. if (!device_may_wakeup(mmc_dev(host->mmc))) {
  33986. - ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED,
  33987. + ret = request_irq(host->irq, sdhci_irq, 0 /*IRQF_SHARED*/,
  33988. mmc_hostname(host->mmc), host);
  33989. if (ret)
  33990. return ret;
  33991. @@ -2681,15 +2845,15 @@
  33992. host->flags &= ~SDHCI_NEEDS_RETUNING;
  33993. }
  33994. - spin_lock_irqsave(&host->lock, flags);
  33995. + sdhci_spin_lock_irqsave(host, &flags);
  33996. sdhci_mask_irqs(host, SDHCI_INT_ALL_MASK);
  33997. - spin_unlock_irqrestore(&host->lock, flags);
  33998. + sdhci_spin_unlock_irqrestore(host, flags);
  33999. synchronize_irq(host->irq);
  34000. - spin_lock_irqsave(&host->lock, flags);
  34001. + sdhci_spin_lock_irqsave(host, &flags);
  34002. host->runtime_suspended = true;
  34003. - spin_unlock_irqrestore(&host->lock, flags);
  34004. + sdhci_spin_unlock_irqrestore(host, flags);
  34005. return ret;
  34006. }
  34007. @@ -2715,16 +2879,16 @@
  34008. sdhci_do_start_signal_voltage_switch(host, &host->mmc->ios);
  34009. if ((host_flags & SDHCI_PV_ENABLED) &&
  34010. !(host->quirks2 & SDHCI_QUIRK2_PRESET_VALUE_BROKEN)) {
  34011. - spin_lock_irqsave(&host->lock, flags);
  34012. + sdhci_spin_lock_irqsave(host, &flags);
  34013. sdhci_enable_preset_value(host, true);
  34014. - spin_unlock_irqrestore(&host->lock, flags);
  34015. + sdhci_spin_unlock_irqrestore(host, flags);
  34016. }
  34017. /* Set the re-tuning expiration flag */
  34018. if (host->flags & SDHCI_USING_RETUNING_TIMER)
  34019. host->flags |= SDHCI_NEEDS_RETUNING;
  34020. - spin_lock_irqsave(&host->lock, flags);
  34021. + sdhci_spin_lock_irqsave(host, &flags);
  34022. host->runtime_suspended = false;
  34023. @@ -2735,7 +2899,7 @@
  34024. /* Enable Card Detection */
  34025. sdhci_enable_card_detection(host);
  34026. - spin_unlock_irqrestore(&host->lock, flags);
  34027. + sdhci_spin_unlock_irqrestore(host, flags);
  34028. return ret;
  34029. }
  34030. @@ -2830,14 +2994,16 @@
  34031. host->flags &= ~SDHCI_USE_ADMA;
  34032. }
  34033. - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
  34034. + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA |
  34035. + SDHCI_USE_PLATDMA)) {
  34036. if (host->ops->enable_dma) {
  34037. if (host->ops->enable_dma(host)) {
  34038. pr_warning("%s: No suitable DMA "
  34039. "available. Falling back to PIO.\n",
  34040. mmc_hostname(mmc));
  34041. host->flags &=
  34042. - ~(SDHCI_USE_SDMA | SDHCI_USE_ADMA);
  34043. + ~(SDHCI_USE_SDMA | SDHCI_USE_ADMA |
  34044. + SDHCI_USE_PLATDMA);
  34045. }
  34046. }
  34047. }
  34048. @@ -3230,8 +3396,8 @@
  34049. sdhci_init(host, 0);
  34050. - ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED,
  34051. - mmc_hostname(mmc), host);
  34052. + ret = request_irq(host->irq, sdhci_irq, 0 /*IRQF_SHARED*/,
  34053. + mmc_hostname(mmc), host);
  34054. if (ret) {
  34055. pr_err("%s: Failed to request IRQ %d: %d\n",
  34056. mmc_hostname(mmc), host->irq, ret);
  34057. @@ -3264,6 +3430,7 @@
  34058. pr_info("%s: SDHCI controller on %s [%s] using %s\n",
  34059. mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)),
  34060. + (host->flags & SDHCI_USE_PLATDMA) ? "platform's DMA" :
  34061. (host->flags & SDHCI_USE_ADMA) ? "ADMA" :
  34062. (host->flags & SDHCI_USE_SDMA) ? "DMA" : "PIO");
  34063. @@ -3291,7 +3458,7 @@
  34064. unsigned long flags;
  34065. if (dead) {
  34066. - spin_lock_irqsave(&host->lock, flags);
  34067. + sdhci_spin_lock_irqsave(host, &flags);
  34068. host->flags |= SDHCI_DEVICE_DEAD;
  34069. @@ -3303,7 +3470,7 @@
  34070. tasklet_schedule(&host->finish_tasklet);
  34071. }
  34072. - spin_unlock_irqrestore(&host->lock, flags);
  34073. + sdhci_spin_unlock_irqrestore(host, flags);
  34074. }
  34075. sdhci_disable_card_detection(host);
  34076. diff -Nur linux-3.15.4/drivers/mmc/host/sdhci.h linux-rpi/drivers/mmc/host/sdhci.h
  34077. --- linux-3.15.4/drivers/mmc/host/sdhci.h 2014-07-07 03:59:25.000000000 +0200
  34078. +++ linux-rpi/drivers/mmc/host/sdhci.h 2014-07-07 10:45:11.000000000 +0200
  34079. @@ -290,6 +290,18 @@
  34080. void (*platform_reset_exit)(struct sdhci_host *host, u8 mask);
  34081. int (*platform_execute_tuning)(struct sdhci_host *host, u32 opcode);
  34082. int (*set_uhs_signaling)(struct sdhci_host *host, unsigned int uhs);
  34083. +
  34084. + int (*pdma_able)(struct sdhci_host *host,
  34085. + struct mmc_data *data);
  34086. + void (*pdma_avail)(struct sdhci_host *host,
  34087. + unsigned int *ref_intmask,
  34088. + void(*complete)(struct sdhci_host *));
  34089. + void (*pdma_reset)(struct sdhci_host *host,
  34090. + struct mmc_data *data);
  34091. + unsigned int (*extra_ints)(struct sdhci_host *host);
  34092. + unsigned int (*spurious_crc_acmd51)(struct sdhci_host *host);
  34093. + unsigned int (*missing_status)(struct sdhci_host *host);
  34094. +
  34095. void (*hw_reset)(struct sdhci_host *host);
  34096. void (*platform_suspend)(struct sdhci_host *host);
  34097. void (*platform_resume)(struct sdhci_host *host);
  34098. @@ -403,9 +415,38 @@
  34099. extern void sdhci_enable_irq_wakeups(struct sdhci_host *host);
  34100. #endif
  34101. +static inline int /*bool*/
  34102. +sdhci_platdma_dmaable(struct sdhci_host *host, struct mmc_data *data)
  34103. +{
  34104. + if (host->ops->pdma_able)
  34105. + return host->ops->pdma_able(host, data);
  34106. + else
  34107. + return 1;
  34108. +}
  34109. +static inline void
  34110. +sdhci_platdma_avail(struct sdhci_host *host, unsigned int *ref_intmask,
  34111. + void(*completion_callback)(struct sdhci_host *))
  34112. +{
  34113. + if (host->ops->pdma_avail)
  34114. + host->ops->pdma_avail(host, ref_intmask, completion_callback);
  34115. +}
  34116. +
  34117. +static inline void
  34118. +sdhci_platdma_reset(struct sdhci_host *host, struct mmc_data *data)
  34119. +{
  34120. + if (host->ops->pdma_reset)
  34121. + host->ops->pdma_reset(host, data);
  34122. +}
  34123. +
  34124. #ifdef CONFIG_PM_RUNTIME
  34125. extern int sdhci_runtime_suspend_host(struct sdhci_host *host);
  34126. extern int sdhci_runtime_resume_host(struct sdhci_host *host);
  34127. #endif
  34128. +extern void sdhci_spin_lock_irqsave(struct sdhci_host *host,unsigned long *flags);
  34129. +extern void sdhci_spin_unlock_irqrestore(struct sdhci_host *host,unsigned long flags);
  34130. +extern void sdhci_spin_lock(struct sdhci_host *host);
  34131. +extern void sdhci_spin_unlock(struct sdhci_host *host);
  34132. +
  34133. +
  34134. #endif /* __SDHCI_HW_H */
  34135. diff -Nur linux-3.15.4/drivers/net/usb/smsc95xx.c linux-rpi/drivers/net/usb/smsc95xx.c
  34136. --- linux-3.15.4/drivers/net/usb/smsc95xx.c 2014-07-07 03:59:25.000000000 +0200
  34137. +++ linux-rpi/drivers/net/usb/smsc95xx.c 2014-07-07 10:45:25.000000000 +0200
  34138. @@ -59,6 +59,7 @@
  34139. #define SUSPEND_SUSPEND3 (0x08)
  34140. #define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \
  34141. SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3)
  34142. +#define MAC_ADDR_LEN (6)
  34143. struct smsc95xx_priv {
  34144. u32 mac_cr;
  34145. @@ -74,6 +75,10 @@
  34146. module_param(turbo_mode, bool, 0644);
  34147. MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction");
  34148. +static char *macaddr = ":";
  34149. +module_param(macaddr, charp, 0);
  34150. +MODULE_PARM_DESC(macaddr, "MAC address");
  34151. +
  34152. static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index,
  34153. u32 *data, int in_pm)
  34154. {
  34155. @@ -763,8 +768,59 @@
  34156. return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
  34157. }
  34158. +/* Check the macaddr module parameter for a MAC address */
  34159. +static int smsc95xx_is_macaddr_param(struct usbnet *dev, u8 *dev_mac)
  34160. +{
  34161. + int i, j, got_num, num;
  34162. + u8 mtbl[MAC_ADDR_LEN];
  34163. +
  34164. + if (macaddr[0] == ':')
  34165. + return 0;
  34166. +
  34167. + i = 0;
  34168. + j = 0;
  34169. + num = 0;
  34170. + got_num = 0;
  34171. + while (j < MAC_ADDR_LEN) {
  34172. + if (macaddr[i] && macaddr[i] != ':') {
  34173. + got_num++;
  34174. + if ('0' <= macaddr[i] && macaddr[i] <= '9')
  34175. + num = num * 16 + macaddr[i] - '0';
  34176. + else if ('A' <= macaddr[i] && macaddr[i] <= 'F')
  34177. + num = num * 16 + 10 + macaddr[i] - 'A';
  34178. + else if ('a' <= macaddr[i] && macaddr[i] <= 'f')
  34179. + num = num * 16 + 10 + macaddr[i] - 'a';
  34180. + else
  34181. + break;
  34182. + i++;
  34183. + } else if (got_num == 2) {
  34184. + mtbl[j++] = (u8) num;
  34185. + num = 0;
  34186. + got_num = 0;
  34187. + i++;
  34188. + } else {
  34189. + break;
  34190. + }
  34191. + }
  34192. +
  34193. + if (j == MAC_ADDR_LEN) {
  34194. + netif_dbg(dev, ifup, dev->net, "Overriding MAC address with: "
  34195. + "%02x:%02x:%02x:%02x:%02x:%02x\n", mtbl[0], mtbl[1], mtbl[2],
  34196. + mtbl[3], mtbl[4], mtbl[5]);
  34197. + for (i = 0; i < MAC_ADDR_LEN; i++)
  34198. + dev_mac[i] = mtbl[i];
  34199. + return 1;
  34200. + } else {
  34201. + return 0;
  34202. + }
  34203. +}
  34204. +
  34205. static void smsc95xx_init_mac_address(struct usbnet *dev)
  34206. {
  34207. + /* Check module parameters */
  34208. + if (smsc95xx_is_macaddr_param(dev, dev->net->dev_addr))
  34209. + return;
  34210. +
  34211. /* try reading mac address from EEPROM */
  34212. if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
  34213. dev->net->dev_addr) == 0) {
  34214. diff -Nur linux-3.15.4/drivers/pci/pci.c linux-rpi/drivers/pci/pci.c
  34215. --- linux-3.15.4/drivers/pci/pci.c 2014-07-07 03:59:25.000000000 +0200
  34216. +++ linux-rpi/drivers/pci/pci.c 2014-07-07 10:45:26.000000000 +0200
  34217. @@ -4126,7 +4126,7 @@
  34218. u16 cmd;
  34219. int rc;
  34220. - WARN_ON((flags & PCI_VGA_STATE_CHANGE_DECODES) && (command_bits & ~(PCI_COMMAND_IO|PCI_COMMAND_MEMORY)));
  34221. + WARN_ON((flags & PCI_VGA_STATE_CHANGE_DECODES) & (command_bits & ~(PCI_COMMAND_IO|PCI_COMMAND_MEMORY)));
  34222. /* ARCH specific VGA enables */
  34223. rc = pci_set_vga_state_arch(dev, decode, command_bits, flags);
  34224. diff -Nur linux-3.15.4/drivers/pci/quirks.c linux-rpi/drivers/pci/quirks.c
  34225. --- linux-3.15.4/drivers/pci/quirks.c 2014-07-07 03:59:25.000000000 +0200
  34226. +++ linux-rpi/drivers/pci/quirks.c 2014-07-07 10:45:26.000000000 +0200
  34227. @@ -2954,7 +2954,6 @@
  34228. }
  34229. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0102, disable_igfx_irq);
  34230. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x010a, disable_igfx_irq);
  34231. -DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0152, disable_igfx_irq);
  34232. /*
  34233. * PCI devices which are on Intel chips can skip the 10ms delay
  34234. diff -Nur linux-3.15.4/drivers/scsi/hpsa.c linux-rpi/drivers/scsi/hpsa.c
  34235. --- linux-3.15.4/drivers/scsi/hpsa.c 2014-07-07 03:59:25.000000000 +0200
  34236. +++ linux-rpi/drivers/scsi/hpsa.c 2014-07-07 10:45:27.000000000 +0200
  34237. @@ -115,15 +115,9 @@
  34238. {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C3},
  34239. {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C4},
  34240. {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C5},
  34241. - {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C6},
  34242. {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C7},
  34243. {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C8},
  34244. {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21C9},
  34245. - {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21CA},
  34246. - {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21CB},
  34247. - {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21CC},
  34248. - {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21CD},
  34249. - {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21CE},
  34250. {PCI_VENDOR_ID_HP_3PAR, 0x0075, 0x1590, 0x0076},
  34251. {PCI_VENDOR_ID_HP_3PAR, 0x0075, 0x1590, 0x0087},
  34252. {PCI_VENDOR_ID_HP_3PAR, 0x0075, 0x1590, 0x007D},
  34253. @@ -171,15 +165,9 @@
  34254. {0x21C3103C, "Smart Array", &SA5_access},
  34255. {0x21C4103C, "Smart Array", &SA5_access},
  34256. {0x21C5103C, "Smart Array", &SA5_access},
  34257. - {0x21C6103C, "Smart Array", &SA5_access},
  34258. {0x21C7103C, "Smart Array", &SA5_access},
  34259. {0x21C8103C, "Smart Array", &SA5_access},
  34260. {0x21C9103C, "Smart Array", &SA5_access},
  34261. - {0x21CA103C, "Smart Array", &SA5_access},
  34262. - {0x21CB103C, "Smart Array", &SA5_access},
  34263. - {0x21CC103C, "Smart Array", &SA5_access},
  34264. - {0x21CD103C, "Smart Array", &SA5_access},
  34265. - {0x21CE103C, "Smart Array", &SA5_access},
  34266. {0x00761590, "HP Storage P1224 Array Controller", &SA5_access},
  34267. {0x00871590, "HP Storage P1224e Array Controller", &SA5_access},
  34268. {0x007D1590, "HP Storage P1228 Array Controller", &SA5_access},
  34269. diff -Nur linux-3.15.4/drivers/spi/Kconfig linux-rpi/drivers/spi/Kconfig
  34270. --- linux-3.15.4/drivers/spi/Kconfig 2014-07-07 03:59:25.000000000 +0200
  34271. +++ linux-rpi/drivers/spi/Kconfig 2014-07-07 10:45:28.000000000 +0200
  34272. @@ -85,6 +85,14 @@
  34273. is for the regular SPI controller. Slave mode operation is not also
  34274. not supported.
  34275. +config SPI_BCM2708
  34276. + tristate "BCM2708 SPI controller driver (SPI0)"
  34277. + depends on MACH_BCM2708
  34278. + help
  34279. + This selects a driver for the Broadcom BCM2708 SPI master (SPI0). This
  34280. + driver is not compatible with the "Universal SPI Master" or the SPI slave
  34281. + device.
  34282. +
  34283. config SPI_BFIN5XX
  34284. tristate "SPI controller driver for ADI Blackfin5xx"
  34285. depends on BLACKFIN && !BF60x
  34286. diff -Nur linux-3.15.4/drivers/spi/Makefile linux-rpi/drivers/spi/Makefile
  34287. --- linux-3.15.4/drivers/spi/Makefile 2014-07-07 03:59:25.000000000 +0200
  34288. +++ linux-rpi/drivers/spi/Makefile 2014-07-07 10:45:28.000000000 +0200
  34289. @@ -19,6 +19,7 @@
  34290. obj-$(CONFIG_SPI_BCM63XX_HSSPI) += spi-bcm63xx-hsspi.o
  34291. obj-$(CONFIG_SPI_BFIN5XX) += spi-bfin5xx.o
  34292. obj-$(CONFIG_SPI_BFIN_V3) += spi-bfin-v3.o
  34293. +obj-$(CONFIG_SPI_BCM2708) += spi-bcm2708.o
  34294. obj-$(CONFIG_SPI_BFIN_SPORT) += spi-bfin-sport.o
  34295. obj-$(CONFIG_SPI_BITBANG) += spi-bitbang.o
  34296. obj-$(CONFIG_SPI_BUTTERFLY) += spi-butterfly.o
  34297. diff -Nur linux-3.15.4/drivers/spi/spi-bcm2708.c linux-rpi/drivers/spi/spi-bcm2708.c
  34298. --- linux-3.15.4/drivers/spi/spi-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  34299. +++ linux-rpi/drivers/spi/spi-bcm2708.c 2014-07-07 10:45:28.000000000 +0200
  34300. @@ -0,0 +1,626 @@
  34301. +/*
  34302. + * Driver for Broadcom BCM2708 SPI Controllers
  34303. + *
  34304. + * Copyright (C) 2012 Chris Boot
  34305. + *
  34306. + * This driver is inspired by:
  34307. + * spi-ath79.c, Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>
  34308. + * spi-atmel.c, Copyright (C) 2006 Atmel Corporation
  34309. + *
  34310. + * This program is free software; you can redistribute it and/or modify
  34311. + * it under the terms of the GNU General Public License as published by
  34312. + * the Free Software Foundation; either version 2 of the License, or
  34313. + * (at your option) any later version.
  34314. + *
  34315. + * This program is distributed in the hope that it will be useful,
  34316. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  34317. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  34318. + * GNU General Public License for more details.
  34319. + *
  34320. + * You should have received a copy of the GNU General Public License
  34321. + * along with this program; if not, write to the Free Software
  34322. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  34323. + */
  34324. +
  34325. +#include <linux/kernel.h>
  34326. +#include <linux/module.h>
  34327. +#include <linux/spinlock.h>
  34328. +#include <linux/clk.h>
  34329. +#include <linux/err.h>
  34330. +#include <linux/platform_device.h>
  34331. +#include <linux/io.h>
  34332. +#include <linux/spi/spi.h>
  34333. +#include <linux/interrupt.h>
  34334. +#include <linux/delay.h>
  34335. +#include <linux/log2.h>
  34336. +#include <linux/sched.h>
  34337. +#include <linux/wait.h>
  34338. +
  34339. +/* SPI register offsets */
  34340. +#define SPI_CS 0x00
  34341. +#define SPI_FIFO 0x04
  34342. +#define SPI_CLK 0x08
  34343. +#define SPI_DLEN 0x0c
  34344. +#define SPI_LTOH 0x10
  34345. +#define SPI_DC 0x14
  34346. +
  34347. +/* Bitfields in CS */
  34348. +#define SPI_CS_LEN_LONG 0x02000000
  34349. +#define SPI_CS_DMA_LEN 0x01000000
  34350. +#define SPI_CS_CSPOL2 0x00800000
  34351. +#define SPI_CS_CSPOL1 0x00400000
  34352. +#define SPI_CS_CSPOL0 0x00200000
  34353. +#define SPI_CS_RXF 0x00100000
  34354. +#define SPI_CS_RXR 0x00080000
  34355. +#define SPI_CS_TXD 0x00040000
  34356. +#define SPI_CS_RXD 0x00020000
  34357. +#define SPI_CS_DONE 0x00010000
  34358. +#define SPI_CS_LEN 0x00002000
  34359. +#define SPI_CS_REN 0x00001000
  34360. +#define SPI_CS_ADCS 0x00000800
  34361. +#define SPI_CS_INTR 0x00000400
  34362. +#define SPI_CS_INTD 0x00000200
  34363. +#define SPI_CS_DMAEN 0x00000100
  34364. +#define SPI_CS_TA 0x00000080
  34365. +#define SPI_CS_CSPOL 0x00000040
  34366. +#define SPI_CS_CLEAR_RX 0x00000020
  34367. +#define SPI_CS_CLEAR_TX 0x00000010
  34368. +#define SPI_CS_CPOL 0x00000008
  34369. +#define SPI_CS_CPHA 0x00000004
  34370. +#define SPI_CS_CS_10 0x00000002
  34371. +#define SPI_CS_CS_01 0x00000001
  34372. +
  34373. +#define SPI_TIMEOUT_MS 150
  34374. +
  34375. +#define DRV_NAME "bcm2708_spi"
  34376. +
  34377. +struct bcm2708_spi {
  34378. + spinlock_t lock;
  34379. + void __iomem *base;
  34380. + int irq;
  34381. + struct clk *clk;
  34382. + bool stopping;
  34383. +
  34384. + struct list_head queue;
  34385. + struct workqueue_struct *workq;
  34386. + struct work_struct work;
  34387. + struct completion done;
  34388. +
  34389. + const u8 *tx_buf;
  34390. + u8 *rx_buf;
  34391. + int len;
  34392. +};
  34393. +
  34394. +struct bcm2708_spi_state {
  34395. + u32 cs;
  34396. + u16 cdiv;
  34397. +};
  34398. +
  34399. +/*
  34400. + * This function sets the ALT mode on the SPI pins so that we can use them with
  34401. + * the SPI hardware.
  34402. + *
  34403. + * FIXME: This is a hack. Use pinmux / pinctrl.
  34404. + */
  34405. +static void bcm2708_init_pinmode(void)
  34406. +{
  34407. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  34408. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  34409. +
  34410. + int pin;
  34411. + u32 *gpio = ioremap(GPIO_BASE, SZ_16K);
  34412. +
  34413. + /* SPI is on GPIO 7..11 */
  34414. + for (pin = 7; pin <= 11; pin++) {
  34415. + INP_GPIO(pin); /* set mode to GPIO input first */
  34416. + SET_GPIO_ALT(pin, 0); /* set mode to ALT 0 */
  34417. + }
  34418. +
  34419. + iounmap(gpio);
  34420. +
  34421. +#undef INP_GPIO
  34422. +#undef SET_GPIO_ALT
  34423. +}
  34424. +
  34425. +static inline u32 bcm2708_rd(struct bcm2708_spi *bs, unsigned reg)
  34426. +{
  34427. + return readl(bs->base + reg);
  34428. +}
  34429. +
  34430. +static inline void bcm2708_wr(struct bcm2708_spi *bs, unsigned reg, u32 val)
  34431. +{
  34432. + writel(val, bs->base + reg);
  34433. +}
  34434. +
  34435. +static inline void bcm2708_rd_fifo(struct bcm2708_spi *bs, int len)
  34436. +{
  34437. + u8 byte;
  34438. +
  34439. + while (len--) {
  34440. + byte = bcm2708_rd(bs, SPI_FIFO);
  34441. + if (bs->rx_buf)
  34442. + *bs->rx_buf++ = byte;
  34443. + }
  34444. +}
  34445. +
  34446. +static inline void bcm2708_wr_fifo(struct bcm2708_spi *bs, int len)
  34447. +{
  34448. + u8 byte;
  34449. + u16 val;
  34450. +
  34451. + if (len > bs->len)
  34452. + len = bs->len;
  34453. +
  34454. + if (unlikely(bcm2708_rd(bs, SPI_CS) & SPI_CS_LEN)) {
  34455. + /* LoSSI mode */
  34456. + if (unlikely(len % 2)) {
  34457. + printk(KERN_ERR"bcm2708_wr_fifo: length must be even, skipping.\n");
  34458. + bs->len = 0;
  34459. + return;
  34460. + }
  34461. + while (len) {
  34462. + if (bs->tx_buf) {
  34463. + val = *(const u16 *)bs->tx_buf;
  34464. + bs->tx_buf += 2;
  34465. + } else
  34466. + val = 0;
  34467. + bcm2708_wr(bs, SPI_FIFO, val);
  34468. + bs->len -= 2;
  34469. + len -= 2;
  34470. + }
  34471. + return;
  34472. + }
  34473. +
  34474. + while (len--) {
  34475. + byte = bs->tx_buf ? *bs->tx_buf++ : 0;
  34476. + bcm2708_wr(bs, SPI_FIFO, byte);
  34477. + bs->len--;
  34478. + }
  34479. +}
  34480. +
  34481. +static irqreturn_t bcm2708_spi_interrupt(int irq, void *dev_id)
  34482. +{
  34483. + struct spi_master *master = dev_id;
  34484. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  34485. + u32 cs;
  34486. +
  34487. + spin_lock(&bs->lock);
  34488. +
  34489. + cs = bcm2708_rd(bs, SPI_CS);
  34490. +
  34491. + if (cs & SPI_CS_DONE) {
  34492. + if (bs->len) { /* first interrupt in a transfer */
  34493. + /* fill the TX fifo with up to 16 bytes */
  34494. + bcm2708_wr_fifo(bs, 16);
  34495. + } else { /* transfer complete */
  34496. + /* disable interrupts */
  34497. + cs &= ~(SPI_CS_INTR | SPI_CS_INTD);
  34498. + bcm2708_wr(bs, SPI_CS, cs);
  34499. +
  34500. + /* drain RX FIFO */
  34501. + while (cs & SPI_CS_RXD) {
  34502. + bcm2708_rd_fifo(bs, 1);
  34503. + cs = bcm2708_rd(bs, SPI_CS);
  34504. + }
  34505. +
  34506. + /* wake up our bh */
  34507. + complete(&bs->done);
  34508. + }
  34509. + } else if (cs & SPI_CS_RXR) {
  34510. + /* read 12 bytes of data */
  34511. + bcm2708_rd_fifo(bs, 12);
  34512. +
  34513. + /* write up to 12 bytes */
  34514. + bcm2708_wr_fifo(bs, 12);
  34515. + }
  34516. +
  34517. + spin_unlock(&bs->lock);
  34518. +
  34519. + return IRQ_HANDLED;
  34520. +}
  34521. +
  34522. +static int bcm2708_setup_state(struct spi_master *master,
  34523. + struct device *dev, struct bcm2708_spi_state *state,
  34524. + u32 hz, u8 csel, u8 mode, u8 bpw)
  34525. +{
  34526. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  34527. + int cdiv;
  34528. + unsigned long bus_hz;
  34529. + u32 cs = 0;
  34530. +
  34531. + bus_hz = clk_get_rate(bs->clk);
  34532. +
  34533. + if (hz >= bus_hz) {
  34534. + cdiv = 2; /* bus_hz / 2 is as fast as we can go */
  34535. + } else if (hz) {
  34536. + cdiv = DIV_ROUND_UP(bus_hz, hz);
  34537. +
  34538. + /* CDIV must be a power of 2, so round up */
  34539. + cdiv = roundup_pow_of_two(cdiv);
  34540. +
  34541. + if (cdiv > 65536) {
  34542. + dev_dbg(dev,
  34543. + "setup: %d Hz too slow, cdiv %u; min %ld Hz\n",
  34544. + hz, cdiv, bus_hz / 65536);
  34545. + return -EINVAL;
  34546. + } else if (cdiv == 65536) {
  34547. + cdiv = 0;
  34548. + } else if (cdiv == 1) {
  34549. + cdiv = 2; /* 1 gets rounded down to 0; == 65536 */
  34550. + }
  34551. + } else {
  34552. + cdiv = 0;
  34553. + }
  34554. +
  34555. + switch (bpw) {
  34556. + case 8:
  34557. + break;
  34558. + case 9:
  34559. + /* Reading in LoSSI mode is a special case. See 'BCM2835 ARM Peripherals' datasheet */
  34560. + cs |= SPI_CS_LEN;
  34561. + break;
  34562. + default:
  34563. + dev_dbg(dev, "setup: invalid bits_per_word %u (must be 8 or 9)\n",
  34564. + bpw);
  34565. + return -EINVAL;
  34566. + }
  34567. +
  34568. + if (mode & SPI_CPOL)
  34569. + cs |= SPI_CS_CPOL;
  34570. + if (mode & SPI_CPHA)
  34571. + cs |= SPI_CS_CPHA;
  34572. +
  34573. + if (!(mode & SPI_NO_CS)) {
  34574. + if (mode & SPI_CS_HIGH) {
  34575. + cs |= SPI_CS_CSPOL;
  34576. + cs |= SPI_CS_CSPOL0 << csel;
  34577. + }
  34578. +
  34579. + cs |= csel;
  34580. + } else {
  34581. + cs |= SPI_CS_CS_10 | SPI_CS_CS_01;
  34582. + }
  34583. +
  34584. + if (state) {
  34585. + state->cs = cs;
  34586. + state->cdiv = cdiv;
  34587. + dev_dbg(dev, "setup: want %d Hz; "
  34588. + "bus_hz=%lu / cdiv=%u == %lu Hz; "
  34589. + "mode %u: cs 0x%08X\n",
  34590. + hz, bus_hz, cdiv, bus_hz/cdiv, mode, cs);
  34591. + }
  34592. +
  34593. + return 0;
  34594. +}
  34595. +
  34596. +static int bcm2708_process_transfer(struct bcm2708_spi *bs,
  34597. + struct spi_message *msg, struct spi_transfer *xfer)
  34598. +{
  34599. + struct spi_device *spi = msg->spi;
  34600. + struct bcm2708_spi_state state, *stp;
  34601. + int ret;
  34602. + u32 cs;
  34603. +
  34604. + if (bs->stopping)
  34605. + return -ESHUTDOWN;
  34606. +
  34607. + if (xfer->bits_per_word || xfer->speed_hz) {
  34608. + ret = bcm2708_setup_state(spi->master, &spi->dev, &state,
  34609. + xfer->speed_hz ? xfer->speed_hz : spi->max_speed_hz,
  34610. + spi->chip_select, spi->mode,
  34611. + xfer->bits_per_word ? xfer->bits_per_word :
  34612. + spi->bits_per_word);
  34613. + if (ret)
  34614. + return ret;
  34615. +
  34616. + stp = &state;
  34617. + } else {
  34618. + stp = spi->controller_state;
  34619. + }
  34620. +
  34621. + reinit_completion(&bs->done);
  34622. + bs->tx_buf = xfer->tx_buf;
  34623. + bs->rx_buf = xfer->rx_buf;
  34624. + bs->len = xfer->len;
  34625. +
  34626. + cs = stp->cs | SPI_CS_INTR | SPI_CS_INTD | SPI_CS_TA;
  34627. +
  34628. + bcm2708_wr(bs, SPI_CLK, stp->cdiv);
  34629. + bcm2708_wr(bs, SPI_CS, cs);
  34630. +
  34631. + ret = wait_for_completion_timeout(&bs->done,
  34632. + msecs_to_jiffies(SPI_TIMEOUT_MS));
  34633. + if (ret == 0) {
  34634. + dev_err(&spi->dev, "transfer timed out\n");
  34635. + return -ETIMEDOUT;
  34636. + }
  34637. +
  34638. + if (xfer->delay_usecs)
  34639. + udelay(xfer->delay_usecs);
  34640. +
  34641. + if (list_is_last(&xfer->transfer_list, &msg->transfers) ||
  34642. + xfer->cs_change) {
  34643. + /* clear TA and interrupt flags */
  34644. + bcm2708_wr(bs, SPI_CS, stp->cs);
  34645. + }
  34646. +
  34647. + msg->actual_length += (xfer->len - bs->len);
  34648. +
  34649. + return 0;
  34650. +}
  34651. +
  34652. +static void bcm2708_work(struct work_struct *work)
  34653. +{
  34654. + struct bcm2708_spi *bs = container_of(work, struct bcm2708_spi, work);
  34655. + unsigned long flags;
  34656. + struct spi_message *msg;
  34657. + struct spi_transfer *xfer;
  34658. + int status = 0;
  34659. +
  34660. + spin_lock_irqsave(&bs->lock, flags);
  34661. + while (!list_empty(&bs->queue)) {
  34662. + msg = list_first_entry(&bs->queue, struct spi_message, queue);
  34663. + list_del_init(&msg->queue);
  34664. + spin_unlock_irqrestore(&bs->lock, flags);
  34665. +
  34666. + list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  34667. + status = bcm2708_process_transfer(bs, msg, xfer);
  34668. + if (status)
  34669. + break;
  34670. + }
  34671. +
  34672. + msg->status = status;
  34673. + msg->complete(msg->context);
  34674. +
  34675. + spin_lock_irqsave(&bs->lock, flags);
  34676. + }
  34677. + spin_unlock_irqrestore(&bs->lock, flags);
  34678. +}
  34679. +
  34680. +static int bcm2708_spi_setup(struct spi_device *spi)
  34681. +{
  34682. + struct bcm2708_spi *bs = spi_master_get_devdata(spi->master);
  34683. + struct bcm2708_spi_state *state;
  34684. + int ret;
  34685. +
  34686. + if (bs->stopping)
  34687. + return -ESHUTDOWN;
  34688. +
  34689. + if (!(spi->mode & SPI_NO_CS) &&
  34690. + (spi->chip_select > spi->master->num_chipselect)) {
  34691. + dev_dbg(&spi->dev,
  34692. + "setup: invalid chipselect %u (%u defined)\n",
  34693. + spi->chip_select, spi->master->num_chipselect);
  34694. + return -EINVAL;
  34695. + }
  34696. +
  34697. + state = spi->controller_state;
  34698. + if (!state) {
  34699. + state = kzalloc(sizeof(*state), GFP_KERNEL);
  34700. + if (!state)
  34701. + return -ENOMEM;
  34702. +
  34703. + spi->controller_state = state;
  34704. + }
  34705. +
  34706. + ret = bcm2708_setup_state(spi->master, &spi->dev, state,
  34707. + spi->max_speed_hz, spi->chip_select, spi->mode,
  34708. + spi->bits_per_word);
  34709. + if (ret < 0) {
  34710. + kfree(state);
  34711. + spi->controller_state = NULL;
  34712. + return ret;
  34713. + }
  34714. +
  34715. + dev_dbg(&spi->dev,
  34716. + "setup: cd %d: %d Hz, bpw %u, mode 0x%x -> CS=%08x CDIV=%04x\n",
  34717. + spi->chip_select, spi->max_speed_hz, spi->bits_per_word,
  34718. + spi->mode, state->cs, state->cdiv);
  34719. +
  34720. + return 0;
  34721. +}
  34722. +
  34723. +static int bcm2708_spi_transfer(struct spi_device *spi, struct spi_message *msg)
  34724. +{
  34725. + struct bcm2708_spi *bs = spi_master_get_devdata(spi->master);
  34726. + struct spi_transfer *xfer;
  34727. + int ret;
  34728. + unsigned long flags;
  34729. +
  34730. + if (unlikely(list_empty(&msg->transfers)))
  34731. + return -EINVAL;
  34732. +
  34733. + if (bs->stopping)
  34734. + return -ESHUTDOWN;
  34735. +
  34736. + list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  34737. + if (!(xfer->tx_buf || xfer->rx_buf) && xfer->len) {
  34738. + dev_dbg(&spi->dev, "missing rx or tx buf\n");
  34739. + return -EINVAL;
  34740. + }
  34741. +
  34742. + if (!xfer->bits_per_word || xfer->speed_hz)
  34743. + continue;
  34744. +
  34745. + ret = bcm2708_setup_state(spi->master, &spi->dev, NULL,
  34746. + xfer->speed_hz ? xfer->speed_hz : spi->max_speed_hz,
  34747. + spi->chip_select, spi->mode,
  34748. + xfer->bits_per_word ? xfer->bits_per_word :
  34749. + spi->bits_per_word);
  34750. + if (ret)
  34751. + return ret;
  34752. + }
  34753. +
  34754. + msg->status = -EINPROGRESS;
  34755. + msg->actual_length = 0;
  34756. +
  34757. + spin_lock_irqsave(&bs->lock, flags);
  34758. + list_add_tail(&msg->queue, &bs->queue);
  34759. + queue_work(bs->workq, &bs->work);
  34760. + spin_unlock_irqrestore(&bs->lock, flags);
  34761. +
  34762. + return 0;
  34763. +}
  34764. +
  34765. +static void bcm2708_spi_cleanup(struct spi_device *spi)
  34766. +{
  34767. + if (spi->controller_state) {
  34768. + kfree(spi->controller_state);
  34769. + spi->controller_state = NULL;
  34770. + }
  34771. +}
  34772. +
  34773. +static int bcm2708_spi_probe(struct platform_device *pdev)
  34774. +{
  34775. + struct resource *regs;
  34776. + int irq, err = -ENOMEM;
  34777. + struct clk *clk;
  34778. + struct spi_master *master;
  34779. + struct bcm2708_spi *bs;
  34780. +
  34781. + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  34782. + if (!regs) {
  34783. + dev_err(&pdev->dev, "could not get IO memory\n");
  34784. + return -ENXIO;
  34785. + }
  34786. +
  34787. + irq = platform_get_irq(pdev, 0);
  34788. + if (irq < 0) {
  34789. + dev_err(&pdev->dev, "could not get IRQ\n");
  34790. + return irq;
  34791. + }
  34792. +
  34793. + clk = clk_get(&pdev->dev, NULL);
  34794. + if (IS_ERR(clk)) {
  34795. + dev_err(&pdev->dev, "could not find clk: %ld\n", PTR_ERR(clk));
  34796. + return PTR_ERR(clk);
  34797. + }
  34798. +
  34799. + bcm2708_init_pinmode();
  34800. +
  34801. + master = spi_alloc_master(&pdev->dev, sizeof(*bs));
  34802. + if (!master) {
  34803. + dev_err(&pdev->dev, "spi_alloc_master() failed\n");
  34804. + goto out_clk_put;
  34805. + }
  34806. +
  34807. + /* the spi->mode bits understood by this driver: */
  34808. + master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_NO_CS;
  34809. +
  34810. + master->bus_num = pdev->id;
  34811. + master->num_chipselect = 3;
  34812. + master->setup = bcm2708_spi_setup;
  34813. + master->transfer = bcm2708_spi_transfer;
  34814. + master->cleanup = bcm2708_spi_cleanup;
  34815. + platform_set_drvdata(pdev, master);
  34816. +
  34817. + bs = spi_master_get_devdata(master);
  34818. +
  34819. + spin_lock_init(&bs->lock);
  34820. + INIT_LIST_HEAD(&bs->queue);
  34821. + init_completion(&bs->done);
  34822. + INIT_WORK(&bs->work, bcm2708_work);
  34823. +
  34824. + bs->base = ioremap(regs->start, resource_size(regs));
  34825. + if (!bs->base) {
  34826. + dev_err(&pdev->dev, "could not remap memory\n");
  34827. + goto out_master_put;
  34828. + }
  34829. +
  34830. + bs->workq = create_singlethread_workqueue(dev_name(&pdev->dev));
  34831. + if (!bs->workq) {
  34832. + dev_err(&pdev->dev, "could not create workqueue\n");
  34833. + goto out_iounmap;
  34834. + }
  34835. +
  34836. + bs->irq = irq;
  34837. + bs->clk = clk;
  34838. + bs->stopping = false;
  34839. +
  34840. + err = request_irq(irq, bcm2708_spi_interrupt, 0, dev_name(&pdev->dev),
  34841. + master);
  34842. + if (err) {
  34843. + dev_err(&pdev->dev, "could not request IRQ: %d\n", err);
  34844. + goto out_workqueue;
  34845. + }
  34846. +
  34847. + /* initialise the hardware */
  34848. + clk_enable(clk);
  34849. + bcm2708_wr(bs, SPI_CS, SPI_CS_REN | SPI_CS_CLEAR_RX | SPI_CS_CLEAR_TX);
  34850. +
  34851. + err = spi_register_master(master);
  34852. + if (err) {
  34853. + dev_err(&pdev->dev, "could not register SPI master: %d\n", err);
  34854. + goto out_free_irq;
  34855. + }
  34856. +
  34857. + dev_info(&pdev->dev, "SPI Controller at 0x%08lx (irq %d)\n",
  34858. + (unsigned long)regs->start, irq);
  34859. +
  34860. + return 0;
  34861. +
  34862. +out_free_irq:
  34863. + free_irq(bs->irq, master);
  34864. +out_workqueue:
  34865. + destroy_workqueue(bs->workq);
  34866. +out_iounmap:
  34867. + iounmap(bs->base);
  34868. +out_master_put:
  34869. + spi_master_put(master);
  34870. +out_clk_put:
  34871. + clk_put(clk);
  34872. + return err;
  34873. +}
  34874. +
  34875. +static int bcm2708_spi_remove(struct platform_device *pdev)
  34876. +{
  34877. + struct spi_master *master = platform_get_drvdata(pdev);
  34878. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  34879. +
  34880. + /* reset the hardware and block queue progress */
  34881. + spin_lock_irq(&bs->lock);
  34882. + bs->stopping = true;
  34883. + bcm2708_wr(bs, SPI_CS, SPI_CS_CLEAR_RX | SPI_CS_CLEAR_TX);
  34884. + spin_unlock_irq(&bs->lock);
  34885. +
  34886. + flush_work_sync(&bs->work);
  34887. +
  34888. + clk_disable(bs->clk);
  34889. + clk_put(bs->clk);
  34890. + free_irq(bs->irq, master);
  34891. + iounmap(bs->base);
  34892. +
  34893. + spi_unregister_master(master);
  34894. +
  34895. + return 0;
  34896. +}
  34897. +
  34898. +static struct platform_driver bcm2708_spi_driver = {
  34899. + .driver = {
  34900. + .name = DRV_NAME,
  34901. + .owner = THIS_MODULE,
  34902. + },
  34903. + .probe = bcm2708_spi_probe,
  34904. + .remove = bcm2708_spi_remove,
  34905. +};
  34906. +
  34907. +
  34908. +static int __init bcm2708_spi_init(void)
  34909. +{
  34910. + return platform_driver_probe(&bcm2708_spi_driver, bcm2708_spi_probe);
  34911. +}
  34912. +module_init(bcm2708_spi_init);
  34913. +
  34914. +static void __exit bcm2708_spi_exit(void)
  34915. +{
  34916. + platform_driver_unregister(&bcm2708_spi_driver);
  34917. +}
  34918. +module_exit(bcm2708_spi_exit);
  34919. +
  34920. +
  34921. +//module_platform_driver(bcm2708_spi_driver);
  34922. +
  34923. +MODULE_DESCRIPTION("SPI controller driver for Broadcom BCM2708");
  34924. +MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
  34925. +MODULE_LICENSE("GPL v2");
  34926. +MODULE_ALIAS("platform:" DRV_NAME);
  34927. diff -Nur linux-3.15.4/drivers/staging/media/lirc/Kconfig linux-rpi/drivers/staging/media/lirc/Kconfig
  34928. --- linux-3.15.4/drivers/staging/media/lirc/Kconfig 2014-07-07 03:59:25.000000000 +0200
  34929. +++ linux-rpi/drivers/staging/media/lirc/Kconfig 2014-04-13 17:33:09.000000000 +0200
  34930. @@ -38,6 +38,12 @@
  34931. help
  34932. Driver for Homebrew Parallel Port Receivers
  34933. +config LIRC_RPI
  34934. + tristate "Homebrew GPIO Port Receiver/Transmitter for the RaspberryPi"
  34935. + depends on LIRC
  34936. + help
  34937. + Driver for Homebrew GPIO Port Receiver/Transmitter for the RaspberryPi
  34938. +
  34939. config LIRC_SASEM
  34940. tristate "Sasem USB IR Remote"
  34941. depends on LIRC && USB
  34942. diff -Nur linux-3.15.4/drivers/staging/media/lirc/lirc_rpi.c linux-rpi/drivers/staging/media/lirc/lirc_rpi.c
  34943. --- linux-3.15.4/drivers/staging/media/lirc/lirc_rpi.c 1970-01-01 01:00:00.000000000 +0100
  34944. +++ linux-rpi/drivers/staging/media/lirc/lirc_rpi.c 2014-06-29 11:34:17.000000000 +0200
  34945. @@ -0,0 +1,695 @@
  34946. +/*
  34947. + * lirc_rpi.c
  34948. + *
  34949. + * lirc_rpi - Device driver that records pulse- and pause-lengths
  34950. + * (space-lengths) (just like the lirc_serial driver does)
  34951. + * between GPIO interrupt events on the Raspberry Pi.
  34952. + * Lots of code has been taken from the lirc_serial module,
  34953. + * so I would like say thanks to the authors.
  34954. + *
  34955. + * Copyright (C) 2012 Aron Robert Szabo <aron@reon.hu>,
  34956. + * Michael Bishop <cleverca22@gmail.com>
  34957. + * This program is free software; you can redistribute it and/or modify
  34958. + * it under the terms of the GNU General Public License as published by
  34959. + * the Free Software Foundation; either version 2 of the License, or
  34960. + * (at your option) any later version.
  34961. + *
  34962. + * This program is distributed in the hope that it will be useful,
  34963. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  34964. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  34965. + * GNU General Public License for more details.
  34966. + *
  34967. + * You should have received a copy of the GNU General Public License
  34968. + * along with this program; if not, write to the Free Software
  34969. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  34970. + */
  34971. +
  34972. +#include <linux/module.h>
  34973. +#include <linux/errno.h>
  34974. +#include <linux/interrupt.h>
  34975. +#include <linux/sched.h>
  34976. +#include <linux/kernel.h>
  34977. +#include <linux/time.h>
  34978. +#include <linux/timex.h>
  34979. +#include <linux/string.h>
  34980. +#include <linux/delay.h>
  34981. +#include <linux/platform_device.h>
  34982. +#include <linux/irq.h>
  34983. +#include <linux/spinlock.h>
  34984. +#include <media/lirc.h>
  34985. +#include <media/lirc_dev.h>
  34986. +#include <linux/gpio.h>
  34987. +
  34988. +#define LIRC_DRIVER_NAME "lirc_rpi"
  34989. +#define RBUF_LEN 256
  34990. +#define LIRC_TRANSMITTER_LATENCY 50
  34991. +
  34992. +#ifndef MAX_UDELAY_MS
  34993. +#define MAX_UDELAY_US 5000
  34994. +#else
  34995. +#define MAX_UDELAY_US (MAX_UDELAY_MS*1000)
  34996. +#endif
  34997. +
  34998. +#define dprintk(fmt, args...) \
  34999. + do { \
  35000. + if (debug) \
  35001. + printk(KERN_DEBUG LIRC_DRIVER_NAME ": " \
  35002. + fmt, ## args); \
  35003. + } while (0)
  35004. +
  35005. +/* module parameters */
  35006. +
  35007. +/* set the default GPIO input pin */
  35008. +static int gpio_in_pin = 18;
  35009. +/* set the default GPIO output pin */
  35010. +static int gpio_out_pin = 17;
  35011. +/* enable debugging messages */
  35012. +static bool debug;
  35013. +/* -1 = auto, 0 = active high, 1 = active low */
  35014. +static int sense = -1;
  35015. +/* use softcarrier by default */
  35016. +static bool softcarrier = 1;
  35017. +/* 0 = do not invert output, 1 = invert output */
  35018. +static bool invert = 0;
  35019. +
  35020. +struct gpio_chip *gpiochip;
  35021. +struct irq_chip *irqchip;
  35022. +struct irq_data *irqdata;
  35023. +
  35024. +/* forward declarations */
  35025. +static long send_pulse(unsigned long length);
  35026. +static void send_space(long length);
  35027. +static void lirc_rpi_exit(void);
  35028. +
  35029. +int valid_gpio_pins[] = { 0, 1, 2, 3, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 21,
  35030. + 22, 23, 24, 25 ,27, 28, 29, 30, 31 };
  35031. +
  35032. +static struct platform_device *lirc_rpi_dev;
  35033. +static struct timeval lasttv = { 0, 0 };
  35034. +static struct lirc_buffer rbuf;
  35035. +static spinlock_t lock;
  35036. +
  35037. +/* initialized/set in init_timing_params() */
  35038. +static unsigned int freq = 38000;
  35039. +static unsigned int duty_cycle = 50;
  35040. +static unsigned long period;
  35041. +static unsigned long pulse_width;
  35042. +static unsigned long space_width;
  35043. +
  35044. +static void safe_udelay(unsigned long usecs)
  35045. +{
  35046. + while (usecs > MAX_UDELAY_US) {
  35047. + udelay(MAX_UDELAY_US);
  35048. + usecs -= MAX_UDELAY_US;
  35049. + }
  35050. + udelay(usecs);
  35051. +}
  35052. +
  35053. +static int init_timing_params(unsigned int new_duty_cycle,
  35054. + unsigned int new_freq)
  35055. +{
  35056. + if (1000 * 1000000L / new_freq * new_duty_cycle / 100 <=
  35057. + LIRC_TRANSMITTER_LATENCY)
  35058. + return -EINVAL;
  35059. + if (1000 * 1000000L / new_freq * (100 - new_duty_cycle) / 100 <=
  35060. + LIRC_TRANSMITTER_LATENCY)
  35061. + return -EINVAL;
  35062. + duty_cycle = new_duty_cycle;
  35063. + freq = new_freq;
  35064. + period = 1000 * 1000000L / freq;
  35065. + pulse_width = period * duty_cycle / 100;
  35066. + space_width = period - pulse_width;
  35067. + dprintk("in init_timing_params, freq=%d pulse=%ld, "
  35068. + "space=%ld\n", freq, pulse_width, space_width);
  35069. + return 0;
  35070. +}
  35071. +
  35072. +static long send_pulse_softcarrier(unsigned long length)
  35073. +{
  35074. + int flag;
  35075. + unsigned long actual, target;
  35076. + unsigned long actual_us, initial_us, target_us;
  35077. +
  35078. + length *= 1000;
  35079. +
  35080. + actual = 0; target = 0; flag = 0;
  35081. + read_current_timer(&actual_us);
  35082. +
  35083. + while (actual < length) {
  35084. + if (flag) {
  35085. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  35086. + target += space_width;
  35087. + } else {
  35088. + gpiochip->set(gpiochip, gpio_out_pin, !invert);
  35089. + target += pulse_width;
  35090. + }
  35091. + initial_us = actual_us;
  35092. + target_us = actual_us + (target - actual) / 1000;
  35093. + /*
  35094. + * Note - we've checked in ioctl that the pulse/space
  35095. + * widths are big enough so that d is > 0
  35096. + */
  35097. + if ((int)(target_us - actual_us) > 0)
  35098. + udelay(target_us - actual_us);
  35099. + read_current_timer(&actual_us);
  35100. + actual += (actual_us - initial_us) * 1000;
  35101. + flag = !flag;
  35102. + }
  35103. + return (actual-length) / 1000;
  35104. +}
  35105. +
  35106. +static long send_pulse(unsigned long length)
  35107. +{
  35108. + if (length <= 0)
  35109. + return 0;
  35110. +
  35111. + if (softcarrier) {
  35112. + return send_pulse_softcarrier(length);
  35113. + } else {
  35114. + gpiochip->set(gpiochip, gpio_out_pin, !invert);
  35115. + safe_udelay(length);
  35116. + return 0;
  35117. + }
  35118. +}
  35119. +
  35120. +static void send_space(long length)
  35121. +{
  35122. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  35123. + if (length <= 0)
  35124. + return;
  35125. + safe_udelay(length);
  35126. +}
  35127. +
  35128. +static void rbwrite(int l)
  35129. +{
  35130. + if (lirc_buffer_full(&rbuf)) {
  35131. + /* no new signals will be accepted */
  35132. + dprintk("Buffer overrun\n");
  35133. + return;
  35134. + }
  35135. + lirc_buffer_write(&rbuf, (void *)&l);
  35136. +}
  35137. +
  35138. +static void frbwrite(int l)
  35139. +{
  35140. + /* simple noise filter */
  35141. + static int pulse, space;
  35142. + static unsigned int ptr;
  35143. +
  35144. + if (ptr > 0 && (l & PULSE_BIT)) {
  35145. + pulse += l & PULSE_MASK;
  35146. + if (pulse > 250) {
  35147. + rbwrite(space);
  35148. + rbwrite(pulse | PULSE_BIT);
  35149. + ptr = 0;
  35150. + pulse = 0;
  35151. + }
  35152. + return;
  35153. + }
  35154. + if (!(l & PULSE_BIT)) {
  35155. + if (ptr == 0) {
  35156. + if (l > 20000) {
  35157. + space = l;
  35158. + ptr++;
  35159. + return;
  35160. + }
  35161. + } else {
  35162. + if (l > 20000) {
  35163. + space += pulse;
  35164. + if (space > PULSE_MASK)
  35165. + space = PULSE_MASK;
  35166. + space += l;
  35167. + if (space > PULSE_MASK)
  35168. + space = PULSE_MASK;
  35169. + pulse = 0;
  35170. + return;
  35171. + }
  35172. + rbwrite(space);
  35173. + rbwrite(pulse | PULSE_BIT);
  35174. + ptr = 0;
  35175. + pulse = 0;
  35176. + }
  35177. + }
  35178. + rbwrite(l);
  35179. +}
  35180. +
  35181. +static irqreturn_t irq_handler(int i, void *blah, struct pt_regs *regs)
  35182. +{
  35183. + struct timeval tv;
  35184. + long deltv;
  35185. + int data;
  35186. + int signal;
  35187. +
  35188. + /* use the GPIO signal level */
  35189. + signal = gpiochip->get(gpiochip, gpio_in_pin);
  35190. +
  35191. + /* unmask the irq */
  35192. + irqchip->irq_unmask(irqdata);
  35193. +
  35194. + if (sense != -1) {
  35195. + /* get current time */
  35196. + do_gettimeofday(&tv);
  35197. +
  35198. + /* calc time since last interrupt in microseconds */
  35199. + deltv = tv.tv_sec-lasttv.tv_sec;
  35200. + if (tv.tv_sec < lasttv.tv_sec ||
  35201. + (tv.tv_sec == lasttv.tv_sec &&
  35202. + tv.tv_usec < lasttv.tv_usec)) {
  35203. + printk(KERN_WARNING LIRC_DRIVER_NAME
  35204. + ": AIEEEE: your clock just jumped backwards\n");
  35205. + printk(KERN_WARNING LIRC_DRIVER_NAME
  35206. + ": %d %d %lx %lx %lx %lx\n", signal, sense,
  35207. + tv.tv_sec, lasttv.tv_sec,
  35208. + tv.tv_usec, lasttv.tv_usec);
  35209. + data = PULSE_MASK;
  35210. + } else if (deltv > 15) {
  35211. + data = PULSE_MASK; /* really long time */
  35212. + if (!(signal^sense)) {
  35213. + /* sanity check */
  35214. + printk(KERN_WARNING LIRC_DRIVER_NAME
  35215. + ": AIEEEE: %d %d %lx %lx %lx %lx\n",
  35216. + signal, sense, tv.tv_sec, lasttv.tv_sec,
  35217. + tv.tv_usec, lasttv.tv_usec);
  35218. + /*
  35219. + * detecting pulse while this
  35220. + * MUST be a space!
  35221. + */
  35222. + sense = sense ? 0 : 1;
  35223. + }
  35224. + } else {
  35225. + data = (int) (deltv*1000000 +
  35226. + (tv.tv_usec - lasttv.tv_usec));
  35227. + }
  35228. + frbwrite(signal^sense ? data : (data|PULSE_BIT));
  35229. + lasttv = tv;
  35230. + wake_up_interruptible(&rbuf.wait_poll);
  35231. + }
  35232. +
  35233. + return IRQ_HANDLED;
  35234. +}
  35235. +
  35236. +static int is_right_chip(struct gpio_chip *chip, void *data)
  35237. +{
  35238. + dprintk("is_right_chip %s %d\n", chip->label, strcmp(data, chip->label));
  35239. +
  35240. + if (strcmp(data, chip->label) == 0)
  35241. + return 1;
  35242. + return 0;
  35243. +}
  35244. +
  35245. +static int init_port(void)
  35246. +{
  35247. + int i, nlow, nhigh, ret, irq;
  35248. +
  35249. + gpiochip = gpiochip_find("bcm2708_gpio", is_right_chip);
  35250. +
  35251. + if (!gpiochip)
  35252. + return -ENODEV;
  35253. +
  35254. + if (gpio_request(gpio_out_pin, LIRC_DRIVER_NAME " ir/out")) {
  35255. + printk(KERN_ALERT LIRC_DRIVER_NAME
  35256. + ": cant claim gpio pin %d\n", gpio_out_pin);
  35257. + ret = -ENODEV;
  35258. + goto exit_init_port;
  35259. + }
  35260. +
  35261. + if (gpio_request(gpio_in_pin, LIRC_DRIVER_NAME " ir/in")) {
  35262. + printk(KERN_ALERT LIRC_DRIVER_NAME
  35263. + ": cant claim gpio pin %d\n", gpio_in_pin);
  35264. + ret = -ENODEV;
  35265. + goto exit_gpio_free_out_pin;
  35266. + }
  35267. +
  35268. + gpiochip->direction_input(gpiochip, gpio_in_pin);
  35269. + gpiochip->direction_output(gpiochip, gpio_out_pin, 1);
  35270. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  35271. +
  35272. + irq = gpiochip->to_irq(gpiochip, gpio_in_pin);
  35273. + dprintk("to_irq %d\n", irq);
  35274. + irqdata = irq_get_irq_data(irq);
  35275. +
  35276. + if (irqdata && irqdata->chip) {
  35277. + irqchip = irqdata->chip;
  35278. + } else {
  35279. + ret = -ENODEV;
  35280. + goto exit_gpio_free_in_pin;
  35281. + }
  35282. +
  35283. + /* if pin is high, then this must be an active low receiver. */
  35284. + if (sense == -1) {
  35285. + /* wait 1/2 sec for the power supply */
  35286. + msleep(500);
  35287. +
  35288. + /*
  35289. + * probe 9 times every 0.04s, collect "votes" for
  35290. + * active high/low
  35291. + */
  35292. + nlow = 0;
  35293. + nhigh = 0;
  35294. + for (i = 0; i < 9; i++) {
  35295. + if (gpiochip->get(gpiochip, gpio_in_pin))
  35296. + nlow++;
  35297. + else
  35298. + nhigh++;
  35299. + msleep(40);
  35300. + }
  35301. + sense = (nlow >= nhigh ? 1 : 0);
  35302. + printk(KERN_INFO LIRC_DRIVER_NAME
  35303. + ": auto-detected active %s receiver on GPIO pin %d\n",
  35304. + sense ? "low" : "high", gpio_in_pin);
  35305. + } else {
  35306. + printk(KERN_INFO LIRC_DRIVER_NAME
  35307. + ": manually using active %s receiver on GPIO pin %d\n",
  35308. + sense ? "low" : "high", gpio_in_pin);
  35309. + }
  35310. +
  35311. + return 0;
  35312. +
  35313. + exit_gpio_free_in_pin:
  35314. + gpio_free(gpio_in_pin);
  35315. +
  35316. + exit_gpio_free_out_pin:
  35317. + gpio_free(gpio_out_pin);
  35318. +
  35319. + exit_init_port:
  35320. + return ret;
  35321. +}
  35322. +
  35323. +// called when the character device is opened
  35324. +static int set_use_inc(void *data)
  35325. +{
  35326. + int result;
  35327. + unsigned long flags;
  35328. +
  35329. + /* initialize timestamp */
  35330. + do_gettimeofday(&lasttv);
  35331. +
  35332. + result = request_irq(gpiochip->to_irq(gpiochip, gpio_in_pin),
  35333. + (irq_handler_t) irq_handler, 0,
  35334. + LIRC_DRIVER_NAME, (void*) 0);
  35335. +
  35336. + switch (result) {
  35337. + case -EBUSY:
  35338. + printk(KERN_ERR LIRC_DRIVER_NAME
  35339. + ": IRQ %d is busy\n",
  35340. + gpiochip->to_irq(gpiochip, gpio_in_pin));
  35341. + return -EBUSY;
  35342. + case -EINVAL:
  35343. + printk(KERN_ERR LIRC_DRIVER_NAME
  35344. + ": Bad irq number or handler\n");
  35345. + return -EINVAL;
  35346. + default:
  35347. + dprintk("Interrupt %d obtained\n",
  35348. + gpiochip->to_irq(gpiochip, gpio_in_pin));
  35349. + break;
  35350. + };
  35351. +
  35352. + /* initialize pulse/space widths */
  35353. + init_timing_params(duty_cycle, freq);
  35354. +
  35355. + spin_lock_irqsave(&lock, flags);
  35356. +
  35357. + /* GPIO Pin Falling/Rising Edge Detect Enable */
  35358. + irqchip->irq_set_type(irqdata,
  35359. + IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING);
  35360. +
  35361. + /* unmask the irq */
  35362. + irqchip->irq_unmask(irqdata);
  35363. +
  35364. + spin_unlock_irqrestore(&lock, flags);
  35365. +
  35366. + return 0;
  35367. +}
  35368. +
  35369. +static void set_use_dec(void *data)
  35370. +{
  35371. + unsigned long flags;
  35372. +
  35373. + spin_lock_irqsave(&lock, flags);
  35374. +
  35375. + /* GPIO Pin Falling/Rising Edge Detect Disable */
  35376. + irqchip->irq_set_type(irqdata, 0);
  35377. + irqchip->irq_mask(irqdata);
  35378. +
  35379. + spin_unlock_irqrestore(&lock, flags);
  35380. +
  35381. + free_irq(gpiochip->to_irq(gpiochip, gpio_in_pin), (void *) 0);
  35382. +
  35383. + dprintk(KERN_INFO LIRC_DRIVER_NAME
  35384. + ": freed IRQ %d\n", gpiochip->to_irq(gpiochip, gpio_in_pin));
  35385. +}
  35386. +
  35387. +static ssize_t lirc_write(struct file *file, const char *buf,
  35388. + size_t n, loff_t *ppos)
  35389. +{
  35390. + int i, count;
  35391. + unsigned long flags;
  35392. + long delta = 0;
  35393. + int *wbuf;
  35394. +
  35395. + count = n / sizeof(int);
  35396. + if (n % sizeof(int) || count % 2 == 0)
  35397. + return -EINVAL;
  35398. + wbuf = memdup_user(buf, n);
  35399. + if (IS_ERR(wbuf))
  35400. + return PTR_ERR(wbuf);
  35401. + spin_lock_irqsave(&lock, flags);
  35402. +
  35403. + for (i = 0; i < count; i++) {
  35404. + if (i%2)
  35405. + send_space(wbuf[i] - delta);
  35406. + else
  35407. + delta = send_pulse(wbuf[i]);
  35408. + }
  35409. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  35410. +
  35411. + spin_unlock_irqrestore(&lock, flags);
  35412. + kfree(wbuf);
  35413. + return n;
  35414. +}
  35415. +
  35416. +static long lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
  35417. +{
  35418. + int result;
  35419. + __u32 value;
  35420. +
  35421. + switch (cmd) {
  35422. + case LIRC_GET_SEND_MODE:
  35423. + return -ENOIOCTLCMD;
  35424. + break;
  35425. +
  35426. + case LIRC_SET_SEND_MODE:
  35427. + result = get_user(value, (__u32 *) arg);
  35428. + if (result)
  35429. + return result;
  35430. + /* only LIRC_MODE_PULSE supported */
  35431. + if (value != LIRC_MODE_PULSE)
  35432. + return -ENOSYS;
  35433. + break;
  35434. +
  35435. + case LIRC_GET_LENGTH:
  35436. + return -ENOSYS;
  35437. + break;
  35438. +
  35439. + case LIRC_SET_SEND_DUTY_CYCLE:
  35440. + dprintk("SET_SEND_DUTY_CYCLE\n");
  35441. + result = get_user(value, (__u32 *) arg);
  35442. + if (result)
  35443. + return result;
  35444. + if (value <= 0 || value > 100)
  35445. + return -EINVAL;
  35446. + return init_timing_params(value, freq);
  35447. + break;
  35448. +
  35449. + case LIRC_SET_SEND_CARRIER:
  35450. + dprintk("SET_SEND_CARRIER\n");
  35451. + result = get_user(value, (__u32 *) arg);
  35452. + if (result)
  35453. + return result;
  35454. + if (value > 500000 || value < 20000)
  35455. + return -EINVAL;
  35456. + return init_timing_params(duty_cycle, value);
  35457. + break;
  35458. +
  35459. + default:
  35460. + return lirc_dev_fop_ioctl(filep, cmd, arg);
  35461. + }
  35462. + return 0;
  35463. +}
  35464. +
  35465. +static const struct file_operations lirc_fops = {
  35466. + .owner = THIS_MODULE,
  35467. + .write = lirc_write,
  35468. + .unlocked_ioctl = lirc_ioctl,
  35469. + .read = lirc_dev_fop_read,
  35470. + .poll = lirc_dev_fop_poll,
  35471. + .open = lirc_dev_fop_open,
  35472. + .release = lirc_dev_fop_close,
  35473. + .llseek = no_llseek,
  35474. +};
  35475. +
  35476. +static struct lirc_driver driver = {
  35477. + .name = LIRC_DRIVER_NAME,
  35478. + .minor = -1,
  35479. + .code_length = 1,
  35480. + .sample_rate = 0,
  35481. + .data = NULL,
  35482. + .add_to_buf = NULL,
  35483. + .rbuf = &rbuf,
  35484. + .set_use_inc = set_use_inc,
  35485. + .set_use_dec = set_use_dec,
  35486. + .fops = &lirc_fops,
  35487. + .dev = NULL,
  35488. + .owner = THIS_MODULE,
  35489. +};
  35490. +
  35491. +static struct platform_driver lirc_rpi_driver = {
  35492. + .driver = {
  35493. + .name = LIRC_DRIVER_NAME,
  35494. + .owner = THIS_MODULE,
  35495. + },
  35496. +};
  35497. +
  35498. +static int __init lirc_rpi_init(void)
  35499. +{
  35500. + int result;
  35501. +
  35502. + /* Init read buffer. */
  35503. + result = lirc_buffer_init(&rbuf, sizeof(int), RBUF_LEN);
  35504. + if (result < 0)
  35505. + return -ENOMEM;
  35506. +
  35507. + result = platform_driver_register(&lirc_rpi_driver);
  35508. + if (result) {
  35509. + printk(KERN_ERR LIRC_DRIVER_NAME
  35510. + ": lirc register returned %d\n", result);
  35511. + goto exit_buffer_free;
  35512. + }
  35513. +
  35514. + lirc_rpi_dev = platform_device_alloc(LIRC_DRIVER_NAME, 0);
  35515. + if (!lirc_rpi_dev) {
  35516. + result = -ENOMEM;
  35517. + goto exit_driver_unregister;
  35518. + }
  35519. +
  35520. + result = platform_device_add(lirc_rpi_dev);
  35521. + if (result)
  35522. + goto exit_device_put;
  35523. +
  35524. + return 0;
  35525. +
  35526. + exit_device_put:
  35527. + platform_device_put(lirc_rpi_dev);
  35528. +
  35529. + exit_driver_unregister:
  35530. + platform_driver_unregister(&lirc_rpi_driver);
  35531. +
  35532. + exit_buffer_free:
  35533. + lirc_buffer_free(&rbuf);
  35534. +
  35535. + return result;
  35536. +}
  35537. +
  35538. +static void lirc_rpi_exit(void)
  35539. +{
  35540. + platform_device_unregister(lirc_rpi_dev);
  35541. + platform_driver_unregister(&lirc_rpi_driver);
  35542. + lirc_buffer_free(&rbuf);
  35543. +}
  35544. +
  35545. +static int __init lirc_rpi_init_module(void)
  35546. +{
  35547. + int result, i;
  35548. +
  35549. + result = lirc_rpi_init();
  35550. + if (result)
  35551. + return result;
  35552. +
  35553. + /* check if the module received valid gpio pin numbers */
  35554. + result = 0;
  35555. + if (gpio_in_pin != gpio_out_pin) {
  35556. + for(i = 0; (i < ARRAY_SIZE(valid_gpio_pins)) && (result != 2); i++) {
  35557. + if (gpio_in_pin == valid_gpio_pins[i] ||
  35558. + gpio_out_pin == valid_gpio_pins[i]) {
  35559. + result++;
  35560. + }
  35561. + }
  35562. + }
  35563. +
  35564. + if (result != 2) {
  35565. + result = -EINVAL;
  35566. + printk(KERN_ERR LIRC_DRIVER_NAME
  35567. + ": invalid GPIO pin(s) specified!\n");
  35568. + goto exit_rpi;
  35569. + }
  35570. +
  35571. + result = init_port();
  35572. + if (result < 0)
  35573. + goto exit_rpi;
  35574. +
  35575. + driver.features = LIRC_CAN_SET_SEND_DUTY_CYCLE |
  35576. + LIRC_CAN_SET_SEND_CARRIER |
  35577. + LIRC_CAN_SEND_PULSE |
  35578. + LIRC_CAN_REC_MODE2;
  35579. +
  35580. + driver.dev = &lirc_rpi_dev->dev;
  35581. + driver.minor = lirc_register_driver(&driver);
  35582. +
  35583. + if (driver.minor < 0) {
  35584. + printk(KERN_ERR LIRC_DRIVER_NAME
  35585. + ": device registration failed with %d\n", result);
  35586. + result = -EIO;
  35587. + goto exit_rpi;
  35588. + }
  35589. +
  35590. + printk(KERN_INFO LIRC_DRIVER_NAME ": driver registered!\n");
  35591. +
  35592. + return 0;
  35593. +
  35594. + exit_rpi:
  35595. + lirc_rpi_exit();
  35596. +
  35597. + return result;
  35598. +}
  35599. +
  35600. +static void __exit lirc_rpi_exit_module(void)
  35601. +{
  35602. + gpio_free(gpio_out_pin);
  35603. + gpio_free(gpio_in_pin);
  35604. +
  35605. + lirc_rpi_exit();
  35606. +
  35607. + lirc_unregister_driver(driver.minor);
  35608. + printk(KERN_INFO LIRC_DRIVER_NAME ": cleaned up module\n");
  35609. +}
  35610. +
  35611. +module_init(lirc_rpi_init_module);
  35612. +module_exit(lirc_rpi_exit_module);
  35613. +
  35614. +MODULE_DESCRIPTION("Infra-red receiver and blaster driver for Raspberry Pi GPIO.");
  35615. +MODULE_AUTHOR("Aron Robert Szabo <aron@reon.hu>");
  35616. +MODULE_AUTHOR("Michael Bishop <cleverca22@gmail.com>");
  35617. +MODULE_LICENSE("GPL");
  35618. +
  35619. +module_param(gpio_out_pin, int, S_IRUGO);
  35620. +MODULE_PARM_DESC(gpio_out_pin, "GPIO output/transmitter pin number of the BCM"
  35621. + " processor. Valid pin numbers are: 0, 1, 4, 8, 7, 9, 10, 11,"
  35622. + " 14, 15, 17, 18, 21, 22, 23, 24, 25, default 17");
  35623. +
  35624. +module_param(gpio_in_pin, int, S_IRUGO);
  35625. +MODULE_PARM_DESC(gpio_in_pin, "GPIO input pin number of the BCM processor."
  35626. + " Valid pin numbers are: 0, 1, 4, 8, 7, 9, 10, 11, 14, 15,"
  35627. + " 17, 18, 21, 22, 23, 24, 25, default 18");
  35628. +
  35629. +module_param(sense, int, S_IRUGO);
  35630. +MODULE_PARM_DESC(sense, "Override autodetection of IR receiver circuit"
  35631. + " (0 = active high, 1 = active low )");
  35632. +
  35633. +module_param(softcarrier, bool, S_IRUGO);
  35634. +MODULE_PARM_DESC(softcarrier, "Software carrier (0 = off, 1 = on, default on)");
  35635. +
  35636. +module_param(invert, bool, S_IRUGO);
  35637. +MODULE_PARM_DESC(invert, "Invert output (0 = off, 1 = on, default off");
  35638. +
  35639. +module_param(debug, bool, S_IRUGO | S_IWUSR);
  35640. +MODULE_PARM_DESC(debug, "Enable debugging messages");
  35641. diff -Nur linux-3.15.4/drivers/staging/media/lirc/Makefile linux-rpi/drivers/staging/media/lirc/Makefile
  35642. --- linux-3.15.4/drivers/staging/media/lirc/Makefile 2014-07-07 03:59:25.000000000 +0200
  35643. +++ linux-rpi/drivers/staging/media/lirc/Makefile 2014-04-13 17:33:09.000000000 +0200
  35644. @@ -7,6 +7,7 @@
  35645. obj-$(CONFIG_LIRC_IGORPLUGUSB) += lirc_igorplugusb.o
  35646. obj-$(CONFIG_LIRC_IMON) += lirc_imon.o
  35647. obj-$(CONFIG_LIRC_PARALLEL) += lirc_parallel.o
  35648. +obj-$(CONFIG_LIRC_RPI) += lirc_rpi.o
  35649. obj-$(CONFIG_LIRC_SASEM) += lirc_sasem.o
  35650. obj-$(CONFIG_LIRC_SERIAL) += lirc_serial.o
  35651. obj-$(CONFIG_LIRC_SIR) += lirc_sir.o
  35652. diff -Nur linux-3.15.4/drivers/target/iscsi/iscsi_target.c linux-rpi/drivers/target/iscsi/iscsi_target.c
  35653. --- linux-3.15.4/drivers/target/iscsi/iscsi_target.c 2014-07-07 03:59:25.000000000 +0200
  35654. +++ linux-rpi/drivers/target/iscsi/iscsi_target.c 2014-07-07 10:45:41.000000000 +0200
  35655. @@ -1309,7 +1309,7 @@
  35656. if (cmd->data_direction != DMA_TO_DEVICE) {
  35657. pr_err("Command ITT: 0x%08x received DataOUT for a"
  35658. " NON-WRITE command.\n", cmd->init_task_tag);
  35659. - return iscsit_dump_data_payload(conn, payload_length, 1);
  35660. + return iscsit_reject_cmd(cmd, ISCSI_REASON_PROTOCOL_ERROR, buf);
  35661. }
  35662. se_cmd = &cmd->se_cmd;
  35663. iscsit_mod_dataout_timer(cmd);
  35664. diff -Nur linux-3.15.4/drivers/target/iscsi/iscsi_target_login.c linux-rpi/drivers/target/iscsi/iscsi_target_login.c
  35665. --- linux-3.15.4/drivers/target/iscsi/iscsi_target_login.c 2014-07-07 03:59:25.000000000 +0200
  35666. +++ linux-rpi/drivers/target/iscsi/iscsi_target_login.c 2014-07-07 10:45:41.000000000 +0200
  35667. @@ -1216,7 +1216,7 @@
  35668. static int __iscsi_target_login_thread(struct iscsi_np *np)
  35669. {
  35670. u8 *buffer, zero_tsih = 0;
  35671. - int ret = 0, rc;
  35672. + int ret = 0, rc, stop;
  35673. struct iscsi_conn *conn = NULL;
  35674. struct iscsi_login *login;
  35675. struct iscsi_portal_group *tpg = NULL;
  35676. @@ -1230,9 +1230,6 @@
  35677. if (np->np_thread_state == ISCSI_NP_THREAD_RESET) {
  35678. np->np_thread_state = ISCSI_NP_THREAD_ACTIVE;
  35679. complete(&np->np_restart_comp);
  35680. - } else if (np->np_thread_state == ISCSI_NP_THREAD_SHUTDOWN) {
  35681. - spin_unlock_bh(&np->np_thread_lock);
  35682. - goto exit;
  35683. } else {
  35684. np->np_thread_state = ISCSI_NP_THREAD_ACTIVE;
  35685. }
  35686. @@ -1425,8 +1422,10 @@
  35687. }
  35688. out:
  35689. - return 1;
  35690. -
  35691. + stop = kthread_should_stop();
  35692. + /* Wait for another socket.. */
  35693. + if (!stop)
  35694. + return 1;
  35695. exit:
  35696. iscsi_stop_login_thread_timer(np);
  35697. spin_lock_bh(&np->np_thread_lock);
  35698. @@ -1443,7 +1442,7 @@
  35699. allow_signal(SIGINT);
  35700. - while (1) {
  35701. + while (!kthread_should_stop()) {
  35702. ret = __iscsi_target_login_thread(np);
  35703. /*
  35704. * We break and exit here unless another sock_accept() call
  35705. diff -Nur linux-3.15.4/drivers/target/iscsi/iscsi_target_util.c linux-rpi/drivers/target/iscsi/iscsi_target_util.c
  35706. --- linux-3.15.4/drivers/target/iscsi/iscsi_target_util.c 2014-07-07 03:59:25.000000000 +0200
  35707. +++ linux-rpi/drivers/target/iscsi/iscsi_target_util.c 2014-07-07 10:45:41.000000000 +0200
  35708. @@ -1295,8 +1295,6 @@
  35709. login->login_failed = 1;
  35710. iscsit_collect_login_stats(conn, status_class, status_detail);
  35711. - memset(&login->rsp[0], 0, ISCSI_HDR_LEN);
  35712. -
  35713. hdr = (struct iscsi_login_rsp *)&login->rsp[0];
  35714. hdr->opcode = ISCSI_OP_LOGIN_RSP;
  35715. hdr->status_class = status_class;
  35716. diff -Nur linux-3.15.4/drivers/target/target_core_device.c linux-rpi/drivers/target/target_core_device.c
  35717. --- linux-3.15.4/drivers/target/target_core_device.c 2014-07-07 03:59:25.000000000 +0200
  35718. +++ linux-rpi/drivers/target/target_core_device.c 2014-07-07 10:45:41.000000000 +0200
  35719. @@ -616,7 +616,6 @@
  35720. dev->export_count--;
  35721. spin_unlock(&hba->device_lock);
  35722. - lun->lun_sep = NULL;
  35723. lun->lun_se_dev = NULL;
  35724. }
  35725. diff -Nur linux-3.15.4/drivers/thermal/bcm2835-thermal.c linux-rpi/drivers/thermal/bcm2835-thermal.c
  35726. --- linux-3.15.4/drivers/thermal/bcm2835-thermal.c 1970-01-01 01:00:00.000000000 +0100
  35727. +++ linux-rpi/drivers/thermal/bcm2835-thermal.c 2014-04-13 17:33:10.000000000 +0200
  35728. @@ -0,0 +1,184 @@
  35729. +/*****************************************************************************
  35730. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  35731. +*
  35732. +* Unless you and Broadcom execute a separate written software license
  35733. +* agreement governing use of this software, this software is licensed to you
  35734. +* under the terms of the GNU General Public License version 2, available at
  35735. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  35736. +*
  35737. +* Notwithstanding the above, under no circumstances may you combine this
  35738. +* software in any way with any other Broadcom software provided under a
  35739. +* license other than the GPL, without Broadcom's express prior written
  35740. +* consent.
  35741. +*****************************************************************************/
  35742. +
  35743. +#include <linux/kernel.h>
  35744. +#include <linux/module.h>
  35745. +#include <linux/init.h>
  35746. +#include <linux/platform_device.h>
  35747. +#include <linux/slab.h>
  35748. +#include <linux/sysfs.h>
  35749. +#include <mach/vcio.h>
  35750. +#include <linux/thermal.h>
  35751. +
  35752. +
  35753. +/* --- DEFINITIONS --- */
  35754. +#define MODULE_NAME "bcm2835_thermal"
  35755. +
  35756. +/*#define THERMAL_DEBUG_ENABLE*/
  35757. +
  35758. +#ifdef THERMAL_DEBUG_ENABLE
  35759. +#define print_debug(fmt,...) printk(KERN_INFO "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  35760. +#else
  35761. +#define print_debug(fmt,...)
  35762. +#endif
  35763. +#define print_err(fmt,...) printk(KERN_ERR "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  35764. +
  35765. +#define VC_TAG_GET_TEMP 0x00030006
  35766. +#define VC_TAG_GET_MAX_TEMP 0x0003000A
  35767. +
  35768. +typedef enum {
  35769. + TEMP,
  35770. + MAX_TEMP,
  35771. +} temp_type;
  35772. +
  35773. +/* --- STRUCTS --- */
  35774. +/* tag part of the message */
  35775. +struct vc_msg_tag {
  35776. + uint32_t tag_id; /* the tag ID for the temperature */
  35777. + uint32_t buffer_size; /* size of the buffer (should be 8) */
  35778. + uint32_t request_code; /* identifies message as a request (should be 0) */
  35779. + uint32_t id; /* extra ID field (should be 0) */
  35780. + uint32_t val; /* returned value of the temperature */
  35781. +};
  35782. +
  35783. +/* message structure to be sent to videocore */
  35784. +struct vc_msg {
  35785. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  35786. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  35787. + struct vc_msg_tag tag; /* the tag structure above to make */
  35788. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  35789. +};
  35790. +
  35791. +struct bcm2835_thermal_data {
  35792. + struct thermal_zone_device *thermal_dev;
  35793. + struct vc_msg msg;
  35794. +};
  35795. +
  35796. +/* --- GLOBALS --- */
  35797. +static struct bcm2835_thermal_data bcm2835_data;
  35798. +
  35799. +/* Thermal Device Operations */
  35800. +static struct thermal_zone_device_ops ops;
  35801. +
  35802. +/* --- FUNCTIONS --- */
  35803. +
  35804. +static int bcm2835_get_temp_or_max(struct thermal_zone_device *thermal_dev, unsigned long *temp, unsigned tag_id)
  35805. +{
  35806. + int result = -1, retry = 3;
  35807. + print_debug("IN");
  35808. +
  35809. + *temp = 0;
  35810. + while (result != 0 && retry-- > 0) {
  35811. + /* wipe all previous message data */
  35812. + memset(&bcm2835_data.msg, 0, sizeof bcm2835_data.msg);
  35813. +
  35814. + /* prepare message */
  35815. + bcm2835_data.msg.msg_size = sizeof bcm2835_data.msg;
  35816. + bcm2835_data.msg.tag.buffer_size = 8;
  35817. + bcm2835_data.msg.tag.tag_id = tag_id;
  35818. +
  35819. + /* send the message */
  35820. + result = bcm_mailbox_property(&bcm2835_data.msg, sizeof bcm2835_data.msg);
  35821. + 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);
  35822. + if (!(bcm2835_data.msg.request_code & 0x80000000))
  35823. + result = -1;
  35824. + }
  35825. +
  35826. + /* check if it was all ok and return the rate in milli degrees C */
  35827. + if (result == 0)
  35828. + *temp = (uint)bcm2835_data.msg.tag.val;
  35829. + else
  35830. + print_err("Failed to get temperature! (%x:%d)\n", tag_id, result);
  35831. + print_debug("OUT");
  35832. + return result;
  35833. +}
  35834. +
  35835. +static int bcm2835_get_temp(struct thermal_zone_device *thermal_dev, unsigned long *temp)
  35836. +{
  35837. + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_TEMP);
  35838. +}
  35839. +
  35840. +static int bcm2835_get_max_temp(struct thermal_zone_device *thermal_dev, int trip_num, unsigned long *temp)
  35841. +{
  35842. + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_MAX_TEMP);
  35843. +}
  35844. +
  35845. +static int bcm2835_get_trip_type(struct thermal_zone_device * thermal_dev, int trip_num, enum thermal_trip_type *trip_type)
  35846. +{
  35847. + *trip_type = THERMAL_TRIP_HOT;
  35848. + return 0;
  35849. +}
  35850. +
  35851. +
  35852. +static int bcm2835_get_mode(struct thermal_zone_device *thermal_dev, enum thermal_device_mode *dev_mode)
  35853. +{
  35854. + *dev_mode = THERMAL_DEVICE_ENABLED;
  35855. + return 0;
  35856. +}
  35857. +
  35858. +
  35859. +static int bcm2835_thermal_probe(struct platform_device *pdev)
  35860. +{
  35861. + print_debug("IN");
  35862. + print_debug("THERMAL Driver has been probed!");
  35863. +
  35864. + /* check that the device isn't null!*/
  35865. + if(pdev == NULL)
  35866. + {
  35867. + print_debug("Platform device is empty!");
  35868. + return -ENODEV;
  35869. + }
  35870. +
  35871. + if(!(bcm2835_data.thermal_dev = thermal_zone_device_register("bcm2835_thermal", 1, 0, NULL, &ops, NULL, 0, 0)))
  35872. + {
  35873. + print_debug("Unable to register the thermal device!");
  35874. + return -EFAULT;
  35875. + }
  35876. + return 0;
  35877. +}
  35878. +
  35879. +
  35880. +static int bcm2835_thermal_remove(struct platform_device *pdev)
  35881. +{
  35882. + print_debug("IN");
  35883. +
  35884. + thermal_zone_device_unregister(bcm2835_data.thermal_dev);
  35885. +
  35886. + print_debug("OUT");
  35887. +
  35888. + return 0;
  35889. +}
  35890. +
  35891. +static struct thermal_zone_device_ops ops = {
  35892. + .get_temp = bcm2835_get_temp,
  35893. + .get_trip_temp = bcm2835_get_max_temp,
  35894. + .get_trip_type = bcm2835_get_trip_type,
  35895. + .get_mode = bcm2835_get_mode,
  35896. +};
  35897. +
  35898. +/* Thermal Driver */
  35899. +static struct platform_driver bcm2835_thermal_driver = {
  35900. + .probe = bcm2835_thermal_probe,
  35901. + .remove = bcm2835_thermal_remove,
  35902. + .driver = {
  35903. + .name = "bcm2835_thermal",
  35904. + .owner = THIS_MODULE,
  35905. + },
  35906. +};
  35907. +
  35908. +MODULE_LICENSE("GPL");
  35909. +MODULE_AUTHOR("Dorian Peake");
  35910. +MODULE_DESCRIPTION("Thermal driver for bcm2835 chip");
  35911. +
  35912. +module_platform_driver(bcm2835_thermal_driver);
  35913. diff -Nur linux-3.15.4/drivers/thermal/Kconfig linux-rpi/drivers/thermal/Kconfig
  35914. --- linux-3.15.4/drivers/thermal/Kconfig 2014-07-07 03:59:25.000000000 +0200
  35915. +++ linux-rpi/drivers/thermal/Kconfig 2014-07-07 10:45:41.000000000 +0200
  35916. @@ -196,6 +196,12 @@
  35917. enforce idle time which results in more package C-state residency. The
  35918. user interface is exposed via generic thermal framework.
  35919. +config THERMAL_BCM2835
  35920. + tristate "BCM2835 Thermal Driver"
  35921. + help
  35922. + This will enable temperature monitoring for the Broadcom BCM2835
  35923. + chip. If built as a module, it will be called 'bcm2835-thermal'.
  35924. +
  35925. config X86_PKG_TEMP_THERMAL
  35926. tristate "X86 package temperature thermal driver"
  35927. depends on X86_THERMAL_VECTOR
  35928. diff -Nur linux-3.15.4/drivers/thermal/Makefile linux-rpi/drivers/thermal/Makefile
  35929. --- linux-3.15.4/drivers/thermal/Makefile 2014-07-07 03:59:25.000000000 +0200
  35930. +++ linux-rpi/drivers/thermal/Makefile 2014-07-07 10:45:41.000000000 +0200
  35931. @@ -28,6 +28,7 @@
  35932. obj-$(CONFIG_IMX_THERMAL) += imx_thermal.o
  35933. obj-$(CONFIG_DB8500_CPUFREQ_COOLING) += db8500_cpufreq_cooling.o
  35934. obj-$(CONFIG_INTEL_POWERCLAMP) += intel_powerclamp.o
  35935. +obj-$(CONFIG_THERMAL_BCM2835) += bcm2835-thermal.o
  35936. obj-$(CONFIG_X86_PKG_TEMP_THERMAL) += x86_pkg_temp_thermal.o
  35937. obj-$(CONFIG_TI_SOC_THERMAL) += ti-soc-thermal/
  35938. obj-$(CONFIG_ACPI_INT3403_THERMAL) += int3403_thermal.o
  35939. diff -Nur linux-3.15.4/drivers/tty/serial/amba-pl011.c linux-rpi/drivers/tty/serial/amba-pl011.c
  35940. --- linux-3.15.4/drivers/tty/serial/amba-pl011.c 2014-07-07 03:59:25.000000000 +0200
  35941. +++ linux-rpi/drivers/tty/serial/amba-pl011.c 2014-07-07 10:45:42.000000000 +0200
  35942. @@ -84,7 +84,7 @@
  35943. static unsigned int get_fifosize_arm(struct amba_device *dev)
  35944. {
  35945. - return amba_rev(dev) < 3 ? 16 : 32;
  35946. + return 16; //TODO: fix: amba_rev(dev) < 3 ? 16 : 32;
  35947. }
  35948. static struct vendor_data vendor_arm = {
  35949. diff -Nur linux-3.15.4/drivers/usb/core/generic.c linux-rpi/drivers/usb/core/generic.c
  35950. --- linux-3.15.4/drivers/usb/core/generic.c 2014-07-07 03:59:25.000000000 +0200
  35951. +++ linux-rpi/drivers/usb/core/generic.c 2014-07-07 10:45:42.000000000 +0200
  35952. @@ -152,6 +152,7 @@
  35953. dev_warn(&udev->dev,
  35954. "no configuration chosen from %d choice%s\n",
  35955. num_configs, plural(num_configs));
  35956. + dev_warn(&udev->dev, "No support over %dmA\n", udev->bus_mA);
  35957. }
  35958. return i;
  35959. }
  35960. diff -Nur linux-3.15.4/drivers/usb/core/message.c linux-rpi/drivers/usb/core/message.c
  35961. --- linux-3.15.4/drivers/usb/core/message.c 2014-07-07 03:59:25.000000000 +0200
  35962. +++ linux-rpi/drivers/usb/core/message.c 2014-07-07 10:45:42.000000000 +0200
  35963. @@ -1891,6 +1891,85 @@
  35964. if (cp->string == NULL &&
  35965. !(dev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS))
  35966. cp->string = usb_cache_string(dev, cp->desc.iConfiguration);
  35967. +/* Uncomment this define to enable the HS Electrical Test support */
  35968. +#define DWC_HS_ELECT_TST 1
  35969. +#ifdef DWC_HS_ELECT_TST
  35970. + /* Here we implement the HS Electrical Test support. The
  35971. + * tester uses a vendor ID of 0x1A0A to indicate we should
  35972. + * run a special test sequence. The product ID tells us
  35973. + * which sequence to run. We invoke the test sequence by
  35974. + * sending a non-standard SetFeature command to our root
  35975. + * hub port. Our dwc_otg_hcd_hub_control() routine will
  35976. + * recognize the command and perform the desired test
  35977. + * sequence.
  35978. + */
  35979. + if (dev->descriptor.idVendor == 0x1A0A) {
  35980. + /* HSOTG Electrical Test */
  35981. + dev_warn(&dev->dev, "VID from HSOTG Electrical Test Fixture\n");
  35982. +
  35983. + if (dev->bus && dev->bus->root_hub) {
  35984. + struct usb_device *hdev = dev->bus->root_hub;
  35985. + dev_warn(&dev->dev, "Got PID 0x%x\n", dev->descriptor.idProduct);
  35986. +
  35987. + switch (dev->descriptor.idProduct) {
  35988. + case 0x0101: /* TEST_SE0_NAK */
  35989. + dev_warn(&dev->dev, "TEST_SE0_NAK\n");
  35990. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  35991. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  35992. + USB_PORT_FEAT_TEST, 0x300, NULL, 0, HZ);
  35993. + break;
  35994. +
  35995. + case 0x0102: /* TEST_J */
  35996. + dev_warn(&dev->dev, "TEST_J\n");
  35997. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  35998. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  35999. + USB_PORT_FEAT_TEST, 0x100, NULL, 0, HZ);
  36000. + break;
  36001. +
  36002. + case 0x0103: /* TEST_K */
  36003. + dev_warn(&dev->dev, "TEST_K\n");
  36004. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  36005. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  36006. + USB_PORT_FEAT_TEST, 0x200, NULL, 0, HZ);
  36007. + break;
  36008. +
  36009. + case 0x0104: /* TEST_PACKET */
  36010. + dev_warn(&dev->dev, "TEST_PACKET\n");
  36011. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  36012. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  36013. + USB_PORT_FEAT_TEST, 0x400, NULL, 0, HZ);
  36014. + break;
  36015. +
  36016. + case 0x0105: /* TEST_FORCE_ENABLE */
  36017. + dev_warn(&dev->dev, "TEST_FORCE_ENABLE\n");
  36018. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  36019. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  36020. + USB_PORT_FEAT_TEST, 0x500, NULL, 0, HZ);
  36021. + break;
  36022. +
  36023. + case 0x0106: /* HS_HOST_PORT_SUSPEND_RESUME */
  36024. + dev_warn(&dev->dev, "HS_HOST_PORT_SUSPEND_RESUME\n");
  36025. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  36026. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  36027. + USB_PORT_FEAT_TEST, 0x600, NULL, 0, 40 * HZ);
  36028. + break;
  36029. +
  36030. + case 0x0107: /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
  36031. + dev_warn(&dev->dev, "SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup\n");
  36032. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  36033. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  36034. + USB_PORT_FEAT_TEST, 0x700, NULL, 0, 40 * HZ);
  36035. + break;
  36036. +
  36037. + case 0x0108: /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
  36038. + dev_warn(&dev->dev, "SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute\n");
  36039. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  36040. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  36041. + USB_PORT_FEAT_TEST, 0x800, NULL, 0, 40 * HZ);
  36042. + }
  36043. + }
  36044. + }
  36045. +#endif /* DWC_HS_ELECT_TST */
  36046. /* Now that the interfaces are installed, re-enable LPM. */
  36047. usb_unlocked_enable_lpm(dev);
  36048. diff -Nur linux-3.15.4/drivers/usb/core/otg_whitelist.h linux-rpi/drivers/usb/core/otg_whitelist.h
  36049. --- linux-3.15.4/drivers/usb/core/otg_whitelist.h 2014-07-07 03:59:25.000000000 +0200
  36050. +++ linux-rpi/drivers/usb/core/otg_whitelist.h 2014-07-07 10:45:42.000000000 +0200
  36051. @@ -19,33 +19,82 @@
  36052. static struct usb_device_id whitelist_table [] = {
  36053. /* hubs are optional in OTG, but very handy ... */
  36054. +#define CERT_WITHOUT_HUBS
  36055. +#if defined(CERT_WITHOUT_HUBS)
  36056. +{ USB_DEVICE( 0x0000, 0x0000 ), }, /* Root HUB Only*/
  36057. +#else
  36058. { USB_DEVICE_INFO(USB_CLASS_HUB, 0, 0), },
  36059. { USB_DEVICE_INFO(USB_CLASS_HUB, 0, 1), },
  36060. +{ USB_DEVICE_INFO(USB_CLASS_HUB, 0, 2), },
  36061. +#endif
  36062. #ifdef CONFIG_USB_PRINTER /* ignoring nonstatic linkage! */
  36063. /* FIXME actually, printers are NOT supposed to use device classes;
  36064. * they're supposed to use interface classes...
  36065. */
  36066. -{ USB_DEVICE_INFO(7, 1, 1) },
  36067. -{ USB_DEVICE_INFO(7, 1, 2) },
  36068. -{ USB_DEVICE_INFO(7, 1, 3) },
  36069. +//{ USB_DEVICE_INFO(7, 1, 1) },
  36070. +//{ USB_DEVICE_INFO(7, 1, 2) },
  36071. +//{ USB_DEVICE_INFO(7, 1, 3) },
  36072. #endif
  36073. #ifdef CONFIG_USB_NET_CDCETHER
  36074. /* Linux-USB CDC Ethernet gadget */
  36075. -{ USB_DEVICE(0x0525, 0xa4a1), },
  36076. +//{ USB_DEVICE(0x0525, 0xa4a1), },
  36077. /* Linux-USB CDC Ethernet + RNDIS gadget */
  36078. -{ USB_DEVICE(0x0525, 0xa4a2), },
  36079. +//{ USB_DEVICE(0x0525, 0xa4a2), },
  36080. #endif
  36081. #if defined(CONFIG_USB_TEST) || defined(CONFIG_USB_TEST_MODULE)
  36082. /* gadget zero, for testing */
  36083. -{ USB_DEVICE(0x0525, 0xa4a0), },
  36084. +//{ USB_DEVICE(0x0525, 0xa4a0), },
  36085. #endif
  36086. +/* OPT Tester */
  36087. +{ USB_DEVICE( 0x1a0a, 0x0101 ), }, /* TEST_SE0_NAK */
  36088. +{ USB_DEVICE( 0x1a0a, 0x0102 ), }, /* Test_J */
  36089. +{ USB_DEVICE( 0x1a0a, 0x0103 ), }, /* Test_K */
  36090. +{ USB_DEVICE( 0x1a0a, 0x0104 ), }, /* Test_PACKET */
  36091. +{ USB_DEVICE( 0x1a0a, 0x0105 ), }, /* Test_FORCE_ENABLE */
  36092. +{ USB_DEVICE( 0x1a0a, 0x0106 ), }, /* HS_PORT_SUSPEND_RESUME */
  36093. +{ USB_DEVICE( 0x1a0a, 0x0107 ), }, /* SINGLE_STEP_GET_DESCRIPTOR setup */
  36094. +{ USB_DEVICE( 0x1a0a, 0x0108 ), }, /* SINGLE_STEP_GET_DESCRIPTOR execute */
  36095. +
  36096. +/* Sony cameras */
  36097. +{ USB_DEVICE_VER(0x054c,0x0010,0x0410, 0x0500), },
  36098. +
  36099. +/* Memory Devices */
  36100. +//{ USB_DEVICE( 0x0781, 0x5150 ), }, /* SanDisk */
  36101. +//{ USB_DEVICE( 0x05DC, 0x0080 ), }, /* Lexar */
  36102. +//{ USB_DEVICE( 0x4146, 0x9281 ), }, /* IOMEGA */
  36103. +//{ USB_DEVICE( 0x067b, 0x2507 ), }, /* Hammer 20GB External HD */
  36104. +{ USB_DEVICE( 0x0EA0, 0x2168 ), }, /* Ours Technology Inc. (BUFFALO ClipDrive)*/
  36105. +//{ USB_DEVICE( 0x0457, 0x0150 ), }, /* Silicon Integrated Systems Corp. */
  36106. +
  36107. +/* HP Printers */
  36108. +//{ USB_DEVICE( 0x03F0, 0x1102 ), }, /* HP Photosmart 245 */
  36109. +//{ USB_DEVICE( 0x03F0, 0x1302 ), }, /* HP Photosmart 370 Series */
  36110. +
  36111. +/* Speakers */
  36112. +//{ USB_DEVICE( 0x0499, 0x3002 ), }, /* YAMAHA YST-MS35D USB Speakers */
  36113. +//{ USB_DEVICE( 0x0672, 0x1041 ), }, /* Labtec USB Headset */
  36114. +
  36115. { } /* Terminating entry */
  36116. };
  36117. +static inline void report_errors(struct usb_device *dev)
  36118. +{
  36119. + /* OTG MESSAGE: report errors here, customize to match your product */
  36120. + dev_info(&dev->dev, "device Vendor:%04x Product:%04x is not supported\n",
  36121. + le16_to_cpu(dev->descriptor.idVendor),
  36122. + le16_to_cpu(dev->descriptor.idProduct));
  36123. + if (USB_CLASS_HUB == dev->descriptor.bDeviceClass){
  36124. + dev_printk(KERN_CRIT, &dev->dev, "Unsupported Hub Topology\n");
  36125. + } else {
  36126. + dev_printk(KERN_CRIT, &dev->dev, "Attached Device is not Supported\n");
  36127. + }
  36128. +}
  36129. +
  36130. +
  36131. static int is_targeted(struct usb_device *dev)
  36132. {
  36133. struct usb_device_id *id = whitelist_table;
  36134. @@ -55,58 +104,83 @@
  36135. return 1;
  36136. /* HNP test device is _never_ targeted (see OTG spec 6.6.6) */
  36137. - if ((le16_to_cpu(dev->descriptor.idVendor) == 0x1a0a &&
  36138. - le16_to_cpu(dev->descriptor.idProduct) == 0xbadd))
  36139. - return 0;
  36140. + if (dev->descriptor.idVendor == 0x1a0a &&
  36141. + dev->descriptor.idProduct == 0xbadd) {
  36142. + return 0;
  36143. + } else if (!enable_whitelist) {
  36144. + return 1;
  36145. + } else {
  36146. - /* NOTE: can't use usb_match_id() since interface caches
  36147. - * aren't set up yet. this is cut/paste from that code.
  36148. - */
  36149. - for (id = whitelist_table; id->match_flags; id++) {
  36150. - if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
  36151. - id->idVendor != le16_to_cpu(dev->descriptor.idVendor))
  36152. - continue;
  36153. -
  36154. - if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
  36155. - id->idProduct != le16_to_cpu(dev->descriptor.idProduct))
  36156. - continue;
  36157. -
  36158. - /* No need to test id->bcdDevice_lo != 0, since 0 is never
  36159. - greater than any unsigned number. */
  36160. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) &&
  36161. - (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice)))
  36162. - continue;
  36163. -
  36164. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) &&
  36165. - (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice)))
  36166. - continue;
  36167. -
  36168. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) &&
  36169. - (id->bDeviceClass != dev->descriptor.bDeviceClass))
  36170. - continue;
  36171. -
  36172. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
  36173. - (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))
  36174. - continue;
  36175. -
  36176. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
  36177. - (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
  36178. - continue;
  36179. +#ifdef DEBUG
  36180. + dev_dbg(&dev->dev, "device V:%04x P:%04x DC:%04x SC:%04x PR:%04x \n",
  36181. + dev->descriptor.idVendor,
  36182. + dev->descriptor.idProduct,
  36183. + dev->descriptor.bDeviceClass,
  36184. + dev->descriptor.bDeviceSubClass,
  36185. + dev->descriptor.bDeviceProtocol);
  36186. +#endif
  36187. return 1;
  36188. + /* NOTE: can't use usb_match_id() since interface caches
  36189. + * aren't set up yet. this is cut/paste from that code.
  36190. + */
  36191. + for (id = whitelist_table; id->match_flags; id++) {
  36192. +#ifdef DEBUG
  36193. + dev_dbg(&dev->dev,
  36194. + "ID: V:%04x P:%04x DC:%04x SC:%04x PR:%04x \n",
  36195. + id->idVendor,
  36196. + id->idProduct,
  36197. + id->bDeviceClass,
  36198. + id->bDeviceSubClass,
  36199. + id->bDeviceProtocol);
  36200. +#endif
  36201. +
  36202. + if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
  36203. + id->idVendor != le16_to_cpu(dev->descriptor.idVendor))
  36204. + continue;
  36205. +
  36206. + if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
  36207. + id->idProduct != le16_to_cpu(dev->descriptor.idProduct))
  36208. + continue;
  36209. +
  36210. + /* No need to test id->bcdDevice_lo != 0, since 0 is never
  36211. + greater than any unsigned number. */
  36212. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) &&
  36213. + (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice)))
  36214. + continue;
  36215. +
  36216. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) &&
  36217. + (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice)))
  36218. + continue;
  36219. +
  36220. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) &&
  36221. + (id->bDeviceClass != dev->descriptor.bDeviceClass))
  36222. + continue;
  36223. +
  36224. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
  36225. + (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))
  36226. + continue;
  36227. +
  36228. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
  36229. + (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
  36230. + continue;
  36231. +
  36232. + return 1;
  36233. + }
  36234. }
  36235. /* add other match criteria here ... */
  36236. -
  36237. - /* OTG MESSAGE: report errors here, customize to match your product */
  36238. - dev_err(&dev->dev, "device v%04x p%04x is not supported\n",
  36239. - le16_to_cpu(dev->descriptor.idVendor),
  36240. - le16_to_cpu(dev->descriptor.idProduct));
  36241. #ifdef CONFIG_USB_OTG_WHITELIST
  36242. + report_errors(dev);
  36243. return 0;
  36244. #else
  36245. - return 1;
  36246. + if (enable_whitelist) {
  36247. + report_errors(dev);
  36248. + return 0;
  36249. + } else {
  36250. + return 1;
  36251. + }
  36252. #endif
  36253. }
  36254. diff -Nur linux-3.15.4/drivers/usb/gadget/file_storage.c linux-rpi/drivers/usb/gadget/file_storage.c
  36255. --- linux-3.15.4/drivers/usb/gadget/file_storage.c 1970-01-01 01:00:00.000000000 +0100
  36256. +++ linux-rpi/drivers/usb/gadget/file_storage.c 2014-04-13 17:33:11.000000000 +0200
  36257. @@ -0,0 +1,3676 @@
  36258. +/*
  36259. + * file_storage.c -- File-backed USB Storage Gadget, for USB development
  36260. + *
  36261. + * Copyright (C) 2003-2008 Alan Stern
  36262. + * All rights reserved.
  36263. + *
  36264. + * Redistribution and use in source and binary forms, with or without
  36265. + * modification, are permitted provided that the following conditions
  36266. + * are met:
  36267. + * 1. Redistributions of source code must retain the above copyright
  36268. + * notice, this list of conditions, and the following disclaimer,
  36269. + * without modification.
  36270. + * 2. Redistributions in binary form must reproduce the above copyright
  36271. + * notice, this list of conditions and the following disclaimer in the
  36272. + * documentation and/or other materials provided with the distribution.
  36273. + * 3. The names of the above-listed copyright holders may not be used
  36274. + * to endorse or promote products derived from this software without
  36275. + * specific prior written permission.
  36276. + *
  36277. + * ALTERNATIVELY, this software may be distributed under the terms of the
  36278. + * GNU General Public License ("GPL") as published by the Free Software
  36279. + * Foundation, either version 2 of that License or (at your option) any
  36280. + * later version.
  36281. + *
  36282. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  36283. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  36284. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  36285. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  36286. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  36287. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  36288. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  36289. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  36290. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  36291. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  36292. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36293. + */
  36294. +
  36295. +
  36296. +/*
  36297. + * The File-backed Storage Gadget acts as a USB Mass Storage device,
  36298. + * appearing to the host as a disk drive or as a CD-ROM drive. In addition
  36299. + * to providing an example of a genuinely useful gadget driver for a USB
  36300. + * device, it also illustrates a technique of double-buffering for increased
  36301. + * throughput. Last but not least, it gives an easy way to probe the
  36302. + * behavior of the Mass Storage drivers in a USB host.
  36303. + *
  36304. + * Backing storage is provided by a regular file or a block device, specified
  36305. + * by the "file" module parameter. Access can be limited to read-only by
  36306. + * setting the optional "ro" module parameter. (For CD-ROM emulation,
  36307. + * access is always read-only.) The gadget will indicate that it has
  36308. + * removable media if the optional "removable" module parameter is set.
  36309. + *
  36310. + * The gadget supports the Control-Bulk (CB), Control-Bulk-Interrupt (CBI),
  36311. + * and Bulk-Only (also known as Bulk-Bulk-Bulk or BBB) transports, selected
  36312. + * by the optional "transport" module parameter. It also supports the
  36313. + * following protocols: RBC (0x01), ATAPI or SFF-8020i (0x02), QIC-157 (0c03),
  36314. + * UFI (0x04), SFF-8070i (0x05), and transparent SCSI (0x06), selected by
  36315. + * the optional "protocol" module parameter. In addition, the default
  36316. + * Vendor ID, Product ID, release number and serial number can be overridden.
  36317. + *
  36318. + * There is support for multiple logical units (LUNs), each of which has
  36319. + * its own backing file. The number of LUNs can be set using the optional
  36320. + * "luns" module parameter (anywhere from 1 to 8), and the corresponding
  36321. + * files are specified using comma-separated lists for "file" and "ro".
  36322. + * The default number of LUNs is taken from the number of "file" elements;
  36323. + * it is 1 if "file" is not given. If "removable" is not set then a backing
  36324. + * file must be specified for each LUN. If it is set, then an unspecified
  36325. + * or empty backing filename means the LUN's medium is not loaded. Ideally
  36326. + * each LUN would be settable independently as a disk drive or a CD-ROM
  36327. + * drive, but currently all LUNs have to be the same type. The CD-ROM
  36328. + * emulation includes a single data track and no audio tracks; hence there
  36329. + * need be only one backing file per LUN.
  36330. + *
  36331. + * Requirements are modest; only a bulk-in and a bulk-out endpoint are
  36332. + * needed (an interrupt-out endpoint is also needed for CBI). The memory
  36333. + * requirement amounts to two 16K buffers, size configurable by a parameter.
  36334. + * Support is included for both full-speed and high-speed operation.
  36335. + *
  36336. + * Note that the driver is slightly non-portable in that it assumes a
  36337. + * single memory/DMA buffer will be useable for bulk-in, bulk-out, and
  36338. + * interrupt-in endpoints. With most device controllers this isn't an
  36339. + * issue, but there may be some with hardware restrictions that prevent
  36340. + * a buffer from being used by more than one endpoint.
  36341. + *
  36342. + * Module options:
  36343. + *
  36344. + * file=filename[,filename...]
  36345. + * Required if "removable" is not set, names of
  36346. + * the files or block devices used for
  36347. + * backing storage
  36348. + * serial=HHHH... Required serial number (string of hex chars)
  36349. + * ro=b[,b...] Default false, booleans for read-only access
  36350. + * removable Default false, boolean for removable media
  36351. + * luns=N Default N = number of filenames, number of
  36352. + * LUNs to support
  36353. + * nofua=b[,b...] Default false, booleans for ignore FUA flag
  36354. + * in SCSI WRITE(10,12) commands
  36355. + * stall Default determined according to the type of
  36356. + * USB device controller (usually true),
  36357. + * boolean to permit the driver to halt
  36358. + * bulk endpoints
  36359. + * cdrom Default false, boolean for whether to emulate
  36360. + * a CD-ROM drive
  36361. + * transport=XXX Default BBB, transport name (CB, CBI, or BBB)
  36362. + * protocol=YYY Default SCSI, protocol name (RBC, 8020 or
  36363. + * ATAPI, QIC, UFI, 8070, or SCSI;
  36364. + * also 1 - 6)
  36365. + * vendor=0xVVVV Default 0x0525 (NetChip), USB Vendor ID
  36366. + * product=0xPPPP Default 0xa4a5 (FSG), USB Product ID
  36367. + * release=0xRRRR Override the USB release number (bcdDevice)
  36368. + * buflen=N Default N=16384, buffer size used (will be
  36369. + * rounded down to a multiple of
  36370. + * PAGE_CACHE_SIZE)
  36371. + *
  36372. + * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "serial", "ro",
  36373. + * "removable", "luns", "nofua", "stall", and "cdrom" options are available;
  36374. + * default values are used for everything else.
  36375. + *
  36376. + * The pathnames of the backing files and the ro settings are available in
  36377. + * the attribute files "file", "nofua", and "ro" in the lun<n> subdirectory of
  36378. + * the gadget's sysfs directory. If the "removable" option is set, writing to
  36379. + * these files will simulate ejecting/loading the medium (writing an empty
  36380. + * line means eject) and adjusting a write-enable tab. Changes to the ro
  36381. + * setting are not allowed when the medium is loaded or if CD-ROM emulation
  36382. + * is being used.
  36383. + *
  36384. + * This gadget driver is heavily based on "Gadget Zero" by David Brownell.
  36385. + * The driver's SCSI command interface was based on the "Information
  36386. + * technology - Small Computer System Interface - 2" document from
  36387. + * X3T9.2 Project 375D, Revision 10L, 7-SEP-93, available at
  36388. + * <http://www.t10.org/ftp/t10/drafts/s2/s2-r10l.pdf>. The single exception
  36389. + * is opcode 0x23 (READ FORMAT CAPACITIES), which was based on the
  36390. + * "Universal Serial Bus Mass Storage Class UFI Command Specification"
  36391. + * document, Revision 1.0, December 14, 1998, available at
  36392. + * <http://www.usb.org/developers/devclass_docs/usbmass-ufi10.pdf>.
  36393. + */
  36394. +
  36395. +
  36396. +/*
  36397. + * Driver Design
  36398. + *
  36399. + * The FSG driver is fairly straightforward. There is a main kernel
  36400. + * thread that handles most of the work. Interrupt routines field
  36401. + * callbacks from the controller driver: bulk- and interrupt-request
  36402. + * completion notifications, endpoint-0 events, and disconnect events.
  36403. + * Completion events are passed to the main thread by wakeup calls. Many
  36404. + * ep0 requests are handled at interrupt time, but SetInterface,
  36405. + * SetConfiguration, and device reset requests are forwarded to the
  36406. + * thread in the form of "exceptions" using SIGUSR1 signals (since they
  36407. + * should interrupt any ongoing file I/O operations).
  36408. + *
  36409. + * The thread's main routine implements the standard command/data/status
  36410. + * parts of a SCSI interaction. It and its subroutines are full of tests
  36411. + * for pending signals/exceptions -- all this polling is necessary since
  36412. + * the kernel has no setjmp/longjmp equivalents. (Maybe this is an
  36413. + * indication that the driver really wants to be running in userspace.)
  36414. + * An important point is that so long as the thread is alive it keeps an
  36415. + * open reference to the backing file. This will prevent unmounting
  36416. + * the backing file's underlying filesystem and could cause problems
  36417. + * during system shutdown, for example. To prevent such problems, the
  36418. + * thread catches INT, TERM, and KILL signals and converts them into
  36419. + * an EXIT exception.
  36420. + *
  36421. + * In normal operation the main thread is started during the gadget's
  36422. + * fsg_bind() callback and stopped during fsg_unbind(). But it can also
  36423. + * exit when it receives a signal, and there's no point leaving the
  36424. + * gadget running when the thread is dead. So just before the thread
  36425. + * exits, it deregisters the gadget driver. This makes things a little
  36426. + * tricky: The driver is deregistered at two places, and the exiting
  36427. + * thread can indirectly call fsg_unbind() which in turn can tell the
  36428. + * thread to exit. The first problem is resolved through the use of the
  36429. + * REGISTERED atomic bitflag; the driver will only be deregistered once.
  36430. + * The second problem is resolved by having fsg_unbind() check
  36431. + * fsg->state; it won't try to stop the thread if the state is already
  36432. + * FSG_STATE_TERMINATED.
  36433. + *
  36434. + * To provide maximum throughput, the driver uses a circular pipeline of
  36435. + * buffer heads (struct fsg_buffhd). In principle the pipeline can be
  36436. + * arbitrarily long; in practice the benefits don't justify having more
  36437. + * than 2 stages (i.e., double buffering). But it helps to think of the
  36438. + * pipeline as being a long one. Each buffer head contains a bulk-in and
  36439. + * a bulk-out request pointer (since the buffer can be used for both
  36440. + * output and input -- directions always are given from the host's
  36441. + * point of view) as well as a pointer to the buffer and various state
  36442. + * variables.
  36443. + *
  36444. + * Use of the pipeline follows a simple protocol. There is a variable
  36445. + * (fsg->next_buffhd_to_fill) that points to the next buffer head to use.
  36446. + * At any time that buffer head may still be in use from an earlier
  36447. + * request, so each buffer head has a state variable indicating whether
  36448. + * it is EMPTY, FULL, or BUSY. Typical use involves waiting for the
  36449. + * buffer head to be EMPTY, filling the buffer either by file I/O or by
  36450. + * USB I/O (during which the buffer head is BUSY), and marking the buffer
  36451. + * head FULL when the I/O is complete. Then the buffer will be emptied
  36452. + * (again possibly by USB I/O, during which it is marked BUSY) and
  36453. + * finally marked EMPTY again (possibly by a completion routine).
  36454. + *
  36455. + * A module parameter tells the driver to avoid stalling the bulk
  36456. + * endpoints wherever the transport specification allows. This is
  36457. + * necessary for some UDCs like the SuperH, which cannot reliably clear a
  36458. + * halt on a bulk endpoint. However, under certain circumstances the
  36459. + * Bulk-only specification requires a stall. In such cases the driver
  36460. + * will halt the endpoint and set a flag indicating that it should clear
  36461. + * the halt in software during the next device reset. Hopefully this
  36462. + * will permit everything to work correctly. Furthermore, although the
  36463. + * specification allows the bulk-out endpoint to halt when the host sends
  36464. + * too much data, implementing this would cause an unavoidable race.
  36465. + * The driver will always use the "no-stall" approach for OUT transfers.
  36466. + *
  36467. + * One subtle point concerns sending status-stage responses for ep0
  36468. + * requests. Some of these requests, such as device reset, can involve
  36469. + * interrupting an ongoing file I/O operation, which might take an
  36470. + * arbitrarily long time. During that delay the host might give up on
  36471. + * the original ep0 request and issue a new one. When that happens the
  36472. + * driver should not notify the host about completion of the original
  36473. + * request, as the host will no longer be waiting for it. So the driver
  36474. + * assigns to each ep0 request a unique tag, and it keeps track of the
  36475. + * tag value of the request associated with a long-running exception
  36476. + * (device-reset, interface-change, or configuration-change). When the
  36477. + * exception handler is finished, the status-stage response is submitted
  36478. + * only if the current ep0 request tag is equal to the exception request
  36479. + * tag. Thus only the most recently received ep0 request will get a
  36480. + * status-stage response.
  36481. + *
  36482. + * Warning: This driver source file is too long. It ought to be split up
  36483. + * into a header file plus about 3 separate .c files, to handle the details
  36484. + * of the Gadget, USB Mass Storage, and SCSI protocols.
  36485. + */
  36486. +
  36487. +
  36488. +/* #define VERBOSE_DEBUG */
  36489. +/* #define DUMP_MSGS */
  36490. +
  36491. +
  36492. +#include <linux/blkdev.h>
  36493. +#include <linux/completion.h>
  36494. +#include <linux/dcache.h>
  36495. +#include <linux/delay.h>
  36496. +#include <linux/device.h>
  36497. +#include <linux/fcntl.h>
  36498. +#include <linux/file.h>
  36499. +#include <linux/fs.h>
  36500. +#include <linux/kref.h>
  36501. +#include <linux/kthread.h>
  36502. +#include <linux/limits.h>
  36503. +#include <linux/module.h>
  36504. +#include <linux/rwsem.h>
  36505. +#include <linux/slab.h>
  36506. +#include <linux/spinlock.h>
  36507. +#include <linux/string.h>
  36508. +#include <linux/freezer.h>
  36509. +#include <linux/utsname.h>
  36510. +
  36511. +#include <linux/usb/ch9.h>
  36512. +#include <linux/usb/gadget.h>
  36513. +
  36514. +#include "gadget_chips.h"
  36515. +
  36516. +
  36517. +
  36518. +/*
  36519. + * Kbuild is not very cooperative with respect to linking separately
  36520. + * compiled library objects into one module. So for now we won't use
  36521. + * separate compilation ... ensuring init/exit sections work to shrink
  36522. + * the runtime footprint, and giving us at least some parts of what
  36523. + * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
  36524. + */
  36525. +#include "usbstring.c"
  36526. +#include "config.c"
  36527. +#include "epautoconf.c"
  36528. +
  36529. +/*-------------------------------------------------------------------------*/
  36530. +
  36531. +#define DRIVER_DESC "File-backed Storage Gadget"
  36532. +#define DRIVER_NAME "g_file_storage"
  36533. +#define DRIVER_VERSION "1 September 2010"
  36534. +
  36535. +static char fsg_string_manufacturer[64];
  36536. +static const char fsg_string_product[] = DRIVER_DESC;
  36537. +static const char fsg_string_config[] = "Self-powered";
  36538. +static const char fsg_string_interface[] = "Mass Storage";
  36539. +
  36540. +
  36541. +#include "storage_common.c"
  36542. +
  36543. +
  36544. +MODULE_DESCRIPTION(DRIVER_DESC);
  36545. +MODULE_AUTHOR("Alan Stern");
  36546. +MODULE_LICENSE("Dual BSD/GPL");
  36547. +
  36548. +/*
  36549. + * This driver assumes self-powered hardware and has no way for users to
  36550. + * trigger remote wakeup. It uses autoconfiguration to select endpoints
  36551. + * and endpoint addresses.
  36552. + */
  36553. +
  36554. +
  36555. +/*-------------------------------------------------------------------------*/
  36556. +
  36557. +
  36558. +/* Encapsulate the module parameter settings */
  36559. +
  36560. +static struct {
  36561. + char *file[FSG_MAX_LUNS];
  36562. + char *serial;
  36563. + bool ro[FSG_MAX_LUNS];
  36564. + bool nofua[FSG_MAX_LUNS];
  36565. + unsigned int num_filenames;
  36566. + unsigned int num_ros;
  36567. + unsigned int num_nofuas;
  36568. + unsigned int nluns;
  36569. +
  36570. + bool removable;
  36571. + bool can_stall;
  36572. + bool cdrom;
  36573. +
  36574. + char *transport_parm;
  36575. + char *protocol_parm;
  36576. + unsigned short vendor;
  36577. + unsigned short product;
  36578. + unsigned short release;
  36579. + unsigned int buflen;
  36580. +
  36581. + int transport_type;
  36582. + char *transport_name;
  36583. + int protocol_type;
  36584. + char *protocol_name;
  36585. +
  36586. +} mod_data = { // Default values
  36587. + .transport_parm = "BBB",
  36588. + .protocol_parm = "SCSI",
  36589. + .removable = 0,
  36590. + .can_stall = 1,
  36591. + .cdrom = 0,
  36592. + .vendor = FSG_VENDOR_ID,
  36593. + .product = FSG_PRODUCT_ID,
  36594. + .release = 0xffff, // Use controller chip type
  36595. + .buflen = 16384,
  36596. + };
  36597. +
  36598. +
  36599. +module_param_array_named(file, mod_data.file, charp, &mod_data.num_filenames,
  36600. + S_IRUGO);
  36601. +MODULE_PARM_DESC(file, "names of backing files or devices");
  36602. +
  36603. +module_param_named(serial, mod_data.serial, charp, S_IRUGO);
  36604. +MODULE_PARM_DESC(serial, "USB serial number");
  36605. +
  36606. +module_param_array_named(ro, mod_data.ro, bool, &mod_data.num_ros, S_IRUGO);
  36607. +MODULE_PARM_DESC(ro, "true to force read-only");
  36608. +
  36609. +module_param_array_named(nofua, mod_data.nofua, bool, &mod_data.num_nofuas,
  36610. + S_IRUGO);
  36611. +MODULE_PARM_DESC(nofua, "true to ignore SCSI WRITE(10,12) FUA bit");
  36612. +
  36613. +module_param_named(luns, mod_data.nluns, uint, S_IRUGO);
  36614. +MODULE_PARM_DESC(luns, "number of LUNs");
  36615. +
  36616. +module_param_named(removable, mod_data.removable, bool, S_IRUGO);
  36617. +MODULE_PARM_DESC(removable, "true to simulate removable media");
  36618. +
  36619. +module_param_named(stall, mod_data.can_stall, bool, S_IRUGO);
  36620. +MODULE_PARM_DESC(stall, "false to prevent bulk stalls");
  36621. +
  36622. +module_param_named(cdrom, mod_data.cdrom, bool, S_IRUGO);
  36623. +MODULE_PARM_DESC(cdrom, "true to emulate cdrom instead of disk");
  36624. +
  36625. +/* In the non-TEST version, only the module parameters listed above
  36626. + * are available. */
  36627. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  36628. +
  36629. +module_param_named(transport, mod_data.transport_parm, charp, S_IRUGO);
  36630. +MODULE_PARM_DESC(transport, "type of transport (BBB, CBI, or CB)");
  36631. +
  36632. +module_param_named(protocol, mod_data.protocol_parm, charp, S_IRUGO);
  36633. +MODULE_PARM_DESC(protocol, "type of protocol (RBC, 8020, QIC, UFI, "
  36634. + "8070, or SCSI)");
  36635. +
  36636. +module_param_named(vendor, mod_data.vendor, ushort, S_IRUGO);
  36637. +MODULE_PARM_DESC(vendor, "USB Vendor ID");
  36638. +
  36639. +module_param_named(product, mod_data.product, ushort, S_IRUGO);
  36640. +MODULE_PARM_DESC(product, "USB Product ID");
  36641. +
  36642. +module_param_named(release, mod_data.release, ushort, S_IRUGO);
  36643. +MODULE_PARM_DESC(release, "USB release number");
  36644. +
  36645. +module_param_named(buflen, mod_data.buflen, uint, S_IRUGO);
  36646. +MODULE_PARM_DESC(buflen, "I/O buffer size");
  36647. +
  36648. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  36649. +
  36650. +
  36651. +/*
  36652. + * These definitions will permit the compiler to avoid generating code for
  36653. + * parts of the driver that aren't used in the non-TEST version. Even gcc
  36654. + * can recognize when a test of a constant expression yields a dead code
  36655. + * path.
  36656. + */
  36657. +
  36658. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  36659. +
  36660. +#define transport_is_bbb() (mod_data.transport_type == USB_PR_BULK)
  36661. +#define transport_is_cbi() (mod_data.transport_type == USB_PR_CBI)
  36662. +#define protocol_is_scsi() (mod_data.protocol_type == USB_SC_SCSI)
  36663. +
  36664. +#else
  36665. +
  36666. +#define transport_is_bbb() 1
  36667. +#define transport_is_cbi() 0
  36668. +#define protocol_is_scsi() 1
  36669. +
  36670. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  36671. +
  36672. +
  36673. +/*-------------------------------------------------------------------------*/
  36674. +
  36675. +
  36676. +struct fsg_dev {
  36677. + /* lock protects: state, all the req_busy's, and cbbuf_cmnd */
  36678. + spinlock_t lock;
  36679. + struct usb_gadget *gadget;
  36680. +
  36681. + /* filesem protects: backing files in use */
  36682. + struct rw_semaphore filesem;
  36683. +
  36684. + /* reference counting: wait until all LUNs are released */
  36685. + struct kref ref;
  36686. +
  36687. + struct usb_ep *ep0; // Handy copy of gadget->ep0
  36688. + struct usb_request *ep0req; // For control responses
  36689. + unsigned int ep0_req_tag;
  36690. + const char *ep0req_name;
  36691. +
  36692. + struct usb_request *intreq; // For interrupt responses
  36693. + int intreq_busy;
  36694. + struct fsg_buffhd *intr_buffhd;
  36695. +
  36696. + unsigned int bulk_out_maxpacket;
  36697. + enum fsg_state state; // For exception handling
  36698. + unsigned int exception_req_tag;
  36699. +
  36700. + u8 config, new_config;
  36701. +
  36702. + unsigned int running : 1;
  36703. + unsigned int bulk_in_enabled : 1;
  36704. + unsigned int bulk_out_enabled : 1;
  36705. + unsigned int intr_in_enabled : 1;
  36706. + unsigned int phase_error : 1;
  36707. + unsigned int short_packet_received : 1;
  36708. + unsigned int bad_lun_okay : 1;
  36709. +
  36710. + unsigned long atomic_bitflags;
  36711. +#define REGISTERED 0
  36712. +#define IGNORE_BULK_OUT 1
  36713. +#define SUSPENDED 2
  36714. +
  36715. + struct usb_ep *bulk_in;
  36716. + struct usb_ep *bulk_out;
  36717. + struct usb_ep *intr_in;
  36718. +
  36719. + struct fsg_buffhd *next_buffhd_to_fill;
  36720. + struct fsg_buffhd *next_buffhd_to_drain;
  36721. +
  36722. + int thread_wakeup_needed;
  36723. + struct completion thread_notifier;
  36724. + struct task_struct *thread_task;
  36725. +
  36726. + int cmnd_size;
  36727. + u8 cmnd[MAX_COMMAND_SIZE];
  36728. + enum data_direction data_dir;
  36729. + u32 data_size;
  36730. + u32 data_size_from_cmnd;
  36731. + u32 tag;
  36732. + unsigned int lun;
  36733. + u32 residue;
  36734. + u32 usb_amount_left;
  36735. +
  36736. + /* The CB protocol offers no way for a host to know when a command
  36737. + * has completed. As a result the next command may arrive early,
  36738. + * and we will still have to handle it. For that reason we need
  36739. + * a buffer to store new commands when using CB (or CBI, which
  36740. + * does not oblige a host to wait for command completion either). */
  36741. + int cbbuf_cmnd_size;
  36742. + u8 cbbuf_cmnd[MAX_COMMAND_SIZE];
  36743. +
  36744. + unsigned int nluns;
  36745. + struct fsg_lun *luns;
  36746. + struct fsg_lun *curlun;
  36747. + /* Must be the last entry */
  36748. + struct fsg_buffhd buffhds[];
  36749. +};
  36750. +
  36751. +typedef void (*fsg_routine_t)(struct fsg_dev *);
  36752. +
  36753. +static int exception_in_progress(struct fsg_dev *fsg)
  36754. +{
  36755. + return (fsg->state > FSG_STATE_IDLE);
  36756. +}
  36757. +
  36758. +/* Make bulk-out requests be divisible by the maxpacket size */
  36759. +static void set_bulk_out_req_length(struct fsg_dev *fsg,
  36760. + struct fsg_buffhd *bh, unsigned int length)
  36761. +{
  36762. + unsigned int rem;
  36763. +
  36764. + bh->bulk_out_intended_length = length;
  36765. + rem = length % fsg->bulk_out_maxpacket;
  36766. + if (rem > 0)
  36767. + length += fsg->bulk_out_maxpacket - rem;
  36768. + bh->outreq->length = length;
  36769. +}
  36770. +
  36771. +static struct fsg_dev *the_fsg;
  36772. +static struct usb_gadget_driver fsg_driver;
  36773. +
  36774. +
  36775. +/*-------------------------------------------------------------------------*/
  36776. +
  36777. +static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep)
  36778. +{
  36779. + const char *name;
  36780. +
  36781. + if (ep == fsg->bulk_in)
  36782. + name = "bulk-in";
  36783. + else if (ep == fsg->bulk_out)
  36784. + name = "bulk-out";
  36785. + else
  36786. + name = ep->name;
  36787. + DBG(fsg, "%s set halt\n", name);
  36788. + return usb_ep_set_halt(ep);
  36789. +}
  36790. +
  36791. +
  36792. +/*-------------------------------------------------------------------------*/
  36793. +
  36794. +/*
  36795. + * DESCRIPTORS ... most are static, but strings and (full) configuration
  36796. + * descriptors are built on demand. Also the (static) config and interface
  36797. + * descriptors are adjusted during fsg_bind().
  36798. + */
  36799. +
  36800. +/* There is only one configuration. */
  36801. +#define CONFIG_VALUE 1
  36802. +
  36803. +static struct usb_device_descriptor
  36804. +device_desc = {
  36805. + .bLength = sizeof device_desc,
  36806. + .bDescriptorType = USB_DT_DEVICE,
  36807. +
  36808. + .bcdUSB = cpu_to_le16(0x0200),
  36809. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  36810. +
  36811. + /* The next three values can be overridden by module parameters */
  36812. + .idVendor = cpu_to_le16(FSG_VENDOR_ID),
  36813. + .idProduct = cpu_to_le16(FSG_PRODUCT_ID),
  36814. + .bcdDevice = cpu_to_le16(0xffff),
  36815. +
  36816. + .iManufacturer = FSG_STRING_MANUFACTURER,
  36817. + .iProduct = FSG_STRING_PRODUCT,
  36818. + .iSerialNumber = FSG_STRING_SERIAL,
  36819. + .bNumConfigurations = 1,
  36820. +};
  36821. +
  36822. +static struct usb_config_descriptor
  36823. +config_desc = {
  36824. + .bLength = sizeof config_desc,
  36825. + .bDescriptorType = USB_DT_CONFIG,
  36826. +
  36827. + /* wTotalLength computed by usb_gadget_config_buf() */
  36828. + .bNumInterfaces = 1,
  36829. + .bConfigurationValue = CONFIG_VALUE,
  36830. + .iConfiguration = FSG_STRING_CONFIG,
  36831. + .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
  36832. + .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2,
  36833. +};
  36834. +
  36835. +
  36836. +static struct usb_qualifier_descriptor
  36837. +dev_qualifier = {
  36838. + .bLength = sizeof dev_qualifier,
  36839. + .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
  36840. +
  36841. + .bcdUSB = cpu_to_le16(0x0200),
  36842. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  36843. +
  36844. + .bNumConfigurations = 1,
  36845. +};
  36846. +
  36847. +static int populate_bos(struct fsg_dev *fsg, u8 *buf)
  36848. +{
  36849. + memcpy(buf, &fsg_bos_desc, USB_DT_BOS_SIZE);
  36850. + buf += USB_DT_BOS_SIZE;
  36851. +
  36852. + memcpy(buf, &fsg_ext_cap_desc, USB_DT_USB_EXT_CAP_SIZE);
  36853. + buf += USB_DT_USB_EXT_CAP_SIZE;
  36854. +
  36855. + memcpy(buf, &fsg_ss_cap_desc, USB_DT_USB_SS_CAP_SIZE);
  36856. +
  36857. + return USB_DT_BOS_SIZE + USB_DT_USB_SS_CAP_SIZE
  36858. + + USB_DT_USB_EXT_CAP_SIZE;
  36859. +}
  36860. +
  36861. +/*
  36862. + * Config descriptors must agree with the code that sets configurations
  36863. + * and with code managing interfaces and their altsettings. They must
  36864. + * also handle different speeds and other-speed requests.
  36865. + */
  36866. +static int populate_config_buf(struct usb_gadget *gadget,
  36867. + u8 *buf, u8 type, unsigned index)
  36868. +{
  36869. + enum usb_device_speed speed = gadget->speed;
  36870. + int len;
  36871. + const struct usb_descriptor_header **function;
  36872. +
  36873. + if (index > 0)
  36874. + return -EINVAL;
  36875. +
  36876. + if (gadget_is_dualspeed(gadget) && type == USB_DT_OTHER_SPEED_CONFIG)
  36877. + speed = (USB_SPEED_FULL + USB_SPEED_HIGH) - speed;
  36878. + function = gadget_is_dualspeed(gadget) && speed == USB_SPEED_HIGH
  36879. + ? (const struct usb_descriptor_header **)fsg_hs_function
  36880. + : (const struct usb_descriptor_header **)fsg_fs_function;
  36881. +
  36882. + /* for now, don't advertise srp-only devices */
  36883. + if (!gadget_is_otg(gadget))
  36884. + function++;
  36885. +
  36886. + len = usb_gadget_config_buf(&config_desc, buf, EP0_BUFSIZE, function);
  36887. + ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
  36888. + return len;
  36889. +}
  36890. +
  36891. +
  36892. +/*-------------------------------------------------------------------------*/
  36893. +
  36894. +/* These routines may be called in process context or in_irq */
  36895. +
  36896. +/* Caller must hold fsg->lock */
  36897. +static void wakeup_thread(struct fsg_dev *fsg)
  36898. +{
  36899. + /* Tell the main thread that something has happened */
  36900. + fsg->thread_wakeup_needed = 1;
  36901. + if (fsg->thread_task)
  36902. + wake_up_process(fsg->thread_task);
  36903. +}
  36904. +
  36905. +
  36906. +static void raise_exception(struct fsg_dev *fsg, enum fsg_state new_state)
  36907. +{
  36908. + unsigned long flags;
  36909. +
  36910. + /* Do nothing if a higher-priority exception is already in progress.
  36911. + * If a lower-or-equal priority exception is in progress, preempt it
  36912. + * and notify the main thread by sending it a signal. */
  36913. + spin_lock_irqsave(&fsg->lock, flags);
  36914. + if (fsg->state <= new_state) {
  36915. + fsg->exception_req_tag = fsg->ep0_req_tag;
  36916. + fsg->state = new_state;
  36917. + if (fsg->thread_task)
  36918. + send_sig_info(SIGUSR1, SEND_SIG_FORCED,
  36919. + fsg->thread_task);
  36920. + }
  36921. + spin_unlock_irqrestore(&fsg->lock, flags);
  36922. +}
  36923. +
  36924. +
  36925. +/*-------------------------------------------------------------------------*/
  36926. +
  36927. +/* The disconnect callback and ep0 routines. These always run in_irq,
  36928. + * except that ep0_queue() is called in the main thread to acknowledge
  36929. + * completion of various requests: set config, set interface, and
  36930. + * Bulk-only device reset. */
  36931. +
  36932. +static void fsg_disconnect(struct usb_gadget *gadget)
  36933. +{
  36934. + struct fsg_dev *fsg = get_gadget_data(gadget);
  36935. +
  36936. + DBG(fsg, "disconnect or port reset\n");
  36937. + raise_exception(fsg, FSG_STATE_DISCONNECT);
  36938. +}
  36939. +
  36940. +
  36941. +static int ep0_queue(struct fsg_dev *fsg)
  36942. +{
  36943. + int rc;
  36944. +
  36945. + rc = usb_ep_queue(fsg->ep0, fsg->ep0req, GFP_ATOMIC);
  36946. + if (rc != 0 && rc != -ESHUTDOWN) {
  36947. +
  36948. + /* We can't do much more than wait for a reset */
  36949. + WARNING(fsg, "error in submission: %s --> %d\n",
  36950. + fsg->ep0->name, rc);
  36951. + }
  36952. + return rc;
  36953. +}
  36954. +
  36955. +static void ep0_complete(struct usb_ep *ep, struct usb_request *req)
  36956. +{
  36957. + struct fsg_dev *fsg = ep->driver_data;
  36958. +
  36959. + if (req->actual > 0)
  36960. + dump_msg(fsg, fsg->ep0req_name, req->buf, req->actual);
  36961. + if (req->status || req->actual != req->length)
  36962. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  36963. + req->status, req->actual, req->length);
  36964. + if (req->status == -ECONNRESET) // Request was cancelled
  36965. + usb_ep_fifo_flush(ep);
  36966. +
  36967. + if (req->status == 0 && req->context)
  36968. + ((fsg_routine_t) (req->context))(fsg);
  36969. +}
  36970. +
  36971. +
  36972. +/*-------------------------------------------------------------------------*/
  36973. +
  36974. +/* Bulk and interrupt endpoint completion handlers.
  36975. + * These always run in_irq. */
  36976. +
  36977. +static void bulk_in_complete(struct usb_ep *ep, struct usb_request *req)
  36978. +{
  36979. + struct fsg_dev *fsg = ep->driver_data;
  36980. + struct fsg_buffhd *bh = req->context;
  36981. +
  36982. + if (req->status || req->actual != req->length)
  36983. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  36984. + req->status, req->actual, req->length);
  36985. + if (req->status == -ECONNRESET) // Request was cancelled
  36986. + usb_ep_fifo_flush(ep);
  36987. +
  36988. + /* Hold the lock while we update the request and buffer states */
  36989. + smp_wmb();
  36990. + spin_lock(&fsg->lock);
  36991. + bh->inreq_busy = 0;
  36992. + bh->state = BUF_STATE_EMPTY;
  36993. + wakeup_thread(fsg);
  36994. + spin_unlock(&fsg->lock);
  36995. +}
  36996. +
  36997. +static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req)
  36998. +{
  36999. + struct fsg_dev *fsg = ep->driver_data;
  37000. + struct fsg_buffhd *bh = req->context;
  37001. +
  37002. + dump_msg(fsg, "bulk-out", req->buf, req->actual);
  37003. + if (req->status || req->actual != bh->bulk_out_intended_length)
  37004. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  37005. + req->status, req->actual,
  37006. + bh->bulk_out_intended_length);
  37007. + if (req->status == -ECONNRESET) // Request was cancelled
  37008. + usb_ep_fifo_flush(ep);
  37009. +
  37010. + /* Hold the lock while we update the request and buffer states */
  37011. + smp_wmb();
  37012. + spin_lock(&fsg->lock);
  37013. + bh->outreq_busy = 0;
  37014. + bh->state = BUF_STATE_FULL;
  37015. + wakeup_thread(fsg);
  37016. + spin_unlock(&fsg->lock);
  37017. +}
  37018. +
  37019. +
  37020. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  37021. +static void intr_in_complete(struct usb_ep *ep, struct usb_request *req)
  37022. +{
  37023. + struct fsg_dev *fsg = ep->driver_data;
  37024. + struct fsg_buffhd *bh = req->context;
  37025. +
  37026. + if (req->status || req->actual != req->length)
  37027. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  37028. + req->status, req->actual, req->length);
  37029. + if (req->status == -ECONNRESET) // Request was cancelled
  37030. + usb_ep_fifo_flush(ep);
  37031. +
  37032. + /* Hold the lock while we update the request and buffer states */
  37033. + smp_wmb();
  37034. + spin_lock(&fsg->lock);
  37035. + fsg->intreq_busy = 0;
  37036. + bh->state = BUF_STATE_EMPTY;
  37037. + wakeup_thread(fsg);
  37038. + spin_unlock(&fsg->lock);
  37039. +}
  37040. +
  37041. +#else
  37042. +static void intr_in_complete(struct usb_ep *ep, struct usb_request *req)
  37043. +{}
  37044. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  37045. +
  37046. +
  37047. +/*-------------------------------------------------------------------------*/
  37048. +
  37049. +/* Ep0 class-specific handlers. These always run in_irq. */
  37050. +
  37051. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  37052. +static void received_cbi_adsc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37053. +{
  37054. + struct usb_request *req = fsg->ep0req;
  37055. + static u8 cbi_reset_cmnd[6] = {
  37056. + SEND_DIAGNOSTIC, 4, 0xff, 0xff, 0xff, 0xff};
  37057. +
  37058. + /* Error in command transfer? */
  37059. + if (req->status || req->length != req->actual ||
  37060. + req->actual < 6 || req->actual > MAX_COMMAND_SIZE) {
  37061. +
  37062. + /* Not all controllers allow a protocol stall after
  37063. + * receiving control-out data, but we'll try anyway. */
  37064. + fsg_set_halt(fsg, fsg->ep0);
  37065. + return; // Wait for reset
  37066. + }
  37067. +
  37068. + /* Is it the special reset command? */
  37069. + if (req->actual >= sizeof cbi_reset_cmnd &&
  37070. + memcmp(req->buf, cbi_reset_cmnd,
  37071. + sizeof cbi_reset_cmnd) == 0) {
  37072. +
  37073. + /* Raise an exception to stop the current operation
  37074. + * and reinitialize our state. */
  37075. + DBG(fsg, "cbi reset request\n");
  37076. + raise_exception(fsg, FSG_STATE_RESET);
  37077. + return;
  37078. + }
  37079. +
  37080. + VDBG(fsg, "CB[I] accept device-specific command\n");
  37081. + spin_lock(&fsg->lock);
  37082. +
  37083. + /* Save the command for later */
  37084. + if (fsg->cbbuf_cmnd_size)
  37085. + WARNING(fsg, "CB[I] overwriting previous command\n");
  37086. + fsg->cbbuf_cmnd_size = req->actual;
  37087. + memcpy(fsg->cbbuf_cmnd, req->buf, fsg->cbbuf_cmnd_size);
  37088. +
  37089. + wakeup_thread(fsg);
  37090. + spin_unlock(&fsg->lock);
  37091. +}
  37092. +
  37093. +#else
  37094. +static void received_cbi_adsc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37095. +{}
  37096. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  37097. +
  37098. +
  37099. +static int class_setup_req(struct fsg_dev *fsg,
  37100. + const struct usb_ctrlrequest *ctrl)
  37101. +{
  37102. + struct usb_request *req = fsg->ep0req;
  37103. + int value = -EOPNOTSUPP;
  37104. + u16 w_index = le16_to_cpu(ctrl->wIndex);
  37105. + u16 w_value = le16_to_cpu(ctrl->wValue);
  37106. + u16 w_length = le16_to_cpu(ctrl->wLength);
  37107. +
  37108. + if (!fsg->config)
  37109. + return value;
  37110. +
  37111. + /* Handle Bulk-only class-specific requests */
  37112. + if (transport_is_bbb()) {
  37113. + switch (ctrl->bRequest) {
  37114. +
  37115. + case US_BULK_RESET_REQUEST:
  37116. + if (ctrl->bRequestType != (USB_DIR_OUT |
  37117. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  37118. + break;
  37119. + if (w_index != 0 || w_value != 0 || w_length != 0) {
  37120. + value = -EDOM;
  37121. + break;
  37122. + }
  37123. +
  37124. + /* Raise an exception to stop the current operation
  37125. + * and reinitialize our state. */
  37126. + DBG(fsg, "bulk reset request\n");
  37127. + raise_exception(fsg, FSG_STATE_RESET);
  37128. + value = DELAYED_STATUS;
  37129. + break;
  37130. +
  37131. + case US_BULK_GET_MAX_LUN:
  37132. + if (ctrl->bRequestType != (USB_DIR_IN |
  37133. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  37134. + break;
  37135. + if (w_index != 0 || w_value != 0 || w_length != 1) {
  37136. + value = -EDOM;
  37137. + break;
  37138. + }
  37139. + VDBG(fsg, "get max LUN\n");
  37140. + *(u8 *) req->buf = fsg->nluns - 1;
  37141. + value = 1;
  37142. + break;
  37143. + }
  37144. + }
  37145. +
  37146. + /* Handle CBI class-specific requests */
  37147. + else {
  37148. + switch (ctrl->bRequest) {
  37149. +
  37150. + case USB_CBI_ADSC_REQUEST:
  37151. + if (ctrl->bRequestType != (USB_DIR_OUT |
  37152. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  37153. + break;
  37154. + if (w_index != 0 || w_value != 0) {
  37155. + value = -EDOM;
  37156. + break;
  37157. + }
  37158. + if (w_length > MAX_COMMAND_SIZE) {
  37159. + value = -EOVERFLOW;
  37160. + break;
  37161. + }
  37162. + value = w_length;
  37163. + fsg->ep0req->context = received_cbi_adsc;
  37164. + break;
  37165. + }
  37166. + }
  37167. +
  37168. + if (value == -EOPNOTSUPP)
  37169. + VDBG(fsg,
  37170. + "unknown class-specific control req "
  37171. + "%02x.%02x v%04x i%04x l%u\n",
  37172. + ctrl->bRequestType, ctrl->bRequest,
  37173. + le16_to_cpu(ctrl->wValue), w_index, w_length);
  37174. + return value;
  37175. +}
  37176. +
  37177. +
  37178. +/*-------------------------------------------------------------------------*/
  37179. +
  37180. +/* Ep0 standard request handlers. These always run in_irq. */
  37181. +
  37182. +static int standard_setup_req(struct fsg_dev *fsg,
  37183. + const struct usb_ctrlrequest *ctrl)
  37184. +{
  37185. + struct usb_request *req = fsg->ep0req;
  37186. + int value = -EOPNOTSUPP;
  37187. + u16 w_index = le16_to_cpu(ctrl->wIndex);
  37188. + u16 w_value = le16_to_cpu(ctrl->wValue);
  37189. +
  37190. + /* Usually this just stores reply data in the pre-allocated ep0 buffer,
  37191. + * but config change events will also reconfigure hardware. */
  37192. + switch (ctrl->bRequest) {
  37193. +
  37194. + case USB_REQ_GET_DESCRIPTOR:
  37195. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  37196. + USB_RECIP_DEVICE))
  37197. + break;
  37198. + switch (w_value >> 8) {
  37199. +
  37200. + case USB_DT_DEVICE:
  37201. + VDBG(fsg, "get device descriptor\n");
  37202. + device_desc.bMaxPacketSize0 = fsg->ep0->maxpacket;
  37203. + value = sizeof device_desc;
  37204. + memcpy(req->buf, &device_desc, value);
  37205. + break;
  37206. + case USB_DT_DEVICE_QUALIFIER:
  37207. + VDBG(fsg, "get device qualifier\n");
  37208. + if (!gadget_is_dualspeed(fsg->gadget) ||
  37209. + fsg->gadget->speed == USB_SPEED_SUPER)
  37210. + break;
  37211. + /*
  37212. + * Assume ep0 uses the same maxpacket value for both
  37213. + * speeds
  37214. + */
  37215. + dev_qualifier.bMaxPacketSize0 = fsg->ep0->maxpacket;
  37216. + value = sizeof dev_qualifier;
  37217. + memcpy(req->buf, &dev_qualifier, value);
  37218. + break;
  37219. +
  37220. + case USB_DT_OTHER_SPEED_CONFIG:
  37221. + VDBG(fsg, "get other-speed config descriptor\n");
  37222. + if (!gadget_is_dualspeed(fsg->gadget) ||
  37223. + fsg->gadget->speed == USB_SPEED_SUPER)
  37224. + break;
  37225. + goto get_config;
  37226. + case USB_DT_CONFIG:
  37227. + VDBG(fsg, "get configuration descriptor\n");
  37228. +get_config:
  37229. + value = populate_config_buf(fsg->gadget,
  37230. + req->buf,
  37231. + w_value >> 8,
  37232. + w_value & 0xff);
  37233. + break;
  37234. +
  37235. + case USB_DT_STRING:
  37236. + VDBG(fsg, "get string descriptor\n");
  37237. +
  37238. + /* wIndex == language code */
  37239. + value = usb_gadget_get_string(&fsg_stringtab,
  37240. + w_value & 0xff, req->buf);
  37241. + break;
  37242. +
  37243. + case USB_DT_BOS:
  37244. + VDBG(fsg, "get bos descriptor\n");
  37245. +
  37246. + if (gadget_is_superspeed(fsg->gadget))
  37247. + value = populate_bos(fsg, req->buf);
  37248. + break;
  37249. + }
  37250. +
  37251. + break;
  37252. +
  37253. + /* One config, two speeds */
  37254. + case USB_REQ_SET_CONFIGURATION:
  37255. + if (ctrl->bRequestType != (USB_DIR_OUT | USB_TYPE_STANDARD |
  37256. + USB_RECIP_DEVICE))
  37257. + break;
  37258. + VDBG(fsg, "set configuration\n");
  37259. + if (w_value == CONFIG_VALUE || w_value == 0) {
  37260. + fsg->new_config = w_value;
  37261. +
  37262. + /* Raise an exception to wipe out previous transaction
  37263. + * state (queued bufs, etc) and set the new config. */
  37264. + raise_exception(fsg, FSG_STATE_CONFIG_CHANGE);
  37265. + value = DELAYED_STATUS;
  37266. + }
  37267. + break;
  37268. + case USB_REQ_GET_CONFIGURATION:
  37269. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  37270. + USB_RECIP_DEVICE))
  37271. + break;
  37272. + VDBG(fsg, "get configuration\n");
  37273. + *(u8 *) req->buf = fsg->config;
  37274. + value = 1;
  37275. + break;
  37276. +
  37277. + case USB_REQ_SET_INTERFACE:
  37278. + if (ctrl->bRequestType != (USB_DIR_OUT| USB_TYPE_STANDARD |
  37279. + USB_RECIP_INTERFACE))
  37280. + break;
  37281. + if (fsg->config && w_index == 0) {
  37282. +
  37283. + /* Raise an exception to wipe out previous transaction
  37284. + * state (queued bufs, etc) and install the new
  37285. + * interface altsetting. */
  37286. + raise_exception(fsg, FSG_STATE_INTERFACE_CHANGE);
  37287. + value = DELAYED_STATUS;
  37288. + }
  37289. + break;
  37290. + case USB_REQ_GET_INTERFACE:
  37291. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  37292. + USB_RECIP_INTERFACE))
  37293. + break;
  37294. + if (!fsg->config)
  37295. + break;
  37296. + if (w_index != 0) {
  37297. + value = -EDOM;
  37298. + break;
  37299. + }
  37300. + VDBG(fsg, "get interface\n");
  37301. + *(u8 *) req->buf = 0;
  37302. + value = 1;
  37303. + break;
  37304. +
  37305. + default:
  37306. + VDBG(fsg,
  37307. + "unknown control req %02x.%02x v%04x i%04x l%u\n",
  37308. + ctrl->bRequestType, ctrl->bRequest,
  37309. + w_value, w_index, le16_to_cpu(ctrl->wLength));
  37310. + }
  37311. +
  37312. + return value;
  37313. +}
  37314. +
  37315. +
  37316. +static int fsg_setup(struct usb_gadget *gadget,
  37317. + const struct usb_ctrlrequest *ctrl)
  37318. +{
  37319. + struct fsg_dev *fsg = get_gadget_data(gadget);
  37320. + int rc;
  37321. + int w_length = le16_to_cpu(ctrl->wLength);
  37322. +
  37323. + ++fsg->ep0_req_tag; // Record arrival of a new request
  37324. + fsg->ep0req->context = NULL;
  37325. + fsg->ep0req->length = 0;
  37326. + dump_msg(fsg, "ep0-setup", (u8 *) ctrl, sizeof(*ctrl));
  37327. +
  37328. + if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_CLASS)
  37329. + rc = class_setup_req(fsg, ctrl);
  37330. + else
  37331. + rc = standard_setup_req(fsg, ctrl);
  37332. +
  37333. + /* Respond with data/status or defer until later? */
  37334. + if (rc >= 0 && rc != DELAYED_STATUS) {
  37335. + rc = min(rc, w_length);
  37336. + fsg->ep0req->length = rc;
  37337. + fsg->ep0req->zero = rc < w_length;
  37338. + fsg->ep0req_name = (ctrl->bRequestType & USB_DIR_IN ?
  37339. + "ep0-in" : "ep0-out");
  37340. + rc = ep0_queue(fsg);
  37341. + }
  37342. +
  37343. + /* Device either stalls (rc < 0) or reports success */
  37344. + return rc;
  37345. +}
  37346. +
  37347. +
  37348. +/*-------------------------------------------------------------------------*/
  37349. +
  37350. +/* All the following routines run in process context */
  37351. +
  37352. +
  37353. +/* Use this for bulk or interrupt transfers, not ep0 */
  37354. +static void start_transfer(struct fsg_dev *fsg, struct usb_ep *ep,
  37355. + struct usb_request *req, int *pbusy,
  37356. + enum fsg_buffer_state *state)
  37357. +{
  37358. + int rc;
  37359. +
  37360. + if (ep == fsg->bulk_in)
  37361. + dump_msg(fsg, "bulk-in", req->buf, req->length);
  37362. + else if (ep == fsg->intr_in)
  37363. + dump_msg(fsg, "intr-in", req->buf, req->length);
  37364. +
  37365. + spin_lock_irq(&fsg->lock);
  37366. + *pbusy = 1;
  37367. + *state = BUF_STATE_BUSY;
  37368. + spin_unlock_irq(&fsg->lock);
  37369. + rc = usb_ep_queue(ep, req, GFP_KERNEL);
  37370. + if (rc != 0) {
  37371. + *pbusy = 0;
  37372. + *state = BUF_STATE_EMPTY;
  37373. +
  37374. + /* We can't do much more than wait for a reset */
  37375. +
  37376. + /* Note: currently the net2280 driver fails zero-length
  37377. + * submissions if DMA is enabled. */
  37378. + if (rc != -ESHUTDOWN && !(rc == -EOPNOTSUPP &&
  37379. + req->length == 0))
  37380. + WARNING(fsg, "error in submission: %s --> %d\n",
  37381. + ep->name, rc);
  37382. + }
  37383. +}
  37384. +
  37385. +
  37386. +static int sleep_thread(struct fsg_dev *fsg)
  37387. +{
  37388. + int rc = 0;
  37389. +
  37390. + /* Wait until a signal arrives or we are woken up */
  37391. + for (;;) {
  37392. + try_to_freeze();
  37393. + set_current_state(TASK_INTERRUPTIBLE);
  37394. + if (signal_pending(current)) {
  37395. + rc = -EINTR;
  37396. + break;
  37397. + }
  37398. + if (fsg->thread_wakeup_needed)
  37399. + break;
  37400. + schedule();
  37401. + }
  37402. + __set_current_state(TASK_RUNNING);
  37403. + fsg->thread_wakeup_needed = 0;
  37404. + return rc;
  37405. +}
  37406. +
  37407. +
  37408. +/*-------------------------------------------------------------------------*/
  37409. +
  37410. +static int do_read(struct fsg_dev *fsg)
  37411. +{
  37412. + struct fsg_lun *curlun = fsg->curlun;
  37413. + u32 lba;
  37414. + struct fsg_buffhd *bh;
  37415. + int rc;
  37416. + u32 amount_left;
  37417. + loff_t file_offset, file_offset_tmp;
  37418. + unsigned int amount;
  37419. + ssize_t nread;
  37420. +
  37421. + /* Get the starting Logical Block Address and check that it's
  37422. + * not too big */
  37423. + if (fsg->cmnd[0] == READ_6)
  37424. + lba = get_unaligned_be24(&fsg->cmnd[1]);
  37425. + else {
  37426. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  37427. +
  37428. + /* We allow DPO (Disable Page Out = don't save data in the
  37429. + * cache) and FUA (Force Unit Access = don't read from the
  37430. + * cache), but we don't implement them. */
  37431. + if ((fsg->cmnd[1] & ~0x18) != 0) {
  37432. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37433. + return -EINVAL;
  37434. + }
  37435. + }
  37436. + if (lba >= curlun->num_sectors) {
  37437. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  37438. + return -EINVAL;
  37439. + }
  37440. + file_offset = ((loff_t) lba) << curlun->blkbits;
  37441. +
  37442. + /* Carry out the file reads */
  37443. + amount_left = fsg->data_size_from_cmnd;
  37444. + if (unlikely(amount_left == 0))
  37445. + return -EIO; // No default reply
  37446. +
  37447. + for (;;) {
  37448. +
  37449. + /* Figure out how much we need to read:
  37450. + * Try to read the remaining amount.
  37451. + * But don't read more than the buffer size.
  37452. + * And don't try to read past the end of the file.
  37453. + */
  37454. + amount = min((unsigned int) amount_left, mod_data.buflen);
  37455. + amount = min((loff_t) amount,
  37456. + curlun->file_length - file_offset);
  37457. +
  37458. + /* Wait for the next buffer to become available */
  37459. + bh = fsg->next_buffhd_to_fill;
  37460. + while (bh->state != BUF_STATE_EMPTY) {
  37461. + rc = sleep_thread(fsg);
  37462. + if (rc)
  37463. + return rc;
  37464. + }
  37465. +
  37466. + /* If we were asked to read past the end of file,
  37467. + * end with an empty buffer. */
  37468. + if (amount == 0) {
  37469. + curlun->sense_data =
  37470. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  37471. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  37472. + curlun->info_valid = 1;
  37473. + bh->inreq->length = 0;
  37474. + bh->state = BUF_STATE_FULL;
  37475. + break;
  37476. + }
  37477. +
  37478. + /* Perform the read */
  37479. + file_offset_tmp = file_offset;
  37480. + nread = vfs_read(curlun->filp,
  37481. + (char __user *) bh->buf,
  37482. + amount, &file_offset_tmp);
  37483. + VLDBG(curlun, "file read %u @ %llu -> %d\n", amount,
  37484. + (unsigned long long) file_offset,
  37485. + (int) nread);
  37486. + if (signal_pending(current))
  37487. + return -EINTR;
  37488. +
  37489. + if (nread < 0) {
  37490. + LDBG(curlun, "error in file read: %d\n",
  37491. + (int) nread);
  37492. + nread = 0;
  37493. + } else if (nread < amount) {
  37494. + LDBG(curlun, "partial file read: %d/%u\n",
  37495. + (int) nread, amount);
  37496. + nread = round_down(nread, curlun->blksize);
  37497. + }
  37498. + file_offset += nread;
  37499. + amount_left -= nread;
  37500. + fsg->residue -= nread;
  37501. +
  37502. + /* Except at the end of the transfer, nread will be
  37503. + * equal to the buffer size, which is divisible by the
  37504. + * bulk-in maxpacket size.
  37505. + */
  37506. + bh->inreq->length = nread;
  37507. + bh->state = BUF_STATE_FULL;
  37508. +
  37509. + /* If an error occurred, report it and its position */
  37510. + if (nread < amount) {
  37511. + curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
  37512. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  37513. + curlun->info_valid = 1;
  37514. + break;
  37515. + }
  37516. +
  37517. + if (amount_left == 0)
  37518. + break; // No more left to read
  37519. +
  37520. + /* Send this buffer and go read some more */
  37521. + bh->inreq->zero = 0;
  37522. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  37523. + &bh->inreq_busy, &bh->state);
  37524. + fsg->next_buffhd_to_fill = bh->next;
  37525. + }
  37526. +
  37527. + return -EIO; // No default reply
  37528. +}
  37529. +
  37530. +
  37531. +/*-------------------------------------------------------------------------*/
  37532. +
  37533. +static int do_write(struct fsg_dev *fsg)
  37534. +{
  37535. + struct fsg_lun *curlun = fsg->curlun;
  37536. + u32 lba;
  37537. + struct fsg_buffhd *bh;
  37538. + int get_some_more;
  37539. + u32 amount_left_to_req, amount_left_to_write;
  37540. + loff_t usb_offset, file_offset, file_offset_tmp;
  37541. + unsigned int amount;
  37542. + ssize_t nwritten;
  37543. + int rc;
  37544. +
  37545. + if (curlun->ro) {
  37546. + curlun->sense_data = SS_WRITE_PROTECTED;
  37547. + return -EINVAL;
  37548. + }
  37549. + spin_lock(&curlun->filp->f_lock);
  37550. + curlun->filp->f_flags &= ~O_SYNC; // Default is not to wait
  37551. + spin_unlock(&curlun->filp->f_lock);
  37552. +
  37553. + /* Get the starting Logical Block Address and check that it's
  37554. + * not too big */
  37555. + if (fsg->cmnd[0] == WRITE_6)
  37556. + lba = get_unaligned_be24(&fsg->cmnd[1]);
  37557. + else {
  37558. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  37559. +
  37560. + /* We allow DPO (Disable Page Out = don't save data in the
  37561. + * cache) and FUA (Force Unit Access = write directly to the
  37562. + * medium). We don't implement DPO; we implement FUA by
  37563. + * performing synchronous output. */
  37564. + if ((fsg->cmnd[1] & ~0x18) != 0) {
  37565. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37566. + return -EINVAL;
  37567. + }
  37568. + /* FUA */
  37569. + if (!curlun->nofua && (fsg->cmnd[1] & 0x08)) {
  37570. + spin_lock(&curlun->filp->f_lock);
  37571. + curlun->filp->f_flags |= O_DSYNC;
  37572. + spin_unlock(&curlun->filp->f_lock);
  37573. + }
  37574. + }
  37575. + if (lba >= curlun->num_sectors) {
  37576. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  37577. + return -EINVAL;
  37578. + }
  37579. +
  37580. + /* Carry out the file writes */
  37581. + get_some_more = 1;
  37582. + file_offset = usb_offset = ((loff_t) lba) << curlun->blkbits;
  37583. + amount_left_to_req = amount_left_to_write = fsg->data_size_from_cmnd;
  37584. +
  37585. + while (amount_left_to_write > 0) {
  37586. +
  37587. + /* Queue a request for more data from the host */
  37588. + bh = fsg->next_buffhd_to_fill;
  37589. + if (bh->state == BUF_STATE_EMPTY && get_some_more) {
  37590. +
  37591. + /* Figure out how much we want to get:
  37592. + * Try to get the remaining amount,
  37593. + * but not more than the buffer size.
  37594. + */
  37595. + amount = min(amount_left_to_req, mod_data.buflen);
  37596. +
  37597. + /* Beyond the end of the backing file? */
  37598. + if (usb_offset >= curlun->file_length) {
  37599. + get_some_more = 0;
  37600. + curlun->sense_data =
  37601. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  37602. + curlun->sense_data_info = usb_offset >> curlun->blkbits;
  37603. + curlun->info_valid = 1;
  37604. + continue;
  37605. + }
  37606. +
  37607. + /* Get the next buffer */
  37608. + usb_offset += amount;
  37609. + fsg->usb_amount_left -= amount;
  37610. + amount_left_to_req -= amount;
  37611. + if (amount_left_to_req == 0)
  37612. + get_some_more = 0;
  37613. +
  37614. + /* Except at the end of the transfer, amount will be
  37615. + * equal to the buffer size, which is divisible by
  37616. + * the bulk-out maxpacket size.
  37617. + */
  37618. + set_bulk_out_req_length(fsg, bh, amount);
  37619. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  37620. + &bh->outreq_busy, &bh->state);
  37621. + fsg->next_buffhd_to_fill = bh->next;
  37622. + continue;
  37623. + }
  37624. +
  37625. + /* Write the received data to the backing file */
  37626. + bh = fsg->next_buffhd_to_drain;
  37627. + if (bh->state == BUF_STATE_EMPTY && !get_some_more)
  37628. + break; // We stopped early
  37629. + if (bh->state == BUF_STATE_FULL) {
  37630. + smp_rmb();
  37631. + fsg->next_buffhd_to_drain = bh->next;
  37632. + bh->state = BUF_STATE_EMPTY;
  37633. +
  37634. + /* Did something go wrong with the transfer? */
  37635. + if (bh->outreq->status != 0) {
  37636. + curlun->sense_data = SS_COMMUNICATION_FAILURE;
  37637. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  37638. + curlun->info_valid = 1;
  37639. + break;
  37640. + }
  37641. +
  37642. + amount = bh->outreq->actual;
  37643. + if (curlun->file_length - file_offset < amount) {
  37644. + LERROR(curlun,
  37645. + "write %u @ %llu beyond end %llu\n",
  37646. + amount, (unsigned long long) file_offset,
  37647. + (unsigned long long) curlun->file_length);
  37648. + amount = curlun->file_length - file_offset;
  37649. + }
  37650. +
  37651. + /* Don't accept excess data. The spec doesn't say
  37652. + * what to do in this case. We'll ignore the error.
  37653. + */
  37654. + amount = min(amount, bh->bulk_out_intended_length);
  37655. +
  37656. + /* Don't write a partial block */
  37657. + amount = round_down(amount, curlun->blksize);
  37658. + if (amount == 0)
  37659. + goto empty_write;
  37660. +
  37661. + /* Perform the write */
  37662. + file_offset_tmp = file_offset;
  37663. + nwritten = vfs_write(curlun->filp,
  37664. + (char __user *) bh->buf,
  37665. + amount, &file_offset_tmp);
  37666. + VLDBG(curlun, "file write %u @ %llu -> %d\n", amount,
  37667. + (unsigned long long) file_offset,
  37668. + (int) nwritten);
  37669. + if (signal_pending(current))
  37670. + return -EINTR; // Interrupted!
  37671. +
  37672. + if (nwritten < 0) {
  37673. + LDBG(curlun, "error in file write: %d\n",
  37674. + (int) nwritten);
  37675. + nwritten = 0;
  37676. + } else if (nwritten < amount) {
  37677. + LDBG(curlun, "partial file write: %d/%u\n",
  37678. + (int) nwritten, amount);
  37679. + nwritten = round_down(nwritten, curlun->blksize);
  37680. + }
  37681. + file_offset += nwritten;
  37682. + amount_left_to_write -= nwritten;
  37683. + fsg->residue -= nwritten;
  37684. +
  37685. + /* If an error occurred, report it and its position */
  37686. + if (nwritten < amount) {
  37687. + curlun->sense_data = SS_WRITE_ERROR;
  37688. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  37689. + curlun->info_valid = 1;
  37690. + break;
  37691. + }
  37692. +
  37693. + empty_write:
  37694. + /* Did the host decide to stop early? */
  37695. + if (bh->outreq->actual < bh->bulk_out_intended_length) {
  37696. + fsg->short_packet_received = 1;
  37697. + break;
  37698. + }
  37699. + continue;
  37700. + }
  37701. +
  37702. + /* Wait for something to happen */
  37703. + rc = sleep_thread(fsg);
  37704. + if (rc)
  37705. + return rc;
  37706. + }
  37707. +
  37708. + return -EIO; // No default reply
  37709. +}
  37710. +
  37711. +
  37712. +/*-------------------------------------------------------------------------*/
  37713. +
  37714. +static int do_synchronize_cache(struct fsg_dev *fsg)
  37715. +{
  37716. + struct fsg_lun *curlun = fsg->curlun;
  37717. + int rc;
  37718. +
  37719. + /* We ignore the requested LBA and write out all file's
  37720. + * dirty data buffers. */
  37721. + rc = fsg_lun_fsync_sub(curlun);
  37722. + if (rc)
  37723. + curlun->sense_data = SS_WRITE_ERROR;
  37724. + return 0;
  37725. +}
  37726. +
  37727. +
  37728. +/*-------------------------------------------------------------------------*/
  37729. +
  37730. +static void invalidate_sub(struct fsg_lun *curlun)
  37731. +{
  37732. + struct file *filp = curlun->filp;
  37733. + struct inode *inode = filp->f_path.dentry->d_inode;
  37734. + unsigned long rc;
  37735. +
  37736. + rc = invalidate_mapping_pages(inode->i_mapping, 0, -1);
  37737. + VLDBG(curlun, "invalidate_mapping_pages -> %ld\n", rc);
  37738. +}
  37739. +
  37740. +static int do_verify(struct fsg_dev *fsg)
  37741. +{
  37742. + struct fsg_lun *curlun = fsg->curlun;
  37743. + u32 lba;
  37744. + u32 verification_length;
  37745. + struct fsg_buffhd *bh = fsg->next_buffhd_to_fill;
  37746. + loff_t file_offset, file_offset_tmp;
  37747. + u32 amount_left;
  37748. + unsigned int amount;
  37749. + ssize_t nread;
  37750. +
  37751. + /* Get the starting Logical Block Address and check that it's
  37752. + * not too big */
  37753. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  37754. + if (lba >= curlun->num_sectors) {
  37755. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  37756. + return -EINVAL;
  37757. + }
  37758. +
  37759. + /* We allow DPO (Disable Page Out = don't save data in the
  37760. + * cache) but we don't implement it. */
  37761. + if ((fsg->cmnd[1] & ~0x10) != 0) {
  37762. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37763. + return -EINVAL;
  37764. + }
  37765. +
  37766. + verification_length = get_unaligned_be16(&fsg->cmnd[7]);
  37767. + if (unlikely(verification_length == 0))
  37768. + return -EIO; // No default reply
  37769. +
  37770. + /* Prepare to carry out the file verify */
  37771. + amount_left = verification_length << curlun->blkbits;
  37772. + file_offset = ((loff_t) lba) << curlun->blkbits;
  37773. +
  37774. + /* Write out all the dirty buffers before invalidating them */
  37775. + fsg_lun_fsync_sub(curlun);
  37776. + if (signal_pending(current))
  37777. + return -EINTR;
  37778. +
  37779. + invalidate_sub(curlun);
  37780. + if (signal_pending(current))
  37781. + return -EINTR;
  37782. +
  37783. + /* Just try to read the requested blocks */
  37784. + while (amount_left > 0) {
  37785. +
  37786. + /* Figure out how much we need to read:
  37787. + * Try to read the remaining amount, but not more than
  37788. + * the buffer size.
  37789. + * And don't try to read past the end of the file.
  37790. + */
  37791. + amount = min((unsigned int) amount_left, mod_data.buflen);
  37792. + amount = min((loff_t) amount,
  37793. + curlun->file_length - file_offset);
  37794. + if (amount == 0) {
  37795. + curlun->sense_data =
  37796. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  37797. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  37798. + curlun->info_valid = 1;
  37799. + break;
  37800. + }
  37801. +
  37802. + /* Perform the read */
  37803. + file_offset_tmp = file_offset;
  37804. + nread = vfs_read(curlun->filp,
  37805. + (char __user *) bh->buf,
  37806. + amount, &file_offset_tmp);
  37807. + VLDBG(curlun, "file read %u @ %llu -> %d\n", amount,
  37808. + (unsigned long long) file_offset,
  37809. + (int) nread);
  37810. + if (signal_pending(current))
  37811. + return -EINTR;
  37812. +
  37813. + if (nread < 0) {
  37814. + LDBG(curlun, "error in file verify: %d\n",
  37815. + (int) nread);
  37816. + nread = 0;
  37817. + } else if (nread < amount) {
  37818. + LDBG(curlun, "partial file verify: %d/%u\n",
  37819. + (int) nread, amount);
  37820. + nread = round_down(nread, curlun->blksize);
  37821. + }
  37822. + if (nread == 0) {
  37823. + curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
  37824. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  37825. + curlun->info_valid = 1;
  37826. + break;
  37827. + }
  37828. + file_offset += nread;
  37829. + amount_left -= nread;
  37830. + }
  37831. + return 0;
  37832. +}
  37833. +
  37834. +
  37835. +/*-------------------------------------------------------------------------*/
  37836. +
  37837. +static int do_inquiry(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37838. +{
  37839. + u8 *buf = (u8 *) bh->buf;
  37840. +
  37841. + static char vendor_id[] = "Linux ";
  37842. + static char product_disk_id[] = "File-Stor Gadget";
  37843. + static char product_cdrom_id[] = "File-CD Gadget ";
  37844. +
  37845. + if (!fsg->curlun) { // Unsupported LUNs are okay
  37846. + fsg->bad_lun_okay = 1;
  37847. + memset(buf, 0, 36);
  37848. + buf[0] = 0x7f; // Unsupported, no device-type
  37849. + buf[4] = 31; // Additional length
  37850. + return 36;
  37851. + }
  37852. +
  37853. + memset(buf, 0, 8);
  37854. + buf[0] = (mod_data.cdrom ? TYPE_ROM : TYPE_DISK);
  37855. + if (mod_data.removable)
  37856. + buf[1] = 0x80;
  37857. + buf[2] = 2; // ANSI SCSI level 2
  37858. + buf[3] = 2; // SCSI-2 INQUIRY data format
  37859. + buf[4] = 31; // Additional length
  37860. + // No special options
  37861. + sprintf(buf + 8, "%-8s%-16s%04x", vendor_id,
  37862. + (mod_data.cdrom ? product_cdrom_id :
  37863. + product_disk_id),
  37864. + mod_data.release);
  37865. + return 36;
  37866. +}
  37867. +
  37868. +
  37869. +static int do_request_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37870. +{
  37871. + struct fsg_lun *curlun = fsg->curlun;
  37872. + u8 *buf = (u8 *) bh->buf;
  37873. + u32 sd, sdinfo;
  37874. + int valid;
  37875. +
  37876. + /*
  37877. + * From the SCSI-2 spec., section 7.9 (Unit attention condition):
  37878. + *
  37879. + * If a REQUEST SENSE command is received from an initiator
  37880. + * with a pending unit attention condition (before the target
  37881. + * generates the contingent allegiance condition), then the
  37882. + * target shall either:
  37883. + * a) report any pending sense data and preserve the unit
  37884. + * attention condition on the logical unit, or,
  37885. + * b) report the unit attention condition, may discard any
  37886. + * pending sense data, and clear the unit attention
  37887. + * condition on the logical unit for that initiator.
  37888. + *
  37889. + * FSG normally uses option a); enable this code to use option b).
  37890. + */
  37891. +#if 0
  37892. + if (curlun && curlun->unit_attention_data != SS_NO_SENSE) {
  37893. + curlun->sense_data = curlun->unit_attention_data;
  37894. + curlun->unit_attention_data = SS_NO_SENSE;
  37895. + }
  37896. +#endif
  37897. +
  37898. + if (!curlun) { // Unsupported LUNs are okay
  37899. + fsg->bad_lun_okay = 1;
  37900. + sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
  37901. + sdinfo = 0;
  37902. + valid = 0;
  37903. + } else {
  37904. + sd = curlun->sense_data;
  37905. + sdinfo = curlun->sense_data_info;
  37906. + valid = curlun->info_valid << 7;
  37907. + curlun->sense_data = SS_NO_SENSE;
  37908. + curlun->sense_data_info = 0;
  37909. + curlun->info_valid = 0;
  37910. + }
  37911. +
  37912. + memset(buf, 0, 18);
  37913. + buf[0] = valid | 0x70; // Valid, current error
  37914. + buf[2] = SK(sd);
  37915. + put_unaligned_be32(sdinfo, &buf[3]); /* Sense information */
  37916. + buf[7] = 18 - 8; // Additional sense length
  37917. + buf[12] = ASC(sd);
  37918. + buf[13] = ASCQ(sd);
  37919. + return 18;
  37920. +}
  37921. +
  37922. +
  37923. +static int do_read_capacity(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37924. +{
  37925. + struct fsg_lun *curlun = fsg->curlun;
  37926. + u32 lba = get_unaligned_be32(&fsg->cmnd[2]);
  37927. + int pmi = fsg->cmnd[8];
  37928. + u8 *buf = (u8 *) bh->buf;
  37929. +
  37930. + /* Check the PMI and LBA fields */
  37931. + if (pmi > 1 || (pmi == 0 && lba != 0)) {
  37932. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37933. + return -EINVAL;
  37934. + }
  37935. +
  37936. + put_unaligned_be32(curlun->num_sectors - 1, &buf[0]);
  37937. + /* Max logical block */
  37938. + put_unaligned_be32(curlun->blksize, &buf[4]); /* Block length */
  37939. + return 8;
  37940. +}
  37941. +
  37942. +
  37943. +static int do_read_header(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37944. +{
  37945. + struct fsg_lun *curlun = fsg->curlun;
  37946. + int msf = fsg->cmnd[1] & 0x02;
  37947. + u32 lba = get_unaligned_be32(&fsg->cmnd[2]);
  37948. + u8 *buf = (u8 *) bh->buf;
  37949. +
  37950. + if ((fsg->cmnd[1] & ~0x02) != 0) { /* Mask away MSF */
  37951. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37952. + return -EINVAL;
  37953. + }
  37954. + if (lba >= curlun->num_sectors) {
  37955. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  37956. + return -EINVAL;
  37957. + }
  37958. +
  37959. + memset(buf, 0, 8);
  37960. + buf[0] = 0x01; /* 2048 bytes of user data, rest is EC */
  37961. + store_cdrom_address(&buf[4], msf, lba);
  37962. + return 8;
  37963. +}
  37964. +
  37965. +
  37966. +static int do_read_toc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37967. +{
  37968. + struct fsg_lun *curlun = fsg->curlun;
  37969. + int msf = fsg->cmnd[1] & 0x02;
  37970. + int start_track = fsg->cmnd[6];
  37971. + u8 *buf = (u8 *) bh->buf;
  37972. +
  37973. + if ((fsg->cmnd[1] & ~0x02) != 0 || /* Mask away MSF */
  37974. + start_track > 1) {
  37975. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37976. + return -EINVAL;
  37977. + }
  37978. +
  37979. + memset(buf, 0, 20);
  37980. + buf[1] = (20-2); /* TOC data length */
  37981. + buf[2] = 1; /* First track number */
  37982. + buf[3] = 1; /* Last track number */
  37983. + buf[5] = 0x16; /* Data track, copying allowed */
  37984. + buf[6] = 0x01; /* Only track is number 1 */
  37985. + store_cdrom_address(&buf[8], msf, 0);
  37986. +
  37987. + buf[13] = 0x16; /* Lead-out track is data */
  37988. + buf[14] = 0xAA; /* Lead-out track number */
  37989. + store_cdrom_address(&buf[16], msf, curlun->num_sectors);
  37990. + return 20;
  37991. +}
  37992. +
  37993. +
  37994. +static int do_mode_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37995. +{
  37996. + struct fsg_lun *curlun = fsg->curlun;
  37997. + int mscmnd = fsg->cmnd[0];
  37998. + u8 *buf = (u8 *) bh->buf;
  37999. + u8 *buf0 = buf;
  38000. + int pc, page_code;
  38001. + int changeable_values, all_pages;
  38002. + int valid_page = 0;
  38003. + int len, limit;
  38004. +
  38005. + if ((fsg->cmnd[1] & ~0x08) != 0) { // Mask away DBD
  38006. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  38007. + return -EINVAL;
  38008. + }
  38009. + pc = fsg->cmnd[2] >> 6;
  38010. + page_code = fsg->cmnd[2] & 0x3f;
  38011. + if (pc == 3) {
  38012. + curlun->sense_data = SS_SAVING_PARAMETERS_NOT_SUPPORTED;
  38013. + return -EINVAL;
  38014. + }
  38015. + changeable_values = (pc == 1);
  38016. + all_pages = (page_code == 0x3f);
  38017. +
  38018. + /* Write the mode parameter header. Fixed values are: default
  38019. + * medium type, no cache control (DPOFUA), and no block descriptors.
  38020. + * The only variable value is the WriteProtect bit. We will fill in
  38021. + * the mode data length later. */
  38022. + memset(buf, 0, 8);
  38023. + if (mscmnd == MODE_SENSE) {
  38024. + buf[2] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA
  38025. + buf += 4;
  38026. + limit = 255;
  38027. + } else { // MODE_SENSE_10
  38028. + buf[3] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA
  38029. + buf += 8;
  38030. + limit = 65535; // Should really be mod_data.buflen
  38031. + }
  38032. +
  38033. + /* No block descriptors */
  38034. +
  38035. + /* The mode pages, in numerical order. The only page we support
  38036. + * is the Caching page. */
  38037. + if (page_code == 0x08 || all_pages) {
  38038. + valid_page = 1;
  38039. + buf[0] = 0x08; // Page code
  38040. + buf[1] = 10; // Page length
  38041. + memset(buf+2, 0, 10); // None of the fields are changeable
  38042. +
  38043. + if (!changeable_values) {
  38044. + buf[2] = 0x04; // Write cache enable,
  38045. + // Read cache not disabled
  38046. + // No cache retention priorities
  38047. + put_unaligned_be16(0xffff, &buf[4]);
  38048. + /* Don't disable prefetch */
  38049. + /* Minimum prefetch = 0 */
  38050. + put_unaligned_be16(0xffff, &buf[8]);
  38051. + /* Maximum prefetch */
  38052. + put_unaligned_be16(0xffff, &buf[10]);
  38053. + /* Maximum prefetch ceiling */
  38054. + }
  38055. + buf += 12;
  38056. + }
  38057. +
  38058. + /* Check that a valid page was requested and the mode data length
  38059. + * isn't too long. */
  38060. + len = buf - buf0;
  38061. + if (!valid_page || len > limit) {
  38062. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  38063. + return -EINVAL;
  38064. + }
  38065. +
  38066. + /* Store the mode data length */
  38067. + if (mscmnd == MODE_SENSE)
  38068. + buf0[0] = len - 1;
  38069. + else
  38070. + put_unaligned_be16(len - 2, buf0);
  38071. + return len;
  38072. +}
  38073. +
  38074. +
  38075. +static int do_start_stop(struct fsg_dev *fsg)
  38076. +{
  38077. + struct fsg_lun *curlun = fsg->curlun;
  38078. + int loej, start;
  38079. +
  38080. + if (!mod_data.removable) {
  38081. + curlun->sense_data = SS_INVALID_COMMAND;
  38082. + return -EINVAL;
  38083. + }
  38084. +
  38085. + // int immed = fsg->cmnd[1] & 0x01;
  38086. + loej = fsg->cmnd[4] & 0x02;
  38087. + start = fsg->cmnd[4] & 0x01;
  38088. +
  38089. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  38090. + if ((fsg->cmnd[1] & ~0x01) != 0 || // Mask away Immed
  38091. + (fsg->cmnd[4] & ~0x03) != 0) { // Mask LoEj, Start
  38092. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  38093. + return -EINVAL;
  38094. + }
  38095. +
  38096. + if (!start) {
  38097. +
  38098. + /* Are we allowed to unload the media? */
  38099. + if (curlun->prevent_medium_removal) {
  38100. + LDBG(curlun, "unload attempt prevented\n");
  38101. + curlun->sense_data = SS_MEDIUM_REMOVAL_PREVENTED;
  38102. + return -EINVAL;
  38103. + }
  38104. + if (loej) { // Simulate an unload/eject
  38105. + up_read(&fsg->filesem);
  38106. + down_write(&fsg->filesem);
  38107. + fsg_lun_close(curlun);
  38108. + up_write(&fsg->filesem);
  38109. + down_read(&fsg->filesem);
  38110. + }
  38111. + } else {
  38112. +
  38113. + /* Our emulation doesn't support mounting; the medium is
  38114. + * available for use as soon as it is loaded. */
  38115. + if (!fsg_lun_is_open(curlun)) {
  38116. + curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
  38117. + return -EINVAL;
  38118. + }
  38119. + }
  38120. +#endif
  38121. + return 0;
  38122. +}
  38123. +
  38124. +
  38125. +static int do_prevent_allow(struct fsg_dev *fsg)
  38126. +{
  38127. + struct fsg_lun *curlun = fsg->curlun;
  38128. + int prevent;
  38129. +
  38130. + if (!mod_data.removable) {
  38131. + curlun->sense_data = SS_INVALID_COMMAND;
  38132. + return -EINVAL;
  38133. + }
  38134. +
  38135. + prevent = fsg->cmnd[4] & 0x01;
  38136. + if ((fsg->cmnd[4] & ~0x01) != 0) { // Mask away Prevent
  38137. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  38138. + return -EINVAL;
  38139. + }
  38140. +
  38141. + if (curlun->prevent_medium_removal && !prevent)
  38142. + fsg_lun_fsync_sub(curlun);
  38143. + curlun->prevent_medium_removal = prevent;
  38144. + return 0;
  38145. +}
  38146. +
  38147. +
  38148. +static int do_read_format_capacities(struct fsg_dev *fsg,
  38149. + struct fsg_buffhd *bh)
  38150. +{
  38151. + struct fsg_lun *curlun = fsg->curlun;
  38152. + u8 *buf = (u8 *) bh->buf;
  38153. +
  38154. + buf[0] = buf[1] = buf[2] = 0;
  38155. + buf[3] = 8; // Only the Current/Maximum Capacity Descriptor
  38156. + buf += 4;
  38157. +
  38158. + put_unaligned_be32(curlun->num_sectors, &buf[0]);
  38159. + /* Number of blocks */
  38160. + put_unaligned_be32(curlun->blksize, &buf[4]); /* Block length */
  38161. + buf[4] = 0x02; /* Current capacity */
  38162. + return 12;
  38163. +}
  38164. +
  38165. +
  38166. +static int do_mode_select(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  38167. +{
  38168. + struct fsg_lun *curlun = fsg->curlun;
  38169. +
  38170. + /* We don't support MODE SELECT */
  38171. + curlun->sense_data = SS_INVALID_COMMAND;
  38172. + return -EINVAL;
  38173. +}
  38174. +
  38175. +
  38176. +/*-------------------------------------------------------------------------*/
  38177. +
  38178. +static int halt_bulk_in_endpoint(struct fsg_dev *fsg)
  38179. +{
  38180. + int rc;
  38181. +
  38182. + rc = fsg_set_halt(fsg, fsg->bulk_in);
  38183. + if (rc == -EAGAIN)
  38184. + VDBG(fsg, "delayed bulk-in endpoint halt\n");
  38185. + while (rc != 0) {
  38186. + if (rc != -EAGAIN) {
  38187. + WARNING(fsg, "usb_ep_set_halt -> %d\n", rc);
  38188. + rc = 0;
  38189. + break;
  38190. + }
  38191. +
  38192. + /* Wait for a short time and then try again */
  38193. + if (msleep_interruptible(100) != 0)
  38194. + return -EINTR;
  38195. + rc = usb_ep_set_halt(fsg->bulk_in);
  38196. + }
  38197. + return rc;
  38198. +}
  38199. +
  38200. +static int wedge_bulk_in_endpoint(struct fsg_dev *fsg)
  38201. +{
  38202. + int rc;
  38203. +
  38204. + DBG(fsg, "bulk-in set wedge\n");
  38205. + rc = usb_ep_set_wedge(fsg->bulk_in);
  38206. + if (rc == -EAGAIN)
  38207. + VDBG(fsg, "delayed bulk-in endpoint wedge\n");
  38208. + while (rc != 0) {
  38209. + if (rc != -EAGAIN) {
  38210. + WARNING(fsg, "usb_ep_set_wedge -> %d\n", rc);
  38211. + rc = 0;
  38212. + break;
  38213. + }
  38214. +
  38215. + /* Wait for a short time and then try again */
  38216. + if (msleep_interruptible(100) != 0)
  38217. + return -EINTR;
  38218. + rc = usb_ep_set_wedge(fsg->bulk_in);
  38219. + }
  38220. + return rc;
  38221. +}
  38222. +
  38223. +static int throw_away_data(struct fsg_dev *fsg)
  38224. +{
  38225. + struct fsg_buffhd *bh;
  38226. + u32 amount;
  38227. + int rc;
  38228. +
  38229. + while ((bh = fsg->next_buffhd_to_drain)->state != BUF_STATE_EMPTY ||
  38230. + fsg->usb_amount_left > 0) {
  38231. +
  38232. + /* Throw away the data in a filled buffer */
  38233. + if (bh->state == BUF_STATE_FULL) {
  38234. + smp_rmb();
  38235. + bh->state = BUF_STATE_EMPTY;
  38236. + fsg->next_buffhd_to_drain = bh->next;
  38237. +
  38238. + /* A short packet or an error ends everything */
  38239. + if (bh->outreq->actual < bh->bulk_out_intended_length ||
  38240. + bh->outreq->status != 0) {
  38241. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  38242. + return -EINTR;
  38243. + }
  38244. + continue;
  38245. + }
  38246. +
  38247. + /* Try to submit another request if we need one */
  38248. + bh = fsg->next_buffhd_to_fill;
  38249. + if (bh->state == BUF_STATE_EMPTY && fsg->usb_amount_left > 0) {
  38250. + amount = min(fsg->usb_amount_left,
  38251. + (u32) mod_data.buflen);
  38252. +
  38253. + /* Except at the end of the transfer, amount will be
  38254. + * equal to the buffer size, which is divisible by
  38255. + * the bulk-out maxpacket size.
  38256. + */
  38257. + set_bulk_out_req_length(fsg, bh, amount);
  38258. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  38259. + &bh->outreq_busy, &bh->state);
  38260. + fsg->next_buffhd_to_fill = bh->next;
  38261. + fsg->usb_amount_left -= amount;
  38262. + continue;
  38263. + }
  38264. +
  38265. + /* Otherwise wait for something to happen */
  38266. + rc = sleep_thread(fsg);
  38267. + if (rc)
  38268. + return rc;
  38269. + }
  38270. + return 0;
  38271. +}
  38272. +
  38273. +
  38274. +static int finish_reply(struct fsg_dev *fsg)
  38275. +{
  38276. + struct fsg_buffhd *bh = fsg->next_buffhd_to_fill;
  38277. + int rc = 0;
  38278. +
  38279. + switch (fsg->data_dir) {
  38280. + case DATA_DIR_NONE:
  38281. + break; // Nothing to send
  38282. +
  38283. + /* If we don't know whether the host wants to read or write,
  38284. + * this must be CB or CBI with an unknown command. We mustn't
  38285. + * try to send or receive any data. So stall both bulk pipes
  38286. + * if we can and wait for a reset. */
  38287. + case DATA_DIR_UNKNOWN:
  38288. + if (mod_data.can_stall) {
  38289. + fsg_set_halt(fsg, fsg->bulk_out);
  38290. + rc = halt_bulk_in_endpoint(fsg);
  38291. + }
  38292. + break;
  38293. +
  38294. + /* All but the last buffer of data must have already been sent */
  38295. + case DATA_DIR_TO_HOST:
  38296. + if (fsg->data_size == 0)
  38297. + ; // Nothing to send
  38298. +
  38299. + /* If there's no residue, simply send the last buffer */
  38300. + else if (fsg->residue == 0) {
  38301. + bh->inreq->zero = 0;
  38302. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  38303. + &bh->inreq_busy, &bh->state);
  38304. + fsg->next_buffhd_to_fill = bh->next;
  38305. + }
  38306. +
  38307. + /* There is a residue. For CB and CBI, simply mark the end
  38308. + * of the data with a short packet. However, if we are
  38309. + * allowed to stall, there was no data at all (residue ==
  38310. + * data_size), and the command failed (invalid LUN or
  38311. + * sense data is set), then halt the bulk-in endpoint
  38312. + * instead. */
  38313. + else if (!transport_is_bbb()) {
  38314. + if (mod_data.can_stall &&
  38315. + fsg->residue == fsg->data_size &&
  38316. + (!fsg->curlun || fsg->curlun->sense_data != SS_NO_SENSE)) {
  38317. + bh->state = BUF_STATE_EMPTY;
  38318. + rc = halt_bulk_in_endpoint(fsg);
  38319. + } else {
  38320. + bh->inreq->zero = 1;
  38321. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  38322. + &bh->inreq_busy, &bh->state);
  38323. + fsg->next_buffhd_to_fill = bh->next;
  38324. + }
  38325. + }
  38326. +
  38327. + /*
  38328. + * For Bulk-only, mark the end of the data with a short
  38329. + * packet. If we are allowed to stall, halt the bulk-in
  38330. + * endpoint. (Note: This violates the Bulk-Only Transport
  38331. + * specification, which requires us to pad the data if we
  38332. + * don't halt the endpoint. Presumably nobody will mind.)
  38333. + */
  38334. + else {
  38335. + bh->inreq->zero = 1;
  38336. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  38337. + &bh->inreq_busy, &bh->state);
  38338. + fsg->next_buffhd_to_fill = bh->next;
  38339. + if (mod_data.can_stall)
  38340. + rc = halt_bulk_in_endpoint(fsg);
  38341. + }
  38342. + break;
  38343. +
  38344. + /* We have processed all we want from the data the host has sent.
  38345. + * There may still be outstanding bulk-out requests. */
  38346. + case DATA_DIR_FROM_HOST:
  38347. + if (fsg->residue == 0)
  38348. + ; // Nothing to receive
  38349. +
  38350. + /* Did the host stop sending unexpectedly early? */
  38351. + else if (fsg->short_packet_received) {
  38352. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  38353. + rc = -EINTR;
  38354. + }
  38355. +
  38356. + /* We haven't processed all the incoming data. Even though
  38357. + * we may be allowed to stall, doing so would cause a race.
  38358. + * The controller may already have ACK'ed all the remaining
  38359. + * bulk-out packets, in which case the host wouldn't see a
  38360. + * STALL. Not realizing the endpoint was halted, it wouldn't
  38361. + * clear the halt -- leading to problems later on. */
  38362. +#if 0
  38363. + else if (mod_data.can_stall) {
  38364. + fsg_set_halt(fsg, fsg->bulk_out);
  38365. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  38366. + rc = -EINTR;
  38367. + }
  38368. +#endif
  38369. +
  38370. + /* We can't stall. Read in the excess data and throw it
  38371. + * all away. */
  38372. + else
  38373. + rc = throw_away_data(fsg);
  38374. + break;
  38375. + }
  38376. + return rc;
  38377. +}
  38378. +
  38379. +
  38380. +static int send_status(struct fsg_dev *fsg)
  38381. +{
  38382. + struct fsg_lun *curlun = fsg->curlun;
  38383. + struct fsg_buffhd *bh;
  38384. + int rc;
  38385. + u8 status = US_BULK_STAT_OK;
  38386. + u32 sd, sdinfo = 0;
  38387. +
  38388. + /* Wait for the next buffer to become available */
  38389. + bh = fsg->next_buffhd_to_fill;
  38390. + while (bh->state != BUF_STATE_EMPTY) {
  38391. + rc = sleep_thread(fsg);
  38392. + if (rc)
  38393. + return rc;
  38394. + }
  38395. +
  38396. + if (curlun) {
  38397. + sd = curlun->sense_data;
  38398. + sdinfo = curlun->sense_data_info;
  38399. + } else if (fsg->bad_lun_okay)
  38400. + sd = SS_NO_SENSE;
  38401. + else
  38402. + sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
  38403. +
  38404. + if (fsg->phase_error) {
  38405. + DBG(fsg, "sending phase-error status\n");
  38406. + status = US_BULK_STAT_PHASE;
  38407. + sd = SS_INVALID_COMMAND;
  38408. + } else if (sd != SS_NO_SENSE) {
  38409. + DBG(fsg, "sending command-failure status\n");
  38410. + status = US_BULK_STAT_FAIL;
  38411. + VDBG(fsg, " sense data: SK x%02x, ASC x%02x, ASCQ x%02x;"
  38412. + " info x%x\n",
  38413. + SK(sd), ASC(sd), ASCQ(sd), sdinfo);
  38414. + }
  38415. +
  38416. + if (transport_is_bbb()) {
  38417. + struct bulk_cs_wrap *csw = bh->buf;
  38418. +
  38419. + /* Store and send the Bulk-only CSW */
  38420. + csw->Signature = cpu_to_le32(US_BULK_CS_SIGN);
  38421. + csw->Tag = fsg->tag;
  38422. + csw->Residue = cpu_to_le32(fsg->residue);
  38423. + csw->Status = status;
  38424. +
  38425. + bh->inreq->length = US_BULK_CS_WRAP_LEN;
  38426. + bh->inreq->zero = 0;
  38427. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  38428. + &bh->inreq_busy, &bh->state);
  38429. +
  38430. + } else if (mod_data.transport_type == USB_PR_CB) {
  38431. +
  38432. + /* Control-Bulk transport has no status phase! */
  38433. + return 0;
  38434. +
  38435. + } else { // USB_PR_CBI
  38436. + struct interrupt_data *buf = bh->buf;
  38437. +
  38438. + /* Store and send the Interrupt data. UFI sends the ASC
  38439. + * and ASCQ bytes. Everything else sends a Type (which
  38440. + * is always 0) and the status Value. */
  38441. + if (mod_data.protocol_type == USB_SC_UFI) {
  38442. + buf->bType = ASC(sd);
  38443. + buf->bValue = ASCQ(sd);
  38444. + } else {
  38445. + buf->bType = 0;
  38446. + buf->bValue = status;
  38447. + }
  38448. + fsg->intreq->length = CBI_INTERRUPT_DATA_LEN;
  38449. +
  38450. + fsg->intr_buffhd = bh; // Point to the right buffhd
  38451. + fsg->intreq->buf = bh->inreq->buf;
  38452. + fsg->intreq->context = bh;
  38453. + start_transfer(fsg, fsg->intr_in, fsg->intreq,
  38454. + &fsg->intreq_busy, &bh->state);
  38455. + }
  38456. +
  38457. + fsg->next_buffhd_to_fill = bh->next;
  38458. + return 0;
  38459. +}
  38460. +
  38461. +
  38462. +/*-------------------------------------------------------------------------*/
  38463. +
  38464. +/* Check whether the command is properly formed and whether its data size
  38465. + * and direction agree with the values we already have. */
  38466. +static int check_command(struct fsg_dev *fsg, int cmnd_size,
  38467. + enum data_direction data_dir, unsigned int mask,
  38468. + int needs_medium, const char *name)
  38469. +{
  38470. + int i;
  38471. + int lun = fsg->cmnd[1] >> 5;
  38472. + static const char dirletter[4] = {'u', 'o', 'i', 'n'};
  38473. + char hdlen[20];
  38474. + struct fsg_lun *curlun;
  38475. +
  38476. + /* Adjust the expected cmnd_size for protocol encapsulation padding.
  38477. + * Transparent SCSI doesn't pad. */
  38478. + if (protocol_is_scsi())
  38479. + ;
  38480. +
  38481. + /* There's some disagreement as to whether RBC pads commands or not.
  38482. + * We'll play it safe and accept either form. */
  38483. + else if (mod_data.protocol_type == USB_SC_RBC) {
  38484. + if (fsg->cmnd_size == 12)
  38485. + cmnd_size = 12;
  38486. +
  38487. + /* All the other protocols pad to 12 bytes */
  38488. + } else
  38489. + cmnd_size = 12;
  38490. +
  38491. + hdlen[0] = 0;
  38492. + if (fsg->data_dir != DATA_DIR_UNKNOWN)
  38493. + sprintf(hdlen, ", H%c=%u", dirletter[(int) fsg->data_dir],
  38494. + fsg->data_size);
  38495. + VDBG(fsg, "SCSI command: %s; Dc=%d, D%c=%u; Hc=%d%s\n",
  38496. + name, cmnd_size, dirletter[(int) data_dir],
  38497. + fsg->data_size_from_cmnd, fsg->cmnd_size, hdlen);
  38498. +
  38499. + /* We can't reply at all until we know the correct data direction
  38500. + * and size. */
  38501. + if (fsg->data_size_from_cmnd == 0)
  38502. + data_dir = DATA_DIR_NONE;
  38503. + if (fsg->data_dir == DATA_DIR_UNKNOWN) { // CB or CBI
  38504. + fsg->data_dir = data_dir;
  38505. + fsg->data_size = fsg->data_size_from_cmnd;
  38506. +
  38507. + } else { // Bulk-only
  38508. + if (fsg->data_size < fsg->data_size_from_cmnd) {
  38509. +
  38510. + /* Host data size < Device data size is a phase error.
  38511. + * Carry out the command, but only transfer as much
  38512. + * as we are allowed. */
  38513. + fsg->data_size_from_cmnd = fsg->data_size;
  38514. + fsg->phase_error = 1;
  38515. + }
  38516. + }
  38517. + fsg->residue = fsg->usb_amount_left = fsg->data_size;
  38518. +
  38519. + /* Conflicting data directions is a phase error */
  38520. + if (fsg->data_dir != data_dir && fsg->data_size_from_cmnd > 0) {
  38521. + fsg->phase_error = 1;
  38522. + return -EINVAL;
  38523. + }
  38524. +
  38525. + /* Verify the length of the command itself */
  38526. + if (cmnd_size != fsg->cmnd_size) {
  38527. +
  38528. + /* Special case workaround: There are plenty of buggy SCSI
  38529. + * implementations. Many have issues with cbw->Length
  38530. + * field passing a wrong command size. For those cases we
  38531. + * always try to work around the problem by using the length
  38532. + * sent by the host side provided it is at least as large
  38533. + * as the correct command length.
  38534. + * Examples of such cases would be MS-Windows, which issues
  38535. + * REQUEST SENSE with cbw->Length == 12 where it should
  38536. + * be 6, and xbox360 issuing INQUIRY, TEST UNIT READY and
  38537. + * REQUEST SENSE with cbw->Length == 10 where it should
  38538. + * be 6 as well.
  38539. + */
  38540. + if (cmnd_size <= fsg->cmnd_size) {
  38541. + DBG(fsg, "%s is buggy! Expected length %d "
  38542. + "but we got %d\n", name,
  38543. + cmnd_size, fsg->cmnd_size);
  38544. + cmnd_size = fsg->cmnd_size;
  38545. + } else {
  38546. + fsg->phase_error = 1;
  38547. + return -EINVAL;
  38548. + }
  38549. + }
  38550. +
  38551. + /* Check that the LUN values are consistent */
  38552. + if (transport_is_bbb()) {
  38553. + if (fsg->lun != lun)
  38554. + DBG(fsg, "using LUN %d from CBW, "
  38555. + "not LUN %d from CDB\n",
  38556. + fsg->lun, lun);
  38557. + }
  38558. +
  38559. + /* Check the LUN */
  38560. + curlun = fsg->curlun;
  38561. + if (curlun) {
  38562. + if (fsg->cmnd[0] != REQUEST_SENSE) {
  38563. + curlun->sense_data = SS_NO_SENSE;
  38564. + curlun->sense_data_info = 0;
  38565. + curlun->info_valid = 0;
  38566. + }
  38567. + } else {
  38568. + fsg->bad_lun_okay = 0;
  38569. +
  38570. + /* INQUIRY and REQUEST SENSE commands are explicitly allowed
  38571. + * to use unsupported LUNs; all others may not. */
  38572. + if (fsg->cmnd[0] != INQUIRY &&
  38573. + fsg->cmnd[0] != REQUEST_SENSE) {
  38574. + DBG(fsg, "unsupported LUN %d\n", fsg->lun);
  38575. + return -EINVAL;
  38576. + }
  38577. + }
  38578. +
  38579. + /* If a unit attention condition exists, only INQUIRY and
  38580. + * REQUEST SENSE commands are allowed; anything else must fail. */
  38581. + if (curlun && curlun->unit_attention_data != SS_NO_SENSE &&
  38582. + fsg->cmnd[0] != INQUIRY &&
  38583. + fsg->cmnd[0] != REQUEST_SENSE) {
  38584. + curlun->sense_data = curlun->unit_attention_data;
  38585. + curlun->unit_attention_data = SS_NO_SENSE;
  38586. + return -EINVAL;
  38587. + }
  38588. +
  38589. + /* Check that only command bytes listed in the mask are non-zero */
  38590. + fsg->cmnd[1] &= 0x1f; // Mask away the LUN
  38591. + for (i = 1; i < cmnd_size; ++i) {
  38592. + if (fsg->cmnd[i] && !(mask & (1 << i))) {
  38593. + if (curlun)
  38594. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  38595. + return -EINVAL;
  38596. + }
  38597. + }
  38598. +
  38599. + /* If the medium isn't mounted and the command needs to access
  38600. + * it, return an error. */
  38601. + if (curlun && !fsg_lun_is_open(curlun) && needs_medium) {
  38602. + curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
  38603. + return -EINVAL;
  38604. + }
  38605. +
  38606. + return 0;
  38607. +}
  38608. +
  38609. +/* wrapper of check_command for data size in blocks handling */
  38610. +static int check_command_size_in_blocks(struct fsg_dev *fsg, int cmnd_size,
  38611. + enum data_direction data_dir, unsigned int mask,
  38612. + int needs_medium, const char *name)
  38613. +{
  38614. + if (fsg->curlun)
  38615. + fsg->data_size_from_cmnd <<= fsg->curlun->blkbits;
  38616. + return check_command(fsg, cmnd_size, data_dir,
  38617. + mask, needs_medium, name);
  38618. +}
  38619. +
  38620. +static int do_scsi_command(struct fsg_dev *fsg)
  38621. +{
  38622. + struct fsg_buffhd *bh;
  38623. + int rc;
  38624. + int reply = -EINVAL;
  38625. + int i;
  38626. + static char unknown[16];
  38627. +
  38628. + dump_cdb(fsg);
  38629. +
  38630. + /* Wait for the next buffer to become available for data or status */
  38631. + bh = fsg->next_buffhd_to_drain = fsg->next_buffhd_to_fill;
  38632. + while (bh->state != BUF_STATE_EMPTY) {
  38633. + rc = sleep_thread(fsg);
  38634. + if (rc)
  38635. + return rc;
  38636. + }
  38637. + fsg->phase_error = 0;
  38638. + fsg->short_packet_received = 0;
  38639. +
  38640. + down_read(&fsg->filesem); // We're using the backing file
  38641. + switch (fsg->cmnd[0]) {
  38642. +
  38643. + case INQUIRY:
  38644. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  38645. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  38646. + (1<<4), 0,
  38647. + "INQUIRY")) == 0)
  38648. + reply = do_inquiry(fsg, bh);
  38649. + break;
  38650. +
  38651. + case MODE_SELECT:
  38652. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  38653. + if ((reply = check_command(fsg, 6, DATA_DIR_FROM_HOST,
  38654. + (1<<1) | (1<<4), 0,
  38655. + "MODE SELECT(6)")) == 0)
  38656. + reply = do_mode_select(fsg, bh);
  38657. + break;
  38658. +
  38659. + case MODE_SELECT_10:
  38660. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  38661. + if ((reply = check_command(fsg, 10, DATA_DIR_FROM_HOST,
  38662. + (1<<1) | (3<<7), 0,
  38663. + "MODE SELECT(10)")) == 0)
  38664. + reply = do_mode_select(fsg, bh);
  38665. + break;
  38666. +
  38667. + case MODE_SENSE:
  38668. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  38669. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  38670. + (1<<1) | (1<<2) | (1<<4), 0,
  38671. + "MODE SENSE(6)")) == 0)
  38672. + reply = do_mode_sense(fsg, bh);
  38673. + break;
  38674. +
  38675. + case MODE_SENSE_10:
  38676. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  38677. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  38678. + (1<<1) | (1<<2) | (3<<7), 0,
  38679. + "MODE SENSE(10)")) == 0)
  38680. + reply = do_mode_sense(fsg, bh);
  38681. + break;
  38682. +
  38683. + case ALLOW_MEDIUM_REMOVAL:
  38684. + fsg->data_size_from_cmnd = 0;
  38685. + if ((reply = check_command(fsg, 6, DATA_DIR_NONE,
  38686. + (1<<4), 0,
  38687. + "PREVENT-ALLOW MEDIUM REMOVAL")) == 0)
  38688. + reply = do_prevent_allow(fsg);
  38689. + break;
  38690. +
  38691. + case READ_6:
  38692. + i = fsg->cmnd[4];
  38693. + fsg->data_size_from_cmnd = (i == 0) ? 256 : i;
  38694. + if ((reply = check_command_size_in_blocks(fsg, 6,
  38695. + DATA_DIR_TO_HOST,
  38696. + (7<<1) | (1<<4), 1,
  38697. + "READ(6)")) == 0)
  38698. + reply = do_read(fsg);
  38699. + break;
  38700. +
  38701. + case READ_10:
  38702. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  38703. + if ((reply = check_command_size_in_blocks(fsg, 10,
  38704. + DATA_DIR_TO_HOST,
  38705. + (1<<1) | (0xf<<2) | (3<<7), 1,
  38706. + "READ(10)")) == 0)
  38707. + reply = do_read(fsg);
  38708. + break;
  38709. +
  38710. + case READ_12:
  38711. + fsg->data_size_from_cmnd = get_unaligned_be32(&fsg->cmnd[6]);
  38712. + if ((reply = check_command_size_in_blocks(fsg, 12,
  38713. + DATA_DIR_TO_HOST,
  38714. + (1<<1) | (0xf<<2) | (0xf<<6), 1,
  38715. + "READ(12)")) == 0)
  38716. + reply = do_read(fsg);
  38717. + break;
  38718. +
  38719. + case READ_CAPACITY:
  38720. + fsg->data_size_from_cmnd = 8;
  38721. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  38722. + (0xf<<2) | (1<<8), 1,
  38723. + "READ CAPACITY")) == 0)
  38724. + reply = do_read_capacity(fsg, bh);
  38725. + break;
  38726. +
  38727. + case READ_HEADER:
  38728. + if (!mod_data.cdrom)
  38729. + goto unknown_cmnd;
  38730. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  38731. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  38732. + (3<<7) | (0x1f<<1), 1,
  38733. + "READ HEADER")) == 0)
  38734. + reply = do_read_header(fsg, bh);
  38735. + break;
  38736. +
  38737. + case READ_TOC:
  38738. + if (!mod_data.cdrom)
  38739. + goto unknown_cmnd;
  38740. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  38741. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  38742. + (7<<6) | (1<<1), 1,
  38743. + "READ TOC")) == 0)
  38744. + reply = do_read_toc(fsg, bh);
  38745. + break;
  38746. +
  38747. + case READ_FORMAT_CAPACITIES:
  38748. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  38749. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  38750. + (3<<7), 1,
  38751. + "READ FORMAT CAPACITIES")) == 0)
  38752. + reply = do_read_format_capacities(fsg, bh);
  38753. + break;
  38754. +
  38755. + case REQUEST_SENSE:
  38756. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  38757. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  38758. + (1<<4), 0,
  38759. + "REQUEST SENSE")) == 0)
  38760. + reply = do_request_sense(fsg, bh);
  38761. + break;
  38762. +
  38763. + case START_STOP:
  38764. + fsg->data_size_from_cmnd = 0;
  38765. + if ((reply = check_command(fsg, 6, DATA_DIR_NONE,
  38766. + (1<<1) | (1<<4), 0,
  38767. + "START-STOP UNIT")) == 0)
  38768. + reply = do_start_stop(fsg);
  38769. + break;
  38770. +
  38771. + case SYNCHRONIZE_CACHE:
  38772. + fsg->data_size_from_cmnd = 0;
  38773. + if ((reply = check_command(fsg, 10, DATA_DIR_NONE,
  38774. + (0xf<<2) | (3<<7), 1,
  38775. + "SYNCHRONIZE CACHE")) == 0)
  38776. + reply = do_synchronize_cache(fsg);
  38777. + break;
  38778. +
  38779. + case TEST_UNIT_READY:
  38780. + fsg->data_size_from_cmnd = 0;
  38781. + reply = check_command(fsg, 6, DATA_DIR_NONE,
  38782. + 0, 1,
  38783. + "TEST UNIT READY");
  38784. + break;
  38785. +
  38786. + /* Although optional, this command is used by MS-Windows. We
  38787. + * support a minimal version: BytChk must be 0. */
  38788. + case VERIFY:
  38789. + fsg->data_size_from_cmnd = 0;
  38790. + if ((reply = check_command(fsg, 10, DATA_DIR_NONE,
  38791. + (1<<1) | (0xf<<2) | (3<<7), 1,
  38792. + "VERIFY")) == 0)
  38793. + reply = do_verify(fsg);
  38794. + break;
  38795. +
  38796. + case WRITE_6:
  38797. + i = fsg->cmnd[4];
  38798. + fsg->data_size_from_cmnd = (i == 0) ? 256 : i;
  38799. + if ((reply = check_command_size_in_blocks(fsg, 6,
  38800. + DATA_DIR_FROM_HOST,
  38801. + (7<<1) | (1<<4), 1,
  38802. + "WRITE(6)")) == 0)
  38803. + reply = do_write(fsg);
  38804. + break;
  38805. +
  38806. + case WRITE_10:
  38807. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  38808. + if ((reply = check_command_size_in_blocks(fsg, 10,
  38809. + DATA_DIR_FROM_HOST,
  38810. + (1<<1) | (0xf<<2) | (3<<7), 1,
  38811. + "WRITE(10)")) == 0)
  38812. + reply = do_write(fsg);
  38813. + break;
  38814. +
  38815. + case WRITE_12:
  38816. + fsg->data_size_from_cmnd = get_unaligned_be32(&fsg->cmnd[6]);
  38817. + if ((reply = check_command_size_in_blocks(fsg, 12,
  38818. + DATA_DIR_FROM_HOST,
  38819. + (1<<1) | (0xf<<2) | (0xf<<6), 1,
  38820. + "WRITE(12)")) == 0)
  38821. + reply = do_write(fsg);
  38822. + break;
  38823. +
  38824. + /* Some mandatory commands that we recognize but don't implement.
  38825. + * They don't mean much in this setting. It's left as an exercise
  38826. + * for anyone interested to implement RESERVE and RELEASE in terms
  38827. + * of Posix locks. */
  38828. + case FORMAT_UNIT:
  38829. + case RELEASE:
  38830. + case RESERVE:
  38831. + case SEND_DIAGNOSTIC:
  38832. + // Fall through
  38833. +
  38834. + default:
  38835. + unknown_cmnd:
  38836. + fsg->data_size_from_cmnd = 0;
  38837. + sprintf(unknown, "Unknown x%02x", fsg->cmnd[0]);
  38838. + if ((reply = check_command(fsg, fsg->cmnd_size,
  38839. + DATA_DIR_UNKNOWN, ~0, 0, unknown)) == 0) {
  38840. + fsg->curlun->sense_data = SS_INVALID_COMMAND;
  38841. + reply = -EINVAL;
  38842. + }
  38843. + break;
  38844. + }
  38845. + up_read(&fsg->filesem);
  38846. +
  38847. + if (reply == -EINTR || signal_pending(current))
  38848. + return -EINTR;
  38849. +
  38850. + /* Set up the single reply buffer for finish_reply() */
  38851. + if (reply == -EINVAL)
  38852. + reply = 0; // Error reply length
  38853. + if (reply >= 0 && fsg->data_dir == DATA_DIR_TO_HOST) {
  38854. + reply = min((u32) reply, fsg->data_size_from_cmnd);
  38855. + bh->inreq->length = reply;
  38856. + bh->state = BUF_STATE_FULL;
  38857. + fsg->residue -= reply;
  38858. + } // Otherwise it's already set
  38859. +
  38860. + return 0;
  38861. +}
  38862. +
  38863. +
  38864. +/*-------------------------------------------------------------------------*/
  38865. +
  38866. +static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  38867. +{
  38868. + struct usb_request *req = bh->outreq;
  38869. + struct bulk_cb_wrap *cbw = req->buf;
  38870. +
  38871. + /* Was this a real packet? Should it be ignored? */
  38872. + if (req->status || test_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
  38873. + return -EINVAL;
  38874. +
  38875. + /* Is the CBW valid? */
  38876. + if (req->actual != US_BULK_CB_WRAP_LEN ||
  38877. + cbw->Signature != cpu_to_le32(
  38878. + US_BULK_CB_SIGN)) {
  38879. + DBG(fsg, "invalid CBW: len %u sig 0x%x\n",
  38880. + req->actual,
  38881. + le32_to_cpu(cbw->Signature));
  38882. +
  38883. + /* The Bulk-only spec says we MUST stall the IN endpoint
  38884. + * (6.6.1), so it's unavoidable. It also says we must
  38885. + * retain this state until the next reset, but there's
  38886. + * no way to tell the controller driver it should ignore
  38887. + * Clear-Feature(HALT) requests.
  38888. + *
  38889. + * We aren't required to halt the OUT endpoint; instead
  38890. + * we can simply accept and discard any data received
  38891. + * until the next reset. */
  38892. + wedge_bulk_in_endpoint(fsg);
  38893. + set_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
  38894. + return -EINVAL;
  38895. + }
  38896. +
  38897. + /* Is the CBW meaningful? */
  38898. + if (cbw->Lun >= FSG_MAX_LUNS || cbw->Flags & ~US_BULK_FLAG_IN ||
  38899. + cbw->Length <= 0 || cbw->Length > MAX_COMMAND_SIZE) {
  38900. + DBG(fsg, "non-meaningful CBW: lun = %u, flags = 0x%x, "
  38901. + "cmdlen %u\n",
  38902. + cbw->Lun, cbw->Flags, cbw->Length);
  38903. +
  38904. + /* We can do anything we want here, so let's stall the
  38905. + * bulk pipes if we are allowed to. */
  38906. + if (mod_data.can_stall) {
  38907. + fsg_set_halt(fsg, fsg->bulk_out);
  38908. + halt_bulk_in_endpoint(fsg);
  38909. + }
  38910. + return -EINVAL;
  38911. + }
  38912. +
  38913. + /* Save the command for later */
  38914. + fsg->cmnd_size = cbw->Length;
  38915. + memcpy(fsg->cmnd, cbw->CDB, fsg->cmnd_size);
  38916. + if (cbw->Flags & US_BULK_FLAG_IN)
  38917. + fsg->data_dir = DATA_DIR_TO_HOST;
  38918. + else
  38919. + fsg->data_dir = DATA_DIR_FROM_HOST;
  38920. + fsg->data_size = le32_to_cpu(cbw->DataTransferLength);
  38921. + if (fsg->data_size == 0)
  38922. + fsg->data_dir = DATA_DIR_NONE;
  38923. + fsg->lun = cbw->Lun;
  38924. + fsg->tag = cbw->Tag;
  38925. + return 0;
  38926. +}
  38927. +
  38928. +
  38929. +static int get_next_command(struct fsg_dev *fsg)
  38930. +{
  38931. + struct fsg_buffhd *bh;
  38932. + int rc = 0;
  38933. +
  38934. + if (transport_is_bbb()) {
  38935. +
  38936. + /* Wait for the next buffer to become available */
  38937. + bh = fsg->next_buffhd_to_fill;
  38938. + while (bh->state != BUF_STATE_EMPTY) {
  38939. + rc = sleep_thread(fsg);
  38940. + if (rc)
  38941. + return rc;
  38942. + }
  38943. +
  38944. + /* Queue a request to read a Bulk-only CBW */
  38945. + set_bulk_out_req_length(fsg, bh, US_BULK_CB_WRAP_LEN);
  38946. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  38947. + &bh->outreq_busy, &bh->state);
  38948. +
  38949. + /* We will drain the buffer in software, which means we
  38950. + * can reuse it for the next filling. No need to advance
  38951. + * next_buffhd_to_fill. */
  38952. +
  38953. + /* Wait for the CBW to arrive */
  38954. + while (bh->state != BUF_STATE_FULL) {
  38955. + rc = sleep_thread(fsg);
  38956. + if (rc)
  38957. + return rc;
  38958. + }
  38959. + smp_rmb();
  38960. + rc = received_cbw(fsg, bh);
  38961. + bh->state = BUF_STATE_EMPTY;
  38962. +
  38963. + } else { // USB_PR_CB or USB_PR_CBI
  38964. +
  38965. + /* Wait for the next command to arrive */
  38966. + while (fsg->cbbuf_cmnd_size == 0) {
  38967. + rc = sleep_thread(fsg);
  38968. + if (rc)
  38969. + return rc;
  38970. + }
  38971. +
  38972. + /* Is the previous status interrupt request still busy?
  38973. + * The host is allowed to skip reading the status,
  38974. + * so we must cancel it. */
  38975. + if (fsg->intreq_busy)
  38976. + usb_ep_dequeue(fsg->intr_in, fsg->intreq);
  38977. +
  38978. + /* Copy the command and mark the buffer empty */
  38979. + fsg->data_dir = DATA_DIR_UNKNOWN;
  38980. + spin_lock_irq(&fsg->lock);
  38981. + fsg->cmnd_size = fsg->cbbuf_cmnd_size;
  38982. + memcpy(fsg->cmnd, fsg->cbbuf_cmnd, fsg->cmnd_size);
  38983. + fsg->cbbuf_cmnd_size = 0;
  38984. + spin_unlock_irq(&fsg->lock);
  38985. +
  38986. + /* Use LUN from the command */
  38987. + fsg->lun = fsg->cmnd[1] >> 5;
  38988. + }
  38989. +
  38990. + /* Update current lun */
  38991. + if (fsg->lun >= 0 && fsg->lun < fsg->nluns)
  38992. + fsg->curlun = &fsg->luns[fsg->lun];
  38993. + else
  38994. + fsg->curlun = NULL;
  38995. +
  38996. + return rc;
  38997. +}
  38998. +
  38999. +
  39000. +/*-------------------------------------------------------------------------*/
  39001. +
  39002. +static int enable_endpoint(struct fsg_dev *fsg, struct usb_ep *ep,
  39003. + const struct usb_endpoint_descriptor *d)
  39004. +{
  39005. + int rc;
  39006. +
  39007. + ep->driver_data = fsg;
  39008. + ep->desc = d;
  39009. + rc = usb_ep_enable(ep);
  39010. + if (rc)
  39011. + ERROR(fsg, "can't enable %s, result %d\n", ep->name, rc);
  39012. + return rc;
  39013. +}
  39014. +
  39015. +static int alloc_request(struct fsg_dev *fsg, struct usb_ep *ep,
  39016. + struct usb_request **preq)
  39017. +{
  39018. + *preq = usb_ep_alloc_request(ep, GFP_ATOMIC);
  39019. + if (*preq)
  39020. + return 0;
  39021. + ERROR(fsg, "can't allocate request for %s\n", ep->name);
  39022. + return -ENOMEM;
  39023. +}
  39024. +
  39025. +/*
  39026. + * Reset interface setting and re-init endpoint state (toggle etc).
  39027. + * Call with altsetting < 0 to disable the interface. The only other
  39028. + * available altsetting is 0, which enables the interface.
  39029. + */
  39030. +static int do_set_interface(struct fsg_dev *fsg, int altsetting)
  39031. +{
  39032. + int rc = 0;
  39033. + int i;
  39034. + const struct usb_endpoint_descriptor *d;
  39035. +
  39036. + if (fsg->running)
  39037. + DBG(fsg, "reset interface\n");
  39038. +
  39039. +reset:
  39040. + /* Deallocate the requests */
  39041. + for (i = 0; i < fsg_num_buffers; ++i) {
  39042. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  39043. +
  39044. + if (bh->inreq) {
  39045. + usb_ep_free_request(fsg->bulk_in, bh->inreq);
  39046. + bh->inreq = NULL;
  39047. + }
  39048. + if (bh->outreq) {
  39049. + usb_ep_free_request(fsg->bulk_out, bh->outreq);
  39050. + bh->outreq = NULL;
  39051. + }
  39052. + }
  39053. + if (fsg->intreq) {
  39054. + usb_ep_free_request(fsg->intr_in, fsg->intreq);
  39055. + fsg->intreq = NULL;
  39056. + }
  39057. +
  39058. + /* Disable the endpoints */
  39059. + if (fsg->bulk_in_enabled) {
  39060. + usb_ep_disable(fsg->bulk_in);
  39061. + fsg->bulk_in_enabled = 0;
  39062. + }
  39063. + if (fsg->bulk_out_enabled) {
  39064. + usb_ep_disable(fsg->bulk_out);
  39065. + fsg->bulk_out_enabled = 0;
  39066. + }
  39067. + if (fsg->intr_in_enabled) {
  39068. + usb_ep_disable(fsg->intr_in);
  39069. + fsg->intr_in_enabled = 0;
  39070. + }
  39071. +
  39072. + fsg->running = 0;
  39073. + if (altsetting < 0 || rc != 0)
  39074. + return rc;
  39075. +
  39076. + DBG(fsg, "set interface %d\n", altsetting);
  39077. +
  39078. + /* Enable the endpoints */
  39079. + d = fsg_ep_desc(fsg->gadget,
  39080. + &fsg_fs_bulk_in_desc, &fsg_hs_bulk_in_desc,
  39081. + &fsg_ss_bulk_in_desc);
  39082. + if ((rc = enable_endpoint(fsg, fsg->bulk_in, d)) != 0)
  39083. + goto reset;
  39084. + fsg->bulk_in_enabled = 1;
  39085. +
  39086. + d = fsg_ep_desc(fsg->gadget,
  39087. + &fsg_fs_bulk_out_desc, &fsg_hs_bulk_out_desc,
  39088. + &fsg_ss_bulk_out_desc);
  39089. + if ((rc = enable_endpoint(fsg, fsg->bulk_out, d)) != 0)
  39090. + goto reset;
  39091. + fsg->bulk_out_enabled = 1;
  39092. + fsg->bulk_out_maxpacket = usb_endpoint_maxp(d);
  39093. + clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
  39094. +
  39095. + if (transport_is_cbi()) {
  39096. + d = fsg_ep_desc(fsg->gadget,
  39097. + &fsg_fs_intr_in_desc, &fsg_hs_intr_in_desc,
  39098. + &fsg_ss_intr_in_desc);
  39099. + if ((rc = enable_endpoint(fsg, fsg->intr_in, d)) != 0)
  39100. + goto reset;
  39101. + fsg->intr_in_enabled = 1;
  39102. + }
  39103. +
  39104. + /* Allocate the requests */
  39105. + for (i = 0; i < fsg_num_buffers; ++i) {
  39106. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  39107. +
  39108. + if ((rc = alloc_request(fsg, fsg->bulk_in, &bh->inreq)) != 0)
  39109. + goto reset;
  39110. + if ((rc = alloc_request(fsg, fsg->bulk_out, &bh->outreq)) != 0)
  39111. + goto reset;
  39112. + bh->inreq->buf = bh->outreq->buf = bh->buf;
  39113. + bh->inreq->context = bh->outreq->context = bh;
  39114. + bh->inreq->complete = bulk_in_complete;
  39115. + bh->outreq->complete = bulk_out_complete;
  39116. + }
  39117. + if (transport_is_cbi()) {
  39118. + if ((rc = alloc_request(fsg, fsg->intr_in, &fsg->intreq)) != 0)
  39119. + goto reset;
  39120. + fsg->intreq->complete = intr_in_complete;
  39121. + }
  39122. +
  39123. + fsg->running = 1;
  39124. + for (i = 0; i < fsg->nluns; ++i)
  39125. + fsg->luns[i].unit_attention_data = SS_RESET_OCCURRED;
  39126. + return rc;
  39127. +}
  39128. +
  39129. +
  39130. +/*
  39131. + * Change our operational configuration. This code must agree with the code
  39132. + * that returns config descriptors, and with interface altsetting code.
  39133. + *
  39134. + * It's also responsible for power management interactions. Some
  39135. + * configurations might not work with our current power sources.
  39136. + * For now we just assume the gadget is always self-powered.
  39137. + */
  39138. +static int do_set_config(struct fsg_dev *fsg, u8 new_config)
  39139. +{
  39140. + int rc = 0;
  39141. +
  39142. + /* Disable the single interface */
  39143. + if (fsg->config != 0) {
  39144. + DBG(fsg, "reset config\n");
  39145. + fsg->config = 0;
  39146. + rc = do_set_interface(fsg, -1);
  39147. + }
  39148. +
  39149. + /* Enable the interface */
  39150. + if (new_config != 0) {
  39151. + fsg->config = new_config;
  39152. + if ((rc = do_set_interface(fsg, 0)) != 0)
  39153. + fsg->config = 0; // Reset on errors
  39154. + else
  39155. + INFO(fsg, "%s config #%d\n",
  39156. + usb_speed_string(fsg->gadget->speed),
  39157. + fsg->config);
  39158. + }
  39159. + return rc;
  39160. +}
  39161. +
  39162. +
  39163. +/*-------------------------------------------------------------------------*/
  39164. +
  39165. +static void handle_exception(struct fsg_dev *fsg)
  39166. +{
  39167. + siginfo_t info;
  39168. + int sig;
  39169. + int i;
  39170. + int num_active;
  39171. + struct fsg_buffhd *bh;
  39172. + enum fsg_state old_state;
  39173. + u8 new_config;
  39174. + struct fsg_lun *curlun;
  39175. + unsigned int exception_req_tag;
  39176. + int rc;
  39177. +
  39178. + /* Clear the existing signals. Anything but SIGUSR1 is converted
  39179. + * into a high-priority EXIT exception. */
  39180. + for (;;) {
  39181. + sig = dequeue_signal_lock(current, &current->blocked, &info);
  39182. + if (!sig)
  39183. + break;
  39184. + if (sig != SIGUSR1) {
  39185. + if (fsg->state < FSG_STATE_EXIT)
  39186. + DBG(fsg, "Main thread exiting on signal\n");
  39187. + raise_exception(fsg, FSG_STATE_EXIT);
  39188. + }
  39189. + }
  39190. +
  39191. + /* Cancel all the pending transfers */
  39192. + if (fsg->intreq_busy)
  39193. + usb_ep_dequeue(fsg->intr_in, fsg->intreq);
  39194. + for (i = 0; i < fsg_num_buffers; ++i) {
  39195. + bh = &fsg->buffhds[i];
  39196. + if (bh->inreq_busy)
  39197. + usb_ep_dequeue(fsg->bulk_in, bh->inreq);
  39198. + if (bh->outreq_busy)
  39199. + usb_ep_dequeue(fsg->bulk_out, bh->outreq);
  39200. + }
  39201. +
  39202. + /* Wait until everything is idle */
  39203. + for (;;) {
  39204. + num_active = fsg->intreq_busy;
  39205. + for (i = 0; i < fsg_num_buffers; ++i) {
  39206. + bh = &fsg->buffhds[i];
  39207. + num_active += bh->inreq_busy + bh->outreq_busy;
  39208. + }
  39209. + if (num_active == 0)
  39210. + break;
  39211. + if (sleep_thread(fsg))
  39212. + return;
  39213. + }
  39214. +
  39215. + /* Clear out the controller's fifos */
  39216. + if (fsg->bulk_in_enabled)
  39217. + usb_ep_fifo_flush(fsg->bulk_in);
  39218. + if (fsg->bulk_out_enabled)
  39219. + usb_ep_fifo_flush(fsg->bulk_out);
  39220. + if (fsg->intr_in_enabled)
  39221. + usb_ep_fifo_flush(fsg->intr_in);
  39222. +
  39223. + /* Reset the I/O buffer states and pointers, the SCSI
  39224. + * state, and the exception. Then invoke the handler. */
  39225. + spin_lock_irq(&fsg->lock);
  39226. +
  39227. + for (i = 0; i < fsg_num_buffers; ++i) {
  39228. + bh = &fsg->buffhds[i];
  39229. + bh->state = BUF_STATE_EMPTY;
  39230. + }
  39231. + fsg->next_buffhd_to_fill = fsg->next_buffhd_to_drain =
  39232. + &fsg->buffhds[0];
  39233. +
  39234. + exception_req_tag = fsg->exception_req_tag;
  39235. + new_config = fsg->new_config;
  39236. + old_state = fsg->state;
  39237. +
  39238. + if (old_state == FSG_STATE_ABORT_BULK_OUT)
  39239. + fsg->state = FSG_STATE_STATUS_PHASE;
  39240. + else {
  39241. + for (i = 0; i < fsg->nluns; ++i) {
  39242. + curlun = &fsg->luns[i];
  39243. + curlun->prevent_medium_removal = 0;
  39244. + curlun->sense_data = curlun->unit_attention_data =
  39245. + SS_NO_SENSE;
  39246. + curlun->sense_data_info = 0;
  39247. + curlun->info_valid = 0;
  39248. + }
  39249. + fsg->state = FSG_STATE_IDLE;
  39250. + }
  39251. + spin_unlock_irq(&fsg->lock);
  39252. +
  39253. + /* Carry out any extra actions required for the exception */
  39254. + switch (old_state) {
  39255. + default:
  39256. + break;
  39257. +
  39258. + case FSG_STATE_ABORT_BULK_OUT:
  39259. + send_status(fsg);
  39260. + spin_lock_irq(&fsg->lock);
  39261. + if (fsg->state == FSG_STATE_STATUS_PHASE)
  39262. + fsg->state = FSG_STATE_IDLE;
  39263. + spin_unlock_irq(&fsg->lock);
  39264. + break;
  39265. +
  39266. + case FSG_STATE_RESET:
  39267. + /* In case we were forced against our will to halt a
  39268. + * bulk endpoint, clear the halt now. (The SuperH UDC
  39269. + * requires this.) */
  39270. + if (test_and_clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
  39271. + usb_ep_clear_halt(fsg->bulk_in);
  39272. +
  39273. + if (transport_is_bbb()) {
  39274. + if (fsg->ep0_req_tag == exception_req_tag)
  39275. + ep0_queue(fsg); // Complete the status stage
  39276. +
  39277. + } else if (transport_is_cbi())
  39278. + send_status(fsg); // Status by interrupt pipe
  39279. +
  39280. + /* Technically this should go here, but it would only be
  39281. + * a waste of time. Ditto for the INTERFACE_CHANGE and
  39282. + * CONFIG_CHANGE cases. */
  39283. + // for (i = 0; i < fsg->nluns; ++i)
  39284. + // fsg->luns[i].unit_attention_data = SS_RESET_OCCURRED;
  39285. + break;
  39286. +
  39287. + case FSG_STATE_INTERFACE_CHANGE:
  39288. + rc = do_set_interface(fsg, 0);
  39289. + if (fsg->ep0_req_tag != exception_req_tag)
  39290. + break;
  39291. + if (rc != 0) // STALL on errors
  39292. + fsg_set_halt(fsg, fsg->ep0);
  39293. + else // Complete the status stage
  39294. + ep0_queue(fsg);
  39295. + break;
  39296. +
  39297. + case FSG_STATE_CONFIG_CHANGE:
  39298. + rc = do_set_config(fsg, new_config);
  39299. + if (fsg->ep0_req_tag != exception_req_tag)
  39300. + break;
  39301. + if (rc != 0) // STALL on errors
  39302. + fsg_set_halt(fsg, fsg->ep0);
  39303. + else // Complete the status stage
  39304. + ep0_queue(fsg);
  39305. + break;
  39306. +
  39307. + case FSG_STATE_DISCONNECT:
  39308. + for (i = 0; i < fsg->nluns; ++i)
  39309. + fsg_lun_fsync_sub(fsg->luns + i);
  39310. + do_set_config(fsg, 0); // Unconfigured state
  39311. + break;
  39312. +
  39313. + case FSG_STATE_EXIT:
  39314. + case FSG_STATE_TERMINATED:
  39315. + do_set_config(fsg, 0); // Free resources
  39316. + spin_lock_irq(&fsg->lock);
  39317. + fsg->state = FSG_STATE_TERMINATED; // Stop the thread
  39318. + spin_unlock_irq(&fsg->lock);
  39319. + break;
  39320. + }
  39321. +}
  39322. +
  39323. +
  39324. +/*-------------------------------------------------------------------------*/
  39325. +
  39326. +static int fsg_main_thread(void *fsg_)
  39327. +{
  39328. + struct fsg_dev *fsg = fsg_;
  39329. +
  39330. + /* Allow the thread to be killed by a signal, but set the signal mask
  39331. + * to block everything but INT, TERM, KILL, and USR1. */
  39332. + allow_signal(SIGINT);
  39333. + allow_signal(SIGTERM);
  39334. + allow_signal(SIGKILL);
  39335. + allow_signal(SIGUSR1);
  39336. +
  39337. + /* Allow the thread to be frozen */
  39338. + set_freezable();
  39339. +
  39340. + /* Arrange for userspace references to be interpreted as kernel
  39341. + * pointers. That way we can pass a kernel pointer to a routine
  39342. + * that expects a __user pointer and it will work okay. */
  39343. + set_fs(get_ds());
  39344. +
  39345. + /* The main loop */
  39346. + while (fsg->state != FSG_STATE_TERMINATED) {
  39347. + if (exception_in_progress(fsg) || signal_pending(current)) {
  39348. + handle_exception(fsg);
  39349. + continue;
  39350. + }
  39351. +
  39352. + if (!fsg->running) {
  39353. + sleep_thread(fsg);
  39354. + continue;
  39355. + }
  39356. +
  39357. + if (get_next_command(fsg))
  39358. + continue;
  39359. +
  39360. + spin_lock_irq(&fsg->lock);
  39361. + if (!exception_in_progress(fsg))
  39362. + fsg->state = FSG_STATE_DATA_PHASE;
  39363. + spin_unlock_irq(&fsg->lock);
  39364. +
  39365. + if (do_scsi_command(fsg) || finish_reply(fsg))
  39366. + continue;
  39367. +
  39368. + spin_lock_irq(&fsg->lock);
  39369. + if (!exception_in_progress(fsg))
  39370. + fsg->state = FSG_STATE_STATUS_PHASE;
  39371. + spin_unlock_irq(&fsg->lock);
  39372. +
  39373. + if (send_status(fsg))
  39374. + continue;
  39375. +
  39376. + spin_lock_irq(&fsg->lock);
  39377. + if (!exception_in_progress(fsg))
  39378. + fsg->state = FSG_STATE_IDLE;
  39379. + spin_unlock_irq(&fsg->lock);
  39380. + }
  39381. +
  39382. + spin_lock_irq(&fsg->lock);
  39383. + fsg->thread_task = NULL;
  39384. + spin_unlock_irq(&fsg->lock);
  39385. +
  39386. + /* If we are exiting because of a signal, unregister the
  39387. + * gadget driver. */
  39388. + if (test_and_clear_bit(REGISTERED, &fsg->atomic_bitflags))
  39389. + usb_gadget_unregister_driver(&fsg_driver);
  39390. +
  39391. + /* Let the unbind and cleanup routines know the thread has exited */
  39392. + complete_and_exit(&fsg->thread_notifier, 0);
  39393. +}
  39394. +
  39395. +
  39396. +/*-------------------------------------------------------------------------*/
  39397. +
  39398. +
  39399. +/* The write permissions and store_xxx pointers are set in fsg_bind() */
  39400. +static DEVICE_ATTR(ro, 0444, fsg_show_ro, NULL);
  39401. +static DEVICE_ATTR(nofua, 0644, fsg_show_nofua, NULL);
  39402. +static DEVICE_ATTR(file, 0444, fsg_show_file, NULL);
  39403. +
  39404. +
  39405. +/*-------------------------------------------------------------------------*/
  39406. +
  39407. +static void fsg_release(struct kref *ref)
  39408. +{
  39409. + struct fsg_dev *fsg = container_of(ref, struct fsg_dev, ref);
  39410. +
  39411. + kfree(fsg->luns);
  39412. + kfree(fsg);
  39413. +}
  39414. +
  39415. +static void lun_release(struct device *dev)
  39416. +{
  39417. + struct rw_semaphore *filesem = dev_get_drvdata(dev);
  39418. + struct fsg_dev *fsg =
  39419. + container_of(filesem, struct fsg_dev, filesem);
  39420. +
  39421. + kref_put(&fsg->ref, fsg_release);
  39422. +}
  39423. +
  39424. +static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget)
  39425. +{
  39426. + struct fsg_dev *fsg = get_gadget_data(gadget);
  39427. + int i;
  39428. + struct fsg_lun *curlun;
  39429. + struct usb_request *req = fsg->ep0req;
  39430. +
  39431. + DBG(fsg, "unbind\n");
  39432. + clear_bit(REGISTERED, &fsg->atomic_bitflags);
  39433. +
  39434. + /* If the thread isn't already dead, tell it to exit now */
  39435. + if (fsg->state != FSG_STATE_TERMINATED) {
  39436. + raise_exception(fsg, FSG_STATE_EXIT);
  39437. + wait_for_completion(&fsg->thread_notifier);
  39438. +
  39439. + /* The cleanup routine waits for this completion also */
  39440. + complete(&fsg->thread_notifier);
  39441. + }
  39442. +
  39443. + /* Unregister the sysfs attribute files and the LUNs */
  39444. + for (i = 0; i < fsg->nluns; ++i) {
  39445. + curlun = &fsg->luns[i];
  39446. + if (curlun->registered) {
  39447. + device_remove_file(&curlun->dev, &dev_attr_nofua);
  39448. + device_remove_file(&curlun->dev, &dev_attr_ro);
  39449. + device_remove_file(&curlun->dev, &dev_attr_file);
  39450. + fsg_lun_close(curlun);
  39451. + device_unregister(&curlun->dev);
  39452. + curlun->registered = 0;
  39453. + }
  39454. + }
  39455. +
  39456. + /* Free the data buffers */
  39457. + for (i = 0; i < fsg_num_buffers; ++i)
  39458. + kfree(fsg->buffhds[i].buf);
  39459. +
  39460. + /* Free the request and buffer for endpoint 0 */
  39461. + if (req) {
  39462. + kfree(req->buf);
  39463. + usb_ep_free_request(fsg->ep0, req);
  39464. + }
  39465. +
  39466. + set_gadget_data(gadget, NULL);
  39467. +}
  39468. +
  39469. +
  39470. +static int __init check_parameters(struct fsg_dev *fsg)
  39471. +{
  39472. + int prot;
  39473. + int gcnum;
  39474. +
  39475. + /* Store the default values */
  39476. + mod_data.transport_type = USB_PR_BULK;
  39477. + mod_data.transport_name = "Bulk-only";
  39478. + mod_data.protocol_type = USB_SC_SCSI;
  39479. + mod_data.protocol_name = "Transparent SCSI";
  39480. +
  39481. + /* Some peripheral controllers are known not to be able to
  39482. + * halt bulk endpoints correctly. If one of them is present,
  39483. + * disable stalls.
  39484. + */
  39485. + if (gadget_is_at91(fsg->gadget))
  39486. + mod_data.can_stall = 0;
  39487. +
  39488. + if (mod_data.release == 0xffff) { // Parameter wasn't set
  39489. + gcnum = usb_gadget_controller_number(fsg->gadget);
  39490. + if (gcnum >= 0)
  39491. + mod_data.release = 0x0300 + gcnum;
  39492. + else {
  39493. + WARNING(fsg, "controller '%s' not recognized\n",
  39494. + fsg->gadget->name);
  39495. + mod_data.release = 0x0399;
  39496. + }
  39497. + }
  39498. +
  39499. + prot = simple_strtol(mod_data.protocol_parm, NULL, 0);
  39500. +
  39501. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  39502. + if (strnicmp(mod_data.transport_parm, "BBB", 10) == 0) {
  39503. + ; // Use default setting
  39504. + } else if (strnicmp(mod_data.transport_parm, "CB", 10) == 0) {
  39505. + mod_data.transport_type = USB_PR_CB;
  39506. + mod_data.transport_name = "Control-Bulk";
  39507. + } else if (strnicmp(mod_data.transport_parm, "CBI", 10) == 0) {
  39508. + mod_data.transport_type = USB_PR_CBI;
  39509. + mod_data.transport_name = "Control-Bulk-Interrupt";
  39510. + } else {
  39511. + ERROR(fsg, "invalid transport: %s\n", mod_data.transport_parm);
  39512. + return -EINVAL;
  39513. + }
  39514. +
  39515. + if (strnicmp(mod_data.protocol_parm, "SCSI", 10) == 0 ||
  39516. + prot == USB_SC_SCSI) {
  39517. + ; // Use default setting
  39518. + } else if (strnicmp(mod_data.protocol_parm, "RBC", 10) == 0 ||
  39519. + prot == USB_SC_RBC) {
  39520. + mod_data.protocol_type = USB_SC_RBC;
  39521. + mod_data.protocol_name = "RBC";
  39522. + } else if (strnicmp(mod_data.protocol_parm, "8020", 4) == 0 ||
  39523. + strnicmp(mod_data.protocol_parm, "ATAPI", 10) == 0 ||
  39524. + prot == USB_SC_8020) {
  39525. + mod_data.protocol_type = USB_SC_8020;
  39526. + mod_data.protocol_name = "8020i (ATAPI)";
  39527. + } else if (strnicmp(mod_data.protocol_parm, "QIC", 3) == 0 ||
  39528. + prot == USB_SC_QIC) {
  39529. + mod_data.protocol_type = USB_SC_QIC;
  39530. + mod_data.protocol_name = "QIC-157";
  39531. + } else if (strnicmp(mod_data.protocol_parm, "UFI", 10) == 0 ||
  39532. + prot == USB_SC_UFI) {
  39533. + mod_data.protocol_type = USB_SC_UFI;
  39534. + mod_data.protocol_name = "UFI";
  39535. + } else if (strnicmp(mod_data.protocol_parm, "8070", 4) == 0 ||
  39536. + prot == USB_SC_8070) {
  39537. + mod_data.protocol_type = USB_SC_8070;
  39538. + mod_data.protocol_name = "8070i";
  39539. + } else {
  39540. + ERROR(fsg, "invalid protocol: %s\n", mod_data.protocol_parm);
  39541. + return -EINVAL;
  39542. + }
  39543. +
  39544. + mod_data.buflen &= PAGE_CACHE_MASK;
  39545. + if (mod_data.buflen <= 0) {
  39546. + ERROR(fsg, "invalid buflen\n");
  39547. + return -ETOOSMALL;
  39548. + }
  39549. +
  39550. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  39551. +
  39552. + /* Serial string handling.
  39553. + * On a real device, the serial string would be loaded
  39554. + * from permanent storage. */
  39555. + if (mod_data.serial) {
  39556. + const char *ch;
  39557. + unsigned len = 0;
  39558. +
  39559. + /* Sanity check :
  39560. + * The CB[I] specification limits the serial string to
  39561. + * 12 uppercase hexadecimal characters.
  39562. + * BBB need at least 12 uppercase hexadecimal characters,
  39563. + * with a maximum of 126. */
  39564. + for (ch = mod_data.serial; *ch; ++ch) {
  39565. + ++len;
  39566. + if ((*ch < '0' || *ch > '9') &&
  39567. + (*ch < 'A' || *ch > 'F')) { /* not uppercase hex */
  39568. + WARNING(fsg,
  39569. + "Invalid serial string character: %c\n",
  39570. + *ch);
  39571. + goto no_serial;
  39572. + }
  39573. + }
  39574. + if (len > 126 ||
  39575. + (mod_data.transport_type == USB_PR_BULK && len < 12) ||
  39576. + (mod_data.transport_type != USB_PR_BULK && len > 12)) {
  39577. + WARNING(fsg, "Invalid serial string length!\n");
  39578. + goto no_serial;
  39579. + }
  39580. + fsg_strings[FSG_STRING_SERIAL - 1].s = mod_data.serial;
  39581. + } else {
  39582. + WARNING(fsg, "No serial-number string provided!\n");
  39583. + no_serial:
  39584. + device_desc.iSerialNumber = 0;
  39585. + }
  39586. +
  39587. + return 0;
  39588. +}
  39589. +
  39590. +
  39591. +static int __init fsg_bind(struct usb_gadget *gadget)
  39592. +{
  39593. + struct fsg_dev *fsg = the_fsg;
  39594. + int rc;
  39595. + int i;
  39596. + struct fsg_lun *curlun;
  39597. + struct usb_ep *ep;
  39598. + struct usb_request *req;
  39599. + char *pathbuf, *p;
  39600. +
  39601. + fsg->gadget = gadget;
  39602. + set_gadget_data(gadget, fsg);
  39603. + fsg->ep0 = gadget->ep0;
  39604. + fsg->ep0->driver_data = fsg;
  39605. +
  39606. + if ((rc = check_parameters(fsg)) != 0)
  39607. + goto out;
  39608. +
  39609. + if (mod_data.removable) { // Enable the store_xxx attributes
  39610. + dev_attr_file.attr.mode = 0644;
  39611. + dev_attr_file.store = fsg_store_file;
  39612. + if (!mod_data.cdrom) {
  39613. + dev_attr_ro.attr.mode = 0644;
  39614. + dev_attr_ro.store = fsg_store_ro;
  39615. + }
  39616. + }
  39617. +
  39618. + /* Only for removable media? */
  39619. + dev_attr_nofua.attr.mode = 0644;
  39620. + dev_attr_nofua.store = fsg_store_nofua;
  39621. +
  39622. + /* Find out how many LUNs there should be */
  39623. + i = mod_data.nluns;
  39624. + if (i == 0)
  39625. + i = max(mod_data.num_filenames, 1u);
  39626. + if (i > FSG_MAX_LUNS) {
  39627. + ERROR(fsg, "invalid number of LUNs: %d\n", i);
  39628. + rc = -EINVAL;
  39629. + goto out;
  39630. + }
  39631. +
  39632. + /* Create the LUNs, open their backing files, and register the
  39633. + * LUN devices in sysfs. */
  39634. + fsg->luns = kzalloc(i * sizeof(struct fsg_lun), GFP_KERNEL);
  39635. + if (!fsg->luns) {
  39636. + rc = -ENOMEM;
  39637. + goto out;
  39638. + }
  39639. + fsg->nluns = i;
  39640. +
  39641. + for (i = 0; i < fsg->nluns; ++i) {
  39642. + curlun = &fsg->luns[i];
  39643. + curlun->cdrom = !!mod_data.cdrom;
  39644. + curlun->ro = mod_data.cdrom || mod_data.ro[i];
  39645. + curlun->initially_ro = curlun->ro;
  39646. + curlun->removable = mod_data.removable;
  39647. + curlun->nofua = mod_data.nofua[i];
  39648. + curlun->dev.release = lun_release;
  39649. + curlun->dev.parent = &gadget->dev;
  39650. + curlun->dev.driver = &fsg_driver.driver;
  39651. + dev_set_drvdata(&curlun->dev, &fsg->filesem);
  39652. + dev_set_name(&curlun->dev,"%s-lun%d",
  39653. + dev_name(&gadget->dev), i);
  39654. +
  39655. + kref_get(&fsg->ref);
  39656. + rc = device_register(&curlun->dev);
  39657. + if (rc) {
  39658. + INFO(fsg, "failed to register LUN%d: %d\n", i, rc);
  39659. + put_device(&curlun->dev);
  39660. + goto out;
  39661. + }
  39662. + curlun->registered = 1;
  39663. +
  39664. + rc = device_create_file(&curlun->dev, &dev_attr_ro);
  39665. + if (rc)
  39666. + goto out;
  39667. + rc = device_create_file(&curlun->dev, &dev_attr_nofua);
  39668. + if (rc)
  39669. + goto out;
  39670. + rc = device_create_file(&curlun->dev, &dev_attr_file);
  39671. + if (rc)
  39672. + goto out;
  39673. +
  39674. + if (mod_data.file[i] && *mod_data.file[i]) {
  39675. + rc = fsg_lun_open(curlun, mod_data.file[i]);
  39676. + if (rc)
  39677. + goto out;
  39678. + } else if (!mod_data.removable) {
  39679. + ERROR(fsg, "no file given for LUN%d\n", i);
  39680. + rc = -EINVAL;
  39681. + goto out;
  39682. + }
  39683. + }
  39684. +
  39685. + /* Find all the endpoints we will use */
  39686. + usb_ep_autoconfig_reset(gadget);
  39687. + ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_in_desc);
  39688. + if (!ep)
  39689. + goto autoconf_fail;
  39690. + ep->driver_data = fsg; // claim the endpoint
  39691. + fsg->bulk_in = ep;
  39692. +
  39693. + ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_out_desc);
  39694. + if (!ep)
  39695. + goto autoconf_fail;
  39696. + ep->driver_data = fsg; // claim the endpoint
  39697. + fsg->bulk_out = ep;
  39698. +
  39699. + if (transport_is_cbi()) {
  39700. + ep = usb_ep_autoconfig(gadget, &fsg_fs_intr_in_desc);
  39701. + if (!ep)
  39702. + goto autoconf_fail;
  39703. + ep->driver_data = fsg; // claim the endpoint
  39704. + fsg->intr_in = ep;
  39705. + }
  39706. +
  39707. + /* Fix up the descriptors */
  39708. + device_desc.idVendor = cpu_to_le16(mod_data.vendor);
  39709. + device_desc.idProduct = cpu_to_le16(mod_data.product);
  39710. + device_desc.bcdDevice = cpu_to_le16(mod_data.release);
  39711. +
  39712. + i = (transport_is_cbi() ? 3 : 2); // Number of endpoints
  39713. + fsg_intf_desc.bNumEndpoints = i;
  39714. + fsg_intf_desc.bInterfaceSubClass = mod_data.protocol_type;
  39715. + fsg_intf_desc.bInterfaceProtocol = mod_data.transport_type;
  39716. + fsg_fs_function[i + FSG_FS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  39717. +
  39718. + if (gadget_is_dualspeed(gadget)) {
  39719. + fsg_hs_function[i + FSG_HS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  39720. +
  39721. + /* Assume endpoint addresses are the same for both speeds */
  39722. + fsg_hs_bulk_in_desc.bEndpointAddress =
  39723. + fsg_fs_bulk_in_desc.bEndpointAddress;
  39724. + fsg_hs_bulk_out_desc.bEndpointAddress =
  39725. + fsg_fs_bulk_out_desc.bEndpointAddress;
  39726. + fsg_hs_intr_in_desc.bEndpointAddress =
  39727. + fsg_fs_intr_in_desc.bEndpointAddress;
  39728. + }
  39729. +
  39730. + if (gadget_is_superspeed(gadget)) {
  39731. + unsigned max_burst;
  39732. +
  39733. + fsg_ss_function[i + FSG_SS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  39734. +
  39735. + /* Calculate bMaxBurst, we know packet size is 1024 */
  39736. + max_burst = min_t(unsigned, mod_data.buflen / 1024, 15);
  39737. +
  39738. + /* Assume endpoint addresses are the same for both speeds */
  39739. + fsg_ss_bulk_in_desc.bEndpointAddress =
  39740. + fsg_fs_bulk_in_desc.bEndpointAddress;
  39741. + fsg_ss_bulk_in_comp_desc.bMaxBurst = max_burst;
  39742. +
  39743. + fsg_ss_bulk_out_desc.bEndpointAddress =
  39744. + fsg_fs_bulk_out_desc.bEndpointAddress;
  39745. + fsg_ss_bulk_out_comp_desc.bMaxBurst = max_burst;
  39746. + }
  39747. +
  39748. + if (gadget_is_otg(gadget))
  39749. + fsg_otg_desc.bmAttributes |= USB_OTG_HNP;
  39750. +
  39751. + rc = -ENOMEM;
  39752. +
  39753. + /* Allocate the request and buffer for endpoint 0 */
  39754. + fsg->ep0req = req = usb_ep_alloc_request(fsg->ep0, GFP_KERNEL);
  39755. + if (!req)
  39756. + goto out;
  39757. + req->buf = kmalloc(EP0_BUFSIZE, GFP_KERNEL);
  39758. + if (!req->buf)
  39759. + goto out;
  39760. + req->complete = ep0_complete;
  39761. +
  39762. + /* Allocate the data buffers */
  39763. + for (i = 0; i < fsg_num_buffers; ++i) {
  39764. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  39765. +
  39766. + /* Allocate for the bulk-in endpoint. We assume that
  39767. + * the buffer will also work with the bulk-out (and
  39768. + * interrupt-in) endpoint. */
  39769. + bh->buf = kmalloc(mod_data.buflen, GFP_KERNEL);
  39770. + if (!bh->buf)
  39771. + goto out;
  39772. + bh->next = bh + 1;
  39773. + }
  39774. + fsg->buffhds[fsg_num_buffers - 1].next = &fsg->buffhds[0];
  39775. +
  39776. + /* This should reflect the actual gadget power source */
  39777. + usb_gadget_set_selfpowered(gadget);
  39778. +
  39779. + snprintf(fsg_string_manufacturer, sizeof fsg_string_manufacturer,
  39780. + "%s %s with %s",
  39781. + init_utsname()->sysname, init_utsname()->release,
  39782. + gadget->name);
  39783. +
  39784. + fsg->thread_task = kthread_create(fsg_main_thread, fsg,
  39785. + "file-storage-gadget");
  39786. + if (IS_ERR(fsg->thread_task)) {
  39787. + rc = PTR_ERR(fsg->thread_task);
  39788. + goto out;
  39789. + }
  39790. +
  39791. + INFO(fsg, DRIVER_DESC ", version: " DRIVER_VERSION "\n");
  39792. + INFO(fsg, "NOTE: This driver is deprecated. "
  39793. + "Consider using g_mass_storage instead.\n");
  39794. + INFO(fsg, "Number of LUNs=%d\n", fsg->nluns);
  39795. +
  39796. + pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
  39797. + for (i = 0; i < fsg->nluns; ++i) {
  39798. + curlun = &fsg->luns[i];
  39799. + if (fsg_lun_is_open(curlun)) {
  39800. + p = NULL;
  39801. + if (pathbuf) {
  39802. + p = d_path(&curlun->filp->f_path,
  39803. + pathbuf, PATH_MAX);
  39804. + if (IS_ERR(p))
  39805. + p = NULL;
  39806. + }
  39807. + LINFO(curlun, "ro=%d, nofua=%d, file: %s\n",
  39808. + curlun->ro, curlun->nofua, (p ? p : "(error)"));
  39809. + }
  39810. + }
  39811. + kfree(pathbuf);
  39812. +
  39813. + DBG(fsg, "transport=%s (x%02x)\n",
  39814. + mod_data.transport_name, mod_data.transport_type);
  39815. + DBG(fsg, "protocol=%s (x%02x)\n",
  39816. + mod_data.protocol_name, mod_data.protocol_type);
  39817. + DBG(fsg, "VendorID=x%04x, ProductID=x%04x, Release=x%04x\n",
  39818. + mod_data.vendor, mod_data.product, mod_data.release);
  39819. + DBG(fsg, "removable=%d, stall=%d, cdrom=%d, buflen=%u\n",
  39820. + mod_data.removable, mod_data.can_stall,
  39821. + mod_data.cdrom, mod_data.buflen);
  39822. + DBG(fsg, "I/O thread pid: %d\n", task_pid_nr(fsg->thread_task));
  39823. +
  39824. + set_bit(REGISTERED, &fsg->atomic_bitflags);
  39825. +
  39826. + /* Tell the thread to start working */
  39827. + wake_up_process(fsg->thread_task);
  39828. + return 0;
  39829. +
  39830. +autoconf_fail:
  39831. + ERROR(fsg, "unable to autoconfigure all endpoints\n");
  39832. + rc = -ENOTSUPP;
  39833. +
  39834. +out:
  39835. + fsg->state = FSG_STATE_TERMINATED; // The thread is dead
  39836. + fsg_unbind(gadget);
  39837. + complete(&fsg->thread_notifier);
  39838. + return rc;
  39839. +}
  39840. +
  39841. +
  39842. +/*-------------------------------------------------------------------------*/
  39843. +
  39844. +static void fsg_suspend(struct usb_gadget *gadget)
  39845. +{
  39846. + struct fsg_dev *fsg = get_gadget_data(gadget);
  39847. +
  39848. + DBG(fsg, "suspend\n");
  39849. + set_bit(SUSPENDED, &fsg->atomic_bitflags);
  39850. +}
  39851. +
  39852. +static void fsg_resume(struct usb_gadget *gadget)
  39853. +{
  39854. + struct fsg_dev *fsg = get_gadget_data(gadget);
  39855. +
  39856. + DBG(fsg, "resume\n");
  39857. + clear_bit(SUSPENDED, &fsg->atomic_bitflags);
  39858. +}
  39859. +
  39860. +
  39861. +/*-------------------------------------------------------------------------*/
  39862. +
  39863. +static struct usb_gadget_driver fsg_driver = {
  39864. + .max_speed = USB_SPEED_SUPER,
  39865. + .function = (char *) fsg_string_product,
  39866. + .unbind = fsg_unbind,
  39867. + .disconnect = fsg_disconnect,
  39868. + .setup = fsg_setup,
  39869. + .suspend = fsg_suspend,
  39870. + .resume = fsg_resume,
  39871. +
  39872. + .driver = {
  39873. + .name = DRIVER_NAME,
  39874. + .owner = THIS_MODULE,
  39875. + // .release = ...
  39876. + // .suspend = ...
  39877. + // .resume = ...
  39878. + },
  39879. +};
  39880. +
  39881. +
  39882. +static int __init fsg_alloc(void)
  39883. +{
  39884. + struct fsg_dev *fsg;
  39885. +
  39886. + fsg = kzalloc(sizeof *fsg +
  39887. + fsg_num_buffers * sizeof *(fsg->buffhds), GFP_KERNEL);
  39888. +
  39889. + if (!fsg)
  39890. + return -ENOMEM;
  39891. + spin_lock_init(&fsg->lock);
  39892. + init_rwsem(&fsg->filesem);
  39893. + kref_init(&fsg->ref);
  39894. + init_completion(&fsg->thread_notifier);
  39895. +
  39896. + the_fsg = fsg;
  39897. + return 0;
  39898. +}
  39899. +
  39900. +
  39901. +static int __init fsg_init(void)
  39902. +{
  39903. + int rc;
  39904. + struct fsg_dev *fsg;
  39905. +
  39906. + rc = fsg_num_buffers_validate();
  39907. + if (rc != 0)
  39908. + return rc;
  39909. +
  39910. + if ((rc = fsg_alloc()) != 0)
  39911. + return rc;
  39912. + fsg = the_fsg;
  39913. + if ((rc = usb_gadget_probe_driver(&fsg_driver, fsg_bind)) != 0)
  39914. + kref_put(&fsg->ref, fsg_release);
  39915. + return rc;
  39916. +}
  39917. +module_init(fsg_init);
  39918. +
  39919. +
  39920. +static void __exit fsg_cleanup(void)
  39921. +{
  39922. + struct fsg_dev *fsg = the_fsg;
  39923. +
  39924. + /* Unregister the driver iff the thread hasn't already done so */
  39925. + if (test_and_clear_bit(REGISTERED, &fsg->atomic_bitflags))
  39926. + usb_gadget_unregister_driver(&fsg_driver);
  39927. +
  39928. + /* Wait for the thread to finish up */
  39929. + wait_for_completion(&fsg->thread_notifier);
  39930. +
  39931. + kref_put(&fsg->ref, fsg_release);
  39932. +}
  39933. +module_exit(fsg_cleanup);
  39934. diff -Nur linux-3.15.4/drivers/usb/host/dwc_common_port/changes.txt linux-rpi/drivers/usb/host/dwc_common_port/changes.txt
  39935. --- linux-3.15.4/drivers/usb/host/dwc_common_port/changes.txt 1970-01-01 01:00:00.000000000 +0100
  39936. +++ linux-rpi/drivers/usb/host/dwc_common_port/changes.txt 2014-04-13 17:33:11.000000000 +0200
  39937. @@ -0,0 +1,174 @@
  39938. +
  39939. +dwc_read_reg32() and friends now take an additional parameter, a pointer to an
  39940. +IO context struct. The IO context struct should live in an os-dependent struct
  39941. +in your driver. As an example, the dwc_usb3 driver has an os-dependent struct
  39942. +named 'os_dep' embedded in the main device struct. So there these calls look
  39943. +like this:
  39944. +
  39945. + dwc_read_reg32(&usb3_dev->os_dep.ioctx, &pcd->dev_global_regs->dcfg);
  39946. +
  39947. + dwc_write_reg32(&usb3_dev->os_dep.ioctx,
  39948. + &pcd->dev_global_regs->dcfg, 0);
  39949. +
  39950. +Note that for the existing Linux driver ports, it is not necessary to actually
  39951. +define the 'ioctx' member in the os-dependent struct. Since Linux does not
  39952. +require an IO context, its macros for dwc_read_reg32() and friends do not
  39953. +use the context pointer, so it is optimized away by the compiler. But it is
  39954. +necessary to add the pointer parameter to all of the call sites, to be ready
  39955. +for any future ports (such as FreeBSD) which do require an IO context.
  39956. +
  39957. +
  39958. +Similarly, dwc_alloc(), dwc_alloc_atomic(), dwc_strdup(), and dwc_free() now
  39959. +take an additional parameter, a pointer to a memory context. Examples:
  39960. +
  39961. + addr = dwc_alloc(&usb3_dev->os_dep.memctx, size);
  39962. +
  39963. + dwc_free(&usb3_dev->os_dep.memctx, addr);
  39964. +
  39965. +Again, for the Linux ports, it is not necessary to actually define the memctx
  39966. +member, but it is necessary to add the pointer parameter to all of the call
  39967. +sites.
  39968. +
  39969. +
  39970. +Same for dwc_dma_alloc() and dwc_dma_free(). Examples:
  39971. +
  39972. + virt_addr = dwc_dma_alloc(&usb3_dev->os_dep.dmactx, size, &phys_addr);
  39973. +
  39974. + dwc_dma_free(&usb3_dev->os_dep.dmactx, size, virt_addr, phys_addr);
  39975. +
  39976. +
  39977. +Same for dwc_mutex_alloc() and dwc_mutex_free(). Examples:
  39978. +
  39979. + mutex = dwc_mutex_alloc(&usb3_dev->os_dep.mtxctx);
  39980. +
  39981. + dwc_mutex_free(&usb3_dev->os_dep.mtxctx, mutex);
  39982. +
  39983. +
  39984. +Same for dwc_spinlock_alloc() and dwc_spinlock_free(). Examples:
  39985. +
  39986. + lock = dwc_spinlock_alloc(&usb3_dev->osdep.splctx);
  39987. +
  39988. + dwc_spinlock_free(&usb3_dev->osdep.splctx, lock);
  39989. +
  39990. +
  39991. +Same for dwc_timer_alloc(). Example:
  39992. +
  39993. + timer = dwc_timer_alloc(&usb3_dev->os_dep.tmrctx, "dwc_usb3_tmr1",
  39994. + cb_func, cb_data);
  39995. +
  39996. +
  39997. +Same for dwc_waitq_alloc(). Example:
  39998. +
  39999. + waitq = dwc_waitq_alloc(&usb3_dev->os_dep.wtqctx);
  40000. +
  40001. +
  40002. +Same for dwc_thread_run(). Example:
  40003. +
  40004. + thread = dwc_thread_run(&usb3_dev->os_dep.thdctx, func,
  40005. + "dwc_usb3_thd1", data);
  40006. +
  40007. +
  40008. +Same for dwc_workq_alloc(). Example:
  40009. +
  40010. + workq = dwc_workq_alloc(&usb3_dev->osdep.wkqctx, "dwc_usb3_wkq1");
  40011. +
  40012. +
  40013. +Same for dwc_task_alloc(). Example:
  40014. +
  40015. + task = dwc_task_alloc(&usb3_dev->os_dep.tskctx, "dwc_usb3_tsk1",
  40016. + cb_func, cb_data);
  40017. +
  40018. +
  40019. +In addition to the context pointer additions, a few core functions have had
  40020. +other changes made to their parameters:
  40021. +
  40022. +The 'flags' parameter to dwc_spinlock_irqsave() and dwc_spinunlock_irqrestore()
  40023. +has been changed from a uint64_t to a dwc_irqflags_t.
  40024. +
  40025. +dwc_thread_should_stop() now takes a 'dwc_thread_t *' parameter, because the
  40026. +FreeBSD equivalent of that function requires it.
  40027. +
  40028. +And, in addition to the context pointer, dwc_task_alloc() also adds a
  40029. +'char *name' parameter, to be consistent with dwc_thread_run() and
  40030. +dwc_workq_alloc(), and because the FreeBSD equivalent of that function
  40031. +requires a unique name.
  40032. +
  40033. +
  40034. +Here is a complete list of the core functions that now take a pointer to a
  40035. +context as their first parameter:
  40036. +
  40037. + dwc_read_reg32
  40038. + dwc_read_reg64
  40039. + dwc_write_reg32
  40040. + dwc_write_reg64
  40041. + dwc_modify_reg32
  40042. + dwc_modify_reg64
  40043. + dwc_alloc
  40044. + dwc_alloc_atomic
  40045. + dwc_strdup
  40046. + dwc_free
  40047. + dwc_dma_alloc
  40048. + dwc_dma_free
  40049. + dwc_mutex_alloc
  40050. + dwc_mutex_free
  40051. + dwc_spinlock_alloc
  40052. + dwc_spinlock_free
  40053. + dwc_timer_alloc
  40054. + dwc_waitq_alloc
  40055. + dwc_thread_run
  40056. + dwc_workq_alloc
  40057. + dwc_task_alloc Also adds a 'char *name' as its 2nd parameter
  40058. +
  40059. +And here are the core functions that have other changes to their parameters:
  40060. +
  40061. + dwc_spinlock_irqsave 'flags' param is now a 'dwc_irqflags_t *'
  40062. + dwc_spinunlock_irqrestore 'flags' param is now a 'dwc_irqflags_t'
  40063. + dwc_thread_should_stop Adds a 'dwc_thread_t *' parameter
  40064. +
  40065. +
  40066. +
  40067. +The changes to the core functions also require some of the other library
  40068. +functions to change:
  40069. +
  40070. + dwc_cc_if_alloc() and dwc_cc_if_free() now take a 'void *memctx'
  40071. + (for memory allocation) as the 1st param and a 'void *mtxctx'
  40072. + (for mutex allocation) as the 2nd param.
  40073. +
  40074. + dwc_cc_clear(), dwc_cc_add(), dwc_cc_change(), dwc_cc_remove(),
  40075. + dwc_cc_data_for_save(), and dwc_cc_restore_from_data() now take a
  40076. + 'void *memctx' as the 1st param.
  40077. +
  40078. + dwc_dh_modpow(), dwc_dh_pk(), and dwc_dh_derive_keys() now take a
  40079. + 'void *memctx' as the 1st param.
  40080. +
  40081. + dwc_modpow() now takes a 'void *memctx' as the 1st param.
  40082. +
  40083. + dwc_alloc_notification_manager() now takes a 'void *memctx' as the
  40084. + 1st param and a 'void *wkqctx' (for work queue allocation) as the 2nd
  40085. + param, and also now returns an integer value that is non-zero if
  40086. + allocation of its data structures or work queue fails.
  40087. +
  40088. + dwc_register_notifier() now takes a 'void *memctx' as the 1st param.
  40089. +
  40090. + dwc_memory_debug_start() now takes a 'void *mem_ctx' as the first
  40091. + param, and also now returns an integer value that is non-zero if
  40092. + allocation of its data structures fails.
  40093. +
  40094. +
  40095. +
  40096. +Other miscellaneous changes:
  40097. +
  40098. +The DEBUG_MEMORY and DEBUG_REGS #define's have been renamed to
  40099. +DWC_DEBUG_MEMORY and DWC_DEBUG_REGS.
  40100. +
  40101. +The following #define's have been added to allow selectively compiling library
  40102. +features:
  40103. +
  40104. + DWC_CCLIB
  40105. + DWC_CRYPTOLIB
  40106. + DWC_NOTIFYLIB
  40107. + DWC_UTFLIB
  40108. +
  40109. +A DWC_LIBMODULE #define has also been added. If this is not defined, then the
  40110. +module code in dwc_common_linux.c is not compiled in. This allows linking the
  40111. +library code directly into a driver module, instead of as a standalone module.
  40112. diff -Nur linux-3.15.4/drivers/usb/host/dwc_common_port/doc/doxygen.cfg linux-rpi/drivers/usb/host/dwc_common_port/doc/doxygen.cfg
  40113. --- linux-3.15.4/drivers/usb/host/dwc_common_port/doc/doxygen.cfg 1970-01-01 01:00:00.000000000 +0100
  40114. +++ linux-rpi/drivers/usb/host/dwc_common_port/doc/doxygen.cfg 2014-07-07 10:45:43.000000000 +0200
  40115. @@ -0,0 +1,270 @@
  40116. +# Doxyfile 1.4.5
  40117. +
  40118. +#---------------------------------------------------------------------------
  40119. +# Project related configuration options
  40120. +#---------------------------------------------------------------------------
  40121. +PROJECT_NAME = "Synopsys DWC Portability and Common Library for UWB"
  40122. +PROJECT_NUMBER =
  40123. +OUTPUT_DIRECTORY = doc
  40124. +CREATE_SUBDIRS = NO
  40125. +OUTPUT_LANGUAGE = English
  40126. +BRIEF_MEMBER_DESC = YES
  40127. +REPEAT_BRIEF = YES
  40128. +ABBREVIATE_BRIEF = "The $name class" \
  40129. + "The $name widget" \
  40130. + "The $name file" \
  40131. + is \
  40132. + provides \
  40133. + specifies \
  40134. + contains \
  40135. + represents \
  40136. + a \
  40137. + an \
  40138. + the
  40139. +ALWAYS_DETAILED_SEC = YES
  40140. +INLINE_INHERITED_MEMB = NO
  40141. +FULL_PATH_NAMES = NO
  40142. +STRIP_FROM_PATH = ..
  40143. +STRIP_FROM_INC_PATH =
  40144. +SHORT_NAMES = NO
  40145. +JAVADOC_AUTOBRIEF = YES
  40146. +MULTILINE_CPP_IS_BRIEF = NO
  40147. +DETAILS_AT_TOP = YES
  40148. +INHERIT_DOCS = YES
  40149. +SEPARATE_MEMBER_PAGES = NO
  40150. +TAB_SIZE = 8
  40151. +ALIASES =
  40152. +OPTIMIZE_OUTPUT_FOR_C = YES
  40153. +OPTIMIZE_OUTPUT_JAVA = NO
  40154. +BUILTIN_STL_SUPPORT = NO
  40155. +DISTRIBUTE_GROUP_DOC = NO
  40156. +SUBGROUPING = NO
  40157. +#---------------------------------------------------------------------------
  40158. +# Build related configuration options
  40159. +#---------------------------------------------------------------------------
  40160. +EXTRACT_ALL = NO
  40161. +EXTRACT_PRIVATE = NO
  40162. +EXTRACT_STATIC = YES
  40163. +EXTRACT_LOCAL_CLASSES = NO
  40164. +EXTRACT_LOCAL_METHODS = NO
  40165. +HIDE_UNDOC_MEMBERS = NO
  40166. +HIDE_UNDOC_CLASSES = NO
  40167. +HIDE_FRIEND_COMPOUNDS = NO
  40168. +HIDE_IN_BODY_DOCS = NO
  40169. +INTERNAL_DOCS = NO
  40170. +CASE_SENSE_NAMES = YES
  40171. +HIDE_SCOPE_NAMES = NO
  40172. +SHOW_INCLUDE_FILES = NO
  40173. +INLINE_INFO = YES
  40174. +SORT_MEMBER_DOCS = NO
  40175. +SORT_BRIEF_DOCS = NO
  40176. +SORT_BY_SCOPE_NAME = NO
  40177. +GENERATE_TODOLIST = YES
  40178. +GENERATE_TESTLIST = YES
  40179. +GENERATE_BUGLIST = YES
  40180. +GENERATE_DEPRECATEDLIST= YES
  40181. +ENABLED_SECTIONS =
  40182. +MAX_INITIALIZER_LINES = 30
  40183. +SHOW_USED_FILES = YES
  40184. +SHOW_DIRECTORIES = YES
  40185. +FILE_VERSION_FILTER =
  40186. +#---------------------------------------------------------------------------
  40187. +# configuration options related to warning and progress messages
  40188. +#---------------------------------------------------------------------------
  40189. +QUIET = YES
  40190. +WARNINGS = YES
  40191. +WARN_IF_UNDOCUMENTED = NO
  40192. +WARN_IF_DOC_ERROR = YES
  40193. +WARN_NO_PARAMDOC = YES
  40194. +WARN_FORMAT = "$file:$line: $text"
  40195. +WARN_LOGFILE =
  40196. +#---------------------------------------------------------------------------
  40197. +# configuration options related to the input files
  40198. +#---------------------------------------------------------------------------
  40199. +INPUT = .
  40200. +FILE_PATTERNS = *.c \
  40201. + *.cc \
  40202. + *.cxx \
  40203. + *.cpp \
  40204. + *.c++ \
  40205. + *.d \
  40206. + *.java \
  40207. + *.ii \
  40208. + *.ixx \
  40209. + *.ipp \
  40210. + *.i++ \
  40211. + *.inl \
  40212. + *.h \
  40213. + *.hh \
  40214. + *.hxx \
  40215. + *.hpp \
  40216. + *.h++ \
  40217. + *.idl \
  40218. + *.odl \
  40219. + *.cs \
  40220. + *.php \
  40221. + *.php3 \
  40222. + *.inc \
  40223. + *.m \
  40224. + *.mm \
  40225. + *.dox \
  40226. + *.py \
  40227. + *.C \
  40228. + *.CC \
  40229. + *.C++ \
  40230. + *.II \
  40231. + *.I++ \
  40232. + *.H \
  40233. + *.HH \
  40234. + *.H++ \
  40235. + *.CS \
  40236. + *.PHP \
  40237. + *.PHP3 \
  40238. + *.M \
  40239. + *.MM \
  40240. + *.PY
  40241. +RECURSIVE = NO
  40242. +EXCLUDE =
  40243. +EXCLUDE_SYMLINKS = NO
  40244. +EXCLUDE_PATTERNS =
  40245. +EXAMPLE_PATH =
  40246. +EXAMPLE_PATTERNS = *
  40247. +EXAMPLE_RECURSIVE = NO
  40248. +IMAGE_PATH =
  40249. +INPUT_FILTER =
  40250. +FILTER_PATTERNS =
  40251. +FILTER_SOURCE_FILES = NO
  40252. +#---------------------------------------------------------------------------
  40253. +# configuration options related to source browsing
  40254. +#---------------------------------------------------------------------------
  40255. +SOURCE_BROWSER = NO
  40256. +INLINE_SOURCES = NO
  40257. +STRIP_CODE_COMMENTS = YES
  40258. +REFERENCED_BY_RELATION = YES
  40259. +REFERENCES_RELATION = YES
  40260. +USE_HTAGS = NO
  40261. +VERBATIM_HEADERS = NO
  40262. +#---------------------------------------------------------------------------
  40263. +# configuration options related to the alphabetical class index
  40264. +#---------------------------------------------------------------------------
  40265. +ALPHABETICAL_INDEX = NO
  40266. +COLS_IN_ALPHA_INDEX = 5
  40267. +IGNORE_PREFIX =
  40268. +#---------------------------------------------------------------------------
  40269. +# configuration options related to the HTML output
  40270. +#---------------------------------------------------------------------------
  40271. +GENERATE_HTML = YES
  40272. +HTML_OUTPUT = html
  40273. +HTML_FILE_EXTENSION = .html
  40274. +HTML_HEADER =
  40275. +HTML_FOOTER =
  40276. +HTML_STYLESHEET =
  40277. +HTML_ALIGN_MEMBERS = YES
  40278. +GENERATE_HTMLHELP = NO
  40279. +CHM_FILE =
  40280. +HHC_LOCATION =
  40281. +GENERATE_CHI = NO
  40282. +BINARY_TOC = NO
  40283. +TOC_EXPAND = NO
  40284. +DISABLE_INDEX = NO
  40285. +ENUM_VALUES_PER_LINE = 4
  40286. +GENERATE_TREEVIEW = YES
  40287. +TREEVIEW_WIDTH = 250
  40288. +#---------------------------------------------------------------------------
  40289. +# configuration options related to the LaTeX output
  40290. +#---------------------------------------------------------------------------
  40291. +GENERATE_LATEX = NO
  40292. +LATEX_OUTPUT = latex
  40293. +LATEX_CMD_NAME = latex
  40294. +MAKEINDEX_CMD_NAME = makeindex
  40295. +COMPACT_LATEX = NO
  40296. +PAPER_TYPE = a4wide
  40297. +EXTRA_PACKAGES =
  40298. +LATEX_HEADER =
  40299. +PDF_HYPERLINKS = NO
  40300. +USE_PDFLATEX = NO
  40301. +LATEX_BATCHMODE = NO
  40302. +LATEX_HIDE_INDICES = NO
  40303. +#---------------------------------------------------------------------------
  40304. +# configuration options related to the RTF output
  40305. +#---------------------------------------------------------------------------
  40306. +GENERATE_RTF = NO
  40307. +RTF_OUTPUT = rtf
  40308. +COMPACT_RTF = NO
  40309. +RTF_HYPERLINKS = NO
  40310. +RTF_STYLESHEET_FILE =
  40311. +RTF_EXTENSIONS_FILE =
  40312. +#---------------------------------------------------------------------------
  40313. +# configuration options related to the man page output
  40314. +#---------------------------------------------------------------------------
  40315. +GENERATE_MAN = NO
  40316. +MAN_OUTPUT = man
  40317. +MAN_EXTENSION = .3
  40318. +MAN_LINKS = NO
  40319. +#---------------------------------------------------------------------------
  40320. +# configuration options related to the XML output
  40321. +#---------------------------------------------------------------------------
  40322. +GENERATE_XML = NO
  40323. +XML_OUTPUT = xml
  40324. +XML_SCHEMA =
  40325. +XML_DTD =
  40326. +XML_PROGRAMLISTING = YES
  40327. +#---------------------------------------------------------------------------
  40328. +# configuration options for the AutoGen Definitions output
  40329. +#---------------------------------------------------------------------------
  40330. +GENERATE_AUTOGEN_DEF = NO
  40331. +#---------------------------------------------------------------------------
  40332. +# configuration options related to the Perl module output
  40333. +#---------------------------------------------------------------------------
  40334. +GENERATE_PERLMOD = NO
  40335. +PERLMOD_LATEX = NO
  40336. +PERLMOD_PRETTY = YES
  40337. +PERLMOD_MAKEVAR_PREFIX =
  40338. +#---------------------------------------------------------------------------
  40339. +# Configuration options related to the preprocessor
  40340. +#---------------------------------------------------------------------------
  40341. +ENABLE_PREPROCESSING = YES
  40342. +MACRO_EXPANSION = NO
  40343. +EXPAND_ONLY_PREDEF = NO
  40344. +SEARCH_INCLUDES = YES
  40345. +INCLUDE_PATH =
  40346. +INCLUDE_FILE_PATTERNS =
  40347. +PREDEFINED = DEBUG DEBUG_MEMORY
  40348. +EXPAND_AS_DEFINED =
  40349. +SKIP_FUNCTION_MACROS = YES
  40350. +#---------------------------------------------------------------------------
  40351. +# Configuration::additions related to external references
  40352. +#---------------------------------------------------------------------------
  40353. +TAGFILES =
  40354. +GENERATE_TAGFILE =
  40355. +ALLEXTERNALS = NO
  40356. +EXTERNAL_GROUPS = YES
  40357. +PERL_PATH = /usr/bin/perl
  40358. +#---------------------------------------------------------------------------
  40359. +# Configuration options related to the dot tool
  40360. +#---------------------------------------------------------------------------
  40361. +CLASS_DIAGRAMS = YES
  40362. +HIDE_UNDOC_RELATIONS = YES
  40363. +HAVE_DOT = NO
  40364. +CLASS_GRAPH = YES
  40365. +COLLABORATION_GRAPH = YES
  40366. +GROUP_GRAPHS = YES
  40367. +UML_LOOK = NO
  40368. +TEMPLATE_RELATIONS = NO
  40369. +INCLUDE_GRAPH = NO
  40370. +INCLUDED_BY_GRAPH = YES
  40371. +CALL_GRAPH = NO
  40372. +GRAPHICAL_HIERARCHY = YES
  40373. +DIRECTORY_GRAPH = YES
  40374. +DOT_IMAGE_FORMAT = png
  40375. +DOT_PATH =
  40376. +DOTFILE_DIRS =
  40377. +MAX_DOT_GRAPH_DEPTH = 1000
  40378. +DOT_TRANSPARENT = NO
  40379. +DOT_MULTI_TARGETS = NO
  40380. +GENERATE_LEGEND = YES
  40381. +DOT_CLEANUP = YES
  40382. +#---------------------------------------------------------------------------
  40383. +# Configuration::additions related to the search engine
  40384. +#---------------------------------------------------------------------------
  40385. +SEARCHENGINE = NO
  40386. diff -Nur linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_cc.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_cc.c
  40387. --- linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_cc.c 1970-01-01 01:00:00.000000000 +0100
  40388. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_cc.c 2014-07-07 10:45:43.000000000 +0200
  40389. @@ -0,0 +1,532 @@
  40390. +/* =========================================================================
  40391. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_cc.c $
  40392. + * $Revision: #4 $
  40393. + * $Date: 2010/11/04 $
  40394. + * $Change: 1621692 $
  40395. + *
  40396. + * Synopsys Portability Library Software and documentation
  40397. + * (hereinafter, "Software") is an Unsupported proprietary work of
  40398. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  40399. + * between Synopsys and you.
  40400. + *
  40401. + * The Software IS NOT an item of Licensed Software or Licensed Product
  40402. + * under any End User Software License Agreement or Agreement for
  40403. + * Licensed Product with Synopsys or any supplement thereto. You are
  40404. + * permitted to use and redistribute this Software in source and binary
  40405. + * forms, with or without modification, provided that redistributions
  40406. + * of source code must retain this notice. You may not view, use,
  40407. + * disclose, copy or distribute this file or any information contained
  40408. + * herein except pursuant to this license grant from Synopsys. If you
  40409. + * do not agree with this notice, including the disclaimer below, then
  40410. + * you are not authorized to use the Software.
  40411. + *
  40412. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  40413. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  40414. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  40415. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  40416. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  40417. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  40418. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  40419. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  40420. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  40421. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  40422. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  40423. + * DAMAGE.
  40424. + * ========================================================================= */
  40425. +#ifdef DWC_CCLIB
  40426. +
  40427. +#include "dwc_cc.h"
  40428. +
  40429. +typedef struct dwc_cc
  40430. +{
  40431. + uint32_t uid;
  40432. + uint8_t chid[16];
  40433. + uint8_t cdid[16];
  40434. + uint8_t ck[16];
  40435. + uint8_t *name;
  40436. + uint8_t length;
  40437. + DWC_CIRCLEQ_ENTRY(dwc_cc) list_entry;
  40438. +} dwc_cc_t;
  40439. +
  40440. +DWC_CIRCLEQ_HEAD(context_list, dwc_cc);
  40441. +
  40442. +/** The main structure for CC management. */
  40443. +struct dwc_cc_if
  40444. +{
  40445. + dwc_mutex_t *mutex;
  40446. + char *filename;
  40447. +
  40448. + unsigned is_host:1;
  40449. +
  40450. + dwc_notifier_t *notifier;
  40451. +
  40452. + struct context_list list;
  40453. +};
  40454. +
  40455. +#ifdef DEBUG
  40456. +static inline void dump_bytes(char *name, uint8_t *bytes, int len)
  40457. +{
  40458. + int i;
  40459. + DWC_PRINTF("%s: ", name);
  40460. + for (i=0; i<len; i++) {
  40461. + DWC_PRINTF("%02x ", bytes[i]);
  40462. + }
  40463. + DWC_PRINTF("\n");
  40464. +}
  40465. +#else
  40466. +#define dump_bytes(x...)
  40467. +#endif
  40468. +
  40469. +static dwc_cc_t *alloc_cc(void *mem_ctx, uint8_t *name, uint32_t length)
  40470. +{
  40471. + dwc_cc_t *cc = dwc_alloc(mem_ctx, sizeof(dwc_cc_t));
  40472. + if (!cc) {
  40473. + return NULL;
  40474. + }
  40475. + DWC_MEMSET(cc, 0, sizeof(dwc_cc_t));
  40476. +
  40477. + if (name) {
  40478. + cc->length = length;
  40479. + cc->name = dwc_alloc(mem_ctx, length);
  40480. + if (!cc->name) {
  40481. + dwc_free(mem_ctx, cc);
  40482. + return NULL;
  40483. + }
  40484. +
  40485. + DWC_MEMCPY(cc->name, name, length);
  40486. + }
  40487. +
  40488. + return cc;
  40489. +}
  40490. +
  40491. +static void free_cc(void *mem_ctx, dwc_cc_t *cc)
  40492. +{
  40493. + if (cc->name) {
  40494. + dwc_free(mem_ctx, cc->name);
  40495. + }
  40496. + dwc_free(mem_ctx, cc);
  40497. +}
  40498. +
  40499. +static uint32_t next_uid(dwc_cc_if_t *cc_if)
  40500. +{
  40501. + uint32_t uid = 0;
  40502. + dwc_cc_t *cc;
  40503. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  40504. + if (cc->uid > uid) {
  40505. + uid = cc->uid;
  40506. + }
  40507. + }
  40508. +
  40509. + if (uid == 0) {
  40510. + uid = 255;
  40511. + }
  40512. +
  40513. + return uid + 1;
  40514. +}
  40515. +
  40516. +static dwc_cc_t *cc_find(dwc_cc_if_t *cc_if, uint32_t uid)
  40517. +{
  40518. + dwc_cc_t *cc;
  40519. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  40520. + if (cc->uid == uid) {
  40521. + return cc;
  40522. + }
  40523. + }
  40524. + return NULL;
  40525. +}
  40526. +
  40527. +static unsigned int cc_data_size(dwc_cc_if_t *cc_if)
  40528. +{
  40529. + unsigned int size = 0;
  40530. + dwc_cc_t *cc;
  40531. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  40532. + size += (48 + 1);
  40533. + if (cc->name) {
  40534. + size += cc->length;
  40535. + }
  40536. + }
  40537. + return size;
  40538. +}
  40539. +
  40540. +static uint32_t cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid)
  40541. +{
  40542. + uint32_t uid = 0;
  40543. + dwc_cc_t *cc;
  40544. +
  40545. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  40546. + if (DWC_MEMCMP(cc->chid, chid, 16) == 0) {
  40547. + uid = cc->uid;
  40548. + break;
  40549. + }
  40550. + }
  40551. + return uid;
  40552. +}
  40553. +static uint32_t cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid)
  40554. +{
  40555. + uint32_t uid = 0;
  40556. + dwc_cc_t *cc;
  40557. +
  40558. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  40559. + if (DWC_MEMCMP(cc->cdid, cdid, 16) == 0) {
  40560. + uid = cc->uid;
  40561. + break;
  40562. + }
  40563. + }
  40564. + return uid;
  40565. +}
  40566. +
  40567. +/* Internal cc_add */
  40568. +static int32_t cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  40569. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  40570. +{
  40571. + dwc_cc_t *cc;
  40572. + uint32_t uid;
  40573. +
  40574. + if (cc_if->is_host) {
  40575. + uid = cc_match_cdid(cc_if, cdid);
  40576. + }
  40577. + else {
  40578. + uid = cc_match_chid(cc_if, chid);
  40579. + }
  40580. +
  40581. + if (uid) {
  40582. + DWC_DEBUGC("Replacing previous connection context id=%d name=%p name_len=%d", uid, name, length);
  40583. + cc = cc_find(cc_if, uid);
  40584. + }
  40585. + else {
  40586. + cc = alloc_cc(mem_ctx, name, length);
  40587. + cc->uid = next_uid(cc_if);
  40588. + DWC_CIRCLEQ_INSERT_TAIL(&cc_if->list, cc, list_entry);
  40589. + }
  40590. +
  40591. + DWC_MEMCPY(&(cc->chid[0]), chid, 16);
  40592. + DWC_MEMCPY(&(cc->cdid[0]), cdid, 16);
  40593. + DWC_MEMCPY(&(cc->ck[0]), ck, 16);
  40594. +
  40595. + DWC_DEBUGC("Added connection context id=%d name=%p name_len=%d", cc->uid, name, length);
  40596. + dump_bytes("CHID", cc->chid, 16);
  40597. + dump_bytes("CDID", cc->cdid, 16);
  40598. + dump_bytes("CK", cc->ck, 16);
  40599. + return cc->uid;
  40600. +}
  40601. +
  40602. +/* Internal cc_clear */
  40603. +static void cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if)
  40604. +{
  40605. + while (!DWC_CIRCLEQ_EMPTY(&cc_if->list)) {
  40606. + dwc_cc_t *cc = DWC_CIRCLEQ_FIRST(&cc_if->list);
  40607. + DWC_CIRCLEQ_REMOVE_INIT(&cc_if->list, cc, list_entry);
  40608. + free_cc(mem_ctx, cc);
  40609. + }
  40610. +}
  40611. +
  40612. +dwc_cc_if_t *dwc_cc_if_alloc(void *mem_ctx, void *mtx_ctx,
  40613. + dwc_notifier_t *notifier, unsigned is_host)
  40614. +{
  40615. + dwc_cc_if_t *cc_if = NULL;
  40616. +
  40617. + /* Allocate a common_cc_if structure */
  40618. + cc_if = dwc_alloc(mem_ctx, sizeof(dwc_cc_if_t));
  40619. +
  40620. + if (!cc_if)
  40621. + return NULL;
  40622. +
  40623. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  40624. + DWC_MUTEX_ALLOC_LINUX_DEBUG(cc_if->mutex);
  40625. +#else
  40626. + cc_if->mutex = dwc_mutex_alloc(mtx_ctx);
  40627. +#endif
  40628. + if (!cc_if->mutex) {
  40629. + dwc_free(mem_ctx, cc_if);
  40630. + return NULL;
  40631. + }
  40632. +
  40633. + DWC_CIRCLEQ_INIT(&cc_if->list);
  40634. + cc_if->is_host = is_host;
  40635. + cc_if->notifier = notifier;
  40636. + return cc_if;
  40637. +}
  40638. +
  40639. +void dwc_cc_if_free(void *mem_ctx, void *mtx_ctx, dwc_cc_if_t *cc_if)
  40640. +{
  40641. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  40642. + DWC_MUTEX_FREE(cc_if->mutex);
  40643. +#else
  40644. + dwc_mutex_free(mtx_ctx, cc_if->mutex);
  40645. +#endif
  40646. + cc_clear(mem_ctx, cc_if);
  40647. + dwc_free(mem_ctx, cc_if);
  40648. +}
  40649. +
  40650. +static void cc_changed(dwc_cc_if_t *cc_if)
  40651. +{
  40652. + if (cc_if->notifier) {
  40653. + dwc_notify(cc_if->notifier, DWC_CC_LIST_CHANGED_NOTIFICATION, cc_if);
  40654. + }
  40655. +}
  40656. +
  40657. +void dwc_cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if)
  40658. +{
  40659. + DWC_MUTEX_LOCK(cc_if->mutex);
  40660. + cc_clear(mem_ctx, cc_if);
  40661. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40662. + cc_changed(cc_if);
  40663. +}
  40664. +
  40665. +int32_t dwc_cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  40666. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  40667. +{
  40668. + uint32_t uid;
  40669. +
  40670. + DWC_MUTEX_LOCK(cc_if->mutex);
  40671. + uid = cc_add(mem_ctx, cc_if, chid, cdid, ck, name, length);
  40672. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40673. + cc_changed(cc_if);
  40674. +
  40675. + return uid;
  40676. +}
  40677. +
  40678. +void dwc_cc_change(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id, uint8_t *chid,
  40679. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  40680. +{
  40681. + dwc_cc_t* cc;
  40682. +
  40683. + DWC_DEBUGC("Change connection context %d", id);
  40684. +
  40685. + DWC_MUTEX_LOCK(cc_if->mutex);
  40686. + cc = cc_find(cc_if, id);
  40687. + if (!cc) {
  40688. + DWC_ERROR("Uid %d not found in cc list\n", id);
  40689. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40690. + return;
  40691. + }
  40692. +
  40693. + if (chid) {
  40694. + DWC_MEMCPY(&(cc->chid[0]), chid, 16);
  40695. + }
  40696. + if (cdid) {
  40697. + DWC_MEMCPY(&(cc->cdid[0]), cdid, 16);
  40698. + }
  40699. + if (ck) {
  40700. + DWC_MEMCPY(&(cc->ck[0]), ck, 16);
  40701. + }
  40702. +
  40703. + if (name) {
  40704. + if (cc->name) {
  40705. + dwc_free(mem_ctx, cc->name);
  40706. + }
  40707. + cc->name = dwc_alloc(mem_ctx, length);
  40708. + if (!cc->name) {
  40709. + DWC_ERROR("Out of memory in dwc_cc_change()\n");
  40710. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40711. + return;
  40712. + }
  40713. + cc->length = length;
  40714. + DWC_MEMCPY(cc->name, name, length);
  40715. + }
  40716. +
  40717. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40718. +
  40719. + cc_changed(cc_if);
  40720. +
  40721. + DWC_DEBUGC("Changed connection context id=%d\n", id);
  40722. + dump_bytes("New CHID", cc->chid, 16);
  40723. + dump_bytes("New CDID", cc->cdid, 16);
  40724. + dump_bytes("New CK", cc->ck, 16);
  40725. +}
  40726. +
  40727. +void dwc_cc_remove(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id)
  40728. +{
  40729. + dwc_cc_t *cc;
  40730. +
  40731. + DWC_DEBUGC("Removing connection context %d", id);
  40732. +
  40733. + DWC_MUTEX_LOCK(cc_if->mutex);
  40734. + cc = cc_find(cc_if, id);
  40735. + if (!cc) {
  40736. + DWC_ERROR("Uid %d not found in cc list\n", id);
  40737. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40738. + return;
  40739. + }
  40740. +
  40741. + DWC_CIRCLEQ_REMOVE_INIT(&cc_if->list, cc, list_entry);
  40742. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40743. + free_cc(mem_ctx, cc);
  40744. +
  40745. + cc_changed(cc_if);
  40746. +}
  40747. +
  40748. +uint8_t *dwc_cc_data_for_save(void *mem_ctx, dwc_cc_if_t *cc_if, unsigned int *length)
  40749. +{
  40750. + uint8_t *buf, *x;
  40751. + uint8_t zero = 0;
  40752. + dwc_cc_t *cc;
  40753. +
  40754. + DWC_MUTEX_LOCK(cc_if->mutex);
  40755. + *length = cc_data_size(cc_if);
  40756. + if (!(*length)) {
  40757. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40758. + return NULL;
  40759. + }
  40760. +
  40761. + DWC_DEBUGC("Creating data for saving (length=%d)", *length);
  40762. +
  40763. + buf = dwc_alloc(mem_ctx, *length);
  40764. + if (!buf) {
  40765. + *length = 0;
  40766. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40767. + return NULL;
  40768. + }
  40769. +
  40770. + x = buf;
  40771. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  40772. + DWC_MEMCPY(x, cc->chid, 16);
  40773. + x += 16;
  40774. + DWC_MEMCPY(x, cc->cdid, 16);
  40775. + x += 16;
  40776. + DWC_MEMCPY(x, cc->ck, 16);
  40777. + x += 16;
  40778. + if (cc->name) {
  40779. + DWC_MEMCPY(x, &cc->length, 1);
  40780. + x += 1;
  40781. + DWC_MEMCPY(x, cc->name, cc->length);
  40782. + x += cc->length;
  40783. + }
  40784. + else {
  40785. + DWC_MEMCPY(x, &zero, 1);
  40786. + x += 1;
  40787. + }
  40788. + }
  40789. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40790. +
  40791. + return buf;
  40792. +}
  40793. +
  40794. +void dwc_cc_restore_from_data(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *data, uint32_t length)
  40795. +{
  40796. + uint8_t name_length;
  40797. + uint8_t *name;
  40798. + uint8_t *chid;
  40799. + uint8_t *cdid;
  40800. + uint8_t *ck;
  40801. + uint32_t i = 0;
  40802. +
  40803. + DWC_MUTEX_LOCK(cc_if->mutex);
  40804. + cc_clear(mem_ctx, cc_if);
  40805. +
  40806. + while (i < length) {
  40807. + chid = &data[i];
  40808. + i += 16;
  40809. + cdid = &data[i];
  40810. + i += 16;
  40811. + ck = &data[i];
  40812. + i += 16;
  40813. +
  40814. + name_length = data[i];
  40815. + i ++;
  40816. +
  40817. + if (name_length) {
  40818. + name = &data[i];
  40819. + i += name_length;
  40820. + }
  40821. + else {
  40822. + name = NULL;
  40823. + }
  40824. +
  40825. + /* check to see if we haven't overflown the buffer */
  40826. + if (i > length) {
  40827. + DWC_ERROR("Data format error while attempting to load CCs "
  40828. + "(nlen=%d, iter=%d, buflen=%d).\n", name_length, i, length);
  40829. + break;
  40830. + }
  40831. +
  40832. + cc_add(mem_ctx, cc_if, chid, cdid, ck, name, name_length);
  40833. + }
  40834. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40835. +
  40836. + cc_changed(cc_if);
  40837. +}
  40838. +
  40839. +uint32_t dwc_cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid)
  40840. +{
  40841. + uint32_t uid = 0;
  40842. +
  40843. + DWC_MUTEX_LOCK(cc_if->mutex);
  40844. + uid = cc_match_chid(cc_if, chid);
  40845. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40846. + return uid;
  40847. +}
  40848. +uint32_t dwc_cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid)
  40849. +{
  40850. + uint32_t uid = 0;
  40851. +
  40852. + DWC_MUTEX_LOCK(cc_if->mutex);
  40853. + uid = cc_match_cdid(cc_if, cdid);
  40854. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40855. + return uid;
  40856. +}
  40857. +
  40858. +uint8_t *dwc_cc_ck(dwc_cc_if_t *cc_if, int32_t id)
  40859. +{
  40860. + uint8_t *ck = NULL;
  40861. + dwc_cc_t *cc;
  40862. +
  40863. + DWC_MUTEX_LOCK(cc_if->mutex);
  40864. + cc = cc_find(cc_if, id);
  40865. + if (cc) {
  40866. + ck = cc->ck;
  40867. + }
  40868. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40869. +
  40870. + return ck;
  40871. +
  40872. +}
  40873. +
  40874. +uint8_t *dwc_cc_chid(dwc_cc_if_t *cc_if, int32_t id)
  40875. +{
  40876. + uint8_t *retval = NULL;
  40877. + dwc_cc_t *cc;
  40878. +
  40879. + DWC_MUTEX_LOCK(cc_if->mutex);
  40880. + cc = cc_find(cc_if, id);
  40881. + if (cc) {
  40882. + retval = cc->chid;
  40883. + }
  40884. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40885. +
  40886. + return retval;
  40887. +}
  40888. +
  40889. +uint8_t *dwc_cc_cdid(dwc_cc_if_t *cc_if, int32_t id)
  40890. +{
  40891. + uint8_t *retval = NULL;
  40892. + dwc_cc_t *cc;
  40893. +
  40894. + DWC_MUTEX_LOCK(cc_if->mutex);
  40895. + cc = cc_find(cc_if, id);
  40896. + if (cc) {
  40897. + retval = cc->cdid;
  40898. + }
  40899. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40900. +
  40901. + return retval;
  40902. +}
  40903. +
  40904. +uint8_t *dwc_cc_name(dwc_cc_if_t *cc_if, int32_t id, uint8_t *length)
  40905. +{
  40906. + uint8_t *retval = NULL;
  40907. + dwc_cc_t *cc;
  40908. +
  40909. + DWC_MUTEX_LOCK(cc_if->mutex);
  40910. + *length = 0;
  40911. + cc = cc_find(cc_if, id);
  40912. + if (cc) {
  40913. + *length = cc->length;
  40914. + retval = cc->name;
  40915. + }
  40916. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40917. +
  40918. + return retval;
  40919. +}
  40920. +
  40921. +#endif /* DWC_CCLIB */
  40922. diff -Nur linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_cc.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_cc.h
  40923. --- linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_cc.h 1970-01-01 01:00:00.000000000 +0100
  40924. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_cc.h 2014-07-07 10:45:43.000000000 +0200
  40925. @@ -0,0 +1,224 @@
  40926. +/* =========================================================================
  40927. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_cc.h $
  40928. + * $Revision: #4 $
  40929. + * $Date: 2010/09/28 $
  40930. + * $Change: 1596182 $
  40931. + *
  40932. + * Synopsys Portability Library Software and documentation
  40933. + * (hereinafter, "Software") is an Unsupported proprietary work of
  40934. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  40935. + * between Synopsys and you.
  40936. + *
  40937. + * The Software IS NOT an item of Licensed Software or Licensed Product
  40938. + * under any End User Software License Agreement or Agreement for
  40939. + * Licensed Product with Synopsys or any supplement thereto. You are
  40940. + * permitted to use and redistribute this Software in source and binary
  40941. + * forms, with or without modification, provided that redistributions
  40942. + * of source code must retain this notice. You may not view, use,
  40943. + * disclose, copy or distribute this file or any information contained
  40944. + * herein except pursuant to this license grant from Synopsys. If you
  40945. + * do not agree with this notice, including the disclaimer below, then
  40946. + * you are not authorized to use the Software.
  40947. + *
  40948. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  40949. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  40950. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  40951. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  40952. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  40953. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  40954. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  40955. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  40956. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  40957. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  40958. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  40959. + * DAMAGE.
  40960. + * ========================================================================= */
  40961. +#ifndef _DWC_CC_H_
  40962. +#define _DWC_CC_H_
  40963. +
  40964. +#ifdef __cplusplus
  40965. +extern "C" {
  40966. +#endif
  40967. +
  40968. +/** @file
  40969. + *
  40970. + * This file defines the Context Context library.
  40971. + *
  40972. + * The main data structure is dwc_cc_if_t which is returned by either the
  40973. + * dwc_cc_if_alloc function or returned by the module to the user via a provided
  40974. + * function. The data structure is opaque and should only be manipulated via the
  40975. + * functions provied in this API.
  40976. + *
  40977. + * It manages a list of connection contexts and operations can be performed to
  40978. + * add, remove, query, search, and change, those contexts. Additionally,
  40979. + * a dwc_notifier_t object can be requested from the manager so that
  40980. + * the user can be notified whenever the context list has changed.
  40981. + */
  40982. +
  40983. +#include "dwc_os.h"
  40984. +#include "dwc_list.h"
  40985. +#include "dwc_notifier.h"
  40986. +
  40987. +
  40988. +/* Notifications */
  40989. +#define DWC_CC_LIST_CHANGED_NOTIFICATION "DWC_CC_LIST_CHANGED_NOTIFICATION"
  40990. +
  40991. +struct dwc_cc_if;
  40992. +typedef struct dwc_cc_if dwc_cc_if_t;
  40993. +
  40994. +
  40995. +/** @name Connection Context Operations */
  40996. +/** @{ */
  40997. +
  40998. +/** This function allocates memory for a dwc_cc_if_t structure, initializes
  40999. + * fields to default values, and returns a pointer to the structure or NULL on
  41000. + * error. */
  41001. +extern dwc_cc_if_t *dwc_cc_if_alloc(void *mem_ctx, void *mtx_ctx,
  41002. + dwc_notifier_t *notifier, unsigned is_host);
  41003. +
  41004. +/** Frees the memory for the specified CC structure allocated from
  41005. + * dwc_cc_if_alloc(). */
  41006. +extern void dwc_cc_if_free(void *mem_ctx, void *mtx_ctx, dwc_cc_if_t *cc_if);
  41007. +
  41008. +/** Removes all contexts from the connection context list */
  41009. +extern void dwc_cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if);
  41010. +
  41011. +/** Adds a connection context (CHID, CK, CDID, Name) to the connection context list.
  41012. + * If a CHID already exists, the CK and name are overwritten. Statistics are
  41013. + * not overwritten.
  41014. + *
  41015. + * @param cc_if The cc_if structure.
  41016. + * @param chid A pointer to the 16-byte CHID. This value will be copied.
  41017. + * @param ck A pointer to the 16-byte CK. This value will be copied.
  41018. + * @param cdid A pointer to the 16-byte CDID. This value will be copied.
  41019. + * @param name An optional host friendly name as defined in the association model
  41020. + * spec. Must be a UTF16-LE unicode string. Can be NULL to indicated no name.
  41021. + * @param length The length othe unicode string.
  41022. + * @return A unique identifier used to refer to this context that is valid for
  41023. + * as long as this context is still in the list. */
  41024. +extern int32_t dwc_cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  41025. + uint8_t *cdid, uint8_t *ck, uint8_t *name,
  41026. + uint8_t length);
  41027. +
  41028. +/** Changes the CHID, CK, CDID, or Name values of a connection context in the
  41029. + * list, preserving any accumulated statistics. This would typically be called
  41030. + * if the host decideds to change the context with a SET_CONNECTION request.
  41031. + *
  41032. + * @param cc_if The cc_if structure.
  41033. + * @param id The identifier of the connection context.
  41034. + * @param chid A pointer to the 16-byte CHID. This value will be copied. NULL
  41035. + * indicates no change.
  41036. + * @param cdid A pointer to the 16-byte CDID. This value will be copied. NULL
  41037. + * indicates no change.
  41038. + * @param ck A pointer to the 16-byte CK. This value will be copied. NULL
  41039. + * indicates no change.
  41040. + * @param name Host friendly name UTF16-LE. NULL indicates no change.
  41041. + * @param length Length of name. */
  41042. +extern void dwc_cc_change(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id,
  41043. + uint8_t *chid, uint8_t *cdid, uint8_t *ck,
  41044. + uint8_t *name, uint8_t length);
  41045. +
  41046. +/** Remove the specified connection context.
  41047. + * @param cc_if The cc_if structure.
  41048. + * @param id The identifier of the connection context to remove. */
  41049. +extern void dwc_cc_remove(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id);
  41050. +
  41051. +/** Get a binary block of data for the connection context list and attributes.
  41052. + * This data can be used by the OS specific driver to save the connection
  41053. + * context list into non-volatile memory.
  41054. + *
  41055. + * @param cc_if The cc_if structure.
  41056. + * @param length Return the length of the data buffer.
  41057. + * @return A pointer to the data buffer. The memory for this buffer should be
  41058. + * freed with DWC_FREE() after use. */
  41059. +extern uint8_t *dwc_cc_data_for_save(void *mem_ctx, dwc_cc_if_t *cc_if,
  41060. + unsigned int *length);
  41061. +
  41062. +/** Restore the connection context list from the binary data that was previously
  41063. + * returned from a call to dwc_cc_data_for_save. This can be used by the OS specific
  41064. + * driver to load a connection context list from non-volatile memory.
  41065. + *
  41066. + * @param cc_if The cc_if structure.
  41067. + * @param data The data bytes as returned from dwc_cc_data_for_save.
  41068. + * @param length The length of the data. */
  41069. +extern void dwc_cc_restore_from_data(void *mem_ctx, dwc_cc_if_t *cc_if,
  41070. + uint8_t *data, unsigned int length);
  41071. +
  41072. +/** Find the connection context from the specified CHID.
  41073. + *
  41074. + * @param cc_if The cc_if structure.
  41075. + * @param chid A pointer to the CHID data.
  41076. + * @return A non-zero identifier of the connection context if the CHID matches.
  41077. + * Otherwise returns 0. */
  41078. +extern uint32_t dwc_cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid);
  41079. +
  41080. +/** Find the connection context from the specified CDID.
  41081. + *
  41082. + * @param cc_if The cc_if structure.
  41083. + * @param cdid A pointer to the CDID data.
  41084. + * @return A non-zero identifier of the connection context if the CHID matches.
  41085. + * Otherwise returns 0. */
  41086. +extern uint32_t dwc_cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid);
  41087. +
  41088. +/** Retrieve the CK from the specified connection context.
  41089. + *
  41090. + * @param cc_if The cc_if structure.
  41091. + * @param id The identifier of the connection context.
  41092. + * @return A pointer to the CK data. The memory does not need to be freed. */
  41093. +extern uint8_t *dwc_cc_ck(dwc_cc_if_t *cc_if, int32_t id);
  41094. +
  41095. +/** Retrieve the CHID from the specified connection context.
  41096. + *
  41097. + * @param cc_if The cc_if structure.
  41098. + * @param id The identifier of the connection context.
  41099. + * @return A pointer to the CHID data. The memory does not need to be freed. */
  41100. +extern uint8_t *dwc_cc_chid(dwc_cc_if_t *cc_if, int32_t id);
  41101. +
  41102. +/** Retrieve the CDID from the specified connection context.
  41103. + *
  41104. + * @param cc_if The cc_if structure.
  41105. + * @param id The identifier of the connection context.
  41106. + * @return A pointer to the CDID data. The memory does not need to be freed. */
  41107. +extern uint8_t *dwc_cc_cdid(dwc_cc_if_t *cc_if, int32_t id);
  41108. +
  41109. +extern uint8_t *dwc_cc_name(dwc_cc_if_t *cc_if, int32_t id, uint8_t *length);
  41110. +
  41111. +/** Checks a buffer for non-zero.
  41112. + * @param id A pointer to a 16 byte buffer.
  41113. + * @return true if the 16 byte value is non-zero. */
  41114. +static inline unsigned dwc_assoc_is_not_zero_id(uint8_t *id) {
  41115. + int i;
  41116. + for (i=0; i<16; i++) {
  41117. + if (id[i]) return 1;
  41118. + }
  41119. + return 0;
  41120. +}
  41121. +
  41122. +/** Checks a buffer for zero.
  41123. + * @param id A pointer to a 16 byte buffer.
  41124. + * @return true if the 16 byte value is zero. */
  41125. +static inline unsigned dwc_assoc_is_zero_id(uint8_t *id) {
  41126. + return !dwc_assoc_is_not_zero_id(id);
  41127. +}
  41128. +
  41129. +/** Prints an ASCII representation for the 16-byte chid, cdid, or ck, into
  41130. + * buffer. */
  41131. +static inline int dwc_print_id_string(char *buffer, uint8_t *id) {
  41132. + char *ptr = buffer;
  41133. + int i;
  41134. + for (i=0; i<16; i++) {
  41135. + ptr += DWC_SPRINTF(ptr, "%02x", id[i]);
  41136. + if (i < 15) {
  41137. + ptr += DWC_SPRINTF(ptr, " ");
  41138. + }
  41139. + }
  41140. + return ptr - buffer;
  41141. +}
  41142. +
  41143. +/** @} */
  41144. +
  41145. +#ifdef __cplusplus
  41146. +}
  41147. +#endif
  41148. +
  41149. +#endif /* _DWC_CC_H_ */
  41150. diff -Nur linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c
  41151. --- linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c 1970-01-01 01:00:00.000000000 +0100
  41152. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c 2014-04-13 17:33:11.000000000 +0200
  41153. @@ -0,0 +1,1308 @@
  41154. +#include "dwc_os.h"
  41155. +#include "dwc_list.h"
  41156. +
  41157. +#ifdef DWC_CCLIB
  41158. +# include "dwc_cc.h"
  41159. +#endif
  41160. +
  41161. +#ifdef DWC_CRYPTOLIB
  41162. +# include "dwc_modpow.h"
  41163. +# include "dwc_dh.h"
  41164. +# include "dwc_crypto.h"
  41165. +#endif
  41166. +
  41167. +#ifdef DWC_NOTIFYLIB
  41168. +# include "dwc_notifier.h"
  41169. +#endif
  41170. +
  41171. +/* OS-Level Implementations */
  41172. +
  41173. +/* This is the FreeBSD 7.0 kernel implementation of the DWC platform library. */
  41174. +
  41175. +
  41176. +/* MISC */
  41177. +
  41178. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  41179. +{
  41180. + return memset(dest, byte, size);
  41181. +}
  41182. +
  41183. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  41184. +{
  41185. + return memcpy(dest, src, size);
  41186. +}
  41187. +
  41188. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  41189. +{
  41190. + bcopy(src, dest, size);
  41191. + return dest;
  41192. +}
  41193. +
  41194. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  41195. +{
  41196. + return memcmp(m1, m2, size);
  41197. +}
  41198. +
  41199. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  41200. +{
  41201. + return strncmp(s1, s2, size);
  41202. +}
  41203. +
  41204. +int DWC_STRCMP(void *s1, void *s2)
  41205. +{
  41206. + return strcmp(s1, s2);
  41207. +}
  41208. +
  41209. +int DWC_STRLEN(char const *str)
  41210. +{
  41211. + return strlen(str);
  41212. +}
  41213. +
  41214. +char *DWC_STRCPY(char *to, char const *from)
  41215. +{
  41216. + return strcpy(to, from);
  41217. +}
  41218. +
  41219. +char *DWC_STRDUP(char const *str)
  41220. +{
  41221. + int len = DWC_STRLEN(str) + 1;
  41222. + char *new = DWC_ALLOC_ATOMIC(len);
  41223. +
  41224. + if (!new) {
  41225. + return NULL;
  41226. + }
  41227. +
  41228. + DWC_MEMCPY(new, str, len);
  41229. + return new;
  41230. +}
  41231. +
  41232. +int DWC_ATOI(char *str, int32_t *value)
  41233. +{
  41234. + char *end = NULL;
  41235. +
  41236. + *value = strtol(str, &end, 0);
  41237. + if (*end == '\0') {
  41238. + return 0;
  41239. + }
  41240. +
  41241. + return -1;
  41242. +}
  41243. +
  41244. +int DWC_ATOUI(char *str, uint32_t *value)
  41245. +{
  41246. + char *end = NULL;
  41247. +
  41248. + *value = strtoul(str, &end, 0);
  41249. + if (*end == '\0') {
  41250. + return 0;
  41251. + }
  41252. +
  41253. + return -1;
  41254. +}
  41255. +
  41256. +
  41257. +#ifdef DWC_UTFLIB
  41258. +/* From usbstring.c */
  41259. +
  41260. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  41261. +{
  41262. + int count = 0;
  41263. + u8 c;
  41264. + u16 uchar;
  41265. +
  41266. + /* this insists on correct encodings, though not minimal ones.
  41267. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  41268. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  41269. + */
  41270. + while (len != 0 && (c = (u8) *s++) != 0) {
  41271. + if (unlikely(c & 0x80)) {
  41272. + // 2-byte sequence:
  41273. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  41274. + if ((c & 0xe0) == 0xc0) {
  41275. + uchar = (c & 0x1f) << 6;
  41276. +
  41277. + c = (u8) *s++;
  41278. + if ((c & 0xc0) != 0xc0)
  41279. + goto fail;
  41280. + c &= 0x3f;
  41281. + uchar |= c;
  41282. +
  41283. + // 3-byte sequence (most CJKV characters):
  41284. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  41285. + } else if ((c & 0xf0) == 0xe0) {
  41286. + uchar = (c & 0x0f) << 12;
  41287. +
  41288. + c = (u8) *s++;
  41289. + if ((c & 0xc0) != 0xc0)
  41290. + goto fail;
  41291. + c &= 0x3f;
  41292. + uchar |= c << 6;
  41293. +
  41294. + c = (u8) *s++;
  41295. + if ((c & 0xc0) != 0xc0)
  41296. + goto fail;
  41297. + c &= 0x3f;
  41298. + uchar |= c;
  41299. +
  41300. + /* no bogus surrogates */
  41301. + if (0xd800 <= uchar && uchar <= 0xdfff)
  41302. + goto fail;
  41303. +
  41304. + // 4-byte sequence (surrogate pairs, currently rare):
  41305. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  41306. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  41307. + // (uuuuu = wwww + 1)
  41308. + // FIXME accept the surrogate code points (only)
  41309. + } else
  41310. + goto fail;
  41311. + } else
  41312. + uchar = c;
  41313. + put_unaligned (cpu_to_le16 (uchar), cp++);
  41314. + count++;
  41315. + len--;
  41316. + }
  41317. + return count;
  41318. +fail:
  41319. + return -1;
  41320. +}
  41321. +
  41322. +#endif /* DWC_UTFLIB */
  41323. +
  41324. +
  41325. +/* dwc_debug.h */
  41326. +
  41327. +dwc_bool_t DWC_IN_IRQ(void)
  41328. +{
  41329. +// return in_irq();
  41330. + return 0;
  41331. +}
  41332. +
  41333. +dwc_bool_t DWC_IN_BH(void)
  41334. +{
  41335. +// return in_softirq();
  41336. + return 0;
  41337. +}
  41338. +
  41339. +void DWC_VPRINTF(char *format, va_list args)
  41340. +{
  41341. + vprintf(format, args);
  41342. +}
  41343. +
  41344. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  41345. +{
  41346. + return vsnprintf(str, size, format, args);
  41347. +}
  41348. +
  41349. +void DWC_PRINTF(char *format, ...)
  41350. +{
  41351. + va_list args;
  41352. +
  41353. + va_start(args, format);
  41354. + DWC_VPRINTF(format, args);
  41355. + va_end(args);
  41356. +}
  41357. +
  41358. +int DWC_SPRINTF(char *buffer, char *format, ...)
  41359. +{
  41360. + int retval;
  41361. + va_list args;
  41362. +
  41363. + va_start(args, format);
  41364. + retval = vsprintf(buffer, format, args);
  41365. + va_end(args);
  41366. + return retval;
  41367. +}
  41368. +
  41369. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  41370. +{
  41371. + int retval;
  41372. + va_list args;
  41373. +
  41374. + va_start(args, format);
  41375. + retval = vsnprintf(buffer, size, format, args);
  41376. + va_end(args);
  41377. + return retval;
  41378. +}
  41379. +
  41380. +void __DWC_WARN(char *format, ...)
  41381. +{
  41382. + va_list args;
  41383. +
  41384. + va_start(args, format);
  41385. + DWC_VPRINTF(format, args);
  41386. + va_end(args);
  41387. +}
  41388. +
  41389. +void __DWC_ERROR(char *format, ...)
  41390. +{
  41391. + va_list args;
  41392. +
  41393. + va_start(args, format);
  41394. + DWC_VPRINTF(format, args);
  41395. + va_end(args);
  41396. +}
  41397. +
  41398. +void DWC_EXCEPTION(char *format, ...)
  41399. +{
  41400. + va_list args;
  41401. +
  41402. + va_start(args, format);
  41403. + DWC_VPRINTF(format, args);
  41404. + va_end(args);
  41405. +// BUG_ON(1); ???
  41406. +}
  41407. +
  41408. +#ifdef DEBUG
  41409. +void __DWC_DEBUG(char *format, ...)
  41410. +{
  41411. + va_list args;
  41412. +
  41413. + va_start(args, format);
  41414. + DWC_VPRINTF(format, args);
  41415. + va_end(args);
  41416. +}
  41417. +#endif
  41418. +
  41419. +
  41420. +/* dwc_mem.h */
  41421. +
  41422. +#if 0
  41423. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  41424. + uint32_t align,
  41425. + uint32_t alloc)
  41426. +{
  41427. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  41428. + size, align, alloc);
  41429. + return (dwc_pool_t *)pool;
  41430. +}
  41431. +
  41432. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  41433. +{
  41434. + dma_pool_destroy((struct dma_pool *)pool);
  41435. +}
  41436. +
  41437. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  41438. +{
  41439. +// return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  41440. + return dma_pool_alloc((struct dma_pool *)pool, M_WAITOK, dma_addr);
  41441. +}
  41442. +
  41443. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  41444. +{
  41445. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  41446. + memset(..);
  41447. +}
  41448. +
  41449. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  41450. +{
  41451. + dma_pool_free(pool, vaddr, daddr);
  41452. +}
  41453. +#endif
  41454. +
  41455. +static void dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
  41456. +{
  41457. + if (error)
  41458. + return;
  41459. + *(bus_addr_t *)arg = segs[0].ds_addr;
  41460. +}
  41461. +
  41462. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  41463. +{
  41464. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  41465. + int error;
  41466. +
  41467. + error = bus_dma_tag_create(
  41468. +#if __FreeBSD_version >= 700000
  41469. + bus_get_dma_tag(dma->dev), /* parent */
  41470. +#else
  41471. + NULL, /* parent */
  41472. +#endif
  41473. + 4, 0, /* alignment, bounds */
  41474. + BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
  41475. + BUS_SPACE_MAXADDR, /* highaddr */
  41476. + NULL, NULL, /* filter, filterarg */
  41477. + size, /* maxsize */
  41478. + 1, /* nsegments */
  41479. + size, /* maxsegsize */
  41480. + 0, /* flags */
  41481. + NULL, /* lockfunc */
  41482. + NULL, /* lockarg */
  41483. + &dma->dma_tag);
  41484. + if (error) {
  41485. + device_printf(dma->dev, "%s: bus_dma_tag_create failed: %d\n",
  41486. + __func__, error);
  41487. + goto fail_0;
  41488. + }
  41489. +
  41490. + error = bus_dmamem_alloc(dma->dma_tag, &dma->dma_vaddr,
  41491. + BUS_DMA_NOWAIT | BUS_DMA_COHERENT, &dma->dma_map);
  41492. + if (error) {
  41493. + device_printf(dma->dev, "%s: bus_dmamem_alloc(%ju) failed: %d\n",
  41494. + __func__, (uintmax_t)size, error);
  41495. + goto fail_1;
  41496. + }
  41497. +
  41498. + dma->dma_paddr = 0;
  41499. + error = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr, size,
  41500. + dmamap_cb, &dma->dma_paddr, BUS_DMA_NOWAIT);
  41501. + if (error || dma->dma_paddr == 0) {
  41502. + device_printf(dma->dev, "%s: bus_dmamap_load failed: %d\n",
  41503. + __func__, error);
  41504. + goto fail_2;
  41505. + }
  41506. +
  41507. + *dma_addr = dma->dma_paddr;
  41508. + return dma->dma_vaddr;
  41509. +
  41510. +fail_2:
  41511. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  41512. +fail_1:
  41513. + bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
  41514. + bus_dma_tag_destroy(dma->dma_tag);
  41515. +fail_0:
  41516. + dma->dma_map = NULL;
  41517. + dma->dma_tag = NULL;
  41518. +
  41519. + return NULL;
  41520. +}
  41521. +
  41522. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  41523. +{
  41524. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  41525. +
  41526. + if (dma->dma_tag == NULL)
  41527. + return;
  41528. + if (dma->dma_map != NULL) {
  41529. + bus_dmamap_sync(dma->dma_tag, dma->dma_map,
  41530. + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
  41531. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  41532. + bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
  41533. + dma->dma_map = NULL;
  41534. + }
  41535. +
  41536. + bus_dma_tag_destroy(dma->dma_tag);
  41537. + dma->dma_tag = NULL;
  41538. +}
  41539. +
  41540. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  41541. +{
  41542. + return malloc(size, M_DEVBUF, M_WAITOK | M_ZERO);
  41543. +}
  41544. +
  41545. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  41546. +{
  41547. + return malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO);
  41548. +}
  41549. +
  41550. +void __DWC_FREE(void *mem_ctx, void *addr)
  41551. +{
  41552. + free(addr, M_DEVBUF);
  41553. +}
  41554. +
  41555. +
  41556. +#ifdef DWC_CRYPTOLIB
  41557. +/* dwc_crypto.h */
  41558. +
  41559. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  41560. +{
  41561. + get_random_bytes(buffer, length);
  41562. +}
  41563. +
  41564. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  41565. +{
  41566. + struct crypto_blkcipher *tfm;
  41567. + struct blkcipher_desc desc;
  41568. + struct scatterlist sgd;
  41569. + struct scatterlist sgs;
  41570. +
  41571. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  41572. + if (tfm == NULL) {
  41573. + printk("failed to load transform for aes CBC\n");
  41574. + return -1;
  41575. + }
  41576. +
  41577. + crypto_blkcipher_setkey(tfm, key, keylen);
  41578. + crypto_blkcipher_set_iv(tfm, iv, 16);
  41579. +
  41580. + sg_init_one(&sgd, out, messagelen);
  41581. + sg_init_one(&sgs, message, messagelen);
  41582. +
  41583. + desc.tfm = tfm;
  41584. + desc.flags = 0;
  41585. +
  41586. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  41587. + crypto_free_blkcipher(tfm);
  41588. + DWC_ERROR("AES CBC encryption failed");
  41589. + return -1;
  41590. + }
  41591. +
  41592. + crypto_free_blkcipher(tfm);
  41593. + return 0;
  41594. +}
  41595. +
  41596. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  41597. +{
  41598. + struct crypto_hash *tfm;
  41599. + struct hash_desc desc;
  41600. + struct scatterlist sg;
  41601. +
  41602. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  41603. + if (IS_ERR(tfm)) {
  41604. + DWC_ERROR("Failed to load transform for sha256: %ld", PTR_ERR(tfm));
  41605. + return 0;
  41606. + }
  41607. + desc.tfm = tfm;
  41608. + desc.flags = 0;
  41609. +
  41610. + sg_init_one(&sg, message, len);
  41611. + crypto_hash_digest(&desc, &sg, len, out);
  41612. + crypto_free_hash(tfm);
  41613. +
  41614. + return 1;
  41615. +}
  41616. +
  41617. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  41618. + uint8_t *key, uint32_t keylen, uint8_t *out)
  41619. +{
  41620. + struct crypto_hash *tfm;
  41621. + struct hash_desc desc;
  41622. + struct scatterlist sg;
  41623. +
  41624. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  41625. + if (IS_ERR(tfm)) {
  41626. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld", PTR_ERR(tfm));
  41627. + return 0;
  41628. + }
  41629. + desc.tfm = tfm;
  41630. + desc.flags = 0;
  41631. +
  41632. + sg_init_one(&sg, message, messagelen);
  41633. + crypto_hash_setkey(tfm, key, keylen);
  41634. + crypto_hash_digest(&desc, &sg, messagelen, out);
  41635. + crypto_free_hash(tfm);
  41636. +
  41637. + return 1;
  41638. +}
  41639. +
  41640. +#endif /* DWC_CRYPTOLIB */
  41641. +
  41642. +
  41643. +/* Byte Ordering Conversions */
  41644. +
  41645. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  41646. +{
  41647. +#ifdef __LITTLE_ENDIAN
  41648. + return *p;
  41649. +#else
  41650. + uint8_t *u_p = (uint8_t *)p;
  41651. +
  41652. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  41653. +#endif
  41654. +}
  41655. +
  41656. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  41657. +{
  41658. +#ifdef __BIG_ENDIAN
  41659. + return *p;
  41660. +#else
  41661. + uint8_t *u_p = (uint8_t *)p;
  41662. +
  41663. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  41664. +#endif
  41665. +}
  41666. +
  41667. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  41668. +{
  41669. +#ifdef __LITTLE_ENDIAN
  41670. + return *p;
  41671. +#else
  41672. + uint8_t *u_p = (uint8_t *)p;
  41673. +
  41674. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  41675. +#endif
  41676. +}
  41677. +
  41678. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  41679. +{
  41680. +#ifdef __BIG_ENDIAN
  41681. + return *p;
  41682. +#else
  41683. + uint8_t *u_p = (uint8_t *)p;
  41684. +
  41685. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  41686. +#endif
  41687. +}
  41688. +
  41689. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  41690. +{
  41691. +#ifdef __LITTLE_ENDIAN
  41692. + return *p;
  41693. +#else
  41694. + uint8_t *u_p = (uint8_t *)p;
  41695. + return (u_p[1] | (u_p[0] << 8));
  41696. +#endif
  41697. +}
  41698. +
  41699. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  41700. +{
  41701. +#ifdef __BIG_ENDIAN
  41702. + return *p;
  41703. +#else
  41704. + uint8_t *u_p = (uint8_t *)p;
  41705. + return (u_p[1] | (u_p[0] << 8));
  41706. +#endif
  41707. +}
  41708. +
  41709. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  41710. +{
  41711. +#ifdef __LITTLE_ENDIAN
  41712. + return *p;
  41713. +#else
  41714. + uint8_t *u_p = (uint8_t *)p;
  41715. + return (u_p[1] | (u_p[0] << 8));
  41716. +#endif
  41717. +}
  41718. +
  41719. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  41720. +{
  41721. +#ifdef __BIG_ENDIAN
  41722. + return *p;
  41723. +#else
  41724. + uint8_t *u_p = (uint8_t *)p;
  41725. + return (u_p[1] | (u_p[0] << 8));
  41726. +#endif
  41727. +}
  41728. +
  41729. +
  41730. +/* Registers */
  41731. +
  41732. +uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg)
  41733. +{
  41734. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  41735. + bus_size_t ior = (bus_size_t)reg;
  41736. +
  41737. + return bus_space_read_4(io->iot, io->ioh, ior);
  41738. +}
  41739. +
  41740. +#if 0
  41741. +uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg)
  41742. +{
  41743. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  41744. + bus_size_t ior = (bus_size_t)reg;
  41745. +
  41746. + return bus_space_read_8(io->iot, io->ioh, ior);
  41747. +}
  41748. +#endif
  41749. +
  41750. +void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value)
  41751. +{
  41752. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  41753. + bus_size_t ior = (bus_size_t)reg;
  41754. +
  41755. + bus_space_write_4(io->iot, io->ioh, ior, value);
  41756. +}
  41757. +
  41758. +#if 0
  41759. +void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value)
  41760. +{
  41761. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  41762. + bus_size_t ior = (bus_size_t)reg;
  41763. +
  41764. + bus_space_write_8(io->iot, io->ioh, ior, value);
  41765. +}
  41766. +#endif
  41767. +
  41768. +void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask,
  41769. + uint32_t set_mask)
  41770. +{
  41771. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  41772. + bus_size_t ior = (bus_size_t)reg;
  41773. +
  41774. + bus_space_write_4(io->iot, io->ioh, ior,
  41775. + (bus_space_read_4(io->iot, io->ioh, ior) &
  41776. + ~clear_mask) | set_mask);
  41777. +}
  41778. +
  41779. +#if 0
  41780. +void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask,
  41781. + uint64_t set_mask)
  41782. +{
  41783. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  41784. + bus_size_t ior = (bus_size_t)reg;
  41785. +
  41786. + bus_space_write_8(io->iot, io->ioh, ior,
  41787. + (bus_space_read_8(io->iot, io->ioh, ior) &
  41788. + ~clear_mask) | set_mask);
  41789. +}
  41790. +#endif
  41791. +
  41792. +
  41793. +/* Locking */
  41794. +
  41795. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  41796. +{
  41797. + struct mtx *sl = DWC_ALLOC(sizeof(*sl));
  41798. +
  41799. + if (!sl) {
  41800. + DWC_ERROR("Cannot allocate memory for spinlock");
  41801. + return NULL;
  41802. + }
  41803. +
  41804. + mtx_init(sl, "dw3spn", NULL, MTX_SPIN);
  41805. + return (dwc_spinlock_t *)sl;
  41806. +}
  41807. +
  41808. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  41809. +{
  41810. + struct mtx *sl = (struct mtx *)lock;
  41811. +
  41812. + mtx_destroy(sl);
  41813. + DWC_FREE(sl);
  41814. +}
  41815. +
  41816. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  41817. +{
  41818. + mtx_lock_spin((struct mtx *)lock); // ???
  41819. +}
  41820. +
  41821. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  41822. +{
  41823. + mtx_unlock_spin((struct mtx *)lock); // ???
  41824. +}
  41825. +
  41826. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  41827. +{
  41828. + mtx_lock_spin((struct mtx *)lock);
  41829. +}
  41830. +
  41831. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  41832. +{
  41833. + mtx_unlock_spin((struct mtx *)lock);
  41834. +}
  41835. +
  41836. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  41837. +{
  41838. + struct mtx *m;
  41839. + dwc_mutex_t *mutex = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mtx));
  41840. +
  41841. + if (!mutex) {
  41842. + DWC_ERROR("Cannot allocate memory for mutex");
  41843. + return NULL;
  41844. + }
  41845. +
  41846. + m = (struct mtx *)mutex;
  41847. + mtx_init(m, "dw3mtx", NULL, MTX_DEF);
  41848. + return mutex;
  41849. +}
  41850. +
  41851. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  41852. +#else
  41853. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  41854. +{
  41855. + mtx_destroy((struct mtx *)mutex);
  41856. + DWC_FREE(mutex);
  41857. +}
  41858. +#endif
  41859. +
  41860. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  41861. +{
  41862. + struct mtx *m = (struct mtx *)mutex;
  41863. +
  41864. + mtx_lock(m);
  41865. +}
  41866. +
  41867. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  41868. +{
  41869. + struct mtx *m = (struct mtx *)mutex;
  41870. +
  41871. + return mtx_trylock(m);
  41872. +}
  41873. +
  41874. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  41875. +{
  41876. + struct mtx *m = (struct mtx *)mutex;
  41877. +
  41878. + mtx_unlock(m);
  41879. +}
  41880. +
  41881. +
  41882. +/* Timing */
  41883. +
  41884. +void DWC_UDELAY(uint32_t usecs)
  41885. +{
  41886. + DELAY(usecs);
  41887. +}
  41888. +
  41889. +void DWC_MDELAY(uint32_t msecs)
  41890. +{
  41891. + do {
  41892. + DELAY(1000);
  41893. + } while (--msecs);
  41894. +}
  41895. +
  41896. +void DWC_MSLEEP(uint32_t msecs)
  41897. +{
  41898. + struct timeval tv;
  41899. +
  41900. + tv.tv_sec = msecs / 1000;
  41901. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  41902. + pause("dw3slp", tvtohz(&tv));
  41903. +}
  41904. +
  41905. +uint32_t DWC_TIME(void)
  41906. +{
  41907. + struct timeval tv;
  41908. +
  41909. + microuptime(&tv); // or getmicrouptime? (less precise, but faster)
  41910. + return tv.tv_sec * 1000 + tv.tv_usec / 1000;
  41911. +}
  41912. +
  41913. +
  41914. +/* Timers */
  41915. +
  41916. +struct dwc_timer {
  41917. + struct callout t;
  41918. + char *name;
  41919. + dwc_spinlock_t *lock;
  41920. + dwc_timer_callback_t cb;
  41921. + void *data;
  41922. +};
  41923. +
  41924. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  41925. +{
  41926. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  41927. +
  41928. + if (!t) {
  41929. + DWC_ERROR("Cannot allocate memory for timer");
  41930. + return NULL;
  41931. + }
  41932. +
  41933. + callout_init(&t->t, 1);
  41934. +
  41935. + t->name = DWC_STRDUP(name);
  41936. + if (!t->name) {
  41937. + DWC_ERROR("Cannot allocate memory for timer->name");
  41938. + goto no_name;
  41939. + }
  41940. +
  41941. + t->lock = DWC_SPINLOCK_ALLOC();
  41942. + if (!t->lock) {
  41943. + DWC_ERROR("Cannot allocate memory for lock");
  41944. + goto no_lock;
  41945. + }
  41946. +
  41947. + t->cb = cb;
  41948. + t->data = data;
  41949. +
  41950. + return t;
  41951. +
  41952. + no_lock:
  41953. + DWC_FREE(t->name);
  41954. + no_name:
  41955. + DWC_FREE(t);
  41956. +
  41957. + return NULL;
  41958. +}
  41959. +
  41960. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  41961. +{
  41962. + callout_stop(&timer->t);
  41963. + DWC_SPINLOCK_FREE(timer->lock);
  41964. + DWC_FREE(timer->name);
  41965. + DWC_FREE(timer);
  41966. +}
  41967. +
  41968. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  41969. +{
  41970. + struct timeval tv;
  41971. +
  41972. + tv.tv_sec = time / 1000;
  41973. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  41974. + callout_reset(&timer->t, tvtohz(&tv), timer->cb, timer->data);
  41975. +}
  41976. +
  41977. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  41978. +{
  41979. + callout_stop(&timer->t);
  41980. +}
  41981. +
  41982. +
  41983. +/* Wait Queues */
  41984. +
  41985. +struct dwc_waitq {
  41986. + struct mtx lock;
  41987. + int abort;
  41988. +};
  41989. +
  41990. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  41991. +{
  41992. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  41993. +
  41994. + if (!wq) {
  41995. + DWC_ERROR("Cannot allocate memory for waitqueue");
  41996. + return NULL;
  41997. + }
  41998. +
  41999. + mtx_init(&wq->lock, "dw3wtq", NULL, MTX_DEF);
  42000. + wq->abort = 0;
  42001. +
  42002. + return wq;
  42003. +}
  42004. +
  42005. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  42006. +{
  42007. + mtx_destroy(&wq->lock);
  42008. + DWC_FREE(wq);
  42009. +}
  42010. +
  42011. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  42012. +{
  42013. +// intrmask_t ipl;
  42014. + int result = 0;
  42015. +
  42016. + mtx_lock(&wq->lock);
  42017. +// ipl = splbio();
  42018. +
  42019. + /* Skip the sleep if already aborted or triggered */
  42020. + if (!wq->abort && !cond(data)) {
  42021. +// splx(ipl);
  42022. + result = msleep(wq, &wq->lock, PCATCH, "dw3wat", 0); // infinite timeout
  42023. +// ipl = splbio();
  42024. + }
  42025. +
  42026. + if (result == ERESTART) { // signaled - restart
  42027. + result = -DWC_E_RESTART;
  42028. +
  42029. + } else if (result == EINTR) { // signaled - interrupt
  42030. + result = -DWC_E_ABORT;
  42031. +
  42032. + } else if (wq->abort) {
  42033. + result = -DWC_E_ABORT;
  42034. +
  42035. + } else {
  42036. + result = 0;
  42037. + }
  42038. +
  42039. + wq->abort = 0;
  42040. +// splx(ipl);
  42041. + mtx_unlock(&wq->lock);
  42042. + return result;
  42043. +}
  42044. +
  42045. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  42046. + void *data, int32_t msecs)
  42047. +{
  42048. + struct timeval tv, tv1, tv2;
  42049. +// intrmask_t ipl;
  42050. + int result = 0;
  42051. +
  42052. + tv.tv_sec = msecs / 1000;
  42053. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  42054. +
  42055. + mtx_lock(&wq->lock);
  42056. +// ipl = splbio();
  42057. +
  42058. + /* Skip the sleep if already aborted or triggered */
  42059. + if (!wq->abort && !cond(data)) {
  42060. +// splx(ipl);
  42061. + getmicrouptime(&tv1);
  42062. + result = msleep(wq, &wq->lock, PCATCH, "dw3wto", tvtohz(&tv));
  42063. + getmicrouptime(&tv2);
  42064. +// ipl = splbio();
  42065. + }
  42066. +
  42067. + if (result == 0) { // awoken
  42068. + if (wq->abort) {
  42069. + result = -DWC_E_ABORT;
  42070. + } else {
  42071. + tv2.tv_usec -= tv1.tv_usec;
  42072. + if (tv2.tv_usec < 0) {
  42073. + tv2.tv_usec += 1000000;
  42074. + tv2.tv_sec--;
  42075. + }
  42076. +
  42077. + tv2.tv_sec -= tv1.tv_sec;
  42078. + result = tv2.tv_sec * 1000 + tv2.tv_usec / 1000;
  42079. + result = msecs - result;
  42080. + if (result <= 0)
  42081. + result = 1;
  42082. + }
  42083. + } else if (result == ERESTART) { // signaled - restart
  42084. + result = -DWC_E_RESTART;
  42085. +
  42086. + } else if (result == EINTR) { // signaled - interrupt
  42087. + result = -DWC_E_ABORT;
  42088. +
  42089. + } else { // timed out
  42090. + result = -DWC_E_TIMEOUT;
  42091. + }
  42092. +
  42093. + wq->abort = 0;
  42094. +// splx(ipl);
  42095. + mtx_unlock(&wq->lock);
  42096. + return result;
  42097. +}
  42098. +
  42099. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  42100. +{
  42101. + wakeup(wq);
  42102. +}
  42103. +
  42104. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  42105. +{
  42106. +// intrmask_t ipl;
  42107. +
  42108. + mtx_lock(&wq->lock);
  42109. +// ipl = splbio();
  42110. + wq->abort = 1;
  42111. + wakeup(wq);
  42112. +// splx(ipl);
  42113. + mtx_unlock(&wq->lock);
  42114. +}
  42115. +
  42116. +
  42117. +/* Threading */
  42118. +
  42119. +struct dwc_thread {
  42120. + struct proc *proc;
  42121. + int abort;
  42122. +};
  42123. +
  42124. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  42125. +{
  42126. + int retval;
  42127. + dwc_thread_t *thread = DWC_ALLOC(sizeof(*thread));
  42128. +
  42129. + if (!thread) {
  42130. + return NULL;
  42131. + }
  42132. +
  42133. + thread->abort = 0;
  42134. + retval = kthread_create((void (*)(void *))func, data, &thread->proc,
  42135. + RFPROC | RFNOWAIT, 0, "%s", name);
  42136. + if (retval) {
  42137. + DWC_FREE(thread);
  42138. + return NULL;
  42139. + }
  42140. +
  42141. + return thread;
  42142. +}
  42143. +
  42144. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  42145. +{
  42146. + int retval;
  42147. +
  42148. + thread->abort = 1;
  42149. + retval = tsleep(&thread->abort, 0, "dw3stp", 60 * hz);
  42150. +
  42151. + if (retval == 0) {
  42152. + /* DWC_THREAD_EXIT() will free the thread struct */
  42153. + return 0;
  42154. + }
  42155. +
  42156. + /* NOTE: We leak the thread struct if thread doesn't die */
  42157. +
  42158. + if (retval == EWOULDBLOCK) {
  42159. + return -DWC_E_TIMEOUT;
  42160. + }
  42161. +
  42162. + return -DWC_E_UNKNOWN;
  42163. +}
  42164. +
  42165. +dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread)
  42166. +{
  42167. + return thread->abort;
  42168. +}
  42169. +
  42170. +void DWC_THREAD_EXIT(dwc_thread_t *thread)
  42171. +{
  42172. + wakeup(&thread->abort);
  42173. + DWC_FREE(thread);
  42174. + kthread_exit(0);
  42175. +}
  42176. +
  42177. +
  42178. +/* tasklets
  42179. + - Runs in interrupt context (cannot sleep)
  42180. + - Each tasklet runs on a single CPU [ How can we ensure this on FreeBSD? Does it matter? ]
  42181. + - Different tasklets can be running simultaneously on different CPUs [ shouldn't matter ]
  42182. + */
  42183. +struct dwc_tasklet {
  42184. + struct task t;
  42185. + dwc_tasklet_callback_t cb;
  42186. + void *data;
  42187. +};
  42188. +
  42189. +static void tasklet_callback(void *data, int pending) // what to do with pending ???
  42190. +{
  42191. + dwc_tasklet_t *task = (dwc_tasklet_t *)data;
  42192. +
  42193. + task->cb(task->data);
  42194. +}
  42195. +
  42196. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  42197. +{
  42198. + dwc_tasklet_t *task = DWC_ALLOC(sizeof(*task));
  42199. +
  42200. + if (task) {
  42201. + task->cb = cb;
  42202. + task->data = data;
  42203. + TASK_INIT(&task->t, 0, tasklet_callback, task);
  42204. + } else {
  42205. + DWC_ERROR("Cannot allocate memory for tasklet");
  42206. + }
  42207. +
  42208. + return task;
  42209. +}
  42210. +
  42211. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  42212. +{
  42213. + taskqueue_drain(taskqueue_fast, &task->t); // ???
  42214. + DWC_FREE(task);
  42215. +}
  42216. +
  42217. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  42218. +{
  42219. + /* Uses predefined system queue */
  42220. + taskqueue_enqueue_fast(taskqueue_fast, &task->t);
  42221. +}
  42222. +
  42223. +
  42224. +/* workqueues
  42225. + - Runs in process context (can sleep)
  42226. + */
  42227. +typedef struct work_container {
  42228. + dwc_work_callback_t cb;
  42229. + void *data;
  42230. + dwc_workq_t *wq;
  42231. + char *name;
  42232. + int hz;
  42233. +
  42234. +#ifdef DEBUG
  42235. + DWC_CIRCLEQ_ENTRY(work_container) entry;
  42236. +#endif
  42237. + struct task task;
  42238. +} work_container_t;
  42239. +
  42240. +#ifdef DEBUG
  42241. +DWC_CIRCLEQ_HEAD(work_container_queue, work_container);
  42242. +#endif
  42243. +
  42244. +struct dwc_workq {
  42245. + struct taskqueue *taskq;
  42246. + dwc_spinlock_t *lock;
  42247. + dwc_waitq_t *waitq;
  42248. + int pending;
  42249. +
  42250. +#ifdef DEBUG
  42251. + struct work_container_queue entries;
  42252. +#endif
  42253. +};
  42254. +
  42255. +static void do_work(void *data, int pending) // what to do with pending ???
  42256. +{
  42257. + work_container_t *container = (work_container_t *)data;
  42258. + dwc_workq_t *wq = container->wq;
  42259. + dwc_irqflags_t flags;
  42260. +
  42261. + if (container->hz) {
  42262. + pause("dw3wrk", container->hz);
  42263. + }
  42264. +
  42265. + container->cb(container->data);
  42266. + DWC_DEBUG("Work done: %s, container=%p", container->name, container);
  42267. +
  42268. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  42269. +
  42270. +#ifdef DEBUG
  42271. + DWC_CIRCLEQ_REMOVE(&wq->entries, container, entry);
  42272. +#endif
  42273. + if (container->name)
  42274. + DWC_FREE(container->name);
  42275. + DWC_FREE(container);
  42276. + wq->pending--;
  42277. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  42278. + DWC_WAITQ_TRIGGER(wq->waitq);
  42279. +}
  42280. +
  42281. +static int work_done(void *data)
  42282. +{
  42283. + dwc_workq_t *workq = (dwc_workq_t *)data;
  42284. +
  42285. + return workq->pending == 0;
  42286. +}
  42287. +
  42288. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  42289. +{
  42290. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  42291. +}
  42292. +
  42293. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  42294. +{
  42295. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  42296. +
  42297. + if (!wq) {
  42298. + DWC_ERROR("Cannot allocate memory for workqueue");
  42299. + return NULL;
  42300. + }
  42301. +
  42302. + wq->taskq = taskqueue_create(name, M_NOWAIT, taskqueue_thread_enqueue, &wq->taskq);
  42303. + if (!wq->taskq) {
  42304. + DWC_ERROR("Cannot allocate memory for taskqueue");
  42305. + goto no_taskq;
  42306. + }
  42307. +
  42308. + wq->pending = 0;
  42309. +
  42310. + wq->lock = DWC_SPINLOCK_ALLOC();
  42311. + if (!wq->lock) {
  42312. + DWC_ERROR("Cannot allocate memory for spinlock");
  42313. + goto no_lock;
  42314. + }
  42315. +
  42316. + wq->waitq = DWC_WAITQ_ALLOC();
  42317. + if (!wq->waitq) {
  42318. + DWC_ERROR("Cannot allocate memory for waitqueue");
  42319. + goto no_waitq;
  42320. + }
  42321. +
  42322. + taskqueue_start_threads(&wq->taskq, 1, PWAIT, "%s taskq", "dw3tsk");
  42323. +
  42324. +#ifdef DEBUG
  42325. + DWC_CIRCLEQ_INIT(&wq->entries);
  42326. +#endif
  42327. + return wq;
  42328. +
  42329. + no_waitq:
  42330. + DWC_SPINLOCK_FREE(wq->lock);
  42331. + no_lock:
  42332. + taskqueue_free(wq->taskq);
  42333. + no_taskq:
  42334. + DWC_FREE(wq);
  42335. +
  42336. + return NULL;
  42337. +}
  42338. +
  42339. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  42340. +{
  42341. +#ifdef DEBUG
  42342. + dwc_irqflags_t flags;
  42343. +
  42344. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  42345. +
  42346. + if (wq->pending != 0) {
  42347. + struct work_container *container;
  42348. +
  42349. + DWC_ERROR("Destroying work queue with pending work");
  42350. +
  42351. + DWC_CIRCLEQ_FOREACH(container, &wq->entries, entry) {
  42352. + DWC_ERROR("Work %s still pending", container->name);
  42353. + }
  42354. + }
  42355. +
  42356. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  42357. +#endif
  42358. + DWC_WAITQ_FREE(wq->waitq);
  42359. + DWC_SPINLOCK_FREE(wq->lock);
  42360. + taskqueue_free(wq->taskq);
  42361. + DWC_FREE(wq);
  42362. +}
  42363. +
  42364. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  42365. + char *format, ...)
  42366. +{
  42367. + dwc_irqflags_t flags;
  42368. + work_container_t *container;
  42369. + static char name[128];
  42370. + va_list args;
  42371. +
  42372. + va_start(args, format);
  42373. + DWC_VSNPRINTF(name, 128, format, args);
  42374. + va_end(args);
  42375. +
  42376. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  42377. + wq->pending++;
  42378. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  42379. + DWC_WAITQ_TRIGGER(wq->waitq);
  42380. +
  42381. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  42382. + if (!container) {
  42383. + DWC_ERROR("Cannot allocate memory for container");
  42384. + return;
  42385. + }
  42386. +
  42387. + container->name = DWC_STRDUP(name);
  42388. + if (!container->name) {
  42389. + DWC_ERROR("Cannot allocate memory for container->name");
  42390. + DWC_FREE(container);
  42391. + return;
  42392. + }
  42393. +
  42394. + container->cb = cb;
  42395. + container->data = data;
  42396. + container->wq = wq;
  42397. + container->hz = 0;
  42398. +
  42399. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  42400. +
  42401. + TASK_INIT(&container->task, 0, do_work, container);
  42402. +
  42403. +#ifdef DEBUG
  42404. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  42405. +#endif
  42406. + taskqueue_enqueue_fast(wq->taskq, &container->task);
  42407. +}
  42408. +
  42409. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  42410. + void *data, uint32_t time, char *format, ...)
  42411. +{
  42412. + dwc_irqflags_t flags;
  42413. + work_container_t *container;
  42414. + static char name[128];
  42415. + struct timeval tv;
  42416. + va_list args;
  42417. +
  42418. + va_start(args, format);
  42419. + DWC_VSNPRINTF(name, 128, format, args);
  42420. + va_end(args);
  42421. +
  42422. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  42423. + wq->pending++;
  42424. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  42425. + DWC_WAITQ_TRIGGER(wq->waitq);
  42426. +
  42427. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  42428. + if (!container) {
  42429. + DWC_ERROR("Cannot allocate memory for container");
  42430. + return;
  42431. + }
  42432. +
  42433. + container->name = DWC_STRDUP(name);
  42434. + if (!container->name) {
  42435. + DWC_ERROR("Cannot allocate memory for container->name");
  42436. + DWC_FREE(container);
  42437. + return;
  42438. + }
  42439. +
  42440. + container->cb = cb;
  42441. + container->data = data;
  42442. + container->wq = wq;
  42443. +
  42444. + tv.tv_sec = time / 1000;
  42445. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  42446. + container->hz = tvtohz(&tv);
  42447. +
  42448. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  42449. +
  42450. + TASK_INIT(&container->task, 0, do_work, container);
  42451. +
  42452. +#ifdef DEBUG
  42453. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  42454. +#endif
  42455. + taskqueue_enqueue_fast(wq->taskq, &container->task);
  42456. +}
  42457. +
  42458. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  42459. +{
  42460. + return wq->pending;
  42461. +}
  42462. diff -Nur linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_common_linux.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_linux.c
  42463. --- linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_common_linux.c 1970-01-01 01:00:00.000000000 +0100
  42464. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_linux.c 2014-07-07 10:45:43.000000000 +0200
  42465. @@ -0,0 +1,1432 @@
  42466. +#include <linux/kernel.h>
  42467. +#include <linux/init.h>
  42468. +#include <linux/module.h>
  42469. +#include <linux/kthread.h>
  42470. +
  42471. +#ifdef DWC_CCLIB
  42472. +# include "dwc_cc.h"
  42473. +#endif
  42474. +
  42475. +#ifdef DWC_CRYPTOLIB
  42476. +# include "dwc_modpow.h"
  42477. +# include "dwc_dh.h"
  42478. +# include "dwc_crypto.h"
  42479. +#endif
  42480. +
  42481. +#ifdef DWC_NOTIFYLIB
  42482. +# include "dwc_notifier.h"
  42483. +#endif
  42484. +
  42485. +/* OS-Level Implementations */
  42486. +
  42487. +/* This is the Linux kernel implementation of the DWC platform library. */
  42488. +#include <linux/moduleparam.h>
  42489. +#include <linux/ctype.h>
  42490. +#include <linux/crypto.h>
  42491. +#include <linux/delay.h>
  42492. +#include <linux/device.h>
  42493. +#include <linux/dma-mapping.h>
  42494. +#include <linux/cdev.h>
  42495. +#include <linux/errno.h>
  42496. +#include <linux/interrupt.h>
  42497. +#include <linux/jiffies.h>
  42498. +#include <linux/list.h>
  42499. +#include <linux/pci.h>
  42500. +#include <linux/random.h>
  42501. +#include <linux/scatterlist.h>
  42502. +#include <linux/slab.h>
  42503. +#include <linux/stat.h>
  42504. +#include <linux/string.h>
  42505. +#include <linux/timer.h>
  42506. +#include <linux/usb.h>
  42507. +
  42508. +#include <linux/version.h>
  42509. +
  42510. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
  42511. +# include <linux/usb/gadget.h>
  42512. +#else
  42513. +# include <linux/usb_gadget.h>
  42514. +#endif
  42515. +
  42516. +#include <asm/io.h>
  42517. +#include <asm/page.h>
  42518. +#include <asm/uaccess.h>
  42519. +#include <asm/unaligned.h>
  42520. +
  42521. +#include "dwc_os.h"
  42522. +#include "dwc_list.h"
  42523. +
  42524. +
  42525. +/* MISC */
  42526. +
  42527. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  42528. +{
  42529. + return memset(dest, byte, size);
  42530. +}
  42531. +
  42532. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  42533. +{
  42534. + return memcpy(dest, src, size);
  42535. +}
  42536. +
  42537. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  42538. +{
  42539. + return memmove(dest, src, size);
  42540. +}
  42541. +
  42542. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  42543. +{
  42544. + return memcmp(m1, m2, size);
  42545. +}
  42546. +
  42547. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  42548. +{
  42549. + return strncmp(s1, s2, size);
  42550. +}
  42551. +
  42552. +int DWC_STRCMP(void *s1, void *s2)
  42553. +{
  42554. + return strcmp(s1, s2);
  42555. +}
  42556. +
  42557. +int DWC_STRLEN(char const *str)
  42558. +{
  42559. + return strlen(str);
  42560. +}
  42561. +
  42562. +char *DWC_STRCPY(char *to, char const *from)
  42563. +{
  42564. + return strcpy(to, from);
  42565. +}
  42566. +
  42567. +char *DWC_STRDUP(char const *str)
  42568. +{
  42569. + int len = DWC_STRLEN(str) + 1;
  42570. + char *new = DWC_ALLOC_ATOMIC(len);
  42571. +
  42572. + if (!new) {
  42573. + return NULL;
  42574. + }
  42575. +
  42576. + DWC_MEMCPY(new, str, len);
  42577. + return new;
  42578. +}
  42579. +
  42580. +int DWC_ATOI(const char *str, int32_t *value)
  42581. +{
  42582. + char *end = NULL;
  42583. +
  42584. + *value = simple_strtol(str, &end, 0);
  42585. + if (*end == '\0') {
  42586. + return 0;
  42587. + }
  42588. +
  42589. + return -1;
  42590. +}
  42591. +
  42592. +int DWC_ATOUI(const char *str, uint32_t *value)
  42593. +{
  42594. + char *end = NULL;
  42595. +
  42596. + *value = simple_strtoul(str, &end, 0);
  42597. + if (*end == '\0') {
  42598. + return 0;
  42599. + }
  42600. +
  42601. + return -1;
  42602. +}
  42603. +
  42604. +
  42605. +#ifdef DWC_UTFLIB
  42606. +/* From usbstring.c */
  42607. +
  42608. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  42609. +{
  42610. + int count = 0;
  42611. + u8 c;
  42612. + u16 uchar;
  42613. +
  42614. + /* this insists on correct encodings, though not minimal ones.
  42615. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  42616. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  42617. + */
  42618. + while (len != 0 && (c = (u8) *s++) != 0) {
  42619. + if (unlikely(c & 0x80)) {
  42620. + // 2-byte sequence:
  42621. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  42622. + if ((c & 0xe0) == 0xc0) {
  42623. + uchar = (c & 0x1f) << 6;
  42624. +
  42625. + c = (u8) *s++;
  42626. + if ((c & 0xc0) != 0xc0)
  42627. + goto fail;
  42628. + c &= 0x3f;
  42629. + uchar |= c;
  42630. +
  42631. + // 3-byte sequence (most CJKV characters):
  42632. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  42633. + } else if ((c & 0xf0) == 0xe0) {
  42634. + uchar = (c & 0x0f) << 12;
  42635. +
  42636. + c = (u8) *s++;
  42637. + if ((c & 0xc0) != 0xc0)
  42638. + goto fail;
  42639. + c &= 0x3f;
  42640. + uchar |= c << 6;
  42641. +
  42642. + c = (u8) *s++;
  42643. + if ((c & 0xc0) != 0xc0)
  42644. + goto fail;
  42645. + c &= 0x3f;
  42646. + uchar |= c;
  42647. +
  42648. + /* no bogus surrogates */
  42649. + if (0xd800 <= uchar && uchar <= 0xdfff)
  42650. + goto fail;
  42651. +
  42652. + // 4-byte sequence (surrogate pairs, currently rare):
  42653. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  42654. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  42655. + // (uuuuu = wwww + 1)
  42656. + // FIXME accept the surrogate code points (only)
  42657. + } else
  42658. + goto fail;
  42659. + } else
  42660. + uchar = c;
  42661. + put_unaligned (cpu_to_le16 (uchar), cp++);
  42662. + count++;
  42663. + len--;
  42664. + }
  42665. + return count;
  42666. +fail:
  42667. + return -1;
  42668. +}
  42669. +#endif /* DWC_UTFLIB */
  42670. +
  42671. +
  42672. +/* dwc_debug.h */
  42673. +
  42674. +dwc_bool_t DWC_IN_IRQ(void)
  42675. +{
  42676. + return in_irq();
  42677. +}
  42678. +
  42679. +dwc_bool_t DWC_IN_BH(void)
  42680. +{
  42681. + return in_softirq();
  42682. +}
  42683. +
  42684. +void DWC_VPRINTF(char *format, va_list args)
  42685. +{
  42686. + vprintk(format, args);
  42687. +}
  42688. +
  42689. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  42690. +{
  42691. + return vsnprintf(str, size, format, args);
  42692. +}
  42693. +
  42694. +void DWC_PRINTF(char *format, ...)
  42695. +{
  42696. + va_list args;
  42697. +
  42698. + va_start(args, format);
  42699. + DWC_VPRINTF(format, args);
  42700. + va_end(args);
  42701. +}
  42702. +
  42703. +int DWC_SPRINTF(char *buffer, char *format, ...)
  42704. +{
  42705. + int retval;
  42706. + va_list args;
  42707. +
  42708. + va_start(args, format);
  42709. + retval = vsprintf(buffer, format, args);
  42710. + va_end(args);
  42711. + return retval;
  42712. +}
  42713. +
  42714. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  42715. +{
  42716. + int retval;
  42717. + va_list args;
  42718. +
  42719. + va_start(args, format);
  42720. + retval = vsnprintf(buffer, size, format, args);
  42721. + va_end(args);
  42722. + return retval;
  42723. +}
  42724. +
  42725. +void __DWC_WARN(char *format, ...)
  42726. +{
  42727. + va_list args;
  42728. +
  42729. + va_start(args, format);
  42730. + DWC_PRINTF(KERN_WARNING);
  42731. + DWC_VPRINTF(format, args);
  42732. + va_end(args);
  42733. +}
  42734. +
  42735. +void __DWC_ERROR(char *format, ...)
  42736. +{
  42737. + va_list args;
  42738. +
  42739. + va_start(args, format);
  42740. + DWC_PRINTF(KERN_ERR);
  42741. + DWC_VPRINTF(format, args);
  42742. + va_end(args);
  42743. +}
  42744. +
  42745. +void DWC_EXCEPTION(char *format, ...)
  42746. +{
  42747. + va_list args;
  42748. +
  42749. + va_start(args, format);
  42750. + DWC_PRINTF(KERN_ERR);
  42751. + DWC_VPRINTF(format, args);
  42752. + va_end(args);
  42753. + BUG_ON(1);
  42754. +}
  42755. +
  42756. +#ifdef DEBUG
  42757. +void __DWC_DEBUG(char *format, ...)
  42758. +{
  42759. + va_list args;
  42760. +
  42761. + va_start(args, format);
  42762. + DWC_PRINTF(KERN_DEBUG);
  42763. + DWC_VPRINTF(format, args);
  42764. + va_end(args);
  42765. +}
  42766. +#endif
  42767. +
  42768. +
  42769. +/* dwc_mem.h */
  42770. +
  42771. +#if 0
  42772. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  42773. + uint32_t align,
  42774. + uint32_t alloc)
  42775. +{
  42776. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  42777. + size, align, alloc);
  42778. + return (dwc_pool_t *)pool;
  42779. +}
  42780. +
  42781. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  42782. +{
  42783. + dma_pool_destroy((struct dma_pool *)pool);
  42784. +}
  42785. +
  42786. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  42787. +{
  42788. + return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  42789. +}
  42790. +
  42791. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  42792. +{
  42793. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  42794. + memset(..);
  42795. +}
  42796. +
  42797. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  42798. +{
  42799. + dma_pool_free(pool, vaddr, daddr);
  42800. +}
  42801. +#endif
  42802. +
  42803. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  42804. +{
  42805. +#ifdef xxCOSIM /* Only works for 32-bit cosim */
  42806. + void *buf = dma_alloc_coherent(dma_ctx, (size_t)size, dma_addr, GFP_KERNEL);
  42807. +#else
  42808. + void *buf = dma_alloc_coherent(dma_ctx, (size_t)size, dma_addr, GFP_KERNEL | GFP_DMA32);
  42809. +#endif
  42810. + if (!buf) {
  42811. + return NULL;
  42812. + }
  42813. +
  42814. + memset(buf, 0, (size_t)size);
  42815. + return buf;
  42816. +}
  42817. +
  42818. +void *__DWC_DMA_ALLOC_ATOMIC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  42819. +{
  42820. + void *buf = dma_alloc_coherent(NULL, (size_t)size, dma_addr, GFP_ATOMIC);
  42821. + if (!buf) {
  42822. + return NULL;
  42823. + }
  42824. + memset(buf, 0, (size_t)size);
  42825. + return buf;
  42826. +}
  42827. +
  42828. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  42829. +{
  42830. + dma_free_coherent(dma_ctx, size, virt_addr, dma_addr);
  42831. +}
  42832. +
  42833. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  42834. +{
  42835. + return kzalloc(size, GFP_KERNEL);
  42836. +}
  42837. +
  42838. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  42839. +{
  42840. + return kzalloc(size, GFP_ATOMIC);
  42841. +}
  42842. +
  42843. +void __DWC_FREE(void *mem_ctx, void *addr)
  42844. +{
  42845. + kfree(addr);
  42846. +}
  42847. +
  42848. +
  42849. +#ifdef DWC_CRYPTOLIB
  42850. +/* dwc_crypto.h */
  42851. +
  42852. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  42853. +{
  42854. + get_random_bytes(buffer, length);
  42855. +}
  42856. +
  42857. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  42858. +{
  42859. + struct crypto_blkcipher *tfm;
  42860. + struct blkcipher_desc desc;
  42861. + struct scatterlist sgd;
  42862. + struct scatterlist sgs;
  42863. +
  42864. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  42865. + if (tfm == NULL) {
  42866. + printk("failed to load transform for aes CBC\n");
  42867. + return -1;
  42868. + }
  42869. +
  42870. + crypto_blkcipher_setkey(tfm, key, keylen);
  42871. + crypto_blkcipher_set_iv(tfm, iv, 16);
  42872. +
  42873. + sg_init_one(&sgd, out, messagelen);
  42874. + sg_init_one(&sgs, message, messagelen);
  42875. +
  42876. + desc.tfm = tfm;
  42877. + desc.flags = 0;
  42878. +
  42879. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  42880. + crypto_free_blkcipher(tfm);
  42881. + DWC_ERROR("AES CBC encryption failed");
  42882. + return -1;
  42883. + }
  42884. +
  42885. + crypto_free_blkcipher(tfm);
  42886. + return 0;
  42887. +}
  42888. +
  42889. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  42890. +{
  42891. + struct crypto_hash *tfm;
  42892. + struct hash_desc desc;
  42893. + struct scatterlist sg;
  42894. +
  42895. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  42896. + if (IS_ERR(tfm)) {
  42897. + DWC_ERROR("Failed to load transform for sha256: %ld\n", PTR_ERR(tfm));
  42898. + return 0;
  42899. + }
  42900. + desc.tfm = tfm;
  42901. + desc.flags = 0;
  42902. +
  42903. + sg_init_one(&sg, message, len);
  42904. + crypto_hash_digest(&desc, &sg, len, out);
  42905. + crypto_free_hash(tfm);
  42906. +
  42907. + return 1;
  42908. +}
  42909. +
  42910. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  42911. + uint8_t *key, uint32_t keylen, uint8_t *out)
  42912. +{
  42913. + struct crypto_hash *tfm;
  42914. + struct hash_desc desc;
  42915. + struct scatterlist sg;
  42916. +
  42917. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  42918. + if (IS_ERR(tfm)) {
  42919. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld\n", PTR_ERR(tfm));
  42920. + return 0;
  42921. + }
  42922. + desc.tfm = tfm;
  42923. + desc.flags = 0;
  42924. +
  42925. + sg_init_one(&sg, message, messagelen);
  42926. + crypto_hash_setkey(tfm, key, keylen);
  42927. + crypto_hash_digest(&desc, &sg, messagelen, out);
  42928. + crypto_free_hash(tfm);
  42929. +
  42930. + return 1;
  42931. +}
  42932. +#endif /* DWC_CRYPTOLIB */
  42933. +
  42934. +
  42935. +/* Byte Ordering Conversions */
  42936. +
  42937. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  42938. +{
  42939. +#ifdef __LITTLE_ENDIAN
  42940. + return *p;
  42941. +#else
  42942. + uint8_t *u_p = (uint8_t *)p;
  42943. +
  42944. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  42945. +#endif
  42946. +}
  42947. +
  42948. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  42949. +{
  42950. +#ifdef __BIG_ENDIAN
  42951. + return *p;
  42952. +#else
  42953. + uint8_t *u_p = (uint8_t *)p;
  42954. +
  42955. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  42956. +#endif
  42957. +}
  42958. +
  42959. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  42960. +{
  42961. +#ifdef __LITTLE_ENDIAN
  42962. + return *p;
  42963. +#else
  42964. + uint8_t *u_p = (uint8_t *)p;
  42965. +
  42966. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  42967. +#endif
  42968. +}
  42969. +
  42970. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  42971. +{
  42972. +#ifdef __BIG_ENDIAN
  42973. + return *p;
  42974. +#else
  42975. + uint8_t *u_p = (uint8_t *)p;
  42976. +
  42977. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  42978. +#endif
  42979. +}
  42980. +
  42981. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  42982. +{
  42983. +#ifdef __LITTLE_ENDIAN
  42984. + return *p;
  42985. +#else
  42986. + uint8_t *u_p = (uint8_t *)p;
  42987. + return (u_p[1] | (u_p[0] << 8));
  42988. +#endif
  42989. +}
  42990. +
  42991. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  42992. +{
  42993. +#ifdef __BIG_ENDIAN
  42994. + return *p;
  42995. +#else
  42996. + uint8_t *u_p = (uint8_t *)p;
  42997. + return (u_p[1] | (u_p[0] << 8));
  42998. +#endif
  42999. +}
  43000. +
  43001. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  43002. +{
  43003. +#ifdef __LITTLE_ENDIAN
  43004. + return *p;
  43005. +#else
  43006. + uint8_t *u_p = (uint8_t *)p;
  43007. + return (u_p[1] | (u_p[0] << 8));
  43008. +#endif
  43009. +}
  43010. +
  43011. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  43012. +{
  43013. +#ifdef __BIG_ENDIAN
  43014. + return *p;
  43015. +#else
  43016. + uint8_t *u_p = (uint8_t *)p;
  43017. + return (u_p[1] | (u_p[0] << 8));
  43018. +#endif
  43019. +}
  43020. +
  43021. +
  43022. +/* Registers */
  43023. +
  43024. +uint32_t DWC_READ_REG32(uint32_t volatile *reg)
  43025. +{
  43026. + return readl(reg);
  43027. +}
  43028. +
  43029. +#if 0
  43030. +uint64_t DWC_READ_REG64(uint64_t volatile *reg)
  43031. +{
  43032. +}
  43033. +#endif
  43034. +
  43035. +void DWC_WRITE_REG32(uint32_t volatile *reg, uint32_t value)
  43036. +{
  43037. + writel(value, reg);
  43038. +}
  43039. +
  43040. +#if 0
  43041. +void DWC_WRITE_REG64(uint64_t volatile *reg, uint64_t value)
  43042. +{
  43043. +}
  43044. +#endif
  43045. +
  43046. +void DWC_MODIFY_REG32(uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask)
  43047. +{
  43048. + unsigned long flags;
  43049. +
  43050. + local_irq_save(flags);
  43051. + local_fiq_disable();
  43052. + writel((readl(reg) & ~clear_mask) | set_mask, reg);
  43053. + local_fiq_enable();
  43054. + local_irq_restore(flags);
  43055. +}
  43056. +
  43057. +#if 0
  43058. +void DWC_MODIFY_REG64(uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask)
  43059. +{
  43060. +}
  43061. +#endif
  43062. +
  43063. +
  43064. +/* Locking */
  43065. +
  43066. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  43067. +{
  43068. + spinlock_t *sl = (spinlock_t *)1;
  43069. +
  43070. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  43071. + sl = DWC_ALLOC(sizeof(*sl));
  43072. + if (!sl) {
  43073. + DWC_ERROR("Cannot allocate memory for spinlock\n");
  43074. + return NULL;
  43075. + }
  43076. +
  43077. + spin_lock_init(sl);
  43078. +#endif
  43079. + return (dwc_spinlock_t *)sl;
  43080. +}
  43081. +
  43082. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  43083. +{
  43084. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  43085. + DWC_FREE(lock);
  43086. +#endif
  43087. +}
  43088. +
  43089. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  43090. +{
  43091. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  43092. + spin_lock((spinlock_t *)lock);
  43093. +#endif
  43094. +}
  43095. +
  43096. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  43097. +{
  43098. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  43099. + spin_unlock((spinlock_t *)lock);
  43100. +#endif
  43101. +}
  43102. +
  43103. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  43104. +{
  43105. + dwc_irqflags_t f;
  43106. +
  43107. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  43108. + spin_lock_irqsave((spinlock_t *)lock, f);
  43109. +#else
  43110. + local_irq_save(f);
  43111. +#endif
  43112. + *flags = f;
  43113. +}
  43114. +
  43115. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  43116. +{
  43117. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  43118. + spin_unlock_irqrestore((spinlock_t *)lock, flags);
  43119. +#else
  43120. + local_irq_restore(flags);
  43121. +#endif
  43122. +}
  43123. +
  43124. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  43125. +{
  43126. + struct mutex *m;
  43127. + dwc_mutex_t *mutex = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mutex));
  43128. +
  43129. + if (!mutex) {
  43130. + DWC_ERROR("Cannot allocate memory for mutex\n");
  43131. + return NULL;
  43132. + }
  43133. +
  43134. + m = (struct mutex *)mutex;
  43135. + mutex_init(m);
  43136. + return mutex;
  43137. +}
  43138. +
  43139. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  43140. +#else
  43141. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  43142. +{
  43143. + mutex_destroy((struct mutex *)mutex);
  43144. + DWC_FREE(mutex);
  43145. +}
  43146. +#endif
  43147. +
  43148. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  43149. +{
  43150. + struct mutex *m = (struct mutex *)mutex;
  43151. + mutex_lock(m);
  43152. +}
  43153. +
  43154. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  43155. +{
  43156. + struct mutex *m = (struct mutex *)mutex;
  43157. + return mutex_trylock(m);
  43158. +}
  43159. +
  43160. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  43161. +{
  43162. + struct mutex *m = (struct mutex *)mutex;
  43163. + mutex_unlock(m);
  43164. +}
  43165. +
  43166. +
  43167. +/* Timing */
  43168. +
  43169. +void DWC_UDELAY(uint32_t usecs)
  43170. +{
  43171. + udelay(usecs);
  43172. +}
  43173. +
  43174. +void DWC_MDELAY(uint32_t msecs)
  43175. +{
  43176. + mdelay(msecs);
  43177. +}
  43178. +
  43179. +void DWC_MSLEEP(uint32_t msecs)
  43180. +{
  43181. + msleep(msecs);
  43182. +}
  43183. +
  43184. +uint32_t DWC_TIME(void)
  43185. +{
  43186. + return jiffies_to_msecs(jiffies);
  43187. +}
  43188. +
  43189. +
  43190. +/* Timers */
  43191. +
  43192. +struct dwc_timer {
  43193. + struct timer_list *t;
  43194. + char *name;
  43195. + dwc_timer_callback_t cb;
  43196. + void *data;
  43197. + uint8_t scheduled;
  43198. + dwc_spinlock_t *lock;
  43199. +};
  43200. +
  43201. +static void timer_callback(unsigned long data)
  43202. +{
  43203. + dwc_timer_t *timer = (dwc_timer_t *)data;
  43204. + dwc_irqflags_t flags;
  43205. +
  43206. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  43207. + timer->scheduled = 0;
  43208. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  43209. + DWC_DEBUGC("Timer %s callback", timer->name);
  43210. + timer->cb(timer->data);
  43211. +}
  43212. +
  43213. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  43214. +{
  43215. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  43216. +
  43217. + if (!t) {
  43218. + DWC_ERROR("Cannot allocate memory for timer");
  43219. + return NULL;
  43220. + }
  43221. +
  43222. + t->t = DWC_ALLOC(sizeof(*t->t));
  43223. + if (!t->t) {
  43224. + DWC_ERROR("Cannot allocate memory for timer->t");
  43225. + goto no_timer;
  43226. + }
  43227. +
  43228. + t->name = DWC_STRDUP(name);
  43229. + if (!t->name) {
  43230. + DWC_ERROR("Cannot allocate memory for timer->name");
  43231. + goto no_name;
  43232. + }
  43233. +
  43234. + t->lock = DWC_SPINLOCK_ALLOC();
  43235. + if (!t->lock) {
  43236. + DWC_ERROR("Cannot allocate memory for lock");
  43237. + goto no_lock;
  43238. + }
  43239. +
  43240. + t->scheduled = 0;
  43241. + t->t->base = &boot_tvec_bases;
  43242. + t->t->expires = jiffies;
  43243. + setup_timer(t->t, timer_callback, (unsigned long)t);
  43244. +
  43245. + t->cb = cb;
  43246. + t->data = data;
  43247. +
  43248. + return t;
  43249. +
  43250. + no_lock:
  43251. + DWC_FREE(t->name);
  43252. + no_name:
  43253. + DWC_FREE(t->t);
  43254. + no_timer:
  43255. + DWC_FREE(t);
  43256. + return NULL;
  43257. +}
  43258. +
  43259. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  43260. +{
  43261. + dwc_irqflags_t flags;
  43262. +
  43263. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  43264. +
  43265. + if (timer->scheduled) {
  43266. + del_timer(timer->t);
  43267. + timer->scheduled = 0;
  43268. + }
  43269. +
  43270. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  43271. + DWC_SPINLOCK_FREE(timer->lock);
  43272. + DWC_FREE(timer->t);
  43273. + DWC_FREE(timer->name);
  43274. + DWC_FREE(timer);
  43275. +}
  43276. +
  43277. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  43278. +{
  43279. + dwc_irqflags_t flags;
  43280. +
  43281. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  43282. +
  43283. + if (!timer->scheduled) {
  43284. + timer->scheduled = 1;
  43285. + DWC_DEBUGC("Scheduling timer %s to expire in +%d msec", timer->name, time);
  43286. + timer->t->expires = jiffies + msecs_to_jiffies(time);
  43287. + add_timer(timer->t);
  43288. + } else {
  43289. + DWC_DEBUGC("Modifying timer %s to expire in +%d msec", timer->name, time);
  43290. + mod_timer(timer->t, jiffies + msecs_to_jiffies(time));
  43291. + }
  43292. +
  43293. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  43294. +}
  43295. +
  43296. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  43297. +{
  43298. + del_timer(timer->t);
  43299. +}
  43300. +
  43301. +
  43302. +/* Wait Queues */
  43303. +
  43304. +struct dwc_waitq {
  43305. + wait_queue_head_t queue;
  43306. + int abort;
  43307. +};
  43308. +
  43309. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  43310. +{
  43311. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  43312. +
  43313. + if (!wq) {
  43314. + DWC_ERROR("Cannot allocate memory for waitqueue\n");
  43315. + return NULL;
  43316. + }
  43317. +
  43318. + init_waitqueue_head(&wq->queue);
  43319. + wq->abort = 0;
  43320. + return wq;
  43321. +}
  43322. +
  43323. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  43324. +{
  43325. + DWC_FREE(wq);
  43326. +}
  43327. +
  43328. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  43329. +{
  43330. + int result = wait_event_interruptible(wq->queue,
  43331. + cond(data) || wq->abort);
  43332. + if (result == -ERESTARTSYS) {
  43333. + wq->abort = 0;
  43334. + return -DWC_E_RESTART;
  43335. + }
  43336. +
  43337. + if (wq->abort == 1) {
  43338. + wq->abort = 0;
  43339. + return -DWC_E_ABORT;
  43340. + }
  43341. +
  43342. + wq->abort = 0;
  43343. +
  43344. + if (result == 0) {
  43345. + return 0;
  43346. + }
  43347. +
  43348. + return -DWC_E_UNKNOWN;
  43349. +}
  43350. +
  43351. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  43352. + void *data, int32_t msecs)
  43353. +{
  43354. + int32_t tmsecs;
  43355. + int result = wait_event_interruptible_timeout(wq->queue,
  43356. + cond(data) || wq->abort,
  43357. + msecs_to_jiffies(msecs));
  43358. + if (result == -ERESTARTSYS) {
  43359. + wq->abort = 0;
  43360. + return -DWC_E_RESTART;
  43361. + }
  43362. +
  43363. + if (wq->abort == 1) {
  43364. + wq->abort = 0;
  43365. + return -DWC_E_ABORT;
  43366. + }
  43367. +
  43368. + wq->abort = 0;
  43369. +
  43370. + if (result > 0) {
  43371. + tmsecs = jiffies_to_msecs(result);
  43372. + if (!tmsecs) {
  43373. + return 1;
  43374. + }
  43375. +
  43376. + return tmsecs;
  43377. + }
  43378. +
  43379. + if (result == 0) {
  43380. + return -DWC_E_TIMEOUT;
  43381. + }
  43382. +
  43383. + return -DWC_E_UNKNOWN;
  43384. +}
  43385. +
  43386. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  43387. +{
  43388. + wq->abort = 0;
  43389. + wake_up_interruptible(&wq->queue);
  43390. +}
  43391. +
  43392. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  43393. +{
  43394. + wq->abort = 1;
  43395. + wake_up_interruptible(&wq->queue);
  43396. +}
  43397. +
  43398. +
  43399. +/* Threading */
  43400. +
  43401. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  43402. +{
  43403. + struct task_struct *thread = kthread_run(func, data, name);
  43404. +
  43405. + if (thread == ERR_PTR(-ENOMEM)) {
  43406. + return NULL;
  43407. + }
  43408. +
  43409. + return (dwc_thread_t *)thread;
  43410. +}
  43411. +
  43412. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  43413. +{
  43414. + return kthread_stop((struct task_struct *)thread);
  43415. +}
  43416. +
  43417. +dwc_bool_t DWC_THREAD_SHOULD_STOP(void)
  43418. +{
  43419. + return kthread_should_stop();
  43420. +}
  43421. +
  43422. +
  43423. +/* tasklets
  43424. + - run in interrupt context (cannot sleep)
  43425. + - each tasklet runs on a single CPU
  43426. + - different tasklets can be running simultaneously on different CPUs
  43427. + */
  43428. +struct dwc_tasklet {
  43429. + struct tasklet_struct t;
  43430. + dwc_tasklet_callback_t cb;
  43431. + void *data;
  43432. +};
  43433. +
  43434. +static void tasklet_callback(unsigned long data)
  43435. +{
  43436. + dwc_tasklet_t *t = (dwc_tasklet_t *)data;
  43437. + t->cb(t->data);
  43438. +}
  43439. +
  43440. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  43441. +{
  43442. + dwc_tasklet_t *t = DWC_ALLOC(sizeof(*t));
  43443. +
  43444. + if (t) {
  43445. + t->cb = cb;
  43446. + t->data = data;
  43447. + tasklet_init(&t->t, tasklet_callback, (unsigned long)t);
  43448. + } else {
  43449. + DWC_ERROR("Cannot allocate memory for tasklet\n");
  43450. + }
  43451. +
  43452. + return t;
  43453. +}
  43454. +
  43455. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  43456. +{
  43457. + DWC_FREE(task);
  43458. +}
  43459. +
  43460. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  43461. +{
  43462. + tasklet_schedule(&task->t);
  43463. +}
  43464. +
  43465. +void DWC_TASK_HI_SCHEDULE(dwc_tasklet_t *task)
  43466. +{
  43467. + tasklet_hi_schedule(&task->t);
  43468. +}
  43469. +
  43470. +
  43471. +/* workqueues
  43472. + - run in process context (can sleep)
  43473. + */
  43474. +typedef struct work_container {
  43475. + dwc_work_callback_t cb;
  43476. + void *data;
  43477. + dwc_workq_t *wq;
  43478. + char *name;
  43479. +
  43480. +#ifdef DEBUG
  43481. + DWC_CIRCLEQ_ENTRY(work_container) entry;
  43482. +#endif
  43483. + struct delayed_work work;
  43484. +} work_container_t;
  43485. +
  43486. +#ifdef DEBUG
  43487. +DWC_CIRCLEQ_HEAD(work_container_queue, work_container);
  43488. +#endif
  43489. +
  43490. +struct dwc_workq {
  43491. + struct workqueue_struct *wq;
  43492. + dwc_spinlock_t *lock;
  43493. + dwc_waitq_t *waitq;
  43494. + int pending;
  43495. +
  43496. +#ifdef DEBUG
  43497. + struct work_container_queue entries;
  43498. +#endif
  43499. +};
  43500. +
  43501. +static void do_work(struct work_struct *work)
  43502. +{
  43503. + dwc_irqflags_t flags;
  43504. + struct delayed_work *dw = container_of(work, struct delayed_work, work);
  43505. + work_container_t *container = container_of(dw, struct work_container, work);
  43506. + dwc_workq_t *wq = container->wq;
  43507. +
  43508. + container->cb(container->data);
  43509. +
  43510. +#ifdef DEBUG
  43511. + DWC_CIRCLEQ_REMOVE(&wq->entries, container, entry);
  43512. +#endif
  43513. + DWC_DEBUGC("Work done: %s, container=%p", container->name, container);
  43514. + if (container->name) {
  43515. + DWC_FREE(container->name);
  43516. + }
  43517. + DWC_FREE(container);
  43518. +
  43519. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  43520. + wq->pending--;
  43521. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  43522. + DWC_WAITQ_TRIGGER(wq->waitq);
  43523. +}
  43524. +
  43525. +static int work_done(void *data)
  43526. +{
  43527. + dwc_workq_t *workq = (dwc_workq_t *)data;
  43528. + return workq->pending == 0;
  43529. +}
  43530. +
  43531. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  43532. +{
  43533. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  43534. +}
  43535. +
  43536. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  43537. +{
  43538. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  43539. +
  43540. + if (!wq) {
  43541. + return NULL;
  43542. + }
  43543. +
  43544. + wq->wq = create_singlethread_workqueue(name);
  43545. + if (!wq->wq) {
  43546. + goto no_wq;
  43547. + }
  43548. +
  43549. + wq->pending = 0;
  43550. +
  43551. + wq->lock = DWC_SPINLOCK_ALLOC();
  43552. + if (!wq->lock) {
  43553. + goto no_lock;
  43554. + }
  43555. +
  43556. + wq->waitq = DWC_WAITQ_ALLOC();
  43557. + if (!wq->waitq) {
  43558. + goto no_waitq;
  43559. + }
  43560. +
  43561. +#ifdef DEBUG
  43562. + DWC_CIRCLEQ_INIT(&wq->entries);
  43563. +#endif
  43564. + return wq;
  43565. +
  43566. + no_waitq:
  43567. + DWC_SPINLOCK_FREE(wq->lock);
  43568. + no_lock:
  43569. + destroy_workqueue(wq->wq);
  43570. + no_wq:
  43571. + DWC_FREE(wq);
  43572. +
  43573. + return NULL;
  43574. +}
  43575. +
  43576. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  43577. +{
  43578. +#ifdef DEBUG
  43579. + if (wq->pending != 0) {
  43580. + struct work_container *wc;
  43581. + DWC_ERROR("Destroying work queue with pending work");
  43582. + DWC_CIRCLEQ_FOREACH(wc, &wq->entries, entry) {
  43583. + DWC_ERROR("Work %s still pending", wc->name);
  43584. + }
  43585. + }
  43586. +#endif
  43587. + destroy_workqueue(wq->wq);
  43588. + DWC_SPINLOCK_FREE(wq->lock);
  43589. + DWC_WAITQ_FREE(wq->waitq);
  43590. + DWC_FREE(wq);
  43591. +}
  43592. +
  43593. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  43594. + char *format, ...)
  43595. +{
  43596. + dwc_irqflags_t flags;
  43597. + work_container_t *container;
  43598. + static char name[128];
  43599. + va_list args;
  43600. +
  43601. + va_start(args, format);
  43602. + DWC_VSNPRINTF(name, 128, format, args);
  43603. + va_end(args);
  43604. +
  43605. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  43606. + wq->pending++;
  43607. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  43608. + DWC_WAITQ_TRIGGER(wq->waitq);
  43609. +
  43610. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  43611. + if (!container) {
  43612. + DWC_ERROR("Cannot allocate memory for container\n");
  43613. + return;
  43614. + }
  43615. +
  43616. + container->name = DWC_STRDUP(name);
  43617. + if (!container->name) {
  43618. + DWC_ERROR("Cannot allocate memory for container->name\n");
  43619. + DWC_FREE(container);
  43620. + return;
  43621. + }
  43622. +
  43623. + container->cb = cb;
  43624. + container->data = data;
  43625. + container->wq = wq;
  43626. + DWC_DEBUGC("Queueing work: %s, container=%p", container->name, container);
  43627. + INIT_WORK(&container->work.work, do_work);
  43628. +
  43629. +#ifdef DEBUG
  43630. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  43631. +#endif
  43632. + queue_work(wq->wq, &container->work.work);
  43633. +}
  43634. +
  43635. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  43636. + void *data, uint32_t time, char *format, ...)
  43637. +{
  43638. + dwc_irqflags_t flags;
  43639. + work_container_t *container;
  43640. + static char name[128];
  43641. + va_list args;
  43642. +
  43643. + va_start(args, format);
  43644. + DWC_VSNPRINTF(name, 128, format, args);
  43645. + va_end(args);
  43646. +
  43647. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  43648. + wq->pending++;
  43649. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  43650. + DWC_WAITQ_TRIGGER(wq->waitq);
  43651. +
  43652. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  43653. + if (!container) {
  43654. + DWC_ERROR("Cannot allocate memory for container\n");
  43655. + return;
  43656. + }
  43657. +
  43658. + container->name = DWC_STRDUP(name);
  43659. + if (!container->name) {
  43660. + DWC_ERROR("Cannot allocate memory for container->name\n");
  43661. + DWC_FREE(container);
  43662. + return;
  43663. + }
  43664. +
  43665. + container->cb = cb;
  43666. + container->data = data;
  43667. + container->wq = wq;
  43668. + DWC_DEBUGC("Queueing work: %s, container=%p", container->name, container);
  43669. + INIT_DELAYED_WORK(&container->work, do_work);
  43670. +
  43671. +#ifdef DEBUG
  43672. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  43673. +#endif
  43674. + queue_delayed_work(wq->wq, &container->work, msecs_to_jiffies(time));
  43675. +}
  43676. +
  43677. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  43678. +{
  43679. + return wq->pending;
  43680. +}
  43681. +
  43682. +
  43683. +#ifdef DWC_LIBMODULE
  43684. +
  43685. +#ifdef DWC_CCLIB
  43686. +/* CC */
  43687. +EXPORT_SYMBOL(dwc_cc_if_alloc);
  43688. +EXPORT_SYMBOL(dwc_cc_if_free);
  43689. +EXPORT_SYMBOL(dwc_cc_clear);
  43690. +EXPORT_SYMBOL(dwc_cc_add);
  43691. +EXPORT_SYMBOL(dwc_cc_remove);
  43692. +EXPORT_SYMBOL(dwc_cc_change);
  43693. +EXPORT_SYMBOL(dwc_cc_data_for_save);
  43694. +EXPORT_SYMBOL(dwc_cc_restore_from_data);
  43695. +EXPORT_SYMBOL(dwc_cc_match_chid);
  43696. +EXPORT_SYMBOL(dwc_cc_match_cdid);
  43697. +EXPORT_SYMBOL(dwc_cc_ck);
  43698. +EXPORT_SYMBOL(dwc_cc_chid);
  43699. +EXPORT_SYMBOL(dwc_cc_cdid);
  43700. +EXPORT_SYMBOL(dwc_cc_name);
  43701. +#endif /* DWC_CCLIB */
  43702. +
  43703. +#ifdef DWC_CRYPTOLIB
  43704. +# ifndef CONFIG_MACH_IPMATE
  43705. +/* Modpow */
  43706. +EXPORT_SYMBOL(dwc_modpow);
  43707. +
  43708. +/* DH */
  43709. +EXPORT_SYMBOL(dwc_dh_modpow);
  43710. +EXPORT_SYMBOL(dwc_dh_derive_keys);
  43711. +EXPORT_SYMBOL(dwc_dh_pk);
  43712. +# endif /* CONFIG_MACH_IPMATE */
  43713. +
  43714. +/* Crypto */
  43715. +EXPORT_SYMBOL(dwc_wusb_aes_encrypt);
  43716. +EXPORT_SYMBOL(dwc_wusb_cmf);
  43717. +EXPORT_SYMBOL(dwc_wusb_prf);
  43718. +EXPORT_SYMBOL(dwc_wusb_fill_ccm_nonce);
  43719. +EXPORT_SYMBOL(dwc_wusb_gen_nonce);
  43720. +EXPORT_SYMBOL(dwc_wusb_gen_key);
  43721. +EXPORT_SYMBOL(dwc_wusb_gen_mic);
  43722. +#endif /* DWC_CRYPTOLIB */
  43723. +
  43724. +/* Notification */
  43725. +#ifdef DWC_NOTIFYLIB
  43726. +EXPORT_SYMBOL(dwc_alloc_notification_manager);
  43727. +EXPORT_SYMBOL(dwc_free_notification_manager);
  43728. +EXPORT_SYMBOL(dwc_register_notifier);
  43729. +EXPORT_SYMBOL(dwc_unregister_notifier);
  43730. +EXPORT_SYMBOL(dwc_add_observer);
  43731. +EXPORT_SYMBOL(dwc_remove_observer);
  43732. +EXPORT_SYMBOL(dwc_notify);
  43733. +#endif
  43734. +
  43735. +/* Memory Debugging Routines */
  43736. +#ifdef DWC_DEBUG_MEMORY
  43737. +EXPORT_SYMBOL(dwc_alloc_debug);
  43738. +EXPORT_SYMBOL(dwc_alloc_atomic_debug);
  43739. +EXPORT_SYMBOL(dwc_free_debug);
  43740. +EXPORT_SYMBOL(dwc_dma_alloc_debug);
  43741. +EXPORT_SYMBOL(dwc_dma_free_debug);
  43742. +#endif
  43743. +
  43744. +EXPORT_SYMBOL(DWC_MEMSET);
  43745. +EXPORT_SYMBOL(DWC_MEMCPY);
  43746. +EXPORT_SYMBOL(DWC_MEMMOVE);
  43747. +EXPORT_SYMBOL(DWC_MEMCMP);
  43748. +EXPORT_SYMBOL(DWC_STRNCMP);
  43749. +EXPORT_SYMBOL(DWC_STRCMP);
  43750. +EXPORT_SYMBOL(DWC_STRLEN);
  43751. +EXPORT_SYMBOL(DWC_STRCPY);
  43752. +EXPORT_SYMBOL(DWC_STRDUP);
  43753. +EXPORT_SYMBOL(DWC_ATOI);
  43754. +EXPORT_SYMBOL(DWC_ATOUI);
  43755. +
  43756. +#ifdef DWC_UTFLIB
  43757. +EXPORT_SYMBOL(DWC_UTF8_TO_UTF16LE);
  43758. +#endif /* DWC_UTFLIB */
  43759. +
  43760. +EXPORT_SYMBOL(DWC_IN_IRQ);
  43761. +EXPORT_SYMBOL(DWC_IN_BH);
  43762. +EXPORT_SYMBOL(DWC_VPRINTF);
  43763. +EXPORT_SYMBOL(DWC_VSNPRINTF);
  43764. +EXPORT_SYMBOL(DWC_PRINTF);
  43765. +EXPORT_SYMBOL(DWC_SPRINTF);
  43766. +EXPORT_SYMBOL(DWC_SNPRINTF);
  43767. +EXPORT_SYMBOL(__DWC_WARN);
  43768. +EXPORT_SYMBOL(__DWC_ERROR);
  43769. +EXPORT_SYMBOL(DWC_EXCEPTION);
  43770. +
  43771. +#ifdef DEBUG
  43772. +EXPORT_SYMBOL(__DWC_DEBUG);
  43773. +#endif
  43774. +
  43775. +EXPORT_SYMBOL(__DWC_DMA_ALLOC);
  43776. +EXPORT_SYMBOL(__DWC_DMA_ALLOC_ATOMIC);
  43777. +EXPORT_SYMBOL(__DWC_DMA_FREE);
  43778. +EXPORT_SYMBOL(__DWC_ALLOC);
  43779. +EXPORT_SYMBOL(__DWC_ALLOC_ATOMIC);
  43780. +EXPORT_SYMBOL(__DWC_FREE);
  43781. +
  43782. +#ifdef DWC_CRYPTOLIB
  43783. +EXPORT_SYMBOL(DWC_RANDOM_BYTES);
  43784. +EXPORT_SYMBOL(DWC_AES_CBC);
  43785. +EXPORT_SYMBOL(DWC_SHA256);
  43786. +EXPORT_SYMBOL(DWC_HMAC_SHA256);
  43787. +#endif
  43788. +
  43789. +EXPORT_SYMBOL(DWC_CPU_TO_LE32);
  43790. +EXPORT_SYMBOL(DWC_CPU_TO_BE32);
  43791. +EXPORT_SYMBOL(DWC_LE32_TO_CPU);
  43792. +EXPORT_SYMBOL(DWC_BE32_TO_CPU);
  43793. +EXPORT_SYMBOL(DWC_CPU_TO_LE16);
  43794. +EXPORT_SYMBOL(DWC_CPU_TO_BE16);
  43795. +EXPORT_SYMBOL(DWC_LE16_TO_CPU);
  43796. +EXPORT_SYMBOL(DWC_BE16_TO_CPU);
  43797. +EXPORT_SYMBOL(DWC_READ_REG32);
  43798. +EXPORT_SYMBOL(DWC_WRITE_REG32);
  43799. +EXPORT_SYMBOL(DWC_MODIFY_REG32);
  43800. +
  43801. +#if 0
  43802. +EXPORT_SYMBOL(DWC_READ_REG64);
  43803. +EXPORT_SYMBOL(DWC_WRITE_REG64);
  43804. +EXPORT_SYMBOL(DWC_MODIFY_REG64);
  43805. +#endif
  43806. +
  43807. +EXPORT_SYMBOL(DWC_SPINLOCK_ALLOC);
  43808. +EXPORT_SYMBOL(DWC_SPINLOCK_FREE);
  43809. +EXPORT_SYMBOL(DWC_SPINLOCK);
  43810. +EXPORT_SYMBOL(DWC_SPINUNLOCK);
  43811. +EXPORT_SYMBOL(DWC_SPINLOCK_IRQSAVE);
  43812. +EXPORT_SYMBOL(DWC_SPINUNLOCK_IRQRESTORE);
  43813. +EXPORT_SYMBOL(DWC_MUTEX_ALLOC);
  43814. +
  43815. +#if (!defined(DWC_LINUX) || !defined(CONFIG_DEBUG_MUTEXES))
  43816. +EXPORT_SYMBOL(DWC_MUTEX_FREE);
  43817. +#endif
  43818. +
  43819. +EXPORT_SYMBOL(DWC_MUTEX_LOCK);
  43820. +EXPORT_SYMBOL(DWC_MUTEX_TRYLOCK);
  43821. +EXPORT_SYMBOL(DWC_MUTEX_UNLOCK);
  43822. +EXPORT_SYMBOL(DWC_UDELAY);
  43823. +EXPORT_SYMBOL(DWC_MDELAY);
  43824. +EXPORT_SYMBOL(DWC_MSLEEP);
  43825. +EXPORT_SYMBOL(DWC_TIME);
  43826. +EXPORT_SYMBOL(DWC_TIMER_ALLOC);
  43827. +EXPORT_SYMBOL(DWC_TIMER_FREE);
  43828. +EXPORT_SYMBOL(DWC_TIMER_SCHEDULE);
  43829. +EXPORT_SYMBOL(DWC_TIMER_CANCEL);
  43830. +EXPORT_SYMBOL(DWC_WAITQ_ALLOC);
  43831. +EXPORT_SYMBOL(DWC_WAITQ_FREE);
  43832. +EXPORT_SYMBOL(DWC_WAITQ_WAIT);
  43833. +EXPORT_SYMBOL(DWC_WAITQ_WAIT_TIMEOUT);
  43834. +EXPORT_SYMBOL(DWC_WAITQ_TRIGGER);
  43835. +EXPORT_SYMBOL(DWC_WAITQ_ABORT);
  43836. +EXPORT_SYMBOL(DWC_THREAD_RUN);
  43837. +EXPORT_SYMBOL(DWC_THREAD_STOP);
  43838. +EXPORT_SYMBOL(DWC_THREAD_SHOULD_STOP);
  43839. +EXPORT_SYMBOL(DWC_TASK_ALLOC);
  43840. +EXPORT_SYMBOL(DWC_TASK_FREE);
  43841. +EXPORT_SYMBOL(DWC_TASK_SCHEDULE);
  43842. +EXPORT_SYMBOL(DWC_WORKQ_WAIT_WORK_DONE);
  43843. +EXPORT_SYMBOL(DWC_WORKQ_ALLOC);
  43844. +EXPORT_SYMBOL(DWC_WORKQ_FREE);
  43845. +EXPORT_SYMBOL(DWC_WORKQ_SCHEDULE);
  43846. +EXPORT_SYMBOL(DWC_WORKQ_SCHEDULE_DELAYED);
  43847. +EXPORT_SYMBOL(DWC_WORKQ_PENDING);
  43848. +
  43849. +static int dwc_common_port_init_module(void)
  43850. +{
  43851. + int result = 0;
  43852. +
  43853. + printk(KERN_DEBUG "Module dwc_common_port init\n" );
  43854. +
  43855. +#ifdef DWC_DEBUG_MEMORY
  43856. + result = dwc_memory_debug_start(NULL);
  43857. + if (result) {
  43858. + printk(KERN_ERR
  43859. + "dwc_memory_debug_start() failed with error %d\n",
  43860. + result);
  43861. + return result;
  43862. + }
  43863. +#endif
  43864. +
  43865. +#ifdef DWC_NOTIFYLIB
  43866. + result = dwc_alloc_notification_manager(NULL, NULL);
  43867. + if (result) {
  43868. + printk(KERN_ERR
  43869. + "dwc_alloc_notification_manager() failed with error %d\n",
  43870. + result);
  43871. + return result;
  43872. + }
  43873. +#endif
  43874. + return result;
  43875. +}
  43876. +
  43877. +static void dwc_common_port_exit_module(void)
  43878. +{
  43879. + printk(KERN_DEBUG "Module dwc_common_port exit\n" );
  43880. +
  43881. +#ifdef DWC_NOTIFYLIB
  43882. + dwc_free_notification_manager();
  43883. +#endif
  43884. +
  43885. +#ifdef DWC_DEBUG_MEMORY
  43886. + dwc_memory_debug_stop();
  43887. +#endif
  43888. +}
  43889. +
  43890. +module_init(dwc_common_port_init_module);
  43891. +module_exit(dwc_common_port_exit_module);
  43892. +
  43893. +MODULE_DESCRIPTION("DWC Common Library - Portable version");
  43894. +MODULE_AUTHOR("Synopsys Inc.");
  43895. +MODULE_LICENSE ("GPL");
  43896. +
  43897. +#endif /* DWC_LIBMODULE */
  43898. diff -Nur linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c
  43899. --- linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c 1970-01-01 01:00:00.000000000 +0100
  43900. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c 2014-04-13 17:33:11.000000000 +0200
  43901. @@ -0,0 +1,1275 @@
  43902. +#include "dwc_os.h"
  43903. +#include "dwc_list.h"
  43904. +
  43905. +#ifdef DWC_CCLIB
  43906. +# include "dwc_cc.h"
  43907. +#endif
  43908. +
  43909. +#ifdef DWC_CRYPTOLIB
  43910. +# include "dwc_modpow.h"
  43911. +# include "dwc_dh.h"
  43912. +# include "dwc_crypto.h"
  43913. +#endif
  43914. +
  43915. +#ifdef DWC_NOTIFYLIB
  43916. +# include "dwc_notifier.h"
  43917. +#endif
  43918. +
  43919. +/* OS-Level Implementations */
  43920. +
  43921. +/* This is the NetBSD 4.0.1 kernel implementation of the DWC platform library. */
  43922. +
  43923. +
  43924. +/* MISC */
  43925. +
  43926. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  43927. +{
  43928. + return memset(dest, byte, size);
  43929. +}
  43930. +
  43931. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  43932. +{
  43933. + return memcpy(dest, src, size);
  43934. +}
  43935. +
  43936. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  43937. +{
  43938. + bcopy(src, dest, size);
  43939. + return dest;
  43940. +}
  43941. +
  43942. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  43943. +{
  43944. + return memcmp(m1, m2, size);
  43945. +}
  43946. +
  43947. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  43948. +{
  43949. + return strncmp(s1, s2, size);
  43950. +}
  43951. +
  43952. +int DWC_STRCMP(void *s1, void *s2)
  43953. +{
  43954. + return strcmp(s1, s2);
  43955. +}
  43956. +
  43957. +int DWC_STRLEN(char const *str)
  43958. +{
  43959. + return strlen(str);
  43960. +}
  43961. +
  43962. +char *DWC_STRCPY(char *to, char const *from)
  43963. +{
  43964. + return strcpy(to, from);
  43965. +}
  43966. +
  43967. +char *DWC_STRDUP(char const *str)
  43968. +{
  43969. + int len = DWC_STRLEN(str) + 1;
  43970. + char *new = DWC_ALLOC_ATOMIC(len);
  43971. +
  43972. + if (!new) {
  43973. + return NULL;
  43974. + }
  43975. +
  43976. + DWC_MEMCPY(new, str, len);
  43977. + return new;
  43978. +}
  43979. +
  43980. +int DWC_ATOI(char *str, int32_t *value)
  43981. +{
  43982. + char *end = NULL;
  43983. +
  43984. + /* NetBSD doesn't have 'strtol' in the kernel, but 'strtoul'
  43985. + * should be equivalent on 2's complement machines
  43986. + */
  43987. + *value = strtoul(str, &end, 0);
  43988. + if (*end == '\0') {
  43989. + return 0;
  43990. + }
  43991. +
  43992. + return -1;
  43993. +}
  43994. +
  43995. +int DWC_ATOUI(char *str, uint32_t *value)
  43996. +{
  43997. + char *end = NULL;
  43998. +
  43999. + *value = strtoul(str, &end, 0);
  44000. + if (*end == '\0') {
  44001. + return 0;
  44002. + }
  44003. +
  44004. + return -1;
  44005. +}
  44006. +
  44007. +
  44008. +#ifdef DWC_UTFLIB
  44009. +/* From usbstring.c */
  44010. +
  44011. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  44012. +{
  44013. + int count = 0;
  44014. + u8 c;
  44015. + u16 uchar;
  44016. +
  44017. + /* this insists on correct encodings, though not minimal ones.
  44018. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  44019. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  44020. + */
  44021. + while (len != 0 && (c = (u8) *s++) != 0) {
  44022. + if (unlikely(c & 0x80)) {
  44023. + // 2-byte sequence:
  44024. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  44025. + if ((c & 0xe0) == 0xc0) {
  44026. + uchar = (c & 0x1f) << 6;
  44027. +
  44028. + c = (u8) *s++;
  44029. + if ((c & 0xc0) != 0xc0)
  44030. + goto fail;
  44031. + c &= 0x3f;
  44032. + uchar |= c;
  44033. +
  44034. + // 3-byte sequence (most CJKV characters):
  44035. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  44036. + } else if ((c & 0xf0) == 0xe0) {
  44037. + uchar = (c & 0x0f) << 12;
  44038. +
  44039. + c = (u8) *s++;
  44040. + if ((c & 0xc0) != 0xc0)
  44041. + goto fail;
  44042. + c &= 0x3f;
  44043. + uchar |= c << 6;
  44044. +
  44045. + c = (u8) *s++;
  44046. + if ((c & 0xc0) != 0xc0)
  44047. + goto fail;
  44048. + c &= 0x3f;
  44049. + uchar |= c;
  44050. +
  44051. + /* no bogus surrogates */
  44052. + if (0xd800 <= uchar && uchar <= 0xdfff)
  44053. + goto fail;
  44054. +
  44055. + // 4-byte sequence (surrogate pairs, currently rare):
  44056. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  44057. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  44058. + // (uuuuu = wwww + 1)
  44059. + // FIXME accept the surrogate code points (only)
  44060. + } else
  44061. + goto fail;
  44062. + } else
  44063. + uchar = c;
  44064. + put_unaligned (cpu_to_le16 (uchar), cp++);
  44065. + count++;
  44066. + len--;
  44067. + }
  44068. + return count;
  44069. +fail:
  44070. + return -1;
  44071. +}
  44072. +
  44073. +#endif /* DWC_UTFLIB */
  44074. +
  44075. +
  44076. +/* dwc_debug.h */
  44077. +
  44078. +dwc_bool_t DWC_IN_IRQ(void)
  44079. +{
  44080. +// return in_irq();
  44081. + return 0;
  44082. +}
  44083. +
  44084. +dwc_bool_t DWC_IN_BH(void)
  44085. +{
  44086. +// return in_softirq();
  44087. + return 0;
  44088. +}
  44089. +
  44090. +void DWC_VPRINTF(char *format, va_list args)
  44091. +{
  44092. + vprintf(format, args);
  44093. +}
  44094. +
  44095. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  44096. +{
  44097. + return vsnprintf(str, size, format, args);
  44098. +}
  44099. +
  44100. +void DWC_PRINTF(char *format, ...)
  44101. +{
  44102. + va_list args;
  44103. +
  44104. + va_start(args, format);
  44105. + DWC_VPRINTF(format, args);
  44106. + va_end(args);
  44107. +}
  44108. +
  44109. +int DWC_SPRINTF(char *buffer, char *format, ...)
  44110. +{
  44111. + int retval;
  44112. + va_list args;
  44113. +
  44114. + va_start(args, format);
  44115. + retval = vsprintf(buffer, format, args);
  44116. + va_end(args);
  44117. + return retval;
  44118. +}
  44119. +
  44120. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  44121. +{
  44122. + int retval;
  44123. + va_list args;
  44124. +
  44125. + va_start(args, format);
  44126. + retval = vsnprintf(buffer, size, format, args);
  44127. + va_end(args);
  44128. + return retval;
  44129. +}
  44130. +
  44131. +void __DWC_WARN(char *format, ...)
  44132. +{
  44133. + va_list args;
  44134. +
  44135. + va_start(args, format);
  44136. + DWC_VPRINTF(format, args);
  44137. + va_end(args);
  44138. +}
  44139. +
  44140. +void __DWC_ERROR(char *format, ...)
  44141. +{
  44142. + va_list args;
  44143. +
  44144. + va_start(args, format);
  44145. + DWC_VPRINTF(format, args);
  44146. + va_end(args);
  44147. +}
  44148. +
  44149. +void DWC_EXCEPTION(char *format, ...)
  44150. +{
  44151. + va_list args;
  44152. +
  44153. + va_start(args, format);
  44154. + DWC_VPRINTF(format, args);
  44155. + va_end(args);
  44156. +// BUG_ON(1); ???
  44157. +}
  44158. +
  44159. +#ifdef DEBUG
  44160. +void __DWC_DEBUG(char *format, ...)
  44161. +{
  44162. + va_list args;
  44163. +
  44164. + va_start(args, format);
  44165. + DWC_VPRINTF(format, args);
  44166. + va_end(args);
  44167. +}
  44168. +#endif
  44169. +
  44170. +
  44171. +/* dwc_mem.h */
  44172. +
  44173. +#if 0
  44174. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  44175. + uint32_t align,
  44176. + uint32_t alloc)
  44177. +{
  44178. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  44179. + size, align, alloc);
  44180. + return (dwc_pool_t *)pool;
  44181. +}
  44182. +
  44183. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  44184. +{
  44185. + dma_pool_destroy((struct dma_pool *)pool);
  44186. +}
  44187. +
  44188. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  44189. +{
  44190. +// return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  44191. + return dma_pool_alloc((struct dma_pool *)pool, M_WAITOK, dma_addr);
  44192. +}
  44193. +
  44194. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  44195. +{
  44196. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  44197. + memset(..);
  44198. +}
  44199. +
  44200. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  44201. +{
  44202. + dma_pool_free(pool, vaddr, daddr);
  44203. +}
  44204. +#endif
  44205. +
  44206. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  44207. +{
  44208. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  44209. + int error;
  44210. +
  44211. + error = bus_dmamem_alloc(dma->dma_tag, size, 1, size, dma->segs,
  44212. + sizeof(dma->segs) / sizeof(dma->segs[0]),
  44213. + &dma->nsegs, BUS_DMA_NOWAIT);
  44214. + if (error) {
  44215. + printf("%s: bus_dmamem_alloc(%ju) failed: %d\n", __func__,
  44216. + (uintmax_t)size, error);
  44217. + goto fail_0;
  44218. + }
  44219. +
  44220. + error = bus_dmamem_map(dma->dma_tag, dma->segs, dma->nsegs, size,
  44221. + (caddr_t *)&dma->dma_vaddr,
  44222. + BUS_DMA_NOWAIT | BUS_DMA_COHERENT);
  44223. + if (error) {
  44224. + printf("%s: bus_dmamem_map failed: %d\n", __func__, error);
  44225. + goto fail_1;
  44226. + }
  44227. +
  44228. + error = bus_dmamap_create(dma->dma_tag, size, 1, size, 0,
  44229. + BUS_DMA_NOWAIT, &dma->dma_map);
  44230. + if (error) {
  44231. + printf("%s: bus_dmamap_create failed: %d\n", __func__, error);
  44232. + goto fail_2;
  44233. + }
  44234. +
  44235. + error = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr,
  44236. + size, NULL, BUS_DMA_NOWAIT);
  44237. + if (error) {
  44238. + printf("%s: bus_dmamap_load failed: %d\n", __func__, error);
  44239. + goto fail_3;
  44240. + }
  44241. +
  44242. + dma->dma_paddr = (bus_addr_t)dma->segs[0].ds_addr;
  44243. + *dma_addr = dma->dma_paddr;
  44244. + return dma->dma_vaddr;
  44245. +
  44246. +fail_3:
  44247. + bus_dmamap_destroy(dma->dma_tag, dma->dma_map);
  44248. +fail_2:
  44249. + bus_dmamem_unmap(dma->dma_tag, dma->dma_vaddr, size);
  44250. +fail_1:
  44251. + bus_dmamem_free(dma->dma_tag, dma->segs, dma->nsegs);
  44252. +fail_0:
  44253. + dma->dma_map = NULL;
  44254. + dma->dma_vaddr = NULL;
  44255. + dma->nsegs = 0;
  44256. +
  44257. + return NULL;
  44258. +}
  44259. +
  44260. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  44261. +{
  44262. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  44263. +
  44264. + if (dma->dma_map != NULL) {
  44265. + bus_dmamap_sync(dma->dma_tag, dma->dma_map, 0, size,
  44266. + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
  44267. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  44268. + bus_dmamap_destroy(dma->dma_tag, dma->dma_map);
  44269. + bus_dmamem_unmap(dma->dma_tag, dma->dma_vaddr, size);
  44270. + bus_dmamem_free(dma->dma_tag, dma->segs, dma->nsegs);
  44271. + dma->dma_paddr = 0;
  44272. + dma->dma_map = NULL;
  44273. + dma->dma_vaddr = NULL;
  44274. + dma->nsegs = 0;
  44275. + }
  44276. +}
  44277. +
  44278. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  44279. +{
  44280. + return malloc(size, M_DEVBUF, M_WAITOK | M_ZERO);
  44281. +}
  44282. +
  44283. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  44284. +{
  44285. + return malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO);
  44286. +}
  44287. +
  44288. +void __DWC_FREE(void *mem_ctx, void *addr)
  44289. +{
  44290. + free(addr, M_DEVBUF);
  44291. +}
  44292. +
  44293. +
  44294. +#ifdef DWC_CRYPTOLIB
  44295. +/* dwc_crypto.h */
  44296. +
  44297. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  44298. +{
  44299. + get_random_bytes(buffer, length);
  44300. +}
  44301. +
  44302. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  44303. +{
  44304. + struct crypto_blkcipher *tfm;
  44305. + struct blkcipher_desc desc;
  44306. + struct scatterlist sgd;
  44307. + struct scatterlist sgs;
  44308. +
  44309. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  44310. + if (tfm == NULL) {
  44311. + printk("failed to load transform for aes CBC\n");
  44312. + return -1;
  44313. + }
  44314. +
  44315. + crypto_blkcipher_setkey(tfm, key, keylen);
  44316. + crypto_blkcipher_set_iv(tfm, iv, 16);
  44317. +
  44318. + sg_init_one(&sgd, out, messagelen);
  44319. + sg_init_one(&sgs, message, messagelen);
  44320. +
  44321. + desc.tfm = tfm;
  44322. + desc.flags = 0;
  44323. +
  44324. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  44325. + crypto_free_blkcipher(tfm);
  44326. + DWC_ERROR("AES CBC encryption failed");
  44327. + return -1;
  44328. + }
  44329. +
  44330. + crypto_free_blkcipher(tfm);
  44331. + return 0;
  44332. +}
  44333. +
  44334. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  44335. +{
  44336. + struct crypto_hash *tfm;
  44337. + struct hash_desc desc;
  44338. + struct scatterlist sg;
  44339. +
  44340. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  44341. + if (IS_ERR(tfm)) {
  44342. + DWC_ERROR("Failed to load transform for sha256: %ld", PTR_ERR(tfm));
  44343. + return 0;
  44344. + }
  44345. + desc.tfm = tfm;
  44346. + desc.flags = 0;
  44347. +
  44348. + sg_init_one(&sg, message, len);
  44349. + crypto_hash_digest(&desc, &sg, len, out);
  44350. + crypto_free_hash(tfm);
  44351. +
  44352. + return 1;
  44353. +}
  44354. +
  44355. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  44356. + uint8_t *key, uint32_t keylen, uint8_t *out)
  44357. +{
  44358. + struct crypto_hash *tfm;
  44359. + struct hash_desc desc;
  44360. + struct scatterlist sg;
  44361. +
  44362. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  44363. + if (IS_ERR(tfm)) {
  44364. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld", PTR_ERR(tfm));
  44365. + return 0;
  44366. + }
  44367. + desc.tfm = tfm;
  44368. + desc.flags = 0;
  44369. +
  44370. + sg_init_one(&sg, message, messagelen);
  44371. + crypto_hash_setkey(tfm, key, keylen);
  44372. + crypto_hash_digest(&desc, &sg, messagelen, out);
  44373. + crypto_free_hash(tfm);
  44374. +
  44375. + return 1;
  44376. +}
  44377. +
  44378. +#endif /* DWC_CRYPTOLIB */
  44379. +
  44380. +
  44381. +/* Byte Ordering Conversions */
  44382. +
  44383. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  44384. +{
  44385. +#ifdef __LITTLE_ENDIAN
  44386. + return *p;
  44387. +#else
  44388. + uint8_t *u_p = (uint8_t *)p;
  44389. +
  44390. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  44391. +#endif
  44392. +}
  44393. +
  44394. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  44395. +{
  44396. +#ifdef __BIG_ENDIAN
  44397. + return *p;
  44398. +#else
  44399. + uint8_t *u_p = (uint8_t *)p;
  44400. +
  44401. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  44402. +#endif
  44403. +}
  44404. +
  44405. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  44406. +{
  44407. +#ifdef __LITTLE_ENDIAN
  44408. + return *p;
  44409. +#else
  44410. + uint8_t *u_p = (uint8_t *)p;
  44411. +
  44412. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  44413. +#endif
  44414. +}
  44415. +
  44416. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  44417. +{
  44418. +#ifdef __BIG_ENDIAN
  44419. + return *p;
  44420. +#else
  44421. + uint8_t *u_p = (uint8_t *)p;
  44422. +
  44423. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  44424. +#endif
  44425. +}
  44426. +
  44427. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  44428. +{
  44429. +#ifdef __LITTLE_ENDIAN
  44430. + return *p;
  44431. +#else
  44432. + uint8_t *u_p = (uint8_t *)p;
  44433. + return (u_p[1] | (u_p[0] << 8));
  44434. +#endif
  44435. +}
  44436. +
  44437. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  44438. +{
  44439. +#ifdef __BIG_ENDIAN
  44440. + return *p;
  44441. +#else
  44442. + uint8_t *u_p = (uint8_t *)p;
  44443. + return (u_p[1] | (u_p[0] << 8));
  44444. +#endif
  44445. +}
  44446. +
  44447. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  44448. +{
  44449. +#ifdef __LITTLE_ENDIAN
  44450. + return *p;
  44451. +#else
  44452. + uint8_t *u_p = (uint8_t *)p;
  44453. + return (u_p[1] | (u_p[0] << 8));
  44454. +#endif
  44455. +}
  44456. +
  44457. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  44458. +{
  44459. +#ifdef __BIG_ENDIAN
  44460. + return *p;
  44461. +#else
  44462. + uint8_t *u_p = (uint8_t *)p;
  44463. + return (u_p[1] | (u_p[0] << 8));
  44464. +#endif
  44465. +}
  44466. +
  44467. +
  44468. +/* Registers */
  44469. +
  44470. +uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg)
  44471. +{
  44472. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  44473. + bus_size_t ior = (bus_size_t)reg;
  44474. +
  44475. + return bus_space_read_4(io->iot, io->ioh, ior);
  44476. +}
  44477. +
  44478. +#if 0
  44479. +uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg)
  44480. +{
  44481. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  44482. + bus_size_t ior = (bus_size_t)reg;
  44483. +
  44484. + return bus_space_read_8(io->iot, io->ioh, ior);
  44485. +}
  44486. +#endif
  44487. +
  44488. +void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value)
  44489. +{
  44490. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  44491. + bus_size_t ior = (bus_size_t)reg;
  44492. +
  44493. + bus_space_write_4(io->iot, io->ioh, ior, value);
  44494. +}
  44495. +
  44496. +#if 0
  44497. +void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value)
  44498. +{
  44499. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  44500. + bus_size_t ior = (bus_size_t)reg;
  44501. +
  44502. + bus_space_write_8(io->iot, io->ioh, ior, value);
  44503. +}
  44504. +#endif
  44505. +
  44506. +void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask,
  44507. + uint32_t set_mask)
  44508. +{
  44509. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  44510. + bus_size_t ior = (bus_size_t)reg;
  44511. +
  44512. + bus_space_write_4(io->iot, io->ioh, ior,
  44513. + (bus_space_read_4(io->iot, io->ioh, ior) &
  44514. + ~clear_mask) | set_mask);
  44515. +}
  44516. +
  44517. +#if 0
  44518. +void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask,
  44519. + uint64_t set_mask)
  44520. +{
  44521. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  44522. + bus_size_t ior = (bus_size_t)reg;
  44523. +
  44524. + bus_space_write_8(io->iot, io->ioh, ior,
  44525. + (bus_space_read_8(io->iot, io->ioh, ior) &
  44526. + ~clear_mask) | set_mask);
  44527. +}
  44528. +#endif
  44529. +
  44530. +
  44531. +/* Locking */
  44532. +
  44533. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  44534. +{
  44535. + struct simplelock *sl = DWC_ALLOC(sizeof(*sl));
  44536. +
  44537. + if (!sl) {
  44538. + DWC_ERROR("Cannot allocate memory for spinlock");
  44539. + return NULL;
  44540. + }
  44541. +
  44542. + simple_lock_init(sl);
  44543. + return (dwc_spinlock_t *)sl;
  44544. +}
  44545. +
  44546. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  44547. +{
  44548. + struct simplelock *sl = (struct simplelock *)lock;
  44549. +
  44550. + DWC_FREE(sl);
  44551. +}
  44552. +
  44553. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  44554. +{
  44555. + simple_lock((struct simplelock *)lock);
  44556. +}
  44557. +
  44558. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  44559. +{
  44560. + simple_unlock((struct simplelock *)lock);
  44561. +}
  44562. +
  44563. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  44564. +{
  44565. + simple_lock((struct simplelock *)lock);
  44566. + *flags = splbio();
  44567. +}
  44568. +
  44569. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  44570. +{
  44571. + splx(flags);
  44572. + simple_unlock((struct simplelock *)lock);
  44573. +}
  44574. +
  44575. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  44576. +{
  44577. + dwc_mutex_t *mutex = DWC_ALLOC(sizeof(struct lock));
  44578. +
  44579. + if (!mutex) {
  44580. + DWC_ERROR("Cannot allocate memory for mutex");
  44581. + return NULL;
  44582. + }
  44583. +
  44584. + lockinit((struct lock *)mutex, 0, "dw3mtx", 0, 0);
  44585. + return mutex;
  44586. +}
  44587. +
  44588. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  44589. +#else
  44590. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  44591. +{
  44592. + DWC_FREE(mutex);
  44593. +}
  44594. +#endif
  44595. +
  44596. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  44597. +{
  44598. + lockmgr((struct lock *)mutex, LK_EXCLUSIVE, NULL);
  44599. +}
  44600. +
  44601. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  44602. +{
  44603. + int status;
  44604. +
  44605. + status = lockmgr((struct lock *)mutex, LK_EXCLUSIVE | LK_NOWAIT, NULL);
  44606. + return status == 0;
  44607. +}
  44608. +
  44609. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  44610. +{
  44611. + lockmgr((struct lock *)mutex, LK_RELEASE, NULL);
  44612. +}
  44613. +
  44614. +
  44615. +/* Timing */
  44616. +
  44617. +void DWC_UDELAY(uint32_t usecs)
  44618. +{
  44619. + DELAY(usecs);
  44620. +}
  44621. +
  44622. +void DWC_MDELAY(uint32_t msecs)
  44623. +{
  44624. + do {
  44625. + DELAY(1000);
  44626. + } while (--msecs);
  44627. +}
  44628. +
  44629. +void DWC_MSLEEP(uint32_t msecs)
  44630. +{
  44631. + struct timeval tv;
  44632. +
  44633. + tv.tv_sec = msecs / 1000;
  44634. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  44635. + tsleep(&tv, 0, "dw3slp", tvtohz(&tv));
  44636. +}
  44637. +
  44638. +uint32_t DWC_TIME(void)
  44639. +{
  44640. + struct timeval tv;
  44641. +
  44642. + microuptime(&tv); // or getmicrouptime? (less precise, but faster)
  44643. + return tv.tv_sec * 1000 + tv.tv_usec / 1000;
  44644. +}
  44645. +
  44646. +
  44647. +/* Timers */
  44648. +
  44649. +struct dwc_timer {
  44650. + struct callout t;
  44651. + char *name;
  44652. + dwc_spinlock_t *lock;
  44653. + dwc_timer_callback_t cb;
  44654. + void *data;
  44655. +};
  44656. +
  44657. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  44658. +{
  44659. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  44660. +
  44661. + if (!t) {
  44662. + DWC_ERROR("Cannot allocate memory for timer");
  44663. + return NULL;
  44664. + }
  44665. +
  44666. + callout_init(&t->t);
  44667. +
  44668. + t->name = DWC_STRDUP(name);
  44669. + if (!t->name) {
  44670. + DWC_ERROR("Cannot allocate memory for timer->name");
  44671. + goto no_name;
  44672. + }
  44673. +
  44674. + t->lock = DWC_SPINLOCK_ALLOC();
  44675. + if (!t->lock) {
  44676. + DWC_ERROR("Cannot allocate memory for timer->lock");
  44677. + goto no_lock;
  44678. + }
  44679. +
  44680. + t->cb = cb;
  44681. + t->data = data;
  44682. +
  44683. + return t;
  44684. +
  44685. + no_lock:
  44686. + DWC_FREE(t->name);
  44687. + no_name:
  44688. + DWC_FREE(t);
  44689. +
  44690. + return NULL;
  44691. +}
  44692. +
  44693. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  44694. +{
  44695. + callout_stop(&timer->t);
  44696. + DWC_SPINLOCK_FREE(timer->lock);
  44697. + DWC_FREE(timer->name);
  44698. + DWC_FREE(timer);
  44699. +}
  44700. +
  44701. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  44702. +{
  44703. + struct timeval tv;
  44704. +
  44705. + tv.tv_sec = time / 1000;
  44706. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  44707. + callout_reset(&timer->t, tvtohz(&tv), timer->cb, timer->data);
  44708. +}
  44709. +
  44710. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  44711. +{
  44712. + callout_stop(&timer->t);
  44713. +}
  44714. +
  44715. +
  44716. +/* Wait Queues */
  44717. +
  44718. +struct dwc_waitq {
  44719. + struct simplelock lock;
  44720. + int abort;
  44721. +};
  44722. +
  44723. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  44724. +{
  44725. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  44726. +
  44727. + if (!wq) {
  44728. + DWC_ERROR("Cannot allocate memory for waitqueue");
  44729. + return NULL;
  44730. + }
  44731. +
  44732. + simple_lock_init(&wq->lock);
  44733. + wq->abort = 0;
  44734. +
  44735. + return wq;
  44736. +}
  44737. +
  44738. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  44739. +{
  44740. + DWC_FREE(wq);
  44741. +}
  44742. +
  44743. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  44744. +{
  44745. + int ipl;
  44746. + int result = 0;
  44747. +
  44748. + simple_lock(&wq->lock);
  44749. + ipl = splbio();
  44750. +
  44751. + /* Skip the sleep if already aborted or triggered */
  44752. + if (!wq->abort && !cond(data)) {
  44753. + splx(ipl);
  44754. + result = ltsleep(wq, PCATCH, "dw3wat", 0, &wq->lock); // infinite timeout
  44755. + ipl = splbio();
  44756. + }
  44757. +
  44758. + if (result == 0) { // awoken
  44759. + if (wq->abort) {
  44760. + wq->abort = 0;
  44761. + result = -DWC_E_ABORT;
  44762. + } else {
  44763. + result = 0;
  44764. + }
  44765. +
  44766. + splx(ipl);
  44767. + simple_unlock(&wq->lock);
  44768. + } else {
  44769. + wq->abort = 0;
  44770. + splx(ipl);
  44771. + simple_unlock(&wq->lock);
  44772. +
  44773. + if (result == ERESTART) { // signaled - restart
  44774. + result = -DWC_E_RESTART;
  44775. + } else { // signaled - must be EINTR
  44776. + result = -DWC_E_ABORT;
  44777. + }
  44778. + }
  44779. +
  44780. + return result;
  44781. +}
  44782. +
  44783. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  44784. + void *data, int32_t msecs)
  44785. +{
  44786. + struct timeval tv, tv1, tv2;
  44787. + int ipl;
  44788. + int result = 0;
  44789. +
  44790. + tv.tv_sec = msecs / 1000;
  44791. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  44792. +
  44793. + simple_lock(&wq->lock);
  44794. + ipl = splbio();
  44795. +
  44796. + /* Skip the sleep if already aborted or triggered */
  44797. + if (!wq->abort && !cond(data)) {
  44798. + splx(ipl);
  44799. + getmicrouptime(&tv1);
  44800. + result = ltsleep(wq, PCATCH, "dw3wto", tvtohz(&tv), &wq->lock);
  44801. + getmicrouptime(&tv2);
  44802. + ipl = splbio();
  44803. + }
  44804. +
  44805. + if (result == 0) { // awoken
  44806. + if (wq->abort) {
  44807. + wq->abort = 0;
  44808. + splx(ipl);
  44809. + simple_unlock(&wq->lock);
  44810. + result = -DWC_E_ABORT;
  44811. + } else {
  44812. + splx(ipl);
  44813. + simple_unlock(&wq->lock);
  44814. +
  44815. + tv2.tv_usec -= tv1.tv_usec;
  44816. + if (tv2.tv_usec < 0) {
  44817. + tv2.tv_usec += 1000000;
  44818. + tv2.tv_sec--;
  44819. + }
  44820. +
  44821. + tv2.tv_sec -= tv1.tv_sec;
  44822. + result = tv2.tv_sec * 1000 + tv2.tv_usec / 1000;
  44823. + result = msecs - result;
  44824. + if (result <= 0)
  44825. + result = 1;
  44826. + }
  44827. + } else {
  44828. + wq->abort = 0;
  44829. + splx(ipl);
  44830. + simple_unlock(&wq->lock);
  44831. +
  44832. + if (result == ERESTART) { // signaled - restart
  44833. + result = -DWC_E_RESTART;
  44834. +
  44835. + } else if (result == EINTR) { // signaled - interrupt
  44836. + result = -DWC_E_ABORT;
  44837. +
  44838. + } else { // timed out
  44839. + result = -DWC_E_TIMEOUT;
  44840. + }
  44841. + }
  44842. +
  44843. + return result;
  44844. +}
  44845. +
  44846. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  44847. +{
  44848. + wakeup(wq);
  44849. +}
  44850. +
  44851. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  44852. +{
  44853. + int ipl;
  44854. +
  44855. + simple_lock(&wq->lock);
  44856. + ipl = splbio();
  44857. + wq->abort = 1;
  44858. + wakeup(wq);
  44859. + splx(ipl);
  44860. + simple_unlock(&wq->lock);
  44861. +}
  44862. +
  44863. +
  44864. +/* Threading */
  44865. +
  44866. +struct dwc_thread {
  44867. + struct proc *proc;
  44868. + int abort;
  44869. +};
  44870. +
  44871. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  44872. +{
  44873. + int retval;
  44874. + dwc_thread_t *thread = DWC_ALLOC(sizeof(*thread));
  44875. +
  44876. + if (!thread) {
  44877. + return NULL;
  44878. + }
  44879. +
  44880. + thread->abort = 0;
  44881. + retval = kthread_create1((void (*)(void *))func, data, &thread->proc,
  44882. + "%s", name);
  44883. + if (retval) {
  44884. + DWC_FREE(thread);
  44885. + return NULL;
  44886. + }
  44887. +
  44888. + return thread;
  44889. +}
  44890. +
  44891. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  44892. +{
  44893. + int retval;
  44894. +
  44895. + thread->abort = 1;
  44896. + retval = tsleep(&thread->abort, 0, "dw3stp", 60 * hz);
  44897. +
  44898. + if (retval == 0) {
  44899. + /* DWC_THREAD_EXIT() will free the thread struct */
  44900. + return 0;
  44901. + }
  44902. +
  44903. + /* NOTE: We leak the thread struct if thread doesn't die */
  44904. +
  44905. + if (retval == EWOULDBLOCK) {
  44906. + return -DWC_E_TIMEOUT;
  44907. + }
  44908. +
  44909. + return -DWC_E_UNKNOWN;
  44910. +}
  44911. +
  44912. +dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread)
  44913. +{
  44914. + return thread->abort;
  44915. +}
  44916. +
  44917. +void DWC_THREAD_EXIT(dwc_thread_t *thread)
  44918. +{
  44919. + wakeup(&thread->abort);
  44920. + DWC_FREE(thread);
  44921. + kthread_exit(0);
  44922. +}
  44923. +
  44924. +/* tasklets
  44925. + - Runs in interrupt context (cannot sleep)
  44926. + - Each tasklet runs on a single CPU
  44927. + - Different tasklets can be running simultaneously on different CPUs
  44928. + [ On NetBSD there is no corresponding mechanism, drivers don't have bottom-
  44929. + halves. So we just call the callback directly from DWC_TASK_SCHEDULE() ]
  44930. + */
  44931. +struct dwc_tasklet {
  44932. + dwc_tasklet_callback_t cb;
  44933. + void *data;
  44934. +};
  44935. +
  44936. +static void tasklet_callback(void *data)
  44937. +{
  44938. + dwc_tasklet_t *task = (dwc_tasklet_t *)data;
  44939. +
  44940. + task->cb(task->data);
  44941. +}
  44942. +
  44943. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  44944. +{
  44945. + dwc_tasklet_t *task = DWC_ALLOC(sizeof(*task));
  44946. +
  44947. + if (task) {
  44948. + task->cb = cb;
  44949. + task->data = data;
  44950. + } else {
  44951. + DWC_ERROR("Cannot allocate memory for tasklet");
  44952. + }
  44953. +
  44954. + return task;
  44955. +}
  44956. +
  44957. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  44958. +{
  44959. + DWC_FREE(task);
  44960. +}
  44961. +
  44962. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  44963. +{
  44964. + tasklet_callback(task);
  44965. +}
  44966. +
  44967. +
  44968. +/* workqueues
  44969. + - Runs in process context (can sleep)
  44970. + */
  44971. +typedef struct work_container {
  44972. + dwc_work_callback_t cb;
  44973. + void *data;
  44974. + dwc_workq_t *wq;
  44975. + char *name;
  44976. + int hz;
  44977. + struct work task;
  44978. +} work_container_t;
  44979. +
  44980. +struct dwc_workq {
  44981. + struct workqueue *taskq;
  44982. + dwc_spinlock_t *lock;
  44983. + dwc_waitq_t *waitq;
  44984. + int pending;
  44985. + struct work_container *container;
  44986. +};
  44987. +
  44988. +static void do_work(struct work *task, void *data)
  44989. +{
  44990. + dwc_workq_t *wq = (dwc_workq_t *)data;
  44991. + work_container_t *container = wq->container;
  44992. + dwc_irqflags_t flags;
  44993. +
  44994. + if (container->hz) {
  44995. + tsleep(container, 0, "dw3wrk", container->hz);
  44996. + }
  44997. +
  44998. + container->cb(container->data);
  44999. + DWC_DEBUG("Work done: %s, container=%p", container->name, container);
  45000. +
  45001. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  45002. + if (container->name)
  45003. + DWC_FREE(container->name);
  45004. + DWC_FREE(container);
  45005. + wq->pending--;
  45006. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  45007. + DWC_WAITQ_TRIGGER(wq->waitq);
  45008. +}
  45009. +
  45010. +static int work_done(void *data)
  45011. +{
  45012. + dwc_workq_t *workq = (dwc_workq_t *)data;
  45013. +
  45014. + return workq->pending == 0;
  45015. +}
  45016. +
  45017. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  45018. +{
  45019. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  45020. +}
  45021. +
  45022. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  45023. +{
  45024. + int result;
  45025. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  45026. +
  45027. + if (!wq) {
  45028. + DWC_ERROR("Cannot allocate memory for workqueue");
  45029. + return NULL;
  45030. + }
  45031. +
  45032. + result = workqueue_create(&wq->taskq, name, do_work, wq, 0 /*PWAIT*/,
  45033. + IPL_BIO, 0);
  45034. + if (result) {
  45035. + DWC_ERROR("Cannot create workqueue");
  45036. + goto no_taskq;
  45037. + }
  45038. +
  45039. + wq->pending = 0;
  45040. +
  45041. + wq->lock = DWC_SPINLOCK_ALLOC();
  45042. + if (!wq->lock) {
  45043. + DWC_ERROR("Cannot allocate memory for spinlock");
  45044. + goto no_lock;
  45045. + }
  45046. +
  45047. + wq->waitq = DWC_WAITQ_ALLOC();
  45048. + if (!wq->waitq) {
  45049. + DWC_ERROR("Cannot allocate memory for waitqueue");
  45050. + goto no_waitq;
  45051. + }
  45052. +
  45053. + return wq;
  45054. +
  45055. + no_waitq:
  45056. + DWC_SPINLOCK_FREE(wq->lock);
  45057. + no_lock:
  45058. + workqueue_destroy(wq->taskq);
  45059. + no_taskq:
  45060. + DWC_FREE(wq);
  45061. +
  45062. + return NULL;
  45063. +}
  45064. +
  45065. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  45066. +{
  45067. +#ifdef DEBUG
  45068. + dwc_irqflags_t flags;
  45069. +
  45070. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  45071. +
  45072. + if (wq->pending != 0) {
  45073. + struct work_container *container = wq->container;
  45074. +
  45075. + DWC_ERROR("Destroying work queue with pending work");
  45076. +
  45077. + if (container && container->name) {
  45078. + DWC_ERROR("Work %s still pending", container->name);
  45079. + }
  45080. + }
  45081. +
  45082. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  45083. +#endif
  45084. + DWC_WAITQ_FREE(wq->waitq);
  45085. + DWC_SPINLOCK_FREE(wq->lock);
  45086. + workqueue_destroy(wq->taskq);
  45087. + DWC_FREE(wq);
  45088. +}
  45089. +
  45090. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  45091. + char *format, ...)
  45092. +{
  45093. + dwc_irqflags_t flags;
  45094. + work_container_t *container;
  45095. + static char name[128];
  45096. + va_list args;
  45097. +
  45098. + va_start(args, format);
  45099. + DWC_VSNPRINTF(name, 128, format, args);
  45100. + va_end(args);
  45101. +
  45102. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  45103. + wq->pending++;
  45104. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  45105. + DWC_WAITQ_TRIGGER(wq->waitq);
  45106. +
  45107. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  45108. + if (!container) {
  45109. + DWC_ERROR("Cannot allocate memory for container");
  45110. + return;
  45111. + }
  45112. +
  45113. + container->name = DWC_STRDUP(name);
  45114. + if (!container->name) {
  45115. + DWC_ERROR("Cannot allocate memory for container->name");
  45116. + DWC_FREE(container);
  45117. + return;
  45118. + }
  45119. +
  45120. + container->cb = cb;
  45121. + container->data = data;
  45122. + container->wq = wq;
  45123. + container->hz = 0;
  45124. + wq->container = container;
  45125. +
  45126. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  45127. + workqueue_enqueue(wq->taskq, &container->task);
  45128. +}
  45129. +
  45130. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  45131. + void *data, uint32_t time, char *format, ...)
  45132. +{
  45133. + dwc_irqflags_t flags;
  45134. + work_container_t *container;
  45135. + static char name[128];
  45136. + struct timeval tv;
  45137. + va_list args;
  45138. +
  45139. + va_start(args, format);
  45140. + DWC_VSNPRINTF(name, 128, format, args);
  45141. + va_end(args);
  45142. +
  45143. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  45144. + wq->pending++;
  45145. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  45146. + DWC_WAITQ_TRIGGER(wq->waitq);
  45147. +
  45148. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  45149. + if (!container) {
  45150. + DWC_ERROR("Cannot allocate memory for container");
  45151. + return;
  45152. + }
  45153. +
  45154. + container->name = DWC_STRDUP(name);
  45155. + if (!container->name) {
  45156. + DWC_ERROR("Cannot allocate memory for container->name");
  45157. + DWC_FREE(container);
  45158. + return;
  45159. + }
  45160. +
  45161. + container->cb = cb;
  45162. + container->data = data;
  45163. + container->wq = wq;
  45164. + tv.tv_sec = time / 1000;
  45165. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  45166. + container->hz = tvtohz(&tv);
  45167. + wq->container = container;
  45168. +
  45169. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  45170. + workqueue_enqueue(wq->taskq, &container->task);
  45171. +}
  45172. +
  45173. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  45174. +{
  45175. + return wq->pending;
  45176. +}
  45177. diff -Nur linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_crypto.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_crypto.c
  45178. --- linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_crypto.c 1970-01-01 01:00:00.000000000 +0100
  45179. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_crypto.c 2014-04-13 17:33:11.000000000 +0200
  45180. @@ -0,0 +1,308 @@
  45181. +/* =========================================================================
  45182. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_crypto.c $
  45183. + * $Revision: #5 $
  45184. + * $Date: 2010/09/28 $
  45185. + * $Change: 1596182 $
  45186. + *
  45187. + * Synopsys Portability Library Software and documentation
  45188. + * (hereinafter, "Software") is an Unsupported proprietary work of
  45189. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  45190. + * between Synopsys and you.
  45191. + *
  45192. + * The Software IS NOT an item of Licensed Software or Licensed Product
  45193. + * under any End User Software License Agreement or Agreement for
  45194. + * Licensed Product with Synopsys or any supplement thereto. You are
  45195. + * permitted to use and redistribute this Software in source and binary
  45196. + * forms, with or without modification, provided that redistributions
  45197. + * of source code must retain this notice. You may not view, use,
  45198. + * disclose, copy or distribute this file or any information contained
  45199. + * herein except pursuant to this license grant from Synopsys. If you
  45200. + * do not agree with this notice, including the disclaimer below, then
  45201. + * you are not authorized to use the Software.
  45202. + *
  45203. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  45204. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  45205. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  45206. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  45207. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  45208. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  45209. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  45210. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  45211. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  45212. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  45213. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  45214. + * DAMAGE.
  45215. + * ========================================================================= */
  45216. +
  45217. +/** @file
  45218. + * This file contains the WUSB cryptographic routines.
  45219. + */
  45220. +
  45221. +#ifdef DWC_CRYPTOLIB
  45222. +
  45223. +#include "dwc_crypto.h"
  45224. +#include "usb.h"
  45225. +
  45226. +#ifdef DEBUG
  45227. +static inline void dump_bytes(char *name, uint8_t *bytes, int len)
  45228. +{
  45229. + int i;
  45230. + DWC_PRINTF("%s: ", name);
  45231. + for (i=0; i<len; i++) {
  45232. + DWC_PRINTF("%02x ", bytes[i]);
  45233. + }
  45234. + DWC_PRINTF("\n");
  45235. +}
  45236. +#else
  45237. +#define dump_bytes(x...)
  45238. +#endif
  45239. +
  45240. +/* Display a block */
  45241. +void show_block(const u8 *blk, const char *prefix, const char *suffix, int a)
  45242. +{
  45243. +#ifdef DWC_DEBUG_CRYPTO
  45244. + int i, blksize = 16;
  45245. +
  45246. + DWC_DEBUG("%s", prefix);
  45247. +
  45248. + if (suffix == NULL) {
  45249. + suffix = "\n";
  45250. + blksize = a;
  45251. + }
  45252. +
  45253. + for (i = 0; i < blksize; i++)
  45254. + DWC_PRINT("%02x%s", *blk++, ((i & 3) == 3) ? " " : " ");
  45255. + DWC_PRINT(suffix);
  45256. +#endif
  45257. +}
  45258. +
  45259. +/**
  45260. + * Encrypts an array of bytes using the AES encryption engine.
  45261. + * If <code>dst</code> == <code>src</code>, then the bytes will be encrypted
  45262. + * in-place.
  45263. + *
  45264. + * @return 0 on success, negative error code on error.
  45265. + */
  45266. +int dwc_wusb_aes_encrypt(u8 *src, u8 *key, u8 *dst)
  45267. +{
  45268. + u8 block_t[16];
  45269. + DWC_MEMSET(block_t, 0, 16);
  45270. +
  45271. + return DWC_AES_CBC(src, 16, key, 16, block_t, dst);
  45272. +}
  45273. +
  45274. +/**
  45275. + * The CCM-MAC-FUNCTION described in section 6.5 of the WUSB spec.
  45276. + * This function takes a data string and returns the encrypted CBC
  45277. + * Counter-mode MIC.
  45278. + *
  45279. + * @param key The 128-bit symmetric key.
  45280. + * @param nonce The CCM nonce.
  45281. + * @param label The unique 14-byte ASCII text label.
  45282. + * @param bytes The byte array to be encrypted.
  45283. + * @param len Length of the byte array.
  45284. + * @param result Byte array to receive the 8-byte encrypted MIC.
  45285. + */
  45286. +void dwc_wusb_cmf(u8 *key, u8 *nonce,
  45287. + char *label, u8 *bytes, int len, u8 *result)
  45288. +{
  45289. + u8 block_m[16];
  45290. + u8 block_x[16];
  45291. + u8 block_t[8];
  45292. + int idx, blkNum;
  45293. + u16 la = (u16)(len + 14);
  45294. +
  45295. + /* Set the AES-128 key */
  45296. + //dwc_aes_setkey(tfm, key, 16);
  45297. +
  45298. + /* Fill block B0 from flags = 0x59, N, and l(m) = 0 */
  45299. + block_m[0] = 0x59;
  45300. + for (idx = 0; idx < 13; idx++)
  45301. + block_m[idx + 1] = nonce[idx];
  45302. + block_m[14] = 0;
  45303. + block_m[15] = 0;
  45304. +
  45305. + /* Produce the CBC IV */
  45306. + dwc_wusb_aes_encrypt(block_m, key, block_x);
  45307. + show_block(block_m, "CBC IV in: ", "\n", 0);
  45308. + show_block(block_x, "CBC IV out:", "\n", 0);
  45309. +
  45310. + /* Fill block B1 from l(a) = Blen + 14, and A */
  45311. + block_x[0] ^= (u8)(la >> 8);
  45312. + block_x[1] ^= (u8)la;
  45313. + for (idx = 0; idx < 14; idx++)
  45314. + block_x[idx + 2] ^= label[idx];
  45315. + show_block(block_x, "After xor: ", "b1\n", 16);
  45316. +
  45317. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  45318. + show_block(block_x, "After AES: ", "b1\n", 16);
  45319. +
  45320. + idx = 0;
  45321. + blkNum = 0;
  45322. +
  45323. + /* Fill remaining blocks with B */
  45324. + while (len-- > 0) {
  45325. + block_x[idx] ^= *bytes++;
  45326. + if (++idx >= 16) {
  45327. + idx = 0;
  45328. + show_block(block_x, "After xor: ", "\n", blkNum);
  45329. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  45330. + show_block(block_x, "After AES: ", "\n", blkNum);
  45331. + blkNum++;
  45332. + }
  45333. + }
  45334. +
  45335. + /* Handle partial last block */
  45336. + if (idx > 0) {
  45337. + show_block(block_x, "After xor: ", "\n", blkNum);
  45338. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  45339. + show_block(block_x, "After AES: ", "\n", blkNum);
  45340. + }
  45341. +
  45342. + /* Save the MIC tag */
  45343. + DWC_MEMCPY(block_t, block_x, 8);
  45344. + show_block(block_t, "MIC tag : ", NULL, 8);
  45345. +
  45346. + /* Fill block A0 from flags = 0x01, N, and counter = 0 */
  45347. + block_m[0] = 0x01;
  45348. + block_m[14] = 0;
  45349. + block_m[15] = 0;
  45350. +
  45351. + /* Encrypt the counter */
  45352. + dwc_wusb_aes_encrypt(block_m, key, block_x);
  45353. + show_block(block_x, "CTR[MIC] : ", NULL, 8);
  45354. +
  45355. + /* XOR with MIC tag */
  45356. + for (idx = 0; idx < 8; idx++) {
  45357. + block_t[idx] ^= block_x[idx];
  45358. + }
  45359. +
  45360. + /* Return result to caller */
  45361. + DWC_MEMCPY(result, block_t, 8);
  45362. + show_block(result, "CCM-MIC : ", NULL, 8);
  45363. +
  45364. +}
  45365. +
  45366. +/**
  45367. + * The PRF function described in section 6.5 of the WUSB spec. This function
  45368. + * concatenates MIC values returned from dwc_cmf() to create a value of
  45369. + * the requested length.
  45370. + *
  45371. + * @param prf_len Length of the PRF function in bits (64, 128, or 256).
  45372. + * @param key, nonce, label, bytes, len Same as for dwc_cmf().
  45373. + * @param result Byte array to receive the result.
  45374. + */
  45375. +void dwc_wusb_prf(int prf_len, u8 *key,
  45376. + u8 *nonce, char *label, u8 *bytes, int len, u8 *result)
  45377. +{
  45378. + int i;
  45379. +
  45380. + nonce[0] = 0;
  45381. + for (i = 0; i < prf_len >> 6; i++, nonce[0]++) {
  45382. + dwc_wusb_cmf(key, nonce, label, bytes, len, result);
  45383. + result += 8;
  45384. + }
  45385. +}
  45386. +
  45387. +/**
  45388. + * Fills in CCM Nonce per the WUSB spec.
  45389. + *
  45390. + * @param[in] haddr Host address.
  45391. + * @param[in] daddr Device address.
  45392. + * @param[in] tkid Session Key(PTK) identifier.
  45393. + * @param[out] nonce Pointer to where the CCM Nonce output is to be written.
  45394. + */
  45395. +void dwc_wusb_fill_ccm_nonce(uint16_t haddr, uint16_t daddr, uint8_t *tkid,
  45396. + uint8_t *nonce)
  45397. +{
  45398. +
  45399. + DWC_DEBUG("%s %x %x\n", __func__, daddr, haddr);
  45400. +
  45401. + DWC_MEMSET(&nonce[0], 0, 16);
  45402. +
  45403. + DWC_MEMCPY(&nonce[6], tkid, 3);
  45404. + nonce[9] = daddr & 0xFF;
  45405. + nonce[10] = (daddr >> 8) & 0xFF;
  45406. + nonce[11] = haddr & 0xFF;
  45407. + nonce[12] = (haddr >> 8) & 0xFF;
  45408. +
  45409. + dump_bytes("CCM nonce", nonce, 16);
  45410. +}
  45411. +
  45412. +/**
  45413. + * Generates a 16-byte cryptographic-grade random number for the Host/Device
  45414. + * Nonce.
  45415. + */
  45416. +void dwc_wusb_gen_nonce(uint16_t addr, uint8_t *nonce)
  45417. +{
  45418. + uint8_t inonce[16];
  45419. + uint32_t temp[4];
  45420. +
  45421. + /* Fill in the Nonce */
  45422. + DWC_MEMSET(&inonce[0], 0, sizeof(inonce));
  45423. + inonce[9] = addr & 0xFF;
  45424. + inonce[10] = (addr >> 8) & 0xFF;
  45425. + inonce[11] = inonce[9];
  45426. + inonce[12] = inonce[10];
  45427. +
  45428. + /* Collect "randomness samples" */
  45429. + DWC_RANDOM_BYTES((uint8_t *)temp, 16);
  45430. +
  45431. + dwc_wusb_prf_128((uint8_t *)temp, nonce,
  45432. + "Random Numbers", (uint8_t *)temp, sizeof(temp),
  45433. + nonce);
  45434. +}
  45435. +
  45436. +/**
  45437. + * Generates the Session Key (PTK) and Key Confirmation Key (KCK) per the
  45438. + * WUSB spec.
  45439. + *
  45440. + * @param[in] ccm_nonce Pointer to CCM Nonce.
  45441. + * @param[in] mk Master Key to derive the session from
  45442. + * @param[in] hnonce Pointer to Host Nonce.
  45443. + * @param[in] dnonce Pointer to Device Nonce.
  45444. + * @param[out] kck Pointer to where the KCK output is to be written.
  45445. + * @param[out] ptk Pointer to where the PTK output is to be written.
  45446. + */
  45447. +void dwc_wusb_gen_key(uint8_t *ccm_nonce, uint8_t *mk, uint8_t *hnonce,
  45448. + uint8_t *dnonce, uint8_t *kck, uint8_t *ptk)
  45449. +{
  45450. + uint8_t idata[32];
  45451. + uint8_t odata[32];
  45452. +
  45453. + dump_bytes("ck", mk, 16);
  45454. + dump_bytes("hnonce", hnonce, 16);
  45455. + dump_bytes("dnonce", dnonce, 16);
  45456. +
  45457. + /* The data is the HNonce and DNonce concatenated */
  45458. + DWC_MEMCPY(&idata[0], hnonce, 16);
  45459. + DWC_MEMCPY(&idata[16], dnonce, 16);
  45460. +
  45461. + dwc_wusb_prf_256(mk, ccm_nonce, "Pair-wise keys", idata, 32, odata);
  45462. +
  45463. + /* Low 16 bytes of the result is the KCK, high 16 is the PTK */
  45464. + DWC_MEMCPY(kck, &odata[0], 16);
  45465. + DWC_MEMCPY(ptk, &odata[16], 16);
  45466. +
  45467. + dump_bytes("kck", kck, 16);
  45468. + dump_bytes("ptk", ptk, 16);
  45469. +}
  45470. +
  45471. +/**
  45472. + * Generates the Message Integrity Code over the Handshake data per the
  45473. + * WUSB spec.
  45474. + *
  45475. + * @param ccm_nonce Pointer to CCM Nonce.
  45476. + * @param kck Pointer to Key Confirmation Key.
  45477. + * @param data Pointer to Handshake data to be checked.
  45478. + * @param mic Pointer to where the MIC output is to be written.
  45479. + */
  45480. +void dwc_wusb_gen_mic(uint8_t *ccm_nonce, uint8_t *kck,
  45481. + uint8_t *data, uint8_t *mic)
  45482. +{
  45483. +
  45484. + dwc_wusb_prf_64(kck, ccm_nonce, "out-of-bandMIC",
  45485. + data, WUSB_HANDSHAKE_LEN_FOR_MIC, mic);
  45486. +}
  45487. +
  45488. +#endif /* DWC_CRYPTOLIB */
  45489. diff -Nur linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_crypto.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_crypto.h
  45490. --- linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_crypto.h 1970-01-01 01:00:00.000000000 +0100
  45491. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_crypto.h 2014-04-13 17:33:11.000000000 +0200
  45492. @@ -0,0 +1,111 @@
  45493. +/* =========================================================================
  45494. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_crypto.h $
  45495. + * $Revision: #3 $
  45496. + * $Date: 2010/09/28 $
  45497. + * $Change: 1596182 $
  45498. + *
  45499. + * Synopsys Portability Library Software and documentation
  45500. + * (hereinafter, "Software") is an Unsupported proprietary work of
  45501. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  45502. + * between Synopsys and you.
  45503. + *
  45504. + * The Software IS NOT an item of Licensed Software or Licensed Product
  45505. + * under any End User Software License Agreement or Agreement for
  45506. + * Licensed Product with Synopsys or any supplement thereto. You are
  45507. + * permitted to use and redistribute this Software in source and binary
  45508. + * forms, with or without modification, provided that redistributions
  45509. + * of source code must retain this notice. You may not view, use,
  45510. + * disclose, copy or distribute this file or any information contained
  45511. + * herein except pursuant to this license grant from Synopsys. If you
  45512. + * do not agree with this notice, including the disclaimer below, then
  45513. + * you are not authorized to use the Software.
  45514. + *
  45515. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  45516. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  45517. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  45518. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  45519. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  45520. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  45521. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  45522. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  45523. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  45524. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  45525. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  45526. + * DAMAGE.
  45527. + * ========================================================================= */
  45528. +
  45529. +#ifndef _DWC_CRYPTO_H_
  45530. +#define _DWC_CRYPTO_H_
  45531. +
  45532. +#ifdef __cplusplus
  45533. +extern "C" {
  45534. +#endif
  45535. +
  45536. +/** @file
  45537. + *
  45538. + * This file contains declarations for the WUSB Cryptographic routines as
  45539. + * defined in the WUSB spec. They are only to be used internally by the DWC UWB
  45540. + * modules.
  45541. + */
  45542. +
  45543. +#include "dwc_os.h"
  45544. +
  45545. +int dwc_wusb_aes_encrypt(u8 *src, u8 *key, u8 *dst);
  45546. +
  45547. +void dwc_wusb_cmf(u8 *key, u8 *nonce,
  45548. + char *label, u8 *bytes, int len, u8 *result);
  45549. +void dwc_wusb_prf(int prf_len, u8 *key,
  45550. + u8 *nonce, char *label, u8 *bytes, int len, u8 *result);
  45551. +
  45552. +/**
  45553. + * The PRF-64 function described in section 6.5 of the WUSB spec.
  45554. + *
  45555. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  45556. + */
  45557. +static inline void dwc_wusb_prf_64(u8 *key, u8 *nonce,
  45558. + char *label, u8 *bytes, int len, u8 *result)
  45559. +{
  45560. + dwc_wusb_prf(64, key, nonce, label, bytes, len, result);
  45561. +}
  45562. +
  45563. +/**
  45564. + * The PRF-128 function described in section 6.5 of the WUSB spec.
  45565. + *
  45566. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  45567. + */
  45568. +static inline void dwc_wusb_prf_128(u8 *key, u8 *nonce,
  45569. + char *label, u8 *bytes, int len, u8 *result)
  45570. +{
  45571. + dwc_wusb_prf(128, key, nonce, label, bytes, len, result);
  45572. +}
  45573. +
  45574. +/**
  45575. + * The PRF-256 function described in section 6.5 of the WUSB spec.
  45576. + *
  45577. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  45578. + */
  45579. +static inline void dwc_wusb_prf_256(u8 *key, u8 *nonce,
  45580. + char *label, u8 *bytes, int len, u8 *result)
  45581. +{
  45582. + dwc_wusb_prf(256, key, nonce, label, bytes, len, result);
  45583. +}
  45584. +
  45585. +
  45586. +void dwc_wusb_fill_ccm_nonce(uint16_t haddr, uint16_t daddr, uint8_t *tkid,
  45587. + uint8_t *nonce);
  45588. +void dwc_wusb_gen_nonce(uint16_t addr,
  45589. + uint8_t *nonce);
  45590. +
  45591. +void dwc_wusb_gen_key(uint8_t *ccm_nonce, uint8_t *mk,
  45592. + uint8_t *hnonce, uint8_t *dnonce,
  45593. + uint8_t *kck, uint8_t *ptk);
  45594. +
  45595. +
  45596. +void dwc_wusb_gen_mic(uint8_t *ccm_nonce, uint8_t
  45597. + *kck, uint8_t *data, uint8_t *mic);
  45598. +
  45599. +#ifdef __cplusplus
  45600. +}
  45601. +#endif
  45602. +
  45603. +#endif /* _DWC_CRYPTO_H_ */
  45604. diff -Nur linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_dh.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_dh.c
  45605. --- linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_dh.c 1970-01-01 01:00:00.000000000 +0100
  45606. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_dh.c 2014-07-07 10:45:43.000000000 +0200
  45607. @@ -0,0 +1,291 @@
  45608. +/* =========================================================================
  45609. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_dh.c $
  45610. + * $Revision: #3 $
  45611. + * $Date: 2010/09/28 $
  45612. + * $Change: 1596182 $
  45613. + *
  45614. + * Synopsys Portability Library Software and documentation
  45615. + * (hereinafter, "Software") is an Unsupported proprietary work of
  45616. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  45617. + * between Synopsys and you.
  45618. + *
  45619. + * The Software IS NOT an item of Licensed Software or Licensed Product
  45620. + * under any End User Software License Agreement or Agreement for
  45621. + * Licensed Product with Synopsys or any supplement thereto. You are
  45622. + * permitted to use and redistribute this Software in source and binary
  45623. + * forms, with or without modification, provided that redistributions
  45624. + * of source code must retain this notice. You may not view, use,
  45625. + * disclose, copy or distribute this file or any information contained
  45626. + * herein except pursuant to this license grant from Synopsys. If you
  45627. + * do not agree with this notice, including the disclaimer below, then
  45628. + * you are not authorized to use the Software.
  45629. + *
  45630. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  45631. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  45632. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  45633. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  45634. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  45635. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  45636. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  45637. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  45638. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  45639. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  45640. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  45641. + * DAMAGE.
  45642. + * ========================================================================= */
  45643. +#ifdef DWC_CRYPTOLIB
  45644. +
  45645. +#ifndef CONFIG_MACH_IPMATE
  45646. +
  45647. +#include "dwc_dh.h"
  45648. +#include "dwc_modpow.h"
  45649. +
  45650. +#ifdef DEBUG
  45651. +/* This function prints out a buffer in the format described in the Association
  45652. + * Model specification. */
  45653. +static void dh_dump(char *str, void *_num, int len)
  45654. +{
  45655. + uint8_t *num = _num;
  45656. + int i;
  45657. + DWC_PRINTF("%s\n", str);
  45658. + for (i = 0; i < len; i ++) {
  45659. + DWC_PRINTF("%02x", num[i]);
  45660. + if (((i + 1) % 2) == 0) DWC_PRINTF(" ");
  45661. + if (((i + 1) % 26) == 0) DWC_PRINTF("\n");
  45662. + }
  45663. +
  45664. + DWC_PRINTF("\n");
  45665. +}
  45666. +#else
  45667. +#define dh_dump(_x...) do {; } while(0)
  45668. +#endif
  45669. +
  45670. +/* Constant g value */
  45671. +static __u32 dh_g[] = {
  45672. + 0x02000000,
  45673. +};
  45674. +
  45675. +/* Constant p value */
  45676. +static __u32 dh_p[] = {
  45677. + 0xFFFFFFFF, 0xFFFFFFFF, 0xA2DA0FC9, 0x34C26821, 0x8B62C6C4, 0xD11CDC80, 0x084E0229, 0x74CC678A,
  45678. + 0xA6BE0B02, 0x229B133B, 0x79084A51, 0xDD04348E, 0xB31995EF, 0x1B433ACD, 0x6D0A2B30, 0x37145FF2,
  45679. + 0x6D35E14F, 0x45C2516D, 0x76B585E4, 0xC67E5E62, 0xE9424CF4, 0x6BED37A6, 0xB65CFF0B, 0xEDB706F4,
  45680. + 0xFB6B38EE, 0xA59F895A, 0x11249FAE, 0xE61F4B7C, 0x51662849, 0x3D5BE4EC, 0xB87C00C2, 0x05BF63A1,
  45681. + 0x3648DA98, 0x9AD3551C, 0xA83F1669, 0x5FCF24FD, 0x235D6583, 0x96ADA3DC, 0x56F3621C, 0xBB528520,
  45682. + 0x0729D59E, 0x6D969670, 0x4E350C67, 0x0498BC4A, 0x086C74F1, 0x7C2118CA, 0x465E9032, 0x3BCE362E,
  45683. + 0x2C779EE3, 0x03860E18, 0xA283279B, 0x8FA207EC, 0xF05DC5B5, 0xC9524C6F, 0xF6CB2BDE, 0x18175895,
  45684. + 0x7C499539, 0xE56A95EA, 0x1826D215, 0x1005FA98, 0x5A8E7215, 0x2DC4AA8A, 0x0D1733AD, 0x337A5004,
  45685. + 0xAB2155A8, 0x64BA1CDF, 0x0485FBEC, 0x0AEFDB58, 0x5771EA8A, 0x7D0C065D, 0x850F97B3, 0xC7E4E1A6,
  45686. + 0x8CAEF5AB, 0xD73309DB, 0xE0948C1E, 0x9D61254A, 0x26D2E3CE, 0x6BEED21A, 0x06FA2FF1, 0x64088AD9,
  45687. + 0x730276D8, 0x646AC83E, 0x182B1F52, 0x0C207B17, 0x5717E1BB, 0x6C5D617A, 0xC0880977, 0xE246D9BA,
  45688. + 0xA04FE208, 0x31ABE574, 0xFC5BDB43, 0x8E10FDE0, 0x20D1824B, 0xCAD23AA9, 0xFFFFFFFF, 0xFFFFFFFF,
  45689. +};
  45690. +
  45691. +static void dh_swap_bytes(void *_in, void *_out, uint32_t len)
  45692. +{
  45693. + uint8_t *in = _in;
  45694. + uint8_t *out = _out;
  45695. + int i;
  45696. + for (i=0; i<len; i++) {
  45697. + out[i] = in[len-1-i];
  45698. + }
  45699. +}
  45700. +
  45701. +/* Computes the modular exponentiation (num^exp % mod). num, exp, and mod are
  45702. + * big endian numbers of size len, in bytes. Each len value must be a multiple
  45703. + * of 4. */
  45704. +int dwc_dh_modpow(void *mem_ctx, void *num, uint32_t num_len,
  45705. + void *exp, uint32_t exp_len,
  45706. + void *mod, uint32_t mod_len,
  45707. + void *out)
  45708. +{
  45709. + /* modpow() takes little endian numbers. AM uses big-endian. This
  45710. + * function swaps bytes of numbers before passing onto modpow. */
  45711. +
  45712. + int retval = 0;
  45713. + uint32_t *result;
  45714. +
  45715. + uint32_t *bignum_num = dwc_alloc(mem_ctx, num_len + 4);
  45716. + uint32_t *bignum_exp = dwc_alloc(mem_ctx, exp_len + 4);
  45717. + uint32_t *bignum_mod = dwc_alloc(mem_ctx, mod_len + 4);
  45718. +
  45719. + dh_swap_bytes(num, &bignum_num[1], num_len);
  45720. + bignum_num[0] = num_len / 4;
  45721. +
  45722. + dh_swap_bytes(exp, &bignum_exp[1], exp_len);
  45723. + bignum_exp[0] = exp_len / 4;
  45724. +
  45725. + dh_swap_bytes(mod, &bignum_mod[1], mod_len);
  45726. + bignum_mod[0] = mod_len / 4;
  45727. +
  45728. + result = dwc_modpow(mem_ctx, bignum_num, bignum_exp, bignum_mod);
  45729. + if (!result) {
  45730. + retval = -1;
  45731. + goto dh_modpow_nomem;
  45732. + }
  45733. +
  45734. + dh_swap_bytes(&result[1], out, result[0] * 4);
  45735. + dwc_free(mem_ctx, result);
  45736. +
  45737. + dh_modpow_nomem:
  45738. + dwc_free(mem_ctx, bignum_num);
  45739. + dwc_free(mem_ctx, bignum_exp);
  45740. + dwc_free(mem_ctx, bignum_mod);
  45741. + return retval;
  45742. +}
  45743. +
  45744. +
  45745. +int dwc_dh_pk(void *mem_ctx, uint8_t nd, uint8_t *exp, uint8_t *pk, uint8_t *hash)
  45746. +{
  45747. + int retval;
  45748. + uint8_t m3[385];
  45749. +
  45750. +#ifndef DH_TEST_VECTORS
  45751. + DWC_RANDOM_BYTES(exp, 32);
  45752. +#endif
  45753. +
  45754. + /* Compute the pkd */
  45755. + if ((retval = dwc_dh_modpow(mem_ctx, dh_g, 4,
  45756. + exp, 32,
  45757. + dh_p, 384, pk))) {
  45758. + return retval;
  45759. + }
  45760. +
  45761. + m3[384] = nd;
  45762. + DWC_MEMCPY(&m3[0], pk, 384);
  45763. + DWC_SHA256(m3, 385, hash);
  45764. +
  45765. + dh_dump("PK", pk, 384);
  45766. + dh_dump("SHA-256(M3)", hash, 32);
  45767. + return 0;
  45768. +}
  45769. +
  45770. +int dwc_dh_derive_keys(void *mem_ctx, uint8_t nd, uint8_t *pkh, uint8_t *pkd,
  45771. + uint8_t *exp, int is_host,
  45772. + char *dd, uint8_t *ck, uint8_t *kdk)
  45773. +{
  45774. + int retval;
  45775. + uint8_t mv[784];
  45776. + uint8_t sha_result[32];
  45777. + uint8_t dhkey[384];
  45778. + uint8_t shared_secret[384];
  45779. + char *message;
  45780. + uint32_t vd;
  45781. +
  45782. + uint8_t *pk;
  45783. +
  45784. + if (is_host) {
  45785. + pk = pkd;
  45786. + }
  45787. + else {
  45788. + pk = pkh;
  45789. + }
  45790. +
  45791. + if ((retval = dwc_dh_modpow(mem_ctx, pk, 384,
  45792. + exp, 32,
  45793. + dh_p, 384, shared_secret))) {
  45794. + return retval;
  45795. + }
  45796. + dh_dump("Shared Secret", shared_secret, 384);
  45797. +
  45798. + DWC_SHA256(shared_secret, 384, dhkey);
  45799. + dh_dump("DHKEY", dhkey, 384);
  45800. +
  45801. + DWC_MEMCPY(&mv[0], pkd, 384);
  45802. + DWC_MEMCPY(&mv[384], pkh, 384);
  45803. + DWC_MEMCPY(&mv[768], "displayed digest", 16);
  45804. + dh_dump("MV", mv, 784);
  45805. +
  45806. + DWC_SHA256(mv, 784, sha_result);
  45807. + dh_dump("SHA-256(MV)", sha_result, 32);
  45808. + dh_dump("First 32-bits of SHA-256(MV)", sha_result, 4);
  45809. +
  45810. + dh_swap_bytes(sha_result, &vd, 4);
  45811. +#ifdef DEBUG
  45812. + DWC_PRINTF("Vd (decimal) = %d\n", vd);
  45813. +#endif
  45814. +
  45815. + switch (nd) {
  45816. + case 2:
  45817. + vd = vd % 100;
  45818. + DWC_SPRINTF(dd, "%02d", vd);
  45819. + break;
  45820. + case 3:
  45821. + vd = vd % 1000;
  45822. + DWC_SPRINTF(dd, "%03d", vd);
  45823. + break;
  45824. + case 4:
  45825. + vd = vd % 10000;
  45826. + DWC_SPRINTF(dd, "%04d", vd);
  45827. + break;
  45828. + }
  45829. +#ifdef DEBUG
  45830. + DWC_PRINTF("Display Digits: %s\n", dd);
  45831. +#endif
  45832. +
  45833. + message = "connection key";
  45834. + DWC_HMAC_SHA256(message, DWC_STRLEN(message), dhkey, 32, sha_result);
  45835. + dh_dump("HMAC(SHA-256, DHKey, connection key)", sha_result, 32);
  45836. + DWC_MEMCPY(ck, sha_result, 16);
  45837. +
  45838. + message = "key derivation key";
  45839. + DWC_HMAC_SHA256(message, DWC_STRLEN(message), dhkey, 32, sha_result);
  45840. + dh_dump("HMAC(SHA-256, DHKey, key derivation key)", sha_result, 32);
  45841. + DWC_MEMCPY(kdk, sha_result, 32);
  45842. +
  45843. + return 0;
  45844. +}
  45845. +
  45846. +
  45847. +#ifdef DH_TEST_VECTORS
  45848. +
  45849. +static __u8 dh_a[] = {
  45850. + 0x44, 0x00, 0x51, 0xd6,
  45851. + 0xf0, 0xb5, 0x5e, 0xa9,
  45852. + 0x67, 0xab, 0x31, 0xc6,
  45853. + 0x8a, 0x8b, 0x5e, 0x37,
  45854. + 0xd9, 0x10, 0xda, 0xe0,
  45855. + 0xe2, 0xd4, 0x59, 0xa4,
  45856. + 0x86, 0x45, 0x9c, 0xaa,
  45857. + 0xdf, 0x36, 0x75, 0x16,
  45858. +};
  45859. +
  45860. +static __u8 dh_b[] = {
  45861. + 0x5d, 0xae, 0xc7, 0x86,
  45862. + 0x79, 0x80, 0xa3, 0x24,
  45863. + 0x8c, 0xe3, 0x57, 0x8f,
  45864. + 0xc7, 0x5f, 0x1b, 0x0f,
  45865. + 0x2d, 0xf8, 0x9d, 0x30,
  45866. + 0x6f, 0xa4, 0x52, 0xcd,
  45867. + 0xe0, 0x7a, 0x04, 0x8a,
  45868. + 0xde, 0xd9, 0x26, 0x56,
  45869. +};
  45870. +
  45871. +void dwc_run_dh_test_vectors(void *mem_ctx)
  45872. +{
  45873. + uint8_t pkd[384];
  45874. + uint8_t pkh[384];
  45875. + uint8_t hashd[32];
  45876. + uint8_t hashh[32];
  45877. + uint8_t ck[16];
  45878. + uint8_t kdk[32];
  45879. + char dd[5];
  45880. +
  45881. + DWC_PRINTF("\n\n\nDH_TEST_VECTORS\n\n");
  45882. +
  45883. + /* compute the PKd and SHA-256(PKd || Nd) */
  45884. + DWC_PRINTF("Computing PKd\n");
  45885. + dwc_dh_pk(mem_ctx, 2, dh_a, pkd, hashd);
  45886. +
  45887. + /* compute the PKd and SHA-256(PKh || Nd) */
  45888. + DWC_PRINTF("Computing PKh\n");
  45889. + dwc_dh_pk(mem_ctx, 2, dh_b, pkh, hashh);
  45890. +
  45891. + /* compute the dhkey */
  45892. + dwc_dh_derive_keys(mem_ctx, 2, pkh, pkd, dh_a, 0, dd, ck, kdk);
  45893. +}
  45894. +#endif /* DH_TEST_VECTORS */
  45895. +
  45896. +#endif /* !CONFIG_MACH_IPMATE */
  45897. +
  45898. +#endif /* DWC_CRYPTOLIB */
  45899. diff -Nur linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_dh.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_dh.h
  45900. --- linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_dh.h 1970-01-01 01:00:00.000000000 +0100
  45901. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_dh.h 2014-04-13 17:33:11.000000000 +0200
  45902. @@ -0,0 +1,106 @@
  45903. +/* =========================================================================
  45904. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_dh.h $
  45905. + * $Revision: #4 $
  45906. + * $Date: 2010/09/28 $
  45907. + * $Change: 1596182 $
  45908. + *
  45909. + * Synopsys Portability Library Software and documentation
  45910. + * (hereinafter, "Software") is an Unsupported proprietary work of
  45911. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  45912. + * between Synopsys and you.
  45913. + *
  45914. + * The Software IS NOT an item of Licensed Software or Licensed Product
  45915. + * under any End User Software License Agreement or Agreement for
  45916. + * Licensed Product with Synopsys or any supplement thereto. You are
  45917. + * permitted to use and redistribute this Software in source and binary
  45918. + * forms, with or without modification, provided that redistributions
  45919. + * of source code must retain this notice. You may not view, use,
  45920. + * disclose, copy or distribute this file or any information contained
  45921. + * herein except pursuant to this license grant from Synopsys. If you
  45922. + * do not agree with this notice, including the disclaimer below, then
  45923. + * you are not authorized to use the Software.
  45924. + *
  45925. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  45926. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  45927. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  45928. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  45929. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  45930. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  45931. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  45932. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  45933. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  45934. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  45935. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  45936. + * DAMAGE.
  45937. + * ========================================================================= */
  45938. +#ifndef _DWC_DH_H_
  45939. +#define _DWC_DH_H_
  45940. +
  45941. +#ifdef __cplusplus
  45942. +extern "C" {
  45943. +#endif
  45944. +
  45945. +#include "dwc_os.h"
  45946. +
  45947. +/** @file
  45948. + *
  45949. + * This file defines the common functions on device and host for performing
  45950. + * numeric association as defined in the WUSB spec. They are only to be
  45951. + * used internally by the DWC UWB modules. */
  45952. +
  45953. +extern int dwc_dh_sha256(uint8_t *message, uint32_t len, uint8_t *out);
  45954. +extern int dwc_dh_hmac_sha256(uint8_t *message, uint32_t messagelen,
  45955. + uint8_t *key, uint32_t keylen,
  45956. + uint8_t *out);
  45957. +extern int dwc_dh_modpow(void *mem_ctx, void *num, uint32_t num_len,
  45958. + void *exp, uint32_t exp_len,
  45959. + void *mod, uint32_t mod_len,
  45960. + void *out);
  45961. +
  45962. +/** Computes PKD or PKH, and SHA-256(PKd || Nd)
  45963. + *
  45964. + * PK = g^exp mod p.
  45965. + *
  45966. + * Input:
  45967. + * Nd = Number of digits on the device.
  45968. + *
  45969. + * Output:
  45970. + * exp = A 32-byte buffer to be filled with a randomly generated number.
  45971. + * used as either A or B.
  45972. + * pk = A 384-byte buffer to be filled with the PKH or PKD.
  45973. + * hash = A 32-byte buffer to be filled with SHA-256(PK || ND).
  45974. + */
  45975. +extern int dwc_dh_pk(void *mem_ctx, uint8_t nd, uint8_t *exp, uint8_t *pkd, uint8_t *hash);
  45976. +
  45977. +/** Computes the DHKEY, and VD.
  45978. + *
  45979. + * If called from host, then it will comput DHKEY=PKD^exp % p.
  45980. + * If called from device, then it will comput DHKEY=PKH^exp % p.
  45981. + *
  45982. + * Input:
  45983. + * pkd = The PKD value.
  45984. + * pkh = The PKH value.
  45985. + * exp = The A value (if device) or B value (if host) generated in dwc_wudev_dh_pk.
  45986. + * is_host = Set to non zero if a WUSB host is calling this function.
  45987. + *
  45988. + * Output:
  45989. +
  45990. + * dd = A pointer to an buffer to be set to the displayed digits string to be shown
  45991. + * to the user. This buffer should be at 5 bytes long to hold 4 digits plus a
  45992. + * null termination character. This buffer can be used directly for display.
  45993. + * ck = A 16-byte buffer to be filled with the CK.
  45994. + * kdk = A 32-byte buffer to be filled with the KDK.
  45995. + */
  45996. +extern int dwc_dh_derive_keys(void *mem_ctx, uint8_t nd, uint8_t *pkh, uint8_t *pkd,
  45997. + uint8_t *exp, int is_host,
  45998. + char *dd, uint8_t *ck, uint8_t *kdk);
  45999. +
  46000. +#ifdef DH_TEST_VECTORS
  46001. +extern void dwc_run_dh_test_vectors(void);
  46002. +#endif
  46003. +
  46004. +#ifdef __cplusplus
  46005. +}
  46006. +#endif
  46007. +
  46008. +#endif /* _DWC_DH_H_ */
  46009. diff -Nur linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_list.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_list.h
  46010. --- linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_list.h 1970-01-01 01:00:00.000000000 +0100
  46011. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_list.h 2014-04-13 17:33:11.000000000 +0200
  46012. @@ -0,0 +1,594 @@
  46013. +/* $OpenBSD: queue.h,v 1.26 2004/05/04 16:59:32 grange Exp $ */
  46014. +/* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */
  46015. +
  46016. +/*
  46017. + * Copyright (c) 1991, 1993
  46018. + * The Regents of the University of California. All rights reserved.
  46019. + *
  46020. + * Redistribution and use in source and binary forms, with or without
  46021. + * modification, are permitted provided that the following conditions
  46022. + * are met:
  46023. + * 1. Redistributions of source code must retain the above copyright
  46024. + * notice, this list of conditions and the following disclaimer.
  46025. + * 2. Redistributions in binary form must reproduce the above copyright
  46026. + * notice, this list of conditions and the following disclaimer in the
  46027. + * documentation and/or other materials provided with the distribution.
  46028. + * 3. Neither the name of the University nor the names of its contributors
  46029. + * may be used to endorse or promote products derived from this software
  46030. + * without specific prior written permission.
  46031. + *
  46032. + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  46033. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  46034. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  46035. + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  46036. + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  46037. + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  46038. + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  46039. + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  46040. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  46041. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46042. + * SUCH DAMAGE.
  46043. + *
  46044. + * @(#)queue.h 8.5 (Berkeley) 8/20/94
  46045. + */
  46046. +
  46047. +#ifndef _DWC_LIST_H_
  46048. +#define _DWC_LIST_H_
  46049. +
  46050. +#ifdef __cplusplus
  46051. +extern "C" {
  46052. +#endif
  46053. +
  46054. +/** @file
  46055. + *
  46056. + * This file defines linked list operations. It is derived from BSD with
  46057. + * only the MACRO names being prefixed with DWC_. This is because a few of
  46058. + * these names conflict with those on Linux. For documentation on use, see the
  46059. + * inline comments in the source code. The original license for this source
  46060. + * code applies and is preserved in the dwc_list.h source file.
  46061. + */
  46062. +
  46063. +/*
  46064. + * This file defines five types of data structures: singly-linked lists,
  46065. + * lists, simple queues, tail queues, and circular queues.
  46066. + *
  46067. + *
  46068. + * A singly-linked list is headed by a single forward pointer. The elements
  46069. + * are singly linked for minimum space and pointer manipulation overhead at
  46070. + * the expense of O(n) removal for arbitrary elements. New elements can be
  46071. + * added to the list after an existing element or at the head of the list.
  46072. + * Elements being removed from the head of the list should use the explicit
  46073. + * macro for this purpose for optimum efficiency. A singly-linked list may
  46074. + * only be traversed in the forward direction. Singly-linked lists are ideal
  46075. + * for applications with large datasets and few or no removals or for
  46076. + * implementing a LIFO queue.
  46077. + *
  46078. + * A list is headed by a single forward pointer (or an array of forward
  46079. + * pointers for a hash table header). The elements are doubly linked
  46080. + * so that an arbitrary element can be removed without a need to
  46081. + * traverse the list. New elements can be added to the list before
  46082. + * or after an existing element or at the head of the list. A list
  46083. + * may only be traversed in the forward direction.
  46084. + *
  46085. + * A simple queue is headed by a pair of pointers, one the head of the
  46086. + * list and the other to the tail of the list. The elements are singly
  46087. + * linked to save space, so elements can only be removed from the
  46088. + * head of the list. New elements can be added to the list before or after
  46089. + * an existing element, at the head of the list, or at the end of the
  46090. + * list. A simple queue may only be traversed in the forward direction.
  46091. + *
  46092. + * A tail queue is headed by a pair of pointers, one to the head of the
  46093. + * list and the other to the tail of the list. The elements are doubly
  46094. + * linked so that an arbitrary element can be removed without a need to
  46095. + * traverse the list. New elements can be added to the list before or
  46096. + * after an existing element, at the head of the list, or at the end of
  46097. + * the list. A tail queue may be traversed in either direction.
  46098. + *
  46099. + * A circle queue is headed by a pair of pointers, one to the head of the
  46100. + * list and the other to the tail of the list. The elements are doubly
  46101. + * linked so that an arbitrary element can be removed without a need to
  46102. + * traverse the list. New elements can be added to the list before or after
  46103. + * an existing element, at the head of the list, or at the end of the list.
  46104. + * A circle queue may be traversed in either direction, but has a more
  46105. + * complex end of list detection.
  46106. + *
  46107. + * For details on the use of these macros, see the queue(3) manual page.
  46108. + */
  46109. +
  46110. +/*
  46111. + * Double-linked List.
  46112. + */
  46113. +
  46114. +typedef struct dwc_list_link {
  46115. + struct dwc_list_link *next;
  46116. + struct dwc_list_link *prev;
  46117. +} dwc_list_link_t;
  46118. +
  46119. +#define DWC_LIST_INIT(link) do { \
  46120. + (link)->next = (link); \
  46121. + (link)->prev = (link); \
  46122. +} while (0)
  46123. +
  46124. +#define DWC_LIST_FIRST(link) ((link)->next)
  46125. +#define DWC_LIST_LAST(link) ((link)->prev)
  46126. +#define DWC_LIST_END(link) (link)
  46127. +#define DWC_LIST_NEXT(link) ((link)->next)
  46128. +#define DWC_LIST_PREV(link) ((link)->prev)
  46129. +#define DWC_LIST_EMPTY(link) \
  46130. + (DWC_LIST_FIRST(link) == DWC_LIST_END(link))
  46131. +#define DWC_LIST_ENTRY(link, type, field) \
  46132. + (type *)((uint8_t *)(link) - (size_t)(&((type *)0)->field))
  46133. +
  46134. +#if 0
  46135. +#define DWC_LIST_INSERT_HEAD(list, link) do { \
  46136. + (link)->next = (list)->next; \
  46137. + (link)->prev = (list); \
  46138. + (list)->next->prev = (link); \
  46139. + (list)->next = (link); \
  46140. +} while (0)
  46141. +
  46142. +#define DWC_LIST_INSERT_TAIL(list, link) do { \
  46143. + (link)->next = (list); \
  46144. + (link)->prev = (list)->prev; \
  46145. + (list)->prev->next = (link); \
  46146. + (list)->prev = (link); \
  46147. +} while (0)
  46148. +#else
  46149. +#define DWC_LIST_INSERT_HEAD(list, link) do { \
  46150. + dwc_list_link_t *__next__ = (list)->next; \
  46151. + __next__->prev = (link); \
  46152. + (link)->next = __next__; \
  46153. + (link)->prev = (list); \
  46154. + (list)->next = (link); \
  46155. +} while (0)
  46156. +
  46157. +#define DWC_LIST_INSERT_TAIL(list, link) do { \
  46158. + dwc_list_link_t *__prev__ = (list)->prev; \
  46159. + (list)->prev = (link); \
  46160. + (link)->next = (list); \
  46161. + (link)->prev = __prev__; \
  46162. + __prev__->next = (link); \
  46163. +} while (0)
  46164. +#endif
  46165. +
  46166. +#if 0
  46167. +static inline void __list_add(struct list_head *new,
  46168. + struct list_head *prev,
  46169. + struct list_head *next)
  46170. +{
  46171. + next->prev = new;
  46172. + new->next = next;
  46173. + new->prev = prev;
  46174. + prev->next = new;
  46175. +}
  46176. +
  46177. +static inline void list_add(struct list_head *new, struct list_head *head)
  46178. +{
  46179. + __list_add(new, head, head->next);
  46180. +}
  46181. +
  46182. +static inline void list_add_tail(struct list_head *new, struct list_head *head)
  46183. +{
  46184. + __list_add(new, head->prev, head);
  46185. +}
  46186. +
  46187. +static inline void __list_del(struct list_head * prev, struct list_head * next)
  46188. +{
  46189. + next->prev = prev;
  46190. + prev->next = next;
  46191. +}
  46192. +
  46193. +static inline void list_del(struct list_head *entry)
  46194. +{
  46195. + __list_del(entry->prev, entry->next);
  46196. + entry->next = LIST_POISON1;
  46197. + entry->prev = LIST_POISON2;
  46198. +}
  46199. +#endif
  46200. +
  46201. +#define DWC_LIST_REMOVE(link) do { \
  46202. + (link)->next->prev = (link)->prev; \
  46203. + (link)->prev->next = (link)->next; \
  46204. +} while (0)
  46205. +
  46206. +#define DWC_LIST_REMOVE_INIT(link) do { \
  46207. + DWC_LIST_REMOVE(link); \
  46208. + DWC_LIST_INIT(link); \
  46209. +} while (0)
  46210. +
  46211. +#define DWC_LIST_MOVE_HEAD(list, link) do { \
  46212. + DWC_LIST_REMOVE(link); \
  46213. + DWC_LIST_INSERT_HEAD(list, link); \
  46214. +} while (0)
  46215. +
  46216. +#define DWC_LIST_MOVE_TAIL(list, link) do { \
  46217. + DWC_LIST_REMOVE(link); \
  46218. + DWC_LIST_INSERT_TAIL(list, link); \
  46219. +} while (0)
  46220. +
  46221. +#define DWC_LIST_FOREACH(var, list) \
  46222. + for((var) = DWC_LIST_FIRST(list); \
  46223. + (var) != DWC_LIST_END(list); \
  46224. + (var) = DWC_LIST_NEXT(var))
  46225. +
  46226. +#define DWC_LIST_FOREACH_SAFE(var, var2, list) \
  46227. + for((var) = DWC_LIST_FIRST(list), (var2) = DWC_LIST_NEXT(var); \
  46228. + (var) != DWC_LIST_END(list); \
  46229. + (var) = (var2), (var2) = DWC_LIST_NEXT(var2))
  46230. +
  46231. +#define DWC_LIST_FOREACH_REVERSE(var, list) \
  46232. + for((var) = DWC_LIST_LAST(list); \
  46233. + (var) != DWC_LIST_END(list); \
  46234. + (var) = DWC_LIST_PREV(var))
  46235. +
  46236. +/*
  46237. + * Singly-linked List definitions.
  46238. + */
  46239. +#define DWC_SLIST_HEAD(name, type) \
  46240. +struct name { \
  46241. + struct type *slh_first; /* first element */ \
  46242. +}
  46243. +
  46244. +#define DWC_SLIST_HEAD_INITIALIZER(head) \
  46245. + { NULL }
  46246. +
  46247. +#define DWC_SLIST_ENTRY(type) \
  46248. +struct { \
  46249. + struct type *sle_next; /* next element */ \
  46250. +}
  46251. +
  46252. +/*
  46253. + * Singly-linked List access methods.
  46254. + */
  46255. +#define DWC_SLIST_FIRST(head) ((head)->slh_first)
  46256. +#define DWC_SLIST_END(head) NULL
  46257. +#define DWC_SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head))
  46258. +#define DWC_SLIST_NEXT(elm, field) ((elm)->field.sle_next)
  46259. +
  46260. +#define DWC_SLIST_FOREACH(var, head, field) \
  46261. + for((var) = SLIST_FIRST(head); \
  46262. + (var) != SLIST_END(head); \
  46263. + (var) = SLIST_NEXT(var, field))
  46264. +
  46265. +#define DWC_SLIST_FOREACH_PREVPTR(var, varp, head, field) \
  46266. + for((varp) = &SLIST_FIRST((head)); \
  46267. + ((var) = *(varp)) != SLIST_END(head); \
  46268. + (varp) = &SLIST_NEXT((var), field))
  46269. +
  46270. +/*
  46271. + * Singly-linked List functions.
  46272. + */
  46273. +#define DWC_SLIST_INIT(head) { \
  46274. + SLIST_FIRST(head) = SLIST_END(head); \
  46275. +}
  46276. +
  46277. +#define DWC_SLIST_INSERT_AFTER(slistelm, elm, field) do { \
  46278. + (elm)->field.sle_next = (slistelm)->field.sle_next; \
  46279. + (slistelm)->field.sle_next = (elm); \
  46280. +} while (0)
  46281. +
  46282. +#define DWC_SLIST_INSERT_HEAD(head, elm, field) do { \
  46283. + (elm)->field.sle_next = (head)->slh_first; \
  46284. + (head)->slh_first = (elm); \
  46285. +} while (0)
  46286. +
  46287. +#define DWC_SLIST_REMOVE_NEXT(head, elm, field) do { \
  46288. + (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \
  46289. +} while (0)
  46290. +
  46291. +#define DWC_SLIST_REMOVE_HEAD(head, field) do { \
  46292. + (head)->slh_first = (head)->slh_first->field.sle_next; \
  46293. +} while (0)
  46294. +
  46295. +#define DWC_SLIST_REMOVE(head, elm, type, field) do { \
  46296. + if ((head)->slh_first == (elm)) { \
  46297. + SLIST_REMOVE_HEAD((head), field); \
  46298. + } \
  46299. + else { \
  46300. + struct type *curelm = (head)->slh_first; \
  46301. + while( curelm->field.sle_next != (elm) ) \
  46302. + curelm = curelm->field.sle_next; \
  46303. + curelm->field.sle_next = \
  46304. + curelm->field.sle_next->field.sle_next; \
  46305. + } \
  46306. +} while (0)
  46307. +
  46308. +/*
  46309. + * Simple queue definitions.
  46310. + */
  46311. +#define DWC_SIMPLEQ_HEAD(name, type) \
  46312. +struct name { \
  46313. + struct type *sqh_first; /* first element */ \
  46314. + struct type **sqh_last; /* addr of last next element */ \
  46315. +}
  46316. +
  46317. +#define DWC_SIMPLEQ_HEAD_INITIALIZER(head) \
  46318. + { NULL, &(head).sqh_first }
  46319. +
  46320. +#define DWC_SIMPLEQ_ENTRY(type) \
  46321. +struct { \
  46322. + struct type *sqe_next; /* next element */ \
  46323. +}
  46324. +
  46325. +/*
  46326. + * Simple queue access methods.
  46327. + */
  46328. +#define DWC_SIMPLEQ_FIRST(head) ((head)->sqh_first)
  46329. +#define DWC_SIMPLEQ_END(head) NULL
  46330. +#define DWC_SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head))
  46331. +#define DWC_SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
  46332. +
  46333. +#define DWC_SIMPLEQ_FOREACH(var, head, field) \
  46334. + for((var) = SIMPLEQ_FIRST(head); \
  46335. + (var) != SIMPLEQ_END(head); \
  46336. + (var) = SIMPLEQ_NEXT(var, field))
  46337. +
  46338. +/*
  46339. + * Simple queue functions.
  46340. + */
  46341. +#define DWC_SIMPLEQ_INIT(head) do { \
  46342. + (head)->sqh_first = NULL; \
  46343. + (head)->sqh_last = &(head)->sqh_first; \
  46344. +} while (0)
  46345. +
  46346. +#define DWC_SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
  46347. + if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
  46348. + (head)->sqh_last = &(elm)->field.sqe_next; \
  46349. + (head)->sqh_first = (elm); \
  46350. +} while (0)
  46351. +
  46352. +#define DWC_SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
  46353. + (elm)->field.sqe_next = NULL; \
  46354. + *(head)->sqh_last = (elm); \
  46355. + (head)->sqh_last = &(elm)->field.sqe_next; \
  46356. +} while (0)
  46357. +
  46358. +#define DWC_SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
  46359. + if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
  46360. + (head)->sqh_last = &(elm)->field.sqe_next; \
  46361. + (listelm)->field.sqe_next = (elm); \
  46362. +} while (0)
  46363. +
  46364. +#define DWC_SIMPLEQ_REMOVE_HEAD(head, field) do { \
  46365. + if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
  46366. + (head)->sqh_last = &(head)->sqh_first; \
  46367. +} while (0)
  46368. +
  46369. +/*
  46370. + * Tail queue definitions.
  46371. + */
  46372. +#define DWC_TAILQ_HEAD(name, type) \
  46373. +struct name { \
  46374. + struct type *tqh_first; /* first element */ \
  46375. + struct type **tqh_last; /* addr of last next element */ \
  46376. +}
  46377. +
  46378. +#define DWC_TAILQ_HEAD_INITIALIZER(head) \
  46379. + { NULL, &(head).tqh_first }
  46380. +
  46381. +#define DWC_TAILQ_ENTRY(type) \
  46382. +struct { \
  46383. + struct type *tqe_next; /* next element */ \
  46384. + struct type **tqe_prev; /* address of previous next element */ \
  46385. +}
  46386. +
  46387. +/*
  46388. + * tail queue access methods
  46389. + */
  46390. +#define DWC_TAILQ_FIRST(head) ((head)->tqh_first)
  46391. +#define DWC_TAILQ_END(head) NULL
  46392. +#define DWC_TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
  46393. +#define DWC_TAILQ_LAST(head, headname) \
  46394. + (*(((struct headname *)((head)->tqh_last))->tqh_last))
  46395. +/* XXX */
  46396. +#define DWC_TAILQ_PREV(elm, headname, field) \
  46397. + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
  46398. +#define DWC_TAILQ_EMPTY(head) \
  46399. + (DWC_TAILQ_FIRST(head) == DWC_TAILQ_END(head))
  46400. +
  46401. +#define DWC_TAILQ_FOREACH(var, head, field) \
  46402. + for ((var) = DWC_TAILQ_FIRST(head); \
  46403. + (var) != DWC_TAILQ_END(head); \
  46404. + (var) = DWC_TAILQ_NEXT(var, field))
  46405. +
  46406. +#define DWC_TAILQ_FOREACH_REVERSE(var, head, headname, field) \
  46407. + for ((var) = DWC_TAILQ_LAST(head, headname); \
  46408. + (var) != DWC_TAILQ_END(head); \
  46409. + (var) = DWC_TAILQ_PREV(var, headname, field))
  46410. +
  46411. +/*
  46412. + * Tail queue functions.
  46413. + */
  46414. +#define DWC_TAILQ_INIT(head) do { \
  46415. + (head)->tqh_first = NULL; \
  46416. + (head)->tqh_last = &(head)->tqh_first; \
  46417. +} while (0)
  46418. +
  46419. +#define DWC_TAILQ_INSERT_HEAD(head, elm, field) do { \
  46420. + if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
  46421. + (head)->tqh_first->field.tqe_prev = \
  46422. + &(elm)->field.tqe_next; \
  46423. + else \
  46424. + (head)->tqh_last = &(elm)->field.tqe_next; \
  46425. + (head)->tqh_first = (elm); \
  46426. + (elm)->field.tqe_prev = &(head)->tqh_first; \
  46427. +} while (0)
  46428. +
  46429. +#define DWC_TAILQ_INSERT_TAIL(head, elm, field) do { \
  46430. + (elm)->field.tqe_next = NULL; \
  46431. + (elm)->field.tqe_prev = (head)->tqh_last; \
  46432. + *(head)->tqh_last = (elm); \
  46433. + (head)->tqh_last = &(elm)->field.tqe_next; \
  46434. +} while (0)
  46435. +
  46436. +#define DWC_TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
  46437. + if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
  46438. + (elm)->field.tqe_next->field.tqe_prev = \
  46439. + &(elm)->field.tqe_next; \
  46440. + else \
  46441. + (head)->tqh_last = &(elm)->field.tqe_next; \
  46442. + (listelm)->field.tqe_next = (elm); \
  46443. + (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
  46444. +} while (0)
  46445. +
  46446. +#define DWC_TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
  46447. + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
  46448. + (elm)->field.tqe_next = (listelm); \
  46449. + *(listelm)->field.tqe_prev = (elm); \
  46450. + (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
  46451. +} while (0)
  46452. +
  46453. +#define DWC_TAILQ_REMOVE(head, elm, field) do { \
  46454. + if (((elm)->field.tqe_next) != NULL) \
  46455. + (elm)->field.tqe_next->field.tqe_prev = \
  46456. + (elm)->field.tqe_prev; \
  46457. + else \
  46458. + (head)->tqh_last = (elm)->field.tqe_prev; \
  46459. + *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
  46460. +} while (0)
  46461. +
  46462. +#define DWC_TAILQ_REPLACE(head, elm, elm2, field) do { \
  46463. + if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \
  46464. + (elm2)->field.tqe_next->field.tqe_prev = \
  46465. + &(elm2)->field.tqe_next; \
  46466. + else \
  46467. + (head)->tqh_last = &(elm2)->field.tqe_next; \
  46468. + (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \
  46469. + *(elm2)->field.tqe_prev = (elm2); \
  46470. +} while (0)
  46471. +
  46472. +/*
  46473. + * Circular queue definitions.
  46474. + */
  46475. +#define DWC_CIRCLEQ_HEAD(name, type) \
  46476. +struct name { \
  46477. + struct type *cqh_first; /* first element */ \
  46478. + struct type *cqh_last; /* last element */ \
  46479. +}
  46480. +
  46481. +#define DWC_CIRCLEQ_HEAD_INITIALIZER(head) \
  46482. + { DWC_CIRCLEQ_END(&head), DWC_CIRCLEQ_END(&head) }
  46483. +
  46484. +#define DWC_CIRCLEQ_ENTRY(type) \
  46485. +struct { \
  46486. + struct type *cqe_next; /* next element */ \
  46487. + struct type *cqe_prev; /* previous element */ \
  46488. +}
  46489. +
  46490. +/*
  46491. + * Circular queue access methods
  46492. + */
  46493. +#define DWC_CIRCLEQ_FIRST(head) ((head)->cqh_first)
  46494. +#define DWC_CIRCLEQ_LAST(head) ((head)->cqh_last)
  46495. +#define DWC_CIRCLEQ_END(head) ((void *)(head))
  46496. +#define DWC_CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
  46497. +#define DWC_CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
  46498. +#define DWC_CIRCLEQ_EMPTY(head) \
  46499. + (DWC_CIRCLEQ_FIRST(head) == DWC_CIRCLEQ_END(head))
  46500. +
  46501. +#define DWC_CIRCLEQ_EMPTY_ENTRY(elm, field) (((elm)->field.cqe_next == NULL) && ((elm)->field.cqe_prev == NULL))
  46502. +
  46503. +#define DWC_CIRCLEQ_FOREACH(var, head, field) \
  46504. + for((var) = DWC_CIRCLEQ_FIRST(head); \
  46505. + (var) != DWC_CIRCLEQ_END(head); \
  46506. + (var) = DWC_CIRCLEQ_NEXT(var, field))
  46507. +
  46508. +#define DWC_CIRCLEQ_FOREACH_SAFE(var, var2, head, field) \
  46509. + for((var) = DWC_CIRCLEQ_FIRST(head), var2 = DWC_CIRCLEQ_NEXT(var, field); \
  46510. + (var) != DWC_CIRCLEQ_END(head); \
  46511. + (var) = var2, var2 = DWC_CIRCLEQ_NEXT(var, field))
  46512. +
  46513. +#define DWC_CIRCLEQ_FOREACH_REVERSE(var, head, field) \
  46514. + for((var) = DWC_CIRCLEQ_LAST(head); \
  46515. + (var) != DWC_CIRCLEQ_END(head); \
  46516. + (var) = DWC_CIRCLEQ_PREV(var, field))
  46517. +
  46518. +/*
  46519. + * Circular queue functions.
  46520. + */
  46521. +#define DWC_CIRCLEQ_INIT(head) do { \
  46522. + (head)->cqh_first = DWC_CIRCLEQ_END(head); \
  46523. + (head)->cqh_last = DWC_CIRCLEQ_END(head); \
  46524. +} while (0)
  46525. +
  46526. +#define DWC_CIRCLEQ_INIT_ENTRY(elm, field) do { \
  46527. + (elm)->field.cqe_next = NULL; \
  46528. + (elm)->field.cqe_prev = NULL; \
  46529. +} while (0)
  46530. +
  46531. +#define DWC_CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
  46532. + (elm)->field.cqe_next = (listelm)->field.cqe_next; \
  46533. + (elm)->field.cqe_prev = (listelm); \
  46534. + if ((listelm)->field.cqe_next == DWC_CIRCLEQ_END(head)) \
  46535. + (head)->cqh_last = (elm); \
  46536. + else \
  46537. + (listelm)->field.cqe_next->field.cqe_prev = (elm); \
  46538. + (listelm)->field.cqe_next = (elm); \
  46539. +} while (0)
  46540. +
  46541. +#define DWC_CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
  46542. + (elm)->field.cqe_next = (listelm); \
  46543. + (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
  46544. + if ((listelm)->field.cqe_prev == DWC_CIRCLEQ_END(head)) \
  46545. + (head)->cqh_first = (elm); \
  46546. + else \
  46547. + (listelm)->field.cqe_prev->field.cqe_next = (elm); \
  46548. + (listelm)->field.cqe_prev = (elm); \
  46549. +} while (0)
  46550. +
  46551. +#define DWC_CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
  46552. + (elm)->field.cqe_next = (head)->cqh_first; \
  46553. + (elm)->field.cqe_prev = DWC_CIRCLEQ_END(head); \
  46554. + if ((head)->cqh_last == DWC_CIRCLEQ_END(head)) \
  46555. + (head)->cqh_last = (elm); \
  46556. + else \
  46557. + (head)->cqh_first->field.cqe_prev = (elm); \
  46558. + (head)->cqh_first = (elm); \
  46559. +} while (0)
  46560. +
  46561. +#define DWC_CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
  46562. + (elm)->field.cqe_next = DWC_CIRCLEQ_END(head); \
  46563. + (elm)->field.cqe_prev = (head)->cqh_last; \
  46564. + if ((head)->cqh_first == DWC_CIRCLEQ_END(head)) \
  46565. + (head)->cqh_first = (elm); \
  46566. + else \
  46567. + (head)->cqh_last->field.cqe_next = (elm); \
  46568. + (head)->cqh_last = (elm); \
  46569. +} while (0)
  46570. +
  46571. +#define DWC_CIRCLEQ_REMOVE(head, elm, field) do { \
  46572. + if ((elm)->field.cqe_next == DWC_CIRCLEQ_END(head)) \
  46573. + (head)->cqh_last = (elm)->field.cqe_prev; \
  46574. + else \
  46575. + (elm)->field.cqe_next->field.cqe_prev = \
  46576. + (elm)->field.cqe_prev; \
  46577. + if ((elm)->field.cqe_prev == DWC_CIRCLEQ_END(head)) \
  46578. + (head)->cqh_first = (elm)->field.cqe_next; \
  46579. + else \
  46580. + (elm)->field.cqe_prev->field.cqe_next = \
  46581. + (elm)->field.cqe_next; \
  46582. +} while (0)
  46583. +
  46584. +#define DWC_CIRCLEQ_REMOVE_INIT(head, elm, field) do { \
  46585. + DWC_CIRCLEQ_REMOVE(head, elm, field); \
  46586. + DWC_CIRCLEQ_INIT_ENTRY(elm, field); \
  46587. +} while (0)
  46588. +
  46589. +#define DWC_CIRCLEQ_REPLACE(head, elm, elm2, field) do { \
  46590. + if (((elm2)->field.cqe_next = (elm)->field.cqe_next) == \
  46591. + DWC_CIRCLEQ_END(head)) \
  46592. + (head).cqh_last = (elm2); \
  46593. + else \
  46594. + (elm2)->field.cqe_next->field.cqe_prev = (elm2); \
  46595. + if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) == \
  46596. + DWC_CIRCLEQ_END(head)) \
  46597. + (head).cqh_first = (elm2); \
  46598. + else \
  46599. + (elm2)->field.cqe_prev->field.cqe_next = (elm2); \
  46600. +} while (0)
  46601. +
  46602. +#ifdef __cplusplus
  46603. +}
  46604. +#endif
  46605. +
  46606. +#endif /* _DWC_LIST_H_ */
  46607. diff -Nur linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_mem.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_mem.c
  46608. --- linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_mem.c 1970-01-01 01:00:00.000000000 +0100
  46609. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_mem.c 2014-04-13 17:33:11.000000000 +0200
  46610. @@ -0,0 +1,245 @@
  46611. +/* Memory Debugging */
  46612. +#ifdef DWC_DEBUG_MEMORY
  46613. +
  46614. +#include "dwc_os.h"
  46615. +#include "dwc_list.h"
  46616. +
  46617. +struct allocation {
  46618. + void *addr;
  46619. + void *ctx;
  46620. + char *func;
  46621. + int line;
  46622. + uint32_t size;
  46623. + int dma;
  46624. + DWC_CIRCLEQ_ENTRY(allocation) entry;
  46625. +};
  46626. +
  46627. +DWC_CIRCLEQ_HEAD(allocation_queue, allocation);
  46628. +
  46629. +struct allocation_manager {
  46630. + void *mem_ctx;
  46631. + struct allocation_queue allocations;
  46632. +
  46633. + /* statistics */
  46634. + int num;
  46635. + int num_freed;
  46636. + int num_active;
  46637. + uint32_t total;
  46638. + uint32_t cur;
  46639. + uint32_t max;
  46640. +};
  46641. +
  46642. +static struct allocation_manager *manager = NULL;
  46643. +
  46644. +static int add_allocation(void *ctx, uint32_t size, char const *func, int line, void *addr,
  46645. + int dma)
  46646. +{
  46647. + struct allocation *a;
  46648. +
  46649. + DWC_ASSERT(manager != NULL, "manager not allocated");
  46650. +
  46651. + a = __DWC_ALLOC_ATOMIC(manager->mem_ctx, sizeof(*a));
  46652. + if (!a) {
  46653. + return -DWC_E_NO_MEMORY;
  46654. + }
  46655. +
  46656. + a->func = __DWC_ALLOC_ATOMIC(manager->mem_ctx, DWC_STRLEN(func) + 1);
  46657. + if (!a->func) {
  46658. + __DWC_FREE(manager->mem_ctx, a);
  46659. + return -DWC_E_NO_MEMORY;
  46660. + }
  46661. +
  46662. + DWC_MEMCPY(a->func, func, DWC_STRLEN(func) + 1);
  46663. + a->addr = addr;
  46664. + a->ctx = ctx;
  46665. + a->line = line;
  46666. + a->size = size;
  46667. + a->dma = dma;
  46668. + DWC_CIRCLEQ_INSERT_TAIL(&manager->allocations, a, entry);
  46669. +
  46670. + /* Update stats */
  46671. + manager->num++;
  46672. + manager->num_active++;
  46673. + manager->total += size;
  46674. + manager->cur += size;
  46675. +
  46676. + if (manager->max < manager->cur) {
  46677. + manager->max = manager->cur;
  46678. + }
  46679. +
  46680. + return 0;
  46681. +}
  46682. +
  46683. +static struct allocation *find_allocation(void *ctx, void *addr)
  46684. +{
  46685. + struct allocation *a;
  46686. +
  46687. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  46688. + if (a->ctx == ctx && a->addr == addr) {
  46689. + return a;
  46690. + }
  46691. + }
  46692. +
  46693. + return NULL;
  46694. +}
  46695. +
  46696. +static void free_allocation(void *ctx, void *addr, char const *func, int line)
  46697. +{
  46698. + struct allocation *a = find_allocation(ctx, addr);
  46699. +
  46700. + if (!a) {
  46701. + DWC_ASSERT(0,
  46702. + "Free of address %p that was never allocated or already freed %s:%d",
  46703. + addr, func, line);
  46704. + return;
  46705. + }
  46706. +
  46707. + DWC_CIRCLEQ_REMOVE(&manager->allocations, a, entry);
  46708. +
  46709. + manager->num_active--;
  46710. + manager->num_freed++;
  46711. + manager->cur -= a->size;
  46712. + __DWC_FREE(manager->mem_ctx, a->func);
  46713. + __DWC_FREE(manager->mem_ctx, a);
  46714. +}
  46715. +
  46716. +int dwc_memory_debug_start(void *mem_ctx)
  46717. +{
  46718. + DWC_ASSERT(manager == NULL, "Memory debugging has already started\n");
  46719. +
  46720. + if (manager) {
  46721. + return -DWC_E_BUSY;
  46722. + }
  46723. +
  46724. + manager = __DWC_ALLOC(mem_ctx, sizeof(*manager));
  46725. + if (!manager) {
  46726. + return -DWC_E_NO_MEMORY;
  46727. + }
  46728. +
  46729. + DWC_CIRCLEQ_INIT(&manager->allocations);
  46730. + manager->mem_ctx = mem_ctx;
  46731. + manager->num = 0;
  46732. + manager->num_freed = 0;
  46733. + manager->num_active = 0;
  46734. + manager->total = 0;
  46735. + manager->cur = 0;
  46736. + manager->max = 0;
  46737. +
  46738. + return 0;
  46739. +}
  46740. +
  46741. +void dwc_memory_debug_stop(void)
  46742. +{
  46743. + struct allocation *a;
  46744. +
  46745. + dwc_memory_debug_report();
  46746. +
  46747. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  46748. + DWC_ERROR("Memory leaked from %s:%d\n", a->func, a->line);
  46749. + free_allocation(a->ctx, a->addr, NULL, -1);
  46750. + }
  46751. +
  46752. + __DWC_FREE(manager->mem_ctx, manager);
  46753. +}
  46754. +
  46755. +void dwc_memory_debug_report(void)
  46756. +{
  46757. + struct allocation *a;
  46758. +
  46759. + DWC_PRINTF("\n\n\n----------------- Memory Debugging Report -----------------\n\n");
  46760. + DWC_PRINTF("Num Allocations = %d\n", manager->num);
  46761. + DWC_PRINTF("Freed = %d\n", manager->num_freed);
  46762. + DWC_PRINTF("Active = %d\n", manager->num_active);
  46763. + DWC_PRINTF("Current Memory Used = %d\n", manager->cur);
  46764. + DWC_PRINTF("Total Memory Used = %d\n", manager->total);
  46765. + DWC_PRINTF("Maximum Memory Used at Once = %d\n", manager->max);
  46766. + DWC_PRINTF("Unfreed allocations:\n");
  46767. +
  46768. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  46769. + DWC_PRINTF(" addr=%p, size=%d from %s:%d, DMA=%d\n",
  46770. + a->addr, a->size, a->func, a->line, a->dma);
  46771. + }
  46772. +}
  46773. +
  46774. +/* The replacement functions */
  46775. +void *dwc_alloc_debug(void *mem_ctx, uint32_t size, char const *func, int line)
  46776. +{
  46777. + void *addr = __DWC_ALLOC(mem_ctx, size);
  46778. +
  46779. + if (!addr) {
  46780. + return NULL;
  46781. + }
  46782. +
  46783. + if (add_allocation(mem_ctx, size, func, line, addr, 0)) {
  46784. + __DWC_FREE(mem_ctx, addr);
  46785. + return NULL;
  46786. + }
  46787. +
  46788. + return addr;
  46789. +}
  46790. +
  46791. +void *dwc_alloc_atomic_debug(void *mem_ctx, uint32_t size, char const *func,
  46792. + int line)
  46793. +{
  46794. + void *addr = __DWC_ALLOC_ATOMIC(mem_ctx, size);
  46795. +
  46796. + if (!addr) {
  46797. + return NULL;
  46798. + }
  46799. +
  46800. + if (add_allocation(mem_ctx, size, func, line, addr, 0)) {
  46801. + __DWC_FREE(mem_ctx, addr);
  46802. + return NULL;
  46803. + }
  46804. +
  46805. + return addr;
  46806. +}
  46807. +
  46808. +void dwc_free_debug(void *mem_ctx, void *addr, char const *func, int line)
  46809. +{
  46810. + free_allocation(mem_ctx, addr, func, line);
  46811. + __DWC_FREE(mem_ctx, addr);
  46812. +}
  46813. +
  46814. +void *dwc_dma_alloc_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  46815. + char const *func, int line)
  46816. +{
  46817. + void *addr = __DWC_DMA_ALLOC(dma_ctx, size, dma_addr);
  46818. +
  46819. + if (!addr) {
  46820. + return NULL;
  46821. + }
  46822. +
  46823. + if (add_allocation(dma_ctx, size, func, line, addr, 1)) {
  46824. + __DWC_DMA_FREE(dma_ctx, size, addr, *dma_addr);
  46825. + return NULL;
  46826. + }
  46827. +
  46828. + return addr;
  46829. +}
  46830. +
  46831. +void *dwc_dma_alloc_atomic_debug(void *dma_ctx, uint32_t size,
  46832. + dwc_dma_t *dma_addr, char const *func, int line)
  46833. +{
  46834. + void *addr = __DWC_DMA_ALLOC_ATOMIC(dma_ctx, size, dma_addr);
  46835. +
  46836. + if (!addr) {
  46837. + return NULL;
  46838. + }
  46839. +
  46840. + if (add_allocation(dma_ctx, size, func, line, addr, 1)) {
  46841. + __DWC_DMA_FREE(dma_ctx, size, addr, *dma_addr);
  46842. + return NULL;
  46843. + }
  46844. +
  46845. + return addr;
  46846. +}
  46847. +
  46848. +void dwc_dma_free_debug(void *dma_ctx, uint32_t size, void *virt_addr,
  46849. + dwc_dma_t dma_addr, char const *func, int line)
  46850. +{
  46851. + free_allocation(dma_ctx, virt_addr, func, line);
  46852. + __DWC_DMA_FREE(dma_ctx, size, virt_addr, dma_addr);
  46853. +}
  46854. +
  46855. +#endif /* DWC_DEBUG_MEMORY */
  46856. diff -Nur linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_modpow.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_modpow.c
  46857. --- linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_modpow.c 1970-01-01 01:00:00.000000000 +0100
  46858. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_modpow.c 2014-07-07 10:45:43.000000000 +0200
  46859. @@ -0,0 +1,636 @@
  46860. +/* Bignum routines adapted from PUTTY sources. PuTTY copyright notice follows.
  46861. + *
  46862. + * PuTTY is copyright 1997-2007 Simon Tatham.
  46863. + *
  46864. + * Portions copyright Robert de Bath, Joris van Rantwijk, Delian
  46865. + * Delchev, Andreas Schultz, Jeroen Massar, Wez Furlong, Nicolas Barry,
  46866. + * Justin Bradford, Ben Harris, Malcolm Smith, Ahmad Khalifa, Markus
  46867. + * Kuhn, and CORE SDI S.A.
  46868. + *
  46869. + * Permission is hereby granted, free of charge, to any person
  46870. + * obtaining a copy of this software and associated documentation files
  46871. + * (the "Software"), to deal in the Software without restriction,
  46872. + * including without limitation the rights to use, copy, modify, merge,
  46873. + * publish, distribute, sublicense, and/or sell copies of the Software,
  46874. + * and to permit persons to whom the Software is furnished to do so,
  46875. + * subject to the following conditions:
  46876. + *
  46877. + * The above copyright notice and this permission notice shall be
  46878. + * included in all copies or substantial portions of the Software.
  46879. +
  46880. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  46881. + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  46882. + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  46883. + * NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE
  46884. + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  46885. + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  46886. + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  46887. + *
  46888. + */
  46889. +#ifdef DWC_CRYPTOLIB
  46890. +
  46891. +#ifndef CONFIG_MACH_IPMATE
  46892. +
  46893. +#include "dwc_modpow.h"
  46894. +
  46895. +#define BIGNUM_INT_MASK 0xFFFFFFFFUL
  46896. +#define BIGNUM_TOP_BIT 0x80000000UL
  46897. +#define BIGNUM_INT_BITS 32
  46898. +
  46899. +
  46900. +static void *snmalloc(void *mem_ctx, size_t n, size_t size)
  46901. +{
  46902. + void *p;
  46903. + size *= n;
  46904. + if (size == 0) size = 1;
  46905. + p = dwc_alloc(mem_ctx, size);
  46906. + return p;
  46907. +}
  46908. +
  46909. +#define snewn(ctx, n, type) ((type *)snmalloc((ctx), (n), sizeof(type)))
  46910. +#define sfree dwc_free
  46911. +
  46912. +/*
  46913. + * Usage notes:
  46914. + * * Do not call the DIVMOD_WORD macro with expressions such as array
  46915. + * subscripts, as some implementations object to this (see below).
  46916. + * * Note that none of the division methods below will cope if the
  46917. + * quotient won't fit into BIGNUM_INT_BITS. Callers should be careful
  46918. + * to avoid this case.
  46919. + * If this condition occurs, in the case of the x86 DIV instruction,
  46920. + * an overflow exception will occur, which (according to a correspondent)
  46921. + * will manifest on Windows as something like
  46922. + * 0xC0000095: Integer overflow
  46923. + * The C variant won't give the right answer, either.
  46924. + */
  46925. +
  46926. +#define MUL_WORD(w1, w2) ((BignumDblInt)w1 * w2)
  46927. +
  46928. +#if defined __GNUC__ && defined __i386__
  46929. +#define DIVMOD_WORD(q, r, hi, lo, w) \
  46930. + __asm__("div %2" : \
  46931. + "=d" (r), "=a" (q) : \
  46932. + "r" (w), "d" (hi), "a" (lo))
  46933. +#else
  46934. +#define DIVMOD_WORD(q, r, hi, lo, w) do { \
  46935. + BignumDblInt n = (((BignumDblInt)hi) << BIGNUM_INT_BITS) | lo; \
  46936. + q = n / w; \
  46937. + r = n % w; \
  46938. +} while (0)
  46939. +#endif
  46940. +
  46941. +// q = n / w;
  46942. +// r = n % w;
  46943. +
  46944. +#define BIGNUM_INT_BYTES (BIGNUM_INT_BITS / 8)
  46945. +
  46946. +#define BIGNUM_INTERNAL
  46947. +
  46948. +static Bignum newbn(void *mem_ctx, int length)
  46949. +{
  46950. + Bignum b = snewn(mem_ctx, length + 1, BignumInt);
  46951. + //if (!b)
  46952. + //abort(); /* FIXME */
  46953. + DWC_MEMSET(b, 0, (length + 1) * sizeof(*b));
  46954. + b[0] = length;
  46955. + return b;
  46956. +}
  46957. +
  46958. +void freebn(void *mem_ctx, Bignum b)
  46959. +{
  46960. + /*
  46961. + * Burn the evidence, just in case.
  46962. + */
  46963. + DWC_MEMSET(b, 0, sizeof(b[0]) * (b[0] + 1));
  46964. + sfree(mem_ctx, b);
  46965. +}
  46966. +
  46967. +/*
  46968. + * Compute c = a * b.
  46969. + * Input is in the first len words of a and b.
  46970. + * Result is returned in the first 2*len words of c.
  46971. + */
  46972. +static void internal_mul(BignumInt *a, BignumInt *b,
  46973. + BignumInt *c, int len)
  46974. +{
  46975. + int i, j;
  46976. + BignumDblInt t;
  46977. +
  46978. + for (j = 0; j < 2 * len; j++)
  46979. + c[j] = 0;
  46980. +
  46981. + for (i = len - 1; i >= 0; i--) {
  46982. + t = 0;
  46983. + for (j = len - 1; j >= 0; j--) {
  46984. + t += MUL_WORD(a[i], (BignumDblInt) b[j]);
  46985. + t += (BignumDblInt) c[i + j + 1];
  46986. + c[i + j + 1] = (BignumInt) t;
  46987. + t = t >> BIGNUM_INT_BITS;
  46988. + }
  46989. + c[i] = (BignumInt) t;
  46990. + }
  46991. +}
  46992. +
  46993. +static void internal_add_shifted(BignumInt *number,
  46994. + unsigned n, int shift)
  46995. +{
  46996. + int word = 1 + (shift / BIGNUM_INT_BITS);
  46997. + int bshift = shift % BIGNUM_INT_BITS;
  46998. + BignumDblInt addend;
  46999. +
  47000. + addend = (BignumDblInt)n << bshift;
  47001. +
  47002. + while (addend) {
  47003. + addend += number[word];
  47004. + number[word] = (BignumInt) addend & BIGNUM_INT_MASK;
  47005. + addend >>= BIGNUM_INT_BITS;
  47006. + word++;
  47007. + }
  47008. +}
  47009. +
  47010. +/*
  47011. + * Compute a = a % m.
  47012. + * Input in first alen words of a and first mlen words of m.
  47013. + * Output in first alen words of a
  47014. + * (of which first alen-mlen words will be zero).
  47015. + * The MSW of m MUST have its high bit set.
  47016. + * Quotient is accumulated in the `quotient' array, which is a Bignum
  47017. + * rather than the internal bigendian format. Quotient parts are shifted
  47018. + * left by `qshift' before adding into quot.
  47019. + */
  47020. +static void internal_mod(BignumInt *a, int alen,
  47021. + BignumInt *m, int mlen,
  47022. + BignumInt *quot, int qshift)
  47023. +{
  47024. + BignumInt m0, m1;
  47025. + unsigned int h;
  47026. + int i, k;
  47027. +
  47028. + m0 = m[0];
  47029. + if (mlen > 1)
  47030. + m1 = m[1];
  47031. + else
  47032. + m1 = 0;
  47033. +
  47034. + for (i = 0; i <= alen - mlen; i++) {
  47035. + BignumDblInt t;
  47036. + unsigned int q, r, c, ai1;
  47037. +
  47038. + if (i == 0) {
  47039. + h = 0;
  47040. + } else {
  47041. + h = a[i - 1];
  47042. + a[i - 1] = 0;
  47043. + }
  47044. +
  47045. + if (i == alen - 1)
  47046. + ai1 = 0;
  47047. + else
  47048. + ai1 = a[i + 1];
  47049. +
  47050. + /* Find q = h:a[i] / m0 */
  47051. + if (h >= m0) {
  47052. + /*
  47053. + * Special case.
  47054. + *
  47055. + * To illustrate it, suppose a BignumInt is 8 bits, and
  47056. + * we are dividing (say) A1:23:45:67 by A1:B2:C3. Then
  47057. + * our initial division will be 0xA123 / 0xA1, which
  47058. + * will give a quotient of 0x100 and a divide overflow.
  47059. + * However, the invariants in this division algorithm
  47060. + * are not violated, since the full number A1:23:... is
  47061. + * _less_ than the quotient prefix A1:B2:... and so the
  47062. + * following correction loop would have sorted it out.
  47063. + *
  47064. + * In this situation we set q to be the largest
  47065. + * quotient we _can_ stomach (0xFF, of course).
  47066. + */
  47067. + q = BIGNUM_INT_MASK;
  47068. + } else {
  47069. + /* Macro doesn't want an array subscript expression passed
  47070. + * into it (see definition), so use a temporary. */
  47071. + BignumInt tmplo = a[i];
  47072. + DIVMOD_WORD(q, r, h, tmplo, m0);
  47073. +
  47074. + /* Refine our estimate of q by looking at
  47075. + h:a[i]:a[i+1] / m0:m1 */
  47076. + t = MUL_WORD(m1, q);
  47077. + if (t > ((BignumDblInt) r << BIGNUM_INT_BITS) + ai1) {
  47078. + q--;
  47079. + t -= m1;
  47080. + r = (r + m0) & BIGNUM_INT_MASK; /* overflow? */
  47081. + if (r >= (BignumDblInt) m0 &&
  47082. + t > ((BignumDblInt) r << BIGNUM_INT_BITS) + ai1) q--;
  47083. + }
  47084. + }
  47085. +
  47086. + /* Subtract q * m from a[i...] */
  47087. + c = 0;
  47088. + for (k = mlen - 1; k >= 0; k--) {
  47089. + t = MUL_WORD(q, m[k]);
  47090. + t += c;
  47091. + c = (unsigned)(t >> BIGNUM_INT_BITS);
  47092. + if ((BignumInt) t > a[i + k])
  47093. + c++;
  47094. + a[i + k] -= (BignumInt) t;
  47095. + }
  47096. +
  47097. + /* Add back m in case of borrow */
  47098. + if (c != h) {
  47099. + t = 0;
  47100. + for (k = mlen - 1; k >= 0; k--) {
  47101. + t += m[k];
  47102. + t += a[i + k];
  47103. + a[i + k] = (BignumInt) t;
  47104. + t = t >> BIGNUM_INT_BITS;
  47105. + }
  47106. + q--;
  47107. + }
  47108. + if (quot)
  47109. + internal_add_shifted(quot, q, qshift + BIGNUM_INT_BITS * (alen - mlen - i));
  47110. + }
  47111. +}
  47112. +
  47113. +/*
  47114. + * Compute p % mod.
  47115. + * The most significant word of mod MUST be non-zero.
  47116. + * We assume that the result array is the same size as the mod array.
  47117. + * We optionally write out a quotient if `quotient' is non-NULL.
  47118. + * We can avoid writing out the result if `result' is NULL.
  47119. + */
  47120. +void bigdivmod(void *mem_ctx, Bignum p, Bignum mod, Bignum result, Bignum quotient)
  47121. +{
  47122. + BignumInt *n, *m;
  47123. + int mshift;
  47124. + int plen, mlen, i, j;
  47125. +
  47126. + /* Allocate m of size mlen, copy mod to m */
  47127. + /* We use big endian internally */
  47128. + mlen = mod[0];
  47129. + m = snewn(mem_ctx, mlen, BignumInt);
  47130. + //if (!m)
  47131. + //abort(); /* FIXME */
  47132. + for (j = 0; j < mlen; j++)
  47133. + m[j] = mod[mod[0] - j];
  47134. +
  47135. + /* Shift m left to make msb bit set */
  47136. + for (mshift = 0; mshift < BIGNUM_INT_BITS-1; mshift++)
  47137. + if ((m[0] << mshift) & BIGNUM_TOP_BIT)
  47138. + break;
  47139. + if (mshift) {
  47140. + for (i = 0; i < mlen - 1; i++)
  47141. + m[i] = (m[i] << mshift) | (m[i + 1] >> (BIGNUM_INT_BITS - mshift));
  47142. + m[mlen - 1] = m[mlen - 1] << mshift;
  47143. + }
  47144. +
  47145. + plen = p[0];
  47146. + /* Ensure plen > mlen */
  47147. + if (plen <= mlen)
  47148. + plen = mlen + 1;
  47149. +
  47150. + /* Allocate n of size plen, copy p to n */
  47151. + n = snewn(mem_ctx, plen, BignumInt);
  47152. + //if (!n)
  47153. + //abort(); /* FIXME */
  47154. + for (j = 0; j < plen; j++)
  47155. + n[j] = 0;
  47156. + for (j = 1; j <= (int)p[0]; j++)
  47157. + n[plen - j] = p[j];
  47158. +
  47159. + /* Main computation */
  47160. + internal_mod(n, plen, m, mlen, quotient, mshift);
  47161. +
  47162. + /* Fixup result in case the modulus was shifted */
  47163. + if (mshift) {
  47164. + for (i = plen - mlen - 1; i < plen - 1; i++)
  47165. + n[i] = (n[i] << mshift) | (n[i + 1] >> (BIGNUM_INT_BITS - mshift));
  47166. + n[plen - 1] = n[plen - 1] << mshift;
  47167. + internal_mod(n, plen, m, mlen, quotient, 0);
  47168. + for (i = plen - 1; i >= plen - mlen; i--)
  47169. + n[i] = (n[i] >> mshift) | (n[i - 1] << (BIGNUM_INT_BITS - mshift));
  47170. + }
  47171. +
  47172. + /* Copy result to buffer */
  47173. + if (result) {
  47174. + for (i = 1; i <= (int)result[0]; i++) {
  47175. + int j = plen - i;
  47176. + result[i] = j >= 0 ? n[j] : 0;
  47177. + }
  47178. + }
  47179. +
  47180. + /* Free temporary arrays */
  47181. + for (i = 0; i < mlen; i++)
  47182. + m[i] = 0;
  47183. + sfree(mem_ctx, m);
  47184. + for (i = 0; i < plen; i++)
  47185. + n[i] = 0;
  47186. + sfree(mem_ctx, n);
  47187. +}
  47188. +
  47189. +/*
  47190. + * Simple remainder.
  47191. + */
  47192. +Bignum bigmod(void *mem_ctx, Bignum a, Bignum b)
  47193. +{
  47194. + Bignum r = newbn(mem_ctx, b[0]);
  47195. + bigdivmod(mem_ctx, a, b, r, NULL);
  47196. + return r;
  47197. +}
  47198. +
  47199. +/*
  47200. + * Compute (base ^ exp) % mod.
  47201. + */
  47202. +Bignum dwc_modpow(void *mem_ctx, Bignum base_in, Bignum exp, Bignum mod)
  47203. +{
  47204. + BignumInt *a, *b, *n, *m;
  47205. + int mshift;
  47206. + int mlen, i, j;
  47207. + Bignum base, result;
  47208. +
  47209. + /*
  47210. + * The most significant word of mod needs to be non-zero. It
  47211. + * should already be, but let's make sure.
  47212. + */
  47213. + //assert(mod[mod[0]] != 0);
  47214. +
  47215. + /*
  47216. + * Make sure the base is smaller than the modulus, by reducing
  47217. + * it modulo the modulus if not.
  47218. + */
  47219. + base = bigmod(mem_ctx, base_in, mod);
  47220. +
  47221. + /* Allocate m of size mlen, copy mod to m */
  47222. + /* We use big endian internally */
  47223. + mlen = mod[0];
  47224. + m = snewn(mem_ctx, mlen, BignumInt);
  47225. + //if (!m)
  47226. + //abort(); /* FIXME */
  47227. + for (j = 0; j < mlen; j++)
  47228. + m[j] = mod[mod[0] - j];
  47229. +
  47230. + /* Shift m left to make msb bit set */
  47231. + for (mshift = 0; mshift < BIGNUM_INT_BITS - 1; mshift++)
  47232. + if ((m[0] << mshift) & BIGNUM_TOP_BIT)
  47233. + break;
  47234. + if (mshift) {
  47235. + for (i = 0; i < mlen - 1; i++)
  47236. + m[i] =
  47237. + (m[i] << mshift) | (m[i + 1] >>
  47238. + (BIGNUM_INT_BITS - mshift));
  47239. + m[mlen - 1] = m[mlen - 1] << mshift;
  47240. + }
  47241. +
  47242. + /* Allocate n of size mlen, copy base to n */
  47243. + n = snewn(mem_ctx, mlen, BignumInt);
  47244. + //if (!n)
  47245. + //abort(); /* FIXME */
  47246. + i = mlen - base[0];
  47247. + for (j = 0; j < i; j++)
  47248. + n[j] = 0;
  47249. + for (j = 0; j < base[0]; j++)
  47250. + n[i + j] = base[base[0] - j];
  47251. +
  47252. + /* Allocate a and b of size 2*mlen. Set a = 1 */
  47253. + a = snewn(mem_ctx, 2 * mlen, BignumInt);
  47254. + //if (!a)
  47255. + //abort(); /* FIXME */
  47256. + b = snewn(mem_ctx, 2 * mlen, BignumInt);
  47257. + //if (!b)
  47258. + //abort(); /* FIXME */
  47259. + for (i = 0; i < 2 * mlen; i++)
  47260. + a[i] = 0;
  47261. + a[2 * mlen - 1] = 1;
  47262. +
  47263. + /* Skip leading zero bits of exp. */
  47264. + i = 0;
  47265. + j = BIGNUM_INT_BITS - 1;
  47266. + while (i < exp[0] && (exp[exp[0] - i] & (1 << j)) == 0) {
  47267. + j--;
  47268. + if (j < 0) {
  47269. + i++;
  47270. + j = BIGNUM_INT_BITS - 1;
  47271. + }
  47272. + }
  47273. +
  47274. + /* Main computation */
  47275. + while (i < exp[0]) {
  47276. + while (j >= 0) {
  47277. + internal_mul(a + mlen, a + mlen, b, mlen);
  47278. + internal_mod(b, mlen * 2, m, mlen, NULL, 0);
  47279. + if ((exp[exp[0] - i] & (1 << j)) != 0) {
  47280. + internal_mul(b + mlen, n, a, mlen);
  47281. + internal_mod(a, mlen * 2, m, mlen, NULL, 0);
  47282. + } else {
  47283. + BignumInt *t;
  47284. + t = a;
  47285. + a = b;
  47286. + b = t;
  47287. + }
  47288. + j--;
  47289. + }
  47290. + i++;
  47291. + j = BIGNUM_INT_BITS - 1;
  47292. + }
  47293. +
  47294. + /* Fixup result in case the modulus was shifted */
  47295. + if (mshift) {
  47296. + for (i = mlen - 1; i < 2 * mlen - 1; i++)
  47297. + a[i] =
  47298. + (a[i] << mshift) | (a[i + 1] >>
  47299. + (BIGNUM_INT_BITS - mshift));
  47300. + a[2 * mlen - 1] = a[2 * mlen - 1] << mshift;
  47301. + internal_mod(a, mlen * 2, m, mlen, NULL, 0);
  47302. + for (i = 2 * mlen - 1; i >= mlen; i--)
  47303. + a[i] =
  47304. + (a[i] >> mshift) | (a[i - 1] <<
  47305. + (BIGNUM_INT_BITS - mshift));
  47306. + }
  47307. +
  47308. + /* Copy result to buffer */
  47309. + result = newbn(mem_ctx, mod[0]);
  47310. + for (i = 0; i < mlen; i++)
  47311. + result[result[0] - i] = a[i + mlen];
  47312. + while (result[0] > 1 && result[result[0]] == 0)
  47313. + result[0]--;
  47314. +
  47315. + /* Free temporary arrays */
  47316. + for (i = 0; i < 2 * mlen; i++)
  47317. + a[i] = 0;
  47318. + sfree(mem_ctx, a);
  47319. + for (i = 0; i < 2 * mlen; i++)
  47320. + b[i] = 0;
  47321. + sfree(mem_ctx, b);
  47322. + for (i = 0; i < mlen; i++)
  47323. + m[i] = 0;
  47324. + sfree(mem_ctx, m);
  47325. + for (i = 0; i < mlen; i++)
  47326. + n[i] = 0;
  47327. + sfree(mem_ctx, n);
  47328. +
  47329. + freebn(mem_ctx, base);
  47330. +
  47331. + return result;
  47332. +}
  47333. +
  47334. +
  47335. +#ifdef UNITTEST
  47336. +
  47337. +static __u32 dh_p[] = {
  47338. + 96,
  47339. + 0xFFFFFFFF,
  47340. + 0xFFFFFFFF,
  47341. + 0xA93AD2CA,
  47342. + 0x4B82D120,
  47343. + 0xE0FD108E,
  47344. + 0x43DB5BFC,
  47345. + 0x74E5AB31,
  47346. + 0x08E24FA0,
  47347. + 0xBAD946E2,
  47348. + 0x770988C0,
  47349. + 0x7A615D6C,
  47350. + 0xBBE11757,
  47351. + 0x177B200C,
  47352. + 0x521F2B18,
  47353. + 0x3EC86A64,
  47354. + 0xD8760273,
  47355. + 0xD98A0864,
  47356. + 0xF12FFA06,
  47357. + 0x1AD2EE6B,
  47358. + 0xCEE3D226,
  47359. + 0x4A25619D,
  47360. + 0x1E8C94E0,
  47361. + 0xDB0933D7,
  47362. + 0xABF5AE8C,
  47363. + 0xA6E1E4C7,
  47364. + 0xB3970F85,
  47365. + 0x5D060C7D,
  47366. + 0x8AEA7157,
  47367. + 0x58DBEF0A,
  47368. + 0xECFB8504,
  47369. + 0xDF1CBA64,
  47370. + 0xA85521AB,
  47371. + 0x04507A33,
  47372. + 0xAD33170D,
  47373. + 0x8AAAC42D,
  47374. + 0x15728E5A,
  47375. + 0x98FA0510,
  47376. + 0x15D22618,
  47377. + 0xEA956AE5,
  47378. + 0x3995497C,
  47379. + 0x95581718,
  47380. + 0xDE2BCBF6,
  47381. + 0x6F4C52C9,
  47382. + 0xB5C55DF0,
  47383. + 0xEC07A28F,
  47384. + 0x9B2783A2,
  47385. + 0x180E8603,
  47386. + 0xE39E772C,
  47387. + 0x2E36CE3B,
  47388. + 0x32905E46,
  47389. + 0xCA18217C,
  47390. + 0xF1746C08,
  47391. + 0x4ABC9804,
  47392. + 0x670C354E,
  47393. + 0x7096966D,
  47394. + 0x9ED52907,
  47395. + 0x208552BB,
  47396. + 0x1C62F356,
  47397. + 0xDCA3AD96,
  47398. + 0x83655D23,
  47399. + 0xFD24CF5F,
  47400. + 0x69163FA8,
  47401. + 0x1C55D39A,
  47402. + 0x98DA4836,
  47403. + 0xA163BF05,
  47404. + 0xC2007CB8,
  47405. + 0xECE45B3D,
  47406. + 0x49286651,
  47407. + 0x7C4B1FE6,
  47408. + 0xAE9F2411,
  47409. + 0x5A899FA5,
  47410. + 0xEE386BFB,
  47411. + 0xF406B7ED,
  47412. + 0x0BFF5CB6,
  47413. + 0xA637ED6B,
  47414. + 0xF44C42E9,
  47415. + 0x625E7EC6,
  47416. + 0xE485B576,
  47417. + 0x6D51C245,
  47418. + 0x4FE1356D,
  47419. + 0xF25F1437,
  47420. + 0x302B0A6D,
  47421. + 0xCD3A431B,
  47422. + 0xEF9519B3,
  47423. + 0x8E3404DD,
  47424. + 0x514A0879,
  47425. + 0x3B139B22,
  47426. + 0x020BBEA6,
  47427. + 0x8A67CC74,
  47428. + 0x29024E08,
  47429. + 0x80DC1CD1,
  47430. + 0xC4C6628B,
  47431. + 0x2168C234,
  47432. + 0xC90FDAA2,
  47433. + 0xFFFFFFFF,
  47434. + 0xFFFFFFFF,
  47435. +};
  47436. +
  47437. +static __u32 dh_a[] = {
  47438. + 8,
  47439. + 0xdf367516,
  47440. + 0x86459caa,
  47441. + 0xe2d459a4,
  47442. + 0xd910dae0,
  47443. + 0x8a8b5e37,
  47444. + 0x67ab31c6,
  47445. + 0xf0b55ea9,
  47446. + 0x440051d6,
  47447. +};
  47448. +
  47449. +static __u32 dh_b[] = {
  47450. + 8,
  47451. + 0xded92656,
  47452. + 0xe07a048a,
  47453. + 0x6fa452cd,
  47454. + 0x2df89d30,
  47455. + 0xc75f1b0f,
  47456. + 0x8ce3578f,
  47457. + 0x7980a324,
  47458. + 0x5daec786,
  47459. +};
  47460. +
  47461. +static __u32 dh_g[] = {
  47462. + 1,
  47463. + 2,
  47464. +};
  47465. +
  47466. +int main(void)
  47467. +{
  47468. + int i;
  47469. + __u32 *k;
  47470. + k = dwc_modpow(NULL, dh_g, dh_a, dh_p);
  47471. +
  47472. + printf("\n\n");
  47473. + for (i=0; i<k[0]; i++) {
  47474. + __u32 word32 = k[k[0] - i];
  47475. + __u16 l = word32 & 0xffff;
  47476. + __u16 m = (word32 & 0xffff0000) >> 16;
  47477. + printf("%04x %04x ", m, l);
  47478. + if (!((i + 1)%13)) printf("\n");
  47479. + }
  47480. + printf("\n\n");
  47481. +
  47482. + if ((k[0] == 0x60) && (k[1] == 0x28e490e5) && (k[0x60] == 0x5a0d3d4e)) {
  47483. + printf("PASS\n\n");
  47484. + }
  47485. + else {
  47486. + printf("FAIL\n\n");
  47487. + }
  47488. +
  47489. +}
  47490. +
  47491. +#endif /* UNITTEST */
  47492. +
  47493. +#endif /* CONFIG_MACH_IPMATE */
  47494. +
  47495. +#endif /*DWC_CRYPTOLIB */
  47496. diff -Nur linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_modpow.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_modpow.h
  47497. --- linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_modpow.h 1970-01-01 01:00:00.000000000 +0100
  47498. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_modpow.h 2014-04-13 17:33:11.000000000 +0200
  47499. @@ -0,0 +1,34 @@
  47500. +/*
  47501. + * dwc_modpow.h
  47502. + * See dwc_modpow.c for license and changes
  47503. + */
  47504. +#ifndef _DWC_MODPOW_H
  47505. +#define _DWC_MODPOW_H
  47506. +
  47507. +#ifdef __cplusplus
  47508. +extern "C" {
  47509. +#endif
  47510. +
  47511. +#include "dwc_os.h"
  47512. +
  47513. +/** @file
  47514. + *
  47515. + * This file defines the module exponentiation function which is only used
  47516. + * internally by the DWC UWB modules for calculation of PKs during numeric
  47517. + * association. The routine is taken from the PUTTY, an open source terminal
  47518. + * emulator. The PUTTY License is preserved in the dwc_modpow.c file.
  47519. + *
  47520. + */
  47521. +
  47522. +typedef uint32_t BignumInt;
  47523. +typedef uint64_t BignumDblInt;
  47524. +typedef BignumInt *Bignum;
  47525. +
  47526. +/* Compute modular exponentiaion */
  47527. +extern Bignum dwc_modpow(void *mem_ctx, Bignum base_in, Bignum exp, Bignum mod);
  47528. +
  47529. +#ifdef __cplusplus
  47530. +}
  47531. +#endif
  47532. +
  47533. +#endif /* _LINUX_BIGNUM_H */
  47534. diff -Nur linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_notifier.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_notifier.c
  47535. --- linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_notifier.c 1970-01-01 01:00:00.000000000 +0100
  47536. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_notifier.c 2014-04-13 17:33:11.000000000 +0200
  47537. @@ -0,0 +1,319 @@
  47538. +#ifdef DWC_NOTIFYLIB
  47539. +
  47540. +#include "dwc_notifier.h"
  47541. +#include "dwc_list.h"
  47542. +
  47543. +typedef struct dwc_observer {
  47544. + void *observer;
  47545. + dwc_notifier_callback_t callback;
  47546. + void *data;
  47547. + char *notification;
  47548. + DWC_CIRCLEQ_ENTRY(dwc_observer) list_entry;
  47549. +} observer_t;
  47550. +
  47551. +DWC_CIRCLEQ_HEAD(observer_queue, dwc_observer);
  47552. +
  47553. +typedef struct dwc_notifier {
  47554. + void *mem_ctx;
  47555. + void *object;
  47556. + struct observer_queue observers;
  47557. + DWC_CIRCLEQ_ENTRY(dwc_notifier) list_entry;
  47558. +} notifier_t;
  47559. +
  47560. +DWC_CIRCLEQ_HEAD(notifier_queue, dwc_notifier);
  47561. +
  47562. +typedef struct manager {
  47563. + void *mem_ctx;
  47564. + void *wkq_ctx;
  47565. + dwc_workq_t *wq;
  47566. +// dwc_mutex_t *mutex;
  47567. + struct notifier_queue notifiers;
  47568. +} manager_t;
  47569. +
  47570. +static manager_t *manager = NULL;
  47571. +
  47572. +static int create_manager(void *mem_ctx, void *wkq_ctx)
  47573. +{
  47574. + manager = dwc_alloc(mem_ctx, sizeof(manager_t));
  47575. + if (!manager) {
  47576. + return -DWC_E_NO_MEMORY;
  47577. + }
  47578. +
  47579. + DWC_CIRCLEQ_INIT(&manager->notifiers);
  47580. +
  47581. + manager->wq = dwc_workq_alloc(wkq_ctx, "DWC Notification WorkQ");
  47582. + if (!manager->wq) {
  47583. + return -DWC_E_NO_MEMORY;
  47584. + }
  47585. +
  47586. + return 0;
  47587. +}
  47588. +
  47589. +static void free_manager(void)
  47590. +{
  47591. + dwc_workq_free(manager->wq);
  47592. +
  47593. + /* All notifiers must have unregistered themselves before this module
  47594. + * can be removed. Hitting this assertion indicates a programmer
  47595. + * error. */
  47596. + DWC_ASSERT(DWC_CIRCLEQ_EMPTY(&manager->notifiers),
  47597. + "Notification manager being freed before all notifiers have been removed");
  47598. + dwc_free(manager->mem_ctx, manager);
  47599. +}
  47600. +
  47601. +#ifdef DEBUG
  47602. +static void dump_manager(void)
  47603. +{
  47604. + notifier_t *n;
  47605. + observer_t *o;
  47606. +
  47607. + DWC_ASSERT(manager, "Notification manager not found");
  47608. +
  47609. + DWC_DEBUG("List of all notifiers and observers:\n");
  47610. + DWC_CIRCLEQ_FOREACH(n, &manager->notifiers, list_entry) {
  47611. + DWC_DEBUG("Notifier %p has observers:\n", n->object);
  47612. + DWC_CIRCLEQ_FOREACH(o, &n->observers, list_entry) {
  47613. + DWC_DEBUG(" %p watching %s\n", o->observer, o->notification);
  47614. + }
  47615. + }
  47616. +}
  47617. +#else
  47618. +#define dump_manager(...)
  47619. +#endif
  47620. +
  47621. +static observer_t *alloc_observer(void *mem_ctx, void *observer, char *notification,
  47622. + dwc_notifier_callback_t callback, void *data)
  47623. +{
  47624. + observer_t *new_observer = dwc_alloc(mem_ctx, sizeof(observer_t));
  47625. +
  47626. + if (!new_observer) {
  47627. + return NULL;
  47628. + }
  47629. +
  47630. + DWC_CIRCLEQ_INIT_ENTRY(new_observer, list_entry);
  47631. + new_observer->observer = observer;
  47632. + new_observer->notification = notification;
  47633. + new_observer->callback = callback;
  47634. + new_observer->data = data;
  47635. + return new_observer;
  47636. +}
  47637. +
  47638. +static void free_observer(void *mem_ctx, observer_t *observer)
  47639. +{
  47640. + dwc_free(mem_ctx, observer);
  47641. +}
  47642. +
  47643. +static notifier_t *alloc_notifier(void *mem_ctx, void *object)
  47644. +{
  47645. + notifier_t *notifier;
  47646. +
  47647. + if (!object) {
  47648. + return NULL;
  47649. + }
  47650. +
  47651. + notifier = dwc_alloc(mem_ctx, sizeof(notifier_t));
  47652. + if (!notifier) {
  47653. + return NULL;
  47654. + }
  47655. +
  47656. + DWC_CIRCLEQ_INIT(&notifier->observers);
  47657. + DWC_CIRCLEQ_INIT_ENTRY(notifier, list_entry);
  47658. +
  47659. + notifier->mem_ctx = mem_ctx;
  47660. + notifier->object = object;
  47661. + return notifier;
  47662. +}
  47663. +
  47664. +static void free_notifier(notifier_t *notifier)
  47665. +{
  47666. + observer_t *observer;
  47667. +
  47668. + DWC_CIRCLEQ_FOREACH(observer, &notifier->observers, list_entry) {
  47669. + free_observer(notifier->mem_ctx, observer);
  47670. + }
  47671. +
  47672. + dwc_free(notifier->mem_ctx, notifier);
  47673. +}
  47674. +
  47675. +static notifier_t *find_notifier(void *object)
  47676. +{
  47677. + notifier_t *notifier;
  47678. +
  47679. + DWC_ASSERT(manager, "Notification manager not found");
  47680. +
  47681. + if (!object) {
  47682. + return NULL;
  47683. + }
  47684. +
  47685. + DWC_CIRCLEQ_FOREACH(notifier, &manager->notifiers, list_entry) {
  47686. + if (notifier->object == object) {
  47687. + return notifier;
  47688. + }
  47689. + }
  47690. +
  47691. + return NULL;
  47692. +}
  47693. +
  47694. +int dwc_alloc_notification_manager(void *mem_ctx, void *wkq_ctx)
  47695. +{
  47696. + return create_manager(mem_ctx, wkq_ctx);
  47697. +}
  47698. +
  47699. +void dwc_free_notification_manager(void)
  47700. +{
  47701. + free_manager();
  47702. +}
  47703. +
  47704. +dwc_notifier_t *dwc_register_notifier(void *mem_ctx, void *object)
  47705. +{
  47706. + notifier_t *notifier;
  47707. +
  47708. + DWC_ASSERT(manager, "Notification manager not found");
  47709. +
  47710. + notifier = find_notifier(object);
  47711. + if (notifier) {
  47712. + DWC_ERROR("Notifier %p is already registered\n", object);
  47713. + return NULL;
  47714. + }
  47715. +
  47716. + notifier = alloc_notifier(mem_ctx, object);
  47717. + if (!notifier) {
  47718. + return NULL;
  47719. + }
  47720. +
  47721. + DWC_CIRCLEQ_INSERT_TAIL(&manager->notifiers, notifier, list_entry);
  47722. +
  47723. + DWC_INFO("Notifier %p registered", object);
  47724. + dump_manager();
  47725. +
  47726. + return notifier;
  47727. +}
  47728. +
  47729. +void dwc_unregister_notifier(dwc_notifier_t *notifier)
  47730. +{
  47731. + DWC_ASSERT(manager, "Notification manager not found");
  47732. +
  47733. + if (!DWC_CIRCLEQ_EMPTY(&notifier->observers)) {
  47734. + observer_t *o;
  47735. +
  47736. + DWC_ERROR("Notifier %p has active observers when removing\n", notifier->object);
  47737. + DWC_CIRCLEQ_FOREACH(o, &notifier->observers, list_entry) {
  47738. + DWC_DEBUGC(" %p watching %s\n", o->observer, o->notification);
  47739. + }
  47740. +
  47741. + DWC_ASSERT(DWC_CIRCLEQ_EMPTY(&notifier->observers),
  47742. + "Notifier %p has active observers when removing", notifier);
  47743. + }
  47744. +
  47745. + DWC_CIRCLEQ_REMOVE_INIT(&manager->notifiers, notifier, list_entry);
  47746. + free_notifier(notifier);
  47747. +
  47748. + DWC_INFO("Notifier unregistered");
  47749. + dump_manager();
  47750. +}
  47751. +
  47752. +/* Add an observer to observe the notifier for a particular state, event, or notification. */
  47753. +int dwc_add_observer(void *observer, void *object, char *notification,
  47754. + dwc_notifier_callback_t callback, void *data)
  47755. +{
  47756. + notifier_t *notifier = find_notifier(object);
  47757. + observer_t *new_observer;
  47758. +
  47759. + if (!notifier) {
  47760. + DWC_ERROR("Notifier %p is not found when adding observer\n", object);
  47761. + return -DWC_E_INVALID;
  47762. + }
  47763. +
  47764. + new_observer = alloc_observer(notifier->mem_ctx, observer, notification, callback, data);
  47765. + if (!new_observer) {
  47766. + return -DWC_E_NO_MEMORY;
  47767. + }
  47768. +
  47769. + DWC_CIRCLEQ_INSERT_TAIL(&notifier->observers, new_observer, list_entry);
  47770. +
  47771. + DWC_INFO("Added observer %p to notifier %p observing notification %s, callback=%p, data=%p",
  47772. + observer, object, notification, callback, data);
  47773. +
  47774. + dump_manager();
  47775. + return 0;
  47776. +}
  47777. +
  47778. +int dwc_remove_observer(void *observer)
  47779. +{
  47780. + notifier_t *n;
  47781. +
  47782. + DWC_ASSERT(manager, "Notification manager not found");
  47783. +
  47784. + DWC_CIRCLEQ_FOREACH(n, &manager->notifiers, list_entry) {
  47785. + observer_t *o;
  47786. + observer_t *o2;
  47787. +
  47788. + DWC_CIRCLEQ_FOREACH_SAFE(o, o2, &n->observers, list_entry) {
  47789. + if (o->observer == observer) {
  47790. + DWC_CIRCLEQ_REMOVE_INIT(&n->observers, o, list_entry);
  47791. + DWC_INFO("Removing observer %p from notifier %p watching notification %s:",
  47792. + o->observer, n->object, o->notification);
  47793. + free_observer(n->mem_ctx, o);
  47794. + }
  47795. + }
  47796. + }
  47797. +
  47798. + dump_manager();
  47799. + return 0;
  47800. +}
  47801. +
  47802. +typedef struct callback_data {
  47803. + void *mem_ctx;
  47804. + dwc_notifier_callback_t cb;
  47805. + void *observer;
  47806. + void *data;
  47807. + void *object;
  47808. + char *notification;
  47809. + void *notification_data;
  47810. +} cb_data_t;
  47811. +
  47812. +static void cb_task(void *data)
  47813. +{
  47814. + cb_data_t *cb = (cb_data_t *)data;
  47815. +
  47816. + cb->cb(cb->object, cb->notification, cb->observer, cb->notification_data, cb->data);
  47817. + dwc_free(cb->mem_ctx, cb);
  47818. +}
  47819. +
  47820. +void dwc_notify(dwc_notifier_t *notifier, char *notification, void *notification_data)
  47821. +{
  47822. + observer_t *o;
  47823. +
  47824. + DWC_ASSERT(manager, "Notification manager not found");
  47825. +
  47826. + DWC_CIRCLEQ_FOREACH(o, &notifier->observers, list_entry) {
  47827. + int len = DWC_STRLEN(notification);
  47828. +
  47829. + if (DWC_STRLEN(o->notification) != len) {
  47830. + continue;
  47831. + }
  47832. +
  47833. + if (DWC_STRNCMP(o->notification, notification, len) == 0) {
  47834. + cb_data_t *cb_data = dwc_alloc(notifier->mem_ctx, sizeof(cb_data_t));
  47835. +
  47836. + if (!cb_data) {
  47837. + DWC_ERROR("Failed to allocate callback data\n");
  47838. + return;
  47839. + }
  47840. +
  47841. + cb_data->mem_ctx = notifier->mem_ctx;
  47842. + cb_data->cb = o->callback;
  47843. + cb_data->observer = o->observer;
  47844. + cb_data->data = o->data;
  47845. + cb_data->object = notifier->object;
  47846. + cb_data->notification = notification;
  47847. + cb_data->notification_data = notification_data;
  47848. + DWC_DEBUGC("Observer found %p for notification %s\n", o->observer, notification);
  47849. + DWC_WORKQ_SCHEDULE(manager->wq, cb_task, cb_data,
  47850. + "Notify callback from %p for Notification %s, to observer %p",
  47851. + cb_data->object, notification, cb_data->observer);
  47852. + }
  47853. + }
  47854. +}
  47855. +
  47856. +#endif /* DWC_NOTIFYLIB */
  47857. diff -Nur linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_notifier.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_notifier.h
  47858. --- linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_notifier.h 1970-01-01 01:00:00.000000000 +0100
  47859. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_notifier.h 2014-04-13 17:33:11.000000000 +0200
  47860. @@ -0,0 +1,122 @@
  47861. +
  47862. +#ifndef __DWC_NOTIFIER_H__
  47863. +#define __DWC_NOTIFIER_H__
  47864. +
  47865. +#ifdef __cplusplus
  47866. +extern "C" {
  47867. +#endif
  47868. +
  47869. +#include "dwc_os.h"
  47870. +
  47871. +/** @file
  47872. + *
  47873. + * A simple implementation of the Observer pattern. Any "module" can
  47874. + * register as an observer or notifier. The notion of "module" is abstract and
  47875. + * can mean anything used to identify either an observer or notifier. Usually
  47876. + * it will be a pointer to a data structure which contains some state, ie an
  47877. + * object.
  47878. + *
  47879. + * Before any notifiers can be added, the global notification manager must be
  47880. + * brought up with dwc_alloc_notification_manager().
  47881. + * dwc_free_notification_manager() will bring it down and free all resources.
  47882. + * These would typically be called upon module load and unload. The
  47883. + * notification manager is a single global instance that handles all registered
  47884. + * observable modules and observers so this should be done only once.
  47885. + *
  47886. + * A module can be observable by using Notifications to publicize some general
  47887. + * information about it's state or operation. It does not care who listens, or
  47888. + * even if anyone listens, or what they do with the information. The observable
  47889. + * modules do not need to know any information about it's observers or their
  47890. + * interface, or their state or data.
  47891. + *
  47892. + * Any module can register to emit Notifications. It should publish a list of
  47893. + * notifications that it can emit and their behavior, such as when they will get
  47894. + * triggered, and what information will be provided to the observer. Then it
  47895. + * should register itself as an observable module. See dwc_register_notifier().
  47896. + *
  47897. + * Any module can observe any observable, registered module, provided it has a
  47898. + * handle to the other module and knows what notifications to observe. See
  47899. + * dwc_add_observer().
  47900. + *
  47901. + * A function of type dwc_notifier_callback_t is called whenever a notification
  47902. + * is triggered with one or more observers observing it. This function is
  47903. + * called in it's own process so it may sleep or block if needed. It is
  47904. + * guaranteed to be called sometime after the notification has occurred and will
  47905. + * be called once per each time the notification is triggered. It will NOT be
  47906. + * called in the same process context used to trigger the notification.
  47907. + *
  47908. + * @section Limitiations
  47909. + *
  47910. + * Keep in mind that Notifications that can be triggered in rapid sucession may
  47911. + * schedule too many processes too handle. Be aware of this limitation when
  47912. + * designing to use notifications, and only add notifications for appropriate
  47913. + * observable information.
  47914. + *
  47915. + * Also Notification callbacks are not synchronous. If you need to synchronize
  47916. + * the behavior between module/observer you must use other means. And perhaps
  47917. + * that will mean Notifications are not the proper solution.
  47918. + */
  47919. +
  47920. +struct dwc_notifier;
  47921. +typedef struct dwc_notifier dwc_notifier_t;
  47922. +
  47923. +/** The callback function must be of this type.
  47924. + *
  47925. + * @param object This is the object that is being observed.
  47926. + * @param notification This is the notification that was triggered.
  47927. + * @param observer This is the observer
  47928. + * @param notification_data This is notification-specific data that the notifier
  47929. + * has included in this notification. The value of this should be published in
  47930. + * the documentation of the observable module with the notifications.
  47931. + * @param user_data This is any custom data that the observer provided when
  47932. + * adding itself as an observer to the notification. */
  47933. +typedef void (*dwc_notifier_callback_t)(void *object, char *notification, void *observer,
  47934. + void *notification_data, void *user_data);
  47935. +
  47936. +/** Brings up the notification manager. */
  47937. +extern int dwc_alloc_notification_manager(void *mem_ctx, void *wkq_ctx);
  47938. +/** Brings down the notification manager. */
  47939. +extern void dwc_free_notification_manager(void);
  47940. +
  47941. +/** This function registers an observable module. A dwc_notifier_t object is
  47942. + * returned to the observable module. This is an opaque object that is used by
  47943. + * the observable module to trigger notifications. This object should only be
  47944. + * accessible to functions that are authorized to trigger notifications for this
  47945. + * module. Observers do not need this object. */
  47946. +extern dwc_notifier_t *dwc_register_notifier(void *mem_ctx, void *object);
  47947. +
  47948. +/** This function unregisters an observable module. All observers have to be
  47949. + * removed prior to unregistration. */
  47950. +extern void dwc_unregister_notifier(dwc_notifier_t *notifier);
  47951. +
  47952. +/** Add a module as an observer to the observable module. The observable module
  47953. + * needs to have previously registered with the notification manager.
  47954. + *
  47955. + * @param observer The observer module
  47956. + * @param object The module to observe
  47957. + * @param notification The notification to observe
  47958. + * @param callback The callback function to call
  47959. + * @param user_data Any additional user data to pass into the callback function */
  47960. +extern int dwc_add_observer(void *observer, void *object, char *notification,
  47961. + dwc_notifier_callback_t callback, void *user_data);
  47962. +
  47963. +/** Removes the specified observer from all notifications that it is currently
  47964. + * observing. */
  47965. +extern int dwc_remove_observer(void *observer);
  47966. +
  47967. +/** This function triggers a Notification. It should be called by the
  47968. + * observable module, or any module or library which the observable module
  47969. + * allows to trigger notification on it's behalf. Such as the dwc_cc_t.
  47970. + *
  47971. + * dwc_notify is a non-blocking function. Callbacks are scheduled called in
  47972. + * their own process context for each trigger. Callbacks can be blocking.
  47973. + * dwc_notify can be called from interrupt context if needed.
  47974. + *
  47975. + */
  47976. +void dwc_notify(dwc_notifier_t *notifier, char *notification, void *notification_data);
  47977. +
  47978. +#ifdef __cplusplus
  47979. +}
  47980. +#endif
  47981. +
  47982. +#endif /* __DWC_NOTIFIER_H__ */
  47983. diff -Nur linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_os.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_os.h
  47984. --- linux-3.15.4/drivers/usb/host/dwc_common_port/dwc_os.h 1970-01-01 01:00:00.000000000 +0100
  47985. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_os.h 2014-07-07 10:45:43.000000000 +0200
  47986. @@ -0,0 +1,1262 @@
  47987. +/* =========================================================================
  47988. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_os.h $
  47989. + * $Revision: #14 $
  47990. + * $Date: 2010/11/04 $
  47991. + * $Change: 1621695 $
  47992. + *
  47993. + * Synopsys Portability Library Software and documentation
  47994. + * (hereinafter, "Software") is an Unsupported proprietary work of
  47995. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  47996. + * between Synopsys and you.
  47997. + *
  47998. + * The Software IS NOT an item of Licensed Software or Licensed Product
  47999. + * under any End User Software License Agreement or Agreement for
  48000. + * Licensed Product with Synopsys or any supplement thereto. You are
  48001. + * permitted to use and redistribute this Software in source and binary
  48002. + * forms, with or without modification, provided that redistributions
  48003. + * of source code must retain this notice. You may not view, use,
  48004. + * disclose, copy or distribute this file or any information contained
  48005. + * herein except pursuant to this license grant from Synopsys. If you
  48006. + * do not agree with this notice, including the disclaimer below, then
  48007. + * you are not authorized to use the Software.
  48008. + *
  48009. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  48010. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  48011. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  48012. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  48013. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  48014. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  48015. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  48016. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  48017. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  48018. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  48019. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  48020. + * DAMAGE.
  48021. + * ========================================================================= */
  48022. +#ifndef _DWC_OS_H_
  48023. +#define _DWC_OS_H_
  48024. +
  48025. +#ifdef __cplusplus
  48026. +extern "C" {
  48027. +#endif
  48028. +
  48029. +/** @file
  48030. + *
  48031. + * DWC portability library, low level os-wrapper functions
  48032. + *
  48033. + */
  48034. +
  48035. +/* These basic types need to be defined by some OS header file or custom header
  48036. + * file for your specific target architecture.
  48037. + *
  48038. + * uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t
  48039. + *
  48040. + * Any custom or alternate header file must be added and enabled here.
  48041. + */
  48042. +
  48043. +#ifdef DWC_LINUX
  48044. +# include <linux/types.h>
  48045. +# ifdef CONFIG_DEBUG_MUTEXES
  48046. +# include <linux/mutex.h>
  48047. +# endif
  48048. +# include <linux/errno.h>
  48049. +# include <stdarg.h>
  48050. +#endif
  48051. +
  48052. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  48053. +# include <os_dep.h>
  48054. +#endif
  48055. +
  48056. +
  48057. +/** @name Primitive Types and Values */
  48058. +
  48059. +/** We define a boolean type for consistency. Can be either YES or NO */
  48060. +typedef uint8_t dwc_bool_t;
  48061. +#define YES 1
  48062. +#define NO 0
  48063. +
  48064. +#ifdef DWC_LINUX
  48065. +
  48066. +/** @name Error Codes */
  48067. +#define DWC_E_INVALID EINVAL
  48068. +#define DWC_E_NO_MEMORY ENOMEM
  48069. +#define DWC_E_NO_DEVICE ENODEV
  48070. +#define DWC_E_NOT_SUPPORTED EOPNOTSUPP
  48071. +#define DWC_E_TIMEOUT ETIMEDOUT
  48072. +#define DWC_E_BUSY EBUSY
  48073. +#define DWC_E_AGAIN EAGAIN
  48074. +#define DWC_E_RESTART ERESTART
  48075. +#define DWC_E_ABORT ECONNABORTED
  48076. +#define DWC_E_SHUTDOWN ESHUTDOWN
  48077. +#define DWC_E_NO_DATA ENODATA
  48078. +#define DWC_E_DISCONNECT ECONNRESET
  48079. +#define DWC_E_UNKNOWN EINVAL
  48080. +#define DWC_E_NO_STREAM_RES ENOSR
  48081. +#define DWC_E_COMMUNICATION ECOMM
  48082. +#define DWC_E_OVERFLOW EOVERFLOW
  48083. +#define DWC_E_PROTOCOL EPROTO
  48084. +#define DWC_E_IN_PROGRESS EINPROGRESS
  48085. +#define DWC_E_PIPE EPIPE
  48086. +#define DWC_E_IO EIO
  48087. +#define DWC_E_NO_SPACE ENOSPC
  48088. +
  48089. +#else
  48090. +
  48091. +/** @name Error Codes */
  48092. +#define DWC_E_INVALID 1001
  48093. +#define DWC_E_NO_MEMORY 1002
  48094. +#define DWC_E_NO_DEVICE 1003
  48095. +#define DWC_E_NOT_SUPPORTED 1004
  48096. +#define DWC_E_TIMEOUT 1005
  48097. +#define DWC_E_BUSY 1006
  48098. +#define DWC_E_AGAIN 1007
  48099. +#define DWC_E_RESTART 1008
  48100. +#define DWC_E_ABORT 1009
  48101. +#define DWC_E_SHUTDOWN 1010
  48102. +#define DWC_E_NO_DATA 1011
  48103. +#define DWC_E_DISCONNECT 2000
  48104. +#define DWC_E_UNKNOWN 3000
  48105. +#define DWC_E_NO_STREAM_RES 4001
  48106. +#define DWC_E_COMMUNICATION 4002
  48107. +#define DWC_E_OVERFLOW 4003
  48108. +#define DWC_E_PROTOCOL 4004
  48109. +#define DWC_E_IN_PROGRESS 4005
  48110. +#define DWC_E_PIPE 4006
  48111. +#define DWC_E_IO 4007
  48112. +#define DWC_E_NO_SPACE 4008
  48113. +
  48114. +#endif
  48115. +
  48116. +
  48117. +/** @name Tracing/Logging Functions
  48118. + *
  48119. + * These function provide the capability to add tracing, debugging, and error
  48120. + * messages, as well exceptions as assertions. The WUDEV uses these
  48121. + * extensively. These could be logged to the main console, the serial port, an
  48122. + * internal buffer, etc. These functions could also be no-op if they are too
  48123. + * expensive on your system. By default undefining the DEBUG macro already
  48124. + * no-ops some of these functions. */
  48125. +
  48126. +/** Returns non-zero if in interrupt context. */
  48127. +extern dwc_bool_t DWC_IN_IRQ(void);
  48128. +#define dwc_in_irq DWC_IN_IRQ
  48129. +
  48130. +/** Returns "IRQ" if DWC_IN_IRQ is true. */
  48131. +static inline char *dwc_irq(void) {
  48132. + return DWC_IN_IRQ() ? "IRQ" : "";
  48133. +}
  48134. +
  48135. +/** Returns non-zero if in bottom-half context. */
  48136. +extern dwc_bool_t DWC_IN_BH(void);
  48137. +#define dwc_in_bh DWC_IN_BH
  48138. +
  48139. +/** Returns "BH" if DWC_IN_BH is true. */
  48140. +static inline char *dwc_bh(void) {
  48141. + return DWC_IN_BH() ? "BH" : "";
  48142. +}
  48143. +
  48144. +/**
  48145. + * A vprintf() clone. Just call vprintf if you've got it.
  48146. + */
  48147. +extern void DWC_VPRINTF(char *format, va_list args);
  48148. +#define dwc_vprintf DWC_VPRINTF
  48149. +
  48150. +/**
  48151. + * A vsnprintf() clone. Just call vprintf if you've got it.
  48152. + */
  48153. +extern int DWC_VSNPRINTF(char *str, int size, char *format, va_list args);
  48154. +#define dwc_vsnprintf DWC_VSNPRINTF
  48155. +
  48156. +/**
  48157. + * printf() clone. Just call printf if you've go it.
  48158. + */
  48159. +extern void DWC_PRINTF(char *format, ...)
  48160. +/* This provides compiler level static checking of the parameters if you're
  48161. + * using GCC. */
  48162. +#ifdef __GNUC__
  48163. + __attribute__ ((format(printf, 1, 2)));
  48164. +#else
  48165. + ;
  48166. +#endif
  48167. +#define dwc_printf DWC_PRINTF
  48168. +
  48169. +/**
  48170. + * sprintf() clone. Just call sprintf if you've got it.
  48171. + */
  48172. +extern int DWC_SPRINTF(char *string, char *format, ...)
  48173. +#ifdef __GNUC__
  48174. + __attribute__ ((format(printf, 2, 3)));
  48175. +#else
  48176. + ;
  48177. +#endif
  48178. +#define dwc_sprintf DWC_SPRINTF
  48179. +
  48180. +/**
  48181. + * snprintf() clone. Just call snprintf if you've got it.
  48182. + */
  48183. +extern int DWC_SNPRINTF(char *string, int size, char *format, ...)
  48184. +#ifdef __GNUC__
  48185. + __attribute__ ((format(printf, 3, 4)));
  48186. +#else
  48187. + ;
  48188. +#endif
  48189. +#define dwc_snprintf DWC_SNPRINTF
  48190. +
  48191. +/**
  48192. + * Prints a WARNING message. On systems that don't differentiate between
  48193. + * warnings and regular log messages, just print it. Indicates that something
  48194. + * may be wrong with the driver. Works like printf().
  48195. + *
  48196. + * Use the DWC_WARN macro to call this function.
  48197. + */
  48198. +extern void __DWC_WARN(char *format, ...)
  48199. +#ifdef __GNUC__
  48200. + __attribute__ ((format(printf, 1, 2)));
  48201. +#else
  48202. + ;
  48203. +#endif
  48204. +
  48205. +/**
  48206. + * Prints an error message. On systems that don't differentiate between errors
  48207. + * and regular log messages, just print it. Indicates that something went wrong
  48208. + * with the driver. Works like printf().
  48209. + *
  48210. + * Use the DWC_ERROR macro to call this function.
  48211. + */
  48212. +extern void __DWC_ERROR(char *format, ...)
  48213. +#ifdef __GNUC__
  48214. + __attribute__ ((format(printf, 1, 2)));
  48215. +#else
  48216. + ;
  48217. +#endif
  48218. +
  48219. +/**
  48220. + * Prints an exception error message and takes some user-defined action such as
  48221. + * print out a backtrace or trigger a breakpoint. Indicates that something went
  48222. + * abnormally wrong with the driver such as programmer error, or other
  48223. + * exceptional condition. It should not be ignored so even on systems without
  48224. + * printing capability, some action should be taken to notify the developer of
  48225. + * it. Works like printf().
  48226. + */
  48227. +extern void DWC_EXCEPTION(char *format, ...)
  48228. +#ifdef __GNUC__
  48229. + __attribute__ ((format(printf, 1, 2)));
  48230. +#else
  48231. + ;
  48232. +#endif
  48233. +#define dwc_exception DWC_EXCEPTION
  48234. +
  48235. +#ifndef DWC_OTG_DEBUG_LEV
  48236. +#define DWC_OTG_DEBUG_LEV 0
  48237. +#endif
  48238. +
  48239. +#ifdef DEBUG
  48240. +/**
  48241. + * Prints out a debug message. Used for logging/trace messages.
  48242. + *
  48243. + * Use the DWC_DEBUG macro to call this function
  48244. + */
  48245. +extern void __DWC_DEBUG(char *format, ...)
  48246. +#ifdef __GNUC__
  48247. + __attribute__ ((format(printf, 1, 2)));
  48248. +#else
  48249. + ;
  48250. +#endif
  48251. +#else
  48252. +#define __DWC_DEBUG printk
  48253. +#endif
  48254. +
  48255. +/**
  48256. + * Prints out a Debug message.
  48257. + */
  48258. +#define DWC_DEBUG(_format, _args...) __DWC_DEBUG("DEBUG:%s:%s: " _format "\n", \
  48259. + __func__, dwc_irq(), ## _args)
  48260. +#define dwc_debug DWC_DEBUG
  48261. +/**
  48262. + * Prints out a Debug message if enabled at compile time.
  48263. + */
  48264. +#if DWC_OTG_DEBUG_LEV > 0
  48265. +#define DWC_DEBUGC(_format, _args...) DWC_DEBUG(_format, ##_args )
  48266. +#else
  48267. +#define DWC_DEBUGC(_format, _args...)
  48268. +#endif
  48269. +#define dwc_debugc DWC_DEBUGC
  48270. +/**
  48271. + * Prints out an informative message.
  48272. + */
  48273. +#define DWC_INFO(_format, _args...) DWC_PRINTF("INFO:%s: " _format "\n", \
  48274. + dwc_irq(), ## _args)
  48275. +#define dwc_info DWC_INFO
  48276. +/**
  48277. + * Prints out an informative message if enabled at compile time.
  48278. + */
  48279. +#if DWC_OTG_DEBUG_LEV > 1
  48280. +#define DWC_INFOC(_format, _args...) DWC_INFO(_format, ##_args )
  48281. +#else
  48282. +#define DWC_INFOC(_format, _args...)
  48283. +#endif
  48284. +#define dwc_infoc DWC_INFOC
  48285. +/**
  48286. + * Prints out a warning message.
  48287. + */
  48288. +#define DWC_WARN(_format, _args...) __DWC_WARN("WARN:%s:%s:%d: " _format "\n", \
  48289. + dwc_irq(), __func__, __LINE__, ## _args)
  48290. +#define dwc_warn DWC_WARN
  48291. +/**
  48292. + * Prints out an error message.
  48293. + */
  48294. +#define DWC_ERROR(_format, _args...) __DWC_ERROR("ERROR:%s:%s:%d: " _format "\n", \
  48295. + dwc_irq(), __func__, __LINE__, ## _args)
  48296. +#define dwc_error DWC_ERROR
  48297. +
  48298. +#define DWC_PROTO_ERROR(_format, _args...) __DWC_WARN("ERROR:%s:%s:%d: " _format "\n", \
  48299. + dwc_irq(), __func__, __LINE__, ## _args)
  48300. +#define dwc_proto_error DWC_PROTO_ERROR
  48301. +
  48302. +#ifdef DEBUG
  48303. +/** Prints out a exception error message if the _expr expression fails. Disabled
  48304. + * if DEBUG is not enabled. */
  48305. +#define DWC_ASSERT(_expr, _format, _args...) do { \
  48306. + if (!(_expr)) { DWC_EXCEPTION("%s:%s:%d: " _format "\n", dwc_irq(), \
  48307. + __FILE__, __LINE__, ## _args); } \
  48308. + } while (0)
  48309. +#else
  48310. +#define DWC_ASSERT(_x...)
  48311. +#endif
  48312. +#define dwc_assert DWC_ASSERT
  48313. +
  48314. +
  48315. +/** @name Byte Ordering
  48316. + * The following functions are for conversions between processor's byte ordering
  48317. + * and specific ordering you want.
  48318. + */
  48319. +
  48320. +/** Converts 32 bit data in CPU byte ordering to little endian. */
  48321. +extern uint32_t DWC_CPU_TO_LE32(uint32_t *p);
  48322. +#define dwc_cpu_to_le32 DWC_CPU_TO_LE32
  48323. +
  48324. +/** Converts 32 bit data in CPU byte orderint to big endian. */
  48325. +extern uint32_t DWC_CPU_TO_BE32(uint32_t *p);
  48326. +#define dwc_cpu_to_be32 DWC_CPU_TO_BE32
  48327. +
  48328. +/** Converts 32 bit little endian data to CPU byte ordering. */
  48329. +extern uint32_t DWC_LE32_TO_CPU(uint32_t *p);
  48330. +#define dwc_le32_to_cpu DWC_LE32_TO_CPU
  48331. +
  48332. +/** Converts 32 bit big endian data to CPU byte ordering. */
  48333. +extern uint32_t DWC_BE32_TO_CPU(uint32_t *p);
  48334. +#define dwc_be32_to_cpu DWC_BE32_TO_CPU
  48335. +
  48336. +/** Converts 16 bit data in CPU byte ordering to little endian. */
  48337. +extern uint16_t DWC_CPU_TO_LE16(uint16_t *p);
  48338. +#define dwc_cpu_to_le16 DWC_CPU_TO_LE16
  48339. +
  48340. +/** Converts 16 bit data in CPU byte orderint to big endian. */
  48341. +extern uint16_t DWC_CPU_TO_BE16(uint16_t *p);
  48342. +#define dwc_cpu_to_be16 DWC_CPU_TO_BE16
  48343. +
  48344. +/** Converts 16 bit little endian data to CPU byte ordering. */
  48345. +extern uint16_t DWC_LE16_TO_CPU(uint16_t *p);
  48346. +#define dwc_le16_to_cpu DWC_LE16_TO_CPU
  48347. +
  48348. +/** Converts 16 bit bi endian data to CPU byte ordering. */
  48349. +extern uint16_t DWC_BE16_TO_CPU(uint16_t *p);
  48350. +#define dwc_be16_to_cpu DWC_BE16_TO_CPU
  48351. +
  48352. +
  48353. +/** @name Register Read/Write
  48354. + *
  48355. + * The following six functions should be implemented to read/write registers of
  48356. + * 32-bit and 64-bit sizes. All modules use this to read/write register values.
  48357. + * The reg value is a pointer to the register calculated from the void *base
  48358. + * variable passed into the driver when it is started. */
  48359. +
  48360. +#ifdef DWC_LINUX
  48361. +/* Linux doesn't need any extra parameters for register read/write, so we
  48362. + * just throw away the IO context parameter.
  48363. + */
  48364. +/** Reads the content of a 32-bit register. */
  48365. +extern uint32_t DWC_READ_REG32(uint32_t volatile *reg);
  48366. +#define dwc_read_reg32(_ctx_,_reg_) DWC_READ_REG32(_reg_)
  48367. +
  48368. +/** Reads the content of a 64-bit register. */
  48369. +extern uint64_t DWC_READ_REG64(uint64_t volatile *reg);
  48370. +#define dwc_read_reg64(_ctx_,_reg_) DWC_READ_REG64(_reg_)
  48371. +
  48372. +/** Writes to a 32-bit register. */
  48373. +extern void DWC_WRITE_REG32(uint32_t volatile *reg, uint32_t value);
  48374. +#define dwc_write_reg32(_ctx_,_reg_,_val_) DWC_WRITE_REG32(_reg_, _val_)
  48375. +
  48376. +/** Writes to a 64-bit register. */
  48377. +extern void DWC_WRITE_REG64(uint64_t volatile *reg, uint64_t value);
  48378. +#define dwc_write_reg64(_ctx_,_reg_,_val_) DWC_WRITE_REG64(_reg_, _val_)
  48379. +
  48380. +/**
  48381. + * Modify bit values in a register. Using the
  48382. + * algorithm: (reg_contents & ~clear_mask) | set_mask.
  48383. + */
  48384. +extern void DWC_MODIFY_REG32(uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask);
  48385. +#define dwc_modify_reg32(_ctx_,_reg_,_cmsk_,_smsk_) DWC_MODIFY_REG32(_reg_,_cmsk_,_smsk_)
  48386. +extern void DWC_MODIFY_REG64(uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask);
  48387. +#define dwc_modify_reg64(_ctx_,_reg_,_cmsk_,_smsk_) DWC_MODIFY_REG64(_reg_,_cmsk_,_smsk_)
  48388. +
  48389. +#endif /* DWC_LINUX */
  48390. +
  48391. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  48392. +typedef struct dwc_ioctx {
  48393. + struct device *dev;
  48394. + bus_space_tag_t iot;
  48395. + bus_space_handle_t ioh;
  48396. +} dwc_ioctx_t;
  48397. +
  48398. +/** BSD needs two extra parameters for register read/write, so we pass
  48399. + * them in using the IO context parameter.
  48400. + */
  48401. +/** Reads the content of a 32-bit register. */
  48402. +extern uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg);
  48403. +#define dwc_read_reg32 DWC_READ_REG32
  48404. +
  48405. +/** Reads the content of a 64-bit register. */
  48406. +extern uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg);
  48407. +#define dwc_read_reg64 DWC_READ_REG64
  48408. +
  48409. +/** Writes to a 32-bit register. */
  48410. +extern void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value);
  48411. +#define dwc_write_reg32 DWC_WRITE_REG32
  48412. +
  48413. +/** Writes to a 64-bit register. */
  48414. +extern void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value);
  48415. +#define dwc_write_reg64 DWC_WRITE_REG64
  48416. +
  48417. +/**
  48418. + * Modify bit values in a register. Using the
  48419. + * algorithm: (reg_contents & ~clear_mask) | set_mask.
  48420. + */
  48421. +extern void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask);
  48422. +#define dwc_modify_reg32 DWC_MODIFY_REG32
  48423. +extern void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask);
  48424. +#define dwc_modify_reg64 DWC_MODIFY_REG64
  48425. +
  48426. +#endif /* DWC_FREEBSD || DWC_NETBSD */
  48427. +
  48428. +/** @cond */
  48429. +
  48430. +/** @name Some convenience MACROS used internally. Define DWC_DEBUG_REGS to log the
  48431. + * register writes. */
  48432. +
  48433. +#ifdef DWC_LINUX
  48434. +
  48435. +# ifdef DWC_DEBUG_REGS
  48436. +
  48437. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  48438. +static inline uint32_t dwc_read_##_reg##_n(_container_type *container, int num) { \
  48439. + return DWC_READ_REG32(&container->regs->_reg[num]); \
  48440. +} \
  48441. +static inline void dwc_write_##_reg##_n(_container_type *container, int num, uint32_t data) { \
  48442. + DWC_DEBUG("WRITING %8s[%d]: %p: %08x", #_reg, num, \
  48443. + &(((uint32_t*)container->regs->_reg)[num]), data); \
  48444. + DWC_WRITE_REG32(&(((uint32_t*)container->regs->_reg)[num]), data); \
  48445. +}
  48446. +
  48447. +#define dwc_define_read_write_reg(_reg,_container_type) \
  48448. +static inline uint32_t dwc_read_##_reg(_container_type *container) { \
  48449. + return DWC_READ_REG32(&container->regs->_reg); \
  48450. +} \
  48451. +static inline void dwc_write_##_reg(_container_type *container, uint32_t data) { \
  48452. + DWC_DEBUG("WRITING %11s: %p: %08x", #_reg, &container->regs->_reg, data); \
  48453. + DWC_WRITE_REG32(&container->regs->_reg, data); \
  48454. +}
  48455. +
  48456. +# else /* DWC_DEBUG_REGS */
  48457. +
  48458. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  48459. +static inline uint32_t dwc_read_##_reg##_n(_container_type *container, int num) { \
  48460. + return DWC_READ_REG32(&container->regs->_reg[num]); \
  48461. +} \
  48462. +static inline void dwc_write_##_reg##_n(_container_type *container, int num, uint32_t data) { \
  48463. + DWC_WRITE_REG32(&(((uint32_t*)container->regs->_reg)[num]), data); \
  48464. +}
  48465. +
  48466. +#define dwc_define_read_write_reg(_reg,_container_type) \
  48467. +static inline uint32_t dwc_read_##_reg(_container_type *container) { \
  48468. + return DWC_READ_REG32(&container->regs->_reg); \
  48469. +} \
  48470. +static inline void dwc_write_##_reg(_container_type *container, uint32_t data) { \
  48471. + DWC_WRITE_REG32(&container->regs->_reg, data); \
  48472. +}
  48473. +
  48474. +# endif /* DWC_DEBUG_REGS */
  48475. +
  48476. +#endif /* DWC_LINUX */
  48477. +
  48478. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  48479. +
  48480. +# ifdef DWC_DEBUG_REGS
  48481. +
  48482. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  48483. +static inline uint32_t dwc_read_##_reg##_n(void *io_ctx, _container_type *container, int num) { \
  48484. + return DWC_READ_REG32(io_ctx, &container->regs->_reg[num]); \
  48485. +} \
  48486. +static inline void dwc_write_##_reg##_n(void *io_ctx, _container_type *container, int num, uint32_t data) { \
  48487. + DWC_DEBUG("WRITING %8s[%d]: %p: %08x", #_reg, num, \
  48488. + &(((uint32_t*)container->regs->_reg)[num]), data); \
  48489. + DWC_WRITE_REG32(io_ctx, &(((uint32_t*)container->regs->_reg)[num]), data); \
  48490. +}
  48491. +
  48492. +#define dwc_define_read_write_reg(_reg,_container_type) \
  48493. +static inline uint32_t dwc_read_##_reg(void *io_ctx, _container_type *container) { \
  48494. + return DWC_READ_REG32(io_ctx, &container->regs->_reg); \
  48495. +} \
  48496. +static inline void dwc_write_##_reg(void *io_ctx, _container_type *container, uint32_t data) { \
  48497. + DWC_DEBUG("WRITING %11s: %p: %08x", #_reg, &container->regs->_reg, data); \
  48498. + DWC_WRITE_REG32(io_ctx, &container->regs->_reg, data); \
  48499. +}
  48500. +
  48501. +# else /* DWC_DEBUG_REGS */
  48502. +
  48503. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  48504. +static inline uint32_t dwc_read_##_reg##_n(void *io_ctx, _container_type *container, int num) { \
  48505. + return DWC_READ_REG32(io_ctx, &container->regs->_reg[num]); \
  48506. +} \
  48507. +static inline void dwc_write_##_reg##_n(void *io_ctx, _container_type *container, int num, uint32_t data) { \
  48508. + DWC_WRITE_REG32(io_ctx, &(((uint32_t*)container->regs->_reg)[num]), data); \
  48509. +}
  48510. +
  48511. +#define dwc_define_read_write_reg(_reg,_container_type) \
  48512. +static inline uint32_t dwc_read_##_reg(void *io_ctx, _container_type *container) { \
  48513. + return DWC_READ_REG32(io_ctx, &container->regs->_reg); \
  48514. +} \
  48515. +static inline void dwc_write_##_reg(void *io_ctx, _container_type *container, uint32_t data) { \
  48516. + DWC_WRITE_REG32(io_ctx, &container->regs->_reg, data); \
  48517. +}
  48518. +
  48519. +# endif /* DWC_DEBUG_REGS */
  48520. +
  48521. +#endif /* DWC_FREEBSD || DWC_NETBSD */
  48522. +
  48523. +/** @endcond */
  48524. +
  48525. +
  48526. +#ifdef DWC_CRYPTOLIB
  48527. +/** @name Crypto Functions
  48528. + *
  48529. + * These are the low-level cryptographic functions used by the driver. */
  48530. +
  48531. +/** Perform AES CBC */
  48532. +extern int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out);
  48533. +#define dwc_aes_cbc DWC_AES_CBC
  48534. +
  48535. +/** Fill the provided buffer with random bytes. These should be cryptographic grade random numbers. */
  48536. +extern void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length);
  48537. +#define dwc_random_bytes DWC_RANDOM_BYTES
  48538. +
  48539. +/** Perform the SHA-256 hash function */
  48540. +extern int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out);
  48541. +#define dwc_sha256 DWC_SHA256
  48542. +
  48543. +/** Calculated the HMAC-SHA256 */
  48544. +extern int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t *out);
  48545. +#define dwc_hmac_sha256 DWC_HMAC_SHA256
  48546. +
  48547. +#endif /* DWC_CRYPTOLIB */
  48548. +
  48549. +
  48550. +/** @name Memory Allocation
  48551. + *
  48552. + * These function provide access to memory allocation. There are only 2 DMA
  48553. + * functions and 3 Regular memory functions that need to be implemented. None
  48554. + * of the memory debugging routines need to be implemented. The allocation
  48555. + * routines all ZERO the contents of the memory.
  48556. + *
  48557. + * Defining DWC_DEBUG_MEMORY turns on memory debugging and statistic gathering.
  48558. + * This checks for memory leaks, keeping track of alloc/free pairs. It also
  48559. + * keeps track of how much memory the driver is using at any given time. */
  48560. +
  48561. +#define DWC_PAGE_SIZE 4096
  48562. +#define DWC_PAGE_OFFSET(addr) (((uint32_t)addr) & 0xfff)
  48563. +#define DWC_PAGE_ALIGNED(addr) ((((uint32_t)addr) & 0xfff) == 0)
  48564. +
  48565. +#define DWC_INVALID_DMA_ADDR 0x0
  48566. +
  48567. +#ifdef DWC_LINUX
  48568. +/** Type for a DMA address */
  48569. +typedef dma_addr_t dwc_dma_t;
  48570. +#endif
  48571. +
  48572. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  48573. +typedef bus_addr_t dwc_dma_t;
  48574. +#endif
  48575. +
  48576. +#ifdef DWC_FREEBSD
  48577. +typedef struct dwc_dmactx {
  48578. + struct device *dev;
  48579. + bus_dma_tag_t dma_tag;
  48580. + bus_dmamap_t dma_map;
  48581. + bus_addr_t dma_paddr;
  48582. + void *dma_vaddr;
  48583. +} dwc_dmactx_t;
  48584. +#endif
  48585. +
  48586. +#ifdef DWC_NETBSD
  48587. +typedef struct dwc_dmactx {
  48588. + struct device *dev;
  48589. + bus_dma_tag_t dma_tag;
  48590. + bus_dmamap_t dma_map;
  48591. + bus_dma_segment_t segs[1];
  48592. + int nsegs;
  48593. + bus_addr_t dma_paddr;
  48594. + void *dma_vaddr;
  48595. +} dwc_dmactx_t;
  48596. +#endif
  48597. +
  48598. +/* @todo these functions will be added in the future */
  48599. +#if 0
  48600. +/**
  48601. + * Creates a DMA pool from which you can allocate DMA buffers. Buffers
  48602. + * allocated from this pool will be guaranteed to meet the size, alignment, and
  48603. + * boundary requirements specified.
  48604. + *
  48605. + * @param[in] size Specifies the size of the buffers that will be allocated from
  48606. + * this pool.
  48607. + * @param[in] align Specifies the byte alignment requirements of the buffers
  48608. + * allocated from this pool. Must be a power of 2.
  48609. + * @param[in] boundary Specifies the N-byte boundary that buffers allocated from
  48610. + * this pool must not cross.
  48611. + *
  48612. + * @returns A pointer to an internal opaque structure which is not to be
  48613. + * accessed outside of these library functions. Use this handle to specify
  48614. + * which pools to allocate/free DMA buffers from and also to destroy the pool,
  48615. + * when you are done with it.
  48616. + */
  48617. +extern dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size, uint32_t align, uint32_t boundary);
  48618. +
  48619. +/**
  48620. + * Destroy a DMA pool. All buffers allocated from that pool must be freed first.
  48621. + */
  48622. +extern void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool);
  48623. +
  48624. +/**
  48625. + * Allocate a buffer from the specified DMA pool and zeros its contents.
  48626. + */
  48627. +extern void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr);
  48628. +
  48629. +/**
  48630. + * Free a previously allocated buffer from the DMA pool.
  48631. + */
  48632. +extern void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr);
  48633. +#endif
  48634. +
  48635. +/** Allocates a DMA capable buffer and zeroes its contents. */
  48636. +extern void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr);
  48637. +
  48638. +/** Allocates a DMA capable buffer and zeroes its contents in atomic contest */
  48639. +extern void *__DWC_DMA_ALLOC_ATOMIC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr);
  48640. +
  48641. +/** Frees a previously allocated buffer. */
  48642. +extern void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr);
  48643. +
  48644. +/** Allocates a block of memory and zeroes its contents. */
  48645. +extern void *__DWC_ALLOC(void *mem_ctx, uint32_t size);
  48646. +
  48647. +/** Allocates a block of memory and zeroes its contents, in an atomic manner
  48648. + * which can be used inside interrupt context. The size should be sufficiently
  48649. + * small, a few KB at most, such that failures are not likely to occur. Can just call
  48650. + * __DWC_ALLOC if it is atomic. */
  48651. +extern void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size);
  48652. +
  48653. +/** Frees a previously allocated buffer. */
  48654. +extern void __DWC_FREE(void *mem_ctx, void *addr);
  48655. +
  48656. +#ifndef DWC_DEBUG_MEMORY
  48657. +
  48658. +#define DWC_ALLOC(_size_) __DWC_ALLOC(NULL, _size_)
  48659. +#define DWC_ALLOC_ATOMIC(_size_) __DWC_ALLOC_ATOMIC(NULL, _size_)
  48660. +#define DWC_FREE(_addr_) __DWC_FREE(NULL, _addr_)
  48661. +
  48662. +# ifdef DWC_LINUX
  48663. +#define DWC_DMA_ALLOC(_size_,_dma_) __DWC_DMA_ALLOC(NULL, _size_, _dma_)
  48664. +#define DWC_DMA_ALLOC_ATOMIC(_size_,_dma_) __DWC_DMA_ALLOC_ATOMIC(NULL, _size_,_dma_)
  48665. +#define DWC_DMA_FREE(_size_,_virt_,_dma_) __DWC_DMA_FREE(NULL, _size_, _virt_, _dma_)
  48666. +# endif
  48667. +
  48668. +# if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  48669. +#define DWC_DMA_ALLOC __DWC_DMA_ALLOC
  48670. +#define DWC_DMA_FREE __DWC_DMA_FREE
  48671. +# endif
  48672. +extern void *dwc_dma_alloc_atomic_debug(uint32_t size, dwc_dma_t *dma_addr, char const *func, int line);
  48673. +
  48674. +#else /* DWC_DEBUG_MEMORY */
  48675. +
  48676. +extern void *dwc_alloc_debug(void *mem_ctx, uint32_t size, char const *func, int line);
  48677. +extern void *dwc_alloc_atomic_debug(void *mem_ctx, uint32_t size, char const *func, int line);
  48678. +extern void dwc_free_debug(void *mem_ctx, void *addr, char const *func, int line);
  48679. +extern void *dwc_dma_alloc_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  48680. + char const *func, int line);
  48681. +extern void *dwc_dma_alloc_atomic_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  48682. + char const *func, int line);
  48683. +extern void dwc_dma_free_debug(void *dma_ctx, uint32_t size, void *virt_addr,
  48684. + dwc_dma_t dma_addr, char const *func, int line);
  48685. +
  48686. +extern int dwc_memory_debug_start(void *mem_ctx);
  48687. +extern void dwc_memory_debug_stop(void);
  48688. +extern void dwc_memory_debug_report(void);
  48689. +
  48690. +#define DWC_ALLOC(_size_) dwc_alloc_debug(NULL, _size_, __func__, __LINE__)
  48691. +#define DWC_ALLOC_ATOMIC(_size_) dwc_alloc_atomic_debug(NULL, _size_, \
  48692. + __func__, __LINE__)
  48693. +#define DWC_FREE(_addr_) dwc_free_debug(NULL, _addr_, __func__, __LINE__)
  48694. +
  48695. +# ifdef DWC_LINUX
  48696. +#define DWC_DMA_ALLOC(_size_,_dma_) dwc_dma_alloc_debug(NULL, _size_, \
  48697. + _dma_, __func__, __LINE__)
  48698. +#define DWC_DMA_ALLOC_ATOMIC(_size_,_dma_) dwc_dma_alloc_atomic_debug(NULL, _size_, \
  48699. + _dma_, __func__, __LINE__)
  48700. +#define DWC_DMA_FREE(_size_,_virt_,_dma_) dwc_dma_free_debug(NULL, _size_, \
  48701. + _virt_, _dma_, __func__, __LINE__)
  48702. +# endif
  48703. +
  48704. +# if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  48705. +#define DWC_DMA_ALLOC(_ctx_,_size_,_dma_) dwc_dma_alloc_debug(_ctx_, _size_, \
  48706. + _dma_, __func__, __LINE__)
  48707. +#define DWC_DMA_FREE(_ctx_,_size_,_virt_,_dma_) dwc_dma_free_debug(_ctx_, _size_, \
  48708. + _virt_, _dma_, __func__, __LINE__)
  48709. +# endif
  48710. +
  48711. +#endif /* DWC_DEBUG_MEMORY */
  48712. +
  48713. +#define dwc_alloc(_ctx_,_size_) DWC_ALLOC(_size_)
  48714. +#define dwc_alloc_atomic(_ctx_,_size_) DWC_ALLOC_ATOMIC(_size_)
  48715. +#define dwc_free(_ctx_,_addr_) DWC_FREE(_addr_)
  48716. +
  48717. +#ifdef DWC_LINUX
  48718. +/* Linux doesn't need any extra parameters for DMA buffer allocation, so we
  48719. + * just throw away the DMA context parameter.
  48720. + */
  48721. +#define dwc_dma_alloc(_ctx_,_size_,_dma_) DWC_DMA_ALLOC(_size_, _dma_)
  48722. +#define dwc_dma_alloc_atomic(_ctx_,_size_,_dma_) DWC_DMA_ALLOC_ATOMIC(_size_, _dma_)
  48723. +#define dwc_dma_free(_ctx_,_size_,_virt_,_dma_) DWC_DMA_FREE(_size_, _virt_, _dma_)
  48724. +#endif
  48725. +
  48726. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  48727. +/** BSD needs several extra parameters for DMA buffer allocation, so we pass
  48728. + * them in using the DMA context parameter.
  48729. + */
  48730. +#define dwc_dma_alloc DWC_DMA_ALLOC
  48731. +#define dwc_dma_free DWC_DMA_FREE
  48732. +#endif
  48733. +
  48734. +
  48735. +/** @name Memory and String Processing */
  48736. +
  48737. +/** memset() clone */
  48738. +extern void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size);
  48739. +#define dwc_memset DWC_MEMSET
  48740. +
  48741. +/** memcpy() clone */
  48742. +extern void *DWC_MEMCPY(void *dest, void const *src, uint32_t size);
  48743. +#define dwc_memcpy DWC_MEMCPY
  48744. +
  48745. +/** memmove() clone */
  48746. +extern void *DWC_MEMMOVE(void *dest, void *src, uint32_t size);
  48747. +#define dwc_memmove DWC_MEMMOVE
  48748. +
  48749. +/** memcmp() clone */
  48750. +extern int DWC_MEMCMP(void *m1, void *m2, uint32_t size);
  48751. +#define dwc_memcmp DWC_MEMCMP
  48752. +
  48753. +/** strcmp() clone */
  48754. +extern int DWC_STRCMP(void *s1, void *s2);
  48755. +#define dwc_strcmp DWC_STRCMP
  48756. +
  48757. +/** strncmp() clone */
  48758. +extern int DWC_STRNCMP(void *s1, void *s2, uint32_t size);
  48759. +#define dwc_strncmp DWC_STRNCMP
  48760. +
  48761. +/** strlen() clone, for NULL terminated ASCII strings */
  48762. +extern int DWC_STRLEN(char const *str);
  48763. +#define dwc_strlen DWC_STRLEN
  48764. +
  48765. +/** strcpy() clone, for NULL terminated ASCII strings */
  48766. +extern char *DWC_STRCPY(char *to, const char *from);
  48767. +#define dwc_strcpy DWC_STRCPY
  48768. +
  48769. +/** strdup() clone. If you wish to use memory allocation debugging, this
  48770. + * implementation of strdup should use the DWC_* memory routines instead of
  48771. + * calling a predefined strdup. Otherwise the memory allocated by this routine
  48772. + * will not be seen by the debugging routines. */
  48773. +extern char *DWC_STRDUP(char const *str);
  48774. +#define dwc_strdup(_ctx_,_str_) DWC_STRDUP(_str_)
  48775. +
  48776. +/** NOT an atoi() clone. Read the description carefully. Returns an integer
  48777. + * converted from the string str in base 10 unless the string begins with a "0x"
  48778. + * in which case it is base 16. String must be a NULL terminated sequence of
  48779. + * ASCII characters and may optionally begin with whitespace, a + or -, and a
  48780. + * "0x" prefix if base 16. The remaining characters must be valid digits for
  48781. + * the number and end with a NULL character. If any invalid characters are
  48782. + * encountered or it returns with a negative error code and the results of the
  48783. + * conversion are undefined. On sucess it returns 0. Overflow conditions are
  48784. + * undefined. An example implementation using atoi() can be referenced from the
  48785. + * Linux implementation. */
  48786. +extern int DWC_ATOI(const char *str, int32_t *value);
  48787. +#define dwc_atoi DWC_ATOI
  48788. +
  48789. +/** Same as above but for unsigned. */
  48790. +extern int DWC_ATOUI(const char *str, uint32_t *value);
  48791. +#define dwc_atoui DWC_ATOUI
  48792. +
  48793. +#ifdef DWC_UTFLIB
  48794. +/** This routine returns a UTF16LE unicode encoded string from a UTF8 string. */
  48795. +extern int DWC_UTF8_TO_UTF16LE(uint8_t const *utf8string, uint16_t *utf16string, unsigned len);
  48796. +#define dwc_utf8_to_utf16le DWC_UTF8_TO_UTF16LE
  48797. +#endif
  48798. +
  48799. +
  48800. +/** @name Wait queues
  48801. + *
  48802. + * Wait queues provide a means of synchronizing between threads or processes. A
  48803. + * process can block on a waitq if some condition is not true, waiting for it to
  48804. + * become true. When the waitq is triggered all waiting process will get
  48805. + * unblocked and the condition will be check again. Waitqs should be triggered
  48806. + * every time a condition can potentially change.*/
  48807. +struct dwc_waitq;
  48808. +
  48809. +/** Type for a waitq */
  48810. +typedef struct dwc_waitq dwc_waitq_t;
  48811. +
  48812. +/** The type of waitq condition callback function. This is called every time
  48813. + * condition is evaluated. */
  48814. +typedef int (*dwc_waitq_condition_t)(void *data);
  48815. +
  48816. +/** Allocate a waitq */
  48817. +extern dwc_waitq_t *DWC_WAITQ_ALLOC(void);
  48818. +#define dwc_waitq_alloc(_ctx_) DWC_WAITQ_ALLOC()
  48819. +
  48820. +/** Free a waitq */
  48821. +extern void DWC_WAITQ_FREE(dwc_waitq_t *wq);
  48822. +#define dwc_waitq_free DWC_WAITQ_FREE
  48823. +
  48824. +/** Check the condition and if it is false, block on the waitq. When unblocked, check the
  48825. + * condition again. The function returns when the condition becomes true. The return value
  48826. + * is 0 on condition true, DWC_WAITQ_ABORTED on abort or killed, or DWC_WAITQ_UNKNOWN on error. */
  48827. +extern int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data);
  48828. +#define dwc_waitq_wait DWC_WAITQ_WAIT
  48829. +
  48830. +/** Check the condition and if it is false, block on the waitq. When unblocked,
  48831. + * check the condition again. The function returns when the condition become
  48832. + * true or the timeout has passed. The return value is 0 on condition true or
  48833. + * DWC_TIMED_OUT on timeout, or DWC_WAITQ_ABORTED, or DWC_WAITQ_UNKNOWN on
  48834. + * error. */
  48835. +extern int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  48836. + void *data, int32_t msecs);
  48837. +#define dwc_waitq_wait_timeout DWC_WAITQ_WAIT_TIMEOUT
  48838. +
  48839. +/** Trigger a waitq, unblocking all processes. This should be called whenever a condition
  48840. + * has potentially changed. */
  48841. +extern void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq);
  48842. +#define dwc_waitq_trigger DWC_WAITQ_TRIGGER
  48843. +
  48844. +/** Unblock all processes waiting on the waitq with an ABORTED result. */
  48845. +extern void DWC_WAITQ_ABORT(dwc_waitq_t *wq);
  48846. +#define dwc_waitq_abort DWC_WAITQ_ABORT
  48847. +
  48848. +
  48849. +/** @name Threads
  48850. + *
  48851. + * A thread must be explicitly stopped. It must check DWC_THREAD_SHOULD_STOP
  48852. + * whenever it is woken up, and then return. The DWC_THREAD_STOP function
  48853. + * returns the value from the thread.
  48854. + */
  48855. +
  48856. +struct dwc_thread;
  48857. +
  48858. +/** Type for a thread */
  48859. +typedef struct dwc_thread dwc_thread_t;
  48860. +
  48861. +/** The thread function */
  48862. +typedef int (*dwc_thread_function_t)(void *data);
  48863. +
  48864. +/** Create a thread and start it running the thread_function. Returns a handle
  48865. + * to the thread */
  48866. +extern dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data);
  48867. +#define dwc_thread_run(_ctx_,_func_,_name_,_data_) DWC_THREAD_RUN(_func_, _name_, _data_)
  48868. +
  48869. +/** Stops a thread. Return the value returned by the thread. Or will return
  48870. + * DWC_ABORT if the thread never started. */
  48871. +extern int DWC_THREAD_STOP(dwc_thread_t *thread);
  48872. +#define dwc_thread_stop DWC_THREAD_STOP
  48873. +
  48874. +/** Signifies to the thread that it must stop. */
  48875. +#ifdef DWC_LINUX
  48876. +/* Linux doesn't need any parameters for kthread_should_stop() */
  48877. +extern dwc_bool_t DWC_THREAD_SHOULD_STOP(void);
  48878. +#define dwc_thread_should_stop(_thrd_) DWC_THREAD_SHOULD_STOP()
  48879. +
  48880. +/* No thread_exit function in Linux */
  48881. +#define dwc_thread_exit(_thrd_)
  48882. +#endif
  48883. +
  48884. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  48885. +/** BSD needs the thread pointer for kthread_suspend_check() */
  48886. +extern dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread);
  48887. +#define dwc_thread_should_stop DWC_THREAD_SHOULD_STOP
  48888. +
  48889. +/** The thread must call this to exit. */
  48890. +extern void DWC_THREAD_EXIT(dwc_thread_t *thread);
  48891. +#define dwc_thread_exit DWC_THREAD_EXIT
  48892. +#endif
  48893. +
  48894. +
  48895. +/** @name Work queues
  48896. + *
  48897. + * Workqs are used to queue a callback function to be called at some later time,
  48898. + * in another thread. */
  48899. +struct dwc_workq;
  48900. +
  48901. +/** Type for a workq */
  48902. +typedef struct dwc_workq dwc_workq_t;
  48903. +
  48904. +/** The type of the callback function to be called. */
  48905. +typedef void (*dwc_work_callback_t)(void *data);
  48906. +
  48907. +/** Allocate a workq */
  48908. +extern dwc_workq_t *DWC_WORKQ_ALLOC(char *name);
  48909. +#define dwc_workq_alloc(_ctx_,_name_) DWC_WORKQ_ALLOC(_name_)
  48910. +
  48911. +/** Free a workq. All work must be completed before being freed. */
  48912. +extern void DWC_WORKQ_FREE(dwc_workq_t *workq);
  48913. +#define dwc_workq_free DWC_WORKQ_FREE
  48914. +
  48915. +/** Schedule a callback on the workq, passing in data. The function will be
  48916. + * scheduled at some later time. */
  48917. +extern void DWC_WORKQ_SCHEDULE(dwc_workq_t *workq, dwc_work_callback_t cb,
  48918. + void *data, char *format, ...)
  48919. +#ifdef __GNUC__
  48920. + __attribute__ ((format(printf, 4, 5)));
  48921. +#else
  48922. + ;
  48923. +#endif
  48924. +#define dwc_workq_schedule DWC_WORKQ_SCHEDULE
  48925. +
  48926. +/** Schedule a callback on the workq, that will be called until at least
  48927. + * given number miliseconds have passed. */
  48928. +extern void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *workq, dwc_work_callback_t cb,
  48929. + void *data, uint32_t time, char *format, ...)
  48930. +#ifdef __GNUC__
  48931. + __attribute__ ((format(printf, 5, 6)));
  48932. +#else
  48933. + ;
  48934. +#endif
  48935. +#define dwc_workq_schedule_delayed DWC_WORKQ_SCHEDULE_DELAYED
  48936. +
  48937. +/** The number of processes in the workq */
  48938. +extern int DWC_WORKQ_PENDING(dwc_workq_t *workq);
  48939. +#define dwc_workq_pending DWC_WORKQ_PENDING
  48940. +
  48941. +/** Blocks until all the work in the workq is complete or timed out. Returns <
  48942. + * 0 on timeout. */
  48943. +extern int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout);
  48944. +#define dwc_workq_wait_work_done DWC_WORKQ_WAIT_WORK_DONE
  48945. +
  48946. +
  48947. +/** @name Tasklets
  48948. + *
  48949. + */
  48950. +struct dwc_tasklet;
  48951. +
  48952. +/** Type for a tasklet */
  48953. +typedef struct dwc_tasklet dwc_tasklet_t;
  48954. +
  48955. +/** The type of the callback function to be called */
  48956. +typedef void (*dwc_tasklet_callback_t)(void *data);
  48957. +
  48958. +/** Allocates a tasklet */
  48959. +extern dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data);
  48960. +#define dwc_task_alloc(_ctx_,_name_,_cb_,_data_) DWC_TASK_ALLOC(_name_, _cb_, _data_)
  48961. +
  48962. +/** Frees a tasklet */
  48963. +extern void DWC_TASK_FREE(dwc_tasklet_t *task);
  48964. +#define dwc_task_free DWC_TASK_FREE
  48965. +
  48966. +/** Schedules a tasklet to run */
  48967. +extern void DWC_TASK_SCHEDULE(dwc_tasklet_t *task);
  48968. +#define dwc_task_schedule DWC_TASK_SCHEDULE
  48969. +
  48970. +extern void DWC_TASK_HI_SCHEDULE(dwc_tasklet_t *task);
  48971. +#define dwc_task_hi_schedule DWC_TASK_HI_SCHEDULE
  48972. +
  48973. +/** @name Timer
  48974. + *
  48975. + * Callbacks must be small and atomic.
  48976. + */
  48977. +struct dwc_timer;
  48978. +
  48979. +/** Type for a timer */
  48980. +typedef struct dwc_timer dwc_timer_t;
  48981. +
  48982. +/** The type of the callback function to be called */
  48983. +typedef void (*dwc_timer_callback_t)(void *data);
  48984. +
  48985. +/** Allocates a timer */
  48986. +extern dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data);
  48987. +#define dwc_timer_alloc(_ctx_,_name_,_cb_,_data_) DWC_TIMER_ALLOC(_name_,_cb_,_data_)
  48988. +
  48989. +/** Frees a timer */
  48990. +extern void DWC_TIMER_FREE(dwc_timer_t *timer);
  48991. +#define dwc_timer_free DWC_TIMER_FREE
  48992. +
  48993. +/** Schedules the timer to run at time ms from now. And will repeat at every
  48994. + * repeat_interval msec therafter
  48995. + *
  48996. + * Modifies a timer that is still awaiting execution to a new expiration time.
  48997. + * The mod_time is added to the old time. */
  48998. +extern void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time);
  48999. +#define dwc_timer_schedule DWC_TIMER_SCHEDULE
  49000. +
  49001. +/** Disables the timer from execution. */
  49002. +extern void DWC_TIMER_CANCEL(dwc_timer_t *timer);
  49003. +#define dwc_timer_cancel DWC_TIMER_CANCEL
  49004. +
  49005. +
  49006. +/** @name Spinlocks
  49007. + *
  49008. + * These locks are used when the work between the lock/unlock is atomic and
  49009. + * short. Interrupts are also disabled during the lock/unlock and thus they are
  49010. + * suitable to lock between interrupt/non-interrupt context. They also lock
  49011. + * between processes if you have multiple CPUs or Preemption. If you don't have
  49012. + * multiple CPUS or Preemption, then the you can simply implement the
  49013. + * DWC_SPINLOCK and DWC_SPINUNLOCK to disable and enable interrupts. Because
  49014. + * the work between the lock/unlock is atomic, the process context will never
  49015. + * change, and so you never have to lock between processes. */
  49016. +
  49017. +struct dwc_spinlock;
  49018. +
  49019. +/** Type for a spinlock */
  49020. +typedef struct dwc_spinlock dwc_spinlock_t;
  49021. +
  49022. +/** Type for the 'flags' argument to spinlock funtions */
  49023. +typedef unsigned long dwc_irqflags_t;
  49024. +
  49025. +/** Returns an initialized lock variable. This function should allocate and
  49026. + * initialize the OS-specific data structure used for locking. This data
  49027. + * structure is to be used for the DWC_LOCK and DWC_UNLOCK functions and should
  49028. + * be freed by the DWC_FREE_LOCK when it is no longer used. */
  49029. +extern dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void);
  49030. +#define dwc_spinlock_alloc(_ctx_) DWC_SPINLOCK_ALLOC()
  49031. +
  49032. +/** Frees an initialized lock variable. */
  49033. +extern void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock);
  49034. +#define dwc_spinlock_free(_ctx_,_lock_) DWC_SPINLOCK_FREE(_lock_)
  49035. +
  49036. +/** Disables interrupts and blocks until it acquires the lock.
  49037. + *
  49038. + * @param lock Pointer to the spinlock.
  49039. + * @param flags Unsigned long for irq flags storage.
  49040. + */
  49041. +extern void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags);
  49042. +#define dwc_spinlock_irqsave DWC_SPINLOCK_IRQSAVE
  49043. +
  49044. +/** Re-enables the interrupt and releases the lock.
  49045. + *
  49046. + * @param lock Pointer to the spinlock.
  49047. + * @param flags Unsigned long for irq flags storage. Must be the same as was
  49048. + * passed into DWC_LOCK.
  49049. + */
  49050. +extern void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags);
  49051. +#define dwc_spinunlock_irqrestore DWC_SPINUNLOCK_IRQRESTORE
  49052. +
  49053. +/** Blocks until it acquires the lock.
  49054. + *
  49055. + * @param lock Pointer to the spinlock.
  49056. + */
  49057. +extern void DWC_SPINLOCK(dwc_spinlock_t *lock);
  49058. +#define dwc_spinlock DWC_SPINLOCK
  49059. +
  49060. +/** Releases the lock.
  49061. + *
  49062. + * @param lock Pointer to the spinlock.
  49063. + */
  49064. +extern void DWC_SPINUNLOCK(dwc_spinlock_t *lock);
  49065. +#define dwc_spinunlock DWC_SPINUNLOCK
  49066. +
  49067. +
  49068. +/** @name Mutexes
  49069. + *
  49070. + * Unlike spinlocks Mutexes lock only between processes and the work between the
  49071. + * lock/unlock CAN block, therefore it CANNOT be called from interrupt context.
  49072. + */
  49073. +
  49074. +struct dwc_mutex;
  49075. +
  49076. +/** Type for a mutex */
  49077. +typedef struct dwc_mutex dwc_mutex_t;
  49078. +
  49079. +/* For Linux Mutex Debugging make it inline because the debugging routines use
  49080. + * the symbol to determine recursive locking. This makes it falsely think
  49081. + * recursive locking occurs. */
  49082. +#if defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES)
  49083. +#define DWC_MUTEX_ALLOC_LINUX_DEBUG(__mutexp) ({ \
  49084. + __mutexp = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mutex)); \
  49085. + mutex_init((struct mutex *)__mutexp); \
  49086. +})
  49087. +#endif
  49088. +
  49089. +/** Allocate a mutex */
  49090. +extern dwc_mutex_t *DWC_MUTEX_ALLOC(void);
  49091. +#define dwc_mutex_alloc(_ctx_) DWC_MUTEX_ALLOC()
  49092. +
  49093. +/* For memory leak debugging when using Linux Mutex Debugging */
  49094. +#if defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES)
  49095. +#define DWC_MUTEX_FREE(__mutexp) do { \
  49096. + mutex_destroy((struct mutex *)__mutexp); \
  49097. + DWC_FREE(__mutexp); \
  49098. +} while(0)
  49099. +#else
  49100. +/** Free a mutex */
  49101. +extern void DWC_MUTEX_FREE(dwc_mutex_t *mutex);
  49102. +#define dwc_mutex_free(_ctx_,_mutex_) DWC_MUTEX_FREE(_mutex_)
  49103. +#endif
  49104. +
  49105. +/** Lock a mutex */
  49106. +extern void DWC_MUTEX_LOCK(dwc_mutex_t *mutex);
  49107. +#define dwc_mutex_lock DWC_MUTEX_LOCK
  49108. +
  49109. +/** Non-blocking lock returns 1 on successful lock. */
  49110. +extern int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex);
  49111. +#define dwc_mutex_trylock DWC_MUTEX_TRYLOCK
  49112. +
  49113. +/** Unlock a mutex */
  49114. +extern void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex);
  49115. +#define dwc_mutex_unlock DWC_MUTEX_UNLOCK
  49116. +
  49117. +
  49118. +/** @name Time */
  49119. +
  49120. +/** Microsecond delay.
  49121. + *
  49122. + * @param usecs Microseconds to delay.
  49123. + */
  49124. +extern void DWC_UDELAY(uint32_t usecs);
  49125. +#define dwc_udelay DWC_UDELAY
  49126. +
  49127. +/** Millisecond delay.
  49128. + *
  49129. + * @param msecs Milliseconds to delay.
  49130. + */
  49131. +extern void DWC_MDELAY(uint32_t msecs);
  49132. +#define dwc_mdelay DWC_MDELAY
  49133. +
  49134. +/** Non-busy waiting.
  49135. + * Sleeps for specified number of milliseconds.
  49136. + *
  49137. + * @param msecs Milliseconds to sleep.
  49138. + */
  49139. +extern void DWC_MSLEEP(uint32_t msecs);
  49140. +#define dwc_msleep DWC_MSLEEP
  49141. +
  49142. +/**
  49143. + * Returns number of milliseconds since boot.
  49144. + */
  49145. +extern uint32_t DWC_TIME(void);
  49146. +#define dwc_time DWC_TIME
  49147. +
  49148. +
  49149. +
  49150. +
  49151. +/* @mainpage DWC Portability and Common Library
  49152. + *
  49153. + * This is the documentation for the DWC Portability and Common Library.
  49154. + *
  49155. + * @section intro Introduction
  49156. + *
  49157. + * The DWC Portability library consists of wrapper calls and data structures to
  49158. + * all low-level functions which are typically provided by the OS. The WUDEV
  49159. + * driver uses only these functions. In order to port the WUDEV driver, only
  49160. + * the functions in this library need to be re-implemented, with the same
  49161. + * behavior as documented here.
  49162. + *
  49163. + * The Common library consists of higher level functions, which rely only on
  49164. + * calling the functions from the DWC Portability library. These common
  49165. + * routines are shared across modules. Some of the common libraries need to be
  49166. + * used directly by the driver programmer when porting WUDEV. Such as the
  49167. + * parameter and notification libraries.
  49168. + *
  49169. + * @section low Portability Library OS Wrapper Functions
  49170. + *
  49171. + * Any function starting with DWC and in all CAPS is a low-level OS-wrapper that
  49172. + * needs to be implemented when porting, for example DWC_MUTEX_ALLOC(). All of
  49173. + * these functions are included in the dwc_os.h file.
  49174. + *
  49175. + * There are many functions here covering a wide array of OS services. Please
  49176. + * see dwc_os.h for details, and implementation notes for each function.
  49177. + *
  49178. + * @section common Common Library Functions
  49179. + *
  49180. + * Any function starting with dwc and in all lowercase is a common library
  49181. + * routine. These functions have a portable implementation and do not need to
  49182. + * be reimplemented when porting. The common routines can be used by any
  49183. + * driver, and some must be used by the end user to control the drivers. For
  49184. + * example, you must use the Parameter common library in order to set the
  49185. + * parameters in the WUDEV module.
  49186. + *
  49187. + * The common libraries consist of the following:
  49188. + *
  49189. + * - Connection Contexts - Used internally and can be used by end-user. See dwc_cc.h
  49190. + * - Parameters - Used internally and can be used by end-user. See dwc_params.h
  49191. + * - Notifications - Used internally and can be used by end-user. See dwc_notifier.h
  49192. + * - Lists - Used internally and can be used by end-user. See dwc_list.h
  49193. + * - Memory Debugging - Used internally and can be used by end-user. See dwc_os.h
  49194. + * - Modpow - Used internally only. See dwc_modpow.h
  49195. + * - DH - Used internally only. See dwc_dh.h
  49196. + * - Crypto - Used internally only. See dwc_crypto.h
  49197. + *
  49198. + *
  49199. + * @section prereq Prerequistes For dwc_os.h
  49200. + * @subsection types Data Types
  49201. + *
  49202. + * The dwc_os.h file assumes that several low-level data types are pre defined for the
  49203. + * compilation environment. These data types are:
  49204. + *
  49205. + * - uint8_t - unsigned 8-bit data type
  49206. + * - int8_t - signed 8-bit data type
  49207. + * - uint16_t - unsigned 16-bit data type
  49208. + * - int16_t - signed 16-bit data type
  49209. + * - uint32_t - unsigned 32-bit data type
  49210. + * - int32_t - signed 32-bit data type
  49211. + * - uint64_t - unsigned 64-bit data type
  49212. + * - int64_t - signed 64-bit data type
  49213. + *
  49214. + * Ensure that these are defined before using dwc_os.h. The easiest way to do
  49215. + * that is to modify the top of the file to include the appropriate header.
  49216. + * This is already done for the Linux environment. If the DWC_LINUX macro is
  49217. + * defined, the correct header will be added. A standard header <stdint.h> is
  49218. + * also used for environments where standard C headers are available.
  49219. + *
  49220. + * @subsection stdarg Variable Arguments
  49221. + *
  49222. + * Variable arguments are provided by a standard C header <stdarg.h>. it is
  49223. + * available in Both the Linux and ANSI C enviornment. An equivalent must be
  49224. + * provided in your enviornment in order to use dwc_os.h with the debug and
  49225. + * tracing message functionality.
  49226. + *
  49227. + * @subsection thread Threading
  49228. + *
  49229. + * WUDEV Core must be run on an operating system that provides for multiple
  49230. + * threads/processes. Threading can be implemented in many ways, even in
  49231. + * embedded systems without an operating system. At the bare minimum, the
  49232. + * system should be able to start any number of processes at any time to handle
  49233. + * special work. It need not be a pre-emptive system. Process context can
  49234. + * change upon a call to a blocking function. The hardware interrupt context
  49235. + * that calls the module's ISR() function must be differentiable from process
  49236. + * context, even if your processes are impemented via a hardware interrupt.
  49237. + * Further locking mechanism between process must exist (or be implemented), and
  49238. + * process context must have a way to disable interrupts for a period of time to
  49239. + * lock them out. If all of this exists, the functions in dwc_os.h related to
  49240. + * threading should be able to be implemented with the defined behavior.
  49241. + *
  49242. + */
  49243. +
  49244. +#ifdef __cplusplus
  49245. +}
  49246. +#endif
  49247. +
  49248. +#endif /* _DWC_OS_H_ */
  49249. diff -Nur linux-3.15.4/drivers/usb/host/dwc_common_port/Makefile linux-rpi/drivers/usb/host/dwc_common_port/Makefile
  49250. --- linux-3.15.4/drivers/usb/host/dwc_common_port/Makefile 1970-01-01 01:00:00.000000000 +0100
  49251. +++ linux-rpi/drivers/usb/host/dwc_common_port/Makefile 2014-07-07 10:45:43.000000000 +0200
  49252. @@ -0,0 +1,58 @@
  49253. +#
  49254. +# Makefile for DWC_common library
  49255. +#
  49256. +
  49257. +ifneq ($(KERNELRELEASE),)
  49258. +
  49259. +ccflags-y += -DDWC_LINUX
  49260. +#ccflags-y += -DDEBUG
  49261. +#ccflags-y += -DDWC_DEBUG_REGS
  49262. +#ccflags-y += -DDWC_DEBUG_MEMORY
  49263. +
  49264. +ccflags-y += -DDWC_LIBMODULE
  49265. +ccflags-y += -DDWC_CCLIB
  49266. +#ccflags-y += -DDWC_CRYPTOLIB
  49267. +ccflags-y += -DDWC_NOTIFYLIB
  49268. +ccflags-y += -DDWC_UTFLIB
  49269. +
  49270. +obj-$(CONFIG_USB_DWCOTG) += dwc_common_port_lib.o
  49271. +dwc_common_port_lib-objs := dwc_cc.o dwc_modpow.o dwc_dh.o \
  49272. + dwc_crypto.o dwc_notifier.o \
  49273. + dwc_common_linux.o dwc_mem.o
  49274. +
  49275. +kernrelwd := $(subst ., ,$(KERNELRELEASE))
  49276. +kernrel3 := $(word 1,$(kernrelwd)).$(word 2,$(kernrelwd)).$(word 3,$(kernrelwd))
  49277. +
  49278. +ifneq ($(kernrel3),2.6.20)
  49279. +# grayg - I only know that we use ccflags-y in 2.6.31 actually
  49280. +ccflags-y += $(CPPFLAGS)
  49281. +endif
  49282. +
  49283. +else
  49284. +
  49285. +#ifeq ($(KDIR),)
  49286. +#$(error Must give "KDIR=/path/to/kernel/source" on command line or in environment)
  49287. +#endif
  49288. +
  49289. +ifeq ($(ARCH),)
  49290. +$(error Must give "ARCH=<arch>" on command line or in environment. Also, if \
  49291. + cross-compiling, must give "CROSS_COMPILE=/path/to/compiler/plus/tool-prefix-")
  49292. +endif
  49293. +
  49294. +ifeq ($(DOXYGEN),)
  49295. +DOXYGEN := doxygen
  49296. +endif
  49297. +
  49298. +default:
  49299. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  49300. +
  49301. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  49302. + $(DOXYGEN) doc/doxygen.cfg
  49303. +
  49304. +tags: $(wildcard *.[hc])
  49305. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  49306. +
  49307. +endif
  49308. +
  49309. +clean:
  49310. + rm -rf *.o *.ko .*.cmd *.mod.c .*.o.d .*.o.tmp modules.order Module.markers Module.symvers .tmp_versions/
  49311. diff -Nur linux-3.15.4/drivers/usb/host/dwc_common_port/Makefile.fbsd linux-rpi/drivers/usb/host/dwc_common_port/Makefile.fbsd
  49312. --- linux-3.15.4/drivers/usb/host/dwc_common_port/Makefile.fbsd 1970-01-01 01:00:00.000000000 +0100
  49313. +++ linux-rpi/drivers/usb/host/dwc_common_port/Makefile.fbsd 2014-04-13 17:33:11.000000000 +0200
  49314. @@ -0,0 +1,17 @@
  49315. +CFLAGS += -I/sys/i386/compile/GENERIC -I/sys/i386/include -I/usr/include
  49316. +CFLAGS += -DDWC_FREEBSD
  49317. +CFLAGS += -DDEBUG
  49318. +#CFLAGS += -DDWC_DEBUG_REGS
  49319. +#CFLAGS += -DDWC_DEBUG_MEMORY
  49320. +
  49321. +#CFLAGS += -DDWC_LIBMODULE
  49322. +#CFLAGS += -DDWC_CCLIB
  49323. +#CFLAGS += -DDWC_CRYPTOLIB
  49324. +#CFLAGS += -DDWC_NOTIFYLIB
  49325. +#CFLAGS += -DDWC_UTFLIB
  49326. +
  49327. +KMOD = dwc_common_port_lib
  49328. +SRCS = dwc_cc.c dwc_modpow.c dwc_dh.c dwc_crypto.c dwc_notifier.c \
  49329. + dwc_common_fbsd.c dwc_mem.c
  49330. +
  49331. +.include <bsd.kmod.mk>
  49332. diff -Nur linux-3.15.4/drivers/usb/host/dwc_common_port/Makefile.linux linux-rpi/drivers/usb/host/dwc_common_port/Makefile.linux
  49333. --- linux-3.15.4/drivers/usb/host/dwc_common_port/Makefile.linux 1970-01-01 01:00:00.000000000 +0100
  49334. +++ linux-rpi/drivers/usb/host/dwc_common_port/Makefile.linux 2014-04-13 17:33:11.000000000 +0200
  49335. @@ -0,0 +1,49 @@
  49336. +#
  49337. +# Makefile for DWC_common library
  49338. +#
  49339. +ifneq ($(KERNELRELEASE),)
  49340. +
  49341. +ccflags-y += -DDWC_LINUX
  49342. +#ccflags-y += -DDEBUG
  49343. +#ccflags-y += -DDWC_DEBUG_REGS
  49344. +#ccflags-y += -DDWC_DEBUG_MEMORY
  49345. +
  49346. +ccflags-y += -DDWC_LIBMODULE
  49347. +ccflags-y += -DDWC_CCLIB
  49348. +ccflags-y += -DDWC_CRYPTOLIB
  49349. +ccflags-y += -DDWC_NOTIFYLIB
  49350. +ccflags-y += -DDWC_UTFLIB
  49351. +
  49352. +obj-m := dwc_common_port_lib.o
  49353. +dwc_common_port_lib-objs := dwc_cc.o dwc_modpow.o dwc_dh.o \
  49354. + dwc_crypto.o dwc_notifier.o \
  49355. + dwc_common_linux.o dwc_mem.o
  49356. +
  49357. +else
  49358. +
  49359. +ifeq ($(KDIR),)
  49360. +$(error Must give "KDIR=/path/to/kernel/source" on command line or in environment)
  49361. +endif
  49362. +
  49363. +ifeq ($(ARCH),)
  49364. +$(error Must give "ARCH=<arch>" on command line or in environment. Also, if \
  49365. + cross-compiling, must give "CROSS_COMPILE=/path/to/compiler/plus/tool-prefix-")
  49366. +endif
  49367. +
  49368. +ifeq ($(DOXYGEN),)
  49369. +DOXYGEN := doxygen
  49370. +endif
  49371. +
  49372. +default:
  49373. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  49374. +
  49375. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  49376. + $(DOXYGEN) doc/doxygen.cfg
  49377. +
  49378. +tags: $(wildcard *.[hc])
  49379. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  49380. +
  49381. +endif
  49382. +
  49383. +clean:
  49384. + rm -rf *.o *.ko .*.cmd *.mod.c .*.o.d .*.o.tmp modules.order Module.markers Module.symvers .tmp_versions/
  49385. diff -Nur linux-3.15.4/drivers/usb/host/dwc_common_port/usb.h linux-rpi/drivers/usb/host/dwc_common_port/usb.h
  49386. --- linux-3.15.4/drivers/usb/host/dwc_common_port/usb.h 1970-01-01 01:00:00.000000000 +0100
  49387. +++ linux-rpi/drivers/usb/host/dwc_common_port/usb.h 2014-04-13 17:33:11.000000000 +0200
  49388. @@ -0,0 +1,946 @@
  49389. +/*
  49390. + * Copyright (c) 1998 The NetBSD Foundation, Inc.
  49391. + * All rights reserved.
  49392. + *
  49393. + * This code is derived from software contributed to The NetBSD Foundation
  49394. + * by Lennart Augustsson (lennart@augustsson.net) at
  49395. + * Carlstedt Research & Technology.
  49396. + *
  49397. + * Redistribution and use in source and binary forms, with or without
  49398. + * modification, are permitted provided that the following conditions
  49399. + * are met:
  49400. + * 1. Redistributions of source code must retain the above copyright
  49401. + * notice, this list of conditions and the following disclaimer.
  49402. + * 2. Redistributions in binary form must reproduce the above copyright
  49403. + * notice, this list of conditions and the following disclaimer in the
  49404. + * documentation and/or other materials provided with the distribution.
  49405. + * 3. All advertising materials mentioning features or use of this software
  49406. + * must display the following acknowledgement:
  49407. + * This product includes software developed by the NetBSD
  49408. + * Foundation, Inc. and its contributors.
  49409. + * 4. Neither the name of The NetBSD Foundation nor the names of its
  49410. + * contributors may be used to endorse or promote products derived
  49411. + * from this software without specific prior written permission.
  49412. + *
  49413. + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  49414. + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  49415. + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  49416. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  49417. + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  49418. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  49419. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  49420. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  49421. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  49422. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  49423. + * POSSIBILITY OF SUCH DAMAGE.
  49424. + */
  49425. +
  49426. +/* Modified by Synopsys, Inc, 12/12/2007 */
  49427. +
  49428. +
  49429. +#ifndef _USB_H_
  49430. +#define _USB_H_
  49431. +
  49432. +#ifdef __cplusplus
  49433. +extern "C" {
  49434. +#endif
  49435. +
  49436. +/*
  49437. + * The USB records contain some unaligned little-endian word
  49438. + * components. The U[SG]ETW macros take care of both the alignment
  49439. + * and endian problem and should always be used to access non-byte
  49440. + * values.
  49441. + */
  49442. +typedef u_int8_t uByte;
  49443. +typedef u_int8_t uWord[2];
  49444. +typedef u_int8_t uDWord[4];
  49445. +
  49446. +#define USETW2(w,h,l) ((w)[0] = (u_int8_t)(l), (w)[1] = (u_int8_t)(h))
  49447. +#define UCONSTW(x) { (x) & 0xff, ((x) >> 8) & 0xff }
  49448. +#define UCONSTDW(x) { (x) & 0xff, ((x) >> 8) & 0xff, \
  49449. + ((x) >> 16) & 0xff, ((x) >> 24) & 0xff }
  49450. +
  49451. +#if 1
  49452. +#define UGETW(w) ((w)[0] | ((w)[1] << 8))
  49453. +#define USETW(w,v) ((w)[0] = (u_int8_t)(v), (w)[1] = (u_int8_t)((v) >> 8))
  49454. +#define UGETDW(w) ((w)[0] | ((w)[1] << 8) | ((w)[2] << 16) | ((w)[3] << 24))
  49455. +#define USETDW(w,v) ((w)[0] = (u_int8_t)(v), \
  49456. + (w)[1] = (u_int8_t)((v) >> 8), \
  49457. + (w)[2] = (u_int8_t)((v) >> 16), \
  49458. + (w)[3] = (u_int8_t)((v) >> 24))
  49459. +#else
  49460. +/*
  49461. + * On little-endian machines that can handle unanliged accesses
  49462. + * (e.g. i386) these macros can be replaced by the following.
  49463. + */
  49464. +#define UGETW(w) (*(u_int16_t *)(w))
  49465. +#define USETW(w,v) (*(u_int16_t *)(w) = (v))
  49466. +#define UGETDW(w) (*(u_int32_t *)(w))
  49467. +#define USETDW(w,v) (*(u_int32_t *)(w) = (v))
  49468. +#endif
  49469. +
  49470. +/*
  49471. + * Macros for accessing UAS IU fields, which are big-endian
  49472. + */
  49473. +#define IUSETW2(w,h,l) ((w)[0] = (u_int8_t)(h), (w)[1] = (u_int8_t)(l))
  49474. +#define IUCONSTW(x) { ((x) >> 8) & 0xff, (x) & 0xff }
  49475. +#define IUCONSTDW(x) { ((x) >> 24) & 0xff, ((x) >> 16) & 0xff, \
  49476. + ((x) >> 8) & 0xff, (x) & 0xff }
  49477. +#define IUGETW(w) (((w)[0] << 8) | (w)[1])
  49478. +#define IUSETW(w,v) ((w)[0] = (u_int8_t)((v) >> 8), (w)[1] = (u_int8_t)(v))
  49479. +#define IUGETDW(w) (((w)[0] << 24) | ((w)[1] << 16) | ((w)[2] << 8) | (w)[3])
  49480. +#define IUSETDW(w,v) ((w)[0] = (u_int8_t)((v) >> 24), \
  49481. + (w)[1] = (u_int8_t)((v) >> 16), \
  49482. + (w)[2] = (u_int8_t)((v) >> 8), \
  49483. + (w)[3] = (u_int8_t)(v))
  49484. +
  49485. +#define UPACKED __attribute__((__packed__))
  49486. +
  49487. +typedef struct {
  49488. + uByte bmRequestType;
  49489. + uByte bRequest;
  49490. + uWord wValue;
  49491. + uWord wIndex;
  49492. + uWord wLength;
  49493. +} UPACKED usb_device_request_t;
  49494. +
  49495. +#define UT_GET_DIR(a) ((a) & 0x80)
  49496. +#define UT_WRITE 0x00
  49497. +#define UT_READ 0x80
  49498. +
  49499. +#define UT_GET_TYPE(a) ((a) & 0x60)
  49500. +#define UT_STANDARD 0x00
  49501. +#define UT_CLASS 0x20
  49502. +#define UT_VENDOR 0x40
  49503. +
  49504. +#define UT_GET_RECIPIENT(a) ((a) & 0x1f)
  49505. +#define UT_DEVICE 0x00
  49506. +#define UT_INTERFACE 0x01
  49507. +#define UT_ENDPOINT 0x02
  49508. +#define UT_OTHER 0x03
  49509. +
  49510. +#define UT_READ_DEVICE (UT_READ | UT_STANDARD | UT_DEVICE)
  49511. +#define UT_READ_INTERFACE (UT_READ | UT_STANDARD | UT_INTERFACE)
  49512. +#define UT_READ_ENDPOINT (UT_READ | UT_STANDARD | UT_ENDPOINT)
  49513. +#define UT_WRITE_DEVICE (UT_WRITE | UT_STANDARD | UT_DEVICE)
  49514. +#define UT_WRITE_INTERFACE (UT_WRITE | UT_STANDARD | UT_INTERFACE)
  49515. +#define UT_WRITE_ENDPOINT (UT_WRITE | UT_STANDARD | UT_ENDPOINT)
  49516. +#define UT_READ_CLASS_DEVICE (UT_READ | UT_CLASS | UT_DEVICE)
  49517. +#define UT_READ_CLASS_INTERFACE (UT_READ | UT_CLASS | UT_INTERFACE)
  49518. +#define UT_READ_CLASS_OTHER (UT_READ | UT_CLASS | UT_OTHER)
  49519. +#define UT_READ_CLASS_ENDPOINT (UT_READ | UT_CLASS | UT_ENDPOINT)
  49520. +#define UT_WRITE_CLASS_DEVICE (UT_WRITE | UT_CLASS | UT_DEVICE)
  49521. +#define UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE)
  49522. +#define UT_WRITE_CLASS_OTHER (UT_WRITE | UT_CLASS | UT_OTHER)
  49523. +#define UT_WRITE_CLASS_ENDPOINT (UT_WRITE | UT_CLASS | UT_ENDPOINT)
  49524. +#define UT_READ_VENDOR_DEVICE (UT_READ | UT_VENDOR | UT_DEVICE)
  49525. +#define UT_READ_VENDOR_INTERFACE (UT_READ | UT_VENDOR | UT_INTERFACE)
  49526. +#define UT_READ_VENDOR_OTHER (UT_READ | UT_VENDOR | UT_OTHER)
  49527. +#define UT_READ_VENDOR_ENDPOINT (UT_READ | UT_VENDOR | UT_ENDPOINT)
  49528. +#define UT_WRITE_VENDOR_DEVICE (UT_WRITE | UT_VENDOR | UT_DEVICE)
  49529. +#define UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE)
  49530. +#define UT_WRITE_VENDOR_OTHER (UT_WRITE | UT_VENDOR | UT_OTHER)
  49531. +#define UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT)
  49532. +
  49533. +/* Requests */
  49534. +#define UR_GET_STATUS 0x00
  49535. +#define USTAT_STANDARD_STATUS 0x00
  49536. +#define WUSTAT_WUSB_FEATURE 0x01
  49537. +#define WUSTAT_CHANNEL_INFO 0x02
  49538. +#define WUSTAT_RECEIVED_DATA 0x03
  49539. +#define WUSTAT_MAS_AVAILABILITY 0x04
  49540. +#define WUSTAT_CURRENT_TRANSMIT_POWER 0x05
  49541. +#define UR_CLEAR_FEATURE 0x01
  49542. +#define UR_SET_FEATURE 0x03
  49543. +#define UR_SET_AND_TEST_FEATURE 0x0c
  49544. +#define UR_SET_ADDRESS 0x05
  49545. +#define UR_GET_DESCRIPTOR 0x06
  49546. +#define UDESC_DEVICE 0x01
  49547. +#define UDESC_CONFIG 0x02
  49548. +#define UDESC_STRING 0x03
  49549. +#define UDESC_INTERFACE 0x04
  49550. +#define UDESC_ENDPOINT 0x05
  49551. +#define UDESC_SS_USB_COMPANION 0x30
  49552. +#define UDESC_DEVICE_QUALIFIER 0x06
  49553. +#define UDESC_OTHER_SPEED_CONFIGURATION 0x07
  49554. +#define UDESC_INTERFACE_POWER 0x08
  49555. +#define UDESC_OTG 0x09
  49556. +#define WUDESC_SECURITY 0x0c
  49557. +#define WUDESC_KEY 0x0d
  49558. +#define WUD_GET_KEY_INDEX(_wValue_) ((_wValue_) & 0xf)
  49559. +#define WUD_GET_KEY_TYPE(_wValue_) (((_wValue_) & 0x30) >> 4)
  49560. +#define WUD_KEY_TYPE_ASSOC 0x01
  49561. +#define WUD_KEY_TYPE_GTK 0x02
  49562. +#define WUD_GET_KEY_ORIGIN(_wValue_) (((_wValue_) & 0x40) >> 6)
  49563. +#define WUD_KEY_ORIGIN_HOST 0x00
  49564. +#define WUD_KEY_ORIGIN_DEVICE 0x01
  49565. +#define WUDESC_ENCRYPTION_TYPE 0x0e
  49566. +#define WUDESC_BOS 0x0f
  49567. +#define WUDESC_DEVICE_CAPABILITY 0x10
  49568. +#define WUDESC_WIRELESS_ENDPOINT_COMPANION 0x11
  49569. +#define UDESC_BOS 0x0f
  49570. +#define UDESC_DEVICE_CAPABILITY 0x10
  49571. +#define UDESC_CS_DEVICE 0x21 /* class specific */
  49572. +#define UDESC_CS_CONFIG 0x22
  49573. +#define UDESC_CS_STRING 0x23
  49574. +#define UDESC_CS_INTERFACE 0x24
  49575. +#define UDESC_CS_ENDPOINT 0x25
  49576. +#define UDESC_HUB 0x29
  49577. +#define UR_SET_DESCRIPTOR 0x07
  49578. +#define UR_GET_CONFIG 0x08
  49579. +#define UR_SET_CONFIG 0x09
  49580. +#define UR_GET_INTERFACE 0x0a
  49581. +#define UR_SET_INTERFACE 0x0b
  49582. +#define UR_SYNCH_FRAME 0x0c
  49583. +#define WUR_SET_ENCRYPTION 0x0d
  49584. +#define WUR_GET_ENCRYPTION 0x0e
  49585. +#define WUR_SET_HANDSHAKE 0x0f
  49586. +#define WUR_GET_HANDSHAKE 0x10
  49587. +#define WUR_SET_CONNECTION 0x11
  49588. +#define WUR_SET_SECURITY_DATA 0x12
  49589. +#define WUR_GET_SECURITY_DATA 0x13
  49590. +#define WUR_SET_WUSB_DATA 0x14
  49591. +#define WUDATA_DRPIE_INFO 0x01
  49592. +#define WUDATA_TRANSMIT_DATA 0x02
  49593. +#define WUDATA_TRANSMIT_PARAMS 0x03
  49594. +#define WUDATA_RECEIVE_PARAMS 0x04
  49595. +#define WUDATA_TRANSMIT_POWER 0x05
  49596. +#define WUR_LOOPBACK_DATA_WRITE 0x15
  49597. +#define WUR_LOOPBACK_DATA_READ 0x16
  49598. +#define WUR_SET_INTERFACE_DS 0x17
  49599. +
  49600. +/* Feature numbers */
  49601. +#define UF_ENDPOINT_HALT 0
  49602. +#define UF_DEVICE_REMOTE_WAKEUP 1
  49603. +#define UF_TEST_MODE 2
  49604. +#define UF_DEVICE_B_HNP_ENABLE 3
  49605. +#define UF_DEVICE_A_HNP_SUPPORT 4
  49606. +#define UF_DEVICE_A_ALT_HNP_SUPPORT 5
  49607. +#define WUF_WUSB 3
  49608. +#define WUF_TX_DRPIE 0x0
  49609. +#define WUF_DEV_XMIT_PACKET 0x1
  49610. +#define WUF_COUNT_PACKETS 0x2
  49611. +#define WUF_CAPTURE_PACKETS 0x3
  49612. +#define UF_FUNCTION_SUSPEND 0
  49613. +#define UF_U1_ENABLE 48
  49614. +#define UF_U2_ENABLE 49
  49615. +#define UF_LTM_ENABLE 50
  49616. +
  49617. +/* Class requests from the USB 2.0 hub spec, table 11-15 */
  49618. +#define UCR_CLEAR_HUB_FEATURE (0x2000 | UR_CLEAR_FEATURE)
  49619. +#define UCR_CLEAR_PORT_FEATURE (0x2300 | UR_CLEAR_FEATURE)
  49620. +#define UCR_GET_HUB_DESCRIPTOR (0xa000 | UR_GET_DESCRIPTOR)
  49621. +#define UCR_GET_HUB_STATUS (0xa000 | UR_GET_STATUS)
  49622. +#define UCR_GET_PORT_STATUS (0xa300 | UR_GET_STATUS)
  49623. +#define UCR_SET_HUB_FEATURE (0x2000 | UR_SET_FEATURE)
  49624. +#define UCR_SET_PORT_FEATURE (0x2300 | UR_SET_FEATURE)
  49625. +#define UCR_SET_AND_TEST_PORT_FEATURE (0xa300 | UR_SET_AND_TEST_FEATURE)
  49626. +
  49627. +#ifdef _MSC_VER
  49628. +#include <pshpack1.h>
  49629. +#endif
  49630. +
  49631. +typedef struct {
  49632. + uByte bLength;
  49633. + uByte bDescriptorType;
  49634. + uByte bDescriptorSubtype;
  49635. +} UPACKED usb_descriptor_t;
  49636. +
  49637. +typedef struct {
  49638. + uByte bLength;
  49639. + uByte bDescriptorType;
  49640. +} UPACKED usb_descriptor_header_t;
  49641. +
  49642. +typedef struct {
  49643. + uByte bLength;
  49644. + uByte bDescriptorType;
  49645. + uWord bcdUSB;
  49646. +#define UD_USB_2_0 0x0200
  49647. +#define UD_IS_USB2(d) (UGETW((d)->bcdUSB) >= UD_USB_2_0)
  49648. + uByte bDeviceClass;
  49649. + uByte bDeviceSubClass;
  49650. + uByte bDeviceProtocol;
  49651. + uByte bMaxPacketSize;
  49652. + /* The fields below are not part of the initial descriptor. */
  49653. + uWord idVendor;
  49654. + uWord idProduct;
  49655. + uWord bcdDevice;
  49656. + uByte iManufacturer;
  49657. + uByte iProduct;
  49658. + uByte iSerialNumber;
  49659. + uByte bNumConfigurations;
  49660. +} UPACKED usb_device_descriptor_t;
  49661. +#define USB_DEVICE_DESCRIPTOR_SIZE 18
  49662. +
  49663. +typedef struct {
  49664. + uByte bLength;
  49665. + uByte bDescriptorType;
  49666. + uWord wTotalLength;
  49667. + uByte bNumInterface;
  49668. + uByte bConfigurationValue;
  49669. + uByte iConfiguration;
  49670. +#define UC_ATT_ONE (1 << 7) /* must be set */
  49671. +#define UC_ATT_SELFPOWER (1 << 6) /* self powered */
  49672. +#define UC_ATT_WAKEUP (1 << 5) /* can wakeup */
  49673. +#define UC_ATT_BATTERY (1 << 4) /* battery powered */
  49674. + uByte bmAttributes;
  49675. +#define UC_BUS_POWERED 0x80
  49676. +#define UC_SELF_POWERED 0x40
  49677. +#define UC_REMOTE_WAKEUP 0x20
  49678. + uByte bMaxPower; /* max current in 2 mA units */
  49679. +#define UC_POWER_FACTOR 2
  49680. +} UPACKED usb_config_descriptor_t;
  49681. +#define USB_CONFIG_DESCRIPTOR_SIZE 9
  49682. +
  49683. +typedef struct {
  49684. + uByte bLength;
  49685. + uByte bDescriptorType;
  49686. + uByte bInterfaceNumber;
  49687. + uByte bAlternateSetting;
  49688. + uByte bNumEndpoints;
  49689. + uByte bInterfaceClass;
  49690. + uByte bInterfaceSubClass;
  49691. + uByte bInterfaceProtocol;
  49692. + uByte iInterface;
  49693. +} UPACKED usb_interface_descriptor_t;
  49694. +#define USB_INTERFACE_DESCRIPTOR_SIZE 9
  49695. +
  49696. +typedef struct {
  49697. + uByte bLength;
  49698. + uByte bDescriptorType;
  49699. + uByte bEndpointAddress;
  49700. +#define UE_GET_DIR(a) ((a) & 0x80)
  49701. +#define UE_SET_DIR(a,d) ((a) | (((d)&1) << 7))
  49702. +#define UE_DIR_IN 0x80
  49703. +#define UE_DIR_OUT 0x00
  49704. +#define UE_ADDR 0x0f
  49705. +#define UE_GET_ADDR(a) ((a) & UE_ADDR)
  49706. + uByte bmAttributes;
  49707. +#define UE_XFERTYPE 0x03
  49708. +#define UE_CONTROL 0x00
  49709. +#define UE_ISOCHRONOUS 0x01
  49710. +#define UE_BULK 0x02
  49711. +#define UE_INTERRUPT 0x03
  49712. +#define UE_GET_XFERTYPE(a) ((a) & UE_XFERTYPE)
  49713. +#define UE_ISO_TYPE 0x0c
  49714. +#define UE_ISO_ASYNC 0x04
  49715. +#define UE_ISO_ADAPT 0x08
  49716. +#define UE_ISO_SYNC 0x0c
  49717. +#define UE_GET_ISO_TYPE(a) ((a) & UE_ISO_TYPE)
  49718. + uWord wMaxPacketSize;
  49719. + uByte bInterval;
  49720. +} UPACKED usb_endpoint_descriptor_t;
  49721. +#define USB_ENDPOINT_DESCRIPTOR_SIZE 7
  49722. +
  49723. +typedef struct ss_endpoint_companion_descriptor {
  49724. + uByte bLength;
  49725. + uByte bDescriptorType;
  49726. + uByte bMaxBurst;
  49727. +#define USSE_GET_MAX_STREAMS(a) ((a) & 0x1f)
  49728. +#define USSE_SET_MAX_STREAMS(a, b) ((a) | ((b) & 0x1f))
  49729. +#define USSE_GET_MAX_PACKET_NUM(a) ((a) & 0x03)
  49730. +#define USSE_SET_MAX_PACKET_NUM(a, b) ((a) | ((b) & 0x03))
  49731. + uByte bmAttributes;
  49732. + uWord wBytesPerInterval;
  49733. +} UPACKED ss_endpoint_companion_descriptor_t;
  49734. +#define USB_SS_ENDPOINT_COMPANION_DESCRIPTOR_SIZE 6
  49735. +
  49736. +typedef struct {
  49737. + uByte bLength;
  49738. + uByte bDescriptorType;
  49739. + uWord bString[127];
  49740. +} UPACKED usb_string_descriptor_t;
  49741. +#define USB_MAX_STRING_LEN 128
  49742. +#define USB_LANGUAGE_TABLE 0 /* # of the string language id table */
  49743. +
  49744. +/* Hub specific request */
  49745. +#define UR_GET_BUS_STATE 0x02
  49746. +#define UR_CLEAR_TT_BUFFER 0x08
  49747. +#define UR_RESET_TT 0x09
  49748. +#define UR_GET_TT_STATE 0x0a
  49749. +#define UR_STOP_TT 0x0b
  49750. +
  49751. +/* Hub features */
  49752. +#define UHF_C_HUB_LOCAL_POWER 0
  49753. +#define UHF_C_HUB_OVER_CURRENT 1
  49754. +#define UHF_PORT_CONNECTION 0
  49755. +#define UHF_PORT_ENABLE 1
  49756. +#define UHF_PORT_SUSPEND 2
  49757. +#define UHF_PORT_OVER_CURRENT 3
  49758. +#define UHF_PORT_RESET 4
  49759. +#define UHF_PORT_L1 5
  49760. +#define UHF_PORT_POWER 8
  49761. +#define UHF_PORT_LOW_SPEED 9
  49762. +#define UHF_PORT_HIGH_SPEED 10
  49763. +#define UHF_C_PORT_CONNECTION 16
  49764. +#define UHF_C_PORT_ENABLE 17
  49765. +#define UHF_C_PORT_SUSPEND 18
  49766. +#define UHF_C_PORT_OVER_CURRENT 19
  49767. +#define UHF_C_PORT_RESET 20
  49768. +#define UHF_C_PORT_L1 23
  49769. +#define UHF_PORT_TEST 21
  49770. +#define UHF_PORT_INDICATOR 22
  49771. +
  49772. +typedef struct {
  49773. + uByte bDescLength;
  49774. + uByte bDescriptorType;
  49775. + uByte bNbrPorts;
  49776. + uWord wHubCharacteristics;
  49777. +#define UHD_PWR 0x0003
  49778. +#define UHD_PWR_GANGED 0x0000
  49779. +#define UHD_PWR_INDIVIDUAL 0x0001
  49780. +#define UHD_PWR_NO_SWITCH 0x0002
  49781. +#define UHD_COMPOUND 0x0004
  49782. +#define UHD_OC 0x0018
  49783. +#define UHD_OC_GLOBAL 0x0000
  49784. +#define UHD_OC_INDIVIDUAL 0x0008
  49785. +#define UHD_OC_NONE 0x0010
  49786. +#define UHD_TT_THINK 0x0060
  49787. +#define UHD_TT_THINK_8 0x0000
  49788. +#define UHD_TT_THINK_16 0x0020
  49789. +#define UHD_TT_THINK_24 0x0040
  49790. +#define UHD_TT_THINK_32 0x0060
  49791. +#define UHD_PORT_IND 0x0080
  49792. + uByte bPwrOn2PwrGood; /* delay in 2 ms units */
  49793. +#define UHD_PWRON_FACTOR 2
  49794. + uByte bHubContrCurrent;
  49795. + uByte DeviceRemovable[32]; /* max 255 ports */
  49796. +#define UHD_NOT_REMOV(desc, i) \
  49797. + (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
  49798. + /* deprecated */ uByte PortPowerCtrlMask[1];
  49799. +} UPACKED usb_hub_descriptor_t;
  49800. +#define USB_HUB_DESCRIPTOR_SIZE 9 /* includes deprecated PortPowerCtrlMask */
  49801. +
  49802. +typedef struct {
  49803. + uByte bLength;
  49804. + uByte bDescriptorType;
  49805. + uWord bcdUSB;
  49806. + uByte bDeviceClass;
  49807. + uByte bDeviceSubClass;
  49808. + uByte bDeviceProtocol;
  49809. + uByte bMaxPacketSize0;
  49810. + uByte bNumConfigurations;
  49811. + uByte bReserved;
  49812. +} UPACKED usb_device_qualifier_t;
  49813. +#define USB_DEVICE_QUALIFIER_SIZE 10
  49814. +
  49815. +typedef struct {
  49816. + uByte bLength;
  49817. + uByte bDescriptorType;
  49818. + uByte bmAttributes;
  49819. +#define UOTG_SRP 0x01
  49820. +#define UOTG_HNP 0x02
  49821. +} UPACKED usb_otg_descriptor_t;
  49822. +
  49823. +/* OTG feature selectors */
  49824. +#define UOTG_B_HNP_ENABLE 3
  49825. +#define UOTG_A_HNP_SUPPORT 4
  49826. +#define UOTG_A_ALT_HNP_SUPPORT 5
  49827. +
  49828. +typedef struct {
  49829. + uWord wStatus;
  49830. +/* Device status flags */
  49831. +#define UDS_SELF_POWERED 0x0001
  49832. +#define UDS_REMOTE_WAKEUP 0x0002
  49833. +/* Endpoint status flags */
  49834. +#define UES_HALT 0x0001
  49835. +} UPACKED usb_status_t;
  49836. +
  49837. +typedef struct {
  49838. + uWord wHubStatus;
  49839. +#define UHS_LOCAL_POWER 0x0001
  49840. +#define UHS_OVER_CURRENT 0x0002
  49841. + uWord wHubChange;
  49842. +} UPACKED usb_hub_status_t;
  49843. +
  49844. +typedef struct {
  49845. + uWord wPortStatus;
  49846. +#define UPS_CURRENT_CONNECT_STATUS 0x0001
  49847. +#define UPS_PORT_ENABLED 0x0002
  49848. +#define UPS_SUSPEND 0x0004
  49849. +#define UPS_OVERCURRENT_INDICATOR 0x0008
  49850. +#define UPS_RESET 0x0010
  49851. +#define UPS_PORT_POWER 0x0100
  49852. +#define UPS_LOW_SPEED 0x0200
  49853. +#define UPS_HIGH_SPEED 0x0400
  49854. +#define UPS_PORT_TEST 0x0800
  49855. +#define UPS_PORT_INDICATOR 0x1000
  49856. + uWord wPortChange;
  49857. +#define UPS_C_CONNECT_STATUS 0x0001
  49858. +#define UPS_C_PORT_ENABLED 0x0002
  49859. +#define UPS_C_SUSPEND 0x0004
  49860. +#define UPS_C_OVERCURRENT_INDICATOR 0x0008
  49861. +#define UPS_C_PORT_RESET 0x0010
  49862. +} UPACKED usb_port_status_t;
  49863. +
  49864. +#ifdef _MSC_VER
  49865. +#include <poppack.h>
  49866. +#endif
  49867. +
  49868. +/* Device class codes */
  49869. +#define UDCLASS_IN_INTERFACE 0x00
  49870. +#define UDCLASS_COMM 0x02
  49871. +#define UDCLASS_HUB 0x09
  49872. +#define UDSUBCLASS_HUB 0x00
  49873. +#define UDPROTO_FSHUB 0x00
  49874. +#define UDPROTO_HSHUBSTT 0x01
  49875. +#define UDPROTO_HSHUBMTT 0x02
  49876. +#define UDCLASS_DIAGNOSTIC 0xdc
  49877. +#define UDCLASS_WIRELESS 0xe0
  49878. +#define UDSUBCLASS_RF 0x01
  49879. +#define UDPROTO_BLUETOOTH 0x01
  49880. +#define UDCLASS_VENDOR 0xff
  49881. +
  49882. +/* Interface class codes */
  49883. +#define UICLASS_UNSPEC 0x00
  49884. +
  49885. +#define UICLASS_AUDIO 0x01
  49886. +#define UISUBCLASS_AUDIOCONTROL 1
  49887. +#define UISUBCLASS_AUDIOSTREAM 2
  49888. +#define UISUBCLASS_MIDISTREAM 3
  49889. +
  49890. +#define UICLASS_CDC 0x02 /* communication */
  49891. +#define UISUBCLASS_DIRECT_LINE_CONTROL_MODEL 1
  49892. +#define UISUBCLASS_ABSTRACT_CONTROL_MODEL 2
  49893. +#define UISUBCLASS_TELEPHONE_CONTROL_MODEL 3
  49894. +#define UISUBCLASS_MULTICHANNEL_CONTROL_MODEL 4
  49895. +#define UISUBCLASS_CAPI_CONTROLMODEL 5
  49896. +#define UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
  49897. +#define UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
  49898. +#define UIPROTO_CDC_AT 1
  49899. +
  49900. +#define UICLASS_HID 0x03
  49901. +#define UISUBCLASS_BOOT 1
  49902. +#define UIPROTO_BOOT_KEYBOARD 1
  49903. +
  49904. +#define UICLASS_PHYSICAL 0x05
  49905. +
  49906. +#define UICLASS_IMAGE 0x06
  49907. +
  49908. +#define UICLASS_PRINTER 0x07
  49909. +#define UISUBCLASS_PRINTER 1
  49910. +#define UIPROTO_PRINTER_UNI 1
  49911. +#define UIPROTO_PRINTER_BI 2
  49912. +#define UIPROTO_PRINTER_1284 3
  49913. +
  49914. +#define UICLASS_MASS 0x08
  49915. +#define UISUBCLASS_RBC 1
  49916. +#define UISUBCLASS_SFF8020I 2
  49917. +#define UISUBCLASS_QIC157 3
  49918. +#define UISUBCLASS_UFI 4
  49919. +#define UISUBCLASS_SFF8070I 5
  49920. +#define UISUBCLASS_SCSI 6
  49921. +#define UIPROTO_MASS_CBI_I 0
  49922. +#define UIPROTO_MASS_CBI 1
  49923. +#define UIPROTO_MASS_BBB_OLD 2 /* Not in the spec anymore */
  49924. +#define UIPROTO_MASS_BBB 80 /* 'P' for the Iomega Zip drive */
  49925. +
  49926. +#define UICLASS_HUB 0x09
  49927. +#define UISUBCLASS_HUB 0
  49928. +#define UIPROTO_FSHUB 0
  49929. +#define UIPROTO_HSHUBSTT 0 /* Yes, same as previous */
  49930. +#define UIPROTO_HSHUBMTT 1
  49931. +
  49932. +#define UICLASS_CDC_DATA 0x0a
  49933. +#define UISUBCLASS_DATA 0
  49934. +#define UIPROTO_DATA_ISDNBRI 0x30 /* Physical iface */
  49935. +#define UIPROTO_DATA_HDLC 0x31 /* HDLC */
  49936. +#define UIPROTO_DATA_TRANSPARENT 0x32 /* Transparent */
  49937. +#define UIPROTO_DATA_Q921M 0x50 /* Management for Q921 */
  49938. +#define UIPROTO_DATA_Q921 0x51 /* Data for Q921 */
  49939. +#define UIPROTO_DATA_Q921TM 0x52 /* TEI multiplexer for Q921 */
  49940. +#define UIPROTO_DATA_V42BIS 0x90 /* Data compression */
  49941. +#define UIPROTO_DATA_Q931 0x91 /* Euro-ISDN */
  49942. +#define UIPROTO_DATA_V120 0x92 /* V.24 rate adaption */
  49943. +#define UIPROTO_DATA_CAPI 0x93 /* CAPI 2.0 commands */
  49944. +#define UIPROTO_DATA_HOST_BASED 0xfd /* Host based driver */
  49945. +#define UIPROTO_DATA_PUF 0xfe /* see Prot. Unit Func. Desc.*/
  49946. +#define UIPROTO_DATA_VENDOR 0xff /* Vendor specific */
  49947. +
  49948. +#define UICLASS_SMARTCARD 0x0b
  49949. +
  49950. +/*#define UICLASS_FIRM_UPD 0x0c*/
  49951. +
  49952. +#define UICLASS_SECURITY 0x0d
  49953. +
  49954. +#define UICLASS_DIAGNOSTIC 0xdc
  49955. +
  49956. +#define UICLASS_WIRELESS 0xe0
  49957. +#define UISUBCLASS_RF 0x01
  49958. +#define UIPROTO_BLUETOOTH 0x01
  49959. +
  49960. +#define UICLASS_APPL_SPEC 0xfe
  49961. +#define UISUBCLASS_FIRMWARE_DOWNLOAD 1
  49962. +#define UISUBCLASS_IRDA 2
  49963. +#define UIPROTO_IRDA 0
  49964. +
  49965. +#define UICLASS_VENDOR 0xff
  49966. +
  49967. +#define USB_HUB_MAX_DEPTH 5
  49968. +
  49969. +/*
  49970. + * Minimum time a device needs to be powered down to go through
  49971. + * a power cycle. XXX Are these time in the spec?
  49972. + */
  49973. +#define USB_POWER_DOWN_TIME 200 /* ms */
  49974. +#define USB_PORT_POWER_DOWN_TIME 100 /* ms */
  49975. +
  49976. +#if 0
  49977. +/* These are the values from the spec. */
  49978. +#define USB_PORT_RESET_DELAY 10 /* ms */
  49979. +#define USB_PORT_ROOT_RESET_DELAY 50 /* ms */
  49980. +#define USB_PORT_RESET_RECOVERY 10 /* ms */
  49981. +#define USB_PORT_POWERUP_DELAY 100 /* ms */
  49982. +#define USB_SET_ADDRESS_SETTLE 2 /* ms */
  49983. +#define USB_RESUME_DELAY (20*5) /* ms */
  49984. +#define USB_RESUME_WAIT 10 /* ms */
  49985. +#define USB_RESUME_RECOVERY 10 /* ms */
  49986. +#define USB_EXTRA_POWER_UP_TIME 0 /* ms */
  49987. +#else
  49988. +/* Allow for marginal (i.e. non-conforming) devices. */
  49989. +#define USB_PORT_RESET_DELAY 50 /* ms */
  49990. +#define USB_PORT_ROOT_RESET_DELAY 250 /* ms */
  49991. +#define USB_PORT_RESET_RECOVERY 250 /* ms */
  49992. +#define USB_PORT_POWERUP_DELAY 300 /* ms */
  49993. +#define USB_SET_ADDRESS_SETTLE 10 /* ms */
  49994. +#define USB_RESUME_DELAY (50*5) /* ms */
  49995. +#define USB_RESUME_WAIT 50 /* ms */
  49996. +#define USB_RESUME_RECOVERY 50 /* ms */
  49997. +#define USB_EXTRA_POWER_UP_TIME 20 /* ms */
  49998. +#endif
  49999. +
  50000. +#define USB_MIN_POWER 100 /* mA */
  50001. +#define USB_MAX_POWER 500 /* mA */
  50002. +
  50003. +#define USB_BUS_RESET_DELAY 100 /* ms XXX?*/
  50004. +
  50005. +#define USB_UNCONFIG_NO 0
  50006. +#define USB_UNCONFIG_INDEX (-1)
  50007. +
  50008. +/*** ioctl() related stuff ***/
  50009. +
  50010. +struct usb_ctl_request {
  50011. + int ucr_addr;
  50012. + usb_device_request_t ucr_request;
  50013. + void *ucr_data;
  50014. + int ucr_flags;
  50015. +#define USBD_SHORT_XFER_OK 0x04 /* allow short reads */
  50016. + int ucr_actlen; /* actual length transferred */
  50017. +};
  50018. +
  50019. +struct usb_alt_interface {
  50020. + int uai_config_index;
  50021. + int uai_interface_index;
  50022. + int uai_alt_no;
  50023. +};
  50024. +
  50025. +#define USB_CURRENT_CONFIG_INDEX (-1)
  50026. +#define USB_CURRENT_ALT_INDEX (-1)
  50027. +
  50028. +struct usb_config_desc {
  50029. + int ucd_config_index;
  50030. + usb_config_descriptor_t ucd_desc;
  50031. +};
  50032. +
  50033. +struct usb_interface_desc {
  50034. + int uid_config_index;
  50035. + int uid_interface_index;
  50036. + int uid_alt_index;
  50037. + usb_interface_descriptor_t uid_desc;
  50038. +};
  50039. +
  50040. +struct usb_endpoint_desc {
  50041. + int ued_config_index;
  50042. + int ued_interface_index;
  50043. + int ued_alt_index;
  50044. + int ued_endpoint_index;
  50045. + usb_endpoint_descriptor_t ued_desc;
  50046. +};
  50047. +
  50048. +struct usb_full_desc {
  50049. + int ufd_config_index;
  50050. + u_int ufd_size;
  50051. + u_char *ufd_data;
  50052. +};
  50053. +
  50054. +struct usb_string_desc {
  50055. + int usd_string_index;
  50056. + int usd_language_id;
  50057. + usb_string_descriptor_t usd_desc;
  50058. +};
  50059. +
  50060. +struct usb_ctl_report_desc {
  50061. + int ucrd_size;
  50062. + u_char ucrd_data[1024]; /* filled data size will vary */
  50063. +};
  50064. +
  50065. +typedef struct { u_int32_t cookie; } usb_event_cookie_t;
  50066. +
  50067. +#define USB_MAX_DEVNAMES 4
  50068. +#define USB_MAX_DEVNAMELEN 16
  50069. +struct usb_device_info {
  50070. + u_int8_t udi_bus;
  50071. + u_int8_t udi_addr; /* device address */
  50072. + usb_event_cookie_t udi_cookie;
  50073. + char udi_product[USB_MAX_STRING_LEN];
  50074. + char udi_vendor[USB_MAX_STRING_LEN];
  50075. + char udi_release[8];
  50076. + u_int16_t udi_productNo;
  50077. + u_int16_t udi_vendorNo;
  50078. + u_int16_t udi_releaseNo;
  50079. + u_int8_t udi_class;
  50080. + u_int8_t udi_subclass;
  50081. + u_int8_t udi_protocol;
  50082. + u_int8_t udi_config;
  50083. + u_int8_t udi_speed;
  50084. +#define USB_SPEED_UNKNOWN 0
  50085. +#define USB_SPEED_LOW 1
  50086. +#define USB_SPEED_FULL 2
  50087. +#define USB_SPEED_HIGH 3
  50088. +#define USB_SPEED_VARIABLE 4
  50089. +#define USB_SPEED_SUPER 5
  50090. + int udi_power; /* power consumption in mA, 0 if selfpowered */
  50091. + int udi_nports;
  50092. + char udi_devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
  50093. + u_int8_t udi_ports[16];/* hub only: addresses of devices on ports */
  50094. +#define USB_PORT_ENABLED 0xff
  50095. +#define USB_PORT_SUSPENDED 0xfe
  50096. +#define USB_PORT_POWERED 0xfd
  50097. +#define USB_PORT_DISABLED 0xfc
  50098. +};
  50099. +
  50100. +struct usb_ctl_report {
  50101. + int ucr_report;
  50102. + u_char ucr_data[1024]; /* filled data size will vary */
  50103. +};
  50104. +
  50105. +struct usb_device_stats {
  50106. + u_long uds_requests[4]; /* indexed by transfer type UE_* */
  50107. +};
  50108. +
  50109. +#define WUSB_MIN_IE 0x80
  50110. +#define WUSB_WCTA_IE 0x80
  50111. +#define WUSB_WCONNECTACK_IE 0x81
  50112. +#define WUSB_WHOSTINFO_IE 0x82
  50113. +#define WUHI_GET_CA(_bmAttributes_) ((_bmAttributes_) & 0x3)
  50114. +#define WUHI_CA_RECONN 0x00
  50115. +#define WUHI_CA_LIMITED 0x01
  50116. +#define WUHI_CA_ALL 0x03
  50117. +#define WUHI_GET_MLSI(_bmAttributes_) (((_bmAttributes_) & 0x38) >> 3)
  50118. +#define WUSB_WCHCHANGEANNOUNCE_IE 0x83
  50119. +#define WUSB_WDEV_DISCONNECT_IE 0x84
  50120. +#define WUSB_WHOST_DISCONNECT_IE 0x85
  50121. +#define WUSB_WRELEASE_CHANNEL_IE 0x86
  50122. +#define WUSB_WWORK_IE 0x87
  50123. +#define WUSB_WCHANNEL_STOP_IE 0x88
  50124. +#define WUSB_WDEV_KEEPALIVE_IE 0x89
  50125. +#define WUSB_WISOCH_DISCARD_IE 0x8A
  50126. +#define WUSB_WRESETDEVICE_IE 0x8B
  50127. +#define WUSB_WXMIT_PACKET_ADJUST_IE 0x8C
  50128. +#define WUSB_MAX_IE 0x8C
  50129. +
  50130. +/* Device Notification Types */
  50131. +
  50132. +#define WUSB_DN_MIN 0x01
  50133. +#define WUSB_DN_CONNECT 0x01
  50134. +# define WUSB_DA_OLDCONN 0x00
  50135. +# define WUSB_DA_NEWCONN 0x01
  50136. +# define WUSB_DA_SELF_BEACON 0x02
  50137. +# define WUSB_DA_DIR_BEACON 0x04
  50138. +# define WUSB_DA_NO_BEACON 0x06
  50139. +#define WUSB_DN_DISCONNECT 0x02
  50140. +#define WUSB_DN_EPRDY 0x03
  50141. +#define WUSB_DN_MASAVAILCHANGED 0x04
  50142. +#define WUSB_DN_REMOTEWAKEUP 0x05
  50143. +#define WUSB_DN_SLEEP 0x06
  50144. +#define WUSB_DN_ALIVE 0x07
  50145. +#define WUSB_DN_MAX 0x07
  50146. +
  50147. +#ifdef _MSC_VER
  50148. +#include <pshpack1.h>
  50149. +#endif
  50150. +
  50151. +/* WUSB Handshake Data. Used during the SET/GET HANDSHAKE requests */
  50152. +typedef struct wusb_hndshk_data {
  50153. + uByte bMessageNumber;
  50154. + uByte bStatus;
  50155. + uByte tTKID[3];
  50156. + uByte bReserved;
  50157. + uByte CDID[16];
  50158. + uByte Nonce[16];
  50159. + uByte MIC[8];
  50160. +} UPACKED wusb_hndshk_data_t;
  50161. +#define WUSB_HANDSHAKE_LEN_FOR_MIC 38
  50162. +
  50163. +/* WUSB Connection Context */
  50164. +typedef struct wusb_conn_context {
  50165. + uByte CHID [16];
  50166. + uByte CDID [16];
  50167. + uByte CK [16];
  50168. +} UPACKED wusb_conn_context_t;
  50169. +
  50170. +/* WUSB Security Descriptor */
  50171. +typedef struct wusb_security_desc {
  50172. + uByte bLength;
  50173. + uByte bDescriptorType;
  50174. + uWord wTotalLength;
  50175. + uByte bNumEncryptionTypes;
  50176. +} UPACKED wusb_security_desc_t;
  50177. +
  50178. +/* WUSB Encryption Type Descriptor */
  50179. +typedef struct wusb_encrypt_type_desc {
  50180. + uByte bLength;
  50181. + uByte bDescriptorType;
  50182. +
  50183. + uByte bEncryptionType;
  50184. +#define WUETD_UNSECURE 0
  50185. +#define WUETD_WIRED 1
  50186. +#define WUETD_CCM_1 2
  50187. +#define WUETD_RSA_1 3
  50188. +
  50189. + uByte bEncryptionValue;
  50190. + uByte bAuthKeyIndex;
  50191. +} UPACKED wusb_encrypt_type_desc_t;
  50192. +
  50193. +/* WUSB Key Descriptor */
  50194. +typedef struct wusb_key_desc {
  50195. + uByte bLength;
  50196. + uByte bDescriptorType;
  50197. + uByte tTKID[3];
  50198. + uByte bReserved;
  50199. + uByte KeyData[1]; /* variable length */
  50200. +} UPACKED wusb_key_desc_t;
  50201. +
  50202. +/* WUSB BOS Descriptor (Binary device Object Store) */
  50203. +typedef struct wusb_bos_desc {
  50204. + uByte bLength;
  50205. + uByte bDescriptorType;
  50206. + uWord wTotalLength;
  50207. + uByte bNumDeviceCaps;
  50208. +} UPACKED wusb_bos_desc_t;
  50209. +
  50210. +#define USB_DEVICE_CAPABILITY_20_EXTENSION 0x02
  50211. +typedef struct usb_dev_cap_20_ext_desc {
  50212. + uByte bLength;
  50213. + uByte bDescriptorType;
  50214. + uByte bDevCapabilityType;
  50215. +#define USB_20_EXT_LPM 0x02
  50216. + uDWord bmAttributes;
  50217. +} UPACKED usb_dev_cap_20_ext_desc_t;
  50218. +
  50219. +#define USB_DEVICE_CAPABILITY_SS_USB 0x03
  50220. +typedef struct usb_dev_cap_ss_usb {
  50221. + uByte bLength;
  50222. + uByte bDescriptorType;
  50223. + uByte bDevCapabilityType;
  50224. +#define USB_DC_SS_USB_LTM_CAPABLE 0x02
  50225. + uByte bmAttributes;
  50226. +#define USB_DC_SS_USB_SPEED_SUPPORT_LOW 0x01
  50227. +#define USB_DC_SS_USB_SPEED_SUPPORT_FULL 0x02
  50228. +#define USB_DC_SS_USB_SPEED_SUPPORT_HIGH 0x04
  50229. +#define USB_DC_SS_USB_SPEED_SUPPORT_SS 0x08
  50230. + uWord wSpeedsSupported;
  50231. + uByte bFunctionalitySupport;
  50232. + uByte bU1DevExitLat;
  50233. + uWord wU2DevExitLat;
  50234. +} UPACKED usb_dev_cap_ss_usb_t;
  50235. +
  50236. +#define USB_DEVICE_CAPABILITY_CONTAINER_ID 0x04
  50237. +typedef struct usb_dev_cap_container_id {
  50238. + uByte bLength;
  50239. + uByte bDescriptorType;
  50240. + uByte bDevCapabilityType;
  50241. + uByte bReserved;
  50242. + uByte containerID[16];
  50243. +} UPACKED usb_dev_cap_container_id_t;
  50244. +
  50245. +/* Device Capability Type Codes */
  50246. +#define WUSB_DEVICE_CAPABILITY_WIRELESS_USB 0x01
  50247. +
  50248. +/* Device Capability Descriptor */
  50249. +typedef struct wusb_dev_cap_desc {
  50250. + uByte bLength;
  50251. + uByte bDescriptorType;
  50252. + uByte bDevCapabilityType;
  50253. + uByte caps[1]; /* Variable length */
  50254. +} UPACKED wusb_dev_cap_desc_t;
  50255. +
  50256. +/* Device Capability Descriptor */
  50257. +typedef struct wusb_dev_cap_uwb_desc {
  50258. + uByte bLength;
  50259. + uByte bDescriptorType;
  50260. + uByte bDevCapabilityType;
  50261. + uByte bmAttributes;
  50262. + uWord wPHYRates; /* Bitmap */
  50263. + uByte bmTFITXPowerInfo;
  50264. + uByte bmFFITXPowerInfo;
  50265. + uWord bmBandGroup;
  50266. + uByte bReserved;
  50267. +} UPACKED wusb_dev_cap_uwb_desc_t;
  50268. +
  50269. +/* Wireless USB Endpoint Companion Descriptor */
  50270. +typedef struct wusb_endpoint_companion_desc {
  50271. + uByte bLength;
  50272. + uByte bDescriptorType;
  50273. + uByte bMaxBurst;
  50274. + uByte bMaxSequence;
  50275. + uWord wMaxStreamDelay;
  50276. + uWord wOverTheAirPacketSize;
  50277. + uByte bOverTheAirInterval;
  50278. + uByte bmCompAttributes;
  50279. +} UPACKED wusb_endpoint_companion_desc_t;
  50280. +
  50281. +/* Wireless USB Numeric Association M1 Data Structure */
  50282. +typedef struct wusb_m1_data {
  50283. + uByte version;
  50284. + uWord langId;
  50285. + uByte deviceFriendlyNameLength;
  50286. + uByte sha_256_m3[32];
  50287. + uByte deviceFriendlyName[256];
  50288. +} UPACKED wusb_m1_data_t;
  50289. +
  50290. +typedef struct wusb_m2_data {
  50291. + uByte version;
  50292. + uWord langId;
  50293. + uByte hostFriendlyNameLength;
  50294. + uByte pkh[384];
  50295. + uByte hostFriendlyName[256];
  50296. +} UPACKED wusb_m2_data_t;
  50297. +
  50298. +typedef struct wusb_m3_data {
  50299. + uByte pkd[384];
  50300. + uByte nd;
  50301. +} UPACKED wusb_m3_data_t;
  50302. +
  50303. +typedef struct wusb_m4_data {
  50304. + uDWord _attributeTypeIdAndLength_1;
  50305. + uWord associationTypeId;
  50306. +
  50307. + uDWord _attributeTypeIdAndLength_2;
  50308. + uWord associationSubTypeId;
  50309. +
  50310. + uDWord _attributeTypeIdAndLength_3;
  50311. + uDWord length;
  50312. +
  50313. + uDWord _attributeTypeIdAndLength_4;
  50314. + uDWord associationStatus;
  50315. +
  50316. + uDWord _attributeTypeIdAndLength_5;
  50317. + uByte chid[16];
  50318. +
  50319. + uDWord _attributeTypeIdAndLength_6;
  50320. + uByte cdid[16];
  50321. +
  50322. + uDWord _attributeTypeIdAndLength_7;
  50323. + uByte bandGroups[2];
  50324. +} UPACKED wusb_m4_data_t;
  50325. +
  50326. +#ifdef _MSC_VER
  50327. +#include <poppack.h>
  50328. +#endif
  50329. +
  50330. +#ifdef __cplusplus
  50331. +}
  50332. +#endif
  50333. +
  50334. +#endif /* _USB_H_ */
  50335. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/doc/doxygen.cfg linux-rpi/drivers/usb/host/dwc_otg/doc/doxygen.cfg
  50336. --- linux-3.15.4/drivers/usb/host/dwc_otg/doc/doxygen.cfg 1970-01-01 01:00:00.000000000 +0100
  50337. +++ linux-rpi/drivers/usb/host/dwc_otg/doc/doxygen.cfg 2014-07-07 10:45:43.000000000 +0200
  50338. @@ -0,0 +1,224 @@
  50339. +# Doxyfile 1.3.9.1
  50340. +
  50341. +#---------------------------------------------------------------------------
  50342. +# Project related configuration options
  50343. +#---------------------------------------------------------------------------
  50344. +PROJECT_NAME = "DesignWare USB 2.0 OTG Controller (DWC_otg) Device Driver"
  50345. +PROJECT_NUMBER = v3.00a
  50346. +OUTPUT_DIRECTORY = ./doc/
  50347. +CREATE_SUBDIRS = NO
  50348. +OUTPUT_LANGUAGE = English
  50349. +BRIEF_MEMBER_DESC = YES
  50350. +REPEAT_BRIEF = YES
  50351. +ABBREVIATE_BRIEF = "The $name class" \
  50352. + "The $name widget" \
  50353. + "The $name file" \
  50354. + is \
  50355. + provides \
  50356. + specifies \
  50357. + contains \
  50358. + represents \
  50359. + a \
  50360. + an \
  50361. + the
  50362. +ALWAYS_DETAILED_SEC = NO
  50363. +INLINE_INHERITED_MEMB = NO
  50364. +FULL_PATH_NAMES = NO
  50365. +STRIP_FROM_PATH =
  50366. +STRIP_FROM_INC_PATH =
  50367. +SHORT_NAMES = NO
  50368. +JAVADOC_AUTOBRIEF = YES
  50369. +MULTILINE_CPP_IS_BRIEF = NO
  50370. +INHERIT_DOCS = YES
  50371. +DISTRIBUTE_GROUP_DOC = NO
  50372. +TAB_SIZE = 8
  50373. +ALIASES =
  50374. +OPTIMIZE_OUTPUT_FOR_C = YES
  50375. +OPTIMIZE_OUTPUT_JAVA = NO
  50376. +SUBGROUPING = YES
  50377. +#---------------------------------------------------------------------------
  50378. +# Build related configuration options
  50379. +#---------------------------------------------------------------------------
  50380. +EXTRACT_ALL = NO
  50381. +EXTRACT_PRIVATE = YES
  50382. +EXTRACT_STATIC = YES
  50383. +EXTRACT_LOCAL_CLASSES = YES
  50384. +EXTRACT_LOCAL_METHODS = NO
  50385. +HIDE_UNDOC_MEMBERS = NO
  50386. +HIDE_UNDOC_CLASSES = NO
  50387. +HIDE_FRIEND_COMPOUNDS = NO
  50388. +HIDE_IN_BODY_DOCS = NO
  50389. +INTERNAL_DOCS = NO
  50390. +CASE_SENSE_NAMES = NO
  50391. +HIDE_SCOPE_NAMES = NO
  50392. +SHOW_INCLUDE_FILES = YES
  50393. +INLINE_INFO = YES
  50394. +SORT_MEMBER_DOCS = NO
  50395. +SORT_BRIEF_DOCS = NO
  50396. +SORT_BY_SCOPE_NAME = NO
  50397. +GENERATE_TODOLIST = YES
  50398. +GENERATE_TESTLIST = YES
  50399. +GENERATE_BUGLIST = YES
  50400. +GENERATE_DEPRECATEDLIST= YES
  50401. +ENABLED_SECTIONS =
  50402. +MAX_INITIALIZER_LINES = 30
  50403. +SHOW_USED_FILES = YES
  50404. +SHOW_DIRECTORIES = YES
  50405. +#---------------------------------------------------------------------------
  50406. +# configuration options related to warning and progress messages
  50407. +#---------------------------------------------------------------------------
  50408. +QUIET = YES
  50409. +WARNINGS = YES
  50410. +WARN_IF_UNDOCUMENTED = NO
  50411. +WARN_IF_DOC_ERROR = YES
  50412. +WARN_FORMAT = "$file:$line: $text"
  50413. +WARN_LOGFILE =
  50414. +#---------------------------------------------------------------------------
  50415. +# configuration options related to the input files
  50416. +#---------------------------------------------------------------------------
  50417. +INPUT = .
  50418. +FILE_PATTERNS = *.c \
  50419. + *.h \
  50420. + ./linux/*.c \
  50421. + ./linux/*.h
  50422. +RECURSIVE = NO
  50423. +EXCLUDE = ./test/ \
  50424. + ./dwc_otg/.AppleDouble/
  50425. +EXCLUDE_SYMLINKS = YES
  50426. +EXCLUDE_PATTERNS = *.mod.*
  50427. +EXAMPLE_PATH =
  50428. +EXAMPLE_PATTERNS = *
  50429. +EXAMPLE_RECURSIVE = NO
  50430. +IMAGE_PATH =
  50431. +INPUT_FILTER =
  50432. +FILTER_PATTERNS =
  50433. +FILTER_SOURCE_FILES = NO
  50434. +#---------------------------------------------------------------------------
  50435. +# configuration options related to source browsing
  50436. +#---------------------------------------------------------------------------
  50437. +SOURCE_BROWSER = YES
  50438. +INLINE_SOURCES = NO
  50439. +STRIP_CODE_COMMENTS = YES
  50440. +REFERENCED_BY_RELATION = NO
  50441. +REFERENCES_RELATION = NO
  50442. +VERBATIM_HEADERS = NO
  50443. +#---------------------------------------------------------------------------
  50444. +# configuration options related to the alphabetical class index
  50445. +#---------------------------------------------------------------------------
  50446. +ALPHABETICAL_INDEX = NO
  50447. +COLS_IN_ALPHA_INDEX = 5
  50448. +IGNORE_PREFIX =
  50449. +#---------------------------------------------------------------------------
  50450. +# configuration options related to the HTML output
  50451. +#---------------------------------------------------------------------------
  50452. +GENERATE_HTML = YES
  50453. +HTML_OUTPUT = html
  50454. +HTML_FILE_EXTENSION = .html
  50455. +HTML_HEADER =
  50456. +HTML_FOOTER =
  50457. +HTML_STYLESHEET =
  50458. +HTML_ALIGN_MEMBERS = YES
  50459. +GENERATE_HTMLHELP = NO
  50460. +CHM_FILE =
  50461. +HHC_LOCATION =
  50462. +GENERATE_CHI = NO
  50463. +BINARY_TOC = NO
  50464. +TOC_EXPAND = NO
  50465. +DISABLE_INDEX = NO
  50466. +ENUM_VALUES_PER_LINE = 4
  50467. +GENERATE_TREEVIEW = YES
  50468. +TREEVIEW_WIDTH = 250
  50469. +#---------------------------------------------------------------------------
  50470. +# configuration options related to the LaTeX output
  50471. +#---------------------------------------------------------------------------
  50472. +GENERATE_LATEX = NO
  50473. +LATEX_OUTPUT = latex
  50474. +LATEX_CMD_NAME = latex
  50475. +MAKEINDEX_CMD_NAME = makeindex
  50476. +COMPACT_LATEX = NO
  50477. +PAPER_TYPE = a4wide
  50478. +EXTRA_PACKAGES =
  50479. +LATEX_HEADER =
  50480. +PDF_HYPERLINKS = NO
  50481. +USE_PDFLATEX = NO
  50482. +LATEX_BATCHMODE = NO
  50483. +LATEX_HIDE_INDICES = NO
  50484. +#---------------------------------------------------------------------------
  50485. +# configuration options related to the RTF output
  50486. +#---------------------------------------------------------------------------
  50487. +GENERATE_RTF = NO
  50488. +RTF_OUTPUT = rtf
  50489. +COMPACT_RTF = NO
  50490. +RTF_HYPERLINKS = NO
  50491. +RTF_STYLESHEET_FILE =
  50492. +RTF_EXTENSIONS_FILE =
  50493. +#---------------------------------------------------------------------------
  50494. +# configuration options related to the man page output
  50495. +#---------------------------------------------------------------------------
  50496. +GENERATE_MAN = NO
  50497. +MAN_OUTPUT = man
  50498. +MAN_EXTENSION = .3
  50499. +MAN_LINKS = NO
  50500. +#---------------------------------------------------------------------------
  50501. +# configuration options related to the XML output
  50502. +#---------------------------------------------------------------------------
  50503. +GENERATE_XML = NO
  50504. +XML_OUTPUT = xml
  50505. +XML_SCHEMA =
  50506. +XML_DTD =
  50507. +XML_PROGRAMLISTING = YES
  50508. +#---------------------------------------------------------------------------
  50509. +# configuration options for the AutoGen Definitions output
  50510. +#---------------------------------------------------------------------------
  50511. +GENERATE_AUTOGEN_DEF = NO
  50512. +#---------------------------------------------------------------------------
  50513. +# configuration options related to the Perl module output
  50514. +#---------------------------------------------------------------------------
  50515. +GENERATE_PERLMOD = NO
  50516. +PERLMOD_LATEX = NO
  50517. +PERLMOD_PRETTY = YES
  50518. +PERLMOD_MAKEVAR_PREFIX =
  50519. +#---------------------------------------------------------------------------
  50520. +# Configuration options related to the preprocessor
  50521. +#---------------------------------------------------------------------------
  50522. +ENABLE_PREPROCESSING = YES
  50523. +MACRO_EXPANSION = YES
  50524. +EXPAND_ONLY_PREDEF = YES
  50525. +SEARCH_INCLUDES = YES
  50526. +INCLUDE_PATH =
  50527. +INCLUDE_FILE_PATTERNS =
  50528. +PREDEFINED = DEVICE_ATTR DWC_EN_ISOC
  50529. +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
  50530. +SKIP_FUNCTION_MACROS = NO
  50531. +#---------------------------------------------------------------------------
  50532. +# Configuration::additions related to external references
  50533. +#---------------------------------------------------------------------------
  50534. +TAGFILES =
  50535. +GENERATE_TAGFILE =
  50536. +ALLEXTERNALS = NO
  50537. +EXTERNAL_GROUPS = YES
  50538. +PERL_PATH = /usr/bin/perl
  50539. +#---------------------------------------------------------------------------
  50540. +# Configuration options related to the dot tool
  50541. +#---------------------------------------------------------------------------
  50542. +CLASS_DIAGRAMS = YES
  50543. +HIDE_UNDOC_RELATIONS = YES
  50544. +HAVE_DOT = NO
  50545. +CLASS_GRAPH = YES
  50546. +COLLABORATION_GRAPH = YES
  50547. +UML_LOOK = NO
  50548. +TEMPLATE_RELATIONS = NO
  50549. +INCLUDE_GRAPH = YES
  50550. +INCLUDED_BY_GRAPH = YES
  50551. +CALL_GRAPH = NO
  50552. +GRAPHICAL_HIERARCHY = YES
  50553. +DOT_IMAGE_FORMAT = png
  50554. +DOT_PATH =
  50555. +DOTFILE_DIRS =
  50556. +MAX_DOT_GRAPH_DEPTH = 1000
  50557. +GENERATE_LEGEND = YES
  50558. +DOT_CLEANUP = YES
  50559. +#---------------------------------------------------------------------------
  50560. +# Configuration::additions related to the search engine
  50561. +#---------------------------------------------------------------------------
  50562. +SEARCHENGINE = NO
  50563. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dummy_audio.c linux-rpi/drivers/usb/host/dwc_otg/dummy_audio.c
  50564. --- linux-3.15.4/drivers/usb/host/dwc_otg/dummy_audio.c 1970-01-01 01:00:00.000000000 +0100
  50565. +++ linux-rpi/drivers/usb/host/dwc_otg/dummy_audio.c 2014-07-07 10:45:43.000000000 +0200
  50566. @@ -0,0 +1,1575 @@
  50567. +/*
  50568. + * zero.c -- Gadget Zero, for USB development
  50569. + *
  50570. + * Copyright (C) 2003-2004 David Brownell
  50571. + * All rights reserved.
  50572. + *
  50573. + * Redistribution and use in source and binary forms, with or without
  50574. + * modification, are permitted provided that the following conditions
  50575. + * are met:
  50576. + * 1. Redistributions of source code must retain the above copyright
  50577. + * notice, this list of conditions, and the following disclaimer,
  50578. + * without modification.
  50579. + * 2. Redistributions in binary form must reproduce the above copyright
  50580. + * notice, this list of conditions and the following disclaimer in the
  50581. + * documentation and/or other materials provided with the distribution.
  50582. + * 3. The names of the above-listed copyright holders may not be used
  50583. + * to endorse or promote products derived from this software without
  50584. + * specific prior written permission.
  50585. + *
  50586. + * ALTERNATIVELY, this software may be distributed under the terms of the
  50587. + * GNU General Public License ("GPL") as published by the Free Software
  50588. + * Foundation, either version 2 of that License or (at your option) any
  50589. + * later version.
  50590. + *
  50591. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  50592. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  50593. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  50594. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  50595. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  50596. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  50597. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  50598. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  50599. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  50600. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  50601. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  50602. + */
  50603. +
  50604. +
  50605. +/*
  50606. + * Gadget Zero only needs two bulk endpoints, and is an example of how you
  50607. + * can write a hardware-agnostic gadget driver running inside a USB device.
  50608. + *
  50609. + * Hardware details are visible (see CONFIG_USB_ZERO_* below) but don't
  50610. + * affect most of the driver.
  50611. + *
  50612. + * Use it with the Linux host/master side "usbtest" driver to get a basic
  50613. + * functional test of your device-side usb stack, or with "usb-skeleton".
  50614. + *
  50615. + * It supports two similar configurations. One sinks whatever the usb host
  50616. + * writes, and in return sources zeroes. The other loops whatever the host
  50617. + * writes back, so the host can read it. Module options include:
  50618. + *
  50619. + * buflen=N default N=4096, buffer size used
  50620. + * qlen=N default N=32, how many buffers in the loopback queue
  50621. + * loopdefault default false, list loopback config first
  50622. + *
  50623. + * Many drivers will only have one configuration, letting them be much
  50624. + * simpler if they also don't support high speed operation (like this
  50625. + * driver does).
  50626. + */
  50627. +
  50628. +#include <linux/config.h>
  50629. +#include <linux/module.h>
  50630. +#include <linux/kernel.h>
  50631. +#include <linux/delay.h>
  50632. +#include <linux/ioport.h>
  50633. +#include <linux/sched.h>
  50634. +#include <linux/slab.h>
  50635. +#include <linux/smp_lock.h>
  50636. +#include <linux/errno.h>
  50637. +#include <linux/init.h>
  50638. +#include <linux/timer.h>
  50639. +#include <linux/list.h>
  50640. +#include <linux/interrupt.h>
  50641. +#include <linux/uts.h>
  50642. +#include <linux/version.h>
  50643. +#include <linux/device.h>
  50644. +#include <linux/moduleparam.h>
  50645. +#include <linux/proc_fs.h>
  50646. +
  50647. +#include <asm/byteorder.h>
  50648. +#include <asm/io.h>
  50649. +#include <asm/irq.h>
  50650. +#include <asm/system.h>
  50651. +#include <asm/unaligned.h>
  50652. +
  50653. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
  50654. +# include <linux/usb/ch9.h>
  50655. +#else
  50656. +# include <linux/usb_ch9.h>
  50657. +#endif
  50658. +
  50659. +#include <linux/usb_gadget.h>
  50660. +
  50661. +
  50662. +/*-------------------------------------------------------------------------*/
  50663. +/*-------------------------------------------------------------------------*/
  50664. +
  50665. +
  50666. +static int utf8_to_utf16le(const char *s, u16 *cp, unsigned len)
  50667. +{
  50668. + int count = 0;
  50669. + u8 c;
  50670. + u16 uchar;
  50671. +
  50672. + /* this insists on correct encodings, though not minimal ones.
  50673. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  50674. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  50675. + */
  50676. + while (len != 0 && (c = (u8) *s++) != 0) {
  50677. + if (unlikely(c & 0x80)) {
  50678. + // 2-byte sequence:
  50679. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  50680. + if ((c & 0xe0) == 0xc0) {
  50681. + uchar = (c & 0x1f) << 6;
  50682. +
  50683. + c = (u8) *s++;
  50684. + if ((c & 0xc0) != 0xc0)
  50685. + goto fail;
  50686. + c &= 0x3f;
  50687. + uchar |= c;
  50688. +
  50689. + // 3-byte sequence (most CJKV characters):
  50690. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  50691. + } else if ((c & 0xf0) == 0xe0) {
  50692. + uchar = (c & 0x0f) << 12;
  50693. +
  50694. + c = (u8) *s++;
  50695. + if ((c & 0xc0) != 0xc0)
  50696. + goto fail;
  50697. + c &= 0x3f;
  50698. + uchar |= c << 6;
  50699. +
  50700. + c = (u8) *s++;
  50701. + if ((c & 0xc0) != 0xc0)
  50702. + goto fail;
  50703. + c &= 0x3f;
  50704. + uchar |= c;
  50705. +
  50706. + /* no bogus surrogates */
  50707. + if (0xd800 <= uchar && uchar <= 0xdfff)
  50708. + goto fail;
  50709. +
  50710. + // 4-byte sequence (surrogate pairs, currently rare):
  50711. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  50712. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  50713. + // (uuuuu = wwww + 1)
  50714. + // FIXME accept the surrogate code points (only)
  50715. +
  50716. + } else
  50717. + goto fail;
  50718. + } else
  50719. + uchar = c;
  50720. + put_unaligned (cpu_to_le16 (uchar), cp++);
  50721. + count++;
  50722. + len--;
  50723. + }
  50724. + return count;
  50725. +fail:
  50726. + return -1;
  50727. +}
  50728. +
  50729. +
  50730. +/**
  50731. + * usb_gadget_get_string - fill out a string descriptor
  50732. + * @table: of c strings encoded using UTF-8
  50733. + * @id: string id, from low byte of wValue in get string descriptor
  50734. + * @buf: at least 256 bytes
  50735. + *
  50736. + * Finds the UTF-8 string matching the ID, and converts it into a
  50737. + * string descriptor in utf16-le.
  50738. + * Returns length of descriptor (always even) or negative errno
  50739. + *
  50740. + * If your driver needs stings in multiple languages, you'll probably
  50741. + * "switch (wIndex) { ... }" in your ep0 string descriptor logic,
  50742. + * using this routine after choosing which set of UTF-8 strings to use.
  50743. + * Note that US-ASCII is a strict subset of UTF-8; any string bytes with
  50744. + * the eighth bit set will be multibyte UTF-8 characters, not ISO-8859/1
  50745. + * characters (which are also widely used in C strings).
  50746. + */
  50747. +int
  50748. +usb_gadget_get_string (struct usb_gadget_strings *table, int id, u8 *buf)
  50749. +{
  50750. + struct usb_string *s;
  50751. + int len;
  50752. +
  50753. + /* descriptor 0 has the language id */
  50754. + if (id == 0) {
  50755. + buf [0] = 4;
  50756. + buf [1] = USB_DT_STRING;
  50757. + buf [2] = (u8) table->language;
  50758. + buf [3] = (u8) (table->language >> 8);
  50759. + return 4;
  50760. + }
  50761. + for (s = table->strings; s && s->s; s++)
  50762. + if (s->id == id)
  50763. + break;
  50764. +
  50765. + /* unrecognized: stall. */
  50766. + if (!s || !s->s)
  50767. + return -EINVAL;
  50768. +
  50769. + /* string descriptors have length, tag, then UTF16-LE text */
  50770. + len = min ((size_t) 126, strlen (s->s));
  50771. + memset (buf + 2, 0, 2 * len); /* zero all the bytes */
  50772. + len = utf8_to_utf16le(s->s, (u16 *)&buf[2], len);
  50773. + if (len < 0)
  50774. + return -EINVAL;
  50775. + buf [0] = (len + 1) * 2;
  50776. + buf [1] = USB_DT_STRING;
  50777. + return buf [0];
  50778. +}
  50779. +
  50780. +
  50781. +/*-------------------------------------------------------------------------*/
  50782. +/*-------------------------------------------------------------------------*/
  50783. +
  50784. +
  50785. +/**
  50786. + * usb_descriptor_fillbuf - fill buffer with descriptors
  50787. + * @buf: Buffer to be filled
  50788. + * @buflen: Size of buf
  50789. + * @src: Array of descriptor pointers, terminated by null pointer.
  50790. + *
  50791. + * Copies descriptors into the buffer, returning the length or a
  50792. + * negative error code if they can't all be copied. Useful when
  50793. + * assembling descriptors for an associated set of interfaces used
  50794. + * as part of configuring a composite device; or in other cases where
  50795. + * sets of descriptors need to be marshaled.
  50796. + */
  50797. +int
  50798. +usb_descriptor_fillbuf(void *buf, unsigned buflen,
  50799. + const struct usb_descriptor_header **src)
  50800. +{
  50801. + u8 *dest = buf;
  50802. +
  50803. + if (!src)
  50804. + return -EINVAL;
  50805. +
  50806. + /* fill buffer from src[] until null descriptor ptr */
  50807. + for (; 0 != *src; src++) {
  50808. + unsigned len = (*src)->bLength;
  50809. +
  50810. + if (len > buflen)
  50811. + return -EINVAL;
  50812. + memcpy(dest, *src, len);
  50813. + buflen -= len;
  50814. + dest += len;
  50815. + }
  50816. + return dest - (u8 *)buf;
  50817. +}
  50818. +
  50819. +
  50820. +/**
  50821. + * usb_gadget_config_buf - builts a complete configuration descriptor
  50822. + * @config: Header for the descriptor, including characteristics such
  50823. + * as power requirements and number of interfaces.
  50824. + * @desc: Null-terminated vector of pointers to the descriptors (interface,
  50825. + * endpoint, etc) defining all functions in this device configuration.
  50826. + * @buf: Buffer for the resulting configuration descriptor.
  50827. + * @length: Length of buffer. If this is not big enough to hold the
  50828. + * entire configuration descriptor, an error code will be returned.
  50829. + *
  50830. + * This copies descriptors into the response buffer, building a descriptor
  50831. + * for that configuration. It returns the buffer length or a negative
  50832. + * status code. The config.wTotalLength field is set to match the length
  50833. + * of the result, but other descriptor fields (including power usage and
  50834. + * interface count) must be set by the caller.
  50835. + *
  50836. + * Gadget drivers could use this when constructing a config descriptor
  50837. + * in response to USB_REQ_GET_DESCRIPTOR. They will need to patch the
  50838. + * resulting bDescriptorType value if USB_DT_OTHER_SPEED_CONFIG is needed.
  50839. + */
  50840. +int usb_gadget_config_buf(
  50841. + const struct usb_config_descriptor *config,
  50842. + void *buf,
  50843. + unsigned length,
  50844. + const struct usb_descriptor_header **desc
  50845. +)
  50846. +{
  50847. + struct usb_config_descriptor *cp = buf;
  50848. + int len;
  50849. +
  50850. + /* config descriptor first */
  50851. + if (length < USB_DT_CONFIG_SIZE || !desc)
  50852. + return -EINVAL;
  50853. + *cp = *config;
  50854. +
  50855. + /* then interface/endpoint/class/vendor/... */
  50856. + len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (u8*)buf,
  50857. + length - USB_DT_CONFIG_SIZE, desc);
  50858. + if (len < 0)
  50859. + return len;
  50860. + len += USB_DT_CONFIG_SIZE;
  50861. + if (len > 0xffff)
  50862. + return -EINVAL;
  50863. +
  50864. + /* patch up the config descriptor */
  50865. + cp->bLength = USB_DT_CONFIG_SIZE;
  50866. + cp->bDescriptorType = USB_DT_CONFIG;
  50867. + cp->wTotalLength = cpu_to_le16(len);
  50868. + cp->bmAttributes |= USB_CONFIG_ATT_ONE;
  50869. + return len;
  50870. +}
  50871. +
  50872. +/*-------------------------------------------------------------------------*/
  50873. +/*-------------------------------------------------------------------------*/
  50874. +
  50875. +
  50876. +#define RBUF_LEN (1024*1024)
  50877. +static int rbuf_start;
  50878. +static int rbuf_len;
  50879. +static __u8 rbuf[RBUF_LEN];
  50880. +
  50881. +/*-------------------------------------------------------------------------*/
  50882. +
  50883. +#define DRIVER_VERSION "St Patrick's Day 2004"
  50884. +
  50885. +static const char shortname [] = "zero";
  50886. +static const char longname [] = "YAMAHA YST-MS35D USB Speaker ";
  50887. +
  50888. +static const char source_sink [] = "source and sink data";
  50889. +static const char loopback [] = "loop input to output";
  50890. +
  50891. +/*-------------------------------------------------------------------------*/
  50892. +
  50893. +/*
  50894. + * driver assumes self-powered hardware, and
  50895. + * has no way for users to trigger remote wakeup.
  50896. + *
  50897. + * this version autoconfigures as much as possible,
  50898. + * which is reasonable for most "bulk-only" drivers.
  50899. + */
  50900. +static const char *EP_IN_NAME; /* source */
  50901. +static const char *EP_OUT_NAME; /* sink */
  50902. +
  50903. +/*-------------------------------------------------------------------------*/
  50904. +
  50905. +/* big enough to hold our biggest descriptor */
  50906. +#define USB_BUFSIZ 512
  50907. +
  50908. +struct zero_dev {
  50909. + spinlock_t lock;
  50910. + struct usb_gadget *gadget;
  50911. + struct usb_request *req; /* for control responses */
  50912. +
  50913. + /* when configured, we have one of two configs:
  50914. + * - source data (in to host) and sink it (out from host)
  50915. + * - or loop it back (out from host back in to host)
  50916. + */
  50917. + u8 config;
  50918. + struct usb_ep *in_ep, *out_ep;
  50919. +
  50920. + /* autoresume timer */
  50921. + struct timer_list resume;
  50922. +};
  50923. +
  50924. +#define xprintk(d,level,fmt,args...) \
  50925. + dev_printk(level , &(d)->gadget->dev , fmt , ## args)
  50926. +
  50927. +#ifdef DEBUG
  50928. +#define DBG(dev,fmt,args...) \
  50929. + xprintk(dev , KERN_DEBUG , fmt , ## args)
  50930. +#else
  50931. +#define DBG(dev,fmt,args...) \
  50932. + do { } while (0)
  50933. +#endif /* DEBUG */
  50934. +
  50935. +#ifdef VERBOSE
  50936. +#define VDBG DBG
  50937. +#else
  50938. +#define VDBG(dev,fmt,args...) \
  50939. + do { } while (0)
  50940. +#endif /* VERBOSE */
  50941. +
  50942. +#define ERROR(dev,fmt,args...) \
  50943. + xprintk(dev , KERN_ERR , fmt , ## args)
  50944. +#define WARN(dev,fmt,args...) \
  50945. + xprintk(dev , KERN_WARNING , fmt , ## args)
  50946. +#define INFO(dev,fmt,args...) \
  50947. + xprintk(dev , KERN_INFO , fmt , ## args)
  50948. +
  50949. +/*-------------------------------------------------------------------------*/
  50950. +
  50951. +static unsigned buflen = 4096;
  50952. +static unsigned qlen = 32;
  50953. +static unsigned pattern = 0;
  50954. +
  50955. +module_param (buflen, uint, S_IRUGO|S_IWUSR);
  50956. +module_param (qlen, uint, S_IRUGO|S_IWUSR);
  50957. +module_param (pattern, uint, S_IRUGO|S_IWUSR);
  50958. +
  50959. +/*
  50960. + * if it's nonzero, autoresume says how many seconds to wait
  50961. + * before trying to wake up the host after suspend.
  50962. + */
  50963. +static unsigned autoresume = 0;
  50964. +module_param (autoresume, uint, 0);
  50965. +
  50966. +/*
  50967. + * Normally the "loopback" configuration is second (index 1) so
  50968. + * it's not the default. Here's where to change that order, to
  50969. + * work better with hosts where config changes are problematic.
  50970. + * Or controllers (like superh) that only support one config.
  50971. + */
  50972. +static int loopdefault = 0;
  50973. +
  50974. +module_param (loopdefault, bool, S_IRUGO|S_IWUSR);
  50975. +
  50976. +/*-------------------------------------------------------------------------*/
  50977. +
  50978. +/* Thanks to NetChip Technologies for donating this product ID.
  50979. + *
  50980. + * DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
  50981. + * Instead: allocate your own, using normal USB-IF procedures.
  50982. + */
  50983. +#ifndef CONFIG_USB_ZERO_HNPTEST
  50984. +#define DRIVER_VENDOR_NUM 0x0525 /* NetChip */
  50985. +#define DRIVER_PRODUCT_NUM 0xa4a0 /* Linux-USB "Gadget Zero" */
  50986. +#else
  50987. +#define DRIVER_VENDOR_NUM 0x1a0a /* OTG test device IDs */
  50988. +#define DRIVER_PRODUCT_NUM 0xbadd
  50989. +#endif
  50990. +
  50991. +/*-------------------------------------------------------------------------*/
  50992. +
  50993. +/*
  50994. + * DESCRIPTORS ... most are static, but strings and (full)
  50995. + * configuration descriptors are built on demand.
  50996. + */
  50997. +
  50998. +/*
  50999. +#define STRING_MANUFACTURER 25
  51000. +#define STRING_PRODUCT 42
  51001. +#define STRING_SERIAL 101
  51002. +*/
  51003. +#define STRING_MANUFACTURER 1
  51004. +#define STRING_PRODUCT 2
  51005. +#define STRING_SERIAL 3
  51006. +
  51007. +#define STRING_SOURCE_SINK 250
  51008. +#define STRING_LOOPBACK 251
  51009. +
  51010. +/*
  51011. + * This device advertises two configurations; these numbers work
  51012. + * on a pxa250 as well as more flexible hardware.
  51013. + */
  51014. +#define CONFIG_SOURCE_SINK 3
  51015. +#define CONFIG_LOOPBACK 2
  51016. +
  51017. +/*
  51018. +static struct usb_device_descriptor
  51019. +device_desc = {
  51020. + .bLength = sizeof device_desc,
  51021. + .bDescriptorType = USB_DT_DEVICE,
  51022. +
  51023. + .bcdUSB = __constant_cpu_to_le16 (0x0200),
  51024. + .bDeviceClass = USB_CLASS_VENDOR_SPEC,
  51025. +
  51026. + .idVendor = __constant_cpu_to_le16 (DRIVER_VENDOR_NUM),
  51027. + .idProduct = __constant_cpu_to_le16 (DRIVER_PRODUCT_NUM),
  51028. + .iManufacturer = STRING_MANUFACTURER,
  51029. + .iProduct = STRING_PRODUCT,
  51030. + .iSerialNumber = STRING_SERIAL,
  51031. + .bNumConfigurations = 2,
  51032. +};
  51033. +*/
  51034. +static struct usb_device_descriptor
  51035. +device_desc = {
  51036. + .bLength = sizeof device_desc,
  51037. + .bDescriptorType = USB_DT_DEVICE,
  51038. + .bcdUSB = __constant_cpu_to_le16 (0x0100),
  51039. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  51040. + .bDeviceSubClass = 0,
  51041. + .bDeviceProtocol = 0,
  51042. + .bMaxPacketSize0 = 64,
  51043. + .bcdDevice = __constant_cpu_to_le16 (0x0100),
  51044. + .idVendor = __constant_cpu_to_le16 (0x0499),
  51045. + .idProduct = __constant_cpu_to_le16 (0x3002),
  51046. + .iManufacturer = STRING_MANUFACTURER,
  51047. + .iProduct = STRING_PRODUCT,
  51048. + .iSerialNumber = STRING_SERIAL,
  51049. + .bNumConfigurations = 1,
  51050. +};
  51051. +
  51052. +static struct usb_config_descriptor
  51053. +z_config = {
  51054. + .bLength = sizeof z_config,
  51055. + .bDescriptorType = USB_DT_CONFIG,
  51056. +
  51057. + /* compute wTotalLength on the fly */
  51058. + .bNumInterfaces = 2,
  51059. + .bConfigurationValue = 1,
  51060. + .iConfiguration = 0,
  51061. + .bmAttributes = 0x40,
  51062. + .bMaxPower = 0, /* self-powered */
  51063. +};
  51064. +
  51065. +
  51066. +static struct usb_otg_descriptor
  51067. +otg_descriptor = {
  51068. + .bLength = sizeof otg_descriptor,
  51069. + .bDescriptorType = USB_DT_OTG,
  51070. +
  51071. + .bmAttributes = USB_OTG_SRP,
  51072. +};
  51073. +
  51074. +/* one interface in each configuration */
  51075. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  51076. +
  51077. +/*
  51078. + * usb 2.0 devices need to expose both high speed and full speed
  51079. + * descriptors, unless they only run at full speed.
  51080. + *
  51081. + * that means alternate endpoint descriptors (bigger packets)
  51082. + * and a "device qualifier" ... plus more construction options
  51083. + * for the config descriptor.
  51084. + */
  51085. +
  51086. +static struct usb_qualifier_descriptor
  51087. +dev_qualifier = {
  51088. + .bLength = sizeof dev_qualifier,
  51089. + .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
  51090. +
  51091. + .bcdUSB = __constant_cpu_to_le16 (0x0200),
  51092. + .bDeviceClass = USB_CLASS_VENDOR_SPEC,
  51093. +
  51094. + .bNumConfigurations = 2,
  51095. +};
  51096. +
  51097. +
  51098. +struct usb_cs_as_general_descriptor {
  51099. + __u8 bLength;
  51100. + __u8 bDescriptorType;
  51101. +
  51102. + __u8 bDescriptorSubType;
  51103. + __u8 bTerminalLink;
  51104. + __u8 bDelay;
  51105. + __u16 wFormatTag;
  51106. +} __attribute__ ((packed));
  51107. +
  51108. +struct usb_cs_as_format_descriptor {
  51109. + __u8 bLength;
  51110. + __u8 bDescriptorType;
  51111. +
  51112. + __u8 bDescriptorSubType;
  51113. + __u8 bFormatType;
  51114. + __u8 bNrChannels;
  51115. + __u8 bSubframeSize;
  51116. + __u8 bBitResolution;
  51117. + __u8 bSamfreqType;
  51118. + __u8 tLowerSamFreq[3];
  51119. + __u8 tUpperSamFreq[3];
  51120. +} __attribute__ ((packed));
  51121. +
  51122. +static const struct usb_interface_descriptor
  51123. +z_audio_control_if_desc = {
  51124. + .bLength = sizeof z_audio_control_if_desc,
  51125. + .bDescriptorType = USB_DT_INTERFACE,
  51126. + .bInterfaceNumber = 0,
  51127. + .bAlternateSetting = 0,
  51128. + .bNumEndpoints = 0,
  51129. + .bInterfaceClass = USB_CLASS_AUDIO,
  51130. + .bInterfaceSubClass = 0x1,
  51131. + .bInterfaceProtocol = 0,
  51132. + .iInterface = 0,
  51133. +};
  51134. +
  51135. +static const struct usb_interface_descriptor
  51136. +z_audio_if_desc = {
  51137. + .bLength = sizeof z_audio_if_desc,
  51138. + .bDescriptorType = USB_DT_INTERFACE,
  51139. + .bInterfaceNumber = 1,
  51140. + .bAlternateSetting = 0,
  51141. + .bNumEndpoints = 0,
  51142. + .bInterfaceClass = USB_CLASS_AUDIO,
  51143. + .bInterfaceSubClass = 0x2,
  51144. + .bInterfaceProtocol = 0,
  51145. + .iInterface = 0,
  51146. +};
  51147. +
  51148. +static const struct usb_interface_descriptor
  51149. +z_audio_if_desc2 = {
  51150. + .bLength = sizeof z_audio_if_desc,
  51151. + .bDescriptorType = USB_DT_INTERFACE,
  51152. + .bInterfaceNumber = 1,
  51153. + .bAlternateSetting = 1,
  51154. + .bNumEndpoints = 1,
  51155. + .bInterfaceClass = USB_CLASS_AUDIO,
  51156. + .bInterfaceSubClass = 0x2,
  51157. + .bInterfaceProtocol = 0,
  51158. + .iInterface = 0,
  51159. +};
  51160. +
  51161. +static const struct usb_cs_as_general_descriptor
  51162. +z_audio_cs_as_if_desc = {
  51163. + .bLength = 7,
  51164. + .bDescriptorType = 0x24,
  51165. +
  51166. + .bDescriptorSubType = 0x01,
  51167. + .bTerminalLink = 0x01,
  51168. + .bDelay = 0x0,
  51169. + .wFormatTag = __constant_cpu_to_le16 (0x0001)
  51170. +};
  51171. +
  51172. +
  51173. +static const struct usb_cs_as_format_descriptor
  51174. +z_audio_cs_as_format_desc = {
  51175. + .bLength = 0xe,
  51176. + .bDescriptorType = 0x24,
  51177. +
  51178. + .bDescriptorSubType = 2,
  51179. + .bFormatType = 1,
  51180. + .bNrChannels = 1,
  51181. + .bSubframeSize = 1,
  51182. + .bBitResolution = 8,
  51183. + .bSamfreqType = 0,
  51184. + .tLowerSamFreq = {0x7e, 0x13, 0x00},
  51185. + .tUpperSamFreq = {0xe2, 0xd6, 0x00},
  51186. +};
  51187. +
  51188. +static const struct usb_endpoint_descriptor
  51189. +z_iso_ep = {
  51190. + .bLength = 0x09,
  51191. + .bDescriptorType = 0x05,
  51192. + .bEndpointAddress = 0x04,
  51193. + .bmAttributes = 0x09,
  51194. + .wMaxPacketSize = 0x0038,
  51195. + .bInterval = 0x01,
  51196. + .bRefresh = 0x00,
  51197. + .bSynchAddress = 0x00,
  51198. +};
  51199. +
  51200. +static char z_iso_ep2[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  51201. +
  51202. +// 9 bytes
  51203. +static char z_ac_interface_header_desc[] =
  51204. +{ 0x09, 0x24, 0x01, 0x00, 0x01, 0x2b, 0x00, 0x01, 0x01 };
  51205. +
  51206. +// 12 bytes
  51207. +static char z_0[] = {0x0c, 0x24, 0x02, 0x01, 0x01, 0x01, 0x00, 0x02,
  51208. + 0x03, 0x00, 0x00, 0x00};
  51209. +// 13 bytes
  51210. +static char z_1[] = {0x0d, 0x24, 0x06, 0x02, 0x01, 0x02, 0x15, 0x00,
  51211. + 0x02, 0x00, 0x02, 0x00, 0x00};
  51212. +// 9 bytes
  51213. +static char z_2[] = {0x09, 0x24, 0x03, 0x03, 0x01, 0x03, 0x00, 0x02,
  51214. + 0x00};
  51215. +
  51216. +static char za_0[] = {0x09, 0x04, 0x01, 0x02, 0x01, 0x01, 0x02, 0x00,
  51217. + 0x00};
  51218. +
  51219. +static char za_1[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  51220. +
  51221. +static char za_2[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x01, 0x08, 0x00,
  51222. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  51223. +
  51224. +static char za_3[] = {0x09, 0x05, 0x04, 0x09, 0x70, 0x00, 0x01, 0x00,
  51225. + 0x00};
  51226. +
  51227. +static char za_4[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  51228. +
  51229. +static char za_5[] = {0x09, 0x04, 0x01, 0x03, 0x01, 0x01, 0x02, 0x00,
  51230. + 0x00};
  51231. +
  51232. +static char za_6[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  51233. +
  51234. +static char za_7[] = {0x0e, 0x24, 0x02, 0x01, 0x01, 0x02, 0x10, 0x00,
  51235. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  51236. +
  51237. +static char za_8[] = {0x09, 0x05, 0x04, 0x09, 0x70, 0x00, 0x01, 0x00,
  51238. + 0x00};
  51239. +
  51240. +static char za_9[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  51241. +
  51242. +static char za_10[] = {0x09, 0x04, 0x01, 0x04, 0x01, 0x01, 0x02, 0x00,
  51243. + 0x00};
  51244. +
  51245. +static char za_11[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  51246. +
  51247. +static char za_12[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x02, 0x10, 0x00,
  51248. + 0x73, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  51249. +
  51250. +static char za_13[] = {0x09, 0x05, 0x04, 0x09, 0xe0, 0x00, 0x01, 0x00,
  51251. + 0x00};
  51252. +
  51253. +static char za_14[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  51254. +
  51255. +static char za_15[] = {0x09, 0x04, 0x01, 0x05, 0x01, 0x01, 0x02, 0x00,
  51256. + 0x00};
  51257. +
  51258. +static char za_16[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  51259. +
  51260. +static char za_17[] = {0x0e, 0x24, 0x02, 0x01, 0x01, 0x03, 0x14, 0x00,
  51261. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  51262. +
  51263. +static char za_18[] = {0x09, 0x05, 0x04, 0x09, 0xa8, 0x00, 0x01, 0x00,
  51264. + 0x00};
  51265. +
  51266. +static char za_19[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  51267. +
  51268. +static char za_20[] = {0x09, 0x04, 0x01, 0x06, 0x01, 0x01, 0x02, 0x00,
  51269. + 0x00};
  51270. +
  51271. +static char za_21[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  51272. +
  51273. +static char za_22[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x03, 0x14, 0x00,
  51274. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  51275. +
  51276. +static char za_23[] = {0x09, 0x05, 0x04, 0x09, 0x50, 0x01, 0x01, 0x00,
  51277. + 0x00};
  51278. +
  51279. +static char za_24[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  51280. +
  51281. +
  51282. +
  51283. +static const struct usb_descriptor_header *z_function [] = {
  51284. + (struct usb_descriptor_header *) &z_audio_control_if_desc,
  51285. + (struct usb_descriptor_header *) &z_ac_interface_header_desc,
  51286. + (struct usb_descriptor_header *) &z_0,
  51287. + (struct usb_descriptor_header *) &z_1,
  51288. + (struct usb_descriptor_header *) &z_2,
  51289. + (struct usb_descriptor_header *) &z_audio_if_desc,
  51290. + (struct usb_descriptor_header *) &z_audio_if_desc2,
  51291. + (struct usb_descriptor_header *) &z_audio_cs_as_if_desc,
  51292. + (struct usb_descriptor_header *) &z_audio_cs_as_format_desc,
  51293. + (struct usb_descriptor_header *) &z_iso_ep,
  51294. + (struct usb_descriptor_header *) &z_iso_ep2,
  51295. + (struct usb_descriptor_header *) &za_0,
  51296. + (struct usb_descriptor_header *) &za_1,
  51297. + (struct usb_descriptor_header *) &za_2,
  51298. + (struct usb_descriptor_header *) &za_3,
  51299. + (struct usb_descriptor_header *) &za_4,
  51300. + (struct usb_descriptor_header *) &za_5,
  51301. + (struct usb_descriptor_header *) &za_6,
  51302. + (struct usb_descriptor_header *) &za_7,
  51303. + (struct usb_descriptor_header *) &za_8,
  51304. + (struct usb_descriptor_header *) &za_9,
  51305. + (struct usb_descriptor_header *) &za_10,
  51306. + (struct usb_descriptor_header *) &za_11,
  51307. + (struct usb_descriptor_header *) &za_12,
  51308. + (struct usb_descriptor_header *) &za_13,
  51309. + (struct usb_descriptor_header *) &za_14,
  51310. + (struct usb_descriptor_header *) &za_15,
  51311. + (struct usb_descriptor_header *) &za_16,
  51312. + (struct usb_descriptor_header *) &za_17,
  51313. + (struct usb_descriptor_header *) &za_18,
  51314. + (struct usb_descriptor_header *) &za_19,
  51315. + (struct usb_descriptor_header *) &za_20,
  51316. + (struct usb_descriptor_header *) &za_21,
  51317. + (struct usb_descriptor_header *) &za_22,
  51318. + (struct usb_descriptor_header *) &za_23,
  51319. + (struct usb_descriptor_header *) &za_24,
  51320. + NULL,
  51321. +};
  51322. +
  51323. +/* maxpacket and other transfer characteristics vary by speed. */
  51324. +#define ep_desc(g,hs,fs) (((g)->speed==USB_SPEED_HIGH)?(hs):(fs))
  51325. +
  51326. +#else
  51327. +
  51328. +/* if there's no high speed support, maxpacket doesn't change. */
  51329. +#define ep_desc(g,hs,fs) fs
  51330. +
  51331. +#endif /* !CONFIG_USB_GADGET_DUALSPEED */
  51332. +
  51333. +static char manufacturer [40];
  51334. +//static char serial [40];
  51335. +static char serial [] = "Ser 00 em";
  51336. +
  51337. +/* static strings, in UTF-8 */
  51338. +static struct usb_string strings [] = {
  51339. + { STRING_MANUFACTURER, manufacturer, },
  51340. + { STRING_PRODUCT, longname, },
  51341. + { STRING_SERIAL, serial, },
  51342. + { STRING_LOOPBACK, loopback, },
  51343. + { STRING_SOURCE_SINK, source_sink, },
  51344. + { } /* end of list */
  51345. +};
  51346. +
  51347. +static struct usb_gadget_strings stringtab = {
  51348. + .language = 0x0409, /* en-us */
  51349. + .strings = strings,
  51350. +};
  51351. +
  51352. +/*
  51353. + * config descriptors are also handcrafted. these must agree with code
  51354. + * that sets configurations, and with code managing interfaces and their
  51355. + * altsettings. other complexity may come from:
  51356. + *
  51357. + * - high speed support, including "other speed config" rules
  51358. + * - multiple configurations
  51359. + * - interfaces with alternate settings
  51360. + * - embedded class or vendor-specific descriptors
  51361. + *
  51362. + * this handles high speed, and has a second config that could as easily
  51363. + * have been an alternate interface setting (on most hardware).
  51364. + *
  51365. + * NOTE: to demonstrate (and test) more USB capabilities, this driver
  51366. + * should include an altsetting to test interrupt transfers, including
  51367. + * high bandwidth modes at high speed. (Maybe work like Intel's test
  51368. + * device?)
  51369. + */
  51370. +static int
  51371. +config_buf (struct usb_gadget *gadget, u8 *buf, u8 type, unsigned index)
  51372. +{
  51373. + int len;
  51374. + const struct usb_descriptor_header **function;
  51375. +
  51376. + function = z_function;
  51377. + len = usb_gadget_config_buf (&z_config, buf, USB_BUFSIZ, function);
  51378. + if (len < 0)
  51379. + return len;
  51380. + ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
  51381. + return len;
  51382. +}
  51383. +
  51384. +/*-------------------------------------------------------------------------*/
  51385. +
  51386. +static struct usb_request *
  51387. +alloc_ep_req (struct usb_ep *ep, unsigned length)
  51388. +{
  51389. + struct usb_request *req;
  51390. +
  51391. + req = usb_ep_alloc_request (ep, GFP_ATOMIC);
  51392. + if (req) {
  51393. + req->length = length;
  51394. + req->buf = usb_ep_alloc_buffer (ep, length,
  51395. + &req->dma, GFP_ATOMIC);
  51396. + if (!req->buf) {
  51397. + usb_ep_free_request (ep, req);
  51398. + req = NULL;
  51399. + }
  51400. + }
  51401. + return req;
  51402. +}
  51403. +
  51404. +static void free_ep_req (struct usb_ep *ep, struct usb_request *req)
  51405. +{
  51406. + if (req->buf)
  51407. + usb_ep_free_buffer (ep, req->buf, req->dma, req->length);
  51408. + usb_ep_free_request (ep, req);
  51409. +}
  51410. +
  51411. +/*-------------------------------------------------------------------------*/
  51412. +
  51413. +/* optionally require specific source/sink data patterns */
  51414. +
  51415. +static int
  51416. +check_read_data (
  51417. + struct zero_dev *dev,
  51418. + struct usb_ep *ep,
  51419. + struct usb_request *req
  51420. +)
  51421. +{
  51422. + unsigned i;
  51423. + u8 *buf = req->buf;
  51424. +
  51425. + for (i = 0; i < req->actual; i++, buf++) {
  51426. + switch (pattern) {
  51427. + /* all-zeroes has no synchronization issues */
  51428. + case 0:
  51429. + if (*buf == 0)
  51430. + continue;
  51431. + break;
  51432. + /* mod63 stays in sync with short-terminated transfers,
  51433. + * or otherwise when host and gadget agree on how large
  51434. + * each usb transfer request should be. resync is done
  51435. + * with set_interface or set_config.
  51436. + */
  51437. + case 1:
  51438. + if (*buf == (u8)(i % 63))
  51439. + continue;
  51440. + break;
  51441. + }
  51442. + ERROR (dev, "bad OUT byte, buf [%d] = %d\n", i, *buf);
  51443. + usb_ep_set_halt (ep);
  51444. + return -EINVAL;
  51445. + }
  51446. + return 0;
  51447. +}
  51448. +
  51449. +/*-------------------------------------------------------------------------*/
  51450. +
  51451. +static void zero_reset_config (struct zero_dev *dev)
  51452. +{
  51453. + if (dev->config == 0)
  51454. + return;
  51455. +
  51456. + DBG (dev, "reset config\n");
  51457. +
  51458. + /* just disable endpoints, forcing completion of pending i/o.
  51459. + * all our completion handlers free their requests in this case.
  51460. + */
  51461. + if (dev->in_ep) {
  51462. + usb_ep_disable (dev->in_ep);
  51463. + dev->in_ep = NULL;
  51464. + }
  51465. + if (dev->out_ep) {
  51466. + usb_ep_disable (dev->out_ep);
  51467. + dev->out_ep = NULL;
  51468. + }
  51469. + dev->config = 0;
  51470. + del_timer (&dev->resume);
  51471. +}
  51472. +
  51473. +#define _write(f, buf, sz) (f->f_op->write(f, buf, sz, &f->f_pos))
  51474. +
  51475. +static void
  51476. +zero_isoc_complete (struct usb_ep *ep, struct usb_request *req)
  51477. +{
  51478. + struct zero_dev *dev = ep->driver_data;
  51479. + int status = req->status;
  51480. + int i, j;
  51481. +
  51482. + switch (status) {
  51483. +
  51484. + case 0: /* normal completion? */
  51485. + //printk ("\nzero ---------------> isoc normal completion %d bytes\n", req->actual);
  51486. + for (i=0, j=rbuf_start; i<req->actual; i++) {
  51487. + //printk ("%02x ", ((__u8*)req->buf)[i]);
  51488. + rbuf[j] = ((__u8*)req->buf)[i];
  51489. + j++;
  51490. + if (j >= RBUF_LEN) j=0;
  51491. + }
  51492. + rbuf_start = j;
  51493. + //printk ("\n\n");
  51494. +
  51495. + if (rbuf_len < RBUF_LEN) {
  51496. + rbuf_len += req->actual;
  51497. + if (rbuf_len > RBUF_LEN) {
  51498. + rbuf_len = RBUF_LEN;
  51499. + }
  51500. + }
  51501. +
  51502. + break;
  51503. +
  51504. + /* this endpoint is normally active while we're configured */
  51505. + case -ECONNABORTED: /* hardware forced ep reset */
  51506. + case -ECONNRESET: /* request dequeued */
  51507. + case -ESHUTDOWN: /* disconnect from host */
  51508. + VDBG (dev, "%s gone (%d), %d/%d\n", ep->name, status,
  51509. + req->actual, req->length);
  51510. + if (ep == dev->out_ep)
  51511. + check_read_data (dev, ep, req);
  51512. + free_ep_req (ep, req);
  51513. + return;
  51514. +
  51515. + case -EOVERFLOW: /* buffer overrun on read means that
  51516. + * we didn't provide a big enough
  51517. + * buffer.
  51518. + */
  51519. + default:
  51520. +#if 1
  51521. + DBG (dev, "%s complete --> %d, %d/%d\n", ep->name,
  51522. + status, req->actual, req->length);
  51523. +#endif
  51524. + case -EREMOTEIO: /* short read */
  51525. + break;
  51526. + }
  51527. +
  51528. + status = usb_ep_queue (ep, req, GFP_ATOMIC);
  51529. + if (status) {
  51530. + ERROR (dev, "kill %s: resubmit %d bytes --> %d\n",
  51531. + ep->name, req->length, status);
  51532. + usb_ep_set_halt (ep);
  51533. + /* FIXME recover later ... somehow */
  51534. + }
  51535. +}
  51536. +
  51537. +static struct usb_request *
  51538. +zero_start_isoc_ep (struct usb_ep *ep, int gfp_flags)
  51539. +{
  51540. + struct usb_request *req;
  51541. + int status;
  51542. +
  51543. + req = alloc_ep_req (ep, 512);
  51544. + if (!req)
  51545. + return NULL;
  51546. +
  51547. + req->complete = zero_isoc_complete;
  51548. +
  51549. + status = usb_ep_queue (ep, req, gfp_flags);
  51550. + if (status) {
  51551. + struct zero_dev *dev = ep->driver_data;
  51552. +
  51553. + ERROR (dev, "start %s --> %d\n", ep->name, status);
  51554. + free_ep_req (ep, req);
  51555. + req = NULL;
  51556. + }
  51557. +
  51558. + return req;
  51559. +}
  51560. +
  51561. +/* change our operational config. this code must agree with the code
  51562. + * that returns config descriptors, and altsetting code.
  51563. + *
  51564. + * it's also responsible for power management interactions. some
  51565. + * configurations might not work with our current power sources.
  51566. + *
  51567. + * note that some device controller hardware will constrain what this
  51568. + * code can do, perhaps by disallowing more than one configuration or
  51569. + * by limiting configuration choices (like the pxa2xx).
  51570. + */
  51571. +static int
  51572. +zero_set_config (struct zero_dev *dev, unsigned number, int gfp_flags)
  51573. +{
  51574. + int result = 0;
  51575. + struct usb_gadget *gadget = dev->gadget;
  51576. + const struct usb_endpoint_descriptor *d;
  51577. + struct usb_ep *ep;
  51578. +
  51579. + if (number == dev->config)
  51580. + return 0;
  51581. +
  51582. + zero_reset_config (dev);
  51583. +
  51584. + gadget_for_each_ep (ep, gadget) {
  51585. +
  51586. + if (strcmp (ep->name, "ep4") == 0) {
  51587. +
  51588. + d = (struct usb_endpoint_descripter *)&za_23; // isoc ep desc for audio i/f alt setting 6
  51589. + result = usb_ep_enable (ep, d);
  51590. +
  51591. + if (result == 0) {
  51592. + ep->driver_data = dev;
  51593. + dev->in_ep = ep;
  51594. +
  51595. + if (zero_start_isoc_ep (ep, gfp_flags) != 0) {
  51596. +
  51597. + dev->in_ep = ep;
  51598. + continue;
  51599. + }
  51600. +
  51601. + usb_ep_disable (ep);
  51602. + result = -EIO;
  51603. + }
  51604. + }
  51605. +
  51606. + }
  51607. +
  51608. + dev->config = number;
  51609. + return result;
  51610. +}
  51611. +
  51612. +/*-------------------------------------------------------------------------*/
  51613. +
  51614. +static void zero_setup_complete (struct usb_ep *ep, struct usb_request *req)
  51615. +{
  51616. + if (req->status || req->actual != req->length)
  51617. + DBG ((struct zero_dev *) ep->driver_data,
  51618. + "setup complete --> %d, %d/%d\n",
  51619. + req->status, req->actual, req->length);
  51620. +}
  51621. +
  51622. +/*
  51623. + * The setup() callback implements all the ep0 functionality that's
  51624. + * not handled lower down, in hardware or the hardware driver (like
  51625. + * device and endpoint feature flags, and their status). It's all
  51626. + * housekeeping for the gadget function we're implementing. Most of
  51627. + * the work is in config-specific setup.
  51628. + */
  51629. +static int
  51630. +zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
  51631. +{
  51632. + struct zero_dev *dev = get_gadget_data (gadget);
  51633. + struct usb_request *req = dev->req;
  51634. + int value = -EOPNOTSUPP;
  51635. +
  51636. + /* usually this stores reply data in the pre-allocated ep0 buffer,
  51637. + * but config change events will reconfigure hardware.
  51638. + */
  51639. + req->zero = 0;
  51640. + switch (ctrl->bRequest) {
  51641. +
  51642. + case USB_REQ_GET_DESCRIPTOR:
  51643. +
  51644. + switch (ctrl->wValue >> 8) {
  51645. +
  51646. + case USB_DT_DEVICE:
  51647. + value = min (ctrl->wLength, (u16) sizeof device_desc);
  51648. + memcpy (req->buf, &device_desc, value);
  51649. + break;
  51650. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  51651. + case USB_DT_DEVICE_QUALIFIER:
  51652. + if (!gadget->is_dualspeed)
  51653. + break;
  51654. + value = min (ctrl->wLength, (u16) sizeof dev_qualifier);
  51655. + memcpy (req->buf, &dev_qualifier, value);
  51656. + break;
  51657. +
  51658. + case USB_DT_OTHER_SPEED_CONFIG:
  51659. + if (!gadget->is_dualspeed)
  51660. + break;
  51661. + // FALLTHROUGH
  51662. +#endif /* CONFIG_USB_GADGET_DUALSPEED */
  51663. + case USB_DT_CONFIG:
  51664. + value = config_buf (gadget, req->buf,
  51665. + ctrl->wValue >> 8,
  51666. + ctrl->wValue & 0xff);
  51667. + if (value >= 0)
  51668. + value = min (ctrl->wLength, (u16) value);
  51669. + break;
  51670. +
  51671. + case USB_DT_STRING:
  51672. + /* wIndex == language code.
  51673. + * this driver only handles one language, you can
  51674. + * add string tables for other languages, using
  51675. + * any UTF-8 characters
  51676. + */
  51677. + value = usb_gadget_get_string (&stringtab,
  51678. + ctrl->wValue & 0xff, req->buf);
  51679. + if (value >= 0) {
  51680. + value = min (ctrl->wLength, (u16) value);
  51681. + }
  51682. + break;
  51683. + }
  51684. + break;
  51685. +
  51686. + /* currently two configs, two speeds */
  51687. + case USB_REQ_SET_CONFIGURATION:
  51688. + if (ctrl->bRequestType != 0)
  51689. + goto unknown;
  51690. +
  51691. + spin_lock (&dev->lock);
  51692. + value = zero_set_config (dev, ctrl->wValue, GFP_ATOMIC);
  51693. + spin_unlock (&dev->lock);
  51694. + break;
  51695. + case USB_REQ_GET_CONFIGURATION:
  51696. + if (ctrl->bRequestType != USB_DIR_IN)
  51697. + goto unknown;
  51698. + *(u8 *)req->buf = dev->config;
  51699. + value = min (ctrl->wLength, (u16) 1);
  51700. + break;
  51701. +
  51702. + /* until we add altsetting support, or other interfaces,
  51703. + * only 0/0 are possible. pxa2xx only supports 0/0 (poorly)
  51704. + * and already killed pending endpoint I/O.
  51705. + */
  51706. + case USB_REQ_SET_INTERFACE:
  51707. +
  51708. + if (ctrl->bRequestType != USB_RECIP_INTERFACE)
  51709. + goto unknown;
  51710. + spin_lock (&dev->lock);
  51711. + if (dev->config) {
  51712. + u8 config = dev->config;
  51713. +
  51714. + /* resets interface configuration, forgets about
  51715. + * previous transaction state (queued bufs, etc)
  51716. + * and re-inits endpoint state (toggle etc)
  51717. + * no response queued, just zero status == success.
  51718. + * if we had more than one interface we couldn't
  51719. + * use this "reset the config" shortcut.
  51720. + */
  51721. + zero_reset_config (dev);
  51722. + zero_set_config (dev, config, GFP_ATOMIC);
  51723. + value = 0;
  51724. + }
  51725. + spin_unlock (&dev->lock);
  51726. + break;
  51727. + case USB_REQ_GET_INTERFACE:
  51728. + if ((ctrl->bRequestType == 0x21) && (ctrl->wIndex == 0x02)) {
  51729. + value = ctrl->wLength;
  51730. + break;
  51731. + }
  51732. + else {
  51733. + if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE))
  51734. + goto unknown;
  51735. + if (!dev->config)
  51736. + break;
  51737. + if (ctrl->wIndex != 0) {
  51738. + value = -EDOM;
  51739. + break;
  51740. + }
  51741. + *(u8 *)req->buf = 0;
  51742. + value = min (ctrl->wLength, (u16) 1);
  51743. + }
  51744. + break;
  51745. +
  51746. + /*
  51747. + * These are the same vendor-specific requests supported by
  51748. + * Intel's USB 2.0 compliance test devices. We exceed that
  51749. + * device spec by allowing multiple-packet requests.
  51750. + */
  51751. + case 0x5b: /* control WRITE test -- fill the buffer */
  51752. + if (ctrl->bRequestType != (USB_DIR_OUT|USB_TYPE_VENDOR))
  51753. + goto unknown;
  51754. + if (ctrl->wValue || ctrl->wIndex)
  51755. + break;
  51756. + /* just read that many bytes into the buffer */
  51757. + if (ctrl->wLength > USB_BUFSIZ)
  51758. + break;
  51759. + value = ctrl->wLength;
  51760. + break;
  51761. + case 0x5c: /* control READ test -- return the buffer */
  51762. + if (ctrl->bRequestType != (USB_DIR_IN|USB_TYPE_VENDOR))
  51763. + goto unknown;
  51764. + if (ctrl->wValue || ctrl->wIndex)
  51765. + break;
  51766. + /* expect those bytes are still in the buffer; send back */
  51767. + if (ctrl->wLength > USB_BUFSIZ
  51768. + || ctrl->wLength != req->length)
  51769. + break;
  51770. + value = ctrl->wLength;
  51771. + break;
  51772. +
  51773. + case 0x01: // SET_CUR
  51774. + case 0x02:
  51775. + case 0x03:
  51776. + case 0x04:
  51777. + case 0x05:
  51778. + value = ctrl->wLength;
  51779. + break;
  51780. + case 0x81:
  51781. + switch (ctrl->wValue) {
  51782. + case 0x0201:
  51783. + case 0x0202:
  51784. + ((u8*)req->buf)[0] = 0x00;
  51785. + ((u8*)req->buf)[1] = 0xe3;
  51786. + break;
  51787. + case 0x0300:
  51788. + case 0x0500:
  51789. + ((u8*)req->buf)[0] = 0x00;
  51790. + break;
  51791. + }
  51792. + //((u8*)req->buf)[0] = 0x81;
  51793. + //((u8*)req->buf)[1] = 0x81;
  51794. + value = ctrl->wLength;
  51795. + break;
  51796. + case 0x82:
  51797. + switch (ctrl->wValue) {
  51798. + case 0x0201:
  51799. + case 0x0202:
  51800. + ((u8*)req->buf)[0] = 0x00;
  51801. + ((u8*)req->buf)[1] = 0xc3;
  51802. + break;
  51803. + case 0x0300:
  51804. + case 0x0500:
  51805. + ((u8*)req->buf)[0] = 0x00;
  51806. + break;
  51807. + }
  51808. + //((u8*)req->buf)[0] = 0x82;
  51809. + //((u8*)req->buf)[1] = 0x82;
  51810. + value = ctrl->wLength;
  51811. + break;
  51812. + case 0x83:
  51813. + switch (ctrl->wValue) {
  51814. + case 0x0201:
  51815. + case 0x0202:
  51816. + ((u8*)req->buf)[0] = 0x00;
  51817. + ((u8*)req->buf)[1] = 0x00;
  51818. + break;
  51819. + case 0x0300:
  51820. + ((u8*)req->buf)[0] = 0x60;
  51821. + break;
  51822. + case 0x0500:
  51823. + ((u8*)req->buf)[0] = 0x18;
  51824. + break;
  51825. + }
  51826. + //((u8*)req->buf)[0] = 0x83;
  51827. + //((u8*)req->buf)[1] = 0x83;
  51828. + value = ctrl->wLength;
  51829. + break;
  51830. + case 0x84:
  51831. + switch (ctrl->wValue) {
  51832. + case 0x0201:
  51833. + case 0x0202:
  51834. + ((u8*)req->buf)[0] = 0x00;
  51835. + ((u8*)req->buf)[1] = 0x01;
  51836. + break;
  51837. + case 0x0300:
  51838. + case 0x0500:
  51839. + ((u8*)req->buf)[0] = 0x08;
  51840. + break;
  51841. + }
  51842. + //((u8*)req->buf)[0] = 0x84;
  51843. + //((u8*)req->buf)[1] = 0x84;
  51844. + value = ctrl->wLength;
  51845. + break;
  51846. + case 0x85:
  51847. + ((u8*)req->buf)[0] = 0x85;
  51848. + ((u8*)req->buf)[1] = 0x85;
  51849. + value = ctrl->wLength;
  51850. + break;
  51851. +
  51852. +
  51853. + default:
  51854. +unknown:
  51855. + printk("unknown control req%02x.%02x v%04x i%04x l%d\n",
  51856. + ctrl->bRequestType, ctrl->bRequest,
  51857. + ctrl->wValue, ctrl->wIndex, ctrl->wLength);
  51858. + }
  51859. +
  51860. + /* respond with data transfer before status phase? */
  51861. + if (value >= 0) {
  51862. + req->length = value;
  51863. + req->zero = value < ctrl->wLength
  51864. + && (value % gadget->ep0->maxpacket) == 0;
  51865. + value = usb_ep_queue (gadget->ep0, req, GFP_ATOMIC);
  51866. + if (value < 0) {
  51867. + DBG (dev, "ep_queue < 0 --> %d\n", value);
  51868. + req->status = 0;
  51869. + zero_setup_complete (gadget->ep0, req);
  51870. + }
  51871. + }
  51872. +
  51873. + /* device either stalls (value < 0) or reports success */
  51874. + return value;
  51875. +}
  51876. +
  51877. +static void
  51878. +zero_disconnect (struct usb_gadget *gadget)
  51879. +{
  51880. + struct zero_dev *dev = get_gadget_data (gadget);
  51881. + unsigned long flags;
  51882. +
  51883. + spin_lock_irqsave (&dev->lock, flags);
  51884. + zero_reset_config (dev);
  51885. +
  51886. + /* a more significant application might have some non-usb
  51887. + * activities to quiesce here, saving resources like power
  51888. + * or pushing the notification up a network stack.
  51889. + */
  51890. + spin_unlock_irqrestore (&dev->lock, flags);
  51891. +
  51892. + /* next we may get setup() calls to enumerate new connections;
  51893. + * or an unbind() during shutdown (including removing module).
  51894. + */
  51895. +}
  51896. +
  51897. +static void
  51898. +zero_autoresume (unsigned long _dev)
  51899. +{
  51900. + struct zero_dev *dev = (struct zero_dev *) _dev;
  51901. + int status;
  51902. +
  51903. + /* normally the host would be woken up for something
  51904. + * more significant than just a timer firing...
  51905. + */
  51906. + if (dev->gadget->speed != USB_SPEED_UNKNOWN) {
  51907. + status = usb_gadget_wakeup (dev->gadget);
  51908. + DBG (dev, "wakeup --> %d\n", status);
  51909. + }
  51910. +}
  51911. +
  51912. +/*-------------------------------------------------------------------------*/
  51913. +
  51914. +static void
  51915. +zero_unbind (struct usb_gadget *gadget)
  51916. +{
  51917. + struct zero_dev *dev = get_gadget_data (gadget);
  51918. +
  51919. + DBG (dev, "unbind\n");
  51920. +
  51921. + /* we've already been disconnected ... no i/o is active */
  51922. + if (dev->req)
  51923. + free_ep_req (gadget->ep0, dev->req);
  51924. + del_timer_sync (&dev->resume);
  51925. + kfree (dev);
  51926. + set_gadget_data (gadget, NULL);
  51927. +}
  51928. +
  51929. +static int
  51930. +zero_bind (struct usb_gadget *gadget)
  51931. +{
  51932. + struct zero_dev *dev;
  51933. + //struct usb_ep *ep;
  51934. +
  51935. + printk("binding\n");
  51936. + /*
  51937. + * DRIVER POLICY CHOICE: you may want to do this differently.
  51938. + * One thing to avoid is reusing a bcdDevice revision code
  51939. + * with different host-visible configurations or behavior
  51940. + * restrictions -- using ep1in/ep2out vs ep1out/ep3in, etc
  51941. + */
  51942. + //device_desc.bcdDevice = __constant_cpu_to_le16 (0x0201);
  51943. +
  51944. +
  51945. + /* ok, we made sense of the hardware ... */
  51946. + dev = kmalloc (sizeof *dev, SLAB_KERNEL);
  51947. + if (!dev)
  51948. + return -ENOMEM;
  51949. + memset (dev, 0, sizeof *dev);
  51950. + spin_lock_init (&dev->lock);
  51951. + dev->gadget = gadget;
  51952. + set_gadget_data (gadget, dev);
  51953. +
  51954. + /* preallocate control response and buffer */
  51955. + dev->req = usb_ep_alloc_request (gadget->ep0, GFP_KERNEL);
  51956. + if (!dev->req)
  51957. + goto enomem;
  51958. + dev->req->buf = usb_ep_alloc_buffer (gadget->ep0, USB_BUFSIZ,
  51959. + &dev->req->dma, GFP_KERNEL);
  51960. + if (!dev->req->buf)
  51961. + goto enomem;
  51962. +
  51963. + dev->req->complete = zero_setup_complete;
  51964. +
  51965. + device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
  51966. +
  51967. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  51968. + /* assume ep0 uses the same value for both speeds ... */
  51969. + dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0;
  51970. +
  51971. + /* and that all endpoints are dual-speed */
  51972. + //hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress;
  51973. + //hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress;
  51974. +#endif
  51975. +
  51976. + usb_gadget_set_selfpowered (gadget);
  51977. +
  51978. + init_timer (&dev->resume);
  51979. + dev->resume.function = zero_autoresume;
  51980. + dev->resume.data = (unsigned long) dev;
  51981. +
  51982. + gadget->ep0->driver_data = dev;
  51983. +
  51984. + INFO (dev, "%s, version: " DRIVER_VERSION "\n", longname);
  51985. + INFO (dev, "using %s, OUT %s IN %s\n", gadget->name,
  51986. + EP_OUT_NAME, EP_IN_NAME);
  51987. +
  51988. + snprintf (manufacturer, sizeof manufacturer,
  51989. + UTS_SYSNAME " " UTS_RELEASE " with %s",
  51990. + gadget->name);
  51991. +
  51992. + return 0;
  51993. +
  51994. +enomem:
  51995. + zero_unbind (gadget);
  51996. + return -ENOMEM;
  51997. +}
  51998. +
  51999. +/*-------------------------------------------------------------------------*/
  52000. +
  52001. +static void
  52002. +zero_suspend (struct usb_gadget *gadget)
  52003. +{
  52004. + struct zero_dev *dev = get_gadget_data (gadget);
  52005. +
  52006. + if (gadget->speed == USB_SPEED_UNKNOWN)
  52007. + return;
  52008. +
  52009. + if (autoresume) {
  52010. + mod_timer (&dev->resume, jiffies + (HZ * autoresume));
  52011. + DBG (dev, "suspend, wakeup in %d seconds\n", autoresume);
  52012. + } else
  52013. + DBG (dev, "suspend\n");
  52014. +}
  52015. +
  52016. +static void
  52017. +zero_resume (struct usb_gadget *gadget)
  52018. +{
  52019. + struct zero_dev *dev = get_gadget_data (gadget);
  52020. +
  52021. + DBG (dev, "resume\n");
  52022. + del_timer (&dev->resume);
  52023. +}
  52024. +
  52025. +
  52026. +/*-------------------------------------------------------------------------*/
  52027. +
  52028. +static struct usb_gadget_driver zero_driver = {
  52029. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  52030. + .speed = USB_SPEED_HIGH,
  52031. +#else
  52032. + .speed = USB_SPEED_FULL,
  52033. +#endif
  52034. + .function = (char *) longname,
  52035. + .bind = zero_bind,
  52036. + .unbind = zero_unbind,
  52037. +
  52038. + .setup = zero_setup,
  52039. + .disconnect = zero_disconnect,
  52040. +
  52041. + .suspend = zero_suspend,
  52042. + .resume = zero_resume,
  52043. +
  52044. + .driver = {
  52045. + .name = (char *) shortname,
  52046. + // .shutdown = ...
  52047. + // .suspend = ...
  52048. + // .resume = ...
  52049. + },
  52050. +};
  52051. +
  52052. +MODULE_AUTHOR ("David Brownell");
  52053. +MODULE_LICENSE ("Dual BSD/GPL");
  52054. +
  52055. +static struct proc_dir_entry *pdir, *pfile;
  52056. +
  52057. +static int isoc_read_data (char *page, char **start,
  52058. + off_t off, int count,
  52059. + int *eof, void *data)
  52060. +{
  52061. + int i;
  52062. + static int c = 0;
  52063. + static int done = 0;
  52064. + static int s = 0;
  52065. +
  52066. +/*
  52067. + printk ("\ncount: %d\n", count);
  52068. + printk ("rbuf_start: %d\n", rbuf_start);
  52069. + printk ("rbuf_len: %d\n", rbuf_len);
  52070. + printk ("off: %d\n", off);
  52071. + printk ("start: %p\n\n", *start);
  52072. +*/
  52073. + if (done) {
  52074. + c = 0;
  52075. + done = 0;
  52076. + *eof = 1;
  52077. + return 0;
  52078. + }
  52079. +
  52080. + if (c == 0) {
  52081. + if (rbuf_len == RBUF_LEN)
  52082. + s = rbuf_start;
  52083. + else s = 0;
  52084. + }
  52085. +
  52086. + for (i=0; i<count && c<rbuf_len; i++, c++) {
  52087. + page[i] = rbuf[(c+s) % RBUF_LEN];
  52088. + }
  52089. + *start = page;
  52090. +
  52091. + if (c >= rbuf_len) {
  52092. + *eof = 1;
  52093. + done = 1;
  52094. + }
  52095. +
  52096. +
  52097. + return i;
  52098. +}
  52099. +
  52100. +static int __init init (void)
  52101. +{
  52102. +
  52103. + int retval = 0;
  52104. +
  52105. + pdir = proc_mkdir("isoc_test", NULL);
  52106. + if(pdir == NULL) {
  52107. + retval = -ENOMEM;
  52108. + printk("Error creating dir\n");
  52109. + goto done;
  52110. + }
  52111. + pdir->owner = THIS_MODULE;
  52112. +
  52113. + pfile = create_proc_read_entry("isoc_data",
  52114. + 0444, pdir,
  52115. + isoc_read_data,
  52116. + NULL);
  52117. + if (pfile == NULL) {
  52118. + retval = -ENOMEM;
  52119. + printk("Error creating file\n");
  52120. + goto no_file;
  52121. + }
  52122. + pfile->owner = THIS_MODULE;
  52123. +
  52124. + return usb_gadget_register_driver (&zero_driver);
  52125. +
  52126. + no_file:
  52127. + remove_proc_entry("isoc_data", NULL);
  52128. + done:
  52129. + return retval;
  52130. +}
  52131. +module_init (init);
  52132. +
  52133. +static void __exit cleanup (void)
  52134. +{
  52135. +
  52136. + usb_gadget_unregister_driver (&zero_driver);
  52137. +
  52138. + remove_proc_entry("isoc_data", pdir);
  52139. + remove_proc_entry("isoc_test", NULL);
  52140. +}
  52141. +module_exit (cleanup);
  52142. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_cfi_common.h linux-rpi/drivers/usb/host/dwc_otg/dwc_cfi_common.h
  52143. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_cfi_common.h 1970-01-01 01:00:00.000000000 +0100
  52144. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_cfi_common.h 2014-07-07 10:45:43.000000000 +0200
  52145. @@ -0,0 +1,142 @@
  52146. +/* ==========================================================================
  52147. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  52148. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  52149. + * otherwise expressly agreed to in writing between Synopsys and you.
  52150. + *
  52151. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  52152. + * any End User Software License Agreement or Agreement for Licensed Product
  52153. + * with Synopsys or any supplement thereto. You are permitted to use and
  52154. + * redistribute this Software in source and binary forms, with or without
  52155. + * modification, provided that redistributions of source code must retain this
  52156. + * notice. You may not view, use, disclose, copy or distribute this file or
  52157. + * any information contained herein except pursuant to this license grant from
  52158. + * Synopsys. If you do not agree with this notice, including the disclaimer
  52159. + * below, then you are not authorized to use the Software.
  52160. + *
  52161. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  52162. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  52163. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  52164. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  52165. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  52166. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  52167. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  52168. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  52169. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  52170. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  52171. + * DAMAGE.
  52172. + * ========================================================================== */
  52173. +
  52174. +#if !defined(__DWC_CFI_COMMON_H__)
  52175. +#define __DWC_CFI_COMMON_H__
  52176. +
  52177. +//#include <linux/types.h>
  52178. +
  52179. +/**
  52180. + * @file
  52181. + *
  52182. + * This file contains the CFI specific common constants, interfaces
  52183. + * (functions and macros) and structures for Linux. No PCD specific
  52184. + * data structure or definition is to be included in this file.
  52185. + *
  52186. + */
  52187. +
  52188. +/** This is a request for all Core Features */
  52189. +#define VEN_CORE_GET_FEATURES 0xB1
  52190. +
  52191. +/** This is a request to get the value of a specific Core Feature */
  52192. +#define VEN_CORE_GET_FEATURE 0xB2
  52193. +
  52194. +/** This command allows the host to set the value of a specific Core Feature */
  52195. +#define VEN_CORE_SET_FEATURE 0xB3
  52196. +
  52197. +/** This command allows the host to set the default values of
  52198. + * either all or any specific Core Feature
  52199. + */
  52200. +#define VEN_CORE_RESET_FEATURES 0xB4
  52201. +
  52202. +/** This command forces the PCD to write the deferred values of a Core Features */
  52203. +#define VEN_CORE_ACTIVATE_FEATURES 0xB5
  52204. +
  52205. +/** This request reads a DWORD value from a register at the specified offset */
  52206. +#define VEN_CORE_READ_REGISTER 0xB6
  52207. +
  52208. +/** This request writes a DWORD value into a register at the specified offset */
  52209. +#define VEN_CORE_WRITE_REGISTER 0xB7
  52210. +
  52211. +/** This structure is the header of the Core Features dataset returned to
  52212. + * the Host
  52213. + */
  52214. +struct cfi_all_features_header {
  52215. +/** The features header structure length is */
  52216. +#define CFI_ALL_FEATURES_HDR_LEN 8
  52217. + /**
  52218. + * The total length of the features dataset returned to the Host
  52219. + */
  52220. + uint16_t wTotalLen;
  52221. +
  52222. + /**
  52223. + * CFI version number inBinary-Coded Decimal (i.e., 1.00 is 100H).
  52224. + * This field identifies the version of the CFI Specification with which
  52225. + * the device is compliant.
  52226. + */
  52227. + uint16_t wVersion;
  52228. +
  52229. + /** The ID of the Core */
  52230. + uint16_t wCoreID;
  52231. +#define CFI_CORE_ID_UDC 1
  52232. +#define CFI_CORE_ID_OTG 2
  52233. +#define CFI_CORE_ID_WUDEV 3
  52234. +
  52235. + /** Number of features returned by VEN_CORE_GET_FEATURES request */
  52236. + uint16_t wNumFeatures;
  52237. +} UPACKED;
  52238. +
  52239. +typedef struct cfi_all_features_header cfi_all_features_header_t;
  52240. +
  52241. +/** This structure is a header of the Core Feature descriptor dataset returned to
  52242. + * the Host after the VEN_CORE_GET_FEATURES request
  52243. + */
  52244. +struct cfi_feature_desc_header {
  52245. +#define CFI_FEATURE_DESC_HDR_LEN 8
  52246. +
  52247. + /** The feature ID */
  52248. + uint16_t wFeatureID;
  52249. +
  52250. + /** Length of this feature descriptor in bytes - including the
  52251. + * length of the feature name string
  52252. + */
  52253. + uint16_t wLength;
  52254. +
  52255. + /** The data length of this feature in bytes */
  52256. + uint16_t wDataLength;
  52257. +
  52258. + /**
  52259. + * Attributes of this features
  52260. + * D0: Access rights
  52261. + * 0 - Read/Write
  52262. + * 1 - Read only
  52263. + */
  52264. + uint8_t bmAttributes;
  52265. +#define CFI_FEATURE_ATTR_RO 1
  52266. +#define CFI_FEATURE_ATTR_RW 0
  52267. +
  52268. + /** Length of the feature name in bytes */
  52269. + uint8_t bNameLen;
  52270. +
  52271. + /** The feature name buffer */
  52272. + //uint8_t *name;
  52273. +} UPACKED;
  52274. +
  52275. +typedef struct cfi_feature_desc_header cfi_feature_desc_header_t;
  52276. +
  52277. +/**
  52278. + * This structure describes a NULL terminated string referenced by its id field.
  52279. + * It is very similar to usb_string structure but has the id field type set to 16-bit.
  52280. + */
  52281. +struct cfi_string {
  52282. + uint16_t id;
  52283. + const uint8_t *s;
  52284. +};
  52285. +typedef struct cfi_string cfi_string_t;
  52286. +
  52287. +#endif
  52288. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_adp.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_adp.c
  52289. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_adp.c 1970-01-01 01:00:00.000000000 +0100
  52290. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_adp.c 2014-07-07 10:45:43.000000000 +0200
  52291. @@ -0,0 +1,854 @@
  52292. +/* ==========================================================================
  52293. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_adp.c $
  52294. + * $Revision: #12 $
  52295. + * $Date: 2011/10/26 $
  52296. + * $Change: 1873028 $
  52297. + *
  52298. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  52299. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  52300. + * otherwise expressly agreed to in writing between Synopsys and you.
  52301. + *
  52302. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  52303. + * any End User Software License Agreement or Agreement for Licensed Product
  52304. + * with Synopsys or any supplement thereto. You are permitted to use and
  52305. + * redistribute this Software in source and binary forms, with or without
  52306. + * modification, provided that redistributions of source code must retain this
  52307. + * notice. You may not view, use, disclose, copy or distribute this file or
  52308. + * any information contained herein except pursuant to this license grant from
  52309. + * Synopsys. If you do not agree with this notice, including the disclaimer
  52310. + * below, then you are not authorized to use the Software.
  52311. + *
  52312. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  52313. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  52314. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  52315. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  52316. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  52317. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  52318. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  52319. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  52320. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  52321. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  52322. + * DAMAGE.
  52323. + * ========================================================================== */
  52324. +
  52325. +#include "dwc_os.h"
  52326. +#include "dwc_otg_regs.h"
  52327. +#include "dwc_otg_cil.h"
  52328. +#include "dwc_otg_adp.h"
  52329. +
  52330. +/** @file
  52331. + *
  52332. + * This file contains the most of the Attach Detect Protocol implementation for
  52333. + * the driver to support OTG Rev2.0.
  52334. + *
  52335. + */
  52336. +
  52337. +void dwc_otg_adp_write_reg(dwc_otg_core_if_t * core_if, uint32_t value)
  52338. +{
  52339. + adpctl_data_t adpctl;
  52340. +
  52341. + adpctl.d32 = value;
  52342. + adpctl.b.ar = 0x2;
  52343. +
  52344. + DWC_WRITE_REG32(&core_if->core_global_regs->adpctl, adpctl.d32);
  52345. +
  52346. + while (adpctl.b.ar) {
  52347. + adpctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->adpctl);
  52348. + }
  52349. +
  52350. +}
  52351. +
  52352. +/**
  52353. + * Function is called to read ADP registers
  52354. + */
  52355. +uint32_t dwc_otg_adp_read_reg(dwc_otg_core_if_t * core_if)
  52356. +{
  52357. + adpctl_data_t adpctl;
  52358. +
  52359. + adpctl.d32 = 0;
  52360. + adpctl.b.ar = 0x1;
  52361. +
  52362. + DWC_WRITE_REG32(&core_if->core_global_regs->adpctl, adpctl.d32);
  52363. +
  52364. + while (adpctl.b.ar) {
  52365. + adpctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->adpctl);
  52366. + }
  52367. +
  52368. + return adpctl.d32;
  52369. +}
  52370. +
  52371. +/**
  52372. + * Function is called to read ADPCTL register and filter Write-clear bits
  52373. + */
  52374. +uint32_t dwc_otg_adp_read_reg_filter(dwc_otg_core_if_t * core_if)
  52375. +{
  52376. + adpctl_data_t adpctl;
  52377. +
  52378. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  52379. + adpctl.b.adp_tmout_int = 0;
  52380. + adpctl.b.adp_prb_int = 0;
  52381. + adpctl.b.adp_tmout_int = 0;
  52382. +
  52383. + return adpctl.d32;
  52384. +}
  52385. +
  52386. +/**
  52387. + * Function is called to write ADP registers
  52388. + */
  52389. +void dwc_otg_adp_modify_reg(dwc_otg_core_if_t * core_if, uint32_t clr,
  52390. + uint32_t set)
  52391. +{
  52392. + dwc_otg_adp_write_reg(core_if,
  52393. + (dwc_otg_adp_read_reg(core_if) & (~clr)) | set);
  52394. +}
  52395. +
  52396. +static void adp_sense_timeout(void *ptr)
  52397. +{
  52398. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  52399. + core_if->adp.sense_timer_started = 0;
  52400. + DWC_PRINTF("ADP SENSE TIMEOUT\n");
  52401. + if (core_if->adp_enable) {
  52402. + dwc_otg_adp_sense_stop(core_if);
  52403. + dwc_otg_adp_probe_start(core_if);
  52404. + }
  52405. +}
  52406. +
  52407. +/**
  52408. + * This function is called when the ADP vbus timer expires. Timeout is 1.1s.
  52409. + */
  52410. +static void adp_vbuson_timeout(void *ptr)
  52411. +{
  52412. + gpwrdn_data_t gpwrdn;
  52413. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  52414. + hprt0_data_t hprt0 = {.d32 = 0 };
  52415. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  52416. + DWC_PRINTF("%s: 1.1 seconds expire after turning on VBUS\n",__FUNCTION__);
  52417. + if (core_if) {
  52418. + core_if->adp.vbuson_timer_started = 0;
  52419. + /* Turn off vbus */
  52420. + hprt0.b.prtpwr = 1;
  52421. + DWC_MODIFY_REG32(core_if->host_if->hprt0, hprt0.d32, 0);
  52422. + gpwrdn.d32 = 0;
  52423. +
  52424. + /* Power off the core */
  52425. + if (core_if->power_down == 2) {
  52426. + /* Enable Wakeup Logic */
  52427. +// gpwrdn.b.wkupactiv = 1;
  52428. + gpwrdn.b.pmuactv = 0;
  52429. + gpwrdn.b.pwrdnrstn = 1;
  52430. + gpwrdn.b.pwrdnclmp = 1;
  52431. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  52432. + gpwrdn.d32);
  52433. +
  52434. + /* Suspend the Phy Clock */
  52435. + pcgcctl.b.stoppclk = 1;
  52436. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  52437. +
  52438. + /* Switch on VDD */
  52439. +// gpwrdn.b.wkupactiv = 1;
  52440. + gpwrdn.b.pmuactv = 1;
  52441. + gpwrdn.b.pwrdnrstn = 1;
  52442. + gpwrdn.b.pwrdnclmp = 1;
  52443. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  52444. + gpwrdn.d32);
  52445. + } else {
  52446. + /* Enable Power Down Logic */
  52447. + gpwrdn.b.pmuintsel = 1;
  52448. + gpwrdn.b.pmuactv = 1;
  52449. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  52450. + }
  52451. +
  52452. + /* Power off the core */
  52453. + if (core_if->power_down == 2) {
  52454. + gpwrdn.d32 = 0;
  52455. + gpwrdn.b.pwrdnswtch = 1;
  52456. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn,
  52457. + gpwrdn.d32, 0);
  52458. + }
  52459. +
  52460. + /* Unmask SRP detected interrupt from Power Down Logic */
  52461. + gpwrdn.d32 = 0;
  52462. + gpwrdn.b.srp_det_msk = 1;
  52463. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  52464. +
  52465. + dwc_otg_adp_probe_start(core_if);
  52466. + dwc_otg_dump_global_registers(core_if);
  52467. + dwc_otg_dump_host_registers(core_if);
  52468. + }
  52469. +
  52470. +}
  52471. +
  52472. +/**
  52473. + * Start the ADP Initial Probe timer to detect if Port Connected interrupt is
  52474. + * not asserted within 1.1 seconds.
  52475. + *
  52476. + * @param core_if the pointer to core_if strucure.
  52477. + */
  52478. +void dwc_otg_adp_vbuson_timer_start(dwc_otg_core_if_t * core_if)
  52479. +{
  52480. + core_if->adp.vbuson_timer_started = 1;
  52481. + if (core_if->adp.vbuson_timer)
  52482. + {
  52483. + DWC_PRINTF("SCHEDULING VBUSON TIMER\n");
  52484. + /* 1.1 secs + 60ms necessary for cil_hcd_start*/
  52485. + DWC_TIMER_SCHEDULE(core_if->adp.vbuson_timer, 1160);
  52486. + } else {
  52487. + DWC_WARN("VBUSON_TIMER = %p\n",core_if->adp.vbuson_timer);
  52488. + }
  52489. +}
  52490. +
  52491. +#if 0
  52492. +/**
  52493. + * Masks all DWC OTG core interrupts
  52494. + *
  52495. + */
  52496. +static void mask_all_interrupts(dwc_otg_core_if_t * core_if)
  52497. +{
  52498. + int i;
  52499. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  52500. +
  52501. + /* Mask Host Interrupts */
  52502. +
  52503. + /* Clear and disable HCINTs */
  52504. + for (i = 0; i < core_if->core_params->host_channels; i++) {
  52505. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcintmsk, 0);
  52506. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcint, 0xFFFFFFFF);
  52507. +
  52508. + }
  52509. +
  52510. + /* Clear and disable HAINT */
  52511. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haintmsk, 0x0000);
  52512. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haint, 0xFFFFFFFF);
  52513. +
  52514. + /* Mask Device Interrupts */
  52515. + if (!core_if->multiproc_int_enable) {
  52516. + /* Clear and disable IN Endpoint interrupts */
  52517. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->diepmsk, 0);
  52518. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  52519. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->
  52520. + diepint, 0xFFFFFFFF);
  52521. + }
  52522. +
  52523. + /* Clear and disable OUT Endpoint interrupts */
  52524. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->doepmsk, 0);
  52525. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  52526. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->
  52527. + doepint, 0xFFFFFFFF);
  52528. + }
  52529. +
  52530. + /* Clear and disable DAINT */
  52531. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daint,
  52532. + 0xFFFFFFFF);
  52533. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daintmsk, 0);
  52534. + } else {
  52535. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  52536. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  52537. + diepeachintmsk[i], 0);
  52538. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->
  52539. + diepint, 0xFFFFFFFF);
  52540. + }
  52541. +
  52542. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  52543. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  52544. + doepeachintmsk[i], 0);
  52545. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->
  52546. + doepint, 0xFFFFFFFF);
  52547. + }
  52548. +
  52549. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->deachintmsk,
  52550. + 0);
  52551. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->deachint,
  52552. + 0xFFFFFFFF);
  52553. +
  52554. + }
  52555. +
  52556. + /* Disable interrupts */
  52557. + ahbcfg.b.glblintrmsk = 1;
  52558. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, ahbcfg.d32, 0);
  52559. +
  52560. + /* Disable all interrupts. */
  52561. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0);
  52562. +
  52563. + /* Clear any pending interrupts */
  52564. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  52565. +
  52566. + /* Clear any pending OTG Interrupts */
  52567. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgint, 0xFFFFFFFF);
  52568. +}
  52569. +
  52570. +/**
  52571. + * Unmask Port Connection Detected interrupt
  52572. + *
  52573. + */
  52574. +static void unmask_conn_det_intr(dwc_otg_core_if_t * core_if)
  52575. +{
  52576. + gintmsk_data_t gintmsk = {.d32 = 0,.b.portintr = 1 };
  52577. +
  52578. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32);
  52579. +}
  52580. +#endif
  52581. +
  52582. +/**
  52583. + * Starts the ADP Probing
  52584. + *
  52585. + * @param core_if the pointer to core_if structure.
  52586. + */
  52587. +uint32_t dwc_otg_adp_probe_start(dwc_otg_core_if_t * core_if)
  52588. +{
  52589. +
  52590. + adpctl_data_t adpctl = {.d32 = 0};
  52591. + gpwrdn_data_t gpwrdn;
  52592. +#if 0
  52593. + adpctl_data_t adpctl_int = {.d32 = 0, .b.adp_prb_int = 1,
  52594. + .b.adp_sns_int = 1, b.adp_tmout_int};
  52595. +#endif
  52596. + dwc_otg_disable_global_interrupts(core_if);
  52597. + DWC_PRINTF("ADP Probe Start\n");
  52598. + core_if->adp.probe_enabled = 1;
  52599. +
  52600. + adpctl.b.adpres = 1;
  52601. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  52602. +
  52603. + while (adpctl.b.adpres) {
  52604. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  52605. + }
  52606. +
  52607. + adpctl.d32 = 0;
  52608. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  52609. +
  52610. + /* In Host mode unmask SRP detected interrupt */
  52611. + gpwrdn.d32 = 0;
  52612. + gpwrdn.b.sts_chngint_msk = 1;
  52613. + if (!gpwrdn.b.idsts) {
  52614. + gpwrdn.b.srp_det_msk = 1;
  52615. + }
  52616. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  52617. +
  52618. + adpctl.b.adp_tmout_int_msk = 1;
  52619. + adpctl.b.adp_prb_int_msk = 1;
  52620. + adpctl.b.prb_dschg = 1;
  52621. + adpctl.b.prb_delta = 1;
  52622. + adpctl.b.prb_per = 1;
  52623. + adpctl.b.adpen = 1;
  52624. + adpctl.b.enaprb = 1;
  52625. +
  52626. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  52627. + DWC_PRINTF("ADP Probe Finish\n");
  52628. + return 0;
  52629. +}
  52630. +
  52631. +/**
  52632. + * Starts the ADP Sense timer to detect if ADP Sense interrupt is not asserted
  52633. + * within 3 seconds.
  52634. + *
  52635. + * @param core_if the pointer to core_if strucure.
  52636. + */
  52637. +void dwc_otg_adp_sense_timer_start(dwc_otg_core_if_t * core_if)
  52638. +{
  52639. + core_if->adp.sense_timer_started = 1;
  52640. + DWC_TIMER_SCHEDULE(core_if->adp.sense_timer, 3000 /* 3 secs */ );
  52641. +}
  52642. +
  52643. +/**
  52644. + * Starts the ADP Sense
  52645. + *
  52646. + * @param core_if the pointer to core_if strucure.
  52647. + */
  52648. +uint32_t dwc_otg_adp_sense_start(dwc_otg_core_if_t * core_if)
  52649. +{
  52650. + adpctl_data_t adpctl;
  52651. +
  52652. + DWC_PRINTF("ADP Sense Start\n");
  52653. +
  52654. + /* Unmask ADP sense interrupt and mask all other from the core */
  52655. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  52656. + adpctl.b.adp_sns_int_msk = 1;
  52657. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  52658. + dwc_otg_disable_global_interrupts(core_if); // vahrama
  52659. +
  52660. + /* Set ADP reset bit*/
  52661. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  52662. + adpctl.b.adpres = 1;
  52663. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  52664. +
  52665. + while (adpctl.b.adpres) {
  52666. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  52667. + }
  52668. +
  52669. + adpctl.b.adpres = 0;
  52670. + adpctl.b.adpen = 1;
  52671. + adpctl.b.enasns = 1;
  52672. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  52673. +
  52674. + dwc_otg_adp_sense_timer_start(core_if);
  52675. +
  52676. + return 0;
  52677. +}
  52678. +
  52679. +/**
  52680. + * Stops the ADP Probing
  52681. + *
  52682. + * @param core_if the pointer to core_if strucure.
  52683. + */
  52684. +uint32_t dwc_otg_adp_probe_stop(dwc_otg_core_if_t * core_if)
  52685. +{
  52686. +
  52687. + adpctl_data_t adpctl;
  52688. + DWC_PRINTF("Stop ADP probe\n");
  52689. + core_if->adp.probe_enabled = 0;
  52690. + core_if->adp.probe_counter = 0;
  52691. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  52692. +
  52693. + adpctl.b.adpen = 0;
  52694. + adpctl.b.adp_prb_int = 1;
  52695. + adpctl.b.adp_tmout_int = 1;
  52696. + adpctl.b.adp_sns_int = 1;
  52697. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  52698. +
  52699. + return 0;
  52700. +}
  52701. +
  52702. +/**
  52703. + * Stops the ADP Sensing
  52704. + *
  52705. + * @param core_if the pointer to core_if strucure.
  52706. + */
  52707. +uint32_t dwc_otg_adp_sense_stop(dwc_otg_core_if_t * core_if)
  52708. +{
  52709. + adpctl_data_t adpctl;
  52710. +
  52711. + core_if->adp.sense_enabled = 0;
  52712. +
  52713. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  52714. + adpctl.b.enasns = 0;
  52715. + adpctl.b.adp_sns_int = 1;
  52716. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  52717. +
  52718. + return 0;
  52719. +}
  52720. +
  52721. +/**
  52722. + * Called to turn on the VBUS after initial ADP probe in host mode.
  52723. + * If port power was already enabled in cil_hcd_start function then
  52724. + * only schedule a timer.
  52725. + *
  52726. + * @param core_if the pointer to core_if structure.
  52727. + */
  52728. +void dwc_otg_adp_turnon_vbus(dwc_otg_core_if_t * core_if)
  52729. +{
  52730. + hprt0_data_t hprt0 = {.d32 = 0 };
  52731. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  52732. + DWC_PRINTF("Turn on VBUS for 1.1s, port power is %d\n", hprt0.b.prtpwr);
  52733. +
  52734. + if (hprt0.b.prtpwr == 0) {
  52735. + hprt0.b.prtpwr = 1;
  52736. + //DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  52737. + }
  52738. +
  52739. + dwc_otg_adp_vbuson_timer_start(core_if);
  52740. +}
  52741. +
  52742. +/**
  52743. + * Called right after driver is loaded
  52744. + * to perform initial actions for ADP
  52745. + *
  52746. + * @param core_if the pointer to core_if structure.
  52747. + * @param is_host - flag for current mode of operation either from GINTSTS or GPWRDN
  52748. + */
  52749. +void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host)
  52750. +{
  52751. + gpwrdn_data_t gpwrdn;
  52752. +
  52753. + DWC_PRINTF("ADP Initial Start\n");
  52754. + core_if->adp.adp_started = 1;
  52755. +
  52756. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  52757. + dwc_otg_disable_global_interrupts(core_if);
  52758. + if (is_host) {
  52759. + DWC_PRINTF("HOST MODE\n");
  52760. + /* Enable Power Down Logic Interrupt*/
  52761. + gpwrdn.d32 = 0;
  52762. + gpwrdn.b.pmuintsel = 1;
  52763. + gpwrdn.b.pmuactv = 1;
  52764. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  52765. + /* Initialize first ADP probe to obtain Ramp Time value */
  52766. + core_if->adp.initial_probe = 1;
  52767. + dwc_otg_adp_probe_start(core_if);
  52768. + } else {
  52769. + gotgctl_data_t gotgctl;
  52770. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  52771. + DWC_PRINTF("DEVICE MODE\n");
  52772. + if (gotgctl.b.bsesvld == 0) {
  52773. + /* Enable Power Down Logic Interrupt*/
  52774. + gpwrdn.d32 = 0;
  52775. + DWC_PRINTF("VBUS is not valid - start ADP probe\n");
  52776. + gpwrdn.b.pmuintsel = 1;
  52777. + gpwrdn.b.pmuactv = 1;
  52778. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  52779. + core_if->adp.initial_probe = 1;
  52780. + dwc_otg_adp_probe_start(core_if);
  52781. + } else {
  52782. + DWC_PRINTF("VBUS is valid - initialize core as a Device\n");
  52783. + core_if->op_state = B_PERIPHERAL;
  52784. + dwc_otg_core_init(core_if);
  52785. + dwc_otg_enable_global_interrupts(core_if);
  52786. + cil_pcd_start(core_if);
  52787. + dwc_otg_dump_global_registers(core_if);
  52788. + dwc_otg_dump_dev_registers(core_if);
  52789. + }
  52790. + }
  52791. +}
  52792. +
  52793. +void dwc_otg_adp_init(dwc_otg_core_if_t * core_if)
  52794. +{
  52795. + core_if->adp.adp_started = 0;
  52796. + core_if->adp.initial_probe = 0;
  52797. + core_if->adp.probe_timer_values[0] = -1;
  52798. + core_if->adp.probe_timer_values[1] = -1;
  52799. + core_if->adp.probe_enabled = 0;
  52800. + core_if->adp.sense_enabled = 0;
  52801. + core_if->adp.sense_timer_started = 0;
  52802. + core_if->adp.vbuson_timer_started = 0;
  52803. + core_if->adp.probe_counter = 0;
  52804. + core_if->adp.gpwrdn = 0;
  52805. + core_if->adp.attached = DWC_OTG_ADP_UNKOWN;
  52806. + /* Initialize timers */
  52807. + core_if->adp.sense_timer =
  52808. + DWC_TIMER_ALLOC("ADP SENSE TIMER", adp_sense_timeout, core_if);
  52809. + core_if->adp.vbuson_timer =
  52810. + DWC_TIMER_ALLOC("ADP VBUS ON TIMER", adp_vbuson_timeout, core_if);
  52811. + if (!core_if->adp.sense_timer || !core_if->adp.vbuson_timer)
  52812. + {
  52813. + DWC_ERROR("Could not allocate memory for ADP timers\n");
  52814. + }
  52815. +}
  52816. +
  52817. +void dwc_otg_adp_remove(dwc_otg_core_if_t * core_if)
  52818. +{
  52819. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  52820. + gpwrdn.b.pmuintsel = 1;
  52821. + gpwrdn.b.pmuactv = 1;
  52822. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  52823. +
  52824. + if (core_if->adp.probe_enabled)
  52825. + dwc_otg_adp_probe_stop(core_if);
  52826. + if (core_if->adp.sense_enabled)
  52827. + dwc_otg_adp_sense_stop(core_if);
  52828. + if (core_if->adp.sense_timer_started)
  52829. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  52830. + if (core_if->adp.vbuson_timer_started)
  52831. + DWC_TIMER_CANCEL(core_if->adp.vbuson_timer);
  52832. + DWC_TIMER_FREE(core_if->adp.sense_timer);
  52833. + DWC_TIMER_FREE(core_if->adp.vbuson_timer);
  52834. +}
  52835. +
  52836. +/////////////////////////////////////////////////////////////////////
  52837. +////////////// ADP Interrupt Handlers ///////////////////////////////
  52838. +/////////////////////////////////////////////////////////////////////
  52839. +/**
  52840. + * This function sets Ramp Timer values
  52841. + */
  52842. +static uint32_t set_timer_value(dwc_otg_core_if_t * core_if, uint32_t val)
  52843. +{
  52844. + if (core_if->adp.probe_timer_values[0] == -1) {
  52845. + core_if->adp.probe_timer_values[0] = val;
  52846. + core_if->adp.probe_timer_values[1] = -1;
  52847. + return 1;
  52848. + } else {
  52849. + core_if->adp.probe_timer_values[1] =
  52850. + core_if->adp.probe_timer_values[0];
  52851. + core_if->adp.probe_timer_values[0] = val;
  52852. + return 0;
  52853. + }
  52854. +}
  52855. +
  52856. +/**
  52857. + * This function compares Ramp Timer values
  52858. + */
  52859. +static uint32_t compare_timer_values(dwc_otg_core_if_t * core_if)
  52860. +{
  52861. + uint32_t diff;
  52862. + if (core_if->adp.probe_timer_values[0]>=core_if->adp.probe_timer_values[1])
  52863. + diff = core_if->adp.probe_timer_values[0]-core_if->adp.probe_timer_values[1];
  52864. + else
  52865. + diff = core_if->adp.probe_timer_values[1]-core_if->adp.probe_timer_values[0];
  52866. + if(diff < 2) {
  52867. + return 0;
  52868. + } else {
  52869. + return 1;
  52870. + }
  52871. +}
  52872. +
  52873. +/**
  52874. + * This function handles ADP Probe Interrupts
  52875. + */
  52876. +static int32_t dwc_otg_adp_handle_prb_intr(dwc_otg_core_if_t * core_if,
  52877. + uint32_t val)
  52878. +{
  52879. + adpctl_data_t adpctl = {.d32 = 0 };
  52880. + gpwrdn_data_t gpwrdn, temp;
  52881. + adpctl.d32 = val;
  52882. +
  52883. + temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  52884. + core_if->adp.probe_counter++;
  52885. + core_if->adp.gpwrdn = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  52886. + if (adpctl.b.rtim == 0 && !temp.b.idsts){
  52887. + DWC_PRINTF("RTIM value is 0\n");
  52888. + goto exit;
  52889. + }
  52890. + if (set_timer_value(core_if, adpctl.b.rtim) &&
  52891. + core_if->adp.initial_probe) {
  52892. + core_if->adp.initial_probe = 0;
  52893. + dwc_otg_adp_probe_stop(core_if);
  52894. + gpwrdn.d32 = 0;
  52895. + gpwrdn.b.pmuactv = 1;
  52896. + gpwrdn.b.pmuintsel = 1;
  52897. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  52898. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  52899. +
  52900. + /* check which value is for device mode and which for Host mode */
  52901. + if (!temp.b.idsts) { /* considered host mode value is 0 */
  52902. + /*
  52903. + * Turn on VBUS after initial ADP probe.
  52904. + */
  52905. + core_if->op_state = A_HOST;
  52906. + dwc_otg_enable_global_interrupts(core_if);
  52907. + DWC_SPINUNLOCK(core_if->lock);
  52908. + cil_hcd_start(core_if);
  52909. + dwc_otg_adp_turnon_vbus(core_if);
  52910. + DWC_SPINLOCK(core_if->lock);
  52911. + } else {
  52912. + /*
  52913. + * Initiate SRP after initial ADP probe.
  52914. + */
  52915. + dwc_otg_enable_global_interrupts(core_if);
  52916. + dwc_otg_initiate_srp(core_if);
  52917. + }
  52918. + } else if (core_if->adp.probe_counter > 2){
  52919. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  52920. + if (compare_timer_values(core_if)) {
  52921. + DWC_PRINTF("Difference in timer values !!! \n");
  52922. +// core_if->adp.attached = DWC_OTG_ADP_ATTACHED;
  52923. + dwc_otg_adp_probe_stop(core_if);
  52924. +
  52925. + /* Power on the core */
  52926. + if (core_if->power_down == 2) {
  52927. + gpwrdn.b.pwrdnswtch = 1;
  52928. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  52929. + gpwrdn, 0, gpwrdn.d32);
  52930. + }
  52931. +
  52932. + /* check which value is for device mode and which for Host mode */
  52933. + if (!temp.b.idsts) { /* considered host mode value is 0 */
  52934. + /* Disable Interrupt from Power Down Logic */
  52935. + gpwrdn.d32 = 0;
  52936. + gpwrdn.b.pmuintsel = 1;
  52937. + gpwrdn.b.pmuactv = 1;
  52938. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  52939. + gpwrdn, gpwrdn.d32, 0);
  52940. +
  52941. + /*
  52942. + * Initialize the Core for Host mode.
  52943. + */
  52944. + core_if->op_state = A_HOST;
  52945. + dwc_otg_core_init(core_if);
  52946. + dwc_otg_enable_global_interrupts(core_if);
  52947. + cil_hcd_start(core_if);
  52948. + } else {
  52949. + gotgctl_data_t gotgctl;
  52950. + /* Mask SRP detected interrupt from Power Down Logic */
  52951. + gpwrdn.d32 = 0;
  52952. + gpwrdn.b.srp_det_msk = 1;
  52953. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  52954. + gpwrdn, gpwrdn.d32, 0);
  52955. +
  52956. + /* Disable Power Down Logic */
  52957. + gpwrdn.d32 = 0;
  52958. + gpwrdn.b.pmuintsel = 1;
  52959. + gpwrdn.b.pmuactv = 1;
  52960. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  52961. + gpwrdn, gpwrdn.d32, 0);
  52962. +
  52963. + /*
  52964. + * Initialize the Core for Device mode.
  52965. + */
  52966. + core_if->op_state = B_PERIPHERAL;
  52967. + dwc_otg_core_init(core_if);
  52968. + dwc_otg_enable_global_interrupts(core_if);
  52969. + cil_pcd_start(core_if);
  52970. +
  52971. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  52972. + if (!gotgctl.b.bsesvld) {
  52973. + dwc_otg_initiate_srp(core_if);
  52974. + }
  52975. + }
  52976. + }
  52977. + if (core_if->power_down == 2) {
  52978. + if (gpwrdn.b.bsessvld) {
  52979. + /* Mask SRP detected interrupt from Power Down Logic */
  52980. + gpwrdn.d32 = 0;
  52981. + gpwrdn.b.srp_det_msk = 1;
  52982. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  52983. +
  52984. + /* Disable Power Down Logic */
  52985. + gpwrdn.d32 = 0;
  52986. + gpwrdn.b.pmuactv = 1;
  52987. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  52988. +
  52989. + /*
  52990. + * Initialize the Core for Device mode.
  52991. + */
  52992. + core_if->op_state = B_PERIPHERAL;
  52993. + dwc_otg_core_init(core_if);
  52994. + dwc_otg_enable_global_interrupts(core_if);
  52995. + cil_pcd_start(core_if);
  52996. + }
  52997. + }
  52998. + }
  52999. +exit:
  53000. + /* Clear interrupt */
  53001. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  53002. + adpctl.b.adp_prb_int = 1;
  53003. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  53004. +
  53005. + return 0;
  53006. +}
  53007. +
  53008. +/**
  53009. + * This function hadles ADP Sense Interrupt
  53010. + */
  53011. +static int32_t dwc_otg_adp_handle_sns_intr(dwc_otg_core_if_t * core_if)
  53012. +{
  53013. + adpctl_data_t adpctl;
  53014. + /* Stop ADP Sense timer */
  53015. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  53016. +
  53017. + /* Restart ADP Sense timer */
  53018. + dwc_otg_adp_sense_timer_start(core_if);
  53019. +
  53020. + /* Clear interrupt */
  53021. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  53022. + adpctl.b.adp_sns_int = 1;
  53023. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  53024. +
  53025. + return 0;
  53026. +}
  53027. +
  53028. +/**
  53029. + * This function handles ADP Probe Interrupts
  53030. + */
  53031. +static int32_t dwc_otg_adp_handle_prb_tmout_intr(dwc_otg_core_if_t * core_if,
  53032. + uint32_t val)
  53033. +{
  53034. + adpctl_data_t adpctl = {.d32 = 0 };
  53035. + adpctl.d32 = val;
  53036. + set_timer_value(core_if, adpctl.b.rtim);
  53037. +
  53038. + /* Clear interrupt */
  53039. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  53040. + adpctl.b.adp_tmout_int = 1;
  53041. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  53042. +
  53043. + return 0;
  53044. +}
  53045. +
  53046. +/**
  53047. + * ADP Interrupt handler.
  53048. + *
  53049. + */
  53050. +int32_t dwc_otg_adp_handle_intr(dwc_otg_core_if_t * core_if)
  53051. +{
  53052. + int retval = 0;
  53053. + adpctl_data_t adpctl = {.d32 = 0};
  53054. +
  53055. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  53056. + DWC_PRINTF("ADPCTL = %08x\n",adpctl.d32);
  53057. +
  53058. + if (adpctl.b.adp_sns_int & adpctl.b.adp_sns_int_msk) {
  53059. + DWC_PRINTF("ADP Sense interrupt\n");
  53060. + retval |= dwc_otg_adp_handle_sns_intr(core_if);
  53061. + }
  53062. + if (adpctl.b.adp_tmout_int & adpctl.b.adp_tmout_int_msk) {
  53063. + DWC_PRINTF("ADP timeout interrupt\n");
  53064. + retval |= dwc_otg_adp_handle_prb_tmout_intr(core_if, adpctl.d32);
  53065. + }
  53066. + if (adpctl.b.adp_prb_int & adpctl.b.adp_prb_int_msk) {
  53067. + DWC_PRINTF("ADP Probe interrupt\n");
  53068. + adpctl.b.adp_prb_int = 1;
  53069. + retval |= dwc_otg_adp_handle_prb_intr(core_if, adpctl.d32);
  53070. + }
  53071. +
  53072. +// dwc_otg_adp_modify_reg(core_if, adpctl.d32, 0);
  53073. + //dwc_otg_adp_write_reg(core_if, adpctl.d32);
  53074. + DWC_PRINTF("RETURN FROM ADP ISR\n");
  53075. +
  53076. + return retval;
  53077. +}
  53078. +
  53079. +/**
  53080. + *
  53081. + * @param core_if Programming view of DWC_otg controller.
  53082. + */
  53083. +int32_t dwc_otg_adp_handle_srp_intr(dwc_otg_core_if_t * core_if)
  53084. +{
  53085. +
  53086. +#ifndef DWC_HOST_ONLY
  53087. + hprt0_data_t hprt0;
  53088. + gpwrdn_data_t gpwrdn;
  53089. + DWC_DEBUGPL(DBG_ANY, "++ Power Down Logic Session Request Interrupt++\n");
  53090. +
  53091. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  53092. + /* check which value is for device mode and which for Host mode */
  53093. + if (!gpwrdn.b.idsts) { /* considered host mode value is 0 */
  53094. + DWC_PRINTF("SRP: Host mode\n");
  53095. +
  53096. + if (core_if->adp_enable) {
  53097. + dwc_otg_adp_probe_stop(core_if);
  53098. +
  53099. + /* Power on the core */
  53100. + if (core_if->power_down == 2) {
  53101. + gpwrdn.b.pwrdnswtch = 1;
  53102. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  53103. + gpwrdn, 0, gpwrdn.d32);
  53104. + }
  53105. +
  53106. + core_if->op_state = A_HOST;
  53107. + dwc_otg_core_init(core_if);
  53108. + dwc_otg_enable_global_interrupts(core_if);
  53109. + cil_hcd_start(core_if);
  53110. + }
  53111. +
  53112. + /* Turn on the port power bit. */
  53113. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  53114. + hprt0.b.prtpwr = 1;
  53115. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  53116. +
  53117. + /* Start the Connection timer. So a message can be displayed
  53118. + * if connect does not occur within 10 seconds. */
  53119. + cil_hcd_session_start(core_if);
  53120. + } else {
  53121. + DWC_PRINTF("SRP: Device mode %s\n", __FUNCTION__);
  53122. + if (core_if->adp_enable) {
  53123. + dwc_otg_adp_probe_stop(core_if);
  53124. +
  53125. + /* Power on the core */
  53126. + if (core_if->power_down == 2) {
  53127. + gpwrdn.b.pwrdnswtch = 1;
  53128. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  53129. + gpwrdn, 0, gpwrdn.d32);
  53130. + }
  53131. +
  53132. + gpwrdn.d32 = 0;
  53133. + gpwrdn.b.pmuactv = 0;
  53134. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  53135. + gpwrdn.d32);
  53136. +
  53137. + core_if->op_state = B_PERIPHERAL;
  53138. + dwc_otg_core_init(core_if);
  53139. + dwc_otg_enable_global_interrupts(core_if);
  53140. + cil_pcd_start(core_if);
  53141. + }
  53142. + }
  53143. +#endif
  53144. + return 1;
  53145. +}
  53146. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_adp.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_adp.h
  53147. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_adp.h 1970-01-01 01:00:00.000000000 +0100
  53148. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_adp.h 2014-07-07 10:45:43.000000000 +0200
  53149. @@ -0,0 +1,80 @@
  53150. +/* ==========================================================================
  53151. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_adp.h $
  53152. + * $Revision: #7 $
  53153. + * $Date: 2011/10/24 $
  53154. + * $Change: 1871159 $
  53155. + *
  53156. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  53157. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  53158. + * otherwise expressly agreed to in writing between Synopsys and you.
  53159. + *
  53160. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  53161. + * any End User Software License Agreement or Agreement for Licensed Product
  53162. + * with Synopsys or any supplement thereto. You are permitted to use and
  53163. + * redistribute this Software in source and binary forms, with or without
  53164. + * modification, provided that redistributions of source code must retain this
  53165. + * notice. You may not view, use, disclose, copy or distribute this file or
  53166. + * any information contained herein except pursuant to this license grant from
  53167. + * Synopsys. If you do not agree with this notice, including the disclaimer
  53168. + * below, then you are not authorized to use the Software.
  53169. + *
  53170. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  53171. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  53172. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  53173. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  53174. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  53175. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  53176. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  53177. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  53178. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  53179. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  53180. + * DAMAGE.
  53181. + * ========================================================================== */
  53182. +
  53183. +#ifndef __DWC_OTG_ADP_H__
  53184. +#define __DWC_OTG_ADP_H__
  53185. +
  53186. +/**
  53187. + * @file
  53188. + *
  53189. + * This file contains the Attach Detect Protocol interfaces and defines
  53190. + * (functions) and structures for Linux.
  53191. + *
  53192. + */
  53193. +
  53194. +#define DWC_OTG_ADP_UNATTACHED 0
  53195. +#define DWC_OTG_ADP_ATTACHED 1
  53196. +#define DWC_OTG_ADP_UNKOWN 2
  53197. +
  53198. +typedef struct dwc_otg_adp {
  53199. + uint32_t adp_started;
  53200. + uint32_t initial_probe;
  53201. + int32_t probe_timer_values[2];
  53202. + uint32_t probe_enabled;
  53203. + uint32_t sense_enabled;
  53204. + dwc_timer_t *sense_timer;
  53205. + uint32_t sense_timer_started;
  53206. + dwc_timer_t *vbuson_timer;
  53207. + uint32_t vbuson_timer_started;
  53208. + uint32_t attached;
  53209. + uint32_t probe_counter;
  53210. + uint32_t gpwrdn;
  53211. +} dwc_otg_adp_t;
  53212. +
  53213. +/**
  53214. + * Attach Detect Protocol functions
  53215. + */
  53216. +
  53217. +extern void dwc_otg_adp_write_reg(dwc_otg_core_if_t * core_if, uint32_t value);
  53218. +extern uint32_t dwc_otg_adp_read_reg(dwc_otg_core_if_t * core_if);
  53219. +extern uint32_t dwc_otg_adp_probe_start(dwc_otg_core_if_t * core_if);
  53220. +extern uint32_t dwc_otg_adp_sense_start(dwc_otg_core_if_t * core_if);
  53221. +extern uint32_t dwc_otg_adp_probe_stop(dwc_otg_core_if_t * core_if);
  53222. +extern uint32_t dwc_otg_adp_sense_stop(dwc_otg_core_if_t * core_if);
  53223. +extern void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host);
  53224. +extern void dwc_otg_adp_init(dwc_otg_core_if_t * core_if);
  53225. +extern void dwc_otg_adp_remove(dwc_otg_core_if_t * core_if);
  53226. +extern int32_t dwc_otg_adp_handle_intr(dwc_otg_core_if_t * core_if);
  53227. +extern int32_t dwc_otg_adp_handle_srp_intr(dwc_otg_core_if_t * core_if);
  53228. +
  53229. +#endif //__DWC_OTG_ADP_H__
  53230. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_attr.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_attr.c
  53231. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_attr.c 1970-01-01 01:00:00.000000000 +0100
  53232. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_attr.c 2014-07-07 10:45:43.000000000 +0200
  53233. @@ -0,0 +1,1210 @@
  53234. +/* ==========================================================================
  53235. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.c $
  53236. + * $Revision: #44 $
  53237. + * $Date: 2010/11/29 $
  53238. + * $Change: 1636033 $
  53239. + *
  53240. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  53241. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  53242. + * otherwise expressly agreed to in writing between Synopsys and you.
  53243. + *
  53244. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  53245. + * any End User Software License Agreement or Agreement for Licensed Product
  53246. + * with Synopsys or any supplement thereto. You are permitted to use and
  53247. + * redistribute this Software in source and binary forms, with or without
  53248. + * modification, provided that redistributions of source code must retain this
  53249. + * notice. You may not view, use, disclose, copy or distribute this file or
  53250. + * any information contained herein except pursuant to this license grant from
  53251. + * Synopsys. If you do not agree with this notice, including the disclaimer
  53252. + * below, then you are not authorized to use the Software.
  53253. + *
  53254. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  53255. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  53256. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  53257. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  53258. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  53259. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  53260. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  53261. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  53262. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  53263. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  53264. + * DAMAGE.
  53265. + * ========================================================================== */
  53266. +
  53267. +/** @file
  53268. + *
  53269. + * The diagnostic interface will provide access to the controller for
  53270. + * bringing up the hardware and testing. The Linux driver attributes
  53271. + * feature will be used to provide the Linux Diagnostic
  53272. + * Interface. These attributes are accessed through sysfs.
  53273. + */
  53274. +
  53275. +/** @page "Linux Module Attributes"
  53276. + *
  53277. + * The Linux module attributes feature is used to provide the Linux
  53278. + * Diagnostic Interface. These attributes are accessed through sysfs.
  53279. + * The diagnostic interface will provide access to the controller for
  53280. + * bringing up the hardware and testing.
  53281. +
  53282. + The following table shows the attributes.
  53283. + <table>
  53284. + <tr>
  53285. + <td><b> Name</b></td>
  53286. + <td><b> Description</b></td>
  53287. + <td><b> Access</b></td>
  53288. + </tr>
  53289. +
  53290. + <tr>
  53291. + <td> mode </td>
  53292. + <td> Returns the current mode: 0 for device mode, 1 for host mode</td>
  53293. + <td> Read</td>
  53294. + </tr>
  53295. +
  53296. + <tr>
  53297. + <td> hnpcapable </td>
  53298. + <td> Gets or sets the "HNP-capable" bit in the Core USB Configuraton Register.
  53299. + Read returns the current value.</td>
  53300. + <td> Read/Write</td>
  53301. + </tr>
  53302. +
  53303. + <tr>
  53304. + <td> srpcapable </td>
  53305. + <td> Gets or sets the "SRP-capable" bit in the Core USB Configuraton Register.
  53306. + Read returns the current value.</td>
  53307. + <td> Read/Write</td>
  53308. + </tr>
  53309. +
  53310. + <tr>
  53311. + <td> hsic_connect </td>
  53312. + <td> Gets or sets the "HSIC-Connect" bit in the GLPMCFG Register.
  53313. + Read returns the current value.</td>
  53314. + <td> Read/Write</td>
  53315. + </tr>
  53316. +
  53317. + <tr>
  53318. + <td> inv_sel_hsic </td>
  53319. + <td> Gets or sets the "Invert Select HSIC" bit in the GLPMFG Register.
  53320. + Read returns the current value.</td>
  53321. + <td> Read/Write</td>
  53322. + </tr>
  53323. +
  53324. + <tr>
  53325. + <td> hnp </td>
  53326. + <td> Initiates the Host Negotiation Protocol. Read returns the status.</td>
  53327. + <td> Read/Write</td>
  53328. + </tr>
  53329. +
  53330. + <tr>
  53331. + <td> srp </td>
  53332. + <td> Initiates the Session Request Protocol. Read returns the status.</td>
  53333. + <td> Read/Write</td>
  53334. + </tr>
  53335. +
  53336. + <tr>
  53337. + <td> buspower </td>
  53338. + <td> Gets or sets the Power State of the bus (0 - Off or 1 - On)</td>
  53339. + <td> Read/Write</td>
  53340. + </tr>
  53341. +
  53342. + <tr>
  53343. + <td> bussuspend </td>
  53344. + <td> Suspends the USB bus.</td>
  53345. + <td> Read/Write</td>
  53346. + </tr>
  53347. +
  53348. + <tr>
  53349. + <td> busconnected </td>
  53350. + <td> Gets the connection status of the bus</td>
  53351. + <td> Read</td>
  53352. + </tr>
  53353. +
  53354. + <tr>
  53355. + <td> gotgctl </td>
  53356. + <td> Gets or sets the Core Control Status Register.</td>
  53357. + <td> Read/Write</td>
  53358. + </tr>
  53359. +
  53360. + <tr>
  53361. + <td> gusbcfg </td>
  53362. + <td> Gets or sets the Core USB Configuration Register</td>
  53363. + <td> Read/Write</td>
  53364. + </tr>
  53365. +
  53366. + <tr>
  53367. + <td> grxfsiz </td>
  53368. + <td> Gets or sets the Receive FIFO Size Register</td>
  53369. + <td> Read/Write</td>
  53370. + </tr>
  53371. +
  53372. + <tr>
  53373. + <td> gnptxfsiz </td>
  53374. + <td> Gets or sets the non-periodic Transmit Size Register</td>
  53375. + <td> Read/Write</td>
  53376. + </tr>
  53377. +
  53378. + <tr>
  53379. + <td> gpvndctl </td>
  53380. + <td> Gets or sets the PHY Vendor Control Register</td>
  53381. + <td> Read/Write</td>
  53382. + </tr>
  53383. +
  53384. + <tr>
  53385. + <td> ggpio </td>
  53386. + <td> Gets the value in the lower 16-bits of the General Purpose IO Register
  53387. + or sets the upper 16 bits.</td>
  53388. + <td> Read/Write</td>
  53389. + </tr>
  53390. +
  53391. + <tr>
  53392. + <td> guid </td>
  53393. + <td> Gets or sets the value of the User ID Register</td>
  53394. + <td> Read/Write</td>
  53395. + </tr>
  53396. +
  53397. + <tr>
  53398. + <td> gsnpsid </td>
  53399. + <td> Gets the value of the Synopsys ID Regester</td>
  53400. + <td> Read</td>
  53401. + </tr>
  53402. +
  53403. + <tr>
  53404. + <td> devspeed </td>
  53405. + <td> Gets or sets the device speed setting in the DCFG register</td>
  53406. + <td> Read/Write</td>
  53407. + </tr>
  53408. +
  53409. + <tr>
  53410. + <td> enumspeed </td>
  53411. + <td> Gets the device enumeration Speed.</td>
  53412. + <td> Read</td>
  53413. + </tr>
  53414. +
  53415. + <tr>
  53416. + <td> hptxfsiz </td>
  53417. + <td> Gets the value of the Host Periodic Transmit FIFO</td>
  53418. + <td> Read</td>
  53419. + </tr>
  53420. +
  53421. + <tr>
  53422. + <td> hprt0 </td>
  53423. + <td> Gets or sets the value in the Host Port Control and Status Register</td>
  53424. + <td> Read/Write</td>
  53425. + </tr>
  53426. +
  53427. + <tr>
  53428. + <td> regoffset </td>
  53429. + <td> Sets the register offset for the next Register Access</td>
  53430. + <td> Read/Write</td>
  53431. + </tr>
  53432. +
  53433. + <tr>
  53434. + <td> regvalue </td>
  53435. + <td> Gets or sets the value of the register at the offset in the regoffset attribute.</td>
  53436. + <td> Read/Write</td>
  53437. + </tr>
  53438. +
  53439. + <tr>
  53440. + <td> remote_wakeup </td>
  53441. + <td> On read, shows the status of Remote Wakeup. On write, initiates a remote
  53442. + wakeup of the host. When bit 0 is 1 and Remote Wakeup is enabled, the Remote
  53443. + Wakeup signalling bit in the Device Control Register is set for 1
  53444. + milli-second.</td>
  53445. + <td> Read/Write</td>
  53446. + </tr>
  53447. +
  53448. + <tr>
  53449. + <td> rem_wakeup_pwrdn </td>
  53450. + <td> On read, shows the status core - hibernated or not. On write, initiates
  53451. + a remote wakeup of the device from Hibernation. </td>
  53452. + <td> Read/Write</td>
  53453. + </tr>
  53454. +
  53455. + <tr>
  53456. + <td> mode_ch_tim_en </td>
  53457. + <td> This bit is used to enable or disable the host core to wait for 200 PHY
  53458. + clock cycles at the end of Resume to change the opmode signal to the PHY to 00
  53459. + after Suspend or LPM. </td>
  53460. + <td> Read/Write</td>
  53461. + </tr>
  53462. +
  53463. + <tr>
  53464. + <td> fr_interval </td>
  53465. + <td> On read, shows the value of HFIR Frame Interval. On write, dynamically
  53466. + reload HFIR register during runtime. The application can write a value to this
  53467. + register only after the Port Enable bit of the Host Port Control and Status
  53468. + register (HPRT.PrtEnaPort) has been set </td>
  53469. + <td> Read/Write</td>
  53470. + </tr>
  53471. +
  53472. + <tr>
  53473. + <td> disconnect_us </td>
  53474. + <td> On read, shows the status of disconnect_device_us. On write, sets disconnect_us
  53475. + which causes soft disconnect for 100us. Applicable only for device mode of operation.</td>
  53476. + <td> Read/Write</td>
  53477. + </tr>
  53478. +
  53479. + <tr>
  53480. + <td> regdump </td>
  53481. + <td> Dumps the contents of core registers.</td>
  53482. + <td> Read</td>
  53483. + </tr>
  53484. +
  53485. + <tr>
  53486. + <td> spramdump </td>
  53487. + <td> Dumps the contents of core registers.</td>
  53488. + <td> Read</td>
  53489. + </tr>
  53490. +
  53491. + <tr>
  53492. + <td> hcddump </td>
  53493. + <td> Dumps the current HCD state.</td>
  53494. + <td> Read</td>
  53495. + </tr>
  53496. +
  53497. + <tr>
  53498. + <td> hcd_frrem </td>
  53499. + <td> Shows the average value of the Frame Remaining
  53500. + field in the Host Frame Number/Frame Remaining register when an SOF interrupt
  53501. + occurs. This can be used to determine the average interrupt latency. Also
  53502. + shows the average Frame Remaining value for start_transfer and the "a" and
  53503. + "b" sample points. The "a" and "b" sample points may be used during debugging
  53504. + bto determine how long it takes to execute a section of the HCD code.</td>
  53505. + <td> Read</td>
  53506. + </tr>
  53507. +
  53508. + <tr>
  53509. + <td> rd_reg_test </td>
  53510. + <td> Displays the time required to read the GNPTXFSIZ register many times
  53511. + (the output shows the number of times the register is read).
  53512. + <td> Read</td>
  53513. + </tr>
  53514. +
  53515. + <tr>
  53516. + <td> wr_reg_test </td>
  53517. + <td> Displays the time required to write the GNPTXFSIZ register many times
  53518. + (the output shows the number of times the register is written).
  53519. + <td> Read</td>
  53520. + </tr>
  53521. +
  53522. + <tr>
  53523. + <td> lpm_response </td>
  53524. + <td> Gets or sets lpm_response mode. Applicable only in device mode.
  53525. + <td> Write</td>
  53526. + </tr>
  53527. +
  53528. + <tr>
  53529. + <td> sleep_status </td>
  53530. + <td> Shows sleep status of device.
  53531. + <td> Read</td>
  53532. + </tr>
  53533. +
  53534. + </table>
  53535. +
  53536. + Example usage:
  53537. + To get the current mode:
  53538. + cat /sys/devices/lm0/mode
  53539. +
  53540. + To power down the USB:
  53541. + echo 0 > /sys/devices/lm0/buspower
  53542. + */
  53543. +
  53544. +#include "dwc_otg_os_dep.h"
  53545. +#include "dwc_os.h"
  53546. +#include "dwc_otg_driver.h"
  53547. +#include "dwc_otg_attr.h"
  53548. +#include "dwc_otg_core_if.h"
  53549. +#include "dwc_otg_pcd_if.h"
  53550. +#include "dwc_otg_hcd_if.h"
  53551. +
  53552. +/*
  53553. + * MACROs for defining sysfs attribute
  53554. + */
  53555. +#ifdef LM_INTERFACE
  53556. +
  53557. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  53558. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  53559. +{ \
  53560. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  53561. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  53562. + uint32_t val; \
  53563. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  53564. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  53565. +}
  53566. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  53567. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  53568. + const char *buf, size_t count) \
  53569. +{ \
  53570. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  53571. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  53572. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  53573. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  53574. + return count; \
  53575. +}
  53576. +
  53577. +#elif defined(PCI_INTERFACE)
  53578. +
  53579. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  53580. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  53581. +{ \
  53582. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  53583. + uint32_t val; \
  53584. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  53585. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  53586. +}
  53587. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  53588. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  53589. + const char *buf, size_t count) \
  53590. +{ \
  53591. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  53592. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  53593. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  53594. + return count; \
  53595. +}
  53596. +
  53597. +#elif defined(PLATFORM_INTERFACE)
  53598. +
  53599. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  53600. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  53601. +{ \
  53602. + struct platform_device *platform_dev = \
  53603. + container_of(_dev, struct platform_device, dev); \
  53604. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  53605. + uint32_t val; \
  53606. + DWC_PRINTF("%s(%p) -> platform_dev %p, otg_dev %p\n", \
  53607. + __func__, _dev, platform_dev, otg_dev); \
  53608. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  53609. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  53610. +}
  53611. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  53612. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  53613. + const char *buf, size_t count) \
  53614. +{ \
  53615. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  53616. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  53617. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  53618. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  53619. + return count; \
  53620. +}
  53621. +#endif
  53622. +
  53623. +/*
  53624. + * MACROs for defining sysfs attribute for 32-bit registers
  53625. + */
  53626. +#ifdef LM_INTERFACE
  53627. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  53628. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  53629. +{ \
  53630. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  53631. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  53632. + uint32_t val; \
  53633. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  53634. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  53635. +}
  53636. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  53637. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  53638. + const char *buf, size_t count) \
  53639. +{ \
  53640. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  53641. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  53642. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  53643. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  53644. + return count; \
  53645. +}
  53646. +#elif defined(PCI_INTERFACE)
  53647. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  53648. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  53649. +{ \
  53650. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  53651. + uint32_t val; \
  53652. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  53653. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  53654. +}
  53655. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  53656. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  53657. + const char *buf, size_t count) \
  53658. +{ \
  53659. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  53660. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  53661. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  53662. + return count; \
  53663. +}
  53664. +
  53665. +#elif defined(PLATFORM_INTERFACE)
  53666. +#include "dwc_otg_dbg.h"
  53667. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  53668. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  53669. +{ \
  53670. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  53671. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  53672. + uint32_t val; \
  53673. + DWC_PRINTF("%s(%p) -> platform_dev %p, otg_dev %p\n", \
  53674. + __func__, _dev, platform_dev, otg_dev); \
  53675. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  53676. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  53677. +}
  53678. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  53679. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  53680. + const char *buf, size_t count) \
  53681. +{ \
  53682. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  53683. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  53684. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  53685. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  53686. + return count; \
  53687. +}
  53688. +
  53689. +#endif
  53690. +
  53691. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RW(_otg_attr_name_,_string_) \
  53692. +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  53693. +DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  53694. +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
  53695. +
  53696. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RO(_otg_attr_name_,_string_) \
  53697. +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  53698. +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
  53699. +
  53700. +#define DWC_OTG_DEVICE_ATTR_REG32_RW(_otg_attr_name_,_addr_,_string_) \
  53701. +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  53702. +DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  53703. +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
  53704. +
  53705. +#define DWC_OTG_DEVICE_ATTR_REG32_RO(_otg_attr_name_,_addr_,_string_) \
  53706. +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  53707. +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
  53708. +
  53709. +/** @name Functions for Show/Store of Attributes */
  53710. +/**@{*/
  53711. +
  53712. +/**
  53713. + * Helper function returning the otg_device structure of the given device
  53714. + */
  53715. +static dwc_otg_device_t *dwc_otg_drvdev(struct device *_dev)
  53716. +{
  53717. + dwc_otg_device_t *otg_dev;
  53718. + DWC_OTG_GETDRVDEV(otg_dev, _dev);
  53719. + return otg_dev;
  53720. +}
  53721. +
  53722. +/**
  53723. + * Show the register offset of the Register Access.
  53724. + */
  53725. +static ssize_t regoffset_show(struct device *_dev,
  53726. + struct device_attribute *attr, char *buf)
  53727. +{
  53728. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53729. + return snprintf(buf, sizeof("0xFFFFFFFF\n") + 1, "0x%08x\n",
  53730. + otg_dev->os_dep.reg_offset);
  53731. +}
  53732. +
  53733. +/**
  53734. + * Set the register offset for the next Register Access Read/Write
  53735. + */
  53736. +static ssize_t regoffset_store(struct device *_dev,
  53737. + struct device_attribute *attr,
  53738. + const char *buf, size_t count)
  53739. +{
  53740. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53741. + uint32_t offset = simple_strtoul(buf, NULL, 16);
  53742. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  53743. + if (offset < SZ_256K) {
  53744. +#elif defined(PCI_INTERFACE)
  53745. + if (offset < 0x00040000) {
  53746. +#endif
  53747. + otg_dev->os_dep.reg_offset = offset;
  53748. + } else {
  53749. + dev_err(_dev, "invalid offset\n");
  53750. + }
  53751. +
  53752. + return count;
  53753. +}
  53754. +
  53755. +DEVICE_ATTR(regoffset, S_IRUGO | S_IWUSR, regoffset_show, regoffset_store);
  53756. +
  53757. +/**
  53758. + * Show the value of the register at the offset in the reg_offset
  53759. + * attribute.
  53760. + */
  53761. +static ssize_t regvalue_show(struct device *_dev,
  53762. + struct device_attribute *attr, char *buf)
  53763. +{
  53764. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53765. + uint32_t val;
  53766. + volatile uint32_t *addr;
  53767. +
  53768. + if (otg_dev->os_dep.reg_offset != 0xFFFFFFFF && 0 != otg_dev->os_dep.base) {
  53769. + /* Calculate the address */
  53770. + addr = (uint32_t *) (otg_dev->os_dep.reg_offset +
  53771. + (uint8_t *) otg_dev->os_dep.base);
  53772. + val = DWC_READ_REG32(addr);
  53773. + return snprintf(buf,
  53774. + sizeof("Reg@0xFFFFFFFF = 0xFFFFFFFF\n") + 1,
  53775. + "Reg@0x%06x = 0x%08x\n", otg_dev->os_dep.reg_offset,
  53776. + val);
  53777. + } else {
  53778. + dev_err(_dev, "Invalid offset (0x%0x)\n", otg_dev->os_dep.reg_offset);
  53779. + return sprintf(buf, "invalid offset\n");
  53780. + }
  53781. +}
  53782. +
  53783. +/**
  53784. + * Store the value in the register at the offset in the reg_offset
  53785. + * attribute.
  53786. + *
  53787. + */
  53788. +static ssize_t regvalue_store(struct device *_dev,
  53789. + struct device_attribute *attr,
  53790. + const char *buf, size_t count)
  53791. +{
  53792. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53793. + volatile uint32_t *addr;
  53794. + uint32_t val = simple_strtoul(buf, NULL, 16);
  53795. + //dev_dbg(_dev, "Offset=0x%08x Val=0x%08x\n", otg_dev->reg_offset, val);
  53796. + if (otg_dev->os_dep.reg_offset != 0xFFFFFFFF && 0 != otg_dev->os_dep.base) {
  53797. + /* Calculate the address */
  53798. + addr = (uint32_t *) (otg_dev->os_dep.reg_offset +
  53799. + (uint8_t *) otg_dev->os_dep.base);
  53800. + DWC_WRITE_REG32(addr, val);
  53801. + } else {
  53802. + dev_err(_dev, "Invalid Register Offset (0x%08x)\n",
  53803. + otg_dev->os_dep.reg_offset);
  53804. + }
  53805. + return count;
  53806. +}
  53807. +
  53808. +DEVICE_ATTR(regvalue, S_IRUGO | S_IWUSR, regvalue_show, regvalue_store);
  53809. +
  53810. +/*
  53811. + * Attributes
  53812. + */
  53813. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(mode, "Mode");
  53814. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hnpcapable, "HNPCapable");
  53815. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(srpcapable, "SRPCapable");
  53816. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hsic_connect, "HSIC Connect");
  53817. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(inv_sel_hsic, "Invert Select HSIC");
  53818. +
  53819. +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(buspower,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
  53820. +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(bussuspend,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
  53821. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(busconnected, "Bus Connected");
  53822. +
  53823. +DWC_OTG_DEVICE_ATTR_REG32_RW(gotgctl, 0, "GOTGCTL");
  53824. +DWC_OTG_DEVICE_ATTR_REG32_RW(gusbcfg,
  53825. + &(otg_dev->core_if->core_global_regs->gusbcfg),
  53826. + "GUSBCFG");
  53827. +DWC_OTG_DEVICE_ATTR_REG32_RW(grxfsiz,
  53828. + &(otg_dev->core_if->core_global_regs->grxfsiz),
  53829. + "GRXFSIZ");
  53830. +DWC_OTG_DEVICE_ATTR_REG32_RW(gnptxfsiz,
  53831. + &(otg_dev->core_if->core_global_regs->gnptxfsiz),
  53832. + "GNPTXFSIZ");
  53833. +DWC_OTG_DEVICE_ATTR_REG32_RW(gpvndctl,
  53834. + &(otg_dev->core_if->core_global_regs->gpvndctl),
  53835. + "GPVNDCTL");
  53836. +DWC_OTG_DEVICE_ATTR_REG32_RW(ggpio,
  53837. + &(otg_dev->core_if->core_global_regs->ggpio),
  53838. + "GGPIO");
  53839. +DWC_OTG_DEVICE_ATTR_REG32_RW(guid, &(otg_dev->core_if->core_global_regs->guid),
  53840. + "GUID");
  53841. +DWC_OTG_DEVICE_ATTR_REG32_RO(gsnpsid,
  53842. + &(otg_dev->core_if->core_global_regs->gsnpsid),
  53843. + "GSNPSID");
  53844. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(devspeed, "Device Speed");
  53845. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(enumspeed, "Device Enumeration Speed");
  53846. +
  53847. +DWC_OTG_DEVICE_ATTR_REG32_RO(hptxfsiz,
  53848. + &(otg_dev->core_if->core_global_regs->hptxfsiz),
  53849. + "HPTXFSIZ");
  53850. +DWC_OTG_DEVICE_ATTR_REG32_RW(hprt0, otg_dev->core_if->host_if->hprt0, "HPRT0");
  53851. +
  53852. +/**
  53853. + * @todo Add code to initiate the HNP.
  53854. + */
  53855. +/**
  53856. + * Show the HNP status bit
  53857. + */
  53858. +static ssize_t hnp_show(struct device *_dev,
  53859. + struct device_attribute *attr, char *buf)
  53860. +{
  53861. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53862. + return sprintf(buf, "HstNegScs = 0x%x\n",
  53863. + dwc_otg_get_hnpstatus(otg_dev->core_if));
  53864. +}
  53865. +
  53866. +/**
  53867. + * Set the HNP Request bit
  53868. + */
  53869. +static ssize_t hnp_store(struct device *_dev,
  53870. + struct device_attribute *attr,
  53871. + const char *buf, size_t count)
  53872. +{
  53873. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53874. + uint32_t in = simple_strtoul(buf, NULL, 16);
  53875. + dwc_otg_set_hnpreq(otg_dev->core_if, in);
  53876. + return count;
  53877. +}
  53878. +
  53879. +DEVICE_ATTR(hnp, 0644, hnp_show, hnp_store);
  53880. +
  53881. +/**
  53882. + * @todo Add code to initiate the SRP.
  53883. + */
  53884. +/**
  53885. + * Show the SRP status bit
  53886. + */
  53887. +static ssize_t srp_show(struct device *_dev,
  53888. + struct device_attribute *attr, char *buf)
  53889. +{
  53890. +#ifndef DWC_HOST_ONLY
  53891. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53892. + return sprintf(buf, "SesReqScs = 0x%x\n",
  53893. + dwc_otg_get_srpstatus(otg_dev->core_if));
  53894. +#else
  53895. + return sprintf(buf, "Host Only Mode!\n");
  53896. +#endif
  53897. +}
  53898. +
  53899. +/**
  53900. + * Set the SRP Request bit
  53901. + */
  53902. +static ssize_t srp_store(struct device *_dev,
  53903. + struct device_attribute *attr,
  53904. + const char *buf, size_t count)
  53905. +{
  53906. +#ifndef DWC_HOST_ONLY
  53907. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53908. + dwc_otg_pcd_initiate_srp(otg_dev->pcd);
  53909. +#endif
  53910. + return count;
  53911. +}
  53912. +
  53913. +DEVICE_ATTR(srp, 0644, srp_show, srp_store);
  53914. +
  53915. +/**
  53916. + * @todo Need to do more for power on/off?
  53917. + */
  53918. +/**
  53919. + * Show the Bus Power status
  53920. + */
  53921. +static ssize_t buspower_show(struct device *_dev,
  53922. + struct device_attribute *attr, char *buf)
  53923. +{
  53924. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53925. + return sprintf(buf, "Bus Power = 0x%x\n",
  53926. + dwc_otg_get_prtpower(otg_dev->core_if));
  53927. +}
  53928. +
  53929. +/**
  53930. + * Set the Bus Power status
  53931. + */
  53932. +static ssize_t buspower_store(struct device *_dev,
  53933. + struct device_attribute *attr,
  53934. + const char *buf, size_t count)
  53935. +{
  53936. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53937. + uint32_t on = simple_strtoul(buf, NULL, 16);
  53938. + dwc_otg_set_prtpower(otg_dev->core_if, on);
  53939. + return count;
  53940. +}
  53941. +
  53942. +DEVICE_ATTR(buspower, 0644, buspower_show, buspower_store);
  53943. +
  53944. +/**
  53945. + * @todo Need to do more for suspend?
  53946. + */
  53947. +/**
  53948. + * Show the Bus Suspend status
  53949. + */
  53950. +static ssize_t bussuspend_show(struct device *_dev,
  53951. + struct device_attribute *attr, char *buf)
  53952. +{
  53953. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53954. + return sprintf(buf, "Bus Suspend = 0x%x\n",
  53955. + dwc_otg_get_prtsuspend(otg_dev->core_if));
  53956. +}
  53957. +
  53958. +/**
  53959. + * Set the Bus Suspend status
  53960. + */
  53961. +static ssize_t bussuspend_store(struct device *_dev,
  53962. + struct device_attribute *attr,
  53963. + const char *buf, size_t count)
  53964. +{
  53965. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53966. + uint32_t in = simple_strtoul(buf, NULL, 16);
  53967. + dwc_otg_set_prtsuspend(otg_dev->core_if, in);
  53968. + return count;
  53969. +}
  53970. +
  53971. +DEVICE_ATTR(bussuspend, 0644, bussuspend_show, bussuspend_store);
  53972. +
  53973. +/**
  53974. + * Show the Mode Change Ready Timer status
  53975. + */
  53976. +static ssize_t mode_ch_tim_en_show(struct device *_dev,
  53977. + struct device_attribute *attr, char *buf)
  53978. +{
  53979. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53980. + return sprintf(buf, "Mode Change Ready Timer Enable = 0x%x\n",
  53981. + dwc_otg_get_mode_ch_tim(otg_dev->core_if));
  53982. +}
  53983. +
  53984. +/**
  53985. + * Set the Mode Change Ready Timer status
  53986. + */
  53987. +static ssize_t mode_ch_tim_en_store(struct device *_dev,
  53988. + struct device_attribute *attr,
  53989. + const char *buf, size_t count)
  53990. +{
  53991. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53992. + uint32_t in = simple_strtoul(buf, NULL, 16);
  53993. + dwc_otg_set_mode_ch_tim(otg_dev->core_if, in);
  53994. + return count;
  53995. +}
  53996. +
  53997. +DEVICE_ATTR(mode_ch_tim_en, 0644, mode_ch_tim_en_show, mode_ch_tim_en_store);
  53998. +
  53999. +/**
  54000. + * Show the value of HFIR Frame Interval bitfield
  54001. + */
  54002. +static ssize_t fr_interval_show(struct device *_dev,
  54003. + struct device_attribute *attr, char *buf)
  54004. +{
  54005. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  54006. + return sprintf(buf, "Frame Interval = 0x%x\n",
  54007. + dwc_otg_get_fr_interval(otg_dev->core_if));
  54008. +}
  54009. +
  54010. +/**
  54011. + * Set the HFIR Frame Interval value
  54012. + */
  54013. +static ssize_t fr_interval_store(struct device *_dev,
  54014. + struct device_attribute *attr,
  54015. + const char *buf, size_t count)
  54016. +{
  54017. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  54018. + uint32_t in = simple_strtoul(buf, NULL, 10);
  54019. + dwc_otg_set_fr_interval(otg_dev->core_if, in);
  54020. + return count;
  54021. +}
  54022. +
  54023. +DEVICE_ATTR(fr_interval, 0644, fr_interval_show, fr_interval_store);
  54024. +
  54025. +/**
  54026. + * Show the status of Remote Wakeup.
  54027. + */
  54028. +static ssize_t remote_wakeup_show(struct device *_dev,
  54029. + struct device_attribute *attr, char *buf)
  54030. +{
  54031. +#ifndef DWC_HOST_ONLY
  54032. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  54033. +
  54034. + return sprintf(buf,
  54035. + "Remote Wakeup Sig = %d Enabled = %d LPM Remote Wakeup = %d\n",
  54036. + dwc_otg_get_remotewakesig(otg_dev->core_if),
  54037. + dwc_otg_pcd_get_rmwkup_enable(otg_dev->pcd),
  54038. + dwc_otg_get_lpm_remotewakeenabled(otg_dev->core_if));
  54039. +#else
  54040. + return sprintf(buf, "Host Only Mode!\n");
  54041. +#endif /* DWC_HOST_ONLY */
  54042. +}
  54043. +
  54044. +/**
  54045. + * Initiate a remote wakeup of the host. The Device control register
  54046. + * Remote Wakeup Signal bit is written if the PCD Remote wakeup enable
  54047. + * flag is set.
  54048. + *
  54049. + */
  54050. +static ssize_t remote_wakeup_store(struct device *_dev,
  54051. + struct device_attribute *attr,
  54052. + const char *buf, size_t count)
  54053. +{
  54054. +#ifndef DWC_HOST_ONLY
  54055. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  54056. + uint32_t val = simple_strtoul(buf, NULL, 16);
  54057. +
  54058. + if (val & 1) {
  54059. + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 1);
  54060. + } else {
  54061. + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 0);
  54062. + }
  54063. +#endif /* DWC_HOST_ONLY */
  54064. + return count;
  54065. +}
  54066. +
  54067. +DEVICE_ATTR(remote_wakeup, S_IRUGO | S_IWUSR, remote_wakeup_show,
  54068. + remote_wakeup_store);
  54069. +
  54070. +/**
  54071. + * Show the whether core is hibernated or not.
  54072. + */
  54073. +static ssize_t rem_wakeup_pwrdn_show(struct device *_dev,
  54074. + struct device_attribute *attr, char *buf)
  54075. +{
  54076. +#ifndef DWC_HOST_ONLY
  54077. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  54078. +
  54079. + if (dwc_otg_get_core_state(otg_dev->core_if)) {
  54080. + DWC_PRINTF("Core is in hibernation\n");
  54081. + } else {
  54082. + DWC_PRINTF("Core is not in hibernation\n");
  54083. + }
  54084. +#endif /* DWC_HOST_ONLY */
  54085. + return 0;
  54086. +}
  54087. +
  54088. +extern int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  54089. + int rem_wakeup, int reset);
  54090. +
  54091. +/**
  54092. + * Initiate a remote wakeup of the device to exit from hibernation.
  54093. + */
  54094. +static ssize_t rem_wakeup_pwrdn_store(struct device *_dev,
  54095. + struct device_attribute *attr,
  54096. + const char *buf, size_t count)
  54097. +{
  54098. +#ifndef DWC_HOST_ONLY
  54099. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  54100. + dwc_otg_device_hibernation_restore(otg_dev->core_if, 1, 0);
  54101. +#endif
  54102. + return count;
  54103. +}
  54104. +
  54105. +DEVICE_ATTR(rem_wakeup_pwrdn, S_IRUGO | S_IWUSR, rem_wakeup_pwrdn_show,
  54106. + rem_wakeup_pwrdn_store);
  54107. +
  54108. +static ssize_t disconnect_us(struct device *_dev,
  54109. + struct device_attribute *attr,
  54110. + const char *buf, size_t count)
  54111. +{
  54112. +
  54113. +#ifndef DWC_HOST_ONLY
  54114. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  54115. + uint32_t val = simple_strtoul(buf, NULL, 16);
  54116. + DWC_PRINTF("The Passed value is %04x\n", val);
  54117. +
  54118. + dwc_otg_pcd_disconnect_us(otg_dev->pcd, 50);
  54119. +
  54120. +#endif /* DWC_HOST_ONLY */
  54121. + return count;
  54122. +}
  54123. +
  54124. +DEVICE_ATTR(disconnect_us, S_IWUSR, 0, disconnect_us);
  54125. +
  54126. +/**
  54127. + * Dump global registers and either host or device registers (depending on the
  54128. + * current mode of the core).
  54129. + */
  54130. +static ssize_t regdump_show(struct device *_dev,
  54131. + struct device_attribute *attr, char *buf)
  54132. +{
  54133. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  54134. +
  54135. + dwc_otg_dump_global_registers(otg_dev->core_if);
  54136. + if (dwc_otg_is_host_mode(otg_dev->core_if)) {
  54137. + dwc_otg_dump_host_registers(otg_dev->core_if);
  54138. + } else {
  54139. + dwc_otg_dump_dev_registers(otg_dev->core_if);
  54140. +
  54141. + }
  54142. + return sprintf(buf, "Register Dump\n");
  54143. +}
  54144. +
  54145. +DEVICE_ATTR(regdump, S_IRUGO, regdump_show, 0);
  54146. +
  54147. +/**
  54148. + * Dump global registers and either host or device registers (depending on the
  54149. + * current mode of the core).
  54150. + */
  54151. +static ssize_t spramdump_show(struct device *_dev,
  54152. + struct device_attribute *attr, char *buf)
  54153. +{
  54154. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  54155. +
  54156. + //dwc_otg_dump_spram(otg_dev->core_if);
  54157. +
  54158. + return sprintf(buf, "SPRAM Dump\n");
  54159. +}
  54160. +
  54161. +DEVICE_ATTR(spramdump, S_IRUGO, spramdump_show, 0);
  54162. +
  54163. +/**
  54164. + * Dump the current hcd state.
  54165. + */
  54166. +static ssize_t hcddump_show(struct device *_dev,
  54167. + struct device_attribute *attr, char *buf)
  54168. +{
  54169. +#ifndef DWC_DEVICE_ONLY
  54170. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  54171. + dwc_otg_hcd_dump_state(otg_dev->hcd);
  54172. +#endif /* DWC_DEVICE_ONLY */
  54173. + return sprintf(buf, "HCD Dump\n");
  54174. +}
  54175. +
  54176. +DEVICE_ATTR(hcddump, S_IRUGO, hcddump_show, 0);
  54177. +
  54178. +/**
  54179. + * Dump the average frame remaining at SOF. This can be used to
  54180. + * determine average interrupt latency. Frame remaining is also shown for
  54181. + * start transfer and two additional sample points.
  54182. + */
  54183. +static ssize_t hcd_frrem_show(struct device *_dev,
  54184. + struct device_attribute *attr, char *buf)
  54185. +{
  54186. +#ifndef DWC_DEVICE_ONLY
  54187. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  54188. +
  54189. + dwc_otg_hcd_dump_frrem(otg_dev->hcd);
  54190. +#endif /* DWC_DEVICE_ONLY */
  54191. + return sprintf(buf, "HCD Dump Frame Remaining\n");
  54192. +}
  54193. +
  54194. +DEVICE_ATTR(hcd_frrem, S_IRUGO, hcd_frrem_show, 0);
  54195. +
  54196. +/**
  54197. + * Displays the time required to read the GNPTXFSIZ register many times (the
  54198. + * output shows the number of times the register is read).
  54199. + */
  54200. +#define RW_REG_COUNT 10000000
  54201. +#define MSEC_PER_JIFFIE 1000/HZ
  54202. +static ssize_t rd_reg_test_show(struct device *_dev,
  54203. + struct device_attribute *attr, char *buf)
  54204. +{
  54205. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  54206. + int i;
  54207. + int time;
  54208. + int start_jiffies;
  54209. +
  54210. + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
  54211. + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
  54212. + start_jiffies = jiffies;
  54213. + for (i = 0; i < RW_REG_COUNT; i++) {
  54214. + dwc_otg_get_gnptxfsiz(otg_dev->core_if);
  54215. + }
  54216. + time = jiffies - start_jiffies;
  54217. + return sprintf(buf,
  54218. + "Time to read GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
  54219. + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
  54220. +}
  54221. +
  54222. +DEVICE_ATTR(rd_reg_test, S_IRUGO, rd_reg_test_show, 0);
  54223. +
  54224. +/**
  54225. + * Displays the time required to write the GNPTXFSIZ register many times (the
  54226. + * output shows the number of times the register is written).
  54227. + */
  54228. +static ssize_t wr_reg_test_show(struct device *_dev,
  54229. + struct device_attribute *attr, char *buf)
  54230. +{
  54231. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  54232. + uint32_t reg_val;
  54233. + int i;
  54234. + int time;
  54235. + int start_jiffies;
  54236. +
  54237. + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
  54238. + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
  54239. + reg_val = dwc_otg_get_gnptxfsiz(otg_dev->core_if);
  54240. + start_jiffies = jiffies;
  54241. + for (i = 0; i < RW_REG_COUNT; i++) {
  54242. + dwc_otg_set_gnptxfsiz(otg_dev->core_if, reg_val);
  54243. + }
  54244. + time = jiffies - start_jiffies;
  54245. + return sprintf(buf,
  54246. + "Time to write GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
  54247. + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
  54248. +}
  54249. +
  54250. +DEVICE_ATTR(wr_reg_test, S_IRUGO, wr_reg_test_show, 0);
  54251. +
  54252. +#ifdef CONFIG_USB_DWC_OTG_LPM
  54253. +
  54254. +/**
  54255. +* Show the lpm_response attribute.
  54256. +*/
  54257. +static ssize_t lpmresp_show(struct device *_dev,
  54258. + struct device_attribute *attr, char *buf)
  54259. +{
  54260. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  54261. +
  54262. + if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if))
  54263. + return sprintf(buf, "** LPM is DISABLED **\n");
  54264. +
  54265. + if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
  54266. + return sprintf(buf, "** Current mode is not device mode\n");
  54267. + }
  54268. + return sprintf(buf, "lpm_response = %d\n",
  54269. + dwc_otg_get_lpmresponse(otg_dev->core_if));
  54270. +}
  54271. +
  54272. +/**
  54273. +* Store the lpm_response attribute.
  54274. +*/
  54275. +static ssize_t lpmresp_store(struct device *_dev,
  54276. + struct device_attribute *attr,
  54277. + const char *buf, size_t count)
  54278. +{
  54279. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  54280. + uint32_t val = simple_strtoul(buf, NULL, 16);
  54281. +
  54282. + if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if)) {
  54283. + return 0;
  54284. + }
  54285. +
  54286. + if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
  54287. + return 0;
  54288. + }
  54289. +
  54290. + dwc_otg_set_lpmresponse(otg_dev->core_if, val);
  54291. + return count;
  54292. +}
  54293. +
  54294. +DEVICE_ATTR(lpm_response, S_IRUGO | S_IWUSR, lpmresp_show, lpmresp_store);
  54295. +
  54296. +/**
  54297. +* Show the sleep_status attribute.
  54298. +*/
  54299. +static ssize_t sleepstatus_show(struct device *_dev,
  54300. + struct device_attribute *attr, char *buf)
  54301. +{
  54302. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  54303. + return sprintf(buf, "Sleep Status = %d\n",
  54304. + dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if));
  54305. +}
  54306. +
  54307. +/**
  54308. + * Store the sleep_status attribure.
  54309. + */
  54310. +static ssize_t sleepstatus_store(struct device *_dev,
  54311. + struct device_attribute *attr,
  54312. + const char *buf, size_t count)
  54313. +{
  54314. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  54315. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  54316. +
  54317. + if (dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if)) {
  54318. + if (dwc_otg_is_host_mode(core_if)) {
  54319. +
  54320. + DWC_PRINTF("Host initiated resume\n");
  54321. + dwc_otg_set_prtresume(otg_dev->core_if, 1);
  54322. + }
  54323. + }
  54324. +
  54325. + return count;
  54326. +}
  54327. +
  54328. +DEVICE_ATTR(sleep_status, S_IRUGO | S_IWUSR, sleepstatus_show,
  54329. + sleepstatus_store);
  54330. +
  54331. +#endif /* CONFIG_USB_DWC_OTG_LPM_ENABLE */
  54332. +
  54333. +/**@}*/
  54334. +
  54335. +/**
  54336. + * Create the device files
  54337. + */
  54338. +void dwc_otg_attr_create(
  54339. +#ifdef LM_INTERFACE
  54340. + struct lm_device *dev
  54341. +#elif defined(PCI_INTERFACE)
  54342. + struct pci_dev *dev
  54343. +#elif defined(PLATFORM_INTERFACE)
  54344. + struct platform_device *dev
  54345. +#endif
  54346. + )
  54347. +{
  54348. + int error;
  54349. +
  54350. + error = device_create_file(&dev->dev, &dev_attr_regoffset);
  54351. + error = device_create_file(&dev->dev, &dev_attr_regvalue);
  54352. + error = device_create_file(&dev->dev, &dev_attr_mode);
  54353. + error = device_create_file(&dev->dev, &dev_attr_hnpcapable);
  54354. + error = device_create_file(&dev->dev, &dev_attr_srpcapable);
  54355. + error = device_create_file(&dev->dev, &dev_attr_hsic_connect);
  54356. + error = device_create_file(&dev->dev, &dev_attr_inv_sel_hsic);
  54357. + error = device_create_file(&dev->dev, &dev_attr_hnp);
  54358. + error = device_create_file(&dev->dev, &dev_attr_srp);
  54359. + error = device_create_file(&dev->dev, &dev_attr_buspower);
  54360. + error = device_create_file(&dev->dev, &dev_attr_bussuspend);
  54361. + error = device_create_file(&dev->dev, &dev_attr_mode_ch_tim_en);
  54362. + error = device_create_file(&dev->dev, &dev_attr_fr_interval);
  54363. + error = device_create_file(&dev->dev, &dev_attr_busconnected);
  54364. + error = device_create_file(&dev->dev, &dev_attr_gotgctl);
  54365. + error = device_create_file(&dev->dev, &dev_attr_gusbcfg);
  54366. + error = device_create_file(&dev->dev, &dev_attr_grxfsiz);
  54367. + error = device_create_file(&dev->dev, &dev_attr_gnptxfsiz);
  54368. + error = device_create_file(&dev->dev, &dev_attr_gpvndctl);
  54369. + error = device_create_file(&dev->dev, &dev_attr_ggpio);
  54370. + error = device_create_file(&dev->dev, &dev_attr_guid);
  54371. + error = device_create_file(&dev->dev, &dev_attr_gsnpsid);
  54372. + error = device_create_file(&dev->dev, &dev_attr_devspeed);
  54373. + error = device_create_file(&dev->dev, &dev_attr_enumspeed);
  54374. + error = device_create_file(&dev->dev, &dev_attr_hptxfsiz);
  54375. + error = device_create_file(&dev->dev, &dev_attr_hprt0);
  54376. + error = device_create_file(&dev->dev, &dev_attr_remote_wakeup);
  54377. + error = device_create_file(&dev->dev, &dev_attr_rem_wakeup_pwrdn);
  54378. + error = device_create_file(&dev->dev, &dev_attr_disconnect_us);
  54379. + error = device_create_file(&dev->dev, &dev_attr_regdump);
  54380. + error = device_create_file(&dev->dev, &dev_attr_spramdump);
  54381. + error = device_create_file(&dev->dev, &dev_attr_hcddump);
  54382. + error = device_create_file(&dev->dev, &dev_attr_hcd_frrem);
  54383. + error = device_create_file(&dev->dev, &dev_attr_rd_reg_test);
  54384. + error = device_create_file(&dev->dev, &dev_attr_wr_reg_test);
  54385. +#ifdef CONFIG_USB_DWC_OTG_LPM
  54386. + error = device_create_file(&dev->dev, &dev_attr_lpm_response);
  54387. + error = device_create_file(&dev->dev, &dev_attr_sleep_status);
  54388. +#endif
  54389. +}
  54390. +
  54391. +/**
  54392. + * Remove the device files
  54393. + */
  54394. +void dwc_otg_attr_remove(
  54395. +#ifdef LM_INTERFACE
  54396. + struct lm_device *dev
  54397. +#elif defined(PCI_INTERFACE)
  54398. + struct pci_dev *dev
  54399. +#elif defined(PLATFORM_INTERFACE)
  54400. + struct platform_device *dev
  54401. +#endif
  54402. + )
  54403. +{
  54404. + device_remove_file(&dev->dev, &dev_attr_regoffset);
  54405. + device_remove_file(&dev->dev, &dev_attr_regvalue);
  54406. + device_remove_file(&dev->dev, &dev_attr_mode);
  54407. + device_remove_file(&dev->dev, &dev_attr_hnpcapable);
  54408. + device_remove_file(&dev->dev, &dev_attr_srpcapable);
  54409. + device_remove_file(&dev->dev, &dev_attr_hsic_connect);
  54410. + device_remove_file(&dev->dev, &dev_attr_inv_sel_hsic);
  54411. + device_remove_file(&dev->dev, &dev_attr_hnp);
  54412. + device_remove_file(&dev->dev, &dev_attr_srp);
  54413. + device_remove_file(&dev->dev, &dev_attr_buspower);
  54414. + device_remove_file(&dev->dev, &dev_attr_bussuspend);
  54415. + device_remove_file(&dev->dev, &dev_attr_mode_ch_tim_en);
  54416. + device_remove_file(&dev->dev, &dev_attr_fr_interval);
  54417. + device_remove_file(&dev->dev, &dev_attr_busconnected);
  54418. + device_remove_file(&dev->dev, &dev_attr_gotgctl);
  54419. + device_remove_file(&dev->dev, &dev_attr_gusbcfg);
  54420. + device_remove_file(&dev->dev, &dev_attr_grxfsiz);
  54421. + device_remove_file(&dev->dev, &dev_attr_gnptxfsiz);
  54422. + device_remove_file(&dev->dev, &dev_attr_gpvndctl);
  54423. + device_remove_file(&dev->dev, &dev_attr_ggpio);
  54424. + device_remove_file(&dev->dev, &dev_attr_guid);
  54425. + device_remove_file(&dev->dev, &dev_attr_gsnpsid);
  54426. + device_remove_file(&dev->dev, &dev_attr_devspeed);
  54427. + device_remove_file(&dev->dev, &dev_attr_enumspeed);
  54428. + device_remove_file(&dev->dev, &dev_attr_hptxfsiz);
  54429. + device_remove_file(&dev->dev, &dev_attr_hprt0);
  54430. + device_remove_file(&dev->dev, &dev_attr_remote_wakeup);
  54431. + device_remove_file(&dev->dev, &dev_attr_rem_wakeup_pwrdn);
  54432. + device_remove_file(&dev->dev, &dev_attr_disconnect_us);
  54433. + device_remove_file(&dev->dev, &dev_attr_regdump);
  54434. + device_remove_file(&dev->dev, &dev_attr_spramdump);
  54435. + device_remove_file(&dev->dev, &dev_attr_hcddump);
  54436. + device_remove_file(&dev->dev, &dev_attr_hcd_frrem);
  54437. + device_remove_file(&dev->dev, &dev_attr_rd_reg_test);
  54438. + device_remove_file(&dev->dev, &dev_attr_wr_reg_test);
  54439. +#ifdef CONFIG_USB_DWC_OTG_LPM
  54440. + device_remove_file(&dev->dev, &dev_attr_lpm_response);
  54441. + device_remove_file(&dev->dev, &dev_attr_sleep_status);
  54442. +#endif
  54443. +}
  54444. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_attr.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_attr.h
  54445. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_attr.h 1970-01-01 01:00:00.000000000 +0100
  54446. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_attr.h 2014-07-07 10:45:43.000000000 +0200
  54447. @@ -0,0 +1,89 @@
  54448. +/* ==========================================================================
  54449. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.h $
  54450. + * $Revision: #13 $
  54451. + * $Date: 2010/06/21 $
  54452. + * $Change: 1532021 $
  54453. + *
  54454. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  54455. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  54456. + * otherwise expressly agreed to in writing between Synopsys and you.
  54457. + *
  54458. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  54459. + * any End User Software License Agreement or Agreement for Licensed Product
  54460. + * with Synopsys or any supplement thereto. You are permitted to use and
  54461. + * redistribute this Software in source and binary forms, with or without
  54462. + * modification, provided that redistributions of source code must retain this
  54463. + * notice. You may not view, use, disclose, copy or distribute this file or
  54464. + * any information contained herein except pursuant to this license grant from
  54465. + * Synopsys. If you do not agree with this notice, including the disclaimer
  54466. + * below, then you are not authorized to use the Software.
  54467. + *
  54468. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  54469. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  54470. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  54471. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  54472. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  54473. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  54474. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  54475. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  54476. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  54477. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  54478. + * DAMAGE.
  54479. + * ========================================================================== */
  54480. +
  54481. +#if !defined(__DWC_OTG_ATTR_H__)
  54482. +#define __DWC_OTG_ATTR_H__
  54483. +
  54484. +/** @file
  54485. + * This file contains the interface to the Linux device attributes.
  54486. + */
  54487. +extern struct device_attribute dev_attr_regoffset;
  54488. +extern struct device_attribute dev_attr_regvalue;
  54489. +
  54490. +extern struct device_attribute dev_attr_mode;
  54491. +extern struct device_attribute dev_attr_hnpcapable;
  54492. +extern struct device_attribute dev_attr_srpcapable;
  54493. +extern struct device_attribute dev_attr_hnp;
  54494. +extern struct device_attribute dev_attr_srp;
  54495. +extern struct device_attribute dev_attr_buspower;
  54496. +extern struct device_attribute dev_attr_bussuspend;
  54497. +extern struct device_attribute dev_attr_mode_ch_tim_en;
  54498. +extern struct device_attribute dev_attr_fr_interval;
  54499. +extern struct device_attribute dev_attr_busconnected;
  54500. +extern struct device_attribute dev_attr_gotgctl;
  54501. +extern struct device_attribute dev_attr_gusbcfg;
  54502. +extern struct device_attribute dev_attr_grxfsiz;
  54503. +extern struct device_attribute dev_attr_gnptxfsiz;
  54504. +extern struct device_attribute dev_attr_gpvndctl;
  54505. +extern struct device_attribute dev_attr_ggpio;
  54506. +extern struct device_attribute dev_attr_guid;
  54507. +extern struct device_attribute dev_attr_gsnpsid;
  54508. +extern struct device_attribute dev_attr_devspeed;
  54509. +extern struct device_attribute dev_attr_enumspeed;
  54510. +extern struct device_attribute dev_attr_hptxfsiz;
  54511. +extern struct device_attribute dev_attr_hprt0;
  54512. +#ifdef CONFIG_USB_DWC_OTG_LPM
  54513. +extern struct device_attribute dev_attr_lpm_response;
  54514. +extern struct device_attribute devi_attr_sleep_status;
  54515. +#endif
  54516. +
  54517. +void dwc_otg_attr_create(
  54518. +#ifdef LM_INTERFACE
  54519. + struct lm_device *dev
  54520. +#elif defined(PCI_INTERFACE)
  54521. + struct pci_dev *dev
  54522. +#elif defined(PLATFORM_INTERFACE)
  54523. + struct platform_device *dev
  54524. +#endif
  54525. + );
  54526. +
  54527. +void dwc_otg_attr_remove(
  54528. +#ifdef LM_INTERFACE
  54529. + struct lm_device *dev
  54530. +#elif defined(PCI_INTERFACE)
  54531. + struct pci_dev *dev
  54532. +#elif defined(PLATFORM_INTERFACE)
  54533. + struct platform_device *dev
  54534. +#endif
  54535. + );
  54536. +#endif
  54537. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_cfi.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cfi.c
  54538. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_cfi.c 1970-01-01 01:00:00.000000000 +0100
  54539. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cfi.c 2014-07-07 10:45:43.000000000 +0200
  54540. @@ -0,0 +1,1876 @@
  54541. +/* ==========================================================================
  54542. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  54543. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  54544. + * otherwise expressly agreed to in writing between Synopsys and you.
  54545. + *
  54546. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  54547. + * any End User Software License Agreement or Agreement for Licensed Product
  54548. + * with Synopsys or any supplement thereto. You are permitted to use and
  54549. + * redistribute this Software in source and binary forms, with or without
  54550. + * modification, provided that redistributions of source code must retain this
  54551. + * notice. You may not view, use, disclose, copy or distribute this file or
  54552. + * any information contained herein except pursuant to this license grant from
  54553. + * Synopsys. If you do not agree with this notice, including the disclaimer
  54554. + * below, then you are not authorized to use the Software.
  54555. + *
  54556. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  54557. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  54558. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  54559. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  54560. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  54561. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  54562. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  54563. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  54564. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  54565. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  54566. + * DAMAGE.
  54567. + * ========================================================================== */
  54568. +
  54569. +/** @file
  54570. + *
  54571. + * This file contains the most of the CFI(Core Feature Interface)
  54572. + * implementation for the OTG.
  54573. + */
  54574. +
  54575. +#ifdef DWC_UTE_CFI
  54576. +
  54577. +#include "dwc_otg_pcd.h"
  54578. +#include "dwc_otg_cfi.h"
  54579. +
  54580. +/** This definition should actually migrate to the Portability Library */
  54581. +#define DWC_CONSTANT_CPU_TO_LE16(x) (x)
  54582. +
  54583. +extern dwc_otg_pcd_ep_t *get_ep_by_addr(dwc_otg_pcd_t * pcd, u16 wIndex);
  54584. +
  54585. +static int cfi_core_features_buf(uint8_t * buf, uint16_t buflen);
  54586. +static int cfi_get_feature_value(uint8_t * buf, uint16_t buflen,
  54587. + struct dwc_otg_pcd *pcd,
  54588. + struct cfi_usb_ctrlrequest *ctrl_req);
  54589. +static int cfi_set_feature_value(struct dwc_otg_pcd *pcd);
  54590. +static int cfi_ep_get_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  54591. + struct cfi_usb_ctrlrequest *req);
  54592. +static int cfi_ep_get_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  54593. + struct cfi_usb_ctrlrequest *req);
  54594. +static int cfi_ep_get_align_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  54595. + struct cfi_usb_ctrlrequest *req);
  54596. +static int cfi_preproc_reset(struct dwc_otg_pcd *pcd,
  54597. + struct cfi_usb_ctrlrequest *req);
  54598. +static void cfi_free_ep_bs_dyn_data(cfi_ep_t * cfiep);
  54599. +
  54600. +static uint16_t get_dfifo_size(dwc_otg_core_if_t * core_if);
  54601. +static int32_t get_rxfifo_size(dwc_otg_core_if_t * core_if, uint16_t wValue);
  54602. +static int32_t get_txfifo_size(struct dwc_otg_pcd *pcd, uint16_t wValue);
  54603. +
  54604. +static uint8_t resize_fifos(dwc_otg_core_if_t * core_if);
  54605. +
  54606. +/** This is the header of the all features descriptor */
  54607. +static cfi_all_features_header_t all_props_desc_header = {
  54608. + .wVersion = DWC_CONSTANT_CPU_TO_LE16(0x100),
  54609. + .wCoreID = DWC_CONSTANT_CPU_TO_LE16(CFI_CORE_ID_OTG),
  54610. + .wNumFeatures = DWC_CONSTANT_CPU_TO_LE16(9),
  54611. +};
  54612. +
  54613. +/** This is an array of statically allocated feature descriptors */
  54614. +static cfi_feature_desc_header_t prop_descs[] = {
  54615. +
  54616. + /* FT_ID_DMA_MODE */
  54617. + {
  54618. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_MODE),
  54619. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  54620. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(1),
  54621. + },
  54622. +
  54623. + /* FT_ID_DMA_BUFFER_SETUP */
  54624. + {
  54625. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_BUFFER_SETUP),
  54626. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  54627. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  54628. + },
  54629. +
  54630. + /* FT_ID_DMA_BUFF_ALIGN */
  54631. + {
  54632. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_BUFF_ALIGN),
  54633. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  54634. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  54635. + },
  54636. +
  54637. + /* FT_ID_DMA_CONCAT_SETUP */
  54638. + {
  54639. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_CONCAT_SETUP),
  54640. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  54641. + //.wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  54642. + },
  54643. +
  54644. + /* FT_ID_DMA_CIRCULAR */
  54645. + {
  54646. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_CIRCULAR),
  54647. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  54648. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  54649. + },
  54650. +
  54651. + /* FT_ID_THRESHOLD_SETUP */
  54652. + {
  54653. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_THRESHOLD_SETUP),
  54654. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  54655. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  54656. + },
  54657. +
  54658. + /* FT_ID_DFIFO_DEPTH */
  54659. + {
  54660. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DFIFO_DEPTH),
  54661. + .bmAttributes = CFI_FEATURE_ATTR_RO,
  54662. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  54663. + },
  54664. +
  54665. + /* FT_ID_TX_FIFO_DEPTH */
  54666. + {
  54667. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_TX_FIFO_DEPTH),
  54668. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  54669. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  54670. + },
  54671. +
  54672. + /* FT_ID_RX_FIFO_DEPTH */
  54673. + {
  54674. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_RX_FIFO_DEPTH),
  54675. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  54676. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  54677. + }
  54678. +};
  54679. +
  54680. +/** The table of feature names */
  54681. +cfi_string_t prop_name_table[] = {
  54682. + {FT_ID_DMA_MODE, "dma_mode"},
  54683. + {FT_ID_DMA_BUFFER_SETUP, "buffer_setup"},
  54684. + {FT_ID_DMA_BUFF_ALIGN, "buffer_align"},
  54685. + {FT_ID_DMA_CONCAT_SETUP, "concat_setup"},
  54686. + {FT_ID_DMA_CIRCULAR, "buffer_circular"},
  54687. + {FT_ID_THRESHOLD_SETUP, "threshold_setup"},
  54688. + {FT_ID_DFIFO_DEPTH, "dfifo_depth"},
  54689. + {FT_ID_TX_FIFO_DEPTH, "txfifo_depth"},
  54690. + {FT_ID_RX_FIFO_DEPTH, "rxfifo_depth"},
  54691. + {}
  54692. +};
  54693. +
  54694. +/************************************************************************/
  54695. +
  54696. +/**
  54697. + * Returns the name of the feature by its ID
  54698. + * or NULL if no featute ID matches.
  54699. + *
  54700. + */
  54701. +const uint8_t *get_prop_name(uint16_t prop_id, int *len)
  54702. +{
  54703. + cfi_string_t *pstr;
  54704. + *len = 0;
  54705. +
  54706. + for (pstr = prop_name_table; pstr && pstr->s; pstr++) {
  54707. + if (pstr->id == prop_id) {
  54708. + *len = DWC_STRLEN(pstr->s);
  54709. + return pstr->s;
  54710. + }
  54711. + }
  54712. + return NULL;
  54713. +}
  54714. +
  54715. +/**
  54716. + * This function handles all CFI specific control requests.
  54717. + *
  54718. + * Return a negative value to stall the DCE.
  54719. + */
  54720. +int cfi_setup(struct dwc_otg_pcd *pcd, struct cfi_usb_ctrlrequest *ctrl)
  54721. +{
  54722. + int retval = 0;
  54723. + dwc_otg_pcd_ep_t *ep = NULL;
  54724. + cfiobject_t *cfi = pcd->cfi;
  54725. + struct dwc_otg_core_if *coreif = GET_CORE_IF(pcd);
  54726. + uint16_t wLen = DWC_LE16_TO_CPU(&ctrl->wLength);
  54727. + uint16_t wValue = DWC_LE16_TO_CPU(&ctrl->wValue);
  54728. + uint16_t wIndex = DWC_LE16_TO_CPU(&ctrl->wIndex);
  54729. + uint32_t regaddr = 0;
  54730. + uint32_t regval = 0;
  54731. +
  54732. + /* Save this Control Request in the CFI object.
  54733. + * The data field will be assigned in the data stage completion CB function.
  54734. + */
  54735. + cfi->ctrl_req = *ctrl;
  54736. + cfi->ctrl_req.data = NULL;
  54737. +
  54738. + cfi->need_gadget_att = 0;
  54739. + cfi->need_status_in_complete = 0;
  54740. +
  54741. + switch (ctrl->bRequest) {
  54742. + case VEN_CORE_GET_FEATURES:
  54743. + retval = cfi_core_features_buf(cfi->buf_in.buf, CFI_IN_BUF_LEN);
  54744. + if (retval >= 0) {
  54745. + //dump_msg(cfi->buf_in.buf, retval);
  54746. + ep = &pcd->ep0;
  54747. +
  54748. + retval = min((uint16_t) retval, wLen);
  54749. + /* Transfer this buffer to the host through the EP0-IN EP */
  54750. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  54751. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  54752. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  54753. + ep->dwc_ep.xfer_len = retval;
  54754. + ep->dwc_ep.xfer_count = 0;
  54755. + ep->dwc_ep.sent_zlp = 0;
  54756. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  54757. +
  54758. + pcd->ep0_pending = 1;
  54759. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  54760. + }
  54761. + retval = 0;
  54762. + break;
  54763. +
  54764. + case VEN_CORE_GET_FEATURE:
  54765. + CFI_INFO("VEN_CORE_GET_FEATURE\n");
  54766. + retval = cfi_get_feature_value(cfi->buf_in.buf, CFI_IN_BUF_LEN,
  54767. + pcd, ctrl);
  54768. + if (retval >= 0) {
  54769. + ep = &pcd->ep0;
  54770. +
  54771. + retval = min((uint16_t) retval, wLen);
  54772. + /* Transfer this buffer to the host through the EP0-IN EP */
  54773. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  54774. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  54775. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  54776. + ep->dwc_ep.xfer_len = retval;
  54777. + ep->dwc_ep.xfer_count = 0;
  54778. + ep->dwc_ep.sent_zlp = 0;
  54779. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  54780. +
  54781. + pcd->ep0_pending = 1;
  54782. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  54783. + }
  54784. + CFI_INFO("VEN_CORE_GET_FEATURE=%d\n", retval);
  54785. + dump_msg(cfi->buf_in.buf, retval);
  54786. + break;
  54787. +
  54788. + case VEN_CORE_SET_FEATURE:
  54789. + CFI_INFO("VEN_CORE_SET_FEATURE\n");
  54790. + /* Set up an XFER to get the data stage of the control request,
  54791. + * which is the new value of the feature to be modified.
  54792. + */
  54793. + ep = &pcd->ep0;
  54794. + ep->dwc_ep.is_in = 0;
  54795. + ep->dwc_ep.dma_addr = cfi->buf_out.addr;
  54796. + ep->dwc_ep.start_xfer_buff = cfi->buf_out.buf;
  54797. + ep->dwc_ep.xfer_buff = cfi->buf_out.buf;
  54798. + ep->dwc_ep.xfer_len = wLen;
  54799. + ep->dwc_ep.xfer_count = 0;
  54800. + ep->dwc_ep.sent_zlp = 0;
  54801. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  54802. +
  54803. + pcd->ep0_pending = 1;
  54804. + /* Read the control write's data stage */
  54805. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  54806. + retval = 0;
  54807. + break;
  54808. +
  54809. + case VEN_CORE_RESET_FEATURES:
  54810. + CFI_INFO("VEN_CORE_RESET_FEATURES\n");
  54811. + cfi->need_gadget_att = 1;
  54812. + cfi->need_status_in_complete = 1;
  54813. + retval = cfi_preproc_reset(pcd, ctrl);
  54814. + CFI_INFO("VEN_CORE_RESET_FEATURES = (%d)\n", retval);
  54815. + break;
  54816. +
  54817. + case VEN_CORE_ACTIVATE_FEATURES:
  54818. + CFI_INFO("VEN_CORE_ACTIVATE_FEATURES\n");
  54819. + break;
  54820. +
  54821. + case VEN_CORE_READ_REGISTER:
  54822. + CFI_INFO("VEN_CORE_READ_REGISTER\n");
  54823. + /* wValue optionally contains the HI WORD of the register offset and
  54824. + * wIndex contains the LOW WORD of the register offset
  54825. + */
  54826. + if (wValue == 0) {
  54827. + /* @TODO - MAS - fix the access to the base field */
  54828. + regaddr = 0;
  54829. + //regaddr = (uint32_t) pcd->otg_dev->os_dep.base;
  54830. + //GET_CORE_IF(pcd)->co
  54831. + regaddr |= wIndex;
  54832. + } else {
  54833. + regaddr = (wValue << 16) | wIndex;
  54834. + }
  54835. +
  54836. + /* Read a 32-bit value of the memory at the regaddr */
  54837. + regval = DWC_READ_REG32((uint32_t *) regaddr);
  54838. +
  54839. + ep = &pcd->ep0;
  54840. + dwc_memcpy(cfi->buf_in.buf, &regval, sizeof(uint32_t));
  54841. + ep->dwc_ep.is_in = 1;
  54842. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  54843. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  54844. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  54845. + ep->dwc_ep.xfer_len = wLen;
  54846. + ep->dwc_ep.xfer_count = 0;
  54847. + ep->dwc_ep.sent_zlp = 0;
  54848. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  54849. +
  54850. + pcd->ep0_pending = 1;
  54851. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  54852. + cfi->need_gadget_att = 0;
  54853. + retval = 0;
  54854. + break;
  54855. +
  54856. + case VEN_CORE_WRITE_REGISTER:
  54857. + CFI_INFO("VEN_CORE_WRITE_REGISTER\n");
  54858. + /* Set up an XFER to get the data stage of the control request,
  54859. + * which is the new value of the register to be modified.
  54860. + */
  54861. + ep = &pcd->ep0;
  54862. + ep->dwc_ep.is_in = 0;
  54863. + ep->dwc_ep.dma_addr = cfi->buf_out.addr;
  54864. + ep->dwc_ep.start_xfer_buff = cfi->buf_out.buf;
  54865. + ep->dwc_ep.xfer_buff = cfi->buf_out.buf;
  54866. + ep->dwc_ep.xfer_len = wLen;
  54867. + ep->dwc_ep.xfer_count = 0;
  54868. + ep->dwc_ep.sent_zlp = 0;
  54869. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  54870. +
  54871. + pcd->ep0_pending = 1;
  54872. + /* Read the control write's data stage */
  54873. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  54874. + retval = 0;
  54875. + break;
  54876. +
  54877. + default:
  54878. + retval = -DWC_E_NOT_SUPPORTED;
  54879. + break;
  54880. + }
  54881. +
  54882. + return retval;
  54883. +}
  54884. +
  54885. +/**
  54886. + * This function prepares the core features descriptors and copies its
  54887. + * raw representation into the buffer <buf>.
  54888. + *
  54889. + * The buffer structure is as follows:
  54890. + * all_features_header (8 bytes)
  54891. + * features_#1 (8 bytes + feature name string length)
  54892. + * features_#2 (8 bytes + feature name string length)
  54893. + * .....
  54894. + * features_#n - where n=the total count of feature descriptors
  54895. + */
  54896. +static int cfi_core_features_buf(uint8_t * buf, uint16_t buflen)
  54897. +{
  54898. + cfi_feature_desc_header_t *prop_hdr = prop_descs;
  54899. + cfi_feature_desc_header_t *prop;
  54900. + cfi_all_features_header_t *all_props_hdr = &all_props_desc_header;
  54901. + cfi_all_features_header_t *tmp;
  54902. + uint8_t *tmpbuf = buf;
  54903. + const uint8_t *pname = NULL;
  54904. + int i, j, namelen = 0, totlen;
  54905. +
  54906. + /* Prepare and copy the core features into the buffer */
  54907. + CFI_INFO("%s:\n", __func__);
  54908. +
  54909. + tmp = (cfi_all_features_header_t *) tmpbuf;
  54910. + *tmp = *all_props_hdr;
  54911. + tmpbuf += CFI_ALL_FEATURES_HDR_LEN;
  54912. +
  54913. + j = sizeof(prop_descs) / sizeof(cfi_all_features_header_t);
  54914. + for (i = 0; i < j; i++, prop_hdr++) {
  54915. + pname = get_prop_name(prop_hdr->wFeatureID, &namelen);
  54916. + prop = (cfi_feature_desc_header_t *) tmpbuf;
  54917. + *prop = *prop_hdr;
  54918. +
  54919. + prop->bNameLen = namelen;
  54920. + prop->wLength =
  54921. + DWC_CONSTANT_CPU_TO_LE16(CFI_FEATURE_DESC_HDR_LEN +
  54922. + namelen);
  54923. +
  54924. + tmpbuf += CFI_FEATURE_DESC_HDR_LEN;
  54925. + dwc_memcpy(tmpbuf, pname, namelen);
  54926. + tmpbuf += namelen;
  54927. + }
  54928. +
  54929. + totlen = tmpbuf - buf;
  54930. +
  54931. + if (totlen > 0) {
  54932. + tmp = (cfi_all_features_header_t *) buf;
  54933. + tmp->wTotalLen = DWC_CONSTANT_CPU_TO_LE16(totlen);
  54934. + }
  54935. +
  54936. + return totlen;
  54937. +}
  54938. +
  54939. +/**
  54940. + * This function releases all the dynamic memory in the CFI object.
  54941. + */
  54942. +static void cfi_release(cfiobject_t * cfiobj)
  54943. +{
  54944. + cfi_ep_t *cfiep;
  54945. + dwc_list_link_t *tmp;
  54946. +
  54947. + CFI_INFO("%s\n", __func__);
  54948. +
  54949. + if (cfiobj->buf_in.buf) {
  54950. + DWC_DMA_FREE(CFI_IN_BUF_LEN, cfiobj->buf_in.buf,
  54951. + cfiobj->buf_in.addr);
  54952. + cfiobj->buf_in.buf = NULL;
  54953. + }
  54954. +
  54955. + if (cfiobj->buf_out.buf) {
  54956. + DWC_DMA_FREE(CFI_OUT_BUF_LEN, cfiobj->buf_out.buf,
  54957. + cfiobj->buf_out.addr);
  54958. + cfiobj->buf_out.buf = NULL;
  54959. + }
  54960. +
  54961. + /* Free the Buffer Setup values for each EP */
  54962. + //list_for_each_entry(cfiep, &cfiobj->active_eps, lh) {
  54963. + DWC_LIST_FOREACH(tmp, &cfiobj->active_eps) {
  54964. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  54965. + cfi_free_ep_bs_dyn_data(cfiep);
  54966. + }
  54967. +}
  54968. +
  54969. +/**
  54970. + * This function frees the dynamically allocated EP buffer setup data.
  54971. + */
  54972. +static void cfi_free_ep_bs_dyn_data(cfi_ep_t * cfiep)
  54973. +{
  54974. + if (cfiep->bm_sg) {
  54975. + DWC_FREE(cfiep->bm_sg);
  54976. + cfiep->bm_sg = NULL;
  54977. + }
  54978. +
  54979. + if (cfiep->bm_align) {
  54980. + DWC_FREE(cfiep->bm_align);
  54981. + cfiep->bm_align = NULL;
  54982. + }
  54983. +
  54984. + if (cfiep->bm_concat) {
  54985. + if (NULL != cfiep->bm_concat->wTxBytes) {
  54986. + DWC_FREE(cfiep->bm_concat->wTxBytes);
  54987. + cfiep->bm_concat->wTxBytes = NULL;
  54988. + }
  54989. + DWC_FREE(cfiep->bm_concat);
  54990. + cfiep->bm_concat = NULL;
  54991. + }
  54992. +}
  54993. +
  54994. +/**
  54995. + * This function initializes the default values of the features
  54996. + * for a specific endpoint and should be called only once when
  54997. + * the EP is enabled first time.
  54998. + */
  54999. +static int cfi_ep_init_defaults(struct dwc_otg_pcd *pcd, cfi_ep_t * cfiep)
  55000. +{
  55001. + int retval = 0;
  55002. +
  55003. + cfiep->bm_sg = DWC_ALLOC(sizeof(ddma_sg_buffer_setup_t));
  55004. + if (NULL == cfiep->bm_sg) {
  55005. + CFI_INFO("Failed to allocate memory for SG feature value\n");
  55006. + return -DWC_E_NO_MEMORY;
  55007. + }
  55008. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  55009. +
  55010. + /* For the Concatenation feature's default value we do not allocate
  55011. + * memory for the wTxBytes field - it will be done in the set_feature_value
  55012. + * request handler.
  55013. + */
  55014. + cfiep->bm_concat = DWC_ALLOC(sizeof(ddma_concat_buffer_setup_t));
  55015. + if (NULL == cfiep->bm_concat) {
  55016. + CFI_INFO
  55017. + ("Failed to allocate memory for CONCATENATION feature value\n");
  55018. + DWC_FREE(cfiep->bm_sg);
  55019. + return -DWC_E_NO_MEMORY;
  55020. + }
  55021. + dwc_memset(cfiep->bm_concat, 0, sizeof(ddma_concat_buffer_setup_t));
  55022. +
  55023. + cfiep->bm_align = DWC_ALLOC(sizeof(ddma_align_buffer_setup_t));
  55024. + if (NULL == cfiep->bm_align) {
  55025. + CFI_INFO
  55026. + ("Failed to allocate memory for Alignment feature value\n");
  55027. + DWC_FREE(cfiep->bm_sg);
  55028. + DWC_FREE(cfiep->bm_concat);
  55029. + return -DWC_E_NO_MEMORY;
  55030. + }
  55031. + dwc_memset(cfiep->bm_align, 0, sizeof(ddma_align_buffer_setup_t));
  55032. +
  55033. + return retval;
  55034. +}
  55035. +
  55036. +/**
  55037. + * The callback function that notifies the CFI on the activation of
  55038. + * an endpoint in the PCD. The following steps are done in this function:
  55039. + *
  55040. + * Create a dynamically allocated cfi_ep_t object (a CFI wrapper to the PCD's
  55041. + * active endpoint)
  55042. + * Create MAX_DMA_DESCS_PER_EP count DMA Descriptors for the EP
  55043. + * Set the Buffer Mode to standard
  55044. + * Initialize the default values for all EP modes (SG, Circular, Concat, Align)
  55045. + * Add the cfi_ep_t object to the list of active endpoints in the CFI object
  55046. + */
  55047. +static int cfi_ep_enable(struct cfiobject *cfi, struct dwc_otg_pcd *pcd,
  55048. + struct dwc_otg_pcd_ep *ep)
  55049. +{
  55050. + cfi_ep_t *cfiep;
  55051. + int retval = -DWC_E_NOT_SUPPORTED;
  55052. +
  55053. + CFI_INFO("%s: epname=%s; epnum=0x%02x\n", __func__,
  55054. + "EP_" /*ep->ep.name */ , ep->desc->bEndpointAddress);
  55055. + /* MAS - Check whether this endpoint already is in the list */
  55056. + cfiep = get_cfi_ep_by_pcd_ep(cfi, ep);
  55057. +
  55058. + if (NULL == cfiep) {
  55059. + /* Allocate a cfi_ep_t object */
  55060. + cfiep = DWC_ALLOC(sizeof(cfi_ep_t));
  55061. + if (NULL == cfiep) {
  55062. + CFI_INFO
  55063. + ("Unable to allocate memory for <cfiep> in function %s\n",
  55064. + __func__);
  55065. + return -DWC_E_NO_MEMORY;
  55066. + }
  55067. + dwc_memset(cfiep, 0, sizeof(cfi_ep_t));
  55068. +
  55069. + /* Save the dwc_otg_pcd_ep pointer in the cfiep object */
  55070. + cfiep->ep = ep;
  55071. +
  55072. + /* Allocate the DMA Descriptors chain of MAX_DMA_DESCS_PER_EP count */
  55073. + ep->dwc_ep.descs =
  55074. + DWC_DMA_ALLOC(MAX_DMA_DESCS_PER_EP *
  55075. + sizeof(dwc_otg_dma_desc_t),
  55076. + &ep->dwc_ep.descs_dma_addr);
  55077. +
  55078. + if (NULL == ep->dwc_ep.descs) {
  55079. + DWC_FREE(cfiep);
  55080. + return -DWC_E_NO_MEMORY;
  55081. + }
  55082. +
  55083. + DWC_LIST_INIT(&cfiep->lh);
  55084. +
  55085. + /* Set the buffer mode to BM_STANDARD. It will be modified
  55086. + * when building descriptors for a specific buffer mode */
  55087. + ep->dwc_ep.buff_mode = BM_STANDARD;
  55088. +
  55089. + /* Create and initialize the default values for this EP's Buffer modes */
  55090. + if ((retval = cfi_ep_init_defaults(pcd, cfiep)) < 0)
  55091. + return retval;
  55092. +
  55093. + /* Add the cfi_ep_t object to the CFI object's list of active endpoints */
  55094. + DWC_LIST_INSERT_TAIL(&cfi->active_eps, &cfiep->lh);
  55095. + retval = 0;
  55096. + } else { /* The sought EP already is in the list */
  55097. + CFI_INFO("%s: The sought EP already is in the list\n",
  55098. + __func__);
  55099. + }
  55100. +
  55101. + return retval;
  55102. +}
  55103. +
  55104. +/**
  55105. + * This function is called when the data stage of a 3-stage Control Write request
  55106. + * is complete.
  55107. + *
  55108. + */
  55109. +static int cfi_ctrl_write_complete(struct cfiobject *cfi,
  55110. + struct dwc_otg_pcd *pcd)
  55111. +{
  55112. + uint32_t addr, reg_value;
  55113. + uint16_t wIndex, wValue;
  55114. + uint8_t bRequest;
  55115. + uint8_t *buf = cfi->buf_out.buf;
  55116. + //struct usb_ctrlrequest *ctrl_req = &cfi->ctrl_req_saved;
  55117. + struct cfi_usb_ctrlrequest *ctrl_req = &cfi->ctrl_req;
  55118. + int retval = -DWC_E_NOT_SUPPORTED;
  55119. +
  55120. + CFI_INFO("%s\n", __func__);
  55121. +
  55122. + bRequest = ctrl_req->bRequest;
  55123. + wIndex = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wIndex);
  55124. + wValue = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wValue);
  55125. +
  55126. + /*
  55127. + * Save the pointer to the data stage in the ctrl_req's <data> field.
  55128. + * The request should be already saved in the command stage by now.
  55129. + */
  55130. + ctrl_req->data = cfi->buf_out.buf;
  55131. + cfi->need_status_in_complete = 0;
  55132. + cfi->need_gadget_att = 0;
  55133. +
  55134. + switch (bRequest) {
  55135. + case VEN_CORE_WRITE_REGISTER:
  55136. + /* The buffer contains raw data of the new value for the register */
  55137. + reg_value = *((uint32_t *) buf);
  55138. + if (wValue == 0) {
  55139. + addr = 0;
  55140. + //addr = (uint32_t) pcd->otg_dev->os_dep.base;
  55141. + addr += wIndex;
  55142. + } else {
  55143. + addr = (wValue << 16) | wIndex;
  55144. + }
  55145. +
  55146. + //writel(reg_value, addr);
  55147. +
  55148. + retval = 0;
  55149. + cfi->need_status_in_complete = 1;
  55150. + break;
  55151. +
  55152. + case VEN_CORE_SET_FEATURE:
  55153. + /* The buffer contains raw data of the new value of the feature */
  55154. + retval = cfi_set_feature_value(pcd);
  55155. + if (retval < 0)
  55156. + return retval;
  55157. +
  55158. + cfi->need_status_in_complete = 1;
  55159. + break;
  55160. +
  55161. + default:
  55162. + break;
  55163. + }
  55164. +
  55165. + return retval;
  55166. +}
  55167. +
  55168. +/**
  55169. + * This function builds the DMA descriptors for the SG buffer mode.
  55170. + */
  55171. +static void cfi_build_sg_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  55172. + dwc_otg_pcd_request_t * req)
  55173. +{
  55174. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  55175. + ddma_sg_buffer_setup_t *sgval = cfiep->bm_sg;
  55176. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  55177. + struct dwc_otg_dma_desc *desc_last = cfiep->ep->dwc_ep.descs;
  55178. + dma_addr_t buff_addr = req->dma;
  55179. + int i;
  55180. + uint32_t txsize, off;
  55181. +
  55182. + txsize = sgval->wSize;
  55183. + off = sgval->bOffset;
  55184. +
  55185. +// CFI_INFO("%s: %s TXSIZE=0x%08x; OFFSET=0x%08x\n",
  55186. +// __func__, cfiep->ep->ep.name, txsize, off);
  55187. +
  55188. + for (i = 0; i < sgval->bCount; i++) {
  55189. + desc->status.b.bs = BS_HOST_BUSY;
  55190. + desc->buf = buff_addr;
  55191. + desc->status.b.l = 0;
  55192. + desc->status.b.ioc = 0;
  55193. + desc->status.b.sp = 0;
  55194. + desc->status.b.bytes = txsize;
  55195. + desc->status.b.bs = BS_HOST_READY;
  55196. +
  55197. + /* Set the next address of the buffer */
  55198. + buff_addr += txsize + off;
  55199. + desc_last = desc;
  55200. + desc++;
  55201. + }
  55202. +
  55203. + /* Set the last, ioc and sp bits on the Last DMA Descriptor */
  55204. + desc_last->status.b.l = 1;
  55205. + desc_last->status.b.ioc = 1;
  55206. + desc_last->status.b.sp = ep->dwc_ep.sent_zlp;
  55207. + /* Save the last DMA descriptor pointer */
  55208. + cfiep->dma_desc_last = desc_last;
  55209. + cfiep->desc_count = sgval->bCount;
  55210. +}
  55211. +
  55212. +/**
  55213. + * This function builds the DMA descriptors for the Concatenation buffer mode.
  55214. + */
  55215. +static void cfi_build_concat_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  55216. + dwc_otg_pcd_request_t * req)
  55217. +{
  55218. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  55219. + ddma_concat_buffer_setup_t *concatval = cfiep->bm_concat;
  55220. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  55221. + struct dwc_otg_dma_desc *desc_last = cfiep->ep->dwc_ep.descs;
  55222. + dma_addr_t buff_addr = req->dma;
  55223. + int i;
  55224. + uint16_t *txsize;
  55225. +
  55226. + txsize = concatval->wTxBytes;
  55227. +
  55228. + for (i = 0; i < concatval->hdr.bDescCount; i++) {
  55229. + desc->buf = buff_addr;
  55230. + desc->status.b.bs = BS_HOST_BUSY;
  55231. + desc->status.b.l = 0;
  55232. + desc->status.b.ioc = 0;
  55233. + desc->status.b.sp = 0;
  55234. + desc->status.b.bytes = *txsize;
  55235. + desc->status.b.bs = BS_HOST_READY;
  55236. +
  55237. + txsize++;
  55238. + /* Set the next address of the buffer */
  55239. + buff_addr += UGETW(ep->desc->wMaxPacketSize);
  55240. + desc_last = desc;
  55241. + desc++;
  55242. + }
  55243. +
  55244. + /* Set the last, ioc and sp bits on the Last DMA Descriptor */
  55245. + desc_last->status.b.l = 1;
  55246. + desc_last->status.b.ioc = 1;
  55247. + desc_last->status.b.sp = ep->dwc_ep.sent_zlp;
  55248. + cfiep->dma_desc_last = desc_last;
  55249. + cfiep->desc_count = concatval->hdr.bDescCount;
  55250. +}
  55251. +
  55252. +/**
  55253. + * This function builds the DMA descriptors for the Circular buffer mode
  55254. + */
  55255. +static void cfi_build_circ_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  55256. + dwc_otg_pcd_request_t * req)
  55257. +{
  55258. + /* @todo: MAS - add implementation when this feature needs to be tested */
  55259. +}
  55260. +
  55261. +/**
  55262. + * This function builds the DMA descriptors for the Alignment buffer mode
  55263. + */
  55264. +static void cfi_build_align_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  55265. + dwc_otg_pcd_request_t * req)
  55266. +{
  55267. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  55268. + ddma_align_buffer_setup_t *alignval = cfiep->bm_align;
  55269. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  55270. + dma_addr_t buff_addr = req->dma;
  55271. +
  55272. + desc->status.b.bs = BS_HOST_BUSY;
  55273. + desc->status.b.l = 1;
  55274. + desc->status.b.ioc = 1;
  55275. + desc->status.b.sp = ep->dwc_ep.sent_zlp;
  55276. + desc->status.b.bytes = req->length;
  55277. + /* Adjust the buffer alignment */
  55278. + desc->buf = (buff_addr + alignval->bAlign);
  55279. + desc->status.b.bs = BS_HOST_READY;
  55280. + cfiep->dma_desc_last = desc;
  55281. + cfiep->desc_count = 1;
  55282. +}
  55283. +
  55284. +/**
  55285. + * This function builds the DMA descriptors chain for different modes of the
  55286. + * buffer setup of an endpoint.
  55287. + */
  55288. +static void cfi_build_descriptors(struct cfiobject *cfi,
  55289. + struct dwc_otg_pcd *pcd,
  55290. + struct dwc_otg_pcd_ep *ep,
  55291. + dwc_otg_pcd_request_t * req)
  55292. +{
  55293. + cfi_ep_t *cfiep;
  55294. +
  55295. + /* Get the cfiep by the dwc_otg_pcd_ep */
  55296. + cfiep = get_cfi_ep_by_pcd_ep(cfi, ep);
  55297. + if (NULL == cfiep) {
  55298. + CFI_INFO("%s: Unable to find a matching active endpoint\n",
  55299. + __func__);
  55300. + return;
  55301. + }
  55302. +
  55303. + cfiep->xfer_len = req->length;
  55304. +
  55305. + /* Iterate through all the DMA descriptors */
  55306. + switch (cfiep->ep->dwc_ep.buff_mode) {
  55307. + case BM_SG:
  55308. + cfi_build_sg_descs(cfi, cfiep, req);
  55309. + break;
  55310. +
  55311. + case BM_CONCAT:
  55312. + cfi_build_concat_descs(cfi, cfiep, req);
  55313. + break;
  55314. +
  55315. + case BM_CIRCULAR:
  55316. + cfi_build_circ_descs(cfi, cfiep, req);
  55317. + break;
  55318. +
  55319. + case BM_ALIGN:
  55320. + cfi_build_align_descs(cfi, cfiep, req);
  55321. + break;
  55322. +
  55323. + default:
  55324. + break;
  55325. + }
  55326. +}
  55327. +
  55328. +/**
  55329. + * Allocate DMA buffer for different Buffer modes.
  55330. + */
  55331. +static void *cfi_ep_alloc_buf(struct cfiobject *cfi, struct dwc_otg_pcd *pcd,
  55332. + struct dwc_otg_pcd_ep *ep, dma_addr_t * dma,
  55333. + unsigned size, gfp_t flags)
  55334. +{
  55335. + return DWC_DMA_ALLOC(size, dma);
  55336. +}
  55337. +
  55338. +/**
  55339. + * This function initializes the CFI object.
  55340. + */
  55341. +int init_cfi(cfiobject_t * cfiobj)
  55342. +{
  55343. + CFI_INFO("%s\n", __func__);
  55344. +
  55345. + /* Allocate a buffer for IN XFERs */
  55346. + cfiobj->buf_in.buf =
  55347. + DWC_DMA_ALLOC(CFI_IN_BUF_LEN, &cfiobj->buf_in.addr);
  55348. + if (NULL == cfiobj->buf_in.buf) {
  55349. + CFI_INFO("Unable to allocate buffer for INs\n");
  55350. + return -DWC_E_NO_MEMORY;
  55351. + }
  55352. +
  55353. + /* Allocate a buffer for OUT XFERs */
  55354. + cfiobj->buf_out.buf =
  55355. + DWC_DMA_ALLOC(CFI_OUT_BUF_LEN, &cfiobj->buf_out.addr);
  55356. + if (NULL == cfiobj->buf_out.buf) {
  55357. + CFI_INFO("Unable to allocate buffer for OUT\n");
  55358. + return -DWC_E_NO_MEMORY;
  55359. + }
  55360. +
  55361. + /* Initialize the callback function pointers */
  55362. + cfiobj->ops.release = cfi_release;
  55363. + cfiobj->ops.ep_enable = cfi_ep_enable;
  55364. + cfiobj->ops.ctrl_write_complete = cfi_ctrl_write_complete;
  55365. + cfiobj->ops.build_descriptors = cfi_build_descriptors;
  55366. + cfiobj->ops.ep_alloc_buf = cfi_ep_alloc_buf;
  55367. +
  55368. + /* Initialize the list of active endpoints in the CFI object */
  55369. + DWC_LIST_INIT(&cfiobj->active_eps);
  55370. +
  55371. + return 0;
  55372. +}
  55373. +
  55374. +/**
  55375. + * This function reads the required feature's current value into the buffer
  55376. + *
  55377. + * @retval: Returns negative as error, or the data length of the feature
  55378. + */
  55379. +static int cfi_get_feature_value(uint8_t * buf, uint16_t buflen,
  55380. + struct dwc_otg_pcd *pcd,
  55381. + struct cfi_usb_ctrlrequest *ctrl_req)
  55382. +{
  55383. + int retval = -DWC_E_NOT_SUPPORTED;
  55384. + struct dwc_otg_core_if *coreif = GET_CORE_IF(pcd);
  55385. + uint16_t dfifo, rxfifo, txfifo;
  55386. +
  55387. + switch (ctrl_req->wIndex) {
  55388. + /* Whether the DDMA is enabled or not */
  55389. + case FT_ID_DMA_MODE:
  55390. + *buf = (coreif->dma_enable && coreif->dma_desc_enable) ? 1 : 0;
  55391. + retval = 1;
  55392. + break;
  55393. +
  55394. + case FT_ID_DMA_BUFFER_SETUP:
  55395. + retval = cfi_ep_get_sg_val(buf, pcd, ctrl_req);
  55396. + break;
  55397. +
  55398. + case FT_ID_DMA_BUFF_ALIGN:
  55399. + retval = cfi_ep_get_align_val(buf, pcd, ctrl_req);
  55400. + break;
  55401. +
  55402. + case FT_ID_DMA_CONCAT_SETUP:
  55403. + retval = cfi_ep_get_concat_val(buf, pcd, ctrl_req);
  55404. + break;
  55405. +
  55406. + case FT_ID_DMA_CIRCULAR:
  55407. + CFI_INFO("GetFeature value (FT_ID_DMA_CIRCULAR)\n");
  55408. + break;
  55409. +
  55410. + case FT_ID_THRESHOLD_SETUP:
  55411. + CFI_INFO("GetFeature value (FT_ID_THRESHOLD_SETUP)\n");
  55412. + break;
  55413. +
  55414. + case FT_ID_DFIFO_DEPTH:
  55415. + dfifo = get_dfifo_size(coreif);
  55416. + *((uint16_t *) buf) = dfifo;
  55417. + retval = sizeof(uint16_t);
  55418. + break;
  55419. +
  55420. + case FT_ID_TX_FIFO_DEPTH:
  55421. + retval = get_txfifo_size(pcd, ctrl_req->wValue);
  55422. + if (retval >= 0) {
  55423. + txfifo = retval;
  55424. + *((uint16_t *) buf) = txfifo;
  55425. + retval = sizeof(uint16_t);
  55426. + }
  55427. + break;
  55428. +
  55429. + case FT_ID_RX_FIFO_DEPTH:
  55430. + retval = get_rxfifo_size(coreif, ctrl_req->wValue);
  55431. + if (retval >= 0) {
  55432. + rxfifo = retval;
  55433. + *((uint16_t *) buf) = rxfifo;
  55434. + retval = sizeof(uint16_t);
  55435. + }
  55436. + break;
  55437. + }
  55438. +
  55439. + return retval;
  55440. +}
  55441. +
  55442. +/**
  55443. + * This function resets the SG for the specified EP to its default value
  55444. + */
  55445. +static int cfi_reset_sg_val(cfi_ep_t * cfiep)
  55446. +{
  55447. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  55448. + return 0;
  55449. +}
  55450. +
  55451. +/**
  55452. + * This function resets the Alignment for the specified EP to its default value
  55453. + */
  55454. +static int cfi_reset_align_val(cfi_ep_t * cfiep)
  55455. +{
  55456. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  55457. + return 0;
  55458. +}
  55459. +
  55460. +/**
  55461. + * This function resets the Concatenation for the specified EP to its default value
  55462. + * This function will also set the value of the wTxBytes field to NULL after
  55463. + * freeing the memory previously allocated for this field.
  55464. + */
  55465. +static int cfi_reset_concat_val(cfi_ep_t * cfiep)
  55466. +{
  55467. + /* First we need to free the wTxBytes field */
  55468. + if (cfiep->bm_concat->wTxBytes) {
  55469. + DWC_FREE(cfiep->bm_concat->wTxBytes);
  55470. + cfiep->bm_concat->wTxBytes = NULL;
  55471. + }
  55472. +
  55473. + dwc_memset(cfiep->bm_concat, 0, sizeof(ddma_concat_buffer_setup_t));
  55474. + return 0;
  55475. +}
  55476. +
  55477. +/**
  55478. + * This function resets all the buffer setups of the specified endpoint
  55479. + */
  55480. +static int cfi_ep_reset_all_setup_vals(cfi_ep_t * cfiep)
  55481. +{
  55482. + cfi_reset_sg_val(cfiep);
  55483. + cfi_reset_align_val(cfiep);
  55484. + cfi_reset_concat_val(cfiep);
  55485. + return 0;
  55486. +}
  55487. +
  55488. +static int cfi_handle_reset_fifo_val(struct dwc_otg_pcd *pcd, uint8_t ep_addr,
  55489. + uint8_t rx_rst, uint8_t tx_rst)
  55490. +{
  55491. + int retval = -DWC_E_INVALID;
  55492. + uint16_t tx_siz[15];
  55493. + uint16_t rx_siz = 0;
  55494. + dwc_otg_pcd_ep_t *ep = NULL;
  55495. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  55496. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  55497. +
  55498. + if (rx_rst) {
  55499. + rx_siz = params->dev_rx_fifo_size;
  55500. + params->dev_rx_fifo_size = GET_CORE_IF(pcd)->init_rxfsiz;
  55501. + }
  55502. +
  55503. + if (tx_rst) {
  55504. + if (ep_addr == 0) {
  55505. + int i;
  55506. +
  55507. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  55508. + tx_siz[i] =
  55509. + core_if->core_params->dev_tx_fifo_size[i];
  55510. + core_if->core_params->dev_tx_fifo_size[i] =
  55511. + core_if->init_txfsiz[i];
  55512. + }
  55513. + } else {
  55514. +
  55515. + ep = get_ep_by_addr(pcd, ep_addr);
  55516. +
  55517. + if (NULL == ep) {
  55518. + CFI_INFO
  55519. + ("%s: Unable to get the endpoint addr=0x%02x\n",
  55520. + __func__, ep_addr);
  55521. + return -DWC_E_INVALID;
  55522. + }
  55523. +
  55524. + tx_siz[0] =
  55525. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num -
  55526. + 1];
  55527. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] =
  55528. + GET_CORE_IF(pcd)->init_txfsiz[ep->
  55529. + dwc_ep.tx_fifo_num -
  55530. + 1];
  55531. + }
  55532. + }
  55533. +
  55534. + if (resize_fifos(GET_CORE_IF(pcd))) {
  55535. + retval = 0;
  55536. + } else {
  55537. + CFI_INFO
  55538. + ("%s: Error resetting the feature Reset All(FIFO size)\n",
  55539. + __func__);
  55540. + if (rx_rst) {
  55541. + params->dev_rx_fifo_size = rx_siz;
  55542. + }
  55543. +
  55544. + if (tx_rst) {
  55545. + if (ep_addr == 0) {
  55546. + int i;
  55547. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps;
  55548. + i++) {
  55549. + core_if->
  55550. + core_params->dev_tx_fifo_size[i] =
  55551. + tx_siz[i];
  55552. + }
  55553. + } else {
  55554. + params->dev_tx_fifo_size[ep->
  55555. + dwc_ep.tx_fifo_num -
  55556. + 1] = tx_siz[0];
  55557. + }
  55558. + }
  55559. + retval = -DWC_E_INVALID;
  55560. + }
  55561. + return retval;
  55562. +}
  55563. +
  55564. +static int cfi_handle_reset_all(struct dwc_otg_pcd *pcd, uint8_t addr)
  55565. +{
  55566. + int retval = 0;
  55567. + cfi_ep_t *cfiep;
  55568. + cfiobject_t *cfi = pcd->cfi;
  55569. + dwc_list_link_t *tmp;
  55570. +
  55571. + retval = cfi_handle_reset_fifo_val(pcd, addr, 1, 1);
  55572. + if (retval < 0) {
  55573. + return retval;
  55574. + }
  55575. +
  55576. + /* If the EP address is known then reset the features for only that EP */
  55577. + if (addr) {
  55578. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  55579. + if (NULL == cfiep) {
  55580. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  55581. + __func__, addr);
  55582. + return -DWC_E_INVALID;
  55583. + }
  55584. + retval = cfi_ep_reset_all_setup_vals(cfiep);
  55585. + cfiep->ep->dwc_ep.buff_mode = BM_STANDARD;
  55586. + }
  55587. + /* Otherwise (wValue == 0), reset all features of all EP's */
  55588. + else {
  55589. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  55590. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  55591. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  55592. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  55593. + retval = cfi_ep_reset_all_setup_vals(cfiep);
  55594. + cfiep->ep->dwc_ep.buff_mode = BM_STANDARD;
  55595. + if (retval < 0) {
  55596. + CFI_INFO
  55597. + ("%s: Error resetting the feature Reset All\n",
  55598. + __func__);
  55599. + return retval;
  55600. + }
  55601. + }
  55602. + }
  55603. + return retval;
  55604. +}
  55605. +
  55606. +static int cfi_handle_reset_dma_buff_setup(struct dwc_otg_pcd *pcd,
  55607. + uint8_t addr)
  55608. +{
  55609. + int retval = 0;
  55610. + cfi_ep_t *cfiep;
  55611. + cfiobject_t *cfi = pcd->cfi;
  55612. + dwc_list_link_t *tmp;
  55613. +
  55614. + /* If the EP address is known then reset the features for only that EP */
  55615. + if (addr) {
  55616. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  55617. + if (NULL == cfiep) {
  55618. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  55619. + __func__, addr);
  55620. + return -DWC_E_INVALID;
  55621. + }
  55622. + retval = cfi_reset_sg_val(cfiep);
  55623. + }
  55624. + /* Otherwise (wValue == 0), reset all features of all EP's */
  55625. + else {
  55626. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  55627. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  55628. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  55629. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  55630. + retval = cfi_reset_sg_val(cfiep);
  55631. + if (retval < 0) {
  55632. + CFI_INFO
  55633. + ("%s: Error resetting the feature Buffer Setup\n",
  55634. + __func__);
  55635. + return retval;
  55636. + }
  55637. + }
  55638. + }
  55639. + return retval;
  55640. +}
  55641. +
  55642. +static int cfi_handle_reset_concat_val(struct dwc_otg_pcd *pcd, uint8_t addr)
  55643. +{
  55644. + int retval = 0;
  55645. + cfi_ep_t *cfiep;
  55646. + cfiobject_t *cfi = pcd->cfi;
  55647. + dwc_list_link_t *tmp;
  55648. +
  55649. + /* If the EP address is known then reset the features for only that EP */
  55650. + if (addr) {
  55651. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  55652. + if (NULL == cfiep) {
  55653. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  55654. + __func__, addr);
  55655. + return -DWC_E_INVALID;
  55656. + }
  55657. + retval = cfi_reset_concat_val(cfiep);
  55658. + }
  55659. + /* Otherwise (wValue == 0), reset all features of all EP's */
  55660. + else {
  55661. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  55662. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  55663. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  55664. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  55665. + retval = cfi_reset_concat_val(cfiep);
  55666. + if (retval < 0) {
  55667. + CFI_INFO
  55668. + ("%s: Error resetting the feature Concatenation Value\n",
  55669. + __func__);
  55670. + return retval;
  55671. + }
  55672. + }
  55673. + }
  55674. + return retval;
  55675. +}
  55676. +
  55677. +static int cfi_handle_reset_align_val(struct dwc_otg_pcd *pcd, uint8_t addr)
  55678. +{
  55679. + int retval = 0;
  55680. + cfi_ep_t *cfiep;
  55681. + cfiobject_t *cfi = pcd->cfi;
  55682. + dwc_list_link_t *tmp;
  55683. +
  55684. + /* If the EP address is known then reset the features for only that EP */
  55685. + if (addr) {
  55686. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  55687. + if (NULL == cfiep) {
  55688. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  55689. + __func__, addr);
  55690. + return -DWC_E_INVALID;
  55691. + }
  55692. + retval = cfi_reset_align_val(cfiep);
  55693. + }
  55694. + /* Otherwise (wValue == 0), reset all features of all EP's */
  55695. + else {
  55696. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  55697. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  55698. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  55699. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  55700. + retval = cfi_reset_align_val(cfiep);
  55701. + if (retval < 0) {
  55702. + CFI_INFO
  55703. + ("%s: Error resetting the feature Aliignment Value\n",
  55704. + __func__);
  55705. + return retval;
  55706. + }
  55707. + }
  55708. + }
  55709. + return retval;
  55710. +
  55711. +}
  55712. +
  55713. +static int cfi_preproc_reset(struct dwc_otg_pcd *pcd,
  55714. + struct cfi_usb_ctrlrequest *req)
  55715. +{
  55716. + int retval = 0;
  55717. +
  55718. + switch (req->wIndex) {
  55719. + case 0:
  55720. + /* Reset all features */
  55721. + retval = cfi_handle_reset_all(pcd, req->wValue & 0xff);
  55722. + break;
  55723. +
  55724. + case FT_ID_DMA_BUFFER_SETUP:
  55725. + /* Reset the SG buffer setup */
  55726. + retval =
  55727. + cfi_handle_reset_dma_buff_setup(pcd, req->wValue & 0xff);
  55728. + break;
  55729. +
  55730. + case FT_ID_DMA_CONCAT_SETUP:
  55731. + /* Reset the Concatenation buffer setup */
  55732. + retval = cfi_handle_reset_concat_val(pcd, req->wValue & 0xff);
  55733. + break;
  55734. +
  55735. + case FT_ID_DMA_BUFF_ALIGN:
  55736. + /* Reset the Alignment buffer setup */
  55737. + retval = cfi_handle_reset_align_val(pcd, req->wValue & 0xff);
  55738. + break;
  55739. +
  55740. + case FT_ID_TX_FIFO_DEPTH:
  55741. + retval =
  55742. + cfi_handle_reset_fifo_val(pcd, req->wValue & 0xff, 0, 1);
  55743. + pcd->cfi->need_gadget_att = 0;
  55744. + break;
  55745. +
  55746. + case FT_ID_RX_FIFO_DEPTH:
  55747. + retval = cfi_handle_reset_fifo_val(pcd, 0, 1, 0);
  55748. + pcd->cfi->need_gadget_att = 0;
  55749. + break;
  55750. + default:
  55751. + break;
  55752. + }
  55753. + return retval;
  55754. +}
  55755. +
  55756. +/**
  55757. + * This function sets a new value for the SG buffer setup.
  55758. + */
  55759. +static int cfi_ep_set_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  55760. +{
  55761. + uint8_t inaddr, outaddr;
  55762. + cfi_ep_t *epin, *epout;
  55763. + ddma_sg_buffer_setup_t *psgval;
  55764. + uint32_t desccount, size;
  55765. +
  55766. + CFI_INFO("%s\n", __func__);
  55767. +
  55768. + psgval = (ddma_sg_buffer_setup_t *) buf;
  55769. + desccount = (uint32_t) psgval->bCount;
  55770. + size = (uint32_t) psgval->wSize;
  55771. +
  55772. + /* Check the DMA descriptor count */
  55773. + if ((desccount > MAX_DMA_DESCS_PER_EP) || (desccount == 0)) {
  55774. + CFI_INFO
  55775. + ("%s: The count of DMA Descriptors should be between 1 and %d\n",
  55776. + __func__, MAX_DMA_DESCS_PER_EP);
  55777. + return -DWC_E_INVALID;
  55778. + }
  55779. +
  55780. + /* Check the DMA descriptor count */
  55781. +
  55782. + if (size == 0) {
  55783. +
  55784. + CFI_INFO("%s: The transfer size should be at least 1 byte\n",
  55785. + __func__);
  55786. +
  55787. + return -DWC_E_INVALID;
  55788. +
  55789. + }
  55790. +
  55791. + inaddr = psgval->bInEndpointAddress;
  55792. + outaddr = psgval->bOutEndpointAddress;
  55793. +
  55794. + epin = get_cfi_ep_by_addr(pcd->cfi, inaddr);
  55795. + epout = get_cfi_ep_by_addr(pcd->cfi, outaddr);
  55796. +
  55797. + if (NULL == epin || NULL == epout) {
  55798. + CFI_INFO
  55799. + ("%s: Unable to get the endpoints inaddr=0x%02x outaddr=0x%02x\n",
  55800. + __func__, inaddr, outaddr);
  55801. + return -DWC_E_INVALID;
  55802. + }
  55803. +
  55804. + epin->ep->dwc_ep.buff_mode = BM_SG;
  55805. + dwc_memcpy(epin->bm_sg, psgval, sizeof(ddma_sg_buffer_setup_t));
  55806. +
  55807. + epout->ep->dwc_ep.buff_mode = BM_SG;
  55808. + dwc_memcpy(epout->bm_sg, psgval, sizeof(ddma_sg_buffer_setup_t));
  55809. +
  55810. + return 0;
  55811. +}
  55812. +
  55813. +/**
  55814. + * This function sets a new value for the buffer Alignment setup.
  55815. + */
  55816. +static int cfi_ep_set_alignment_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  55817. +{
  55818. + cfi_ep_t *ep;
  55819. + uint8_t addr;
  55820. + ddma_align_buffer_setup_t *palignval;
  55821. +
  55822. + palignval = (ddma_align_buffer_setup_t *) buf;
  55823. + addr = palignval->bEndpointAddress;
  55824. +
  55825. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  55826. +
  55827. + if (NULL == ep) {
  55828. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  55829. + __func__, addr);
  55830. + return -DWC_E_INVALID;
  55831. + }
  55832. +
  55833. + ep->ep->dwc_ep.buff_mode = BM_ALIGN;
  55834. + dwc_memcpy(ep->bm_align, palignval, sizeof(ddma_align_buffer_setup_t));
  55835. +
  55836. + return 0;
  55837. +}
  55838. +
  55839. +/**
  55840. + * This function sets a new value for the Concatenation buffer setup.
  55841. + */
  55842. +static int cfi_ep_set_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  55843. +{
  55844. + uint8_t addr;
  55845. + cfi_ep_t *ep;
  55846. + struct _ddma_concat_buffer_setup_hdr *pConcatValHdr;
  55847. + uint16_t *pVals;
  55848. + uint32_t desccount;
  55849. + int i;
  55850. + uint16_t mps;
  55851. +
  55852. + pConcatValHdr = (struct _ddma_concat_buffer_setup_hdr *)buf;
  55853. + desccount = (uint32_t) pConcatValHdr->bDescCount;
  55854. + pVals = (uint16_t *) (buf + BS_CONCAT_VAL_HDR_LEN);
  55855. +
  55856. + /* Check the DMA descriptor count */
  55857. + if (desccount > MAX_DMA_DESCS_PER_EP) {
  55858. + CFI_INFO("%s: Maximum DMA Descriptor count should be %d\n",
  55859. + __func__, MAX_DMA_DESCS_PER_EP);
  55860. + return -DWC_E_INVALID;
  55861. + }
  55862. +
  55863. + addr = pConcatValHdr->bEndpointAddress;
  55864. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  55865. + if (NULL == ep) {
  55866. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  55867. + __func__, addr);
  55868. + return -DWC_E_INVALID;
  55869. + }
  55870. +
  55871. + mps = UGETW(ep->ep->desc->wMaxPacketSize);
  55872. +
  55873. +#if 0
  55874. + for (i = 0; i < desccount; i++) {
  55875. + CFI_INFO("%s: wTxSize[%d]=0x%04x\n", __func__, i, pVals[i]);
  55876. + }
  55877. + CFI_INFO("%s: epname=%s; mps=%d\n", __func__, ep->ep->ep.name, mps);
  55878. +#endif
  55879. +
  55880. + /* Check the wTxSizes to be less than or equal to the mps */
  55881. + for (i = 0; i < desccount; i++) {
  55882. + if (pVals[i] > mps) {
  55883. + CFI_INFO
  55884. + ("%s: ERROR - the wTxSize[%d] should be <= MPS (wTxSize=%d)\n",
  55885. + __func__, i, pVals[i]);
  55886. + return -DWC_E_INVALID;
  55887. + }
  55888. + }
  55889. +
  55890. + ep->ep->dwc_ep.buff_mode = BM_CONCAT;
  55891. + dwc_memcpy(ep->bm_concat, pConcatValHdr, BS_CONCAT_VAL_HDR_LEN);
  55892. +
  55893. + /* Free the previously allocated storage for the wTxBytes */
  55894. + if (ep->bm_concat->wTxBytes) {
  55895. + DWC_FREE(ep->bm_concat->wTxBytes);
  55896. + }
  55897. +
  55898. + /* Allocate a new storage for the wTxBytes field */
  55899. + ep->bm_concat->wTxBytes =
  55900. + DWC_ALLOC(sizeof(uint16_t) * pConcatValHdr->bDescCount);
  55901. + if (NULL == ep->bm_concat->wTxBytes) {
  55902. + CFI_INFO("%s: Unable to allocate memory\n", __func__);
  55903. + return -DWC_E_NO_MEMORY;
  55904. + }
  55905. +
  55906. + /* Copy the new values into the wTxBytes filed */
  55907. + dwc_memcpy(ep->bm_concat->wTxBytes, buf + BS_CONCAT_VAL_HDR_LEN,
  55908. + sizeof(uint16_t) * pConcatValHdr->bDescCount);
  55909. +
  55910. + return 0;
  55911. +}
  55912. +
  55913. +/**
  55914. + * This function calculates the total of all FIFO sizes
  55915. + *
  55916. + * @param core_if Programming view of DWC_otg controller
  55917. + *
  55918. + * @return The total of data FIFO sizes.
  55919. + *
  55920. + */
  55921. +static uint16_t get_dfifo_size(dwc_otg_core_if_t * core_if)
  55922. +{
  55923. + dwc_otg_core_params_t *params = core_if->core_params;
  55924. + uint16_t dfifo_total = 0;
  55925. + int i;
  55926. +
  55927. + /* The shared RxFIFO size */
  55928. + dfifo_total =
  55929. + params->dev_rx_fifo_size + params->dev_nperio_tx_fifo_size;
  55930. +
  55931. + /* Add up each TxFIFO size to the total */
  55932. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  55933. + dfifo_total += params->dev_tx_fifo_size[i];
  55934. + }
  55935. +
  55936. + return dfifo_total;
  55937. +}
  55938. +
  55939. +/**
  55940. + * This function returns Rx FIFO size
  55941. + *
  55942. + * @param core_if Programming view of DWC_otg controller
  55943. + *
  55944. + * @return The total of data FIFO sizes.
  55945. + *
  55946. + */
  55947. +static int32_t get_rxfifo_size(dwc_otg_core_if_t * core_if, uint16_t wValue)
  55948. +{
  55949. + switch (wValue >> 8) {
  55950. + case 0:
  55951. + return (core_if->pwron_rxfsiz <
  55952. + 32768) ? core_if->pwron_rxfsiz : 32768;
  55953. + break;
  55954. + case 1:
  55955. + return core_if->core_params->dev_rx_fifo_size;
  55956. + break;
  55957. + default:
  55958. + return -DWC_E_INVALID;
  55959. + break;
  55960. + }
  55961. +}
  55962. +
  55963. +/**
  55964. + * This function returns Tx FIFO size for IN EP
  55965. + *
  55966. + * @param core_if Programming view of DWC_otg controller
  55967. + *
  55968. + * @return The total of data FIFO sizes.
  55969. + *
  55970. + */
  55971. +static int32_t get_txfifo_size(struct dwc_otg_pcd *pcd, uint16_t wValue)
  55972. +{
  55973. + dwc_otg_pcd_ep_t *ep;
  55974. +
  55975. + ep = get_ep_by_addr(pcd, wValue & 0xff);
  55976. +
  55977. + if (NULL == ep) {
  55978. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  55979. + __func__, wValue & 0xff);
  55980. + return -DWC_E_INVALID;
  55981. + }
  55982. +
  55983. + if (!ep->dwc_ep.is_in) {
  55984. + CFI_INFO
  55985. + ("%s: No Tx FIFO assingned to the Out endpoint addr=0x%02x\n",
  55986. + __func__, wValue & 0xff);
  55987. + return -DWC_E_INVALID;
  55988. + }
  55989. +
  55990. + switch (wValue >> 8) {
  55991. + case 0:
  55992. + return (GET_CORE_IF(pcd)->pwron_txfsiz
  55993. + [ep->dwc_ep.tx_fifo_num - 1] <
  55994. + 768) ? GET_CORE_IF(pcd)->pwron_txfsiz[ep->
  55995. + dwc_ep.tx_fifo_num
  55996. + - 1] : 32768;
  55997. + break;
  55998. + case 1:
  55999. + return GET_CORE_IF(pcd)->core_params->
  56000. + dev_tx_fifo_size[ep->dwc_ep.num - 1];
  56001. + break;
  56002. + default:
  56003. + return -DWC_E_INVALID;
  56004. + break;
  56005. + }
  56006. +}
  56007. +
  56008. +/**
  56009. + * This function checks if the submitted combination of
  56010. + * device mode FIFO sizes is possible or not.
  56011. + *
  56012. + * @param core_if Programming view of DWC_otg controller
  56013. + *
  56014. + * @return 1 if possible, 0 otherwise.
  56015. + *
  56016. + */
  56017. +static uint8_t check_fifo_sizes(dwc_otg_core_if_t * core_if)
  56018. +{
  56019. + uint16_t dfifo_actual = 0;
  56020. + dwc_otg_core_params_t *params = core_if->core_params;
  56021. + uint16_t start_addr = 0;
  56022. + int i;
  56023. +
  56024. + dfifo_actual =
  56025. + params->dev_rx_fifo_size + params->dev_nperio_tx_fifo_size;
  56026. +
  56027. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  56028. + dfifo_actual += params->dev_tx_fifo_size[i];
  56029. + }
  56030. +
  56031. + if (dfifo_actual > core_if->total_fifo_size) {
  56032. + return 0;
  56033. + }
  56034. +
  56035. + if (params->dev_rx_fifo_size > 32768 || params->dev_rx_fifo_size < 16)
  56036. + return 0;
  56037. +
  56038. + if (params->dev_nperio_tx_fifo_size > 32768
  56039. + || params->dev_nperio_tx_fifo_size < 16)
  56040. + return 0;
  56041. +
  56042. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  56043. +
  56044. + if (params->dev_tx_fifo_size[i] > 768
  56045. + || params->dev_tx_fifo_size[i] < 4)
  56046. + return 0;
  56047. + }
  56048. +
  56049. + if (params->dev_rx_fifo_size > core_if->pwron_rxfsiz)
  56050. + return 0;
  56051. + start_addr = params->dev_rx_fifo_size;
  56052. +
  56053. + if (params->dev_nperio_tx_fifo_size > core_if->pwron_gnptxfsiz)
  56054. + return 0;
  56055. + start_addr += params->dev_nperio_tx_fifo_size;
  56056. +
  56057. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  56058. +
  56059. + if (params->dev_tx_fifo_size[i] > core_if->pwron_txfsiz[i])
  56060. + return 0;
  56061. + start_addr += params->dev_tx_fifo_size[i];
  56062. + }
  56063. +
  56064. + return 1;
  56065. +}
  56066. +
  56067. +/**
  56068. + * This function resizes Device mode FIFOs
  56069. + *
  56070. + * @param core_if Programming view of DWC_otg controller
  56071. + *
  56072. + * @return 1 if successful, 0 otherwise
  56073. + *
  56074. + */
  56075. +static uint8_t resize_fifos(dwc_otg_core_if_t * core_if)
  56076. +{
  56077. + int i = 0;
  56078. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  56079. + dwc_otg_core_params_t *params = core_if->core_params;
  56080. + uint32_t rx_fifo_size;
  56081. + fifosize_data_t nptxfifosize;
  56082. + fifosize_data_t txfifosize[15];
  56083. +
  56084. + uint32_t rx_fsz_bak;
  56085. + uint32_t nptxfsz_bak;
  56086. + uint32_t txfsz_bak[15];
  56087. +
  56088. + uint16_t start_address;
  56089. + uint8_t retval = 1;
  56090. +
  56091. + if (!check_fifo_sizes(core_if)) {
  56092. + return 0;
  56093. + }
  56094. +
  56095. + /* Configure data FIFO sizes */
  56096. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  56097. + rx_fsz_bak = DWC_READ_REG32(&global_regs->grxfsiz);
  56098. + rx_fifo_size = params->dev_rx_fifo_size;
  56099. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fifo_size);
  56100. +
  56101. + /*
  56102. + * Tx FIFOs These FIFOs are numbered from 1 to 15.
  56103. + * Indexes of the FIFO size module parameters in the
  56104. + * dev_tx_fifo_size array and the FIFO size registers in
  56105. + * the dtxfsiz array run from 0 to 14.
  56106. + */
  56107. +
  56108. + /* Non-periodic Tx FIFO */
  56109. + nptxfsz_bak = DWC_READ_REG32(&global_regs->gnptxfsiz);
  56110. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  56111. + start_address = params->dev_rx_fifo_size;
  56112. + nptxfifosize.b.startaddr = start_address;
  56113. +
  56114. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfifosize.d32);
  56115. +
  56116. + start_address += nptxfifosize.b.depth;
  56117. +
  56118. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  56119. + txfsz_bak[i] = DWC_READ_REG32(&global_regs->dtxfsiz[i]);
  56120. +
  56121. + txfifosize[i].b.depth = params->dev_tx_fifo_size[i];
  56122. + txfifosize[i].b.startaddr = start_address;
  56123. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  56124. + txfifosize[i].d32);
  56125. +
  56126. + start_address += txfifosize[i].b.depth;
  56127. + }
  56128. +
  56129. + /** Check if register values are set correctly */
  56130. + if (rx_fifo_size != DWC_READ_REG32(&global_regs->grxfsiz)) {
  56131. + retval = 0;
  56132. + }
  56133. +
  56134. + if (nptxfifosize.d32 != DWC_READ_REG32(&global_regs->gnptxfsiz)) {
  56135. + retval = 0;
  56136. + }
  56137. +
  56138. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  56139. + if (txfifosize[i].d32 !=
  56140. + DWC_READ_REG32(&global_regs->dtxfsiz[i])) {
  56141. + retval = 0;
  56142. + }
  56143. + }
  56144. +
  56145. + /** If register values are not set correctly, reset old values */
  56146. + if (retval == 0) {
  56147. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fsz_bak);
  56148. +
  56149. + /* Non-periodic Tx FIFO */
  56150. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfsz_bak);
  56151. +
  56152. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  56153. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  56154. + txfsz_bak[i]);
  56155. + }
  56156. + }
  56157. + } else {
  56158. + return 0;
  56159. + }
  56160. +
  56161. + /* Flush the FIFOs */
  56162. + dwc_otg_flush_tx_fifo(core_if, 0x10); /* all Tx FIFOs */
  56163. + dwc_otg_flush_rx_fifo(core_if);
  56164. +
  56165. + return retval;
  56166. +}
  56167. +
  56168. +/**
  56169. + * This function sets a new value for the buffer Alignment setup.
  56170. + */
  56171. +static int cfi_ep_set_tx_fifo_val(uint8_t * buf, dwc_otg_pcd_t * pcd)
  56172. +{
  56173. + int retval;
  56174. + uint32_t fsiz;
  56175. + uint16_t size;
  56176. + uint16_t ep_addr;
  56177. + dwc_otg_pcd_ep_t *ep;
  56178. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  56179. + tx_fifo_size_setup_t *ptxfifoval;
  56180. +
  56181. + ptxfifoval = (tx_fifo_size_setup_t *) buf;
  56182. + ep_addr = ptxfifoval->bEndpointAddress;
  56183. + size = ptxfifoval->wDepth;
  56184. +
  56185. + ep = get_ep_by_addr(pcd, ep_addr);
  56186. +
  56187. + CFI_INFO
  56188. + ("%s: Set Tx FIFO size: endpoint addr=0x%02x, depth=%d, FIFO Num=%d\n",
  56189. + __func__, ep_addr, size, ep->dwc_ep.tx_fifo_num);
  56190. +
  56191. + if (NULL == ep) {
  56192. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  56193. + __func__, ep_addr);
  56194. + return -DWC_E_INVALID;
  56195. + }
  56196. +
  56197. + fsiz = params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1];
  56198. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] = size;
  56199. +
  56200. + if (resize_fifos(GET_CORE_IF(pcd))) {
  56201. + retval = 0;
  56202. + } else {
  56203. + CFI_INFO
  56204. + ("%s: Error setting the feature Tx FIFO Size for EP%d\n",
  56205. + __func__, ep_addr);
  56206. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] = fsiz;
  56207. + retval = -DWC_E_INVALID;
  56208. + }
  56209. +
  56210. + return retval;
  56211. +}
  56212. +
  56213. +/**
  56214. + * This function sets a new value for the buffer Alignment setup.
  56215. + */
  56216. +static int cfi_set_rx_fifo_val(uint8_t * buf, dwc_otg_pcd_t * pcd)
  56217. +{
  56218. + int retval;
  56219. + uint32_t fsiz;
  56220. + uint16_t size;
  56221. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  56222. + rx_fifo_size_setup_t *prxfifoval;
  56223. +
  56224. + prxfifoval = (rx_fifo_size_setup_t *) buf;
  56225. + size = prxfifoval->wDepth;
  56226. +
  56227. + fsiz = params->dev_rx_fifo_size;
  56228. + params->dev_rx_fifo_size = size;
  56229. +
  56230. + if (resize_fifos(GET_CORE_IF(pcd))) {
  56231. + retval = 0;
  56232. + } else {
  56233. + CFI_INFO("%s: Error setting the feature Rx FIFO Size\n",
  56234. + __func__);
  56235. + params->dev_rx_fifo_size = fsiz;
  56236. + retval = -DWC_E_INVALID;
  56237. + }
  56238. +
  56239. + return retval;
  56240. +}
  56241. +
  56242. +/**
  56243. + * This function reads the SG of an EP's buffer setup into the buffer buf
  56244. + */
  56245. +static int cfi_ep_get_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  56246. + struct cfi_usb_ctrlrequest *req)
  56247. +{
  56248. + int retval = -DWC_E_INVALID;
  56249. + uint8_t addr;
  56250. + cfi_ep_t *ep;
  56251. +
  56252. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  56253. + addr = req->wValue & 0xFF;
  56254. + if (addr == 0) /* The address should be non-zero */
  56255. + return retval;
  56256. +
  56257. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  56258. + if (NULL == ep) {
  56259. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  56260. + __func__, addr);
  56261. + return retval;
  56262. + }
  56263. +
  56264. + dwc_memcpy(buf, ep->bm_sg, BS_SG_VAL_DESC_LEN);
  56265. + retval = BS_SG_VAL_DESC_LEN;
  56266. + return retval;
  56267. +}
  56268. +
  56269. +/**
  56270. + * This function reads the Concatenation value of an EP's buffer mode into
  56271. + * the buffer buf
  56272. + */
  56273. +static int cfi_ep_get_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  56274. + struct cfi_usb_ctrlrequest *req)
  56275. +{
  56276. + int retval = -DWC_E_INVALID;
  56277. + uint8_t addr;
  56278. + cfi_ep_t *ep;
  56279. + uint8_t desc_count;
  56280. +
  56281. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  56282. + addr = req->wValue & 0xFF;
  56283. + if (addr == 0) /* The address should be non-zero */
  56284. + return retval;
  56285. +
  56286. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  56287. + if (NULL == ep) {
  56288. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  56289. + __func__, addr);
  56290. + return retval;
  56291. + }
  56292. +
  56293. + /* Copy the header to the buffer */
  56294. + dwc_memcpy(buf, ep->bm_concat, BS_CONCAT_VAL_HDR_LEN);
  56295. + /* Advance the buffer pointer by the header size */
  56296. + buf += BS_CONCAT_VAL_HDR_LEN;
  56297. +
  56298. + desc_count = ep->bm_concat->hdr.bDescCount;
  56299. + /* Copy alll the wTxBytes to the buffer */
  56300. + dwc_memcpy(buf, ep->bm_concat->wTxBytes, sizeof(uid16_t) * desc_count);
  56301. +
  56302. + retval = BS_CONCAT_VAL_HDR_LEN + sizeof(uid16_t) * desc_count;
  56303. + return retval;
  56304. +}
  56305. +
  56306. +/**
  56307. + * This function reads the buffer Alignment value of an EP's buffer mode into
  56308. + * the buffer buf
  56309. + *
  56310. + * @return The total number of bytes copied to the buffer or negative error code.
  56311. + */
  56312. +static int cfi_ep_get_align_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  56313. + struct cfi_usb_ctrlrequest *req)
  56314. +{
  56315. + int retval = -DWC_E_INVALID;
  56316. + uint8_t addr;
  56317. + cfi_ep_t *ep;
  56318. +
  56319. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  56320. + addr = req->wValue & 0xFF;
  56321. + if (addr == 0) /* The address should be non-zero */
  56322. + return retval;
  56323. +
  56324. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  56325. + if (NULL == ep) {
  56326. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  56327. + __func__, addr);
  56328. + return retval;
  56329. + }
  56330. +
  56331. + dwc_memcpy(buf, ep->bm_align, BS_ALIGN_VAL_HDR_LEN);
  56332. + retval = BS_ALIGN_VAL_HDR_LEN;
  56333. +
  56334. + return retval;
  56335. +}
  56336. +
  56337. +/**
  56338. + * This function sets a new value for the specified feature
  56339. + *
  56340. + * @param pcd A pointer to the PCD object
  56341. + *
  56342. + * @return 0 if successful, negative error code otherwise to stall the DCE.
  56343. + */
  56344. +static int cfi_set_feature_value(struct dwc_otg_pcd *pcd)
  56345. +{
  56346. + int retval = -DWC_E_NOT_SUPPORTED;
  56347. + uint16_t wIndex, wValue;
  56348. + uint8_t bRequest;
  56349. + struct dwc_otg_core_if *coreif;
  56350. + cfiobject_t *cfi = pcd->cfi;
  56351. + struct cfi_usb_ctrlrequest *ctrl_req;
  56352. + uint8_t *buf;
  56353. + ctrl_req = &cfi->ctrl_req;
  56354. +
  56355. + buf = pcd->cfi->ctrl_req.data;
  56356. +
  56357. + coreif = GET_CORE_IF(pcd);
  56358. + bRequest = ctrl_req->bRequest;
  56359. + wIndex = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wIndex);
  56360. + wValue = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wValue);
  56361. +
  56362. + /* See which feature is to be modified */
  56363. + switch (wIndex) {
  56364. + case FT_ID_DMA_BUFFER_SETUP:
  56365. + /* Modify the feature */
  56366. + if ((retval = cfi_ep_set_sg_val(buf, pcd)) < 0)
  56367. + return retval;
  56368. +
  56369. + /* And send this request to the gadget */
  56370. + cfi->need_gadget_att = 1;
  56371. + break;
  56372. +
  56373. + case FT_ID_DMA_BUFF_ALIGN:
  56374. + if ((retval = cfi_ep_set_alignment_val(buf, pcd)) < 0)
  56375. + return retval;
  56376. + cfi->need_gadget_att = 1;
  56377. + break;
  56378. +
  56379. + case FT_ID_DMA_CONCAT_SETUP:
  56380. + /* Modify the feature */
  56381. + if ((retval = cfi_ep_set_concat_val(buf, pcd)) < 0)
  56382. + return retval;
  56383. + cfi->need_gadget_att = 1;
  56384. + break;
  56385. +
  56386. + case FT_ID_DMA_CIRCULAR:
  56387. + CFI_INFO("FT_ID_DMA_CIRCULAR\n");
  56388. + break;
  56389. +
  56390. + case FT_ID_THRESHOLD_SETUP:
  56391. + CFI_INFO("FT_ID_THRESHOLD_SETUP\n");
  56392. + break;
  56393. +
  56394. + case FT_ID_DFIFO_DEPTH:
  56395. + CFI_INFO("FT_ID_DFIFO_DEPTH\n");
  56396. + break;
  56397. +
  56398. + case FT_ID_TX_FIFO_DEPTH:
  56399. + CFI_INFO("FT_ID_TX_FIFO_DEPTH\n");
  56400. + if ((retval = cfi_ep_set_tx_fifo_val(buf, pcd)) < 0)
  56401. + return retval;
  56402. + cfi->need_gadget_att = 0;
  56403. + break;
  56404. +
  56405. + case FT_ID_RX_FIFO_DEPTH:
  56406. + CFI_INFO("FT_ID_RX_FIFO_DEPTH\n");
  56407. + if ((retval = cfi_set_rx_fifo_val(buf, pcd)) < 0)
  56408. + return retval;
  56409. + cfi->need_gadget_att = 0;
  56410. + break;
  56411. + }
  56412. +
  56413. + return retval;
  56414. +}
  56415. +
  56416. +#endif //DWC_UTE_CFI
  56417. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_cfi.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cfi.h
  56418. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_cfi.h 1970-01-01 01:00:00.000000000 +0100
  56419. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cfi.h 2014-07-07 10:45:43.000000000 +0200
  56420. @@ -0,0 +1,320 @@
  56421. +/* ==========================================================================
  56422. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  56423. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  56424. + * otherwise expressly agreed to in writing between Synopsys and you.
  56425. + *
  56426. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  56427. + * any End User Software License Agreement or Agreement for Licensed Product
  56428. + * with Synopsys or any supplement thereto. You are permitted to use and
  56429. + * redistribute this Software in source and binary forms, with or without
  56430. + * modification, provided that redistributions of source code must retain this
  56431. + * notice. You may not view, use, disclose, copy or distribute this file or
  56432. + * any information contained herein except pursuant to this license grant from
  56433. + * Synopsys. If you do not agree with this notice, including the disclaimer
  56434. + * below, then you are not authorized to use the Software.
  56435. + *
  56436. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  56437. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  56438. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  56439. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  56440. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  56441. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  56442. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  56443. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  56444. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  56445. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  56446. + * DAMAGE.
  56447. + * ========================================================================== */
  56448. +
  56449. +#if !defined(__DWC_OTG_CFI_H__)
  56450. +#define __DWC_OTG_CFI_H__
  56451. +
  56452. +#include "dwc_otg_pcd.h"
  56453. +#include "dwc_cfi_common.h"
  56454. +
  56455. +/**
  56456. + * @file
  56457. + * This file contains the CFI related OTG PCD specific common constants,
  56458. + * interfaces(functions and macros) and data structures.The CFI Protocol is an
  56459. + * optional interface for internal testing purposes that a DUT may implement to
  56460. + * support testing of configurable features.
  56461. + *
  56462. + */
  56463. +
  56464. +struct dwc_otg_pcd;
  56465. +struct dwc_otg_pcd_ep;
  56466. +
  56467. +/** OTG CFI Features (properties) ID constants */
  56468. +/** This is a request for all Core Features */
  56469. +#define FT_ID_DMA_MODE 0x0001
  56470. +#define FT_ID_DMA_BUFFER_SETUP 0x0002
  56471. +#define FT_ID_DMA_BUFF_ALIGN 0x0003
  56472. +#define FT_ID_DMA_CONCAT_SETUP 0x0004
  56473. +#define FT_ID_DMA_CIRCULAR 0x0005
  56474. +#define FT_ID_THRESHOLD_SETUP 0x0006
  56475. +#define FT_ID_DFIFO_DEPTH 0x0007
  56476. +#define FT_ID_TX_FIFO_DEPTH 0x0008
  56477. +#define FT_ID_RX_FIFO_DEPTH 0x0009
  56478. +
  56479. +/**********************************************************/
  56480. +#define CFI_INFO_DEF
  56481. +
  56482. +#ifdef CFI_INFO_DEF
  56483. +#define CFI_INFO(fmt...) DWC_PRINTF("CFI: " fmt);
  56484. +#else
  56485. +#define CFI_INFO(fmt...)
  56486. +#endif
  56487. +
  56488. +#define min(x,y) ({ \
  56489. + x < y ? x : y; })
  56490. +
  56491. +#define max(x,y) ({ \
  56492. + x > y ? x : y; })
  56493. +
  56494. +/**
  56495. + * Descriptor DMA SG Buffer setup structure (SG buffer). This structure is
  56496. + * also used for setting up a buffer for Circular DDMA.
  56497. + */
  56498. +struct _ddma_sg_buffer_setup {
  56499. +#define BS_SG_VAL_DESC_LEN 6
  56500. + /* The OUT EP address */
  56501. + uint8_t bOutEndpointAddress;
  56502. + /* The IN EP address */
  56503. + uint8_t bInEndpointAddress;
  56504. + /* Number of bytes to put between transfer segments (must be DWORD boundaries) */
  56505. + uint8_t bOffset;
  56506. + /* The number of transfer segments (a DMA descriptors per each segment) */
  56507. + uint8_t bCount;
  56508. + /* Size (in byte) of each transfer segment */
  56509. + uint16_t wSize;
  56510. +} __attribute__ ((packed));
  56511. +typedef struct _ddma_sg_buffer_setup ddma_sg_buffer_setup_t;
  56512. +
  56513. +/** Descriptor DMA Concatenation Buffer setup structure */
  56514. +struct _ddma_concat_buffer_setup_hdr {
  56515. +#define BS_CONCAT_VAL_HDR_LEN 4
  56516. + /* The endpoint for which the buffer is to be set up */
  56517. + uint8_t bEndpointAddress;
  56518. + /* The count of descriptors to be used */
  56519. + uint8_t bDescCount;
  56520. + /* The total size of the transfer */
  56521. + uint16_t wSize;
  56522. +} __attribute__ ((packed));
  56523. +typedef struct _ddma_concat_buffer_setup_hdr ddma_concat_buffer_setup_hdr_t;
  56524. +
  56525. +/** Descriptor DMA Concatenation Buffer setup structure */
  56526. +struct _ddma_concat_buffer_setup {
  56527. + /* The SG header */
  56528. + ddma_concat_buffer_setup_hdr_t hdr;
  56529. +
  56530. + /* The XFER sizes pointer (allocated dynamically) */
  56531. + uint16_t *wTxBytes;
  56532. +} __attribute__ ((packed));
  56533. +typedef struct _ddma_concat_buffer_setup ddma_concat_buffer_setup_t;
  56534. +
  56535. +/** Descriptor DMA Alignment Buffer setup structure */
  56536. +struct _ddma_align_buffer_setup {
  56537. +#define BS_ALIGN_VAL_HDR_LEN 2
  56538. + uint8_t bEndpointAddress;
  56539. + uint8_t bAlign;
  56540. +} __attribute__ ((packed));
  56541. +typedef struct _ddma_align_buffer_setup ddma_align_buffer_setup_t;
  56542. +
  56543. +/** Transmit FIFO Size setup structure */
  56544. +struct _tx_fifo_size_setup {
  56545. + uint8_t bEndpointAddress;
  56546. + uint16_t wDepth;
  56547. +} __attribute__ ((packed));
  56548. +typedef struct _tx_fifo_size_setup tx_fifo_size_setup_t;
  56549. +
  56550. +/** Transmit FIFO Size setup structure */
  56551. +struct _rx_fifo_size_setup {
  56552. + uint16_t wDepth;
  56553. +} __attribute__ ((packed));
  56554. +typedef struct _rx_fifo_size_setup rx_fifo_size_setup_t;
  56555. +
  56556. +/**
  56557. + * struct cfi_usb_ctrlrequest - the CFI implementation of the struct usb_ctrlrequest
  56558. + * This structure encapsulates the standard usb_ctrlrequest and adds a pointer
  56559. + * to the data returned in the data stage of a 3-stage Control Write requests.
  56560. + */
  56561. +struct cfi_usb_ctrlrequest {
  56562. + uint8_t bRequestType;
  56563. + uint8_t bRequest;
  56564. + uint16_t wValue;
  56565. + uint16_t wIndex;
  56566. + uint16_t wLength;
  56567. + uint8_t *data;
  56568. +} UPACKED;
  56569. +
  56570. +/*---------------------------------------------------------------------------*/
  56571. +
  56572. +/**
  56573. + * The CFI wrapper of the enabled and activated dwc_otg_pcd_ep structures.
  56574. + * This structure is used to store the buffer setup data for any
  56575. + * enabled endpoint in the PCD.
  56576. + */
  56577. +struct cfi_ep {
  56578. + /* Entry for the list container */
  56579. + dwc_list_link_t lh;
  56580. + /* Pointer to the active PCD endpoint structure */
  56581. + struct dwc_otg_pcd_ep *ep;
  56582. + /* The last descriptor in the chain of DMA descriptors of the endpoint */
  56583. + struct dwc_otg_dma_desc *dma_desc_last;
  56584. + /* The SG feature value */
  56585. + ddma_sg_buffer_setup_t *bm_sg;
  56586. + /* The Circular feature value */
  56587. + ddma_sg_buffer_setup_t *bm_circ;
  56588. + /* The Concatenation feature value */
  56589. + ddma_concat_buffer_setup_t *bm_concat;
  56590. + /* The Alignment feature value */
  56591. + ddma_align_buffer_setup_t *bm_align;
  56592. + /* XFER length */
  56593. + uint32_t xfer_len;
  56594. + /*
  56595. + * Count of DMA descriptors currently used.
  56596. + * The total should not exceed the MAX_DMA_DESCS_PER_EP value
  56597. + * defined in the dwc_otg_cil.h
  56598. + */
  56599. + uint32_t desc_count;
  56600. +};
  56601. +typedef struct cfi_ep cfi_ep_t;
  56602. +
  56603. +typedef struct cfi_dma_buff {
  56604. +#define CFI_IN_BUF_LEN 1024
  56605. +#define CFI_OUT_BUF_LEN 1024
  56606. + dma_addr_t addr;
  56607. + uint8_t *buf;
  56608. +} cfi_dma_buff_t;
  56609. +
  56610. +struct cfiobject;
  56611. +
  56612. +/**
  56613. + * This is the interface for the CFI operations.
  56614. + *
  56615. + * @param ep_enable Called when any endpoint is enabled and activated.
  56616. + * @param release Called when the CFI object is released and it needs to correctly
  56617. + * deallocate the dynamic memory
  56618. + * @param ctrl_write_complete Called when the data stage of the request is complete
  56619. + */
  56620. +typedef struct cfi_ops {
  56621. + int (*ep_enable) (struct cfiobject * cfi, struct dwc_otg_pcd * pcd,
  56622. + struct dwc_otg_pcd_ep * ep);
  56623. + void *(*ep_alloc_buf) (struct cfiobject * cfi, struct dwc_otg_pcd * pcd,
  56624. + struct dwc_otg_pcd_ep * ep, dma_addr_t * dma,
  56625. + unsigned size, gfp_t flags);
  56626. + void (*release) (struct cfiobject * cfi);
  56627. + int (*ctrl_write_complete) (struct cfiobject * cfi,
  56628. + struct dwc_otg_pcd * pcd);
  56629. + void (*build_descriptors) (struct cfiobject * cfi,
  56630. + struct dwc_otg_pcd * pcd,
  56631. + struct dwc_otg_pcd_ep * ep,
  56632. + dwc_otg_pcd_request_t * req);
  56633. +} cfi_ops_t;
  56634. +
  56635. +struct cfiobject {
  56636. + cfi_ops_t ops;
  56637. + struct dwc_otg_pcd *pcd;
  56638. + struct usb_gadget *gadget;
  56639. +
  56640. + /* Buffers used to send/receive CFI-related request data */
  56641. + cfi_dma_buff_t buf_in;
  56642. + cfi_dma_buff_t buf_out;
  56643. +
  56644. + /* CFI specific Control request wrapper */
  56645. + struct cfi_usb_ctrlrequest ctrl_req;
  56646. +
  56647. + /* The list of active EP's in the PCD of type cfi_ep_t */
  56648. + dwc_list_link_t active_eps;
  56649. +
  56650. + /* This flag shall control the propagation of a specific request
  56651. + * to the gadget's processing routines.
  56652. + * 0 - no gadget handling
  56653. + * 1 - the gadget needs to know about this request (w/o completing a status
  56654. + * phase - just return a 0 to the _setup callback)
  56655. + */
  56656. + uint8_t need_gadget_att;
  56657. +
  56658. + /* Flag indicating whether the status IN phase needs to be
  56659. + * completed by the PCD
  56660. + */
  56661. + uint8_t need_status_in_complete;
  56662. +};
  56663. +typedef struct cfiobject cfiobject_t;
  56664. +
  56665. +#define DUMP_MSG
  56666. +
  56667. +#if defined(DUMP_MSG)
  56668. +static inline void dump_msg(const u8 * buf, unsigned int length)
  56669. +{
  56670. + unsigned int start, num, i;
  56671. + char line[52], *p;
  56672. +
  56673. + if (length >= 512)
  56674. + return;
  56675. +
  56676. + start = 0;
  56677. + while (length > 0) {
  56678. + num = min(length, 16u);
  56679. + p = line;
  56680. + for (i = 0; i < num; ++i) {
  56681. + if (i == 8)
  56682. + *p++ = ' ';
  56683. + DWC_SPRINTF(p, " %02x", buf[i]);
  56684. + p += 3;
  56685. + }
  56686. + *p = 0;
  56687. + DWC_DEBUG("%6x: %s\n", start, line);
  56688. + buf += num;
  56689. + start += num;
  56690. + length -= num;
  56691. + }
  56692. +}
  56693. +#else
  56694. +static inline void dump_msg(const u8 * buf, unsigned int length)
  56695. +{
  56696. +}
  56697. +#endif
  56698. +
  56699. +/**
  56700. + * This function returns a pointer to cfi_ep_t object with the addr address.
  56701. + */
  56702. +static inline struct cfi_ep *get_cfi_ep_by_addr(struct cfiobject *cfi,
  56703. + uint8_t addr)
  56704. +{
  56705. + struct cfi_ep *pcfiep;
  56706. + dwc_list_link_t *tmp;
  56707. +
  56708. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  56709. + pcfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  56710. +
  56711. + if (pcfiep->ep->desc->bEndpointAddress == addr) {
  56712. + return pcfiep;
  56713. + }
  56714. + }
  56715. +
  56716. + return NULL;
  56717. +}
  56718. +
  56719. +/**
  56720. + * This function returns a pointer to cfi_ep_t object that matches
  56721. + * the dwc_otg_pcd_ep object.
  56722. + */
  56723. +static inline struct cfi_ep *get_cfi_ep_by_pcd_ep(struct cfiobject *cfi,
  56724. + struct dwc_otg_pcd_ep *ep)
  56725. +{
  56726. + struct cfi_ep *pcfiep = NULL;
  56727. + dwc_list_link_t *tmp;
  56728. +
  56729. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  56730. + pcfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  56731. + if (pcfiep->ep == ep) {
  56732. + return pcfiep;
  56733. + }
  56734. + }
  56735. + return NULL;
  56736. +}
  56737. +
  56738. +int cfi_setup(struct dwc_otg_pcd *pcd, struct cfi_usb_ctrlrequest *ctrl);
  56739. +
  56740. +#endif /* (__DWC_OTG_CFI_H__) */
  56741. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_cil.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil.c
  56742. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_cil.c 1970-01-01 01:00:00.000000000 +0100
  56743. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil.c 2014-07-07 10:45:43.000000000 +0200
  56744. @@ -0,0 +1,7151 @@
  56745. +/* ==========================================================================
  56746. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.c $
  56747. + * $Revision: #191 $
  56748. + * $Date: 2012/08/10 $
  56749. + * $Change: 2047372 $
  56750. + *
  56751. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  56752. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  56753. + * otherwise expressly agreed to in writing between Synopsys and you.
  56754. + *
  56755. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  56756. + * any End User Software License Agreement or Agreement for Licensed Product
  56757. + * with Synopsys or any supplement thereto. You are permitted to use and
  56758. + * redistribute this Software in source and binary forms, with or without
  56759. + * modification, provided that redistributions of source code must retain this
  56760. + * notice. You may not view, use, disclose, copy or distribute this file or
  56761. + * any information contained herein except pursuant to this license grant from
  56762. + * Synopsys. If you do not agree with this notice, including the disclaimer
  56763. + * below, then you are not authorized to use the Software.
  56764. + *
  56765. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  56766. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  56767. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  56768. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  56769. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  56770. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  56771. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  56772. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  56773. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  56774. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  56775. + * DAMAGE.
  56776. + * ========================================================================== */
  56777. +
  56778. +/** @file
  56779. + *
  56780. + * The Core Interface Layer provides basic services for accessing and
  56781. + * managing the DWC_otg hardware. These services are used by both the
  56782. + * Host Controller Driver and the Peripheral Controller Driver.
  56783. + *
  56784. + * The CIL manages the memory map for the core so that the HCD and PCD
  56785. + * don't have to do this separately. It also handles basic tasks like
  56786. + * reading/writing the registers and data FIFOs in the controller.
  56787. + * Some of the data access functions provide encapsulation of several
  56788. + * operations required to perform a task, such as writing multiple
  56789. + * registers to start a transfer. Finally, the CIL performs basic
  56790. + * services that are not specific to either the host or device modes
  56791. + * of operation. These services include management of the OTG Host
  56792. + * Negotiation Protocol (HNP) and Session Request Protocol (SRP). A
  56793. + * Diagnostic API is also provided to allow testing of the controller
  56794. + * hardware.
  56795. + *
  56796. + * The Core Interface Layer has the following requirements:
  56797. + * - Provides basic controller operations.
  56798. + * - Minimal use of OS services.
  56799. + * - The OS services used will be abstracted by using inline functions
  56800. + * or macros.
  56801. + *
  56802. + */
  56803. +
  56804. +#include "dwc_os.h"
  56805. +#include "dwc_otg_regs.h"
  56806. +#include "dwc_otg_cil.h"
  56807. +
  56808. +static int dwc_otg_setup_params(dwc_otg_core_if_t * core_if);
  56809. +
  56810. +/**
  56811. + * This function is called to initialize the DWC_otg CSR data
  56812. + * structures. The register addresses in the device and host
  56813. + * structures are initialized from the base address supplied by the
  56814. + * caller. The calling function must make the OS calls to get the
  56815. + * base address of the DWC_otg controller registers. The core_params
  56816. + * argument holds the parameters that specify how the core should be
  56817. + * configured.
  56818. + *
  56819. + * @param reg_base_addr Base address of DWC_otg core registers
  56820. + *
  56821. + */
  56822. +dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t * reg_base_addr)
  56823. +{
  56824. + dwc_otg_core_if_t *core_if = 0;
  56825. + dwc_otg_dev_if_t *dev_if = 0;
  56826. + dwc_otg_host_if_t *host_if = 0;
  56827. + uint8_t *reg_base = (uint8_t *) reg_base_addr;
  56828. + int i = 0;
  56829. +
  56830. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, reg_base_addr);
  56831. +
  56832. + core_if = DWC_ALLOC(sizeof(dwc_otg_core_if_t));
  56833. +
  56834. + if (core_if == NULL) {
  56835. + DWC_DEBUGPL(DBG_CIL,
  56836. + "Allocation of dwc_otg_core_if_t failed\n");
  56837. + return 0;
  56838. + }
  56839. + core_if->core_global_regs = (dwc_otg_core_global_regs_t *) reg_base;
  56840. +
  56841. + /*
  56842. + * Allocate the Device Mode structures.
  56843. + */
  56844. + dev_if = DWC_ALLOC(sizeof(dwc_otg_dev_if_t));
  56845. +
  56846. + if (dev_if == NULL) {
  56847. + DWC_DEBUGPL(DBG_CIL, "Allocation of dwc_otg_dev_if_t failed\n");
  56848. + DWC_FREE(core_if);
  56849. + return 0;
  56850. + }
  56851. +
  56852. + dev_if->dev_global_regs =
  56853. + (dwc_otg_device_global_regs_t *) (reg_base +
  56854. + DWC_DEV_GLOBAL_REG_OFFSET);
  56855. +
  56856. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  56857. + dev_if->in_ep_regs[i] = (dwc_otg_dev_in_ep_regs_t *)
  56858. + (reg_base + DWC_DEV_IN_EP_REG_OFFSET +
  56859. + (i * DWC_EP_REG_OFFSET));
  56860. +
  56861. + dev_if->out_ep_regs[i] = (dwc_otg_dev_out_ep_regs_t *)
  56862. + (reg_base + DWC_DEV_OUT_EP_REG_OFFSET +
  56863. + (i * DWC_EP_REG_OFFSET));
  56864. + DWC_DEBUGPL(DBG_CILV, "in_ep_regs[%d]->diepctl=%p\n",
  56865. + i, &dev_if->in_ep_regs[i]->diepctl);
  56866. + DWC_DEBUGPL(DBG_CILV, "out_ep_regs[%d]->doepctl=%p\n",
  56867. + i, &dev_if->out_ep_regs[i]->doepctl);
  56868. + }
  56869. +
  56870. + dev_if->speed = 0; // unknown
  56871. +
  56872. + core_if->dev_if = dev_if;
  56873. +
  56874. + /*
  56875. + * Allocate the Host Mode structures.
  56876. + */
  56877. + host_if = DWC_ALLOC(sizeof(dwc_otg_host_if_t));
  56878. +
  56879. + if (host_if == NULL) {
  56880. + DWC_DEBUGPL(DBG_CIL,
  56881. + "Allocation of dwc_otg_host_if_t failed\n");
  56882. + DWC_FREE(dev_if);
  56883. + DWC_FREE(core_if);
  56884. + return 0;
  56885. + }
  56886. +
  56887. + host_if->host_global_regs = (dwc_otg_host_global_regs_t *)
  56888. + (reg_base + DWC_OTG_HOST_GLOBAL_REG_OFFSET);
  56889. +
  56890. + host_if->hprt0 =
  56891. + (uint32_t *) (reg_base + DWC_OTG_HOST_PORT_REGS_OFFSET);
  56892. +
  56893. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  56894. + host_if->hc_regs[i] = (dwc_otg_hc_regs_t *)
  56895. + (reg_base + DWC_OTG_HOST_CHAN_REGS_OFFSET +
  56896. + (i * DWC_OTG_CHAN_REGS_OFFSET));
  56897. + DWC_DEBUGPL(DBG_CILV, "hc_reg[%d]->hcchar=%p\n",
  56898. + i, &host_if->hc_regs[i]->hcchar);
  56899. + }
  56900. +
  56901. + host_if->num_host_channels = MAX_EPS_CHANNELS;
  56902. + core_if->host_if = host_if;
  56903. +
  56904. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  56905. + core_if->data_fifo[i] =
  56906. + (uint32_t *) (reg_base + DWC_OTG_DATA_FIFO_OFFSET +
  56907. + (i * DWC_OTG_DATA_FIFO_SIZE));
  56908. + DWC_DEBUGPL(DBG_CILV, "data_fifo[%d]=0x%08lx\n",
  56909. + i, (unsigned long)core_if->data_fifo[i]);
  56910. + }
  56911. +
  56912. + core_if->pcgcctl = (uint32_t *) (reg_base + DWC_OTG_PCGCCTL_OFFSET);
  56913. +
  56914. + /* Initiate lx_state to L3 disconnected state */
  56915. + core_if->lx_state = DWC_OTG_L3;
  56916. + /*
  56917. + * Store the contents of the hardware configuration registers here for
  56918. + * easy access later.
  56919. + */
  56920. + core_if->hwcfg1.d32 =
  56921. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg1);
  56922. + core_if->hwcfg2.d32 =
  56923. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg2);
  56924. + core_if->hwcfg3.d32 =
  56925. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg3);
  56926. + core_if->hwcfg4.d32 =
  56927. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg4);
  56928. +
  56929. + /* Force host mode to get HPTXFSIZ exact power on value */
  56930. + {
  56931. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  56932. + gusbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  56933. + gusbcfg.b.force_host_mode = 1;
  56934. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  56935. + dwc_mdelay(100);
  56936. + core_if->hptxfsiz.d32 =
  56937. + DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  56938. + gusbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  56939. + gusbcfg.b.force_host_mode = 0;
  56940. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  56941. + dwc_mdelay(100);
  56942. + }
  56943. +
  56944. + DWC_DEBUGPL(DBG_CILV, "hwcfg1=%08x\n", core_if->hwcfg1.d32);
  56945. + DWC_DEBUGPL(DBG_CILV, "hwcfg2=%08x\n", core_if->hwcfg2.d32);
  56946. + DWC_DEBUGPL(DBG_CILV, "hwcfg3=%08x\n", core_if->hwcfg3.d32);
  56947. + DWC_DEBUGPL(DBG_CILV, "hwcfg4=%08x\n", core_if->hwcfg4.d32);
  56948. +
  56949. + core_if->hcfg.d32 =
  56950. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  56951. + core_if->dcfg.d32 =
  56952. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  56953. +
  56954. + DWC_DEBUGPL(DBG_CILV, "hcfg=%08x\n", core_if->hcfg.d32);
  56955. + DWC_DEBUGPL(DBG_CILV, "dcfg=%08x\n", core_if->dcfg.d32);
  56956. +
  56957. + DWC_DEBUGPL(DBG_CILV, "op_mode=%0x\n", core_if->hwcfg2.b.op_mode);
  56958. + DWC_DEBUGPL(DBG_CILV, "arch=%0x\n", core_if->hwcfg2.b.architecture);
  56959. + DWC_DEBUGPL(DBG_CILV, "num_dev_ep=%d\n", core_if->hwcfg2.b.num_dev_ep);
  56960. + DWC_DEBUGPL(DBG_CILV, "num_host_chan=%d\n",
  56961. + core_if->hwcfg2.b.num_host_chan);
  56962. + DWC_DEBUGPL(DBG_CILV, "nonperio_tx_q_depth=0x%0x\n",
  56963. + core_if->hwcfg2.b.nonperio_tx_q_depth);
  56964. + DWC_DEBUGPL(DBG_CILV, "host_perio_tx_q_depth=0x%0x\n",
  56965. + core_if->hwcfg2.b.host_perio_tx_q_depth);
  56966. + DWC_DEBUGPL(DBG_CILV, "dev_token_q_depth=0x%0x\n",
  56967. + core_if->hwcfg2.b.dev_token_q_depth);
  56968. +
  56969. + DWC_DEBUGPL(DBG_CILV, "Total FIFO SZ=%d\n",
  56970. + core_if->hwcfg3.b.dfifo_depth);
  56971. + DWC_DEBUGPL(DBG_CILV, "xfer_size_cntr_width=%0x\n",
  56972. + core_if->hwcfg3.b.xfer_size_cntr_width);
  56973. +
  56974. + /*
  56975. + * Set the SRP sucess bit for FS-I2c
  56976. + */
  56977. + core_if->srp_success = 0;
  56978. + core_if->srp_timer_started = 0;
  56979. +
  56980. + /*
  56981. + * Create new workqueue and init works
  56982. + */
  56983. + core_if->wq_otg = DWC_WORKQ_ALLOC("dwc_otg");
  56984. + if (core_if->wq_otg == 0) {
  56985. + DWC_WARN("DWC_WORKQ_ALLOC failed\n");
  56986. + DWC_FREE(host_if);
  56987. + DWC_FREE(dev_if);
  56988. + DWC_FREE(core_if);
  56989. + return 0;
  56990. + }
  56991. +
  56992. + core_if->snpsid = DWC_READ_REG32(&core_if->core_global_regs->gsnpsid);
  56993. +
  56994. + DWC_PRINTF("Core Release: %x.%x%x%x\n",
  56995. + (core_if->snpsid >> 12 & 0xF),
  56996. + (core_if->snpsid >> 8 & 0xF),
  56997. + (core_if->snpsid >> 4 & 0xF), (core_if->snpsid & 0xF));
  56998. +
  56999. + core_if->wkp_timer = DWC_TIMER_ALLOC("Wake Up Timer",
  57000. + w_wakeup_detected, core_if);
  57001. + if (core_if->wkp_timer == 0) {
  57002. + DWC_WARN("DWC_TIMER_ALLOC failed\n");
  57003. + DWC_FREE(host_if);
  57004. + DWC_FREE(dev_if);
  57005. + DWC_WORKQ_FREE(core_if->wq_otg);
  57006. + DWC_FREE(core_if);
  57007. + return 0;
  57008. + }
  57009. +
  57010. + if (dwc_otg_setup_params(core_if)) {
  57011. + DWC_WARN("Error while setting core params\n");
  57012. + }
  57013. +
  57014. + core_if->hibernation_suspend = 0;
  57015. +
  57016. + /** ADP initialization */
  57017. + dwc_otg_adp_init(core_if);
  57018. +
  57019. + return core_if;
  57020. +}
  57021. +
  57022. +/**
  57023. + * This function frees the structures allocated by dwc_otg_cil_init().
  57024. + *
  57025. + * @param core_if The core interface pointer returned from
  57026. + * dwc_otg_cil_init().
  57027. + *
  57028. + */
  57029. +void dwc_otg_cil_remove(dwc_otg_core_if_t * core_if)
  57030. +{
  57031. + dctl_data_t dctl = {.d32 = 0 };
  57032. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, core_if);
  57033. +
  57034. + /* Disable all interrupts */
  57035. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, 1, 0);
  57036. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0);
  57037. +
  57038. + dctl.b.sftdiscon = 1;
  57039. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  57040. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0,
  57041. + dctl.d32);
  57042. + }
  57043. +
  57044. + if (core_if->wq_otg) {
  57045. + DWC_WORKQ_WAIT_WORK_DONE(core_if->wq_otg, 500);
  57046. + DWC_WORKQ_FREE(core_if->wq_otg);
  57047. + }
  57048. + if (core_if->dev_if) {
  57049. + DWC_FREE(core_if->dev_if);
  57050. + }
  57051. + if (core_if->host_if) {
  57052. + DWC_FREE(core_if->host_if);
  57053. + }
  57054. +
  57055. + /** Remove ADP Stuff */
  57056. + dwc_otg_adp_remove(core_if);
  57057. + if (core_if->core_params) {
  57058. + DWC_FREE(core_if->core_params);
  57059. + }
  57060. + if (core_if->wkp_timer) {
  57061. + DWC_TIMER_FREE(core_if->wkp_timer);
  57062. + }
  57063. + if (core_if->srp_timer) {
  57064. + DWC_TIMER_FREE(core_if->srp_timer);
  57065. + }
  57066. + DWC_FREE(core_if);
  57067. +}
  57068. +
  57069. +/**
  57070. + * This function enables the controller's Global Interrupt in the AHB Config
  57071. + * register.
  57072. + *
  57073. + * @param core_if Programming view of DWC_otg controller.
  57074. + */
  57075. +void dwc_otg_enable_global_interrupts(dwc_otg_core_if_t * core_if)
  57076. +{
  57077. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  57078. + ahbcfg.b.glblintrmsk = 1; /* Enable interrupts */
  57079. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, 0, ahbcfg.d32);
  57080. +}
  57081. +
  57082. +/**
  57083. + * This function disables the controller's Global Interrupt in the AHB Config
  57084. + * register.
  57085. + *
  57086. + * @param core_if Programming view of DWC_otg controller.
  57087. + */
  57088. +void dwc_otg_disable_global_interrupts(dwc_otg_core_if_t * core_if)
  57089. +{
  57090. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  57091. + ahbcfg.b.glblintrmsk = 1; /* Disable interrupts */
  57092. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, ahbcfg.d32, 0);
  57093. +}
  57094. +
  57095. +/**
  57096. + * This function initializes the commmon interrupts, used in both
  57097. + * device and host modes.
  57098. + *
  57099. + * @param core_if Programming view of the DWC_otg controller
  57100. + *
  57101. + */
  57102. +static void dwc_otg_enable_common_interrupts(dwc_otg_core_if_t * core_if)
  57103. +{
  57104. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  57105. + gintmsk_data_t intr_mask = {.d32 = 0 };
  57106. +
  57107. + /* Clear any pending OTG Interrupts */
  57108. + DWC_WRITE_REG32(&global_regs->gotgint, 0xFFFFFFFF);
  57109. +
  57110. + /* Clear any pending interrupts */
  57111. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  57112. +
  57113. + /*
  57114. + * Enable the interrupts in the GINTMSK.
  57115. + */
  57116. + intr_mask.b.modemismatch = 1;
  57117. + intr_mask.b.otgintr = 1;
  57118. +
  57119. + if (!core_if->dma_enable) {
  57120. + intr_mask.b.rxstsqlvl = 1;
  57121. + }
  57122. +
  57123. + intr_mask.b.conidstschng = 1;
  57124. + intr_mask.b.wkupintr = 1;
  57125. + intr_mask.b.disconnect = 0;
  57126. + intr_mask.b.usbsuspend = 1;
  57127. + intr_mask.b.sessreqintr = 1;
  57128. +#ifdef CONFIG_USB_DWC_OTG_LPM
  57129. + if (core_if->core_params->lpm_enable) {
  57130. + intr_mask.b.lpmtranrcvd = 1;
  57131. + }
  57132. +#endif
  57133. + DWC_WRITE_REG32(&global_regs->gintmsk, intr_mask.d32);
  57134. +}
  57135. +
  57136. +/*
  57137. + * The restore operation is modified to support Synopsys Emulated Powerdown and
  57138. + * Hibernation. This function is for exiting from Device mode hibernation by
  57139. + * Host Initiated Resume/Reset and Device Initiated Remote-Wakeup.
  57140. + * @param core_if Programming view of DWC_otg controller.
  57141. + * @param rem_wakeup - indicates whether resume is initiated by Device or Host.
  57142. + * @param reset - indicates whether resume is initiated by Reset.
  57143. + */
  57144. +int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  57145. + int rem_wakeup, int reset)
  57146. +{
  57147. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  57148. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  57149. + dctl_data_t dctl = {.d32 = 0 };
  57150. +
  57151. + int timeout = 2000;
  57152. +
  57153. + if (!core_if->hibernation_suspend) {
  57154. + DWC_PRINTF("Already exited from Hibernation\n");
  57155. + return 1;
  57156. + }
  57157. +
  57158. + DWC_DEBUGPL(DBG_PCD, "%s called\n", __FUNCTION__);
  57159. + /* Switch-on voltage to the core */
  57160. + gpwrdn.b.pwrdnswtch = 1;
  57161. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  57162. + dwc_udelay(10);
  57163. +
  57164. + /* Reset core */
  57165. + gpwrdn.d32 = 0;
  57166. + gpwrdn.b.pwrdnrstn = 1;
  57167. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  57168. + dwc_udelay(10);
  57169. +
  57170. + /* Assert Restore signal */
  57171. + gpwrdn.d32 = 0;
  57172. + gpwrdn.b.restore = 1;
  57173. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  57174. + dwc_udelay(10);
  57175. +
  57176. + /* Disable power clamps */
  57177. + gpwrdn.d32 = 0;
  57178. + gpwrdn.b.pwrdnclmp = 1;
  57179. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  57180. +
  57181. + if (rem_wakeup) {
  57182. + dwc_udelay(70);
  57183. + }
  57184. +
  57185. + /* Deassert Reset core */
  57186. + gpwrdn.d32 = 0;
  57187. + gpwrdn.b.pwrdnrstn = 1;
  57188. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  57189. + dwc_udelay(10);
  57190. +
  57191. + /* Disable PMU interrupt */
  57192. + gpwrdn.d32 = 0;
  57193. + gpwrdn.b.pmuintsel = 1;
  57194. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  57195. +
  57196. + /* Mask interrupts from gpwrdn */
  57197. + gpwrdn.d32 = 0;
  57198. + gpwrdn.b.connect_det_msk = 1;
  57199. + gpwrdn.b.srp_det_msk = 1;
  57200. + gpwrdn.b.disconn_det_msk = 1;
  57201. + gpwrdn.b.rst_det_msk = 1;
  57202. + gpwrdn.b.lnstchng_msk = 1;
  57203. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  57204. +
  57205. + /* Indicates that we are going out from hibernation */
  57206. + core_if->hibernation_suspend = 0;
  57207. +
  57208. + /*
  57209. + * Set Restore Essential Regs bit in PCGCCTL register, restore_mode = 1
  57210. + * indicates restore from remote_wakeup
  57211. + */
  57212. + restore_essential_regs(core_if, rem_wakeup, 0);
  57213. +
  57214. + /*
  57215. + * Wait a little for seeing new value of variable hibernation_suspend if
  57216. + * Restore done interrupt received before polling
  57217. + */
  57218. + dwc_udelay(10);
  57219. +
  57220. + if (core_if->hibernation_suspend == 0) {
  57221. + /*
  57222. + * Wait For Restore_done Interrupt. This mechanism of polling the
  57223. + * interrupt is introduced to avoid any possible race conditions
  57224. + */
  57225. + do {
  57226. + gintsts_data_t gintsts;
  57227. + gintsts.d32 =
  57228. + DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  57229. + if (gintsts.b.restoredone) {
  57230. + gintsts.d32 = 0;
  57231. + gintsts.b.restoredone = 1;
  57232. + DWC_WRITE_REG32(&core_if->core_global_regs->
  57233. + gintsts, gintsts.d32);
  57234. + DWC_PRINTF("Restore Done Interrupt seen\n");
  57235. + break;
  57236. + }
  57237. + dwc_udelay(10);
  57238. + } while (--timeout);
  57239. + if (!timeout) {
  57240. + DWC_PRINTF("Restore Done interrupt wasn't generated here\n");
  57241. + }
  57242. + }
  57243. + /* Clear all pending interupts */
  57244. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  57245. +
  57246. + /* De-assert Restore */
  57247. + gpwrdn.d32 = 0;
  57248. + gpwrdn.b.restore = 1;
  57249. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  57250. + dwc_udelay(10);
  57251. +
  57252. + if (!rem_wakeup) {
  57253. + pcgcctl.d32 = 0;
  57254. + pcgcctl.b.rstpdwnmodule = 1;
  57255. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  57256. + }
  57257. +
  57258. + /* Restore GUSBCFG and DCFG */
  57259. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  57260. + core_if->gr_backup->gusbcfg_local);
  57261. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  57262. + core_if->dr_backup->dcfg);
  57263. +
  57264. + /* De-assert Wakeup Logic */
  57265. + gpwrdn.d32 = 0;
  57266. + gpwrdn.b.pmuactv = 1;
  57267. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  57268. + dwc_udelay(10);
  57269. +
  57270. + if (!rem_wakeup) {
  57271. + /* Set Device programming done bit */
  57272. + dctl.b.pwronprgdone = 1;
  57273. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  57274. + } else {
  57275. + /* Start Remote Wakeup Signaling */
  57276. + dctl.d32 = core_if->dr_backup->dctl;
  57277. + dctl.b.rmtwkupsig = 1;
  57278. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  57279. + }
  57280. +
  57281. + dwc_mdelay(2);
  57282. + /* Clear all pending interupts */
  57283. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  57284. +
  57285. + /* Restore global registers */
  57286. + dwc_otg_restore_global_regs(core_if);
  57287. + /* Restore device global registers */
  57288. + dwc_otg_restore_dev_regs(core_if, rem_wakeup);
  57289. +
  57290. + if (rem_wakeup) {
  57291. + dwc_mdelay(7);
  57292. + dctl.d32 = 0;
  57293. + dctl.b.rmtwkupsig = 1;
  57294. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  57295. + }
  57296. +
  57297. + core_if->hibernation_suspend = 0;
  57298. + /* The core will be in ON STATE */
  57299. + core_if->lx_state = DWC_OTG_L0;
  57300. + DWC_PRINTF("Hibernation recovery completes here\n");
  57301. +
  57302. + return 1;
  57303. +}
  57304. +
  57305. +/*
  57306. + * The restore operation is modified to support Synopsys Emulated Powerdown and
  57307. + * Hibernation. This function is for exiting from Host mode hibernation by
  57308. + * Host Initiated Resume/Reset and Device Initiated Remote-Wakeup.
  57309. + * @param core_if Programming view of DWC_otg controller.
  57310. + * @param rem_wakeup - indicates whether resume is initiated by Device or Host.
  57311. + * @param reset - indicates whether resume is initiated by Reset.
  57312. + */
  57313. +int dwc_otg_host_hibernation_restore(dwc_otg_core_if_t * core_if,
  57314. + int rem_wakeup, int reset)
  57315. +{
  57316. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  57317. + hprt0_data_t hprt0 = {.d32 = 0 };
  57318. +
  57319. + int timeout = 2000;
  57320. +
  57321. + DWC_DEBUGPL(DBG_HCD, "%s called\n", __FUNCTION__);
  57322. + /* Switch-on voltage to the core */
  57323. + gpwrdn.b.pwrdnswtch = 1;
  57324. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  57325. + dwc_udelay(10);
  57326. +
  57327. + /* Reset core */
  57328. + gpwrdn.d32 = 0;
  57329. + gpwrdn.b.pwrdnrstn = 1;
  57330. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  57331. + dwc_udelay(10);
  57332. +
  57333. + /* Assert Restore signal */
  57334. + gpwrdn.d32 = 0;
  57335. + gpwrdn.b.restore = 1;
  57336. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  57337. + dwc_udelay(10);
  57338. +
  57339. + /* Disable power clamps */
  57340. + gpwrdn.d32 = 0;
  57341. + gpwrdn.b.pwrdnclmp = 1;
  57342. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  57343. +
  57344. + if (!rem_wakeup) {
  57345. + dwc_udelay(50);
  57346. + }
  57347. +
  57348. + /* Deassert Reset core */
  57349. + gpwrdn.d32 = 0;
  57350. + gpwrdn.b.pwrdnrstn = 1;
  57351. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  57352. + dwc_udelay(10);
  57353. +
  57354. + /* Disable PMU interrupt */
  57355. + gpwrdn.d32 = 0;
  57356. + gpwrdn.b.pmuintsel = 1;
  57357. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  57358. +
  57359. + gpwrdn.d32 = 0;
  57360. + gpwrdn.b.connect_det_msk = 1;
  57361. + gpwrdn.b.srp_det_msk = 1;
  57362. + gpwrdn.b.disconn_det_msk = 1;
  57363. + gpwrdn.b.rst_det_msk = 1;
  57364. + gpwrdn.b.lnstchng_msk = 1;
  57365. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  57366. +
  57367. + /* Indicates that we are going out from hibernation */
  57368. + core_if->hibernation_suspend = 0;
  57369. +
  57370. + /* Set Restore Essential Regs bit in PCGCCTL register */
  57371. + restore_essential_regs(core_if, rem_wakeup, 1);
  57372. +
  57373. + /* Wait a little for seeing new value of variable hibernation_suspend if
  57374. + * Restore done interrupt received before polling */
  57375. + dwc_udelay(10);
  57376. +
  57377. + if (core_if->hibernation_suspend == 0) {
  57378. + /* Wait For Restore_done Interrupt. This mechanism of polling the
  57379. + * interrupt is introduced to avoid any possible race conditions
  57380. + */
  57381. + do {
  57382. + gintsts_data_t gintsts;
  57383. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  57384. + if (gintsts.b.restoredone) {
  57385. + gintsts.d32 = 0;
  57386. + gintsts.b.restoredone = 1;
  57387. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  57388. + DWC_DEBUGPL(DBG_HCD,"Restore Done Interrupt seen\n");
  57389. + break;
  57390. + }
  57391. + dwc_udelay(10);
  57392. + } while (--timeout);
  57393. + if (!timeout) {
  57394. + DWC_WARN("Restore Done interrupt wasn't generated\n");
  57395. + }
  57396. + }
  57397. +
  57398. + /* Set the flag's value to 0 again after receiving restore done interrupt */
  57399. + core_if->hibernation_suspend = 0;
  57400. +
  57401. + /* This step is not described in functional spec but if not wait for this
  57402. + * delay, mismatch interrupts occurred because just after restore core is
  57403. + * in Device mode(gintsts.curmode == 0) */
  57404. + dwc_mdelay(100);
  57405. +
  57406. + /* Clear all pending interrupts */
  57407. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  57408. +
  57409. + /* De-assert Restore */
  57410. + gpwrdn.d32 = 0;
  57411. + gpwrdn.b.restore = 1;
  57412. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  57413. + dwc_udelay(10);
  57414. +
  57415. + /* Restore GUSBCFG and HCFG */
  57416. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  57417. + core_if->gr_backup->gusbcfg_local);
  57418. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg,
  57419. + core_if->hr_backup->hcfg_local);
  57420. +
  57421. + /* De-assert Wakeup Logic */
  57422. + gpwrdn.d32 = 0;
  57423. + gpwrdn.b.pmuactv = 1;
  57424. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  57425. + dwc_udelay(10);
  57426. +
  57427. + /* Start the Resume operation by programming HPRT0 */
  57428. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  57429. + hprt0.b.prtpwr = 1;
  57430. + hprt0.b.prtena = 0;
  57431. + hprt0.b.prtsusp = 0;
  57432. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  57433. +
  57434. + DWC_PRINTF("Resume Starts Now\n");
  57435. + if (!reset) { // Indicates it is Resume Operation
  57436. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  57437. + hprt0.b.prtres = 1;
  57438. + hprt0.b.prtpwr = 1;
  57439. + hprt0.b.prtena = 0;
  57440. + hprt0.b.prtsusp = 0;
  57441. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  57442. +
  57443. + if (!rem_wakeup)
  57444. + hprt0.b.prtres = 0;
  57445. + /* Wait for Resume time and then program HPRT again */
  57446. + dwc_mdelay(100);
  57447. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  57448. +
  57449. + } else { // Indicates it is Reset Operation
  57450. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  57451. + hprt0.b.prtrst = 1;
  57452. + hprt0.b.prtpwr = 1;
  57453. + hprt0.b.prtena = 0;
  57454. + hprt0.b.prtsusp = 0;
  57455. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  57456. + /* Wait for Reset time and then program HPRT again */
  57457. + dwc_mdelay(60);
  57458. + hprt0.b.prtrst = 0;
  57459. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  57460. + }
  57461. + /* Clear all interrupt status */
  57462. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  57463. + hprt0.b.prtconndet = 1;
  57464. + hprt0.b.prtenchng = 1;
  57465. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  57466. +
  57467. + /* Clear all pending interupts */
  57468. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  57469. +
  57470. + /* Restore global registers */
  57471. + dwc_otg_restore_global_regs(core_if);
  57472. + /* Restore host global registers */
  57473. + dwc_otg_restore_host_regs(core_if, reset);
  57474. +
  57475. + /* The core will be in ON STATE */
  57476. + core_if->lx_state = DWC_OTG_L0;
  57477. + DWC_PRINTF("Hibernation recovery is complete here\n");
  57478. + return 0;
  57479. +}
  57480. +
  57481. +/** Saves some register values into system memory. */
  57482. +int dwc_otg_save_global_regs(dwc_otg_core_if_t * core_if)
  57483. +{
  57484. + struct dwc_otg_global_regs_backup *gr;
  57485. + int i;
  57486. +
  57487. + gr = core_if->gr_backup;
  57488. + if (!gr) {
  57489. + gr = DWC_ALLOC(sizeof(*gr));
  57490. + if (!gr) {
  57491. + return -DWC_E_NO_MEMORY;
  57492. + }
  57493. + core_if->gr_backup = gr;
  57494. + }
  57495. +
  57496. + gr->gotgctl_local = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  57497. + gr->gintmsk_local = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  57498. + gr->gahbcfg_local = DWC_READ_REG32(&core_if->core_global_regs->gahbcfg);
  57499. + gr->gusbcfg_local = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  57500. + gr->grxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  57501. + gr->gnptxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz);
  57502. + gr->hptxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  57503. +#ifdef CONFIG_USB_DWC_OTG_LPM
  57504. + gr->glpmcfg_local = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  57505. +#endif
  57506. + gr->gi2cctl_local = DWC_READ_REG32(&core_if->core_global_regs->gi2cctl);
  57507. + gr->pcgcctl_local = DWC_READ_REG32(core_if->pcgcctl);
  57508. + gr->gdfifocfg_local =
  57509. + DWC_READ_REG32(&core_if->core_global_regs->gdfifocfg);
  57510. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  57511. + gr->dtxfsiz_local[i] =
  57512. + DWC_READ_REG32(&(core_if->core_global_regs->dtxfsiz[i]));
  57513. + }
  57514. +
  57515. + DWC_DEBUGPL(DBG_ANY, "===========Backing Global registers==========\n");
  57516. + DWC_DEBUGPL(DBG_ANY, "Backed up gotgctl = %08x\n", gr->gotgctl_local);
  57517. + DWC_DEBUGPL(DBG_ANY, "Backed up gintmsk = %08x\n", gr->gintmsk_local);
  57518. + DWC_DEBUGPL(DBG_ANY, "Backed up gahbcfg = %08x\n", gr->gahbcfg_local);
  57519. + DWC_DEBUGPL(DBG_ANY, "Backed up gusbcfg = %08x\n", gr->gusbcfg_local);
  57520. + DWC_DEBUGPL(DBG_ANY, "Backed up grxfsiz = %08x\n", gr->grxfsiz_local);
  57521. + DWC_DEBUGPL(DBG_ANY, "Backed up gnptxfsiz = %08x\n",
  57522. + gr->gnptxfsiz_local);
  57523. + DWC_DEBUGPL(DBG_ANY, "Backed up hptxfsiz = %08x\n",
  57524. + gr->hptxfsiz_local);
  57525. +#ifdef CONFIG_USB_DWC_OTG_LPM
  57526. + DWC_DEBUGPL(DBG_ANY, "Backed up glpmcfg = %08x\n", gr->glpmcfg_local);
  57527. +#endif
  57528. + DWC_DEBUGPL(DBG_ANY, "Backed up gi2cctl = %08x\n", gr->gi2cctl_local);
  57529. + DWC_DEBUGPL(DBG_ANY, "Backed up pcgcctl = %08x\n", gr->pcgcctl_local);
  57530. + DWC_DEBUGPL(DBG_ANY,"Backed up gdfifocfg = %08x\n",gr->gdfifocfg_local);
  57531. +
  57532. + return 0;
  57533. +}
  57534. +
  57535. +/** Saves GINTMSK register before setting the msk bits. */
  57536. +int dwc_otg_save_gintmsk_reg(dwc_otg_core_if_t * core_if)
  57537. +{
  57538. + struct dwc_otg_global_regs_backup *gr;
  57539. +
  57540. + gr = core_if->gr_backup;
  57541. + if (!gr) {
  57542. + gr = DWC_ALLOC(sizeof(*gr));
  57543. + if (!gr) {
  57544. + return -DWC_E_NO_MEMORY;
  57545. + }
  57546. + core_if->gr_backup = gr;
  57547. + }
  57548. +
  57549. + gr->gintmsk_local = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  57550. +
  57551. + DWC_DEBUGPL(DBG_ANY,"=============Backing GINTMSK registers============\n");
  57552. + DWC_DEBUGPL(DBG_ANY, "Backed up gintmsk = %08x\n", gr->gintmsk_local);
  57553. +
  57554. + return 0;
  57555. +}
  57556. +
  57557. +int dwc_otg_save_dev_regs(dwc_otg_core_if_t * core_if)
  57558. +{
  57559. + struct dwc_otg_dev_regs_backup *dr;
  57560. + int i;
  57561. +
  57562. + dr = core_if->dr_backup;
  57563. + if (!dr) {
  57564. + dr = DWC_ALLOC(sizeof(*dr));
  57565. + if (!dr) {
  57566. + return -DWC_E_NO_MEMORY;
  57567. + }
  57568. + core_if->dr_backup = dr;
  57569. + }
  57570. +
  57571. + dr->dcfg = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  57572. + dr->dctl = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  57573. + dr->daintmsk =
  57574. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  57575. + dr->diepmsk =
  57576. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->diepmsk);
  57577. + dr->doepmsk =
  57578. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->doepmsk);
  57579. +
  57580. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  57581. + dr->diepctl[i] =
  57582. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl);
  57583. + dr->dieptsiz[i] =
  57584. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->dieptsiz);
  57585. + dr->diepdma[i] =
  57586. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepdma);
  57587. + }
  57588. +
  57589. + DWC_DEBUGPL(DBG_ANY,
  57590. + "=============Backing Host registers==============\n");
  57591. + DWC_DEBUGPL(DBG_ANY, "Backed up dcfg = %08x\n", dr->dcfg);
  57592. + DWC_DEBUGPL(DBG_ANY, "Backed up dctl = %08x\n", dr->dctl);
  57593. + DWC_DEBUGPL(DBG_ANY, "Backed up daintmsk = %08x\n",
  57594. + dr->daintmsk);
  57595. + DWC_DEBUGPL(DBG_ANY, "Backed up diepmsk = %08x\n", dr->diepmsk);
  57596. + DWC_DEBUGPL(DBG_ANY, "Backed up doepmsk = %08x\n", dr->doepmsk);
  57597. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  57598. + DWC_DEBUGPL(DBG_ANY, "Backed up diepctl[%d] = %08x\n", i,
  57599. + dr->diepctl[i]);
  57600. + DWC_DEBUGPL(DBG_ANY, "Backed up dieptsiz[%d] = %08x\n",
  57601. + i, dr->dieptsiz[i]);
  57602. + DWC_DEBUGPL(DBG_ANY, "Backed up diepdma[%d] = %08x\n", i,
  57603. + dr->diepdma[i]);
  57604. + }
  57605. +
  57606. + return 0;
  57607. +}
  57608. +
  57609. +int dwc_otg_save_host_regs(dwc_otg_core_if_t * core_if)
  57610. +{
  57611. + struct dwc_otg_host_regs_backup *hr;
  57612. + int i;
  57613. +
  57614. + hr = core_if->hr_backup;
  57615. + if (!hr) {
  57616. + hr = DWC_ALLOC(sizeof(*hr));
  57617. + if (!hr) {
  57618. + return -DWC_E_NO_MEMORY;
  57619. + }
  57620. + core_if->hr_backup = hr;
  57621. + }
  57622. +
  57623. + hr->hcfg_local =
  57624. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  57625. + hr->haintmsk_local =
  57626. + DWC_READ_REG32(&core_if->host_if->host_global_regs->haintmsk);
  57627. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  57628. + hr->hcintmsk_local[i] =
  57629. + DWC_READ_REG32(&core_if->host_if->hc_regs[i]->hcintmsk);
  57630. + }
  57631. + hr->hprt0_local = DWC_READ_REG32(core_if->host_if->hprt0);
  57632. + hr->hfir_local =
  57633. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  57634. +
  57635. + DWC_DEBUGPL(DBG_ANY,
  57636. + "=============Backing Host registers===============\n");
  57637. + DWC_DEBUGPL(DBG_ANY, "Backed up hcfg = %08x\n",
  57638. + hr->hcfg_local);
  57639. + DWC_DEBUGPL(DBG_ANY, "Backed up haintmsk = %08x\n", hr->haintmsk_local);
  57640. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  57641. + DWC_DEBUGPL(DBG_ANY, "Backed up hcintmsk[%02d]=%08x\n", i,
  57642. + hr->hcintmsk_local[i]);
  57643. + }
  57644. + DWC_DEBUGPL(DBG_ANY, "Backed up hprt0 = %08x\n",
  57645. + hr->hprt0_local);
  57646. + DWC_DEBUGPL(DBG_ANY, "Backed up hfir = %08x\n",
  57647. + hr->hfir_local);
  57648. +
  57649. + return 0;
  57650. +}
  57651. +
  57652. +int dwc_otg_restore_global_regs(dwc_otg_core_if_t *core_if)
  57653. +{
  57654. + struct dwc_otg_global_regs_backup *gr;
  57655. + int i;
  57656. +
  57657. + gr = core_if->gr_backup;
  57658. + if (!gr) {
  57659. + return -DWC_E_INVALID;
  57660. + }
  57661. +
  57662. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, gr->gotgctl_local);
  57663. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gr->gintmsk_local);
  57664. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gr->gusbcfg_local);
  57665. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gr->gahbcfg_local);
  57666. + DWC_WRITE_REG32(&core_if->core_global_regs->grxfsiz, gr->grxfsiz_local);
  57667. + DWC_WRITE_REG32(&core_if->core_global_regs->gnptxfsiz,
  57668. + gr->gnptxfsiz_local);
  57669. + DWC_WRITE_REG32(&core_if->core_global_regs->hptxfsiz,
  57670. + gr->hptxfsiz_local);
  57671. + DWC_WRITE_REG32(&core_if->core_global_regs->gdfifocfg,
  57672. + gr->gdfifocfg_local);
  57673. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  57674. + DWC_WRITE_REG32(&core_if->core_global_regs->dtxfsiz[i],
  57675. + gr->dtxfsiz_local[i]);
  57676. + }
  57677. +
  57678. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  57679. + DWC_WRITE_REG32(core_if->host_if->hprt0, 0x0000100A);
  57680. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg,
  57681. + (gr->gahbcfg_local));
  57682. + return 0;
  57683. +}
  57684. +
  57685. +int dwc_otg_restore_dev_regs(dwc_otg_core_if_t * core_if, int rem_wakeup)
  57686. +{
  57687. + struct dwc_otg_dev_regs_backup *dr;
  57688. + int i;
  57689. +
  57690. + dr = core_if->dr_backup;
  57691. +
  57692. + if (!dr) {
  57693. + return -DWC_E_INVALID;
  57694. + }
  57695. +
  57696. + if (!rem_wakeup) {
  57697. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  57698. + dr->dctl);
  57699. + }
  57700. +
  57701. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daintmsk, dr->daintmsk);
  57702. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->diepmsk, dr->diepmsk);
  57703. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->doepmsk, dr->doepmsk);
  57704. +
  57705. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  57706. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->dieptsiz, dr->dieptsiz[i]);
  57707. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->diepdma, dr->diepdma[i]);
  57708. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl, dr->diepctl[i]);
  57709. + }
  57710. +
  57711. + return 0;
  57712. +}
  57713. +
  57714. +int dwc_otg_restore_host_regs(dwc_otg_core_if_t * core_if, int reset)
  57715. +{
  57716. + struct dwc_otg_host_regs_backup *hr;
  57717. + int i;
  57718. + hr = core_if->hr_backup;
  57719. +
  57720. + if (!hr) {
  57721. + return -DWC_E_INVALID;
  57722. + }
  57723. +
  57724. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hr->hcfg_local);
  57725. + //if (!reset)
  57726. + //{
  57727. + // DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hfir, hr->hfir_local);
  57728. + //}
  57729. +
  57730. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haintmsk,
  57731. + hr->haintmsk_local);
  57732. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  57733. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcintmsk,
  57734. + hr->hcintmsk_local[i]);
  57735. + }
  57736. +
  57737. + return 0;
  57738. +}
  57739. +
  57740. +int restore_lpm_i2c_regs(dwc_otg_core_if_t * core_if)
  57741. +{
  57742. + struct dwc_otg_global_regs_backup *gr;
  57743. +
  57744. + gr = core_if->gr_backup;
  57745. +
  57746. + /* Restore values for LPM and I2C */
  57747. +#ifdef CONFIG_USB_DWC_OTG_LPM
  57748. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, gr->glpmcfg_local);
  57749. +#endif
  57750. + DWC_WRITE_REG32(&core_if->core_global_regs->gi2cctl, gr->gi2cctl_local);
  57751. +
  57752. + return 0;
  57753. +}
  57754. +
  57755. +int restore_essential_regs(dwc_otg_core_if_t * core_if, int rmode, int is_host)
  57756. +{
  57757. + struct dwc_otg_global_regs_backup *gr;
  57758. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  57759. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  57760. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  57761. + gintmsk_data_t gintmsk = {.d32 = 0 };
  57762. +
  57763. + /* Restore LPM and I2C registers */
  57764. + restore_lpm_i2c_regs(core_if);
  57765. +
  57766. + /* Set PCGCCTL to 0 */
  57767. + DWC_WRITE_REG32(core_if->pcgcctl, 0x00000000);
  57768. +
  57769. + gr = core_if->gr_backup;
  57770. + /* Load restore values for [31:14] bits */
  57771. + DWC_WRITE_REG32(core_if->pcgcctl,
  57772. + ((gr->pcgcctl_local & 0xffffc000) | 0x00020000));
  57773. +
  57774. + /* Umnask global Interrupt in GAHBCFG and restore it */
  57775. + gahbcfg.d32 = gr->gahbcfg_local;
  57776. + gahbcfg.b.glblintrmsk = 1;
  57777. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gahbcfg.d32);
  57778. +
  57779. + /* Clear all pending interupts */
  57780. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  57781. +
  57782. + /* Unmask restore done interrupt */
  57783. + gintmsk.b.restoredone = 1;
  57784. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32);
  57785. +
  57786. + /* Restore GUSBCFG and HCFG/DCFG */
  57787. + gusbcfg.d32 = core_if->gr_backup->gusbcfg_local;
  57788. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  57789. +
  57790. + if (is_host) {
  57791. + hcfg_data_t hcfg = {.d32 = 0 };
  57792. + hcfg.d32 = core_if->hr_backup->hcfg_local;
  57793. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg,
  57794. + hcfg.d32);
  57795. +
  57796. + /* Load restore values for [31:14] bits */
  57797. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  57798. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  57799. +
  57800. + if (rmode)
  57801. + pcgcctl.b.restoremode = 1;
  57802. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  57803. + dwc_udelay(10);
  57804. +
  57805. + /* Load restore values for [31:14] bits and set EssRegRestored bit */
  57806. + pcgcctl.d32 = gr->pcgcctl_local | 0xffffc000;
  57807. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  57808. + pcgcctl.b.ess_reg_restored = 1;
  57809. + if (rmode)
  57810. + pcgcctl.b.restoremode = 1;
  57811. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  57812. + } else {
  57813. + dcfg_data_t dcfg = {.d32 = 0 };
  57814. + dcfg.d32 = core_if->dr_backup->dcfg;
  57815. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  57816. +
  57817. + /* Load restore values for [31:14] bits */
  57818. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  57819. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  57820. + if (!rmode) {
  57821. + pcgcctl.d32 |= 0x208;
  57822. + }
  57823. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  57824. + dwc_udelay(10);
  57825. +
  57826. + /* Load restore values for [31:14] bits */
  57827. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  57828. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  57829. + pcgcctl.b.ess_reg_restored = 1;
  57830. + if (!rmode)
  57831. + pcgcctl.d32 |= 0x208;
  57832. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  57833. + }
  57834. +
  57835. + return 0;
  57836. +}
  57837. +
  57838. +/**
  57839. + * Initializes the FSLSPClkSel field of the HCFG register depending on the PHY
  57840. + * type.
  57841. + */
  57842. +static void init_fslspclksel(dwc_otg_core_if_t * core_if)
  57843. +{
  57844. + uint32_t val;
  57845. + hcfg_data_t hcfg;
  57846. +
  57847. + if (((core_if->hwcfg2.b.hs_phy_type == 2) &&
  57848. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  57849. + (core_if->core_params->ulpi_fs_ls)) ||
  57850. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  57851. + /* Full speed PHY */
  57852. + val = DWC_HCFG_48_MHZ;
  57853. + } else {
  57854. + /* High speed PHY running at full speed or high speed */
  57855. + val = DWC_HCFG_30_60_MHZ;
  57856. + }
  57857. +
  57858. + DWC_DEBUGPL(DBG_CIL, "Initializing HCFG.FSLSPClkSel to 0x%1x\n", val);
  57859. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  57860. + hcfg.b.fslspclksel = val;
  57861. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  57862. +}
  57863. +
  57864. +/**
  57865. + * Initializes the DevSpd field of the DCFG register depending on the PHY type
  57866. + * and the enumeration speed of the device.
  57867. + */
  57868. +static void init_devspd(dwc_otg_core_if_t * core_if)
  57869. +{
  57870. + uint32_t val;
  57871. + dcfg_data_t dcfg;
  57872. +
  57873. + if (((core_if->hwcfg2.b.hs_phy_type == 2) &&
  57874. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  57875. + (core_if->core_params->ulpi_fs_ls)) ||
  57876. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  57877. + /* Full speed PHY */
  57878. + val = 0x3;
  57879. + } else if (core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
  57880. + /* High speed PHY running at full speed */
  57881. + val = 0x1;
  57882. + } else {
  57883. + /* High speed PHY running at high speed */
  57884. + val = 0x0;
  57885. + }
  57886. +
  57887. + DWC_DEBUGPL(DBG_CIL, "Initializing DCFG.DevSpd to 0x%1x\n", val);
  57888. +
  57889. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  57890. + dcfg.b.devspd = val;
  57891. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  57892. +}
  57893. +
  57894. +/**
  57895. + * This function calculates the number of IN EPS
  57896. + * using GHWCFG1 and GHWCFG2 registers values
  57897. + *
  57898. + * @param core_if Programming view of the DWC_otg controller
  57899. + */
  57900. +static uint32_t calc_num_in_eps(dwc_otg_core_if_t * core_if)
  57901. +{
  57902. + uint32_t num_in_eps = 0;
  57903. + uint32_t num_eps = core_if->hwcfg2.b.num_dev_ep;
  57904. + uint32_t hwcfg1 = core_if->hwcfg1.d32 >> 3;
  57905. + uint32_t num_tx_fifos = core_if->hwcfg4.b.num_in_eps;
  57906. + int i;
  57907. +
  57908. + for (i = 0; i < num_eps; ++i) {
  57909. + if (!(hwcfg1 & 0x1))
  57910. + num_in_eps++;
  57911. +
  57912. + hwcfg1 >>= 2;
  57913. + }
  57914. +
  57915. + if (core_if->hwcfg4.b.ded_fifo_en) {
  57916. + num_in_eps =
  57917. + (num_in_eps > num_tx_fifos) ? num_tx_fifos : num_in_eps;
  57918. + }
  57919. +
  57920. + return num_in_eps;
  57921. +}
  57922. +
  57923. +/**
  57924. + * This function calculates the number of OUT EPS
  57925. + * using GHWCFG1 and GHWCFG2 registers values
  57926. + *
  57927. + * @param core_if Programming view of the DWC_otg controller
  57928. + */
  57929. +static uint32_t calc_num_out_eps(dwc_otg_core_if_t * core_if)
  57930. +{
  57931. + uint32_t num_out_eps = 0;
  57932. + uint32_t num_eps = core_if->hwcfg2.b.num_dev_ep;
  57933. + uint32_t hwcfg1 = core_if->hwcfg1.d32 >> 2;
  57934. + int i;
  57935. +
  57936. + for (i = 0; i < num_eps; ++i) {
  57937. + if (!(hwcfg1 & 0x1))
  57938. + num_out_eps++;
  57939. +
  57940. + hwcfg1 >>= 2;
  57941. + }
  57942. + return num_out_eps;
  57943. +}
  57944. +
  57945. +/**
  57946. + * This function initializes the DWC_otg controller registers and
  57947. + * prepares the core for device mode or host mode operation.
  57948. + *
  57949. + * @param core_if Programming view of the DWC_otg controller
  57950. + *
  57951. + */
  57952. +void dwc_otg_core_init(dwc_otg_core_if_t * core_if)
  57953. +{
  57954. + int i = 0;
  57955. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  57956. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  57957. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  57958. + gusbcfg_data_t usbcfg = {.d32 = 0 };
  57959. + gi2cctl_data_t i2cctl = {.d32 = 0 };
  57960. +
  57961. + DWC_DEBUGPL(DBG_CILV, "dwc_otg_core_init(%p) regs at %p\n",
  57962. + core_if, global_regs);
  57963. +
  57964. + /* Common Initialization */
  57965. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  57966. +
  57967. + /* Program the ULPI External VBUS bit if needed */
  57968. + usbcfg.b.ulpi_ext_vbus_drv =
  57969. + (core_if->core_params->phy_ulpi_ext_vbus ==
  57970. + DWC_PHY_ULPI_EXTERNAL_VBUS) ? 1 : 0;
  57971. +
  57972. + /* Set external TS Dline pulsing */
  57973. + usbcfg.b.term_sel_dl_pulse =
  57974. + (core_if->core_params->ts_dline == 1) ? 1 : 0;
  57975. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  57976. +
  57977. + /* Reset the Controller */
  57978. + dwc_otg_core_reset(core_if);
  57979. +
  57980. + core_if->adp_enable = core_if->core_params->adp_supp_enable;
  57981. + core_if->power_down = core_if->core_params->power_down;
  57982. + core_if->otg_sts = 0;
  57983. +
  57984. + /* Initialize parameters from Hardware configuration registers. */
  57985. + dev_if->num_in_eps = calc_num_in_eps(core_if);
  57986. + dev_if->num_out_eps = calc_num_out_eps(core_if);
  57987. +
  57988. + DWC_DEBUGPL(DBG_CIL, "num_dev_perio_in_ep=%d\n",
  57989. + core_if->hwcfg4.b.num_dev_perio_in_ep);
  57990. +
  57991. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
  57992. + dev_if->perio_tx_fifo_size[i] =
  57993. + DWC_READ_REG32(&global_regs->dtxfsiz[i]) >> 16;
  57994. + DWC_DEBUGPL(DBG_CIL, "Periodic Tx FIFO SZ #%d=0x%0x\n",
  57995. + i, dev_if->perio_tx_fifo_size[i]);
  57996. + }
  57997. +
  57998. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  57999. + dev_if->tx_fifo_size[i] =
  58000. + DWC_READ_REG32(&global_regs->dtxfsiz[i]) >> 16;
  58001. + DWC_DEBUGPL(DBG_CIL, "Tx FIFO SZ #%d=0x%0x\n",
  58002. + i, dev_if->tx_fifo_size[i]);
  58003. + }
  58004. +
  58005. + core_if->total_fifo_size = core_if->hwcfg3.b.dfifo_depth;
  58006. + core_if->rx_fifo_size = DWC_READ_REG32(&global_regs->grxfsiz);
  58007. + core_if->nperio_tx_fifo_size =
  58008. + DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16;
  58009. +
  58010. + DWC_DEBUGPL(DBG_CIL, "Total FIFO SZ=%d\n", core_if->total_fifo_size);
  58011. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO SZ=%d\n", core_if->rx_fifo_size);
  58012. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO SZ=%d\n",
  58013. + core_if->nperio_tx_fifo_size);
  58014. +
  58015. + /* This programming sequence needs to happen in FS mode before any other
  58016. + * programming occurs */
  58017. + if ((core_if->core_params->speed == DWC_SPEED_PARAM_FULL) &&
  58018. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  58019. + /* If FS mode with FS PHY */
  58020. +
  58021. + /* core_init() is now called on every switch so only call the
  58022. + * following for the first time through. */
  58023. + if (!core_if->phy_init_done) {
  58024. + core_if->phy_init_done = 1;
  58025. + DWC_DEBUGPL(DBG_CIL, "FS_PHY detected\n");
  58026. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  58027. + usbcfg.b.physel = 1;
  58028. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  58029. +
  58030. + /* Reset after a PHY select */
  58031. + dwc_otg_core_reset(core_if);
  58032. + }
  58033. +
  58034. + /* Program DCFG.DevSpd or HCFG.FSLSPclkSel to 48Mhz in FS. Also
  58035. + * do this on HNP Dev/Host mode switches (done in dev_init and
  58036. + * host_init). */
  58037. + if (dwc_otg_is_host_mode(core_if)) {
  58038. + init_fslspclksel(core_if);
  58039. + } else {
  58040. + init_devspd(core_if);
  58041. + }
  58042. +
  58043. + if (core_if->core_params->i2c_enable) {
  58044. + DWC_DEBUGPL(DBG_CIL, "FS_PHY Enabling I2c\n");
  58045. + /* Program GUSBCFG.OtgUtmifsSel to I2C */
  58046. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  58047. + usbcfg.b.otgutmifssel = 1;
  58048. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  58049. +
  58050. + /* Program GI2CCTL.I2CEn */
  58051. + i2cctl.d32 = DWC_READ_REG32(&global_regs->gi2cctl);
  58052. + i2cctl.b.i2cdevaddr = 1;
  58053. + i2cctl.b.i2cen = 0;
  58054. + DWC_WRITE_REG32(&global_regs->gi2cctl, i2cctl.d32);
  58055. + i2cctl.b.i2cen = 1;
  58056. + DWC_WRITE_REG32(&global_regs->gi2cctl, i2cctl.d32);
  58057. + }
  58058. +
  58059. + } /* endif speed == DWC_SPEED_PARAM_FULL */
  58060. + else {
  58061. + /* High speed PHY. */
  58062. + if (!core_if->phy_init_done) {
  58063. + core_if->phy_init_done = 1;
  58064. + /* HS PHY parameters. These parameters are preserved
  58065. + * during soft reset so only program the first time. Do
  58066. + * a soft reset immediately after setting phyif. */
  58067. +
  58068. + if (core_if->core_params->phy_type == 2) {
  58069. + /* ULPI interface */
  58070. + usbcfg.b.ulpi_utmi_sel = 1;
  58071. + usbcfg.b.phyif = 0;
  58072. + usbcfg.b.ddrsel =
  58073. + core_if->core_params->phy_ulpi_ddr;
  58074. + } else if (core_if->core_params->phy_type == 1) {
  58075. + /* UTMI+ interface */
  58076. + usbcfg.b.ulpi_utmi_sel = 0;
  58077. + if (core_if->core_params->phy_utmi_width == 16) {
  58078. + usbcfg.b.phyif = 1;
  58079. +
  58080. + } else {
  58081. + usbcfg.b.phyif = 0;
  58082. + }
  58083. + } else {
  58084. + DWC_ERROR("FS PHY TYPE\n");
  58085. + }
  58086. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  58087. + /* Reset after setting the PHY parameters */
  58088. + dwc_otg_core_reset(core_if);
  58089. + }
  58090. + }
  58091. +
  58092. + if ((core_if->hwcfg2.b.hs_phy_type == 2) &&
  58093. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  58094. + (core_if->core_params->ulpi_fs_ls)) {
  58095. + DWC_DEBUGPL(DBG_CIL, "Setting ULPI FSLS\n");
  58096. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  58097. + usbcfg.b.ulpi_fsls = 1;
  58098. + usbcfg.b.ulpi_clk_sus_m = 1;
  58099. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  58100. + } else {
  58101. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  58102. + usbcfg.b.ulpi_fsls = 0;
  58103. + usbcfg.b.ulpi_clk_sus_m = 0;
  58104. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  58105. + }
  58106. +
  58107. + /* Program the GAHBCFG Register. */
  58108. + switch (core_if->hwcfg2.b.architecture) {
  58109. +
  58110. + case DWC_SLAVE_ONLY_ARCH:
  58111. + DWC_DEBUGPL(DBG_CIL, "Slave Only Mode\n");
  58112. + ahbcfg.b.nptxfemplvl_txfemplvl =
  58113. + DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
  58114. + ahbcfg.b.ptxfemplvl = DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
  58115. + core_if->dma_enable = 0;
  58116. + core_if->dma_desc_enable = 0;
  58117. + break;
  58118. +
  58119. + case DWC_EXT_DMA_ARCH:
  58120. + DWC_DEBUGPL(DBG_CIL, "External DMA Mode\n");
  58121. + {
  58122. + uint8_t brst_sz = core_if->core_params->dma_burst_size;
  58123. + ahbcfg.b.hburstlen = 0;
  58124. + while (brst_sz > 1) {
  58125. + ahbcfg.b.hburstlen++;
  58126. + brst_sz >>= 1;
  58127. + }
  58128. + }
  58129. + core_if->dma_enable = (core_if->core_params->dma_enable != 0);
  58130. + core_if->dma_desc_enable =
  58131. + (core_if->core_params->dma_desc_enable != 0);
  58132. + break;
  58133. +
  58134. + case DWC_INT_DMA_ARCH:
  58135. + DWC_DEBUGPL(DBG_CIL, "Internal DMA Mode\n");
  58136. + /* Old value was DWC_GAHBCFG_INT_DMA_BURST_INCR - done for
  58137. + Host mode ISOC in issue fix - vahrama */
  58138. + /* Broadcom had altered to (1<<3)|(0<<0) - WRESP=1, max 4 beats */
  58139. + ahbcfg.b.hburstlen = (1<<3)|(0<<0);//DWC_GAHBCFG_INT_DMA_BURST_INCR4;
  58140. + core_if->dma_enable = (core_if->core_params->dma_enable != 0);
  58141. + core_if->dma_desc_enable =
  58142. + (core_if->core_params->dma_desc_enable != 0);
  58143. + break;
  58144. +
  58145. + }
  58146. + if (core_if->dma_enable) {
  58147. + if (core_if->dma_desc_enable) {
  58148. + DWC_PRINTF("Using Descriptor DMA mode\n");
  58149. + } else {
  58150. + DWC_PRINTF("Using Buffer DMA mode\n");
  58151. +
  58152. + }
  58153. + } else {
  58154. + DWC_PRINTF("Using Slave mode\n");
  58155. + core_if->dma_desc_enable = 0;
  58156. + }
  58157. +
  58158. + if (core_if->core_params->ahb_single) {
  58159. + ahbcfg.b.ahbsingle = 1;
  58160. + }
  58161. +
  58162. + ahbcfg.b.dmaenable = core_if->dma_enable;
  58163. + DWC_WRITE_REG32(&global_regs->gahbcfg, ahbcfg.d32);
  58164. +
  58165. + core_if->en_multiple_tx_fifo = core_if->hwcfg4.b.ded_fifo_en;
  58166. +
  58167. + core_if->pti_enh_enable = core_if->core_params->pti_enable != 0;
  58168. + core_if->multiproc_int_enable = core_if->core_params->mpi_enable;
  58169. + DWC_PRINTF("Periodic Transfer Interrupt Enhancement - %s\n",
  58170. + ((core_if->pti_enh_enable) ? "enabled" : "disabled"));
  58171. + DWC_PRINTF("Multiprocessor Interrupt Enhancement - %s\n",
  58172. + ((core_if->multiproc_int_enable) ? "enabled" : "disabled"));
  58173. +
  58174. + /*
  58175. + * Program the GUSBCFG register.
  58176. + */
  58177. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  58178. +
  58179. + switch (core_if->hwcfg2.b.op_mode) {
  58180. + case DWC_MODE_HNP_SRP_CAPABLE:
  58181. + usbcfg.b.hnpcap = (core_if->core_params->otg_cap ==
  58182. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE);
  58183. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  58184. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  58185. + break;
  58186. +
  58187. + case DWC_MODE_SRP_ONLY_CAPABLE:
  58188. + usbcfg.b.hnpcap = 0;
  58189. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  58190. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  58191. + break;
  58192. +
  58193. + case DWC_MODE_NO_HNP_SRP_CAPABLE:
  58194. + usbcfg.b.hnpcap = 0;
  58195. + usbcfg.b.srpcap = 0;
  58196. + break;
  58197. +
  58198. + case DWC_MODE_SRP_CAPABLE_DEVICE:
  58199. + usbcfg.b.hnpcap = 0;
  58200. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  58201. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  58202. + break;
  58203. +
  58204. + case DWC_MODE_NO_SRP_CAPABLE_DEVICE:
  58205. + usbcfg.b.hnpcap = 0;
  58206. + usbcfg.b.srpcap = 0;
  58207. + break;
  58208. +
  58209. + case DWC_MODE_SRP_CAPABLE_HOST:
  58210. + usbcfg.b.hnpcap = 0;
  58211. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  58212. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  58213. + break;
  58214. +
  58215. + case DWC_MODE_NO_SRP_CAPABLE_HOST:
  58216. + usbcfg.b.hnpcap = 0;
  58217. + usbcfg.b.srpcap = 0;
  58218. + break;
  58219. + }
  58220. +
  58221. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  58222. +
  58223. +#ifdef CONFIG_USB_DWC_OTG_LPM
  58224. + if (core_if->core_params->lpm_enable) {
  58225. + glpmcfg_data_t lpmcfg = {.d32 = 0 };
  58226. +
  58227. + /* To enable LPM support set lpm_cap_en bit */
  58228. + lpmcfg.b.lpm_cap_en = 1;
  58229. +
  58230. + /* Make AppL1Res ACK */
  58231. + lpmcfg.b.appl_resp = 1;
  58232. +
  58233. + /* Retry 3 times */
  58234. + lpmcfg.b.retry_count = 3;
  58235. +
  58236. + DWC_MODIFY_REG32(&core_if->core_global_regs->glpmcfg,
  58237. + 0, lpmcfg.d32);
  58238. +
  58239. + }
  58240. +#endif
  58241. + if (core_if->core_params->ic_usb_cap) {
  58242. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  58243. + gusbcfg.b.ic_usb_cap = 1;
  58244. + DWC_MODIFY_REG32(&core_if->core_global_regs->gusbcfg,
  58245. + 0, gusbcfg.d32);
  58246. + }
  58247. + {
  58248. + gotgctl_data_t gotgctl = {.d32 = 0 };
  58249. + gotgctl.b.otgver = core_if->core_params->otg_ver;
  58250. + DWC_MODIFY_REG32(&core_if->core_global_regs->gotgctl, 0,
  58251. + gotgctl.d32);
  58252. + /* Set OTG version supported */
  58253. + core_if->otg_ver = core_if->core_params->otg_ver;
  58254. + DWC_PRINTF("OTG VER PARAM: %d, OTG VER FLAG: %d\n",
  58255. + core_if->core_params->otg_ver, core_if->otg_ver);
  58256. + }
  58257. +
  58258. +
  58259. + /* Enable common interrupts */
  58260. + dwc_otg_enable_common_interrupts(core_if);
  58261. +
  58262. + /* Do device or host intialization based on mode during PCD
  58263. + * and HCD initialization */
  58264. + if (dwc_otg_is_host_mode(core_if)) {
  58265. + DWC_DEBUGPL(DBG_ANY, "Host Mode\n");
  58266. + core_if->op_state = A_HOST;
  58267. + } else {
  58268. + DWC_DEBUGPL(DBG_ANY, "Device Mode\n");
  58269. + core_if->op_state = B_PERIPHERAL;
  58270. +#ifdef DWC_DEVICE_ONLY
  58271. + dwc_otg_core_dev_init(core_if);
  58272. +#endif
  58273. + }
  58274. +}
  58275. +
  58276. +/**
  58277. + * This function enables the Device mode interrupts.
  58278. + *
  58279. + * @param core_if Programming view of DWC_otg controller
  58280. + */
  58281. +void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t * core_if)
  58282. +{
  58283. + gintmsk_data_t intr_mask = {.d32 = 0 };
  58284. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  58285. +
  58286. + DWC_DEBUGPL(DBG_CIL, "%s()\n", __func__);
  58287. +
  58288. + /* Disable all interrupts. */
  58289. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  58290. +
  58291. + /* Clear any pending interrupts */
  58292. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  58293. +
  58294. + /* Enable the common interrupts */
  58295. + dwc_otg_enable_common_interrupts(core_if);
  58296. +
  58297. + /* Enable interrupts */
  58298. + intr_mask.b.usbreset = 1;
  58299. + intr_mask.b.enumdone = 1;
  58300. + /* Disable Disconnect interrupt in Device mode */
  58301. + intr_mask.b.disconnect = 0;
  58302. +
  58303. + if (!core_if->multiproc_int_enable) {
  58304. + intr_mask.b.inepintr = 1;
  58305. + intr_mask.b.outepintr = 1;
  58306. + }
  58307. +
  58308. + intr_mask.b.erlysuspend = 1;
  58309. +
  58310. + if (core_if->en_multiple_tx_fifo == 0) {
  58311. + intr_mask.b.epmismatch = 1;
  58312. + }
  58313. +
  58314. + //intr_mask.b.incomplisoout = 1;
  58315. + intr_mask.b.incomplisoin = 1;
  58316. +
  58317. +/* Enable the ignore frame number for ISOC xfers - MAS */
  58318. +/* Disable to support high bandwith ISOC transfers - manukz */
  58319. +#if 0
  58320. +#ifdef DWC_UTE_PER_IO
  58321. + if (core_if->dma_enable) {
  58322. + if (core_if->dma_desc_enable) {
  58323. + dctl_data_t dctl1 = {.d32 = 0 };
  58324. + dctl1.b.ifrmnum = 1;
  58325. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  58326. + dctl, 0, dctl1.d32);
  58327. + DWC_DEBUG("----Enabled Ignore frame number (0x%08x)",
  58328. + DWC_READ_REG32(&core_if->dev_if->
  58329. + dev_global_regs->dctl));
  58330. + }
  58331. + }
  58332. +#endif
  58333. +#endif
  58334. +#ifdef DWC_EN_ISOC
  58335. + if (core_if->dma_enable) {
  58336. + if (core_if->dma_desc_enable == 0) {
  58337. + if (core_if->pti_enh_enable) {
  58338. + dctl_data_t dctl = {.d32 = 0 };
  58339. + dctl.b.ifrmnum = 1;
  58340. + DWC_MODIFY_REG32(&core_if->
  58341. + dev_if->dev_global_regs->dctl,
  58342. + 0, dctl.d32);
  58343. + } else {
  58344. + intr_mask.b.incomplisoin = 1;
  58345. + intr_mask.b.incomplisoout = 1;
  58346. + }
  58347. + }
  58348. + } else {
  58349. + intr_mask.b.incomplisoin = 1;
  58350. + intr_mask.b.incomplisoout = 1;
  58351. + }
  58352. +#endif /* DWC_EN_ISOC */
  58353. +
  58354. + /** @todo NGS: Should this be a module parameter? */
  58355. +#ifdef USE_PERIODIC_EP
  58356. + intr_mask.b.isooutdrop = 1;
  58357. + intr_mask.b.eopframe = 1;
  58358. + intr_mask.b.incomplisoin = 1;
  58359. + intr_mask.b.incomplisoout = 1;
  58360. +#endif
  58361. +
  58362. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  58363. +
  58364. + DWC_DEBUGPL(DBG_CIL, "%s() gintmsk=%0x\n", __func__,
  58365. + DWC_READ_REG32(&global_regs->gintmsk));
  58366. +}
  58367. +
  58368. +/**
  58369. + * This function initializes the DWC_otg controller registers for
  58370. + * device mode.
  58371. + *
  58372. + * @param core_if Programming view of DWC_otg controller
  58373. + *
  58374. + */
  58375. +void dwc_otg_core_dev_init(dwc_otg_core_if_t * core_if)
  58376. +{
  58377. + int i;
  58378. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  58379. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  58380. + dwc_otg_core_params_t *params = core_if->core_params;
  58381. + dcfg_data_t dcfg = {.d32 = 0 };
  58382. + depctl_data_t diepctl = {.d32 = 0 };
  58383. + grstctl_t resetctl = {.d32 = 0 };
  58384. + uint32_t rx_fifo_size;
  58385. + fifosize_data_t nptxfifosize;
  58386. + fifosize_data_t txfifosize;
  58387. + dthrctl_data_t dthrctl;
  58388. + fifosize_data_t ptxfifosize;
  58389. + uint16_t rxfsiz, nptxfsiz;
  58390. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  58391. + hwcfg3_data_t hwcfg3 = {.d32 = 0 };
  58392. +
  58393. + /* Restart the Phy Clock */
  58394. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  58395. +
  58396. + /* Device configuration register */
  58397. + init_devspd(core_if);
  58398. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  58399. + dcfg.b.descdma = (core_if->dma_desc_enable) ? 1 : 0;
  58400. + dcfg.b.perfrint = DWC_DCFG_FRAME_INTERVAL_80;
  58401. + /* Enable Device OUT NAK in case of DDMA mode*/
  58402. + if (core_if->core_params->dev_out_nak) {
  58403. + dcfg.b.endevoutnak = 1;
  58404. + }
  58405. +
  58406. + if (core_if->core_params->cont_on_bna) {
  58407. + dctl_data_t dctl = {.d32 = 0 };
  58408. + dctl.b.encontonbna = 1;
  58409. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, 0, dctl.d32);
  58410. + }
  58411. +
  58412. +
  58413. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  58414. +
  58415. + /* Configure data FIFO sizes */
  58416. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  58417. + DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n",
  58418. + core_if->total_fifo_size);
  58419. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n",
  58420. + params->dev_rx_fifo_size);
  58421. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n",
  58422. + params->dev_nperio_tx_fifo_size);
  58423. +
  58424. + /* Rx FIFO */
  58425. + DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
  58426. + DWC_READ_REG32(&global_regs->grxfsiz));
  58427. +
  58428. +#ifdef DWC_UTE_CFI
  58429. + core_if->pwron_rxfsiz = DWC_READ_REG32(&global_regs->grxfsiz);
  58430. + core_if->init_rxfsiz = params->dev_rx_fifo_size;
  58431. +#endif
  58432. + rx_fifo_size = params->dev_rx_fifo_size;
  58433. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fifo_size);
  58434. +
  58435. + DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
  58436. + DWC_READ_REG32(&global_regs->grxfsiz));
  58437. +
  58438. + /** Set Periodic Tx FIFO Mask all bits 0 */
  58439. + core_if->p_tx_msk = 0;
  58440. +
  58441. + /** Set Tx FIFO Mask all bits 0 */
  58442. + core_if->tx_msk = 0;
  58443. +
  58444. + if (core_if->en_multiple_tx_fifo == 0) {
  58445. + /* Non-periodic Tx FIFO */
  58446. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  58447. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  58448. +
  58449. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  58450. + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
  58451. +
  58452. + DWC_WRITE_REG32(&global_regs->gnptxfsiz,
  58453. + nptxfifosize.d32);
  58454. +
  58455. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  58456. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  58457. +
  58458. + /**@todo NGS: Fix Periodic FIFO Sizing! */
  58459. + /*
  58460. + * Periodic Tx FIFOs These FIFOs are numbered from 1 to 15.
  58461. + * Indexes of the FIFO size module parameters in the
  58462. + * dev_perio_tx_fifo_size array and the FIFO size registers in
  58463. + * the dptxfsiz array run from 0 to 14.
  58464. + */
  58465. + /** @todo Finish debug of this */
  58466. + ptxfifosize.b.startaddr =
  58467. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  58468. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
  58469. + ptxfifosize.b.depth =
  58470. + params->dev_perio_tx_fifo_size[i];
  58471. + DWC_DEBUGPL(DBG_CIL,
  58472. + "initial dtxfsiz[%d]=%08x\n", i,
  58473. + DWC_READ_REG32(&global_regs->dtxfsiz
  58474. + [i]));
  58475. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  58476. + ptxfifosize.d32);
  58477. + DWC_DEBUGPL(DBG_CIL, "new dtxfsiz[%d]=%08x\n",
  58478. + i,
  58479. + DWC_READ_REG32(&global_regs->dtxfsiz
  58480. + [i]));
  58481. + ptxfifosize.b.startaddr += ptxfifosize.b.depth;
  58482. + }
  58483. + } else {
  58484. + /*
  58485. + * Tx FIFOs These FIFOs are numbered from 1 to 15.
  58486. + * Indexes of the FIFO size module parameters in the
  58487. + * dev_tx_fifo_size array and the FIFO size registers in
  58488. + * the dtxfsiz array run from 0 to 14.
  58489. + */
  58490. +
  58491. + /* Non-periodic Tx FIFO */
  58492. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  58493. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  58494. +
  58495. +#ifdef DWC_UTE_CFI
  58496. + core_if->pwron_gnptxfsiz =
  58497. + (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  58498. + core_if->init_gnptxfsiz =
  58499. + params->dev_nperio_tx_fifo_size;
  58500. +#endif
  58501. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  58502. + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
  58503. +
  58504. + DWC_WRITE_REG32(&global_regs->gnptxfsiz,
  58505. + nptxfifosize.d32);
  58506. +
  58507. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  58508. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  58509. +
  58510. + txfifosize.b.startaddr =
  58511. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  58512. +
  58513. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  58514. +
  58515. + txfifosize.b.depth =
  58516. + params->dev_tx_fifo_size[i];
  58517. +
  58518. + DWC_DEBUGPL(DBG_CIL,
  58519. + "initial dtxfsiz[%d]=%08x\n",
  58520. + i,
  58521. + DWC_READ_REG32(&global_regs->dtxfsiz
  58522. + [i]));
  58523. +
  58524. +#ifdef DWC_UTE_CFI
  58525. + core_if->pwron_txfsiz[i] =
  58526. + (DWC_READ_REG32
  58527. + (&global_regs->dtxfsiz[i]) >> 16);
  58528. + core_if->init_txfsiz[i] =
  58529. + params->dev_tx_fifo_size[i];
  58530. +#endif
  58531. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  58532. + txfifosize.d32);
  58533. +
  58534. + DWC_DEBUGPL(DBG_CIL,
  58535. + "new dtxfsiz[%d]=%08x\n",
  58536. + i,
  58537. + DWC_READ_REG32(&global_regs->dtxfsiz
  58538. + [i]));
  58539. +
  58540. + txfifosize.b.startaddr += txfifosize.b.depth;
  58541. + }
  58542. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  58543. + /* Calculating DFIFOCFG for Device mode to include RxFIFO and NPTXFIFO */
  58544. + gdfifocfg.d32 = DWC_READ_REG32(&global_regs->gdfifocfg);
  58545. + hwcfg3.d32 = DWC_READ_REG32(&global_regs->ghwcfg3);
  58546. + gdfifocfg.b.gdfifocfg = (DWC_READ_REG32(&global_regs->ghwcfg3) >> 16);
  58547. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  58548. + rxfsiz = (DWC_READ_REG32(&global_regs->grxfsiz) & 0x0000ffff);
  58549. + nptxfsiz = (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  58550. + gdfifocfg.b.epinfobase = rxfsiz + nptxfsiz;
  58551. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  58552. + }
  58553. + }
  58554. +
  58555. + /* Flush the FIFOs */
  58556. + dwc_otg_flush_tx_fifo(core_if, 0x10); /* all Tx FIFOs */
  58557. + dwc_otg_flush_rx_fifo(core_if);
  58558. +
  58559. + /* Flush the Learning Queue. */
  58560. + resetctl.b.intknqflsh = 1;
  58561. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  58562. +
  58563. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable) {
  58564. + core_if->start_predict = 0;
  58565. + for (i = 0; i<= core_if->dev_if->num_in_eps; ++i) {
  58566. + core_if->nextep_seq[i] = 0xff; // 0xff - EP not active
  58567. + }
  58568. + core_if->nextep_seq[0] = 0;
  58569. + core_if->first_in_nextep_seq = 0;
  58570. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  58571. + diepctl.b.nextep = 0;
  58572. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  58573. +
  58574. + /* Update IN Endpoint Mismatch Count by active IN NP EP count + 1 */
  58575. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  58576. + dcfg.b.epmscnt = 2;
  58577. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  58578. +
  58579. + DWC_DEBUGPL(DBG_CILV,"%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  58580. + __func__, core_if->first_in_nextep_seq);
  58581. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  58582. + DWC_DEBUGPL(DBG_CILV, "%2d ", core_if->nextep_seq[i]);
  58583. + }
  58584. + DWC_DEBUGPL(DBG_CILV,"\n");
  58585. + }
  58586. +
  58587. + /* Clear all pending Device Interrupts */
  58588. + /** @todo - if the condition needed to be checked
  58589. + * or in any case all pending interrutps should be cleared?
  58590. + */
  58591. + if (core_if->multiproc_int_enable) {
  58592. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  58593. + DWC_WRITE_REG32(&dev_if->
  58594. + dev_global_regs->diepeachintmsk[i], 0);
  58595. + }
  58596. + }
  58597. +
  58598. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  58599. + DWC_WRITE_REG32(&dev_if->
  58600. + dev_global_regs->doepeachintmsk[i], 0);
  58601. + }
  58602. +
  58603. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachint, 0xFFFFFFFF);
  58604. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachintmsk, 0);
  58605. + } else {
  58606. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepmsk, 0);
  58607. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepmsk, 0);
  58608. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daint, 0xFFFFFFFF);
  58609. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daintmsk, 0);
  58610. + }
  58611. +
  58612. + for (i = 0; i <= dev_if->num_in_eps; i++) {
  58613. + depctl_data_t depctl;
  58614. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  58615. + if (depctl.b.epena) {
  58616. + depctl.d32 = 0;
  58617. + depctl.b.epdis = 1;
  58618. + depctl.b.snak = 1;
  58619. + } else {
  58620. + depctl.d32 = 0;
  58621. + }
  58622. +
  58623. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  58624. +
  58625. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->dieptsiz, 0);
  58626. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepdma, 0);
  58627. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepint, 0xFF);
  58628. + }
  58629. +
  58630. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  58631. + depctl_data_t depctl;
  58632. + depctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  58633. + if (depctl.b.epena) {
  58634. + dctl_data_t dctl = {.d32 = 0 };
  58635. + gintmsk_data_t gintsts = {.d32 = 0 };
  58636. + doepint_data_t doepint = {.d32 = 0 };
  58637. + dctl.b.sgoutnak = 1;
  58638. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  58639. + do {
  58640. + dwc_udelay(10);
  58641. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  58642. + } while (!gintsts.b.goutnakeff);
  58643. + gintsts.d32 = 0;
  58644. + gintsts.b.goutnakeff = 1;
  58645. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  58646. +
  58647. + depctl.d32 = 0;
  58648. + depctl.b.epdis = 1;
  58649. + depctl.b.snak = 1;
  58650. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->doepctl, depctl.d32);
  58651. + do {
  58652. + dwc_udelay(10);
  58653. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  58654. + out_ep_regs[i]->doepint);
  58655. + } while (!doepint.b.epdisabled);
  58656. +
  58657. + doepint.b.epdisabled = 1;
  58658. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->doepint, doepint.d32);
  58659. +
  58660. + dctl.d32 = 0;
  58661. + dctl.b.cgoutnak = 1;
  58662. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  58663. + } else {
  58664. + depctl.d32 = 0;
  58665. + }
  58666. +
  58667. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, depctl.d32);
  58668. +
  58669. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doeptsiz, 0);
  58670. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepdma, 0);
  58671. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepint, 0xFF);
  58672. + }
  58673. +
  58674. + if (core_if->en_multiple_tx_fifo && core_if->dma_enable) {
  58675. + dev_if->non_iso_tx_thr_en = params->thr_ctl & 0x1;
  58676. + dev_if->iso_tx_thr_en = (params->thr_ctl >> 1) & 0x1;
  58677. + dev_if->rx_thr_en = (params->thr_ctl >> 2) & 0x1;
  58678. +
  58679. + dev_if->rx_thr_length = params->rx_thr_length;
  58680. + dev_if->tx_thr_length = params->tx_thr_length;
  58681. +
  58682. + dev_if->setup_desc_index = 0;
  58683. +
  58684. + dthrctl.d32 = 0;
  58685. + dthrctl.b.non_iso_thr_en = dev_if->non_iso_tx_thr_en;
  58686. + dthrctl.b.iso_thr_en = dev_if->iso_tx_thr_en;
  58687. + dthrctl.b.tx_thr_len = dev_if->tx_thr_length;
  58688. + dthrctl.b.rx_thr_en = dev_if->rx_thr_en;
  58689. + dthrctl.b.rx_thr_len = dev_if->rx_thr_length;
  58690. + dthrctl.b.ahb_thr_ratio = params->ahb_thr_ratio;
  58691. +
  58692. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dtknqr3_dthrctl,
  58693. + dthrctl.d32);
  58694. +
  58695. + DWC_DEBUGPL(DBG_CIL,
  58696. + "Non ISO Tx Thr - %d\nISO Tx Thr - %d\nRx Thr - %d\nTx Thr Len - %d\nRx Thr Len - %d\n",
  58697. + dthrctl.b.non_iso_thr_en, dthrctl.b.iso_thr_en,
  58698. + dthrctl.b.rx_thr_en, dthrctl.b.tx_thr_len,
  58699. + dthrctl.b.rx_thr_len);
  58700. +
  58701. + }
  58702. +
  58703. + dwc_otg_enable_device_interrupts(core_if);
  58704. +
  58705. + {
  58706. + diepmsk_data_t msk = {.d32 = 0 };
  58707. + msk.b.txfifoundrn = 1;
  58708. + if (core_if->multiproc_int_enable) {
  58709. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->
  58710. + diepeachintmsk[0], msk.d32, msk.d32);
  58711. + } else {
  58712. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->diepmsk,
  58713. + msk.d32, msk.d32);
  58714. + }
  58715. + }
  58716. +
  58717. + if (core_if->multiproc_int_enable) {
  58718. + /* Set NAK on Babble */
  58719. + dctl_data_t dctl = {.d32 = 0 };
  58720. + dctl.b.nakonbble = 1;
  58721. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, 0, dctl.d32);
  58722. + }
  58723. +
  58724. + if (core_if->snpsid >= OTG_CORE_REV_2_94a) {
  58725. + dctl_data_t dctl = {.d32 = 0 };
  58726. + dctl.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dctl);
  58727. + dctl.b.sftdiscon = 0;
  58728. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dctl, dctl.d32);
  58729. + }
  58730. +}
  58731. +
  58732. +/**
  58733. + * This function enables the Host mode interrupts.
  58734. + *
  58735. + * @param core_if Programming view of DWC_otg controller
  58736. + */
  58737. +void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t * core_if)
  58738. +{
  58739. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  58740. + gintmsk_data_t intr_mask = {.d32 = 0 };
  58741. +
  58742. + DWC_DEBUGPL(DBG_CIL, "%s(%p)\n", __func__, core_if);
  58743. +
  58744. + /* Disable all interrupts. */
  58745. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  58746. +
  58747. + /* Clear any pending interrupts. */
  58748. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  58749. +
  58750. + /* Enable the common interrupts */
  58751. + dwc_otg_enable_common_interrupts(core_if);
  58752. +
  58753. + /*
  58754. + * Enable host mode interrupts without disturbing common
  58755. + * interrupts.
  58756. + */
  58757. +
  58758. + intr_mask.b.disconnect = 1;
  58759. + intr_mask.b.portintr = 1;
  58760. + intr_mask.b.hcintr = 1;
  58761. +
  58762. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  58763. +}
  58764. +
  58765. +/**
  58766. + * This function disables the Host Mode interrupts.
  58767. + *
  58768. + * @param core_if Programming view of DWC_otg controller
  58769. + */
  58770. +void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t * core_if)
  58771. +{
  58772. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  58773. + gintmsk_data_t intr_mask = {.d32 = 0 };
  58774. +
  58775. + DWC_DEBUGPL(DBG_CILV, "%s()\n", __func__);
  58776. +
  58777. + /*
  58778. + * Disable host mode interrupts without disturbing common
  58779. + * interrupts.
  58780. + */
  58781. + intr_mask.b.sofintr = 1;
  58782. + intr_mask.b.portintr = 1;
  58783. + intr_mask.b.hcintr = 1;
  58784. + intr_mask.b.ptxfempty = 1;
  58785. + intr_mask.b.nptxfempty = 1;
  58786. +
  58787. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, 0);
  58788. +}
  58789. +
  58790. +/**
  58791. + * This function initializes the DWC_otg controller registers for
  58792. + * host mode.
  58793. + *
  58794. + * This function flushes the Tx and Rx FIFOs and it flushes any entries in the
  58795. + * request queues. Host channels are reset to ensure that they are ready for
  58796. + * performing transfers.
  58797. + *
  58798. + * @param core_if Programming view of DWC_otg controller
  58799. + *
  58800. + */
  58801. +void dwc_otg_core_host_init(dwc_otg_core_if_t * core_if)
  58802. +{
  58803. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  58804. + dwc_otg_host_if_t *host_if = core_if->host_if;
  58805. + dwc_otg_core_params_t *params = core_if->core_params;
  58806. + hprt0_data_t hprt0 = {.d32 = 0 };
  58807. + fifosize_data_t nptxfifosize;
  58808. + fifosize_data_t ptxfifosize;
  58809. + uint16_t rxfsiz, nptxfsiz, hptxfsiz;
  58810. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  58811. + int i;
  58812. + hcchar_data_t hcchar;
  58813. + hcfg_data_t hcfg;
  58814. + hfir_data_t hfir;
  58815. + dwc_otg_hc_regs_t *hc_regs;
  58816. + int num_channels;
  58817. + gotgctl_data_t gotgctl = {.d32 = 0 };
  58818. +
  58819. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, core_if);
  58820. +
  58821. + /* Restart the Phy Clock */
  58822. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  58823. +
  58824. + /* Initialize Host Configuration Register */
  58825. + init_fslspclksel(core_if);
  58826. + if (core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
  58827. + hcfg.d32 = DWC_READ_REG32(&host_if->host_global_regs->hcfg);
  58828. + hcfg.b.fslssupp = 1;
  58829. + DWC_WRITE_REG32(&host_if->host_global_regs->hcfg, hcfg.d32);
  58830. +
  58831. + }
  58832. +
  58833. + /* This bit allows dynamic reloading of the HFIR register
  58834. + * during runtime. This bit needs to be programmed during
  58835. + * initial configuration and its value must not be changed
  58836. + * during runtime.*/
  58837. + if (core_if->core_params->reload_ctl == 1) {
  58838. + hfir.d32 = DWC_READ_REG32(&host_if->host_global_regs->hfir);
  58839. + hfir.b.hfirrldctrl = 1;
  58840. + DWC_WRITE_REG32(&host_if->host_global_regs->hfir, hfir.d32);
  58841. + }
  58842. +
  58843. + if (core_if->core_params->dma_desc_enable) {
  58844. + uint8_t op_mode = core_if->hwcfg2.b.op_mode;
  58845. + if (!
  58846. + (core_if->hwcfg4.b.desc_dma
  58847. + && (core_if->snpsid >= OTG_CORE_REV_2_90a)
  58848. + && ((op_mode == DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  58849. + || (op_mode == DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  58850. + || (op_mode ==
  58851. + DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG)
  58852. + || (op_mode == DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)
  58853. + || (op_mode ==
  58854. + DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST)))) {
  58855. +
  58856. + DWC_ERROR("Host can't operate in Descriptor DMA mode.\n"
  58857. + "Either core version is below 2.90a or "
  58858. + "GHWCFG2, GHWCFG4 registers' values do not allow Descriptor DMA in host mode.\n"
  58859. + "To run the driver in Buffer DMA host mode set dma_desc_enable "
  58860. + "module parameter to 0.\n");
  58861. + return;
  58862. + }
  58863. + hcfg.d32 = DWC_READ_REG32(&host_if->host_global_regs->hcfg);
  58864. + hcfg.b.descdma = 1;
  58865. + DWC_WRITE_REG32(&host_if->host_global_regs->hcfg, hcfg.d32);
  58866. + }
  58867. +
  58868. + /* Configure data FIFO sizes */
  58869. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  58870. + DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n",
  58871. + core_if->total_fifo_size);
  58872. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n",
  58873. + params->host_rx_fifo_size);
  58874. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n",
  58875. + params->host_nperio_tx_fifo_size);
  58876. + DWC_DEBUGPL(DBG_CIL, "P Tx FIFO Size=%d\n",
  58877. + params->host_perio_tx_fifo_size);
  58878. +
  58879. + /* Rx FIFO */
  58880. + DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
  58881. + DWC_READ_REG32(&global_regs->grxfsiz));
  58882. + DWC_WRITE_REG32(&global_regs->grxfsiz,
  58883. + params->host_rx_fifo_size);
  58884. + DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
  58885. + DWC_READ_REG32(&global_regs->grxfsiz));
  58886. +
  58887. + /* Non-periodic Tx FIFO */
  58888. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  58889. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  58890. + nptxfifosize.b.depth = params->host_nperio_tx_fifo_size;
  58891. + nptxfifosize.b.startaddr = params->host_rx_fifo_size;
  58892. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfifosize.d32);
  58893. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  58894. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  58895. +
  58896. + /* Periodic Tx FIFO */
  58897. + DWC_DEBUGPL(DBG_CIL, "initial hptxfsiz=%08x\n",
  58898. + DWC_READ_REG32(&global_regs->hptxfsiz));
  58899. + ptxfifosize.b.depth = params->host_perio_tx_fifo_size;
  58900. + ptxfifosize.b.startaddr =
  58901. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  58902. + DWC_WRITE_REG32(&global_regs->hptxfsiz, ptxfifosize.d32);
  58903. + DWC_DEBUGPL(DBG_CIL, "new hptxfsiz=%08x\n",
  58904. + DWC_READ_REG32(&global_regs->hptxfsiz));
  58905. +
  58906. + if (core_if->en_multiple_tx_fifo
  58907. + && core_if->snpsid <= OTG_CORE_REV_2_94a) {
  58908. + /* Global DFIFOCFG calculation for Host mode - include RxFIFO, NPTXFIFO and HPTXFIFO */
  58909. + gdfifocfg.d32 = DWC_READ_REG32(&global_regs->gdfifocfg);
  58910. + rxfsiz = (DWC_READ_REG32(&global_regs->grxfsiz) & 0x0000ffff);
  58911. + nptxfsiz = (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  58912. + hptxfsiz = (DWC_READ_REG32(&global_regs->hptxfsiz) >> 16);
  58913. + gdfifocfg.b.epinfobase = rxfsiz + nptxfsiz + hptxfsiz;
  58914. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  58915. + }
  58916. + }
  58917. +
  58918. + /* TODO - check this */
  58919. + /* Clear Host Set HNP Enable in the OTG Control Register */
  58920. + gotgctl.b.hstsethnpen = 1;
  58921. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  58922. + /* Make sure the FIFOs are flushed. */
  58923. + dwc_otg_flush_tx_fifo(core_if, 0x10 /* all TX FIFOs */ );
  58924. + dwc_otg_flush_rx_fifo(core_if);
  58925. +
  58926. + /* Clear Host Set HNP Enable in the OTG Control Register */
  58927. + gotgctl.b.hstsethnpen = 1;
  58928. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  58929. +
  58930. + if (!core_if->core_params->dma_desc_enable) {
  58931. + /* Flush out any leftover queued requests. */
  58932. + num_channels = core_if->core_params->host_channels;
  58933. +
  58934. + for (i = 0; i < num_channels; i++) {
  58935. + hc_regs = core_if->host_if->hc_regs[i];
  58936. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58937. + hcchar.b.chen = 0;
  58938. + hcchar.b.chdis = 1;
  58939. + hcchar.b.epdir = 0;
  58940. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  58941. + }
  58942. +
  58943. + /* Halt all channels to put them into a known state. */
  58944. + for (i = 0; i < num_channels; i++) {
  58945. + int count = 0;
  58946. + hc_regs = core_if->host_if->hc_regs[i];
  58947. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58948. + hcchar.b.chen = 1;
  58949. + hcchar.b.chdis = 1;
  58950. + hcchar.b.epdir = 0;
  58951. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  58952. + DWC_DEBUGPL(DBG_HCDV, "%s: Halt channel %d regs %p\n", __func__, i, hc_regs);
  58953. + do {
  58954. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58955. + if (++count > 1000) {
  58956. + DWC_ERROR
  58957. + ("%s: Unable to clear halt on channel %d (timeout HCCHAR 0x%X @%p)\n",
  58958. + __func__, i, hcchar.d32, &hc_regs->hcchar);
  58959. + break;
  58960. + }
  58961. + dwc_udelay(1);
  58962. + } while (hcchar.b.chen);
  58963. + }
  58964. + }
  58965. +
  58966. + /* Turn on the vbus power. */
  58967. + DWC_PRINTF("Init: Port Power? op_state=%d\n", core_if->op_state);
  58968. + if (core_if->op_state == A_HOST) {
  58969. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  58970. + DWC_PRINTF("Init: Power Port (%d)\n", hprt0.b.prtpwr);
  58971. + if (hprt0.b.prtpwr == 0) {
  58972. + hprt0.b.prtpwr = 1;
  58973. + DWC_WRITE_REG32(host_if->hprt0, hprt0.d32);
  58974. + }
  58975. + }
  58976. +
  58977. + dwc_otg_enable_host_interrupts(core_if);
  58978. +}
  58979. +
  58980. +/**
  58981. + * Prepares a host channel for transferring packets to/from a specific
  58982. + * endpoint. The HCCHARn register is set up with the characteristics specified
  58983. + * in _hc. Host channel interrupts that may need to be serviced while this
  58984. + * transfer is in progress are enabled.
  58985. + *
  58986. + * @param core_if Programming view of DWC_otg controller
  58987. + * @param hc Information needed to initialize the host channel
  58988. + */
  58989. +void dwc_otg_hc_init(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  58990. +{
  58991. + uint32_t intr_enable;
  58992. + hcintmsk_data_t hc_intr_mask;
  58993. + gintmsk_data_t gintmsk = {.d32 = 0 };
  58994. + hcchar_data_t hcchar;
  58995. + hcsplt_data_t hcsplt;
  58996. +
  58997. + uint8_t hc_num = hc->hc_num;
  58998. + dwc_otg_host_if_t *host_if = core_if->host_if;
  58999. + dwc_otg_hc_regs_t *hc_regs = host_if->hc_regs[hc_num];
  59000. +
  59001. + /* Clear old interrupt conditions for this host channel. */
  59002. + hc_intr_mask.d32 = 0xFFFFFFFF;
  59003. + hc_intr_mask.b.reserved14_31 = 0;
  59004. + DWC_WRITE_REG32(&hc_regs->hcint, hc_intr_mask.d32);
  59005. +
  59006. + /* Enable channel interrupts required for this transfer. */
  59007. + hc_intr_mask.d32 = 0;
  59008. + hc_intr_mask.b.chhltd = 1;
  59009. + if (core_if->dma_enable) {
  59010. + /* For Descriptor DMA mode core halts the channel on AHB error. Interrupt is not required */
  59011. + if (!core_if->dma_desc_enable)
  59012. + hc_intr_mask.b.ahberr = 1;
  59013. + else {
  59014. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  59015. + hc_intr_mask.b.xfercompl = 1;
  59016. + }
  59017. +
  59018. + if (hc->error_state && !hc->do_split &&
  59019. + hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  59020. + hc_intr_mask.b.ack = 1;
  59021. + if (hc->ep_is_in) {
  59022. + hc_intr_mask.b.datatglerr = 1;
  59023. + if (hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
  59024. + hc_intr_mask.b.nak = 1;
  59025. + }
  59026. + }
  59027. + }
  59028. + } else {
  59029. + switch (hc->ep_type) {
  59030. + case DWC_OTG_EP_TYPE_CONTROL:
  59031. + case DWC_OTG_EP_TYPE_BULK:
  59032. + hc_intr_mask.b.xfercompl = 1;
  59033. + hc_intr_mask.b.stall = 1;
  59034. + hc_intr_mask.b.xacterr = 1;
  59035. + hc_intr_mask.b.datatglerr = 1;
  59036. + if (hc->ep_is_in) {
  59037. + hc_intr_mask.b.bblerr = 1;
  59038. + } else {
  59039. + hc_intr_mask.b.nak = 1;
  59040. + hc_intr_mask.b.nyet = 1;
  59041. + if (hc->do_ping) {
  59042. + hc_intr_mask.b.ack = 1;
  59043. + }
  59044. + }
  59045. +
  59046. + if (hc->do_split) {
  59047. + hc_intr_mask.b.nak = 1;
  59048. + if (hc->complete_split) {
  59049. + hc_intr_mask.b.nyet = 1;
  59050. + } else {
  59051. + hc_intr_mask.b.ack = 1;
  59052. + }
  59053. + }
  59054. +
  59055. + if (hc->error_state) {
  59056. + hc_intr_mask.b.ack = 1;
  59057. + }
  59058. + break;
  59059. + case DWC_OTG_EP_TYPE_INTR:
  59060. + hc_intr_mask.b.xfercompl = 1;
  59061. + hc_intr_mask.b.nak = 1;
  59062. + hc_intr_mask.b.stall = 1;
  59063. + hc_intr_mask.b.xacterr = 1;
  59064. + hc_intr_mask.b.datatglerr = 1;
  59065. + hc_intr_mask.b.frmovrun = 1;
  59066. +
  59067. + if (hc->ep_is_in) {
  59068. + hc_intr_mask.b.bblerr = 1;
  59069. + }
  59070. + if (hc->error_state) {
  59071. + hc_intr_mask.b.ack = 1;
  59072. + }
  59073. + if (hc->do_split) {
  59074. + if (hc->complete_split) {
  59075. + hc_intr_mask.b.nyet = 1;
  59076. + } else {
  59077. + hc_intr_mask.b.ack = 1;
  59078. + }
  59079. + }
  59080. + break;
  59081. + case DWC_OTG_EP_TYPE_ISOC:
  59082. + hc_intr_mask.b.xfercompl = 1;
  59083. + hc_intr_mask.b.frmovrun = 1;
  59084. + hc_intr_mask.b.ack = 1;
  59085. +
  59086. + if (hc->ep_is_in) {
  59087. + hc_intr_mask.b.xacterr = 1;
  59088. + hc_intr_mask.b.bblerr = 1;
  59089. + }
  59090. + break;
  59091. + }
  59092. + }
  59093. + DWC_WRITE_REG32(&hc_regs->hcintmsk, hc_intr_mask.d32);
  59094. +
  59095. + /* Enable the top level host channel interrupt. */
  59096. + intr_enable = (1 << hc_num);
  59097. + DWC_MODIFY_REG32(&host_if->host_global_regs->haintmsk, 0, intr_enable);
  59098. +
  59099. + /* Make sure host channel interrupts are enabled. */
  59100. + gintmsk.b.hcintr = 1;
  59101. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
  59102. +
  59103. + /*
  59104. + * Program the HCCHARn register with the endpoint characteristics for
  59105. + * the current transfer.
  59106. + */
  59107. + hcchar.d32 = 0;
  59108. + hcchar.b.devaddr = hc->dev_addr;
  59109. + hcchar.b.epnum = hc->ep_num;
  59110. + hcchar.b.epdir = hc->ep_is_in;
  59111. + hcchar.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW);
  59112. + hcchar.b.eptype = hc->ep_type;
  59113. + hcchar.b.mps = hc->max_packet;
  59114. +
  59115. + DWC_WRITE_REG32(&host_if->hc_regs[hc_num]->hcchar, hcchar.d32);
  59116. +
  59117. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d, Dev Addr %d, EP #%d\n",
  59118. + __func__, hc->hc_num, hcchar.b.devaddr, hcchar.b.epnum);
  59119. + DWC_DEBUGPL(DBG_HCDV, " Is In %d, Is Low Speed %d, EP Type %d, "
  59120. + "Max Pkt %d, Multi Cnt %d\n",
  59121. + hcchar.b.epdir, hcchar.b.lspddev, hcchar.b.eptype,
  59122. + hcchar.b.mps, hcchar.b.multicnt);
  59123. +
  59124. + /*
  59125. + * Program the HCSPLIT register for SPLITs
  59126. + */
  59127. + hcsplt.d32 = 0;
  59128. + if (hc->do_split) {
  59129. + DWC_DEBUGPL(DBG_HCDV, "Programming HC %d with split --> %s\n",
  59130. + hc->hc_num,
  59131. + hc->complete_split ? "CSPLIT" : "SSPLIT");
  59132. + hcsplt.b.compsplt = hc->complete_split;
  59133. + hcsplt.b.xactpos = hc->xact_pos;
  59134. + hcsplt.b.hubaddr = hc->hub_addr;
  59135. + hcsplt.b.prtaddr = hc->port_addr;
  59136. + DWC_DEBUGPL(DBG_HCDV, "\t comp split %d\n", hc->complete_split);
  59137. + DWC_DEBUGPL(DBG_HCDV, "\t xact pos %d\n", hc->xact_pos);
  59138. + DWC_DEBUGPL(DBG_HCDV, "\t hub addr %d\n", hc->hub_addr);
  59139. + DWC_DEBUGPL(DBG_HCDV, "\t port addr %d\n", hc->port_addr);
  59140. + DWC_DEBUGPL(DBG_HCDV, "\t is_in %d\n", hc->ep_is_in);
  59141. + DWC_DEBUGPL(DBG_HCDV, "\t Max Pkt: %d\n", hcchar.b.mps);
  59142. + DWC_DEBUGPL(DBG_HCDV, "\t xferlen: %d\n", hc->xfer_len);
  59143. + }
  59144. + DWC_WRITE_REG32(&host_if->hc_regs[hc_num]->hcsplt, hcsplt.d32);
  59145. +
  59146. +}
  59147. +
  59148. +/**
  59149. + * Attempts to halt a host channel. This function should only be called in
  59150. + * Slave mode or to abort a transfer in either Slave mode or DMA mode. Under
  59151. + * normal circumstances in DMA mode, the controller halts the channel when the
  59152. + * transfer is complete or a condition occurs that requires application
  59153. + * intervention.
  59154. + *
  59155. + * In slave mode, checks for a free request queue entry, then sets the Channel
  59156. + * Enable and Channel Disable bits of the Host Channel Characteristics
  59157. + * register of the specified channel to intiate the halt. If there is no free
  59158. + * request queue entry, sets only the Channel Disable bit of the HCCHARn
  59159. + * register to flush requests for this channel. In the latter case, sets a
  59160. + * flag to indicate that the host channel needs to be halted when a request
  59161. + * queue slot is open.
  59162. + *
  59163. + * In DMA mode, always sets the Channel Enable and Channel Disable bits of the
  59164. + * HCCHARn register. The controller ensures there is space in the request
  59165. + * queue before submitting the halt request.
  59166. + *
  59167. + * Some time may elapse before the core flushes any posted requests for this
  59168. + * host channel and halts. The Channel Halted interrupt handler completes the
  59169. + * deactivation of the host channel.
  59170. + *
  59171. + * @param core_if Controller register interface.
  59172. + * @param hc Host channel to halt.
  59173. + * @param halt_status Reason for halting the channel.
  59174. + */
  59175. +void dwc_otg_hc_halt(dwc_otg_core_if_t * core_if,
  59176. + dwc_hc_t * hc, dwc_otg_halt_status_e halt_status)
  59177. +{
  59178. + gnptxsts_data_t nptxsts;
  59179. + hptxsts_data_t hptxsts;
  59180. + hcchar_data_t hcchar;
  59181. + dwc_otg_hc_regs_t *hc_regs;
  59182. + dwc_otg_core_global_regs_t *global_regs;
  59183. + dwc_otg_host_global_regs_t *host_global_regs;
  59184. +
  59185. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  59186. + global_regs = core_if->core_global_regs;
  59187. + host_global_regs = core_if->host_if->host_global_regs;
  59188. +
  59189. + DWC_ASSERT(!(halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS),
  59190. + "halt_status = %d\n", halt_status);
  59191. +
  59192. + if (halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
  59193. + halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
  59194. + /*
  59195. + * Disable all channel interrupts except Ch Halted. The QTD
  59196. + * and QH state associated with this transfer has been cleared
  59197. + * (in the case of URB_DEQUEUE), so the channel needs to be
  59198. + * shut down carefully to prevent crashes.
  59199. + */
  59200. + hcintmsk_data_t hcintmsk;
  59201. + hcintmsk.d32 = 0;
  59202. + hcintmsk.b.chhltd = 1;
  59203. + DWC_WRITE_REG32(&hc_regs->hcintmsk, hcintmsk.d32);
  59204. +
  59205. + /*
  59206. + * Make sure no other interrupts besides halt are currently
  59207. + * pending. Handling another interrupt could cause a crash due
  59208. + * to the QTD and QH state.
  59209. + */
  59210. + DWC_WRITE_REG32(&hc_regs->hcint, ~hcintmsk.d32);
  59211. +
  59212. + /*
  59213. + * Make sure the halt status is set to URB_DEQUEUE or AHB_ERR
  59214. + * even if the channel was already halted for some other
  59215. + * reason.
  59216. + */
  59217. + hc->halt_status = halt_status;
  59218. +
  59219. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  59220. + if (hcchar.b.chen == 0) {
  59221. + /*
  59222. + * The channel is either already halted or it hasn't
  59223. + * started yet. In DMA mode, the transfer may halt if
  59224. + * it finishes normally or a condition occurs that
  59225. + * requires driver intervention. Don't want to halt
  59226. + * the channel again. In either Slave or DMA mode,
  59227. + * it's possible that the transfer has been assigned
  59228. + * to a channel, but not started yet when an URB is
  59229. + * dequeued. Don't want to halt a channel that hasn't
  59230. + * started yet.
  59231. + */
  59232. + return;
  59233. + }
  59234. + }
  59235. + if (hc->halt_pending) {
  59236. + /*
  59237. + * A halt has already been issued for this channel. This might
  59238. + * happen when a transfer is aborted by a higher level in
  59239. + * the stack.
  59240. + */
  59241. +#ifdef DEBUG
  59242. + DWC_PRINTF
  59243. + ("*** %s: Channel %d, _hc->halt_pending already set ***\n",
  59244. + __func__, hc->hc_num);
  59245. +
  59246. +#endif
  59247. + return;
  59248. + }
  59249. +
  59250. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  59251. +
  59252. + /* No need to set the bit in DDMA for disabling the channel */
  59253. + //TODO check it everywhere channel is disabled
  59254. + if (!core_if->core_params->dma_desc_enable)
  59255. + hcchar.b.chen = 1;
  59256. + hcchar.b.chdis = 1;
  59257. +
  59258. + if (!core_if->dma_enable) {
  59259. + /* Check for space in the request queue to issue the halt. */
  59260. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  59261. + hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
  59262. + nptxsts.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  59263. + if (nptxsts.b.nptxqspcavail == 0) {
  59264. + hcchar.b.chen = 0;
  59265. + }
  59266. + } else {
  59267. + hptxsts.d32 =
  59268. + DWC_READ_REG32(&host_global_regs->hptxsts);
  59269. + if ((hptxsts.b.ptxqspcavail == 0)
  59270. + || (core_if->queuing_high_bandwidth)) {
  59271. + hcchar.b.chen = 0;
  59272. + }
  59273. + }
  59274. + }
  59275. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  59276. +
  59277. + hc->halt_status = halt_status;
  59278. +
  59279. + if (hcchar.b.chen) {
  59280. + hc->halt_pending = 1;
  59281. + hc->halt_on_queue = 0;
  59282. + } else {
  59283. + hc->halt_on_queue = 1;
  59284. + }
  59285. +
  59286. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  59287. + DWC_DEBUGPL(DBG_HCDV, " hcchar: 0x%08x\n", hcchar.d32);
  59288. + DWC_DEBUGPL(DBG_HCDV, " halt_pending: %d\n", hc->halt_pending);
  59289. + DWC_DEBUGPL(DBG_HCDV, " halt_on_queue: %d\n", hc->halt_on_queue);
  59290. + DWC_DEBUGPL(DBG_HCDV, " halt_status: %d\n", hc->halt_status);
  59291. +
  59292. + return;
  59293. +}
  59294. +
  59295. +/**
  59296. + * Clears the transfer state for a host channel. This function is normally
  59297. + * called after a transfer is done and the host channel is being released.
  59298. + *
  59299. + * @param core_if Programming view of DWC_otg controller.
  59300. + * @param hc Identifies the host channel to clean up.
  59301. + */
  59302. +void dwc_otg_hc_cleanup(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  59303. +{
  59304. + dwc_otg_hc_regs_t *hc_regs;
  59305. +
  59306. + hc->xfer_started = 0;
  59307. +
  59308. + /*
  59309. + * Clear channel interrupt enables and any unhandled channel interrupt
  59310. + * conditions.
  59311. + */
  59312. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  59313. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0);
  59314. + DWC_WRITE_REG32(&hc_regs->hcint, 0xFFFFFFFF);
  59315. +#ifdef DEBUG
  59316. + DWC_TIMER_CANCEL(core_if->hc_xfer_timer[hc->hc_num]);
  59317. +#endif
  59318. +}
  59319. +
  59320. +/**
  59321. + * Sets the channel property that indicates in which frame a periodic transfer
  59322. + * should occur. This is always set to the _next_ frame. This function has no
  59323. + * effect on non-periodic transfers.
  59324. + *
  59325. + * @param core_if Programming view of DWC_otg controller.
  59326. + * @param hc Identifies the host channel to set up and its properties.
  59327. + * @param hcchar Current value of the HCCHAR register for the specified host
  59328. + * channel.
  59329. + */
  59330. +static inline void hc_set_even_odd_frame(dwc_otg_core_if_t * core_if,
  59331. + dwc_hc_t * hc, hcchar_data_t * hcchar)
  59332. +{
  59333. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  59334. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  59335. + hfnum_data_t hfnum;
  59336. + hfnum.d32 =
  59337. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hfnum);
  59338. +
  59339. + /* 1 if _next_ frame is odd, 0 if it's even */
  59340. + hcchar->b.oddfrm = (hfnum.b.frnum & 0x1) ? 0 : 1;
  59341. +#ifdef DEBUG
  59342. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR && hc->do_split
  59343. + && !hc->complete_split) {
  59344. + switch (hfnum.b.frnum & 0x7) {
  59345. + case 7:
  59346. + core_if->hfnum_7_samples++;
  59347. + core_if->hfnum_7_frrem_accum += hfnum.b.frrem;
  59348. + break;
  59349. + case 0:
  59350. + core_if->hfnum_0_samples++;
  59351. + core_if->hfnum_0_frrem_accum += hfnum.b.frrem;
  59352. + break;
  59353. + default:
  59354. + core_if->hfnum_other_samples++;
  59355. + core_if->hfnum_other_frrem_accum +=
  59356. + hfnum.b.frrem;
  59357. + break;
  59358. + }
  59359. + }
  59360. +#endif
  59361. + }
  59362. +}
  59363. +
  59364. +#ifdef DEBUG
  59365. +void hc_xfer_timeout(void *ptr)
  59366. +{
  59367. + hc_xfer_info_t *xfer_info = NULL;
  59368. + int hc_num = 0;
  59369. +
  59370. + if (ptr)
  59371. + xfer_info = (hc_xfer_info_t *) ptr;
  59372. +
  59373. + if (!xfer_info->hc) {
  59374. + DWC_ERROR("xfer_info->hc = %p\n", xfer_info->hc);
  59375. + return;
  59376. + }
  59377. +
  59378. + hc_num = xfer_info->hc->hc_num;
  59379. + DWC_WARN("%s: timeout on channel %d\n", __func__, hc_num);
  59380. + DWC_WARN(" start_hcchar_val 0x%08x\n",
  59381. + xfer_info->core_if->start_hcchar_val[hc_num]);
  59382. +}
  59383. +#endif
  59384. +
  59385. +void ep_xfer_timeout(void *ptr)
  59386. +{
  59387. + ep_xfer_info_t *xfer_info = NULL;
  59388. + int ep_num = 0;
  59389. + dctl_data_t dctl = {.d32 = 0 };
  59390. + gintsts_data_t gintsts = {.d32 = 0 };
  59391. + gintmsk_data_t gintmsk = {.d32 = 0 };
  59392. +
  59393. + if (ptr)
  59394. + xfer_info = (ep_xfer_info_t *) ptr;
  59395. +
  59396. + if (!xfer_info->ep) {
  59397. + DWC_ERROR("xfer_info->ep = %p\n", xfer_info->ep);
  59398. + return;
  59399. + }
  59400. +
  59401. + ep_num = xfer_info->ep->num;
  59402. + DWC_WARN("%s: timeout on endpoit %d\n", __func__, ep_num);
  59403. + /* Put the sate to 2 as it was time outed */
  59404. + xfer_info->state = 2;
  59405. +
  59406. + dctl.d32 =
  59407. + DWC_READ_REG32(&xfer_info->core_if->dev_if->dev_global_regs->dctl);
  59408. + gintsts.d32 =
  59409. + DWC_READ_REG32(&xfer_info->core_if->core_global_regs->gintsts);
  59410. + gintmsk.d32 =
  59411. + DWC_READ_REG32(&xfer_info->core_if->core_global_regs->gintmsk);
  59412. +
  59413. + if (!gintmsk.b.goutnakeff) {
  59414. + /* Unmask it */
  59415. + gintmsk.b.goutnakeff = 1;
  59416. + DWC_WRITE_REG32(&xfer_info->core_if->core_global_regs->gintmsk,
  59417. + gintmsk.d32);
  59418. +
  59419. + }
  59420. +
  59421. + if (!gintsts.b.goutnakeff) {
  59422. + dctl.b.sgoutnak = 1;
  59423. + }
  59424. + DWC_WRITE_REG32(&xfer_info->core_if->dev_if->dev_global_regs->dctl,
  59425. + dctl.d32);
  59426. +
  59427. +}
  59428. +
  59429. +void set_pid_isoc(dwc_hc_t * hc)
  59430. +{
  59431. + /* Set up the initial PID for the transfer. */
  59432. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH) {
  59433. + if (hc->ep_is_in) {
  59434. + if (hc->multi_count == 1) {
  59435. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  59436. + } else if (hc->multi_count == 2) {
  59437. + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
  59438. + } else {
  59439. + hc->data_pid_start = DWC_OTG_HC_PID_DATA2;
  59440. + }
  59441. + } else {
  59442. + if (hc->multi_count == 1) {
  59443. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  59444. + } else {
  59445. + hc->data_pid_start = DWC_OTG_HC_PID_MDATA;
  59446. + }
  59447. + }
  59448. + } else {
  59449. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  59450. + }
  59451. +}
  59452. +
  59453. +/**
  59454. + * This function does the setup for a data transfer for a host channel and
  59455. + * starts the transfer. May be called in either Slave mode or DMA mode. In
  59456. + * Slave mode, the caller must ensure that there is sufficient space in the
  59457. + * request queue and Tx Data FIFO.
  59458. + *
  59459. + * For an OUT transfer in Slave mode, it loads a data packet into the
  59460. + * appropriate FIFO. If necessary, additional data packets will be loaded in
  59461. + * the Host ISR.
  59462. + *
  59463. + * For an IN transfer in Slave mode, a data packet is requested. The data
  59464. + * packets are unloaded from the Rx FIFO in the Host ISR. If necessary,
  59465. + * additional data packets are requested in the Host ISR.
  59466. + *
  59467. + * For a PING transfer in Slave mode, the Do Ping bit is set in the HCTSIZ
  59468. + * register along with a packet count of 1 and the channel is enabled. This
  59469. + * causes a single PING transaction to occur. Other fields in HCTSIZ are
  59470. + * simply set to 0 since no data transfer occurs in this case.
  59471. + *
  59472. + * For a PING transfer in DMA mode, the HCTSIZ register is initialized with
  59473. + * all the information required to perform the subsequent data transfer. In
  59474. + * addition, the Do Ping bit is set in the HCTSIZ register. In this case, the
  59475. + * controller performs the entire PING protocol, then starts the data
  59476. + * transfer.
  59477. + *
  59478. + * @param core_if Programming view of DWC_otg controller.
  59479. + * @param hc Information needed to initialize the host channel. The xfer_len
  59480. + * value may be reduced to accommodate the max widths of the XferSize and
  59481. + * PktCnt fields in the HCTSIZn register. The multi_count value may be changed
  59482. + * to reflect the final xfer_len value.
  59483. + */
  59484. +void dwc_otg_hc_start_transfer(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  59485. +{
  59486. + hcchar_data_t hcchar;
  59487. + hctsiz_data_t hctsiz;
  59488. + uint16_t num_packets;
  59489. + uint32_t max_hc_xfer_size = core_if->core_params->max_transfer_size;
  59490. + uint16_t max_hc_pkt_count = core_if->core_params->max_packet_count;
  59491. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  59492. +
  59493. + hctsiz.d32 = 0;
  59494. +
  59495. + if (hc->do_ping) {
  59496. + if (!core_if->dma_enable) {
  59497. + dwc_otg_hc_do_ping(core_if, hc);
  59498. + hc->xfer_started = 1;
  59499. + return;
  59500. + } else {
  59501. + hctsiz.b.dopng = 1;
  59502. + }
  59503. + }
  59504. +
  59505. + if (hc->do_split) {
  59506. + num_packets = 1;
  59507. +
  59508. + if (hc->complete_split && !hc->ep_is_in) {
  59509. + /* For CSPLIT OUT Transfer, set the size to 0 so the
  59510. + * core doesn't expect any data written to the FIFO */
  59511. + hc->xfer_len = 0;
  59512. + } else if (hc->ep_is_in || (hc->xfer_len > hc->max_packet)) {
  59513. + hc->xfer_len = hc->max_packet;
  59514. + } else if (!hc->ep_is_in && (hc->xfer_len > 188)) {
  59515. + hc->xfer_len = 188;
  59516. + }
  59517. +
  59518. + hctsiz.b.xfersize = hc->xfer_len;
  59519. + } else {
  59520. + /*
  59521. + * Ensure that the transfer length and packet count will fit
  59522. + * in the widths allocated for them in the HCTSIZn register.
  59523. + */
  59524. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  59525. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  59526. + /*
  59527. + * Make sure the transfer size is no larger than one
  59528. + * (micro)frame's worth of data. (A check was done
  59529. + * when the periodic transfer was accepted to ensure
  59530. + * that a (micro)frame's worth of data can be
  59531. + * programmed into a channel.)
  59532. + */
  59533. + uint32_t max_periodic_len =
  59534. + hc->multi_count * hc->max_packet;
  59535. + if (hc->xfer_len > max_periodic_len) {
  59536. + hc->xfer_len = max_periodic_len;
  59537. + } else {
  59538. + }
  59539. + } else if (hc->xfer_len > max_hc_xfer_size) {
  59540. + /* Make sure that xfer_len is a multiple of max packet size. */
  59541. + hc->xfer_len = max_hc_xfer_size - hc->max_packet + 1;
  59542. + }
  59543. +
  59544. + if (hc->xfer_len > 0) {
  59545. + num_packets =
  59546. + (hc->xfer_len + hc->max_packet -
  59547. + 1) / hc->max_packet;
  59548. + if (num_packets > max_hc_pkt_count) {
  59549. + num_packets = max_hc_pkt_count;
  59550. + hc->xfer_len = num_packets * hc->max_packet;
  59551. + }
  59552. + } else {
  59553. + /* Need 1 packet for transfer length of 0. */
  59554. + num_packets = 1;
  59555. + }
  59556. +
  59557. + if (hc->ep_is_in) {
  59558. + /* Always program an integral # of max packets for IN transfers. */
  59559. + hc->xfer_len = num_packets * hc->max_packet;
  59560. + }
  59561. +
  59562. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  59563. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  59564. + /*
  59565. + * Make sure that the multi_count field matches the
  59566. + * actual transfer length.
  59567. + */
  59568. + hc->multi_count = num_packets;
  59569. + }
  59570. +
  59571. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  59572. + set_pid_isoc(hc);
  59573. +
  59574. + hctsiz.b.xfersize = hc->xfer_len;
  59575. + }
  59576. +
  59577. + hc->start_pkt_count = num_packets;
  59578. + hctsiz.b.pktcnt = num_packets;
  59579. + hctsiz.b.pid = hc->data_pid_start;
  59580. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  59581. +
  59582. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  59583. + DWC_DEBUGPL(DBG_HCDV, " Xfer Size: %d\n", hctsiz.b.xfersize);
  59584. + DWC_DEBUGPL(DBG_HCDV, " Num Pkts: %d\n", hctsiz.b.pktcnt);
  59585. + DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
  59586. +
  59587. + if (core_if->dma_enable) {
  59588. + dwc_dma_t dma_addr;
  59589. + if (hc->align_buff) {
  59590. + dma_addr = hc->align_buff;
  59591. + } else {
  59592. + dma_addr = ((unsigned long)hc->xfer_buff & 0xffffffff);
  59593. + }
  59594. + DWC_WRITE_REG32(&hc_regs->hcdma, dma_addr);
  59595. + }
  59596. +
  59597. + /* Start the split */
  59598. + if (hc->do_split) {
  59599. + hcsplt_data_t hcsplt;
  59600. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  59601. + hcsplt.b.spltena = 1;
  59602. + DWC_WRITE_REG32(&hc_regs->hcsplt, hcsplt.d32);
  59603. + }
  59604. +
  59605. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  59606. + hcchar.b.multicnt = hc->multi_count;
  59607. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  59608. +#ifdef DEBUG
  59609. + core_if->start_hcchar_val[hc->hc_num] = hcchar.d32;
  59610. + if (hcchar.b.chdis) {
  59611. + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
  59612. + __func__, hc->hc_num, hcchar.d32);
  59613. + }
  59614. +#endif
  59615. +
  59616. + /* Set host channel enable after all other setup is complete. */
  59617. + hcchar.b.chen = 1;
  59618. + hcchar.b.chdis = 0;
  59619. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  59620. +
  59621. + hc->xfer_started = 1;
  59622. + hc->requests++;
  59623. +
  59624. + if (!core_if->dma_enable && !hc->ep_is_in && hc->xfer_len > 0) {
  59625. + /* Load OUT packet into the appropriate Tx FIFO. */
  59626. + dwc_otg_hc_write_packet(core_if, hc);
  59627. + }
  59628. +#ifdef DEBUG
  59629. + if (hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
  59630. + DWC_DEBUGPL(DBG_HCDV, "transfer %d from core_if %p\n",
  59631. + hc->hc_num, core_if);//GRAYG
  59632. + core_if->hc_xfer_info[hc->hc_num].core_if = core_if;
  59633. + core_if->hc_xfer_info[hc->hc_num].hc = hc;
  59634. +
  59635. + /* Start a timer for this transfer. */
  59636. + DWC_TIMER_SCHEDULE(core_if->hc_xfer_timer[hc->hc_num], 10000);
  59637. + }
  59638. +#endif
  59639. +}
  59640. +
  59641. +/**
  59642. + * This function does the setup for a data transfer for a host channel
  59643. + * and starts the transfer in Descriptor DMA mode.
  59644. + *
  59645. + * Initializes HCTSIZ register. For a PING transfer the Do Ping bit is set.
  59646. + * Sets PID and NTD values. For periodic transfers
  59647. + * initializes SCHED_INFO field with micro-frame bitmap.
  59648. + *
  59649. + * Initializes HCDMA register with descriptor list address and CTD value
  59650. + * then starts the transfer via enabling the channel.
  59651. + *
  59652. + * @param core_if Programming view of DWC_otg controller.
  59653. + * @param hc Information needed to initialize the host channel.
  59654. + */
  59655. +void dwc_otg_hc_start_transfer_ddma(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  59656. +{
  59657. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  59658. + hcchar_data_t hcchar;
  59659. + hctsiz_data_t hctsiz;
  59660. + hcdma_data_t hcdma;
  59661. +
  59662. + hctsiz.d32 = 0;
  59663. +
  59664. + if (hc->do_ping)
  59665. + hctsiz.b_ddma.dopng = 1;
  59666. +
  59667. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  59668. + set_pid_isoc(hc);
  59669. +
  59670. + /* Packet Count and Xfer Size are not used in Descriptor DMA mode */
  59671. + hctsiz.b_ddma.pid = hc->data_pid_start;
  59672. + hctsiz.b_ddma.ntd = hc->ntd - 1; /* 0 - 1 descriptor, 1 - 2 descriptors, etc. */
  59673. + hctsiz.b_ddma.schinfo = hc->schinfo; /* Non-zero only for high-speed interrupt endpoints */
  59674. +
  59675. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  59676. + DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
  59677. + DWC_DEBUGPL(DBG_HCDV, " NTD: %d\n", hctsiz.b_ddma.ntd);
  59678. +
  59679. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  59680. +
  59681. + hcdma.d32 = 0;
  59682. + hcdma.b.dma_addr = ((uint32_t) hc->desc_list_addr) >> 11;
  59683. +
  59684. + /* Always start from first descriptor. */
  59685. + hcdma.b.ctd = 0;
  59686. + DWC_WRITE_REG32(&hc_regs->hcdma, hcdma.d32);
  59687. +
  59688. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  59689. + hcchar.b.multicnt = hc->multi_count;
  59690. +
  59691. +#ifdef DEBUG
  59692. + core_if->start_hcchar_val[hc->hc_num] = hcchar.d32;
  59693. + if (hcchar.b.chdis) {
  59694. + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
  59695. + __func__, hc->hc_num, hcchar.d32);
  59696. + }
  59697. +#endif
  59698. +
  59699. + /* Set host channel enable after all other setup is complete. */
  59700. + hcchar.b.chen = 1;
  59701. + hcchar.b.chdis = 0;
  59702. +
  59703. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  59704. +
  59705. + hc->xfer_started = 1;
  59706. + hc->requests++;
  59707. +
  59708. +#ifdef DEBUG
  59709. + if ((hc->ep_type != DWC_OTG_EP_TYPE_INTR)
  59710. + && (hc->ep_type != DWC_OTG_EP_TYPE_ISOC)) {
  59711. + DWC_DEBUGPL(DBG_HCDV, "DMA transfer %d from core_if %p\n",
  59712. + hc->hc_num, core_if);//GRAYG
  59713. + core_if->hc_xfer_info[hc->hc_num].core_if = core_if;
  59714. + core_if->hc_xfer_info[hc->hc_num].hc = hc;
  59715. + /* Start a timer for this transfer. */
  59716. + DWC_TIMER_SCHEDULE(core_if->hc_xfer_timer[hc->hc_num], 10000);
  59717. + }
  59718. +#endif
  59719. +
  59720. +}
  59721. +
  59722. +/**
  59723. + * This function continues a data transfer that was started by previous call
  59724. + * to <code>dwc_otg_hc_start_transfer</code>. The caller must ensure there is
  59725. + * sufficient space in the request queue and Tx Data FIFO. This function
  59726. + * should only be called in Slave mode. In DMA mode, the controller acts
  59727. + * autonomously to complete transfers programmed to a host channel.
  59728. + *
  59729. + * For an OUT transfer, a new data packet is loaded into the appropriate FIFO
  59730. + * if there is any data remaining to be queued. For an IN transfer, another
  59731. + * data packet is always requested. For the SETUP phase of a control transfer,
  59732. + * this function does nothing.
  59733. + *
  59734. + * @return 1 if a new request is queued, 0 if no more requests are required
  59735. + * for this transfer.
  59736. + */
  59737. +int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  59738. +{
  59739. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  59740. +
  59741. + if (hc->do_split) {
  59742. + /* SPLITs always queue just once per channel */
  59743. + return 0;
  59744. + } else if (hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
  59745. + /* SETUPs are queued only once since they can't be NAKed. */
  59746. + return 0;
  59747. + } else if (hc->ep_is_in) {
  59748. + /*
  59749. + * Always queue another request for other IN transfers. If
  59750. + * back-to-back INs are issued and NAKs are received for both,
  59751. + * the driver may still be processing the first NAK when the
  59752. + * second NAK is received. When the interrupt handler clears
  59753. + * the NAK interrupt for the first NAK, the second NAK will
  59754. + * not be seen. So we can't depend on the NAK interrupt
  59755. + * handler to requeue a NAKed request. Instead, IN requests
  59756. + * are issued each time this function is called. When the
  59757. + * transfer completes, the extra requests for the channel will
  59758. + * be flushed.
  59759. + */
  59760. + hcchar_data_t hcchar;
  59761. + dwc_otg_hc_regs_t *hc_regs =
  59762. + core_if->host_if->hc_regs[hc->hc_num];
  59763. +
  59764. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  59765. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  59766. + hcchar.b.chen = 1;
  59767. + hcchar.b.chdis = 0;
  59768. + DWC_DEBUGPL(DBG_HCDV, " IN xfer: hcchar = 0x%08x\n",
  59769. + hcchar.d32);
  59770. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  59771. + hc->requests++;
  59772. + return 1;
  59773. + } else {
  59774. + /* OUT transfers. */
  59775. + if (hc->xfer_count < hc->xfer_len) {
  59776. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  59777. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  59778. + hcchar_data_t hcchar;
  59779. + dwc_otg_hc_regs_t *hc_regs;
  59780. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  59781. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  59782. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  59783. + }
  59784. +
  59785. + /* Load OUT packet into the appropriate Tx FIFO. */
  59786. + dwc_otg_hc_write_packet(core_if, hc);
  59787. + hc->requests++;
  59788. + return 1;
  59789. + } else {
  59790. + return 0;
  59791. + }
  59792. + }
  59793. +}
  59794. +
  59795. +/**
  59796. + * Starts a PING transfer. This function should only be called in Slave mode.
  59797. + * The Do Ping bit is set in the HCTSIZ register, then the channel is enabled.
  59798. + */
  59799. +void dwc_otg_hc_do_ping(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  59800. +{
  59801. + hcchar_data_t hcchar;
  59802. + hctsiz_data_t hctsiz;
  59803. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  59804. +
  59805. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  59806. +
  59807. + hctsiz.d32 = 0;
  59808. + hctsiz.b.dopng = 1;
  59809. + hctsiz.b.pktcnt = 1;
  59810. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  59811. +
  59812. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  59813. + hcchar.b.chen = 1;
  59814. + hcchar.b.chdis = 0;
  59815. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  59816. +}
  59817. +
  59818. +/*
  59819. + * This function writes a packet into the Tx FIFO associated with the Host
  59820. + * Channel. For a channel associated with a non-periodic EP, the non-periodic
  59821. + * Tx FIFO is written. For a channel associated with a periodic EP, the
  59822. + * periodic Tx FIFO is written. This function should only be called in Slave
  59823. + * mode.
  59824. + *
  59825. + * Upon return the xfer_buff and xfer_count fields in _hc are incremented by
  59826. + * then number of bytes written to the Tx FIFO.
  59827. + */
  59828. +void dwc_otg_hc_write_packet(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  59829. +{
  59830. + uint32_t i;
  59831. + uint32_t remaining_count;
  59832. + uint32_t byte_count;
  59833. + uint32_t dword_count;
  59834. +
  59835. + uint32_t *data_buff = (uint32_t *) (hc->xfer_buff);
  59836. + uint32_t *data_fifo = core_if->data_fifo[hc->hc_num];
  59837. +
  59838. + remaining_count = hc->xfer_len - hc->xfer_count;
  59839. + if (remaining_count > hc->max_packet) {
  59840. + byte_count = hc->max_packet;
  59841. + } else {
  59842. + byte_count = remaining_count;
  59843. + }
  59844. +
  59845. + dword_count = (byte_count + 3) / 4;
  59846. +
  59847. + if ((((unsigned long)data_buff) & 0x3) == 0) {
  59848. + /* xfer_buff is DWORD aligned. */
  59849. + for (i = 0; i < dword_count; i++, data_buff++) {
  59850. + DWC_WRITE_REG32(data_fifo, *data_buff);
  59851. + }
  59852. + } else {
  59853. + /* xfer_buff is not DWORD aligned. */
  59854. + for (i = 0; i < dword_count; i++, data_buff++) {
  59855. + uint32_t data;
  59856. + data =
  59857. + (data_buff[0] | data_buff[1] << 8 | data_buff[2] <<
  59858. + 16 | data_buff[3] << 24);
  59859. + DWC_WRITE_REG32(data_fifo, data);
  59860. + }
  59861. + }
  59862. +
  59863. + hc->xfer_count += byte_count;
  59864. + hc->xfer_buff += byte_count;
  59865. +}
  59866. +
  59867. +/**
  59868. + * Gets the current USB frame number. This is the frame number from the last
  59869. + * SOF packet.
  59870. + */
  59871. +uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t * core_if)
  59872. +{
  59873. + dsts_data_t dsts;
  59874. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  59875. +
  59876. + /* read current frame/microframe number from DSTS register */
  59877. + return dsts.b.soffn;
  59878. +}
  59879. +
  59880. +/**
  59881. + * Calculates and gets the frame Interval value of HFIR register according PHY
  59882. + * type and speed.The application can modify a value of HFIR register only after
  59883. + * the Port Enable bit of the Host Port Control and Status register
  59884. + * (HPRT.PrtEnaPort) has been set.
  59885. +*/
  59886. +
  59887. +uint32_t calc_frame_interval(dwc_otg_core_if_t * core_if)
  59888. +{
  59889. + gusbcfg_data_t usbcfg;
  59890. + hwcfg2_data_t hwcfg2;
  59891. + hprt0_data_t hprt0;
  59892. + int clock = 60; // default value
  59893. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  59894. + hwcfg2.d32 = DWC_READ_REG32(&core_if->core_global_regs->ghwcfg2);
  59895. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  59896. + if (!usbcfg.b.physel && usbcfg.b.ulpi_utmi_sel && !usbcfg.b.phyif)
  59897. + clock = 60;
  59898. + if (usbcfg.b.physel && hwcfg2.b.fs_phy_type == 3)
  59899. + clock = 48;
  59900. + if (!usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  59901. + !usbcfg.b.ulpi_utmi_sel && usbcfg.b.phyif)
  59902. + clock = 30;
  59903. + if (!usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  59904. + !usbcfg.b.ulpi_utmi_sel && !usbcfg.b.phyif)
  59905. + clock = 60;
  59906. + if (usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  59907. + !usbcfg.b.ulpi_utmi_sel && usbcfg.b.phyif)
  59908. + clock = 48;
  59909. + if (usbcfg.b.physel && !usbcfg.b.phyif && hwcfg2.b.fs_phy_type == 2)
  59910. + clock = 48;
  59911. + if (usbcfg.b.physel && hwcfg2.b.fs_phy_type == 1)
  59912. + clock = 48;
  59913. + if (hprt0.b.prtspd == 0)
  59914. + /* High speed case */
  59915. + return 125 * clock;
  59916. + else
  59917. + /* FS/LS case */
  59918. + return 1000 * clock;
  59919. +}
  59920. +
  59921. +/**
  59922. + * This function reads a setup packet from the Rx FIFO into the destination
  59923. + * buffer. This function is called from the Rx Status Queue Level (RxStsQLvl)
  59924. + * Interrupt routine when a SETUP packet has been received in Slave mode.
  59925. + *
  59926. + * @param core_if Programming view of DWC_otg controller.
  59927. + * @param dest Destination buffer for packet data.
  59928. + */
  59929. +void dwc_otg_read_setup_packet(dwc_otg_core_if_t * core_if, uint32_t * dest)
  59930. +{
  59931. + device_grxsts_data_t status;
  59932. + /* Get the 8 bytes of a setup transaction data */
  59933. +
  59934. + /* Pop 2 DWORDS off the receive data FIFO into memory */
  59935. + dest[0] = DWC_READ_REG32(core_if->data_fifo[0]);
  59936. + dest[1] = DWC_READ_REG32(core_if->data_fifo[0]);
  59937. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  59938. + status.d32 =
  59939. + DWC_READ_REG32(&core_if->core_global_regs->grxstsp);
  59940. + DWC_DEBUGPL(DBG_ANY,
  59941. + "EP:%d BCnt:%d " "pktsts:%x Frame:%d(0x%0x)\n",
  59942. + status.b.epnum, status.b.bcnt, status.b.pktsts,
  59943. + status.b.fn, status.b.fn);
  59944. + }
  59945. +}
  59946. +
  59947. +/**
  59948. + * This function enables EP0 OUT to receive SETUP packets and configures EP0
  59949. + * IN for transmitting packets. It is normally called when the
  59950. + * "Enumeration Done" interrupt occurs.
  59951. + *
  59952. + * @param core_if Programming view of DWC_otg controller.
  59953. + * @param ep The EP0 data.
  59954. + */
  59955. +void dwc_otg_ep0_activate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59956. +{
  59957. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  59958. + dsts_data_t dsts;
  59959. + depctl_data_t diepctl;
  59960. + depctl_data_t doepctl;
  59961. + dctl_data_t dctl = {.d32 = 0 };
  59962. +
  59963. + ep->stp_rollover = 0;
  59964. + /* Read the Device Status and Endpoint 0 Control registers */
  59965. + dsts.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dsts);
  59966. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  59967. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl);
  59968. +
  59969. + /* Set the MPS of the IN EP based on the enumeration speed */
  59970. + switch (dsts.b.enumspd) {
  59971. + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
  59972. + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
  59973. + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
  59974. + diepctl.b.mps = DWC_DEP0CTL_MPS_64;
  59975. + break;
  59976. + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
  59977. + diepctl.b.mps = DWC_DEP0CTL_MPS_8;
  59978. + break;
  59979. + }
  59980. +
  59981. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  59982. +
  59983. + /* Enable OUT EP for receive */
  59984. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  59985. + doepctl.b.epena = 1;
  59986. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
  59987. + }
  59988. +#ifdef VERBOSE
  59989. + DWC_DEBUGPL(DBG_PCDV, "doepctl0=%0x\n",
  59990. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  59991. + DWC_DEBUGPL(DBG_PCDV, "diepctl0=%0x\n",
  59992. + DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl));
  59993. +#endif
  59994. + dctl.b.cgnpinnak = 1;
  59995. +
  59996. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  59997. + DWC_DEBUGPL(DBG_PCDV, "dctl=%0x\n",
  59998. + DWC_READ_REG32(&dev_if->dev_global_regs->dctl));
  59999. +
  60000. +}
  60001. +
  60002. +/**
  60003. + * This function activates an EP. The Device EP control register for
  60004. + * the EP is configured as defined in the ep structure. Note: This
  60005. + * function is not used for EP0.
  60006. + *
  60007. + * @param core_if Programming view of DWC_otg controller.
  60008. + * @param ep The EP to activate.
  60009. + */
  60010. +void dwc_otg_ep_activate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  60011. +{
  60012. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  60013. + depctl_data_t depctl;
  60014. + volatile uint32_t *addr;
  60015. + daint_data_t daintmsk = {.d32 = 0 };
  60016. + dcfg_data_t dcfg;
  60017. + uint8_t i;
  60018. +
  60019. + DWC_DEBUGPL(DBG_PCDV, "%s() EP%d-%s\n", __func__, ep->num,
  60020. + (ep->is_in ? "IN" : "OUT"));
  60021. +
  60022. +#ifdef DWC_UTE_PER_IO
  60023. + ep->xiso_frame_num = 0xFFFFFFFF;
  60024. + ep->xiso_active_xfers = 0;
  60025. + ep->xiso_queued_xfers = 0;
  60026. +#endif
  60027. + /* Read DEPCTLn register */
  60028. + if (ep->is_in == 1) {
  60029. + addr = &dev_if->in_ep_regs[ep->num]->diepctl;
  60030. + daintmsk.ep.in = 1 << ep->num;
  60031. + } else {
  60032. + addr = &dev_if->out_ep_regs[ep->num]->doepctl;
  60033. + daintmsk.ep.out = 1 << ep->num;
  60034. + }
  60035. +
  60036. + /* If the EP is already active don't change the EP Control
  60037. + * register. */
  60038. + depctl.d32 = DWC_READ_REG32(addr);
  60039. + if (!depctl.b.usbactep) {
  60040. + depctl.b.mps = ep->maxpacket;
  60041. + depctl.b.eptype = ep->type;
  60042. + depctl.b.txfnum = ep->tx_fifo_num;
  60043. +
  60044. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  60045. + depctl.b.setd0pid = 1; // ???
  60046. + } else {
  60047. + depctl.b.setd0pid = 1;
  60048. + }
  60049. + depctl.b.usbactep = 1;
  60050. +
  60051. + /* Update nextep_seq array and EPMSCNT in DCFG*/
  60052. + if (!(depctl.b.eptype & 1) && (ep->is_in == 1)) { // NP IN EP
  60053. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  60054. + if (core_if->nextep_seq[i] == core_if->first_in_nextep_seq)
  60055. + break;
  60056. + }
  60057. + core_if->nextep_seq[i] = ep->num;
  60058. + core_if->nextep_seq[ep->num] = core_if->first_in_nextep_seq;
  60059. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  60060. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  60061. + dcfg.b.epmscnt++;
  60062. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  60063. +
  60064. + DWC_DEBUGPL(DBG_PCDV,
  60065. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  60066. + __func__, core_if->first_in_nextep_seq);
  60067. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  60068. + DWC_DEBUGPL(DBG_PCDV, "%2d\n",
  60069. + core_if->nextep_seq[i]);
  60070. + }
  60071. +
  60072. + }
  60073. +
  60074. +
  60075. + DWC_WRITE_REG32(addr, depctl.d32);
  60076. + DWC_DEBUGPL(DBG_PCDV, "DEPCTL=%08x\n", DWC_READ_REG32(addr));
  60077. + }
  60078. +
  60079. + /* Enable the Interrupt for this EP */
  60080. + if (core_if->multiproc_int_enable) {
  60081. + if (ep->is_in == 1) {
  60082. + diepmsk_data_t diepmsk = {.d32 = 0 };
  60083. + diepmsk.b.xfercompl = 1;
  60084. + diepmsk.b.timeout = 1;
  60085. + diepmsk.b.epdisabled = 1;
  60086. + diepmsk.b.ahberr = 1;
  60087. + diepmsk.b.intknepmis = 1;
  60088. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  60089. + diepmsk.b.intknepmis = 0;
  60090. + diepmsk.b.txfifoundrn = 1; //?????
  60091. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  60092. + diepmsk.b.nak = 1;
  60093. + }
  60094. +
  60095. +
  60096. +
  60097. +/*
  60098. + if (core_if->dma_desc_enable) {
  60099. + diepmsk.b.bna = 1;
  60100. + }
  60101. +*/
  60102. +/*
  60103. + if (core_if->dma_enable) {
  60104. + doepmsk.b.nak = 1;
  60105. + }
  60106. +*/
  60107. + DWC_WRITE_REG32(&dev_if->dev_global_regs->
  60108. + diepeachintmsk[ep->num], diepmsk.d32);
  60109. +
  60110. + } else {
  60111. + doepmsk_data_t doepmsk = {.d32 = 0 };
  60112. + doepmsk.b.xfercompl = 1;
  60113. + doepmsk.b.ahberr = 1;
  60114. + doepmsk.b.epdisabled = 1;
  60115. + if (ep->type == DWC_OTG_EP_TYPE_ISOC)
  60116. + doepmsk.b.outtknepdis = 1;
  60117. +
  60118. +/*
  60119. +
  60120. + if (core_if->dma_desc_enable) {
  60121. + doepmsk.b.bna = 1;
  60122. + }
  60123. +*/
  60124. +/*
  60125. + doepmsk.b.babble = 1;
  60126. + doepmsk.b.nyet = 1;
  60127. + doepmsk.b.nak = 1;
  60128. +*/
  60129. + DWC_WRITE_REG32(&dev_if->dev_global_regs->
  60130. + doepeachintmsk[ep->num], doepmsk.d32);
  60131. + }
  60132. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->deachintmsk,
  60133. + 0, daintmsk.d32);
  60134. + } else {
  60135. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  60136. + if (ep->is_in) {
  60137. + diepmsk_data_t diepmsk = {.d32 = 0 };
  60138. + diepmsk.b.nak = 1;
  60139. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->diepmsk, 0, diepmsk.d32);
  60140. + } else {
  60141. + doepmsk_data_t doepmsk = {.d32 = 0 };
  60142. + doepmsk.b.outtknepdis = 1;
  60143. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->doepmsk, 0, doepmsk.d32);
  60144. + }
  60145. + }
  60146. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->daintmsk,
  60147. + 0, daintmsk.d32);
  60148. + }
  60149. +
  60150. + DWC_DEBUGPL(DBG_PCDV, "DAINTMSK=%0x\n",
  60151. + DWC_READ_REG32(&dev_if->dev_global_regs->daintmsk));
  60152. +
  60153. + ep->stall_clear_flag = 0;
  60154. +
  60155. + return;
  60156. +}
  60157. +
  60158. +/**
  60159. + * This function deactivates an EP. This is done by clearing the USB Active
  60160. + * EP bit in the Device EP control register. Note: This function is not used
  60161. + * for EP0. EP0 cannot be deactivated.
  60162. + *
  60163. + * @param core_if Programming view of DWC_otg controller.
  60164. + * @param ep The EP to deactivate.
  60165. + */
  60166. +void dwc_otg_ep_deactivate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  60167. +{
  60168. + depctl_data_t depctl = {.d32 = 0 };
  60169. + volatile uint32_t *addr;
  60170. + daint_data_t daintmsk = {.d32 = 0 };
  60171. + dcfg_data_t dcfg;
  60172. + uint8_t i = 0;
  60173. +
  60174. +#ifdef DWC_UTE_PER_IO
  60175. + ep->xiso_frame_num = 0xFFFFFFFF;
  60176. + ep->xiso_active_xfers = 0;
  60177. + ep->xiso_queued_xfers = 0;
  60178. +#endif
  60179. +
  60180. + /* Read DEPCTLn register */
  60181. + if (ep->is_in == 1) {
  60182. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  60183. + daintmsk.ep.in = 1 << ep->num;
  60184. + } else {
  60185. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  60186. + daintmsk.ep.out = 1 << ep->num;
  60187. + }
  60188. +
  60189. + depctl.d32 = DWC_READ_REG32(addr);
  60190. +
  60191. + depctl.b.usbactep = 0;
  60192. +
  60193. + /* Update nextep_seq array and EPMSCNT in DCFG*/
  60194. + if (!(depctl.b.eptype & 1) && ep->is_in == 1) { // NP EP IN
  60195. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  60196. + if (core_if->nextep_seq[i] == ep->num)
  60197. + break;
  60198. + }
  60199. + core_if->nextep_seq[i] = core_if->nextep_seq[ep->num];
  60200. + if (core_if->first_in_nextep_seq == ep->num)
  60201. + core_if->first_in_nextep_seq = i;
  60202. + core_if->nextep_seq[ep->num] = 0xff;
  60203. + depctl.b.nextep = 0;
  60204. + dcfg.d32 =
  60205. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  60206. + dcfg.b.epmscnt--;
  60207. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  60208. + dcfg.d32);
  60209. +
  60210. + DWC_DEBUGPL(DBG_PCDV,
  60211. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  60212. + __func__, core_if->first_in_nextep_seq);
  60213. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  60214. + DWC_DEBUGPL(DBG_PCDV, "%2d\n", core_if->nextep_seq[i]);
  60215. + }
  60216. + }
  60217. +
  60218. + if (ep->is_in == 1)
  60219. + depctl.b.txfnum = 0;
  60220. +
  60221. + if (core_if->dma_desc_enable)
  60222. + depctl.b.epdis = 1;
  60223. +
  60224. + DWC_WRITE_REG32(addr, depctl.d32);
  60225. + depctl.d32 = DWC_READ_REG32(addr);
  60226. + if (core_if->dma_enable && ep->type == DWC_OTG_EP_TYPE_ISOC
  60227. + && depctl.b.epena) {
  60228. + depctl_data_t depctl = {.d32 = 0};
  60229. + if (ep->is_in) {
  60230. + diepint_data_t diepint = {.d32 = 0};
  60231. +
  60232. + depctl.b.snak = 1;
  60233. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  60234. + diepctl, depctl.d32);
  60235. + do {
  60236. + dwc_udelay(10);
  60237. + diepint.d32 =
  60238. + DWC_READ_REG32(&core_if->
  60239. + dev_if->in_ep_regs[ep->num]->
  60240. + diepint);
  60241. + } while (!diepint.b.inepnakeff);
  60242. + diepint.b.inepnakeff = 1;
  60243. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  60244. + diepint, diepint.d32);
  60245. + depctl.d32 = 0;
  60246. + depctl.b.epdis = 1;
  60247. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  60248. + diepctl, depctl.d32);
  60249. + do {
  60250. + dwc_udelay(10);
  60251. + diepint.d32 =
  60252. + DWC_READ_REG32(&core_if->
  60253. + dev_if->in_ep_regs[ep->num]->
  60254. + diepint);
  60255. + } while (!diepint.b.epdisabled);
  60256. + diepint.b.epdisabled = 1;
  60257. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  60258. + diepint, diepint.d32);
  60259. + } else {
  60260. + dctl_data_t dctl = {.d32 = 0};
  60261. + gintmsk_data_t gintsts = {.d32 = 0};
  60262. + doepint_data_t doepint = {.d32 = 0};
  60263. + dctl.b.sgoutnak = 1;
  60264. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  60265. + dctl, 0, dctl.d32);
  60266. + do {
  60267. + dwc_udelay(10);
  60268. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  60269. + } while (!gintsts.b.goutnakeff);
  60270. + gintsts.d32 = 0;
  60271. + gintsts.b.goutnakeff = 1;
  60272. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  60273. +
  60274. + depctl.d32 = 0;
  60275. + depctl.b.epdis = 1;
  60276. + depctl.b.snak = 1;
  60277. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->doepctl, depctl.d32);
  60278. + do
  60279. + {
  60280. + dwc_udelay(10);
  60281. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  60282. + out_ep_regs[ep->num]->doepint);
  60283. + } while (!doepint.b.epdisabled);
  60284. +
  60285. + doepint.b.epdisabled = 1;
  60286. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->doepint, doepint.d32);
  60287. +
  60288. + dctl.d32 = 0;
  60289. + dctl.b.cgoutnak = 1;
  60290. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  60291. + }
  60292. + }
  60293. +
  60294. + /* Disable the Interrupt for this EP */
  60295. + if (core_if->multiproc_int_enable) {
  60296. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->deachintmsk,
  60297. + daintmsk.d32, 0);
  60298. +
  60299. + if (ep->is_in == 1) {
  60300. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  60301. + diepeachintmsk[ep->num], 0);
  60302. + } else {
  60303. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  60304. + doepeachintmsk[ep->num], 0);
  60305. + }
  60306. + } else {
  60307. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->daintmsk,
  60308. + daintmsk.d32, 0);
  60309. + }
  60310. +
  60311. +}
  60312. +
  60313. +/**
  60314. + * This function initializes dma descriptor chain.
  60315. + *
  60316. + * @param core_if Programming view of DWC_otg controller.
  60317. + * @param ep The EP to start the transfer on.
  60318. + */
  60319. +static void init_dma_desc_chain(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  60320. +{
  60321. + dwc_otg_dev_dma_desc_t *dma_desc;
  60322. + uint32_t offset;
  60323. + uint32_t xfer_est;
  60324. + int i;
  60325. + unsigned maxxfer_local, total_len;
  60326. +
  60327. + if (!ep->is_in && ep->type == DWC_OTG_EP_TYPE_INTR &&
  60328. + (ep->maxpacket%4)) {
  60329. + maxxfer_local = ep->maxpacket;
  60330. + total_len = ep->xfer_len;
  60331. + } else {
  60332. + maxxfer_local = ep->maxxfer;
  60333. + total_len = ep->total_len;
  60334. + }
  60335. +
  60336. + ep->desc_cnt = (total_len / maxxfer_local) +
  60337. + ((total_len % maxxfer_local) ? 1 : 0);
  60338. +
  60339. + if (!ep->desc_cnt)
  60340. + ep->desc_cnt = 1;
  60341. +
  60342. + if (ep->desc_cnt > MAX_DMA_DESC_CNT)
  60343. + ep->desc_cnt = MAX_DMA_DESC_CNT;
  60344. +
  60345. + dma_desc = ep->desc_addr;
  60346. + if (maxxfer_local == ep->maxpacket) {
  60347. + if ((total_len % maxxfer_local) &&
  60348. + (total_len/maxxfer_local < MAX_DMA_DESC_CNT)) {
  60349. + xfer_est = (ep->desc_cnt - 1) * maxxfer_local +
  60350. + (total_len % maxxfer_local);
  60351. + } else
  60352. + xfer_est = ep->desc_cnt * maxxfer_local;
  60353. + } else
  60354. + xfer_est = total_len;
  60355. + offset = 0;
  60356. + for (i = 0; i < ep->desc_cnt; ++i) {
  60357. + /** DMA Descriptor Setup */
  60358. + if (xfer_est > maxxfer_local) {
  60359. + dma_desc->status.b.bs = BS_HOST_BUSY;
  60360. + dma_desc->status.b.l = 0;
  60361. + dma_desc->status.b.ioc = 0;
  60362. + dma_desc->status.b.sp = 0;
  60363. + dma_desc->status.b.bytes = maxxfer_local;
  60364. + dma_desc->buf = ep->dma_addr + offset;
  60365. + dma_desc->status.b.sts = 0;
  60366. + dma_desc->status.b.bs = BS_HOST_READY;
  60367. +
  60368. + xfer_est -= maxxfer_local;
  60369. + offset += maxxfer_local;
  60370. + } else {
  60371. + dma_desc->status.b.bs = BS_HOST_BUSY;
  60372. + dma_desc->status.b.l = 1;
  60373. + dma_desc->status.b.ioc = 1;
  60374. + if (ep->is_in) {
  60375. + dma_desc->status.b.sp =
  60376. + (xfer_est %
  60377. + ep->maxpacket) ? 1 : ((ep->
  60378. + sent_zlp) ? 1 : 0);
  60379. + dma_desc->status.b.bytes = xfer_est;
  60380. + } else {
  60381. + if (maxxfer_local == ep->maxpacket)
  60382. + dma_desc->status.b.bytes = xfer_est;
  60383. + else
  60384. + dma_desc->status.b.bytes =
  60385. + xfer_est + ((4 - (xfer_est & 0x3)) & 0x3);
  60386. + }
  60387. +
  60388. + dma_desc->buf = ep->dma_addr + offset;
  60389. + dma_desc->status.b.sts = 0;
  60390. + dma_desc->status.b.bs = BS_HOST_READY;
  60391. + }
  60392. + dma_desc++;
  60393. + }
  60394. +}
  60395. +/**
  60396. + * This function is called when to write ISOC data into appropriate dedicated
  60397. + * periodic FIFO.
  60398. + */
  60399. +static int32_t write_isoc_tx_fifo(dwc_otg_core_if_t * core_if, dwc_ep_t * dwc_ep)
  60400. +{
  60401. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  60402. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  60403. + dtxfsts_data_t txstatus = {.d32 = 0 };
  60404. + uint32_t len = 0;
  60405. + int epnum = dwc_ep->num;
  60406. + int dwords;
  60407. +
  60408. + DWC_DEBUGPL(DBG_PCD, "Dedicated TxFifo Empty: %d \n", epnum);
  60409. +
  60410. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  60411. +
  60412. + len = dwc_ep->xfer_len - dwc_ep->xfer_count;
  60413. +
  60414. + if (len > dwc_ep->maxpacket) {
  60415. + len = dwc_ep->maxpacket;
  60416. + }
  60417. +
  60418. + dwords = (len + 3) / 4;
  60419. +
  60420. + /* While there is space in the queue and space in the FIFO and
  60421. + * More data to tranfer, Write packets to the Tx FIFO */
  60422. + txstatus.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  60423. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum, txstatus.d32);
  60424. +
  60425. + while (txstatus.b.txfspcavail > dwords &&
  60426. + dwc_ep->xfer_count < dwc_ep->xfer_len && dwc_ep->xfer_len != 0) {
  60427. + /* Write the FIFO */
  60428. + dwc_otg_ep_write_packet(core_if, dwc_ep, 0);
  60429. +
  60430. + len = dwc_ep->xfer_len - dwc_ep->xfer_count;
  60431. + if (len > dwc_ep->maxpacket) {
  60432. + len = dwc_ep->maxpacket;
  60433. + }
  60434. +
  60435. + dwords = (len + 3) / 4;
  60436. + txstatus.d32 =
  60437. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  60438. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", epnum,
  60439. + txstatus.d32);
  60440. + }
  60441. +
  60442. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum,
  60443. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts));
  60444. +
  60445. + return 1;
  60446. +}
  60447. +/**
  60448. + * This function does the setup for a data transfer for an EP and
  60449. + * starts the transfer. For an IN transfer, the packets will be
  60450. + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
  60451. + * the packets are unloaded from the Rx FIFO in the ISR. the ISR.
  60452. + *
  60453. + * @param core_if Programming view of DWC_otg controller.
  60454. + * @param ep The EP to start the transfer on.
  60455. + */
  60456. +
  60457. +void dwc_otg_ep_start_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  60458. +{
  60459. + depctl_data_t depctl;
  60460. + deptsiz_data_t deptsiz;
  60461. + gintmsk_data_t intr_mask = {.d32 = 0 };
  60462. +
  60463. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
  60464. + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
  60465. + "xfer_buff=%p start_xfer_buff=%p, total_len = %d\n",
  60466. + ep->num, (ep->is_in ? "IN" : "OUT"), ep->xfer_len,
  60467. + ep->xfer_count, ep->xfer_buff, ep->start_xfer_buff,
  60468. + ep->total_len);
  60469. + /* IN endpoint */
  60470. + if (ep->is_in == 1) {
  60471. + dwc_otg_dev_in_ep_regs_t *in_regs =
  60472. + core_if->dev_if->in_ep_regs[ep->num];
  60473. +
  60474. + gnptxsts_data_t gtxstatus;
  60475. +
  60476. + gtxstatus.d32 =
  60477. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  60478. +
  60479. + if (core_if->en_multiple_tx_fifo == 0
  60480. + && gtxstatus.b.nptxqspcavail == 0 && !core_if->dma_enable) {
  60481. +#ifdef DEBUG
  60482. + DWC_PRINTF("TX Queue Full (0x%0x)\n", gtxstatus.d32);
  60483. +#endif
  60484. + return;
  60485. + }
  60486. +
  60487. + depctl.d32 = DWC_READ_REG32(&(in_regs->diepctl));
  60488. + deptsiz.d32 = DWC_READ_REG32(&(in_regs->dieptsiz));
  60489. +
  60490. + if (ep->maxpacket > ep->maxxfer / MAX_PKT_CNT)
  60491. + ep->xfer_len += (ep->maxxfer < (ep->total_len - ep->xfer_len)) ?
  60492. + ep->maxxfer : (ep->total_len - ep->xfer_len);
  60493. + else
  60494. + ep->xfer_len += (MAX_PKT_CNT * ep->maxpacket < (ep->total_len - ep->xfer_len)) ?
  60495. + MAX_PKT_CNT * ep->maxpacket : (ep->total_len - ep->xfer_len);
  60496. +
  60497. +
  60498. + /* Zero Length Packet? */
  60499. + if ((ep->xfer_len - ep->xfer_count) == 0) {
  60500. + deptsiz.b.xfersize = 0;
  60501. + deptsiz.b.pktcnt = 1;
  60502. + } else {
  60503. + /* Program the transfer size and packet count
  60504. + * as follows: xfersize = N * maxpacket +
  60505. + * short_packet pktcnt = N + (short_packet
  60506. + * exist ? 1 : 0)
  60507. + */
  60508. + deptsiz.b.xfersize = ep->xfer_len - ep->xfer_count;
  60509. + deptsiz.b.pktcnt =
  60510. + (ep->xfer_len - ep->xfer_count - 1 +
  60511. + ep->maxpacket) / ep->maxpacket;
  60512. + if (deptsiz.b.pktcnt > MAX_PKT_CNT) {
  60513. + deptsiz.b.pktcnt = MAX_PKT_CNT;
  60514. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  60515. + }
  60516. + if (ep->type == DWC_OTG_EP_TYPE_ISOC)
  60517. + deptsiz.b.mc = deptsiz.b.pktcnt;
  60518. + }
  60519. +
  60520. + /* Write the DMA register */
  60521. + if (core_if->dma_enable) {
  60522. + if (core_if->dma_desc_enable == 0) {
  60523. + if (ep->type != DWC_OTG_EP_TYPE_ISOC)
  60524. + deptsiz.b.mc = 1;
  60525. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  60526. + deptsiz.d32);
  60527. + DWC_WRITE_REG32(&(in_regs->diepdma),
  60528. + (uint32_t) ep->dma_addr);
  60529. + } else {
  60530. +#ifdef DWC_UTE_CFI
  60531. + /* The descriptor chain should be already initialized by now */
  60532. + if (ep->buff_mode != BM_STANDARD) {
  60533. + DWC_WRITE_REG32(&in_regs->diepdma,
  60534. + ep->descs_dma_addr);
  60535. + } else {
  60536. +#endif
  60537. + init_dma_desc_chain(core_if, ep);
  60538. + /** DIEPDMAn Register write */
  60539. + DWC_WRITE_REG32(&in_regs->diepdma,
  60540. + ep->dma_desc_addr);
  60541. +#ifdef DWC_UTE_CFI
  60542. + }
  60543. +#endif
  60544. + }
  60545. + } else {
  60546. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  60547. + if (ep->type != DWC_OTG_EP_TYPE_ISOC) {
  60548. + /**
  60549. + * Enable the Non-Periodic Tx FIFO empty interrupt,
  60550. + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
  60551. + * the data will be written into the fifo by the ISR.
  60552. + */
  60553. + if (core_if->en_multiple_tx_fifo == 0) {
  60554. + intr_mask.b.nptxfempty = 1;
  60555. + DWC_MODIFY_REG32
  60556. + (&core_if->core_global_regs->gintmsk,
  60557. + intr_mask.d32, intr_mask.d32);
  60558. + } else {
  60559. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  60560. + if (ep->xfer_len > 0) {
  60561. + uint32_t fifoemptymsk = 0;
  60562. + fifoemptymsk = 1 << ep->num;
  60563. + DWC_MODIFY_REG32
  60564. + (&core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  60565. + 0, fifoemptymsk);
  60566. +
  60567. + }
  60568. + }
  60569. + } else {
  60570. + write_isoc_tx_fifo(core_if, ep);
  60571. + }
  60572. + }
  60573. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  60574. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  60575. +
  60576. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  60577. + dsts_data_t dsts = {.d32 = 0};
  60578. + if (ep->bInterval == 1) {
  60579. + dsts.d32 =
  60580. + DWC_READ_REG32(&core_if->dev_if->
  60581. + dev_global_regs->dsts);
  60582. + ep->frame_num = dsts.b.soffn + ep->bInterval;
  60583. + if (ep->frame_num > 0x3FFF) {
  60584. + ep->frm_overrun = 1;
  60585. + ep->frame_num &= 0x3FFF;
  60586. + } else
  60587. + ep->frm_overrun = 0;
  60588. + if (ep->frame_num & 0x1) {
  60589. + depctl.b.setd1pid = 1;
  60590. + } else {
  60591. + depctl.b.setd0pid = 1;
  60592. + }
  60593. + }
  60594. + }
  60595. + /* EP enable, IN data in FIFO */
  60596. + depctl.b.cnak = 1;
  60597. + depctl.b.epena = 1;
  60598. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  60599. +
  60600. + } else {
  60601. + /* OUT endpoint */
  60602. + dwc_otg_dev_out_ep_regs_t *out_regs =
  60603. + core_if->dev_if->out_ep_regs[ep->num];
  60604. +
  60605. + depctl.d32 = DWC_READ_REG32(&(out_regs->doepctl));
  60606. + deptsiz.d32 = DWC_READ_REG32(&(out_regs->doeptsiz));
  60607. +
  60608. + if (!core_if->dma_desc_enable) {
  60609. + if (ep->maxpacket > ep->maxxfer / MAX_PKT_CNT)
  60610. + ep->xfer_len += (ep->maxxfer < (ep->total_len - ep->xfer_len)) ?
  60611. + ep->maxxfer : (ep->total_len - ep->xfer_len);
  60612. + else
  60613. + ep->xfer_len += (MAX_PKT_CNT * ep->maxpacket < (ep->total_len
  60614. + - ep->xfer_len)) ? MAX_PKT_CNT * ep->maxpacket : (ep->total_len - ep->xfer_len);
  60615. + }
  60616. +
  60617. + /* Program the transfer size and packet count as follows:
  60618. + *
  60619. + * pktcnt = N
  60620. + * xfersize = N * maxpacket
  60621. + */
  60622. + if ((ep->xfer_len - ep->xfer_count) == 0) {
  60623. + /* Zero Length Packet */
  60624. + deptsiz.b.xfersize = ep->maxpacket;
  60625. + deptsiz.b.pktcnt = 1;
  60626. + } else {
  60627. + deptsiz.b.pktcnt =
  60628. + (ep->xfer_len - ep->xfer_count +
  60629. + (ep->maxpacket - 1)) / ep->maxpacket;
  60630. + if (deptsiz.b.pktcnt > MAX_PKT_CNT) {
  60631. + deptsiz.b.pktcnt = MAX_PKT_CNT;
  60632. + }
  60633. + if (!core_if->dma_desc_enable) {
  60634. + ep->xfer_len =
  60635. + deptsiz.b.pktcnt * ep->maxpacket + ep->xfer_count;
  60636. + }
  60637. + deptsiz.b.xfersize = ep->xfer_len - ep->xfer_count;
  60638. + }
  60639. +
  60640. + DWC_DEBUGPL(DBG_PCDV, "ep%d xfersize=%d pktcnt=%d\n",
  60641. + ep->num, deptsiz.b.xfersize, deptsiz.b.pktcnt);
  60642. +
  60643. + if (core_if->dma_enable) {
  60644. + if (!core_if->dma_desc_enable) {
  60645. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  60646. + deptsiz.d32);
  60647. +
  60648. + DWC_WRITE_REG32(&(out_regs->doepdma),
  60649. + (uint32_t) ep->dma_addr);
  60650. + } else {
  60651. +#ifdef DWC_UTE_CFI
  60652. + /* The descriptor chain should be already initialized by now */
  60653. + if (ep->buff_mode != BM_STANDARD) {
  60654. + DWC_WRITE_REG32(&out_regs->doepdma,
  60655. + ep->descs_dma_addr);
  60656. + } else {
  60657. +#endif
  60658. + /** This is used for interrupt out transfers*/
  60659. + if (!ep->xfer_len)
  60660. + ep->xfer_len = ep->total_len;
  60661. + init_dma_desc_chain(core_if, ep);
  60662. +
  60663. + if (core_if->core_params->dev_out_nak) {
  60664. + if (ep->type == DWC_OTG_EP_TYPE_BULK) {
  60665. + deptsiz.b.pktcnt = (ep->total_len +
  60666. + (ep->maxpacket - 1)) / ep->maxpacket;
  60667. + deptsiz.b.xfersize = ep->total_len;
  60668. + /* Remember initial value of doeptsiz */
  60669. + core_if->start_doeptsiz_val[ep->num] = deptsiz.d32;
  60670. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  60671. + deptsiz.d32);
  60672. + }
  60673. + }
  60674. + /** DOEPDMAn Register write */
  60675. + DWC_WRITE_REG32(&out_regs->doepdma,
  60676. + ep->dma_desc_addr);
  60677. +#ifdef DWC_UTE_CFI
  60678. + }
  60679. +#endif
  60680. + }
  60681. + } else {
  60682. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  60683. + }
  60684. +
  60685. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  60686. + dsts_data_t dsts = {.d32 = 0};
  60687. + if (ep->bInterval == 1) {
  60688. + dsts.d32 =
  60689. + DWC_READ_REG32(&core_if->dev_if->
  60690. + dev_global_regs->dsts);
  60691. + ep->frame_num = dsts.b.soffn + ep->bInterval;
  60692. + if (ep->frame_num > 0x3FFF) {
  60693. + ep->frm_overrun = 1;
  60694. + ep->frame_num &= 0x3FFF;
  60695. + } else
  60696. + ep->frm_overrun = 0;
  60697. +
  60698. + if (ep->frame_num & 0x1) {
  60699. + depctl.b.setd1pid = 1;
  60700. + } else {
  60701. + depctl.b.setd0pid = 1;
  60702. + }
  60703. + }
  60704. + }
  60705. +
  60706. + /* EP enable */
  60707. + depctl.b.cnak = 1;
  60708. + depctl.b.epena = 1;
  60709. +
  60710. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  60711. +
  60712. + DWC_DEBUGPL(DBG_PCD, "DOEPCTL=%08x DOEPTSIZ=%08x\n",
  60713. + DWC_READ_REG32(&out_regs->doepctl),
  60714. + DWC_READ_REG32(&out_regs->doeptsiz));
  60715. + DWC_DEBUGPL(DBG_PCD, "DAINTMSK=%08x GINTMSK=%08x\n",
  60716. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->
  60717. + daintmsk),
  60718. + DWC_READ_REG32(&core_if->core_global_regs->
  60719. + gintmsk));
  60720. +
  60721. + /* Timer is scheduling only for out bulk transfers for
  60722. + * "Device DDMA OUT NAK Enhancement" feature to inform user
  60723. + * about received data payload in case of timeout
  60724. + */
  60725. + if (core_if->core_params->dev_out_nak) {
  60726. + if (ep->type == DWC_OTG_EP_TYPE_BULK) {
  60727. + core_if->ep_xfer_info[ep->num].core_if = core_if;
  60728. + core_if->ep_xfer_info[ep->num].ep = ep;
  60729. + core_if->ep_xfer_info[ep->num].state = 1;
  60730. +
  60731. + /* Start a timer for this transfer. */
  60732. + DWC_TIMER_SCHEDULE(core_if->ep_xfer_timer[ep->num], 10000);
  60733. + }
  60734. + }
  60735. + }
  60736. +}
  60737. +
  60738. +/**
  60739. + * This function setup a zero length transfer in Buffer DMA and
  60740. + * Slave modes for usb requests with zero field set
  60741. + *
  60742. + * @param core_if Programming view of DWC_otg controller.
  60743. + * @param ep The EP to start the transfer on.
  60744. + *
  60745. + */
  60746. +void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  60747. +{
  60748. +
  60749. + depctl_data_t depctl;
  60750. + deptsiz_data_t deptsiz;
  60751. + gintmsk_data_t intr_mask = {.d32 = 0 };
  60752. +
  60753. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
  60754. + DWC_PRINTF("zero length transfer is called\n");
  60755. +
  60756. + /* IN endpoint */
  60757. + if (ep->is_in == 1) {
  60758. + dwc_otg_dev_in_ep_regs_t *in_regs =
  60759. + core_if->dev_if->in_ep_regs[ep->num];
  60760. +
  60761. + depctl.d32 = DWC_READ_REG32(&(in_regs->diepctl));
  60762. + deptsiz.d32 = DWC_READ_REG32(&(in_regs->dieptsiz));
  60763. +
  60764. + deptsiz.b.xfersize = 0;
  60765. + deptsiz.b.pktcnt = 1;
  60766. +
  60767. + /* Write the DMA register */
  60768. + if (core_if->dma_enable) {
  60769. + if (core_if->dma_desc_enable == 0) {
  60770. + deptsiz.b.mc = 1;
  60771. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  60772. + deptsiz.d32);
  60773. + DWC_WRITE_REG32(&(in_regs->diepdma),
  60774. + (uint32_t) ep->dma_addr);
  60775. + }
  60776. + } else {
  60777. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  60778. + /**
  60779. + * Enable the Non-Periodic Tx FIFO empty interrupt,
  60780. + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
  60781. + * the data will be written into the fifo by the ISR.
  60782. + */
  60783. + if (core_if->en_multiple_tx_fifo == 0) {
  60784. + intr_mask.b.nptxfempty = 1;
  60785. + DWC_MODIFY_REG32(&core_if->
  60786. + core_global_regs->gintmsk,
  60787. + intr_mask.d32, intr_mask.d32);
  60788. + } else {
  60789. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  60790. + if (ep->xfer_len > 0) {
  60791. + uint32_t fifoemptymsk = 0;
  60792. + fifoemptymsk = 1 << ep->num;
  60793. + DWC_MODIFY_REG32(&core_if->
  60794. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  60795. + 0, fifoemptymsk);
  60796. + }
  60797. + }
  60798. + }
  60799. +
  60800. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  60801. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  60802. + /* EP enable, IN data in FIFO */
  60803. + depctl.b.cnak = 1;
  60804. + depctl.b.epena = 1;
  60805. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  60806. +
  60807. + } else {
  60808. + /* OUT endpoint */
  60809. + dwc_otg_dev_out_ep_regs_t *out_regs =
  60810. + core_if->dev_if->out_ep_regs[ep->num];
  60811. +
  60812. + depctl.d32 = DWC_READ_REG32(&(out_regs->doepctl));
  60813. + deptsiz.d32 = DWC_READ_REG32(&(out_regs->doeptsiz));
  60814. +
  60815. + /* Zero Length Packet */
  60816. + deptsiz.b.xfersize = ep->maxpacket;
  60817. + deptsiz.b.pktcnt = 1;
  60818. +
  60819. + if (core_if->dma_enable) {
  60820. + if (!core_if->dma_desc_enable) {
  60821. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  60822. + deptsiz.d32);
  60823. +
  60824. + DWC_WRITE_REG32(&(out_regs->doepdma),
  60825. + (uint32_t) ep->dma_addr);
  60826. + }
  60827. + } else {
  60828. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  60829. + }
  60830. +
  60831. + /* EP enable */
  60832. + depctl.b.cnak = 1;
  60833. + depctl.b.epena = 1;
  60834. +
  60835. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  60836. +
  60837. + }
  60838. +}
  60839. +
  60840. +/**
  60841. + * This function does the setup for a data transfer for EP0 and starts
  60842. + * the transfer. For an IN transfer, the packets will be loaded into
  60843. + * the appropriate Tx FIFO in the ISR. For OUT transfers, the packets are
  60844. + * unloaded from the Rx FIFO in the ISR.
  60845. + *
  60846. + * @param core_if Programming view of DWC_otg controller.
  60847. + * @param ep The EP0 data.
  60848. + */
  60849. +void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  60850. +{
  60851. + depctl_data_t depctl;
  60852. + deptsiz0_data_t deptsiz;
  60853. + gintmsk_data_t intr_mask = {.d32 = 0 };
  60854. + dwc_otg_dev_dma_desc_t *dma_desc;
  60855. +
  60856. + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
  60857. + "xfer_buff=%p start_xfer_buff=%p \n",
  60858. + ep->num, (ep->is_in ? "IN" : "OUT"), ep->xfer_len,
  60859. + ep->xfer_count, ep->xfer_buff, ep->start_xfer_buff);
  60860. +
  60861. + ep->total_len = ep->xfer_len;
  60862. +
  60863. + /* IN endpoint */
  60864. + if (ep->is_in == 1) {
  60865. + dwc_otg_dev_in_ep_regs_t *in_regs =
  60866. + core_if->dev_if->in_ep_regs[0];
  60867. +
  60868. + gnptxsts_data_t gtxstatus;
  60869. +
  60870. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  60871. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  60872. + if (depctl.b.epena)
  60873. + return;
  60874. + }
  60875. +
  60876. + gtxstatus.d32 =
  60877. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  60878. +
  60879. + /* If dedicated FIFO every time flush fifo before enable ep*/
  60880. + if (core_if->en_multiple_tx_fifo && core_if->snpsid >= OTG_CORE_REV_3_00a)
  60881. + dwc_otg_flush_tx_fifo(core_if, ep->tx_fifo_num);
  60882. +
  60883. + if (core_if->en_multiple_tx_fifo == 0
  60884. + && gtxstatus.b.nptxqspcavail == 0
  60885. + && !core_if->dma_enable) {
  60886. +#ifdef DEBUG
  60887. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  60888. + DWC_DEBUGPL(DBG_PCD, "DIEPCTL0=%0x\n",
  60889. + DWC_READ_REG32(&in_regs->diepctl));
  60890. + DWC_DEBUGPL(DBG_PCD, "DIEPTSIZ0=%0x (sz=%d, pcnt=%d)\n",
  60891. + deptsiz.d32,
  60892. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  60893. + DWC_PRINTF("TX Queue or FIFO Full (0x%0x)\n",
  60894. + gtxstatus.d32);
  60895. +#endif
  60896. + return;
  60897. + }
  60898. +
  60899. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  60900. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  60901. +
  60902. + /* Zero Length Packet? */
  60903. + if (ep->xfer_len == 0) {
  60904. + deptsiz.b.xfersize = 0;
  60905. + deptsiz.b.pktcnt = 1;
  60906. + } else {
  60907. + /* Program the transfer size and packet count
  60908. + * as follows: xfersize = N * maxpacket +
  60909. + * short_packet pktcnt = N + (short_packet
  60910. + * exist ? 1 : 0)
  60911. + */
  60912. + if (ep->xfer_len > ep->maxpacket) {
  60913. + ep->xfer_len = ep->maxpacket;
  60914. + deptsiz.b.xfersize = ep->maxpacket;
  60915. + } else {
  60916. + deptsiz.b.xfersize = ep->xfer_len;
  60917. + }
  60918. + deptsiz.b.pktcnt = 1;
  60919. +
  60920. + }
  60921. + DWC_DEBUGPL(DBG_PCDV,
  60922. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  60923. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  60924. + deptsiz.d32);
  60925. +
  60926. + /* Write the DMA register */
  60927. + if (core_if->dma_enable) {
  60928. + if (core_if->dma_desc_enable == 0) {
  60929. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  60930. + deptsiz.d32);
  60931. +
  60932. + DWC_WRITE_REG32(&(in_regs->diepdma),
  60933. + (uint32_t) ep->dma_addr);
  60934. + } else {
  60935. + dma_desc = core_if->dev_if->in_desc_addr;
  60936. +
  60937. + /** DMA Descriptor Setup */
  60938. + dma_desc->status.b.bs = BS_HOST_BUSY;
  60939. + dma_desc->status.b.l = 1;
  60940. + dma_desc->status.b.ioc = 1;
  60941. + dma_desc->status.b.sp =
  60942. + (ep->xfer_len == ep->maxpacket) ? 0 : 1;
  60943. + dma_desc->status.b.bytes = ep->xfer_len;
  60944. + dma_desc->buf = ep->dma_addr;
  60945. + dma_desc->status.b.sts = 0;
  60946. + dma_desc->status.b.bs = BS_HOST_READY;
  60947. +
  60948. + /** DIEPDMA0 Register write */
  60949. + DWC_WRITE_REG32(&in_regs->diepdma,
  60950. + core_if->
  60951. + dev_if->dma_in_desc_addr);
  60952. + }
  60953. + } else {
  60954. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  60955. + }
  60956. +
  60957. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  60958. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  60959. + /* EP enable, IN data in FIFO */
  60960. + depctl.b.cnak = 1;
  60961. + depctl.b.epena = 1;
  60962. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  60963. +
  60964. + /**
  60965. + * Enable the Non-Periodic Tx FIFO empty interrupt, the
  60966. + * data will be written into the fifo by the ISR.
  60967. + */
  60968. + if (!core_if->dma_enable) {
  60969. + if (core_if->en_multiple_tx_fifo == 0) {
  60970. + intr_mask.b.nptxfempty = 1;
  60971. + DWC_MODIFY_REG32(&core_if->
  60972. + core_global_regs->gintmsk,
  60973. + intr_mask.d32, intr_mask.d32);
  60974. + } else {
  60975. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  60976. + if (ep->xfer_len > 0) {
  60977. + uint32_t fifoemptymsk = 0;
  60978. + fifoemptymsk |= 1 << ep->num;
  60979. + DWC_MODIFY_REG32(&core_if->
  60980. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  60981. + 0, fifoemptymsk);
  60982. + }
  60983. + }
  60984. + }
  60985. + } else {
  60986. + /* OUT endpoint */
  60987. + dwc_otg_dev_out_ep_regs_t *out_regs =
  60988. + core_if->dev_if->out_ep_regs[0];
  60989. +
  60990. + depctl.d32 = DWC_READ_REG32(&out_regs->doepctl);
  60991. + deptsiz.d32 = DWC_READ_REG32(&out_regs->doeptsiz);
  60992. +
  60993. + /* Program the transfer size and packet count as follows:
  60994. + * xfersize = N * (maxpacket + 4 - (maxpacket % 4))
  60995. + * pktcnt = N */
  60996. + /* Zero Length Packet */
  60997. + deptsiz.b.xfersize = ep->maxpacket;
  60998. + deptsiz.b.pktcnt = 1;
  60999. + if (core_if->snpsid >= OTG_CORE_REV_3_00a)
  61000. + deptsiz.b.supcnt = 3;
  61001. +
  61002. + DWC_DEBUGPL(DBG_PCDV, "len=%d xfersize=%d pktcnt=%d\n",
  61003. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt);
  61004. +
  61005. + if (core_if->dma_enable) {
  61006. + if (!core_if->dma_desc_enable) {
  61007. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  61008. + deptsiz.d32);
  61009. +
  61010. + DWC_WRITE_REG32(&(out_regs->doepdma),
  61011. + (uint32_t) ep->dma_addr);
  61012. + } else {
  61013. + dma_desc = core_if->dev_if->out_desc_addr;
  61014. +
  61015. + /** DMA Descriptor Setup */
  61016. + dma_desc->status.b.bs = BS_HOST_BUSY;
  61017. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  61018. + dma_desc->status.b.mtrf = 0;
  61019. + dma_desc->status.b.sr = 0;
  61020. + }
  61021. + dma_desc->status.b.l = 1;
  61022. + dma_desc->status.b.ioc = 1;
  61023. + dma_desc->status.b.bytes = ep->maxpacket;
  61024. + dma_desc->buf = ep->dma_addr;
  61025. + dma_desc->status.b.sts = 0;
  61026. + dma_desc->status.b.bs = BS_HOST_READY;
  61027. +
  61028. + /** DOEPDMA0 Register write */
  61029. + DWC_WRITE_REG32(&out_regs->doepdma,
  61030. + core_if->dev_if->
  61031. + dma_out_desc_addr);
  61032. + }
  61033. + } else {
  61034. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  61035. + }
  61036. +
  61037. + /* EP enable */
  61038. + depctl.b.cnak = 1;
  61039. + depctl.b.epena = 1;
  61040. + DWC_WRITE_REG32(&(out_regs->doepctl), depctl.d32);
  61041. + }
  61042. +}
  61043. +
  61044. +/**
  61045. + * This function continues control IN transfers started by
  61046. + * dwc_otg_ep0_start_transfer, when the transfer does not fit in a
  61047. + * single packet. NOTE: The DIEPCTL0/DOEPCTL0 registers only have one
  61048. + * bit for the packet count.
  61049. + *
  61050. + * @param core_if Programming view of DWC_otg controller.
  61051. + * @param ep The EP0 data.
  61052. + */
  61053. +void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  61054. +{
  61055. + depctl_data_t depctl;
  61056. + deptsiz0_data_t deptsiz;
  61057. + gintmsk_data_t intr_mask = {.d32 = 0 };
  61058. + dwc_otg_dev_dma_desc_t *dma_desc;
  61059. +
  61060. + if (ep->is_in == 1) {
  61061. + dwc_otg_dev_in_ep_regs_t *in_regs =
  61062. + core_if->dev_if->in_ep_regs[0];
  61063. + gnptxsts_data_t tx_status = {.d32 = 0 };
  61064. +
  61065. + tx_status.d32 =
  61066. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  61067. + /** @todo Should there be check for room in the Tx
  61068. + * Status Queue. If not remove the code above this comment. */
  61069. +
  61070. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  61071. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  61072. +
  61073. + /* Program the transfer size and packet count
  61074. + * as follows: xfersize = N * maxpacket +
  61075. + * short_packet pktcnt = N + (short_packet
  61076. + * exist ? 1 : 0)
  61077. + */
  61078. +
  61079. + if (core_if->dma_desc_enable == 0) {
  61080. + deptsiz.b.xfersize =
  61081. + (ep->total_len - ep->xfer_count) >
  61082. + ep->maxpacket ? ep->maxpacket : (ep->total_len -
  61083. + ep->xfer_count);
  61084. + deptsiz.b.pktcnt = 1;
  61085. + if (core_if->dma_enable == 0) {
  61086. + ep->xfer_len += deptsiz.b.xfersize;
  61087. + } else {
  61088. + ep->xfer_len = deptsiz.b.xfersize;
  61089. + }
  61090. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  61091. + } else {
  61092. + ep->xfer_len =
  61093. + (ep->total_len - ep->xfer_count) >
  61094. + ep->maxpacket ? ep->maxpacket : (ep->total_len -
  61095. + ep->xfer_count);
  61096. +
  61097. + dma_desc = core_if->dev_if->in_desc_addr;
  61098. +
  61099. + /** DMA Descriptor Setup */
  61100. + dma_desc->status.b.bs = BS_HOST_BUSY;
  61101. + dma_desc->status.b.l = 1;
  61102. + dma_desc->status.b.ioc = 1;
  61103. + dma_desc->status.b.sp =
  61104. + (ep->xfer_len == ep->maxpacket) ? 0 : 1;
  61105. + dma_desc->status.b.bytes = ep->xfer_len;
  61106. + dma_desc->buf = ep->dma_addr;
  61107. + dma_desc->status.b.sts = 0;
  61108. + dma_desc->status.b.bs = BS_HOST_READY;
  61109. +
  61110. + /** DIEPDMA0 Register write */
  61111. + DWC_WRITE_REG32(&in_regs->diepdma,
  61112. + core_if->dev_if->dma_in_desc_addr);
  61113. + }
  61114. +
  61115. + DWC_DEBUGPL(DBG_PCDV,
  61116. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  61117. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  61118. + deptsiz.d32);
  61119. +
  61120. + /* Write the DMA register */
  61121. + if (core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
  61122. + if (core_if->dma_desc_enable == 0)
  61123. + DWC_WRITE_REG32(&(in_regs->diepdma),
  61124. + (uint32_t) ep->dma_addr);
  61125. + }
  61126. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  61127. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  61128. + /* EP enable, IN data in FIFO */
  61129. + depctl.b.cnak = 1;
  61130. + depctl.b.epena = 1;
  61131. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  61132. +
  61133. + /**
  61134. + * Enable the Non-Periodic Tx FIFO empty interrupt, the
  61135. + * data will be written into the fifo by the ISR.
  61136. + */
  61137. + if (!core_if->dma_enable) {
  61138. + if (core_if->en_multiple_tx_fifo == 0) {
  61139. + /* First clear it from GINTSTS */
  61140. + intr_mask.b.nptxfempty = 1;
  61141. + DWC_MODIFY_REG32(&core_if->
  61142. + core_global_regs->gintmsk,
  61143. + intr_mask.d32, intr_mask.d32);
  61144. +
  61145. + } else {
  61146. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  61147. + if (ep->xfer_len > 0) {
  61148. + uint32_t fifoemptymsk = 0;
  61149. + fifoemptymsk |= 1 << ep->num;
  61150. + DWC_MODIFY_REG32(&core_if->
  61151. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  61152. + 0, fifoemptymsk);
  61153. + }
  61154. + }
  61155. + }
  61156. + } else {
  61157. + dwc_otg_dev_out_ep_regs_t *out_regs =
  61158. + core_if->dev_if->out_ep_regs[0];
  61159. +
  61160. + depctl.d32 = DWC_READ_REG32(&out_regs->doepctl);
  61161. + deptsiz.d32 = DWC_READ_REG32(&out_regs->doeptsiz);
  61162. +
  61163. + /* Program the transfer size and packet count
  61164. + * as follows: xfersize = N * maxpacket +
  61165. + * short_packet pktcnt = N + (short_packet
  61166. + * exist ? 1 : 0)
  61167. + */
  61168. + deptsiz.b.xfersize = ep->maxpacket;
  61169. + deptsiz.b.pktcnt = 1;
  61170. +
  61171. + if (core_if->dma_desc_enable == 0) {
  61172. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  61173. + } else {
  61174. + dma_desc = core_if->dev_if->out_desc_addr;
  61175. +
  61176. + /** DMA Descriptor Setup */
  61177. + dma_desc->status.b.bs = BS_HOST_BUSY;
  61178. + dma_desc->status.b.l = 1;
  61179. + dma_desc->status.b.ioc = 1;
  61180. + dma_desc->status.b.bytes = ep->maxpacket;
  61181. + dma_desc->buf = ep->dma_addr;
  61182. + dma_desc->status.b.sts = 0;
  61183. + dma_desc->status.b.bs = BS_HOST_READY;
  61184. +
  61185. + /** DOEPDMA0 Register write */
  61186. + DWC_WRITE_REG32(&out_regs->doepdma,
  61187. + core_if->dev_if->dma_out_desc_addr);
  61188. + }
  61189. +
  61190. + DWC_DEBUGPL(DBG_PCDV,
  61191. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  61192. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  61193. + deptsiz.d32);
  61194. +
  61195. + /* Write the DMA register */
  61196. + if (core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
  61197. + if (core_if->dma_desc_enable == 0)
  61198. + DWC_WRITE_REG32(&(out_regs->doepdma),
  61199. + (uint32_t) ep->dma_addr);
  61200. +
  61201. + }
  61202. +
  61203. + /* EP enable, IN data in FIFO */
  61204. + depctl.b.cnak = 1;
  61205. + depctl.b.epena = 1;
  61206. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  61207. +
  61208. + }
  61209. +}
  61210. +
  61211. +#ifdef DEBUG
  61212. +void dump_msg(const u8 * buf, unsigned int length)
  61213. +{
  61214. + unsigned int start, num, i;
  61215. + char line[52], *p;
  61216. +
  61217. + if (length >= 512)
  61218. + return;
  61219. + start = 0;
  61220. + while (length > 0) {
  61221. + num = length < 16u ? length : 16u;
  61222. + p = line;
  61223. + for (i = 0; i < num; ++i) {
  61224. + if (i == 8)
  61225. + *p++ = ' ';
  61226. + DWC_SPRINTF(p, " %02x", buf[i]);
  61227. + p += 3;
  61228. + }
  61229. + *p = 0;
  61230. + DWC_PRINTF("%6x: %s\n", start, line);
  61231. + buf += num;
  61232. + start += num;
  61233. + length -= num;
  61234. + }
  61235. +}
  61236. +#else
  61237. +static inline void dump_msg(const u8 * buf, unsigned int length)
  61238. +{
  61239. +}
  61240. +#endif
  61241. +
  61242. +/**
  61243. + * This function writes a packet into the Tx FIFO associated with the
  61244. + * EP. For non-periodic EPs the non-periodic Tx FIFO is written. For
  61245. + * periodic EPs the periodic Tx FIFO associated with the EP is written
  61246. + * with all packets for the next micro-frame.
  61247. + *
  61248. + * @param core_if Programming view of DWC_otg controller.
  61249. + * @param ep The EP to write packet for.
  61250. + * @param dma Indicates if DMA is being used.
  61251. + */
  61252. +void dwc_otg_ep_write_packet(dwc_otg_core_if_t * core_if, dwc_ep_t * ep,
  61253. + int dma)
  61254. +{
  61255. + /**
  61256. + * The buffer is padded to DWORD on a per packet basis in
  61257. + * slave/dma mode if the MPS is not DWORD aligned. The last
  61258. + * packet, if short, is also padded to a multiple of DWORD.
  61259. + *
  61260. + * ep->xfer_buff always starts DWORD aligned in memory and is a
  61261. + * multiple of DWORD in length
  61262. + *
  61263. + * ep->xfer_len can be any number of bytes
  61264. + *
  61265. + * ep->xfer_count is a multiple of ep->maxpacket until the last
  61266. + * packet
  61267. + *
  61268. + * FIFO access is DWORD */
  61269. +
  61270. + uint32_t i;
  61271. + uint32_t byte_count;
  61272. + uint32_t dword_count;
  61273. + uint32_t *fifo;
  61274. + uint32_t *data_buff = (uint32_t *) ep->xfer_buff;
  61275. +
  61276. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p)\n", __func__, core_if,
  61277. + ep);
  61278. + if (ep->xfer_count >= ep->xfer_len) {
  61279. + DWC_WARN("%s() No data for EP%d!!!\n", __func__, ep->num);
  61280. + return;
  61281. + }
  61282. +
  61283. + /* Find the byte length of the packet either short packet or MPS */
  61284. + if ((ep->xfer_len - ep->xfer_count) < ep->maxpacket) {
  61285. + byte_count = ep->xfer_len - ep->xfer_count;
  61286. + } else {
  61287. + byte_count = ep->maxpacket;
  61288. + }
  61289. +
  61290. + /* Find the DWORD length, padded by extra bytes as neccessary if MPS
  61291. + * is not a multiple of DWORD */
  61292. + dword_count = (byte_count + 3) / 4;
  61293. +
  61294. +#ifdef VERBOSE
  61295. + dump_msg(ep->xfer_buff, byte_count);
  61296. +#endif
  61297. +
  61298. + /**@todo NGS Where are the Periodic Tx FIFO addresses
  61299. + * intialized? What should this be? */
  61300. +
  61301. + fifo = core_if->data_fifo[ep->num];
  61302. +
  61303. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "fifo=%p buff=%p *p=%08x bc=%d\n",
  61304. + fifo, data_buff, *data_buff, byte_count);
  61305. +
  61306. + if (!dma) {
  61307. + for (i = 0; i < dword_count; i++, data_buff++) {
  61308. + DWC_WRITE_REG32(fifo, *data_buff);
  61309. + }
  61310. + }
  61311. +
  61312. + ep->xfer_count += byte_count;
  61313. + ep->xfer_buff += byte_count;
  61314. + ep->dma_addr += byte_count;
  61315. +}
  61316. +
  61317. +/**
  61318. + * Set the EP STALL.
  61319. + *
  61320. + * @param core_if Programming view of DWC_otg controller.
  61321. + * @param ep The EP to set the stall on.
  61322. + */
  61323. +void dwc_otg_ep_set_stall(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  61324. +{
  61325. + depctl_data_t depctl;
  61326. + volatile uint32_t *depctl_addr;
  61327. +
  61328. + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, ep->num,
  61329. + (ep->is_in ? "IN" : "OUT"));
  61330. +
  61331. + if (ep->is_in == 1) {
  61332. + depctl_addr = &(core_if->dev_if->in_ep_regs[ep->num]->diepctl);
  61333. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  61334. +
  61335. + /* set the disable and stall bits */
  61336. + if (depctl.b.epena) {
  61337. + depctl.b.epdis = 1;
  61338. + }
  61339. + depctl.b.stall = 1;
  61340. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  61341. + } else {
  61342. + depctl_addr = &(core_if->dev_if->out_ep_regs[ep->num]->doepctl);
  61343. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  61344. +
  61345. + /* set the stall bit */
  61346. + depctl.b.stall = 1;
  61347. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  61348. + }
  61349. +
  61350. + DWC_DEBUGPL(DBG_PCD, "DEPCTL=%0x\n", DWC_READ_REG32(depctl_addr));
  61351. +
  61352. + return;
  61353. +}
  61354. +
  61355. +/**
  61356. + * Clear the EP STALL.
  61357. + *
  61358. + * @param core_if Programming view of DWC_otg controller.
  61359. + * @param ep The EP to clear stall from.
  61360. + */
  61361. +void dwc_otg_ep_clear_stall(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  61362. +{
  61363. + depctl_data_t depctl;
  61364. + volatile uint32_t *depctl_addr;
  61365. +
  61366. + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, ep->num,
  61367. + (ep->is_in ? "IN" : "OUT"));
  61368. +
  61369. + if (ep->is_in == 1) {
  61370. + depctl_addr = &(core_if->dev_if->in_ep_regs[ep->num]->diepctl);
  61371. + } else {
  61372. + depctl_addr = &(core_if->dev_if->out_ep_regs[ep->num]->doepctl);
  61373. + }
  61374. +
  61375. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  61376. +
  61377. + /* clear the stall bits */
  61378. + depctl.b.stall = 0;
  61379. +
  61380. + /*
  61381. + * USB Spec 9.4.5: For endpoints using data toggle, regardless
  61382. + * of whether an endpoint has the Halt feature set, a
  61383. + * ClearFeature(ENDPOINT_HALT) request always results in the
  61384. + * data toggle being reinitialized to DATA0.
  61385. + */
  61386. + if (ep->type == DWC_OTG_EP_TYPE_INTR ||
  61387. + ep->type == DWC_OTG_EP_TYPE_BULK) {
  61388. + depctl.b.setd0pid = 1; /* DATA0 */
  61389. + }
  61390. +
  61391. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  61392. + DWC_DEBUGPL(DBG_PCD, "DEPCTL=%0x\n", DWC_READ_REG32(depctl_addr));
  61393. + return;
  61394. +}
  61395. +
  61396. +/**
  61397. + * This function reads a packet from the Rx FIFO into the destination
  61398. + * buffer. To read SETUP data use dwc_otg_read_setup_packet.
  61399. + *
  61400. + * @param core_if Programming view of DWC_otg controller.
  61401. + * @param dest Destination buffer for the packet.
  61402. + * @param bytes Number of bytes to copy to the destination.
  61403. + */
  61404. +void dwc_otg_read_packet(dwc_otg_core_if_t * core_if,
  61405. + uint8_t * dest, uint16_t bytes)
  61406. +{
  61407. + int i;
  61408. + int word_count = (bytes + 3) / 4;
  61409. +
  61410. + volatile uint32_t *fifo = core_if->data_fifo[0];
  61411. + uint32_t *data_buff = (uint32_t *) dest;
  61412. +
  61413. + /**
  61414. + * @todo Account for the case where _dest is not dword aligned. This
  61415. + * requires reading data from the FIFO into a uint32_t temp buffer,
  61416. + * then moving it into the data buffer.
  61417. + */
  61418. +
  61419. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p,%d)\n", __func__,
  61420. + core_if, dest, bytes);
  61421. +
  61422. + for (i = 0; i < word_count; i++, data_buff++) {
  61423. + *data_buff = DWC_READ_REG32(fifo);
  61424. + }
  61425. +
  61426. + return;
  61427. +}
  61428. +
  61429. +/**
  61430. + * This functions reads the device registers and prints them
  61431. + *
  61432. + * @param core_if Programming view of DWC_otg controller.
  61433. + */
  61434. +void dwc_otg_dump_dev_registers(dwc_otg_core_if_t * core_if)
  61435. +{
  61436. + int i;
  61437. + volatile uint32_t *addr;
  61438. +
  61439. + DWC_PRINTF("Device Global Registers\n");
  61440. + addr = &core_if->dev_if->dev_global_regs->dcfg;
  61441. + DWC_PRINTF("DCFG @0x%08lX : 0x%08X\n",
  61442. + (unsigned long)addr, DWC_READ_REG32(addr));
  61443. + addr = &core_if->dev_if->dev_global_regs->dctl;
  61444. + DWC_PRINTF("DCTL @0x%08lX : 0x%08X\n",
  61445. + (unsigned long)addr, DWC_READ_REG32(addr));
  61446. + addr = &core_if->dev_if->dev_global_regs->dsts;
  61447. + DWC_PRINTF("DSTS @0x%08lX : 0x%08X\n",
  61448. + (unsigned long)addr, DWC_READ_REG32(addr));
  61449. + addr = &core_if->dev_if->dev_global_regs->diepmsk;
  61450. + DWC_PRINTF("DIEPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61451. + DWC_READ_REG32(addr));
  61452. + addr = &core_if->dev_if->dev_global_regs->doepmsk;
  61453. + DWC_PRINTF("DOEPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61454. + DWC_READ_REG32(addr));
  61455. + addr = &core_if->dev_if->dev_global_regs->daint;
  61456. + DWC_PRINTF("DAINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61457. + DWC_READ_REG32(addr));
  61458. + addr = &core_if->dev_if->dev_global_regs->daintmsk;
  61459. + DWC_PRINTF("DAINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61460. + DWC_READ_REG32(addr));
  61461. + addr = &core_if->dev_if->dev_global_regs->dtknqr1;
  61462. + DWC_PRINTF("DTKNQR1 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61463. + DWC_READ_REG32(addr));
  61464. + if (core_if->hwcfg2.b.dev_token_q_depth > 6) {
  61465. + addr = &core_if->dev_if->dev_global_regs->dtknqr2;
  61466. + DWC_PRINTF("DTKNQR2 @0x%08lX : 0x%08X\n",
  61467. + (unsigned long)addr, DWC_READ_REG32(addr));
  61468. + }
  61469. +
  61470. + addr = &core_if->dev_if->dev_global_regs->dvbusdis;
  61471. + DWC_PRINTF("DVBUSID @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61472. + DWC_READ_REG32(addr));
  61473. +
  61474. + addr = &core_if->dev_if->dev_global_regs->dvbuspulse;
  61475. + DWC_PRINTF("DVBUSPULSE @0x%08lX : 0x%08X\n",
  61476. + (unsigned long)addr, DWC_READ_REG32(addr));
  61477. +
  61478. + addr = &core_if->dev_if->dev_global_regs->dtknqr3_dthrctl;
  61479. + DWC_PRINTF("DTKNQR3_DTHRCTL @0x%08lX : 0x%08X\n",
  61480. + (unsigned long)addr, DWC_READ_REG32(addr));
  61481. +
  61482. + if (core_if->hwcfg2.b.dev_token_q_depth > 22) {
  61483. + addr = &core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
  61484. + DWC_PRINTF("DTKNQR4 @0x%08lX : 0x%08X\n",
  61485. + (unsigned long)addr, DWC_READ_REG32(addr));
  61486. + }
  61487. +
  61488. + addr = &core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
  61489. + DWC_PRINTF("FIFOEMPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61490. + DWC_READ_REG32(addr));
  61491. +
  61492. + if (core_if->hwcfg2.b.multi_proc_int) {
  61493. +
  61494. + addr = &core_if->dev_if->dev_global_regs->deachint;
  61495. + DWC_PRINTF("DEACHINT @0x%08lX : 0x%08X\n",
  61496. + (unsigned long)addr, DWC_READ_REG32(addr));
  61497. + addr = &core_if->dev_if->dev_global_regs->deachintmsk;
  61498. + DWC_PRINTF("DEACHINTMSK @0x%08lX : 0x%08X\n",
  61499. + (unsigned long)addr, DWC_READ_REG32(addr));
  61500. +
  61501. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  61502. + addr =
  61503. + &core_if->dev_if->
  61504. + dev_global_regs->diepeachintmsk[i];
  61505. + DWC_PRINTF("DIEPEACHINTMSK[%d] @0x%08lX : 0x%08X\n",
  61506. + i, (unsigned long)addr,
  61507. + DWC_READ_REG32(addr));
  61508. + }
  61509. +
  61510. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  61511. + addr =
  61512. + &core_if->dev_if->
  61513. + dev_global_regs->doepeachintmsk[i];
  61514. + DWC_PRINTF("DOEPEACHINTMSK[%d] @0x%08lX : 0x%08X\n",
  61515. + i, (unsigned long)addr,
  61516. + DWC_READ_REG32(addr));
  61517. + }
  61518. + }
  61519. +
  61520. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  61521. + DWC_PRINTF("Device IN EP %d Registers\n", i);
  61522. + addr = &core_if->dev_if->in_ep_regs[i]->diepctl;
  61523. + DWC_PRINTF("DIEPCTL @0x%08lX : 0x%08X\n",
  61524. + (unsigned long)addr, DWC_READ_REG32(addr));
  61525. + addr = &core_if->dev_if->in_ep_regs[i]->diepint;
  61526. + DWC_PRINTF("DIEPINT @0x%08lX : 0x%08X\n",
  61527. + (unsigned long)addr, DWC_READ_REG32(addr));
  61528. + addr = &core_if->dev_if->in_ep_regs[i]->dieptsiz;
  61529. + DWC_PRINTF("DIETSIZ @0x%08lX : 0x%08X\n",
  61530. + (unsigned long)addr, DWC_READ_REG32(addr));
  61531. + addr = &core_if->dev_if->in_ep_regs[i]->diepdma;
  61532. + DWC_PRINTF("DIEPDMA @0x%08lX : 0x%08X\n",
  61533. + (unsigned long)addr, DWC_READ_REG32(addr));
  61534. + addr = &core_if->dev_if->in_ep_regs[i]->dtxfsts;
  61535. + DWC_PRINTF("DTXFSTS @0x%08lX : 0x%08X\n",
  61536. + (unsigned long)addr, DWC_READ_REG32(addr));
  61537. + addr = &core_if->dev_if->in_ep_regs[i]->diepdmab;
  61538. + DWC_PRINTF("DIEPDMAB @0x%08lX : 0x%08X\n",
  61539. + (unsigned long)addr, 0 /*DWC_READ_REG32(addr) */ );
  61540. + }
  61541. +
  61542. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  61543. + DWC_PRINTF("Device OUT EP %d Registers\n", i);
  61544. + addr = &core_if->dev_if->out_ep_regs[i]->doepctl;
  61545. + DWC_PRINTF("DOEPCTL @0x%08lX : 0x%08X\n",
  61546. + (unsigned long)addr, DWC_READ_REG32(addr));
  61547. + addr = &core_if->dev_if->out_ep_regs[i]->doepint;
  61548. + DWC_PRINTF("DOEPINT @0x%08lX : 0x%08X\n",
  61549. + (unsigned long)addr, DWC_READ_REG32(addr));
  61550. + addr = &core_if->dev_if->out_ep_regs[i]->doeptsiz;
  61551. + DWC_PRINTF("DOETSIZ @0x%08lX : 0x%08X\n",
  61552. + (unsigned long)addr, DWC_READ_REG32(addr));
  61553. + addr = &core_if->dev_if->out_ep_regs[i]->doepdma;
  61554. + DWC_PRINTF("DOEPDMA @0x%08lX : 0x%08X\n",
  61555. + (unsigned long)addr, DWC_READ_REG32(addr));
  61556. + if (core_if->dma_enable) { /* Don't access this register in SLAVE mode */
  61557. + addr = &core_if->dev_if->out_ep_regs[i]->doepdmab;
  61558. + DWC_PRINTF("DOEPDMAB @0x%08lX : 0x%08X\n",
  61559. + (unsigned long)addr, DWC_READ_REG32(addr));
  61560. + }
  61561. +
  61562. + }
  61563. +}
  61564. +
  61565. +/**
  61566. + * This functions reads the SPRAM and prints its content
  61567. + *
  61568. + * @param core_if Programming view of DWC_otg controller.
  61569. + */
  61570. +void dwc_otg_dump_spram(dwc_otg_core_if_t * core_if)
  61571. +{
  61572. + volatile uint8_t *addr, *start_addr, *end_addr;
  61573. +
  61574. + DWC_PRINTF("SPRAM Data:\n");
  61575. + start_addr = (void *)core_if->core_global_regs;
  61576. + DWC_PRINTF("Base Address: 0x%8lX\n", (unsigned long)start_addr);
  61577. + start_addr += 0x00028000;
  61578. + end_addr = (void *)core_if->core_global_regs;
  61579. + end_addr += 0x000280e0;
  61580. +
  61581. + for (addr = start_addr; addr < end_addr; addr += 16) {
  61582. + DWC_PRINTF
  61583. + ("0x%8lX:\t%2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X\n",
  61584. + (unsigned long)addr, addr[0], addr[1], addr[2], addr[3],
  61585. + addr[4], addr[5], addr[6], addr[7], addr[8], addr[9],
  61586. + addr[10], addr[11], addr[12], addr[13], addr[14], addr[15]
  61587. + );
  61588. + }
  61589. +
  61590. + return;
  61591. +}
  61592. +
  61593. +/**
  61594. + * This function reads the host registers and prints them
  61595. + *
  61596. + * @param core_if Programming view of DWC_otg controller.
  61597. + */
  61598. +void dwc_otg_dump_host_registers(dwc_otg_core_if_t * core_if)
  61599. +{
  61600. + int i;
  61601. + volatile uint32_t *addr;
  61602. +
  61603. + DWC_PRINTF("Host Global Registers\n");
  61604. + addr = &core_if->host_if->host_global_regs->hcfg;
  61605. + DWC_PRINTF("HCFG @0x%08lX : 0x%08X\n",
  61606. + (unsigned long)addr, DWC_READ_REG32(addr));
  61607. + addr = &core_if->host_if->host_global_regs->hfir;
  61608. + DWC_PRINTF("HFIR @0x%08lX : 0x%08X\n",
  61609. + (unsigned long)addr, DWC_READ_REG32(addr));
  61610. + addr = &core_if->host_if->host_global_regs->hfnum;
  61611. + DWC_PRINTF("HFNUM @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61612. + DWC_READ_REG32(addr));
  61613. + addr = &core_if->host_if->host_global_regs->hptxsts;
  61614. + DWC_PRINTF("HPTXSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61615. + DWC_READ_REG32(addr));
  61616. + addr = &core_if->host_if->host_global_regs->haint;
  61617. + DWC_PRINTF("HAINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61618. + DWC_READ_REG32(addr));
  61619. + addr = &core_if->host_if->host_global_regs->haintmsk;
  61620. + DWC_PRINTF("HAINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61621. + DWC_READ_REG32(addr));
  61622. + if (core_if->dma_desc_enable) {
  61623. + addr = &core_if->host_if->host_global_regs->hflbaddr;
  61624. + DWC_PRINTF("HFLBADDR @0x%08lX : 0x%08X\n",
  61625. + (unsigned long)addr, DWC_READ_REG32(addr));
  61626. + }
  61627. +
  61628. + addr = core_if->host_if->hprt0;
  61629. + DWC_PRINTF("HPRT0 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61630. + DWC_READ_REG32(addr));
  61631. +
  61632. + for (i = 0; i < core_if->core_params->host_channels; i++) {
  61633. + DWC_PRINTF("Host Channel %d Specific Registers\n", i);
  61634. + addr = &core_if->host_if->hc_regs[i]->hcchar;
  61635. + DWC_PRINTF("HCCHAR @0x%08lX : 0x%08X\n",
  61636. + (unsigned long)addr, DWC_READ_REG32(addr));
  61637. + addr = &core_if->host_if->hc_regs[i]->hcsplt;
  61638. + DWC_PRINTF("HCSPLT @0x%08lX : 0x%08X\n",
  61639. + (unsigned long)addr, DWC_READ_REG32(addr));
  61640. + addr = &core_if->host_if->hc_regs[i]->hcint;
  61641. + DWC_PRINTF("HCINT @0x%08lX : 0x%08X\n",
  61642. + (unsigned long)addr, DWC_READ_REG32(addr));
  61643. + addr = &core_if->host_if->hc_regs[i]->hcintmsk;
  61644. + DWC_PRINTF("HCINTMSK @0x%08lX : 0x%08X\n",
  61645. + (unsigned long)addr, DWC_READ_REG32(addr));
  61646. + addr = &core_if->host_if->hc_regs[i]->hctsiz;
  61647. + DWC_PRINTF("HCTSIZ @0x%08lX : 0x%08X\n",
  61648. + (unsigned long)addr, DWC_READ_REG32(addr));
  61649. + addr = &core_if->host_if->hc_regs[i]->hcdma;
  61650. + DWC_PRINTF("HCDMA @0x%08lX : 0x%08X\n",
  61651. + (unsigned long)addr, DWC_READ_REG32(addr));
  61652. + if (core_if->dma_desc_enable) {
  61653. + addr = &core_if->host_if->hc_regs[i]->hcdmab;
  61654. + DWC_PRINTF("HCDMAB @0x%08lX : 0x%08X\n",
  61655. + (unsigned long)addr, DWC_READ_REG32(addr));
  61656. + }
  61657. +
  61658. + }
  61659. + return;
  61660. +}
  61661. +
  61662. +/**
  61663. + * This function reads the core global registers and prints them
  61664. + *
  61665. + * @param core_if Programming view of DWC_otg controller.
  61666. + */
  61667. +void dwc_otg_dump_global_registers(dwc_otg_core_if_t * core_if)
  61668. +{
  61669. + int i, ep_num;
  61670. + volatile uint32_t *addr;
  61671. + char *txfsiz;
  61672. +
  61673. + DWC_PRINTF("Core Global Registers\n");
  61674. + addr = &core_if->core_global_regs->gotgctl;
  61675. + DWC_PRINTF("GOTGCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61676. + DWC_READ_REG32(addr));
  61677. + addr = &core_if->core_global_regs->gotgint;
  61678. + DWC_PRINTF("GOTGINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61679. + DWC_READ_REG32(addr));
  61680. + addr = &core_if->core_global_regs->gahbcfg;
  61681. + DWC_PRINTF("GAHBCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61682. + DWC_READ_REG32(addr));
  61683. + addr = &core_if->core_global_regs->gusbcfg;
  61684. + DWC_PRINTF("GUSBCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61685. + DWC_READ_REG32(addr));
  61686. + addr = &core_if->core_global_regs->grstctl;
  61687. + DWC_PRINTF("GRSTCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61688. + DWC_READ_REG32(addr));
  61689. + addr = &core_if->core_global_regs->gintsts;
  61690. + DWC_PRINTF("GINTSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61691. + DWC_READ_REG32(addr));
  61692. + addr = &core_if->core_global_regs->gintmsk;
  61693. + DWC_PRINTF("GINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61694. + DWC_READ_REG32(addr));
  61695. + addr = &core_if->core_global_regs->grxstsr;
  61696. + DWC_PRINTF("GRXSTSR @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61697. + DWC_READ_REG32(addr));
  61698. + addr = &core_if->core_global_regs->grxfsiz;
  61699. + DWC_PRINTF("GRXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61700. + DWC_READ_REG32(addr));
  61701. + addr = &core_if->core_global_regs->gnptxfsiz;
  61702. + DWC_PRINTF("GNPTXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61703. + DWC_READ_REG32(addr));
  61704. + addr = &core_if->core_global_regs->gnptxsts;
  61705. + DWC_PRINTF("GNPTXSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61706. + DWC_READ_REG32(addr));
  61707. + addr = &core_if->core_global_regs->gi2cctl;
  61708. + DWC_PRINTF("GI2CCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61709. + DWC_READ_REG32(addr));
  61710. + addr = &core_if->core_global_regs->gpvndctl;
  61711. + DWC_PRINTF("GPVNDCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61712. + DWC_READ_REG32(addr));
  61713. + addr = &core_if->core_global_regs->ggpio;
  61714. + DWC_PRINTF("GGPIO @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61715. + DWC_READ_REG32(addr));
  61716. + addr = &core_if->core_global_regs->guid;
  61717. + DWC_PRINTF("GUID @0x%08lX : 0x%08X\n",
  61718. + (unsigned long)addr, DWC_READ_REG32(addr));
  61719. + addr = &core_if->core_global_regs->gsnpsid;
  61720. + DWC_PRINTF("GSNPSID @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61721. + DWC_READ_REG32(addr));
  61722. + addr = &core_if->core_global_regs->ghwcfg1;
  61723. + DWC_PRINTF("GHWCFG1 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61724. + DWC_READ_REG32(addr));
  61725. + addr = &core_if->core_global_regs->ghwcfg2;
  61726. + DWC_PRINTF("GHWCFG2 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61727. + DWC_READ_REG32(addr));
  61728. + addr = &core_if->core_global_regs->ghwcfg3;
  61729. + DWC_PRINTF("GHWCFG3 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61730. + DWC_READ_REG32(addr));
  61731. + addr = &core_if->core_global_regs->ghwcfg4;
  61732. + DWC_PRINTF("GHWCFG4 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61733. + DWC_READ_REG32(addr));
  61734. + addr = &core_if->core_global_regs->glpmcfg;
  61735. + DWC_PRINTF("GLPMCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61736. + DWC_READ_REG32(addr));
  61737. + addr = &core_if->core_global_regs->gpwrdn;
  61738. + DWC_PRINTF("GPWRDN @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61739. + DWC_READ_REG32(addr));
  61740. + addr = &core_if->core_global_regs->gdfifocfg;
  61741. + DWC_PRINTF("GDFIFOCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61742. + DWC_READ_REG32(addr));
  61743. + addr = &core_if->core_global_regs->adpctl;
  61744. + DWC_PRINTF("ADPCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61745. + dwc_otg_adp_read_reg(core_if));
  61746. + addr = &core_if->core_global_regs->hptxfsiz;
  61747. + DWC_PRINTF("HPTXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61748. + DWC_READ_REG32(addr));
  61749. +
  61750. + if (core_if->en_multiple_tx_fifo == 0) {
  61751. + ep_num = core_if->hwcfg4.b.num_dev_perio_in_ep;
  61752. + txfsiz = "DPTXFSIZ";
  61753. + } else {
  61754. + ep_num = core_if->hwcfg4.b.num_in_eps;
  61755. + txfsiz = "DIENPTXF";
  61756. + }
  61757. + for (i = 0; i < ep_num; i++) {
  61758. + addr = &core_if->core_global_regs->dtxfsiz[i];
  61759. + DWC_PRINTF("%s[%d] @0x%08lX : 0x%08X\n", txfsiz, i + 1,
  61760. + (unsigned long)addr, DWC_READ_REG32(addr));
  61761. + }
  61762. + addr = core_if->pcgcctl;
  61763. + DWC_PRINTF("PCGCCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61764. + DWC_READ_REG32(addr));
  61765. +}
  61766. +
  61767. +/**
  61768. + * Flush a Tx FIFO.
  61769. + *
  61770. + * @param core_if Programming view of DWC_otg controller.
  61771. + * @param num Tx FIFO to flush.
  61772. + */
  61773. +void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t * core_if, const int num)
  61774. +{
  61775. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  61776. + volatile grstctl_t greset = {.d32 = 0 };
  61777. + int count = 0;
  61778. +
  61779. + DWC_DEBUGPL((DBG_CIL | DBG_PCDV), "Flush Tx FIFO %d\n", num);
  61780. +
  61781. + greset.b.txfflsh = 1;
  61782. + greset.b.txfnum = num;
  61783. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  61784. +
  61785. + do {
  61786. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  61787. + if (++count > 10000) {
  61788. + DWC_WARN("%s() HANG! GRSTCTL=%0x GNPTXSTS=0x%08x\n",
  61789. + __func__, greset.d32,
  61790. + DWC_READ_REG32(&global_regs->gnptxsts));
  61791. + break;
  61792. + }
  61793. + dwc_udelay(1);
  61794. + } while (greset.b.txfflsh == 1);
  61795. +
  61796. + /* Wait for 3 PHY Clocks */
  61797. + dwc_udelay(1);
  61798. +}
  61799. +
  61800. +/**
  61801. + * Flush Rx FIFO.
  61802. + *
  61803. + * @param core_if Programming view of DWC_otg controller.
  61804. + */
  61805. +void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t * core_if)
  61806. +{
  61807. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  61808. + volatile grstctl_t greset = {.d32 = 0 };
  61809. + int count = 0;
  61810. +
  61811. + DWC_DEBUGPL((DBG_CIL | DBG_PCDV), "%s\n", __func__);
  61812. + /*
  61813. + *
  61814. + */
  61815. + greset.b.rxfflsh = 1;
  61816. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  61817. +
  61818. + do {
  61819. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  61820. + if (++count > 10000) {
  61821. + DWC_WARN("%s() HANG! GRSTCTL=%0x\n", __func__,
  61822. + greset.d32);
  61823. + break;
  61824. + }
  61825. + dwc_udelay(1);
  61826. + } while (greset.b.rxfflsh == 1);
  61827. +
  61828. + /* Wait for 3 PHY Clocks */
  61829. + dwc_udelay(1);
  61830. +}
  61831. +
  61832. +/**
  61833. + * Do core a soft reset of the core. Be careful with this because it
  61834. + * resets all the internal state machines of the core.
  61835. + */
  61836. +void dwc_otg_core_reset(dwc_otg_core_if_t * core_if)
  61837. +{
  61838. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  61839. + volatile grstctl_t greset = {.d32 = 0 };
  61840. + int count = 0;
  61841. +
  61842. + DWC_DEBUGPL(DBG_CILV, "%s\n", __func__);
  61843. + /* Wait for AHB master IDLE state. */
  61844. + do {
  61845. + dwc_udelay(10);
  61846. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  61847. + if (++count > 100000) {
  61848. + DWC_WARN("%s() HANG! AHB Idle GRSTCTL=%0x\n", __func__,
  61849. + greset.d32);
  61850. + return;
  61851. + }
  61852. + }
  61853. + while (greset.b.ahbidle == 0);
  61854. +
  61855. + /* Core Soft Reset */
  61856. + count = 0;
  61857. + greset.b.csftrst = 1;
  61858. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  61859. + do {
  61860. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  61861. + if (++count > 10000) {
  61862. + DWC_WARN("%s() HANG! Soft Reset GRSTCTL=%0x\n",
  61863. + __func__, greset.d32);
  61864. + break;
  61865. + }
  61866. + dwc_udelay(1);
  61867. + }
  61868. + while (greset.b.csftrst == 1);
  61869. +
  61870. + /* Wait for 3 PHY Clocks */
  61871. + dwc_mdelay(100);
  61872. +}
  61873. +
  61874. +uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t * _core_if)
  61875. +{
  61876. + return (dwc_otg_mode(_core_if) != DWC_HOST_MODE);
  61877. +}
  61878. +
  61879. +uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t * _core_if)
  61880. +{
  61881. + return (dwc_otg_mode(_core_if) == DWC_HOST_MODE);
  61882. +}
  61883. +
  61884. +/**
  61885. + * Register HCD callbacks. The callbacks are used to start and stop
  61886. + * the HCD for interrupt processing.
  61887. + *
  61888. + * @param core_if Programming view of DWC_otg controller.
  61889. + * @param cb the HCD callback structure.
  61890. + * @param p pointer to be passed to callback function (usb_hcd*).
  61891. + */
  61892. +void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t * core_if,
  61893. + dwc_otg_cil_callbacks_t * cb, void *p)
  61894. +{
  61895. + core_if->hcd_cb = cb;
  61896. + cb->p = p;
  61897. +}
  61898. +
  61899. +/**
  61900. + * Register PCD callbacks. The callbacks are used to start and stop
  61901. + * the PCD for interrupt processing.
  61902. + *
  61903. + * @param core_if Programming view of DWC_otg controller.
  61904. + * @param cb the PCD callback structure.
  61905. + * @param p pointer to be passed to callback function (pcd*).
  61906. + */
  61907. +void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t * core_if,
  61908. + dwc_otg_cil_callbacks_t * cb, void *p)
  61909. +{
  61910. + core_if->pcd_cb = cb;
  61911. + cb->p = p;
  61912. +}
  61913. +
  61914. +#ifdef DWC_EN_ISOC
  61915. +
  61916. +/**
  61917. + * This function writes isoc data per 1 (micro)frame into tx fifo
  61918. + *
  61919. + * @param core_if Programming view of DWC_otg controller.
  61920. + * @param ep The EP to start the transfer on.
  61921. + *
  61922. + */
  61923. +void write_isoc_frame_data(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  61924. +{
  61925. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  61926. + dtxfsts_data_t txstatus = {.d32 = 0 };
  61927. + uint32_t len = 0;
  61928. + uint32_t dwords;
  61929. +
  61930. + ep->xfer_len = ep->data_per_frame;
  61931. + ep->xfer_count = 0;
  61932. +
  61933. + ep_regs = core_if->dev_if->in_ep_regs[ep->num];
  61934. +
  61935. + len = ep->xfer_len - ep->xfer_count;
  61936. +
  61937. + if (len > ep->maxpacket) {
  61938. + len = ep->maxpacket;
  61939. + }
  61940. +
  61941. + dwords = (len + 3) / 4;
  61942. +
  61943. + /* While there is space in the queue and space in the FIFO and
  61944. + * More data to tranfer, Write packets to the Tx FIFO */
  61945. + txstatus.d32 =
  61946. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->dtxfsts);
  61947. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", ep->num, txstatus.d32);
  61948. +
  61949. + while (txstatus.b.txfspcavail > dwords &&
  61950. + ep->xfer_count < ep->xfer_len && ep->xfer_len != 0) {
  61951. + /* Write the FIFO */
  61952. + dwc_otg_ep_write_packet(core_if, ep, 0);
  61953. +
  61954. + len = ep->xfer_len - ep->xfer_count;
  61955. + if (len > ep->maxpacket) {
  61956. + len = ep->maxpacket;
  61957. + }
  61958. +
  61959. + dwords = (len + 3) / 4;
  61960. + txstatus.d32 =
  61961. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  61962. + dtxfsts);
  61963. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", ep->num,
  61964. + txstatus.d32);
  61965. + }
  61966. +}
  61967. +
  61968. +/**
  61969. + * This function initializes a descriptor chain for Isochronous transfer
  61970. + *
  61971. + * @param core_if Programming view of DWC_otg controller.
  61972. + * @param ep The EP to start the transfer on.
  61973. + *
  61974. + */
  61975. +void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t * core_if,
  61976. + dwc_ep_t * ep)
  61977. +{
  61978. + deptsiz_data_t deptsiz = {.d32 = 0 };
  61979. + depctl_data_t depctl = {.d32 = 0 };
  61980. + dsts_data_t dsts = {.d32 = 0 };
  61981. + volatile uint32_t *addr;
  61982. +
  61983. + if (ep->is_in) {
  61984. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  61985. + } else {
  61986. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  61987. + }
  61988. +
  61989. + ep->xfer_len = ep->data_per_frame;
  61990. + ep->xfer_count = 0;
  61991. + ep->xfer_buff = ep->cur_pkt_addr;
  61992. + ep->dma_addr = ep->cur_pkt_dma_addr;
  61993. +
  61994. + if (ep->is_in) {
  61995. + /* Program the transfer size and packet count
  61996. + * as follows: xfersize = N * maxpacket +
  61997. + * short_packet pktcnt = N + (short_packet
  61998. + * exist ? 1 : 0)
  61999. + */
  62000. + deptsiz.b.xfersize = ep->xfer_len;
  62001. + deptsiz.b.pktcnt =
  62002. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  62003. + deptsiz.b.mc = deptsiz.b.pktcnt;
  62004. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->dieptsiz,
  62005. + deptsiz.d32);
  62006. +
  62007. + /* Write the DMA register */
  62008. + if (core_if->dma_enable) {
  62009. + DWC_WRITE_REG32(&
  62010. + (core_if->dev_if->in_ep_regs[ep->num]->
  62011. + diepdma), (uint32_t) ep->dma_addr);
  62012. + }
  62013. + } else {
  62014. + deptsiz.b.pktcnt =
  62015. + (ep->xfer_len + (ep->maxpacket - 1)) / ep->maxpacket;
  62016. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  62017. +
  62018. + DWC_WRITE_REG32(&core_if->dev_if->
  62019. + out_ep_regs[ep->num]->doeptsiz, deptsiz.d32);
  62020. +
  62021. + if (core_if->dma_enable) {
  62022. + DWC_WRITE_REG32(&
  62023. + (core_if->dev_if->
  62024. + out_ep_regs[ep->num]->doepdma),
  62025. + (uint32_t) ep->dma_addr);
  62026. + }
  62027. + }
  62028. +
  62029. + /** Enable endpoint, clear nak */
  62030. +
  62031. + depctl.d32 = 0;
  62032. + if (ep->bInterval == 1) {
  62033. + dsts.d32 =
  62034. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  62035. + ep->next_frame = dsts.b.soffn + ep->bInterval;
  62036. +
  62037. + if (ep->next_frame & 0x1) {
  62038. + depctl.b.setd1pid = 1;
  62039. + } else {
  62040. + depctl.b.setd0pid = 1;
  62041. + }
  62042. + } else {
  62043. + ep->next_frame += ep->bInterval;
  62044. +
  62045. + if (ep->next_frame & 0x1) {
  62046. + depctl.b.setd1pid = 1;
  62047. + } else {
  62048. + depctl.b.setd0pid = 1;
  62049. + }
  62050. + }
  62051. + depctl.b.epena = 1;
  62052. + depctl.b.cnak = 1;
  62053. +
  62054. + DWC_MODIFY_REG32(addr, 0, depctl.d32);
  62055. + depctl.d32 = DWC_READ_REG32(addr);
  62056. +
  62057. + if (ep->is_in && core_if->dma_enable == 0) {
  62058. + write_isoc_frame_data(core_if, ep);
  62059. + }
  62060. +
  62061. +}
  62062. +#endif /* DWC_EN_ISOC */
  62063. +
  62064. +static void dwc_otg_set_uninitialized(int32_t * p, int size)
  62065. +{
  62066. + int i;
  62067. + for (i = 0; i < size; i++) {
  62068. + p[i] = -1;
  62069. + }
  62070. +}
  62071. +
  62072. +static int dwc_otg_param_initialized(int32_t val)
  62073. +{
  62074. + return val != -1;
  62075. +}
  62076. +
  62077. +static int dwc_otg_setup_params(dwc_otg_core_if_t * core_if)
  62078. +{
  62079. + int i;
  62080. + core_if->core_params = DWC_ALLOC(sizeof(*core_if->core_params));
  62081. + if (!core_if->core_params) {
  62082. + return -DWC_E_NO_MEMORY;
  62083. + }
  62084. + dwc_otg_set_uninitialized((int32_t *) core_if->core_params,
  62085. + sizeof(*core_if->core_params) /
  62086. + sizeof(int32_t));
  62087. + DWC_PRINTF("Setting default values for core params\n");
  62088. + dwc_otg_set_param_otg_cap(core_if, dwc_param_otg_cap_default);
  62089. + dwc_otg_set_param_dma_enable(core_if, dwc_param_dma_enable_default);
  62090. + dwc_otg_set_param_dma_desc_enable(core_if,
  62091. + dwc_param_dma_desc_enable_default);
  62092. + dwc_otg_set_param_opt(core_if, dwc_param_opt_default);
  62093. + dwc_otg_set_param_dma_burst_size(core_if,
  62094. + dwc_param_dma_burst_size_default);
  62095. + dwc_otg_set_param_host_support_fs_ls_low_power(core_if,
  62096. + dwc_param_host_support_fs_ls_low_power_default);
  62097. + dwc_otg_set_param_enable_dynamic_fifo(core_if,
  62098. + dwc_param_enable_dynamic_fifo_default);
  62099. + dwc_otg_set_param_data_fifo_size(core_if,
  62100. + dwc_param_data_fifo_size_default);
  62101. + dwc_otg_set_param_dev_rx_fifo_size(core_if,
  62102. + dwc_param_dev_rx_fifo_size_default);
  62103. + dwc_otg_set_param_dev_nperio_tx_fifo_size(core_if,
  62104. + dwc_param_dev_nperio_tx_fifo_size_default);
  62105. + dwc_otg_set_param_host_rx_fifo_size(core_if,
  62106. + dwc_param_host_rx_fifo_size_default);
  62107. + dwc_otg_set_param_host_nperio_tx_fifo_size(core_if,
  62108. + dwc_param_host_nperio_tx_fifo_size_default);
  62109. + dwc_otg_set_param_host_perio_tx_fifo_size(core_if,
  62110. + dwc_param_host_perio_tx_fifo_size_default);
  62111. + dwc_otg_set_param_max_transfer_size(core_if,
  62112. + dwc_param_max_transfer_size_default);
  62113. + dwc_otg_set_param_max_packet_count(core_if,
  62114. + dwc_param_max_packet_count_default);
  62115. + dwc_otg_set_param_host_channels(core_if,
  62116. + dwc_param_host_channels_default);
  62117. + dwc_otg_set_param_dev_endpoints(core_if,
  62118. + dwc_param_dev_endpoints_default);
  62119. + dwc_otg_set_param_phy_type(core_if, dwc_param_phy_type_default);
  62120. + dwc_otg_set_param_speed(core_if, dwc_param_speed_default);
  62121. + dwc_otg_set_param_host_ls_low_power_phy_clk(core_if,
  62122. + dwc_param_host_ls_low_power_phy_clk_default);
  62123. + dwc_otg_set_param_phy_ulpi_ddr(core_if, dwc_param_phy_ulpi_ddr_default);
  62124. + dwc_otg_set_param_phy_ulpi_ext_vbus(core_if,
  62125. + dwc_param_phy_ulpi_ext_vbus_default);
  62126. + dwc_otg_set_param_phy_utmi_width(core_if,
  62127. + dwc_param_phy_utmi_width_default);
  62128. + dwc_otg_set_param_ts_dline(core_if, dwc_param_ts_dline_default);
  62129. + dwc_otg_set_param_i2c_enable(core_if, dwc_param_i2c_enable_default);
  62130. + dwc_otg_set_param_ulpi_fs_ls(core_if, dwc_param_ulpi_fs_ls_default);
  62131. + dwc_otg_set_param_en_multiple_tx_fifo(core_if,
  62132. + dwc_param_en_multiple_tx_fifo_default);
  62133. + for (i = 0; i < 15; i++) {
  62134. + dwc_otg_set_param_dev_perio_tx_fifo_size(core_if,
  62135. + dwc_param_dev_perio_tx_fifo_size_default,
  62136. + i);
  62137. + }
  62138. +
  62139. + for (i = 0; i < 15; i++) {
  62140. + dwc_otg_set_param_dev_tx_fifo_size(core_if,
  62141. + dwc_param_dev_tx_fifo_size_default,
  62142. + i);
  62143. + }
  62144. + dwc_otg_set_param_thr_ctl(core_if, dwc_param_thr_ctl_default);
  62145. + dwc_otg_set_param_mpi_enable(core_if, dwc_param_mpi_enable_default);
  62146. + dwc_otg_set_param_pti_enable(core_if, dwc_param_pti_enable_default);
  62147. + dwc_otg_set_param_lpm_enable(core_if, dwc_param_lpm_enable_default);
  62148. + dwc_otg_set_param_ic_usb_cap(core_if, dwc_param_ic_usb_cap_default);
  62149. + dwc_otg_set_param_tx_thr_length(core_if,
  62150. + dwc_param_tx_thr_length_default);
  62151. + dwc_otg_set_param_rx_thr_length(core_if,
  62152. + dwc_param_rx_thr_length_default);
  62153. + dwc_otg_set_param_ahb_thr_ratio(core_if,
  62154. + dwc_param_ahb_thr_ratio_default);
  62155. + dwc_otg_set_param_power_down(core_if, dwc_param_power_down_default);
  62156. + dwc_otg_set_param_reload_ctl(core_if, dwc_param_reload_ctl_default);
  62157. + dwc_otg_set_param_dev_out_nak(core_if, dwc_param_dev_out_nak_default);
  62158. + dwc_otg_set_param_cont_on_bna(core_if, dwc_param_cont_on_bna_default);
  62159. + dwc_otg_set_param_ahb_single(core_if, dwc_param_ahb_single_default);
  62160. + dwc_otg_set_param_otg_ver(core_if, dwc_param_otg_ver_default);
  62161. + dwc_otg_set_param_adp_enable(core_if, dwc_param_adp_enable_default);
  62162. + DWC_PRINTF("Finished setting default values for core params\n");
  62163. +
  62164. + return 0;
  62165. +}
  62166. +
  62167. +uint8_t dwc_otg_is_dma_enable(dwc_otg_core_if_t * core_if)
  62168. +{
  62169. + return core_if->dma_enable;
  62170. +}
  62171. +
  62172. +/* Checks if the parameter is outside of its valid range of values */
  62173. +#define DWC_OTG_PARAM_TEST(_param_, _low_, _high_) \
  62174. + (((_param_) < (_low_)) || \
  62175. + ((_param_) > (_high_)))
  62176. +
  62177. +/* Parameter access functions */
  62178. +int dwc_otg_set_param_otg_cap(dwc_otg_core_if_t * core_if, int32_t val)
  62179. +{
  62180. + int valid;
  62181. + int retval = 0;
  62182. + if (DWC_OTG_PARAM_TEST(val, 0, 2)) {
  62183. + DWC_WARN("Wrong value for otg_cap parameter\n");
  62184. + DWC_WARN("otg_cap parameter must be 0,1 or 2\n");
  62185. + retval = -DWC_E_INVALID;
  62186. + goto out;
  62187. + }
  62188. +
  62189. + valid = 1;
  62190. + switch (val) {
  62191. + case DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE:
  62192. + if (core_if->hwcfg2.b.op_mode !=
  62193. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  62194. + valid = 0;
  62195. + break;
  62196. + case DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE:
  62197. + if ((core_if->hwcfg2.b.op_mode !=
  62198. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  62199. + && (core_if->hwcfg2.b.op_mode !=
  62200. + DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  62201. + && (core_if->hwcfg2.b.op_mode !=
  62202. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE)
  62203. + && (core_if->hwcfg2.b.op_mode !=
  62204. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) {
  62205. + valid = 0;
  62206. + }
  62207. + break;
  62208. + case DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE:
  62209. + /* always valid */
  62210. + break;
  62211. + }
  62212. + if (!valid) {
  62213. + if (dwc_otg_param_initialized(core_if->core_params->otg_cap)) {
  62214. + DWC_ERROR
  62215. + ("%d invalid for otg_cap paremter. Check HW configuration.\n",
  62216. + val);
  62217. + }
  62218. + val =
  62219. + (((core_if->hwcfg2.b.op_mode ==
  62220. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  62221. + || (core_if->hwcfg2.b.op_mode ==
  62222. + DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  62223. + || (core_if->hwcfg2.b.op_mode ==
  62224. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE)
  62225. + || (core_if->hwcfg2.b.op_mode ==
  62226. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) ?
  62227. + DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE :
  62228. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  62229. + retval = -DWC_E_INVALID;
  62230. + }
  62231. +
  62232. + core_if->core_params->otg_cap = val;
  62233. +out:
  62234. + return retval;
  62235. +}
  62236. +
  62237. +int32_t dwc_otg_get_param_otg_cap(dwc_otg_core_if_t * core_if)
  62238. +{
  62239. + return core_if->core_params->otg_cap;
  62240. +}
  62241. +
  62242. +int dwc_otg_set_param_opt(dwc_otg_core_if_t * core_if, int32_t val)
  62243. +{
  62244. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62245. + DWC_WARN("Wrong value for opt parameter\n");
  62246. + return -DWC_E_INVALID;
  62247. + }
  62248. + core_if->core_params->opt = val;
  62249. + return 0;
  62250. +}
  62251. +
  62252. +int32_t dwc_otg_get_param_opt(dwc_otg_core_if_t * core_if)
  62253. +{
  62254. + return core_if->core_params->opt;
  62255. +}
  62256. +
  62257. +int dwc_otg_set_param_dma_enable(dwc_otg_core_if_t * core_if, int32_t val)
  62258. +{
  62259. + int retval = 0;
  62260. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62261. + DWC_WARN("Wrong value for dma enable\n");
  62262. + return -DWC_E_INVALID;
  62263. + }
  62264. +
  62265. + if ((val == 1) && (core_if->hwcfg2.b.architecture == 0)) {
  62266. + if (dwc_otg_param_initialized(core_if->core_params->dma_enable)) {
  62267. + DWC_ERROR
  62268. + ("%d invalid for dma_enable paremter. Check HW configuration.\n",
  62269. + val);
  62270. + }
  62271. + val = 0;
  62272. + retval = -DWC_E_INVALID;
  62273. + }
  62274. +
  62275. + core_if->core_params->dma_enable = val;
  62276. + if (val == 0) {
  62277. + dwc_otg_set_param_dma_desc_enable(core_if, 0);
  62278. + }
  62279. + return retval;
  62280. +}
  62281. +
  62282. +int32_t dwc_otg_get_param_dma_enable(dwc_otg_core_if_t * core_if)
  62283. +{
  62284. + return core_if->core_params->dma_enable;
  62285. +}
  62286. +
  62287. +int dwc_otg_set_param_dma_desc_enable(dwc_otg_core_if_t * core_if, int32_t val)
  62288. +{
  62289. + int retval = 0;
  62290. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62291. + DWC_WARN("Wrong value for dma_enable\n");
  62292. + DWC_WARN("dma_desc_enable must be 0 or 1\n");
  62293. + return -DWC_E_INVALID;
  62294. + }
  62295. +
  62296. + if ((val == 1)
  62297. + && ((dwc_otg_get_param_dma_enable(core_if) == 0)
  62298. + || (core_if->hwcfg4.b.desc_dma == 0))) {
  62299. + if (dwc_otg_param_initialized
  62300. + (core_if->core_params->dma_desc_enable)) {
  62301. + DWC_ERROR
  62302. + ("%d invalid for dma_desc_enable paremter. Check HW configuration.\n",
  62303. + val);
  62304. + }
  62305. + val = 0;
  62306. + retval = -DWC_E_INVALID;
  62307. + }
  62308. + core_if->core_params->dma_desc_enable = val;
  62309. + return retval;
  62310. +}
  62311. +
  62312. +int32_t dwc_otg_get_param_dma_desc_enable(dwc_otg_core_if_t * core_if)
  62313. +{
  62314. + return core_if->core_params->dma_desc_enable;
  62315. +}
  62316. +
  62317. +int dwc_otg_set_param_host_support_fs_ls_low_power(dwc_otg_core_if_t * core_if,
  62318. + int32_t val)
  62319. +{
  62320. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62321. + DWC_WARN("Wrong value for host_support_fs_low_power\n");
  62322. + DWC_WARN("host_support_fs_low_power must be 0 or 1\n");
  62323. + return -DWC_E_INVALID;
  62324. + }
  62325. + core_if->core_params->host_support_fs_ls_low_power = val;
  62326. + return 0;
  62327. +}
  62328. +
  62329. +int32_t dwc_otg_get_param_host_support_fs_ls_low_power(dwc_otg_core_if_t *
  62330. + core_if)
  62331. +{
  62332. + return core_if->core_params->host_support_fs_ls_low_power;
  62333. +}
  62334. +
  62335. +int dwc_otg_set_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if,
  62336. + int32_t val)
  62337. +{
  62338. + int retval = 0;
  62339. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62340. + DWC_WARN("Wrong value for enable_dynamic_fifo\n");
  62341. + DWC_WARN("enable_dynamic_fifo must be 0 or 1\n");
  62342. + return -DWC_E_INVALID;
  62343. + }
  62344. +
  62345. + if ((val == 1) && (core_if->hwcfg2.b.dynamic_fifo == 0)) {
  62346. + if (dwc_otg_param_initialized
  62347. + (core_if->core_params->enable_dynamic_fifo)) {
  62348. + DWC_ERROR
  62349. + ("%d invalid for enable_dynamic_fifo paremter. Check HW configuration.\n",
  62350. + val);
  62351. + }
  62352. + val = 0;
  62353. + retval = -DWC_E_INVALID;
  62354. + }
  62355. + core_if->core_params->enable_dynamic_fifo = val;
  62356. + return retval;
  62357. +}
  62358. +
  62359. +int32_t dwc_otg_get_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if)
  62360. +{
  62361. + return core_if->core_params->enable_dynamic_fifo;
  62362. +}
  62363. +
  62364. +int dwc_otg_set_param_data_fifo_size(dwc_otg_core_if_t * core_if, int32_t val)
  62365. +{
  62366. + int retval = 0;
  62367. + if (DWC_OTG_PARAM_TEST(val, 32, 32768)) {
  62368. + DWC_WARN("Wrong value for data_fifo_size\n");
  62369. + DWC_WARN("data_fifo_size must be 32-32768\n");
  62370. + return -DWC_E_INVALID;
  62371. + }
  62372. +
  62373. + if (val > core_if->hwcfg3.b.dfifo_depth) {
  62374. + if (dwc_otg_param_initialized
  62375. + (core_if->core_params->data_fifo_size)) {
  62376. + DWC_ERROR
  62377. + ("%d invalid for data_fifo_size parameter. Check HW configuration.\n",
  62378. + val);
  62379. + }
  62380. + val = core_if->hwcfg3.b.dfifo_depth;
  62381. + retval = -DWC_E_INVALID;
  62382. + }
  62383. +
  62384. + core_if->core_params->data_fifo_size = val;
  62385. + return retval;
  62386. +}
  62387. +
  62388. +int32_t dwc_otg_get_param_data_fifo_size(dwc_otg_core_if_t * core_if)
  62389. +{
  62390. + return core_if->core_params->data_fifo_size;
  62391. +}
  62392. +
  62393. +int dwc_otg_set_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if, int32_t val)
  62394. +{
  62395. + int retval = 0;
  62396. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  62397. + DWC_WARN("Wrong value for dev_rx_fifo_size\n");
  62398. + DWC_WARN("dev_rx_fifo_size must be 16-32768\n");
  62399. + return -DWC_E_INVALID;
  62400. + }
  62401. +
  62402. + if (val > DWC_READ_REG32(&core_if->core_global_regs->grxfsiz)) {
  62403. + if (dwc_otg_param_initialized(core_if->core_params->dev_rx_fifo_size)) {
  62404. + DWC_WARN("%d invalid for dev_rx_fifo_size parameter\n", val);
  62405. + }
  62406. + val = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  62407. + retval = -DWC_E_INVALID;
  62408. + }
  62409. +
  62410. + core_if->core_params->dev_rx_fifo_size = val;
  62411. + return retval;
  62412. +}
  62413. +
  62414. +int32_t dwc_otg_get_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if)
  62415. +{
  62416. + return core_if->core_params->dev_rx_fifo_size;
  62417. +}
  62418. +
  62419. +int dwc_otg_set_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  62420. + int32_t val)
  62421. +{
  62422. + int retval = 0;
  62423. +
  62424. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  62425. + DWC_WARN("Wrong value for dev_nperio_tx_fifo\n");
  62426. + DWC_WARN("dev_nperio_tx_fifo must be 16-32768\n");
  62427. + return -DWC_E_INVALID;
  62428. + }
  62429. +
  62430. + if (val > (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >> 16)) {
  62431. + if (dwc_otg_param_initialized
  62432. + (core_if->core_params->dev_nperio_tx_fifo_size)) {
  62433. + DWC_ERROR
  62434. + ("%d invalid for dev_nperio_tx_fifo_size. Check HW configuration.\n",
  62435. + val);
  62436. + }
  62437. + val =
  62438. + (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >>
  62439. + 16);
  62440. + retval = -DWC_E_INVALID;
  62441. + }
  62442. +
  62443. + core_if->core_params->dev_nperio_tx_fifo_size = val;
  62444. + return retval;
  62445. +}
  62446. +
  62447. +int32_t dwc_otg_get_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  62448. +{
  62449. + return core_if->core_params->dev_nperio_tx_fifo_size;
  62450. +}
  62451. +
  62452. +int dwc_otg_set_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if,
  62453. + int32_t val)
  62454. +{
  62455. + int retval = 0;
  62456. +
  62457. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  62458. + DWC_WARN("Wrong value for host_rx_fifo_size\n");
  62459. + DWC_WARN("host_rx_fifo_size must be 16-32768\n");
  62460. + return -DWC_E_INVALID;
  62461. + }
  62462. +
  62463. + if (val > DWC_READ_REG32(&core_if->core_global_regs->grxfsiz)) {
  62464. + if (dwc_otg_param_initialized
  62465. + (core_if->core_params->host_rx_fifo_size)) {
  62466. + DWC_ERROR
  62467. + ("%d invalid for host_rx_fifo_size. Check HW configuration.\n",
  62468. + val);
  62469. + }
  62470. + val = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  62471. + retval = -DWC_E_INVALID;
  62472. + }
  62473. +
  62474. + core_if->core_params->host_rx_fifo_size = val;
  62475. + return retval;
  62476. +
  62477. +}
  62478. +
  62479. +int32_t dwc_otg_get_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if)
  62480. +{
  62481. + return core_if->core_params->host_rx_fifo_size;
  62482. +}
  62483. +
  62484. +int dwc_otg_set_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  62485. + int32_t val)
  62486. +{
  62487. + int retval = 0;
  62488. +
  62489. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  62490. + DWC_WARN("Wrong value for host_nperio_tx_fifo_size\n");
  62491. + DWC_WARN("host_nperio_tx_fifo_size must be 16-32768\n");
  62492. + return -DWC_E_INVALID;
  62493. + }
  62494. +
  62495. + if (val > (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >> 16)) {
  62496. + if (dwc_otg_param_initialized
  62497. + (core_if->core_params->host_nperio_tx_fifo_size)) {
  62498. + DWC_ERROR
  62499. + ("%d invalid for host_nperio_tx_fifo_size. Check HW configuration.\n",
  62500. + val);
  62501. + }
  62502. + val =
  62503. + (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >>
  62504. + 16);
  62505. + retval = -DWC_E_INVALID;
  62506. + }
  62507. +
  62508. + core_if->core_params->host_nperio_tx_fifo_size = val;
  62509. + return retval;
  62510. +}
  62511. +
  62512. +int32_t dwc_otg_get_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  62513. +{
  62514. + return core_if->core_params->host_nperio_tx_fifo_size;
  62515. +}
  62516. +
  62517. +int dwc_otg_set_param_host_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  62518. + int32_t val)
  62519. +{
  62520. + int retval = 0;
  62521. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  62522. + DWC_WARN("Wrong value for host_perio_tx_fifo_size\n");
  62523. + DWC_WARN("host_perio_tx_fifo_size must be 16-32768\n");
  62524. + return -DWC_E_INVALID;
  62525. + }
  62526. +
  62527. + if (val > ((core_if->hptxfsiz.d32) >> 16)) {
  62528. + if (dwc_otg_param_initialized
  62529. + (core_if->core_params->host_perio_tx_fifo_size)) {
  62530. + DWC_ERROR
  62531. + ("%d invalid for host_perio_tx_fifo_size. Check HW configuration.\n",
  62532. + val);
  62533. + }
  62534. + val = (core_if->hptxfsiz.d32) >> 16;
  62535. + retval = -DWC_E_INVALID;
  62536. + }
  62537. +
  62538. + core_if->core_params->host_perio_tx_fifo_size = val;
  62539. + return retval;
  62540. +}
  62541. +
  62542. +int32_t dwc_otg_get_param_host_perio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  62543. +{
  62544. + return core_if->core_params->host_perio_tx_fifo_size;
  62545. +}
  62546. +
  62547. +int dwc_otg_set_param_max_transfer_size(dwc_otg_core_if_t * core_if,
  62548. + int32_t val)
  62549. +{
  62550. + int retval = 0;
  62551. +
  62552. + if (DWC_OTG_PARAM_TEST(val, 2047, 524288)) {
  62553. + DWC_WARN("Wrong value for max_transfer_size\n");
  62554. + DWC_WARN("max_transfer_size must be 2047-524288\n");
  62555. + return -DWC_E_INVALID;
  62556. + }
  62557. +
  62558. + if (val >= (1 << (core_if->hwcfg3.b.xfer_size_cntr_width + 11))) {
  62559. + if (dwc_otg_param_initialized
  62560. + (core_if->core_params->max_transfer_size)) {
  62561. + DWC_ERROR
  62562. + ("%d invalid for max_transfer_size. Check HW configuration.\n",
  62563. + val);
  62564. + }
  62565. + val =
  62566. + ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 11)) -
  62567. + 1);
  62568. + retval = -DWC_E_INVALID;
  62569. + }
  62570. +
  62571. + core_if->core_params->max_transfer_size = val;
  62572. + return retval;
  62573. +}
  62574. +
  62575. +int32_t dwc_otg_get_param_max_transfer_size(dwc_otg_core_if_t * core_if)
  62576. +{
  62577. + return core_if->core_params->max_transfer_size;
  62578. +}
  62579. +
  62580. +int dwc_otg_set_param_max_packet_count(dwc_otg_core_if_t * core_if, int32_t val)
  62581. +{
  62582. + int retval = 0;
  62583. +
  62584. + if (DWC_OTG_PARAM_TEST(val, 15, 511)) {
  62585. + DWC_WARN("Wrong value for max_packet_count\n");
  62586. + DWC_WARN("max_packet_count must be 15-511\n");
  62587. + return -DWC_E_INVALID;
  62588. + }
  62589. +
  62590. + if (val > (1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4))) {
  62591. + if (dwc_otg_param_initialized
  62592. + (core_if->core_params->max_packet_count)) {
  62593. + DWC_ERROR
  62594. + ("%d invalid for max_packet_count. Check HW configuration.\n",
  62595. + val);
  62596. + }
  62597. + val =
  62598. + ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4)) - 1);
  62599. + retval = -DWC_E_INVALID;
  62600. + }
  62601. +
  62602. + core_if->core_params->max_packet_count = val;
  62603. + return retval;
  62604. +}
  62605. +
  62606. +int32_t dwc_otg_get_param_max_packet_count(dwc_otg_core_if_t * core_if)
  62607. +{
  62608. + return core_if->core_params->max_packet_count;
  62609. +}
  62610. +
  62611. +int dwc_otg_set_param_host_channels(dwc_otg_core_if_t * core_if, int32_t val)
  62612. +{
  62613. + int retval = 0;
  62614. +
  62615. + if (DWC_OTG_PARAM_TEST(val, 1, 16)) {
  62616. + DWC_WARN("Wrong value for host_channels\n");
  62617. + DWC_WARN("host_channels must be 1-16\n");
  62618. + return -DWC_E_INVALID;
  62619. + }
  62620. +
  62621. + if (val > (core_if->hwcfg2.b.num_host_chan + 1)) {
  62622. + if (dwc_otg_param_initialized
  62623. + (core_if->core_params->host_channels)) {
  62624. + DWC_ERROR
  62625. + ("%d invalid for host_channels. Check HW configurations.\n",
  62626. + val);
  62627. + }
  62628. + val = (core_if->hwcfg2.b.num_host_chan + 1);
  62629. + retval = -DWC_E_INVALID;
  62630. + }
  62631. +
  62632. + core_if->core_params->host_channels = val;
  62633. + return retval;
  62634. +}
  62635. +
  62636. +int32_t dwc_otg_get_param_host_channels(dwc_otg_core_if_t * core_if)
  62637. +{
  62638. + return core_if->core_params->host_channels;
  62639. +}
  62640. +
  62641. +int dwc_otg_set_param_dev_endpoints(dwc_otg_core_if_t * core_if, int32_t val)
  62642. +{
  62643. + int retval = 0;
  62644. +
  62645. + if (DWC_OTG_PARAM_TEST(val, 1, 15)) {
  62646. + DWC_WARN("Wrong value for dev_endpoints\n");
  62647. + DWC_WARN("dev_endpoints must be 1-15\n");
  62648. + return -DWC_E_INVALID;
  62649. + }
  62650. +
  62651. + if (val > (core_if->hwcfg2.b.num_dev_ep)) {
  62652. + if (dwc_otg_param_initialized
  62653. + (core_if->core_params->dev_endpoints)) {
  62654. + DWC_ERROR
  62655. + ("%d invalid for dev_endpoints. Check HW configurations.\n",
  62656. + val);
  62657. + }
  62658. + val = core_if->hwcfg2.b.num_dev_ep;
  62659. + retval = -DWC_E_INVALID;
  62660. + }
  62661. +
  62662. + core_if->core_params->dev_endpoints = val;
  62663. + return retval;
  62664. +}
  62665. +
  62666. +int32_t dwc_otg_get_param_dev_endpoints(dwc_otg_core_if_t * core_if)
  62667. +{
  62668. + return core_if->core_params->dev_endpoints;
  62669. +}
  62670. +
  62671. +int dwc_otg_set_param_phy_type(dwc_otg_core_if_t * core_if, int32_t val)
  62672. +{
  62673. + int retval = 0;
  62674. + int valid = 0;
  62675. +
  62676. + if (DWC_OTG_PARAM_TEST(val, 0, 2)) {
  62677. + DWC_WARN("Wrong value for phy_type\n");
  62678. + DWC_WARN("phy_type must be 0,1 or 2\n");
  62679. + return -DWC_E_INVALID;
  62680. + }
  62681. +#ifndef NO_FS_PHY_HW_CHECKS
  62682. + if ((val == DWC_PHY_TYPE_PARAM_UTMI) &&
  62683. + ((core_if->hwcfg2.b.hs_phy_type == 1) ||
  62684. + (core_if->hwcfg2.b.hs_phy_type == 3))) {
  62685. + valid = 1;
  62686. + } else if ((val == DWC_PHY_TYPE_PARAM_ULPI) &&
  62687. + ((core_if->hwcfg2.b.hs_phy_type == 2) ||
  62688. + (core_if->hwcfg2.b.hs_phy_type == 3))) {
  62689. + valid = 1;
  62690. + } else if ((val == DWC_PHY_TYPE_PARAM_FS) &&
  62691. + (core_if->hwcfg2.b.fs_phy_type == 1)) {
  62692. + valid = 1;
  62693. + }
  62694. + if (!valid) {
  62695. + if (dwc_otg_param_initialized(core_if->core_params->phy_type)) {
  62696. + DWC_ERROR
  62697. + ("%d invalid for phy_type. Check HW configurations.\n",
  62698. + val);
  62699. + }
  62700. + if (core_if->hwcfg2.b.hs_phy_type) {
  62701. + if ((core_if->hwcfg2.b.hs_phy_type == 3) ||
  62702. + (core_if->hwcfg2.b.hs_phy_type == 1)) {
  62703. + val = DWC_PHY_TYPE_PARAM_UTMI;
  62704. + } else {
  62705. + val = DWC_PHY_TYPE_PARAM_ULPI;
  62706. + }
  62707. + }
  62708. + retval = -DWC_E_INVALID;
  62709. + }
  62710. +#endif
  62711. + core_if->core_params->phy_type = val;
  62712. + return retval;
  62713. +}
  62714. +
  62715. +int32_t dwc_otg_get_param_phy_type(dwc_otg_core_if_t * core_if)
  62716. +{
  62717. + return core_if->core_params->phy_type;
  62718. +}
  62719. +
  62720. +int dwc_otg_set_param_speed(dwc_otg_core_if_t * core_if, int32_t val)
  62721. +{
  62722. + int retval = 0;
  62723. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62724. + DWC_WARN("Wrong value for speed parameter\n");
  62725. + DWC_WARN("max_speed parameter must be 0 or 1\n");
  62726. + return -DWC_E_INVALID;
  62727. + }
  62728. + if ((val == 0)
  62729. + && dwc_otg_get_param_phy_type(core_if) == DWC_PHY_TYPE_PARAM_FS) {
  62730. + if (dwc_otg_param_initialized(core_if->core_params->speed)) {
  62731. + DWC_ERROR
  62732. + ("%d invalid for speed paremter. Check HW configuration.\n",
  62733. + val);
  62734. + }
  62735. + val =
  62736. + (dwc_otg_get_param_phy_type(core_if) ==
  62737. + DWC_PHY_TYPE_PARAM_FS ? 1 : 0);
  62738. + retval = -DWC_E_INVALID;
  62739. + }
  62740. + core_if->core_params->speed = val;
  62741. + return retval;
  62742. +}
  62743. +
  62744. +int32_t dwc_otg_get_param_speed(dwc_otg_core_if_t * core_if)
  62745. +{
  62746. + return core_if->core_params->speed;
  62747. +}
  62748. +
  62749. +int dwc_otg_set_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t * core_if,
  62750. + int32_t val)
  62751. +{
  62752. + int retval = 0;
  62753. +
  62754. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62755. + DWC_WARN
  62756. + ("Wrong value for host_ls_low_power_phy_clk parameter\n");
  62757. + DWC_WARN("host_ls_low_power_phy_clk must be 0 or 1\n");
  62758. + return -DWC_E_INVALID;
  62759. + }
  62760. +
  62761. + if ((val == DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ)
  62762. + && (dwc_otg_get_param_phy_type(core_if) == DWC_PHY_TYPE_PARAM_FS)) {
  62763. + if (dwc_otg_param_initialized
  62764. + (core_if->core_params->host_ls_low_power_phy_clk)) {
  62765. + DWC_ERROR
  62766. + ("%d invalid for host_ls_low_power_phy_clk. Check HW configuration.\n",
  62767. + val);
  62768. + }
  62769. + val =
  62770. + (dwc_otg_get_param_phy_type(core_if) ==
  62771. + DWC_PHY_TYPE_PARAM_FS) ?
  62772. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ :
  62773. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ;
  62774. + retval = -DWC_E_INVALID;
  62775. + }
  62776. +
  62777. + core_if->core_params->host_ls_low_power_phy_clk = val;
  62778. + return retval;
  62779. +}
  62780. +
  62781. +int32_t dwc_otg_get_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t * core_if)
  62782. +{
  62783. + return core_if->core_params->host_ls_low_power_phy_clk;
  62784. +}
  62785. +
  62786. +int dwc_otg_set_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if, int32_t val)
  62787. +{
  62788. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62789. + DWC_WARN("Wrong value for phy_ulpi_ddr\n");
  62790. + DWC_WARN("phy_upli_ddr must be 0 or 1\n");
  62791. + return -DWC_E_INVALID;
  62792. + }
  62793. +
  62794. + core_if->core_params->phy_ulpi_ddr = val;
  62795. + return 0;
  62796. +}
  62797. +
  62798. +int32_t dwc_otg_get_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if)
  62799. +{
  62800. + return core_if->core_params->phy_ulpi_ddr;
  62801. +}
  62802. +
  62803. +int dwc_otg_set_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if,
  62804. + int32_t val)
  62805. +{
  62806. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62807. + DWC_WARN("Wrong valaue for phy_ulpi_ext_vbus\n");
  62808. + DWC_WARN("phy_ulpi_ext_vbus must be 0 or 1\n");
  62809. + return -DWC_E_INVALID;
  62810. + }
  62811. +
  62812. + core_if->core_params->phy_ulpi_ext_vbus = val;
  62813. + return 0;
  62814. +}
  62815. +
  62816. +int32_t dwc_otg_get_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if)
  62817. +{
  62818. + return core_if->core_params->phy_ulpi_ext_vbus;
  62819. +}
  62820. +
  62821. +int dwc_otg_set_param_phy_utmi_width(dwc_otg_core_if_t * core_if, int32_t val)
  62822. +{
  62823. + if (DWC_OTG_PARAM_TEST(val, 8, 8) && DWC_OTG_PARAM_TEST(val, 16, 16)) {
  62824. + DWC_WARN("Wrong valaue for phy_utmi_width\n");
  62825. + DWC_WARN("phy_utmi_width must be 8 or 16\n");
  62826. + return -DWC_E_INVALID;
  62827. + }
  62828. +
  62829. + core_if->core_params->phy_utmi_width = val;
  62830. + return 0;
  62831. +}
  62832. +
  62833. +int32_t dwc_otg_get_param_phy_utmi_width(dwc_otg_core_if_t * core_if)
  62834. +{
  62835. + return core_if->core_params->phy_utmi_width;
  62836. +}
  62837. +
  62838. +int dwc_otg_set_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if, int32_t val)
  62839. +{
  62840. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62841. + DWC_WARN("Wrong valaue for ulpi_fs_ls\n");
  62842. + DWC_WARN("ulpi_fs_ls must be 0 or 1\n");
  62843. + return -DWC_E_INVALID;
  62844. + }
  62845. +
  62846. + core_if->core_params->ulpi_fs_ls = val;
  62847. + return 0;
  62848. +}
  62849. +
  62850. +int32_t dwc_otg_get_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if)
  62851. +{
  62852. + return core_if->core_params->ulpi_fs_ls;
  62853. +}
  62854. +
  62855. +int dwc_otg_set_param_ts_dline(dwc_otg_core_if_t * core_if, int32_t val)
  62856. +{
  62857. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62858. + DWC_WARN("Wrong valaue for ts_dline\n");
  62859. + DWC_WARN("ts_dline must be 0 or 1\n");
  62860. + return -DWC_E_INVALID;
  62861. + }
  62862. +
  62863. + core_if->core_params->ts_dline = val;
  62864. + return 0;
  62865. +}
  62866. +
  62867. +int32_t dwc_otg_get_param_ts_dline(dwc_otg_core_if_t * core_if)
  62868. +{
  62869. + return core_if->core_params->ts_dline;
  62870. +}
  62871. +
  62872. +int dwc_otg_set_param_i2c_enable(dwc_otg_core_if_t * core_if, int32_t val)
  62873. +{
  62874. + int retval = 0;
  62875. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62876. + DWC_WARN("Wrong valaue for i2c_enable\n");
  62877. + DWC_WARN("i2c_enable must be 0 or 1\n");
  62878. + return -DWC_E_INVALID;
  62879. + }
  62880. +#ifndef NO_FS_PHY_HW_CHECK
  62881. + if (val == 1 && core_if->hwcfg3.b.i2c == 0) {
  62882. + if (dwc_otg_param_initialized(core_if->core_params->i2c_enable)) {
  62883. + DWC_ERROR
  62884. + ("%d invalid for i2c_enable. Check HW configuration.\n",
  62885. + val);
  62886. + }
  62887. + val = 0;
  62888. + retval = -DWC_E_INVALID;
  62889. + }
  62890. +#endif
  62891. +
  62892. + core_if->core_params->i2c_enable = val;
  62893. + return retval;
  62894. +}
  62895. +
  62896. +int32_t dwc_otg_get_param_i2c_enable(dwc_otg_core_if_t * core_if)
  62897. +{
  62898. + return core_if->core_params->i2c_enable;
  62899. +}
  62900. +
  62901. +int dwc_otg_set_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  62902. + int32_t val, int fifo_num)
  62903. +{
  62904. + int retval = 0;
  62905. +
  62906. + if (DWC_OTG_PARAM_TEST(val, 4, 768)) {
  62907. + DWC_WARN("Wrong value for dev_perio_tx_fifo_size\n");
  62908. + DWC_WARN("dev_perio_tx_fifo_size must be 4-768\n");
  62909. + return -DWC_E_INVALID;
  62910. + }
  62911. +
  62912. + if (val >
  62913. + (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]))) {
  62914. + if (dwc_otg_param_initialized
  62915. + (core_if->core_params->dev_perio_tx_fifo_size[fifo_num])) {
  62916. + DWC_ERROR
  62917. + ("`%d' invalid for parameter `dev_perio_fifo_size_%d'. Check HW configuration.\n",
  62918. + val, fifo_num);
  62919. + }
  62920. + val = (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]));
  62921. + retval = -DWC_E_INVALID;
  62922. + }
  62923. +
  62924. + core_if->core_params->dev_perio_tx_fifo_size[fifo_num] = val;
  62925. + return retval;
  62926. +}
  62927. +
  62928. +int32_t dwc_otg_get_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  62929. + int fifo_num)
  62930. +{
  62931. + return core_if->core_params->dev_perio_tx_fifo_size[fifo_num];
  62932. +}
  62933. +
  62934. +int dwc_otg_set_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if,
  62935. + int32_t val)
  62936. +{
  62937. + int retval = 0;
  62938. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62939. + DWC_WARN("Wrong valaue for en_multiple_tx_fifo,\n");
  62940. + DWC_WARN("en_multiple_tx_fifo must be 0 or 1\n");
  62941. + return -DWC_E_INVALID;
  62942. + }
  62943. +
  62944. + if (val == 1 && core_if->hwcfg4.b.ded_fifo_en == 0) {
  62945. + if (dwc_otg_param_initialized
  62946. + (core_if->core_params->en_multiple_tx_fifo)) {
  62947. + DWC_ERROR
  62948. + ("%d invalid for parameter en_multiple_tx_fifo. Check HW configuration.\n",
  62949. + val);
  62950. + }
  62951. + val = 0;
  62952. + retval = -DWC_E_INVALID;
  62953. + }
  62954. +
  62955. + core_if->core_params->en_multiple_tx_fifo = val;
  62956. + return retval;
  62957. +}
  62958. +
  62959. +int32_t dwc_otg_get_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if)
  62960. +{
  62961. + return core_if->core_params->en_multiple_tx_fifo;
  62962. +}
  62963. +
  62964. +int dwc_otg_set_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if, int32_t val,
  62965. + int fifo_num)
  62966. +{
  62967. + int retval = 0;
  62968. +
  62969. + if (DWC_OTG_PARAM_TEST(val, 4, 768)) {
  62970. + DWC_WARN("Wrong value for dev_tx_fifo_size\n");
  62971. + DWC_WARN("dev_tx_fifo_size must be 4-768\n");
  62972. + return -DWC_E_INVALID;
  62973. + }
  62974. +
  62975. + if (val >
  62976. + (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]))) {
  62977. + if (dwc_otg_param_initialized
  62978. + (core_if->core_params->dev_tx_fifo_size[fifo_num])) {
  62979. + DWC_ERROR
  62980. + ("`%d' invalid for parameter `dev_tx_fifo_size_%d'. Check HW configuration.\n",
  62981. + val, fifo_num);
  62982. + }
  62983. + val = (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]));
  62984. + retval = -DWC_E_INVALID;
  62985. + }
  62986. +
  62987. + core_if->core_params->dev_tx_fifo_size[fifo_num] = val;
  62988. + return retval;
  62989. +}
  62990. +
  62991. +int32_t dwc_otg_get_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  62992. + int fifo_num)
  62993. +{
  62994. + return core_if->core_params->dev_tx_fifo_size[fifo_num];
  62995. +}
  62996. +
  62997. +int dwc_otg_set_param_thr_ctl(dwc_otg_core_if_t * core_if, int32_t val)
  62998. +{
  62999. + int retval = 0;
  63000. +
  63001. + if (DWC_OTG_PARAM_TEST(val, 0, 7)) {
  63002. + DWC_WARN("Wrong value for thr_ctl\n");
  63003. + DWC_WARN("thr_ctl must be 0-7\n");
  63004. + return -DWC_E_INVALID;
  63005. + }
  63006. +
  63007. + if ((val != 0) &&
  63008. + (!dwc_otg_get_param_dma_enable(core_if) ||
  63009. + !core_if->hwcfg4.b.ded_fifo_en)) {
  63010. + if (dwc_otg_param_initialized(core_if->core_params->thr_ctl)) {
  63011. + DWC_ERROR
  63012. + ("%d invalid for parameter thr_ctl. Check HW configuration.\n",
  63013. + val);
  63014. + }
  63015. + val = 0;
  63016. + retval = -DWC_E_INVALID;
  63017. + }
  63018. +
  63019. + core_if->core_params->thr_ctl = val;
  63020. + return retval;
  63021. +}
  63022. +
  63023. +int32_t dwc_otg_get_param_thr_ctl(dwc_otg_core_if_t * core_if)
  63024. +{
  63025. + return core_if->core_params->thr_ctl;
  63026. +}
  63027. +
  63028. +int dwc_otg_set_param_lpm_enable(dwc_otg_core_if_t * core_if, int32_t val)
  63029. +{
  63030. + int retval = 0;
  63031. +
  63032. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  63033. + DWC_WARN("Wrong value for lpm_enable\n");
  63034. + DWC_WARN("lpm_enable must be 0 or 1\n");
  63035. + return -DWC_E_INVALID;
  63036. + }
  63037. +
  63038. + if (val && !core_if->hwcfg3.b.otg_lpm_en) {
  63039. + if (dwc_otg_param_initialized(core_if->core_params->lpm_enable)) {
  63040. + DWC_ERROR
  63041. + ("%d invalid for parameter lpm_enable. Check HW configuration.\n",
  63042. + val);
  63043. + }
  63044. + val = 0;
  63045. + retval = -DWC_E_INVALID;
  63046. + }
  63047. +
  63048. + core_if->core_params->lpm_enable = val;
  63049. + return retval;
  63050. +}
  63051. +
  63052. +int32_t dwc_otg_get_param_lpm_enable(dwc_otg_core_if_t * core_if)
  63053. +{
  63054. + return core_if->core_params->lpm_enable;
  63055. +}
  63056. +
  63057. +int dwc_otg_set_param_tx_thr_length(dwc_otg_core_if_t * core_if, int32_t val)
  63058. +{
  63059. + if (DWC_OTG_PARAM_TEST(val, 8, 128)) {
  63060. + DWC_WARN("Wrong valaue for tx_thr_length\n");
  63061. + DWC_WARN("tx_thr_length must be 8 - 128\n");
  63062. + return -DWC_E_INVALID;
  63063. + }
  63064. +
  63065. + core_if->core_params->tx_thr_length = val;
  63066. + return 0;
  63067. +}
  63068. +
  63069. +int32_t dwc_otg_get_param_tx_thr_length(dwc_otg_core_if_t * core_if)
  63070. +{
  63071. + return core_if->core_params->tx_thr_length;
  63072. +}
  63073. +
  63074. +int dwc_otg_set_param_rx_thr_length(dwc_otg_core_if_t * core_if, int32_t val)
  63075. +{
  63076. + if (DWC_OTG_PARAM_TEST(val, 8, 128)) {
  63077. + DWC_WARN("Wrong valaue for rx_thr_length\n");
  63078. + DWC_WARN("rx_thr_length must be 8 - 128\n");
  63079. + return -DWC_E_INVALID;
  63080. + }
  63081. +
  63082. + core_if->core_params->rx_thr_length = val;
  63083. + return 0;
  63084. +}
  63085. +
  63086. +int32_t dwc_otg_get_param_rx_thr_length(dwc_otg_core_if_t * core_if)
  63087. +{
  63088. + return core_if->core_params->rx_thr_length;
  63089. +}
  63090. +
  63091. +int dwc_otg_set_param_dma_burst_size(dwc_otg_core_if_t * core_if, int32_t val)
  63092. +{
  63093. + if (DWC_OTG_PARAM_TEST(val, 1, 1) &&
  63094. + DWC_OTG_PARAM_TEST(val, 4, 4) &&
  63095. + DWC_OTG_PARAM_TEST(val, 8, 8) &&
  63096. + DWC_OTG_PARAM_TEST(val, 16, 16) &&
  63097. + DWC_OTG_PARAM_TEST(val, 32, 32) &&
  63098. + DWC_OTG_PARAM_TEST(val, 64, 64) &&
  63099. + DWC_OTG_PARAM_TEST(val, 128, 128) &&
  63100. + DWC_OTG_PARAM_TEST(val, 256, 256)) {
  63101. + DWC_WARN("`%d' invalid for parameter `dma_burst_size'\n", val);
  63102. + return -DWC_E_INVALID;
  63103. + }
  63104. + core_if->core_params->dma_burst_size = val;
  63105. + return 0;
  63106. +}
  63107. +
  63108. +int32_t dwc_otg_get_param_dma_burst_size(dwc_otg_core_if_t * core_if)
  63109. +{
  63110. + return core_if->core_params->dma_burst_size;
  63111. +}
  63112. +
  63113. +int dwc_otg_set_param_pti_enable(dwc_otg_core_if_t * core_if, int32_t val)
  63114. +{
  63115. + int retval = 0;
  63116. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  63117. + DWC_WARN("`%d' invalid for parameter `pti_enable'\n", val);
  63118. + return -DWC_E_INVALID;
  63119. + }
  63120. + if (val && (core_if->snpsid < OTG_CORE_REV_2_72a)) {
  63121. + if (dwc_otg_param_initialized(core_if->core_params->pti_enable)) {
  63122. + DWC_ERROR
  63123. + ("%d invalid for parameter pti_enable. Check HW configuration.\n",
  63124. + val);
  63125. + }
  63126. + retval = -DWC_E_INVALID;
  63127. + val = 0;
  63128. + }
  63129. + core_if->core_params->pti_enable = val;
  63130. + return retval;
  63131. +}
  63132. +
  63133. +int32_t dwc_otg_get_param_pti_enable(dwc_otg_core_if_t * core_if)
  63134. +{
  63135. + return core_if->core_params->pti_enable;
  63136. +}
  63137. +
  63138. +int dwc_otg_set_param_mpi_enable(dwc_otg_core_if_t * core_if, int32_t val)
  63139. +{
  63140. + int retval = 0;
  63141. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  63142. + DWC_WARN("`%d' invalid for parameter `mpi_enable'\n", val);
  63143. + return -DWC_E_INVALID;
  63144. + }
  63145. + if (val && (core_if->hwcfg2.b.multi_proc_int == 0)) {
  63146. + if (dwc_otg_param_initialized(core_if->core_params->mpi_enable)) {
  63147. + DWC_ERROR
  63148. + ("%d invalid for parameter mpi_enable. Check HW configuration.\n",
  63149. + val);
  63150. + }
  63151. + retval = -DWC_E_INVALID;
  63152. + val = 0;
  63153. + }
  63154. + core_if->core_params->mpi_enable = val;
  63155. + return retval;
  63156. +}
  63157. +
  63158. +int32_t dwc_otg_get_param_mpi_enable(dwc_otg_core_if_t * core_if)
  63159. +{
  63160. + return core_if->core_params->mpi_enable;
  63161. +}
  63162. +
  63163. +int dwc_otg_set_param_adp_enable(dwc_otg_core_if_t * core_if, int32_t val)
  63164. +{
  63165. + int retval = 0;
  63166. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  63167. + DWC_WARN("`%d' invalid for parameter `adp_enable'\n", val);
  63168. + return -DWC_E_INVALID;
  63169. + }
  63170. + if (val && (core_if->hwcfg3.b.adp_supp == 0)) {
  63171. + if (dwc_otg_param_initialized
  63172. + (core_if->core_params->adp_supp_enable)) {
  63173. + DWC_ERROR
  63174. + ("%d invalid for parameter adp_enable. Check HW configuration.\n",
  63175. + val);
  63176. + }
  63177. + retval = -DWC_E_INVALID;
  63178. + val = 0;
  63179. + }
  63180. + core_if->core_params->adp_supp_enable = val;
  63181. + /*Set OTG version 2.0 in case of enabling ADP*/
  63182. + if (val)
  63183. + dwc_otg_set_param_otg_ver(core_if, 1);
  63184. +
  63185. + return retval;
  63186. +}
  63187. +
  63188. +int32_t dwc_otg_get_param_adp_enable(dwc_otg_core_if_t * core_if)
  63189. +{
  63190. + return core_if->core_params->adp_supp_enable;
  63191. +}
  63192. +
  63193. +int dwc_otg_set_param_ic_usb_cap(dwc_otg_core_if_t * core_if, int32_t val)
  63194. +{
  63195. + int retval = 0;
  63196. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  63197. + DWC_WARN("`%d' invalid for parameter `ic_usb_cap'\n", val);
  63198. + DWC_WARN("ic_usb_cap must be 0 or 1\n");
  63199. + return -DWC_E_INVALID;
  63200. + }
  63201. +
  63202. + if (val && (core_if->hwcfg2.b.otg_enable_ic_usb == 0)) {
  63203. + if (dwc_otg_param_initialized(core_if->core_params->ic_usb_cap)) {
  63204. + DWC_ERROR
  63205. + ("%d invalid for parameter ic_usb_cap. Check HW configuration.\n",
  63206. + val);
  63207. + }
  63208. + retval = -DWC_E_INVALID;
  63209. + val = 0;
  63210. + }
  63211. + core_if->core_params->ic_usb_cap = val;
  63212. + return retval;
  63213. +}
  63214. +
  63215. +int32_t dwc_otg_get_param_ic_usb_cap(dwc_otg_core_if_t * core_if)
  63216. +{
  63217. + return core_if->core_params->ic_usb_cap;
  63218. +}
  63219. +
  63220. +int dwc_otg_set_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if, int32_t val)
  63221. +{
  63222. + int retval = 0;
  63223. + int valid = 1;
  63224. +
  63225. + if (DWC_OTG_PARAM_TEST(val, 0, 3)) {
  63226. + DWC_WARN("`%d' invalid for parameter `ahb_thr_ratio'\n", val);
  63227. + DWC_WARN("ahb_thr_ratio must be 0 - 3\n");
  63228. + return -DWC_E_INVALID;
  63229. + }
  63230. +
  63231. + if (val
  63232. + && (core_if->snpsid < OTG_CORE_REV_2_81a
  63233. + || !dwc_otg_get_param_thr_ctl(core_if))) {
  63234. + valid = 0;
  63235. + } else if (val
  63236. + && ((dwc_otg_get_param_tx_thr_length(core_if) / (1 << val)) <
  63237. + 4)) {
  63238. + valid = 0;
  63239. + }
  63240. + if (valid == 0) {
  63241. + if (dwc_otg_param_initialized
  63242. + (core_if->core_params->ahb_thr_ratio)) {
  63243. + DWC_ERROR
  63244. + ("%d invalid for parameter ahb_thr_ratio. Check HW configuration.\n",
  63245. + val);
  63246. + }
  63247. + retval = -DWC_E_INVALID;
  63248. + val = 0;
  63249. + }
  63250. +
  63251. + core_if->core_params->ahb_thr_ratio = val;
  63252. + return retval;
  63253. +}
  63254. +
  63255. +int32_t dwc_otg_get_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if)
  63256. +{
  63257. + return core_if->core_params->ahb_thr_ratio;
  63258. +}
  63259. +
  63260. +int dwc_otg_set_param_power_down(dwc_otg_core_if_t * core_if, int32_t val)
  63261. +{
  63262. + int retval = 0;
  63263. + int valid = 1;
  63264. + hwcfg4_data_t hwcfg4 = {.d32 = 0 };
  63265. + hwcfg4.d32 = DWC_READ_REG32(&core_if->core_global_regs->ghwcfg4);
  63266. +
  63267. + if (DWC_OTG_PARAM_TEST(val, 0, 3)) {
  63268. + DWC_WARN("`%d' invalid for parameter `power_down'\n", val);
  63269. + DWC_WARN("power_down must be 0 - 2\n");
  63270. + return -DWC_E_INVALID;
  63271. + }
  63272. +
  63273. + if ((val == 2) && (core_if->snpsid < OTG_CORE_REV_2_91a)) {
  63274. + valid = 0;
  63275. + }
  63276. + if ((val == 3)
  63277. + && ((core_if->snpsid < OTG_CORE_REV_3_00a)
  63278. + || (hwcfg4.b.xhiber == 0))) {
  63279. + valid = 0;
  63280. + }
  63281. + if (valid == 0) {
  63282. + if (dwc_otg_param_initialized(core_if->core_params->power_down)) {
  63283. + DWC_ERROR
  63284. + ("%d invalid for parameter power_down. Check HW configuration.\n",
  63285. + val);
  63286. + }
  63287. + retval = -DWC_E_INVALID;
  63288. + val = 0;
  63289. + }
  63290. + core_if->core_params->power_down = val;
  63291. + return retval;
  63292. +}
  63293. +
  63294. +int32_t dwc_otg_get_param_power_down(dwc_otg_core_if_t * core_if)
  63295. +{
  63296. + return core_if->core_params->power_down;
  63297. +}
  63298. +
  63299. +int dwc_otg_set_param_reload_ctl(dwc_otg_core_if_t * core_if, int32_t val)
  63300. +{
  63301. + int retval = 0;
  63302. + int valid = 1;
  63303. +
  63304. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  63305. + DWC_WARN("`%d' invalid for parameter `reload_ctl'\n", val);
  63306. + DWC_WARN("reload_ctl must be 0 or 1\n");
  63307. + return -DWC_E_INVALID;
  63308. + }
  63309. +
  63310. + if ((val == 1) && (core_if->snpsid < OTG_CORE_REV_2_92a)) {
  63311. + valid = 0;
  63312. + }
  63313. + if (valid == 0) {
  63314. + if (dwc_otg_param_initialized(core_if->core_params->reload_ctl)) {
  63315. + DWC_ERROR("%d invalid for parameter reload_ctl."
  63316. + "Check HW configuration.\n", val);
  63317. + }
  63318. + retval = -DWC_E_INVALID;
  63319. + val = 0;
  63320. + }
  63321. + core_if->core_params->reload_ctl = val;
  63322. + return retval;
  63323. +}
  63324. +
  63325. +int32_t dwc_otg_get_param_reload_ctl(dwc_otg_core_if_t * core_if)
  63326. +{
  63327. + return core_if->core_params->reload_ctl;
  63328. +}
  63329. +
  63330. +int dwc_otg_set_param_dev_out_nak(dwc_otg_core_if_t * core_if, int32_t val)
  63331. +{
  63332. + int retval = 0;
  63333. + int valid = 1;
  63334. +
  63335. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  63336. + DWC_WARN("`%d' invalid for parameter `dev_out_nak'\n", val);
  63337. + DWC_WARN("dev_out_nak must be 0 or 1\n");
  63338. + return -DWC_E_INVALID;
  63339. + }
  63340. +
  63341. + if ((val == 1) && ((core_if->snpsid < OTG_CORE_REV_2_93a) ||
  63342. + !(core_if->core_params->dma_desc_enable))) {
  63343. + valid = 0;
  63344. + }
  63345. + if (valid == 0) {
  63346. + if (dwc_otg_param_initialized(core_if->core_params->dev_out_nak)) {
  63347. + DWC_ERROR("%d invalid for parameter dev_out_nak."
  63348. + "Check HW configuration.\n", val);
  63349. + }
  63350. + retval = -DWC_E_INVALID;
  63351. + val = 0;
  63352. + }
  63353. + core_if->core_params->dev_out_nak = val;
  63354. + return retval;
  63355. +}
  63356. +
  63357. +int32_t dwc_otg_get_param_dev_out_nak(dwc_otg_core_if_t * core_if)
  63358. +{
  63359. + return core_if->core_params->dev_out_nak;
  63360. +}
  63361. +
  63362. +int dwc_otg_set_param_cont_on_bna(dwc_otg_core_if_t * core_if, int32_t val)
  63363. +{
  63364. + int retval = 0;
  63365. + int valid = 1;
  63366. +
  63367. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  63368. + DWC_WARN("`%d' invalid for parameter `cont_on_bna'\n", val);
  63369. + DWC_WARN("cont_on_bna must be 0 or 1\n");
  63370. + return -DWC_E_INVALID;
  63371. + }
  63372. +
  63373. + if ((val == 1) && ((core_if->snpsid < OTG_CORE_REV_2_94a) ||
  63374. + !(core_if->core_params->dma_desc_enable))) {
  63375. + valid = 0;
  63376. + }
  63377. + if (valid == 0) {
  63378. + if (dwc_otg_param_initialized(core_if->core_params->cont_on_bna)) {
  63379. + DWC_ERROR("%d invalid for parameter cont_on_bna."
  63380. + "Check HW configuration.\n", val);
  63381. + }
  63382. + retval = -DWC_E_INVALID;
  63383. + val = 0;
  63384. + }
  63385. + core_if->core_params->cont_on_bna = val;
  63386. + return retval;
  63387. +}
  63388. +
  63389. +int32_t dwc_otg_get_param_cont_on_bna(dwc_otg_core_if_t * core_if)
  63390. +{
  63391. + return core_if->core_params->cont_on_bna;
  63392. +}
  63393. +
  63394. +int dwc_otg_set_param_ahb_single(dwc_otg_core_if_t * core_if, int32_t val)
  63395. +{
  63396. + int retval = 0;
  63397. + int valid = 1;
  63398. +
  63399. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  63400. + DWC_WARN("`%d' invalid for parameter `ahb_single'\n", val);
  63401. + DWC_WARN("ahb_single must be 0 or 1\n");
  63402. + return -DWC_E_INVALID;
  63403. + }
  63404. +
  63405. + if ((val == 1) && (core_if->snpsid < OTG_CORE_REV_2_94a)) {
  63406. + valid = 0;
  63407. + }
  63408. + if (valid == 0) {
  63409. + if (dwc_otg_param_initialized(core_if->core_params->ahb_single)) {
  63410. + DWC_ERROR("%d invalid for parameter ahb_single."
  63411. + "Check HW configuration.\n", val);
  63412. + }
  63413. + retval = -DWC_E_INVALID;
  63414. + val = 0;
  63415. + }
  63416. + core_if->core_params->ahb_single = val;
  63417. + return retval;
  63418. +}
  63419. +
  63420. +int32_t dwc_otg_get_param_ahb_single(dwc_otg_core_if_t * core_if)
  63421. +{
  63422. + return core_if->core_params->ahb_single;
  63423. +}
  63424. +
  63425. +int dwc_otg_set_param_otg_ver(dwc_otg_core_if_t * core_if, int32_t val)
  63426. +{
  63427. + int retval = 0;
  63428. +
  63429. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  63430. + DWC_WARN("`%d' invalid for parameter `otg_ver'\n", val);
  63431. + DWC_WARN
  63432. + ("otg_ver must be 0(for OTG 1.3 support) or 1(for OTG 2.0 support)\n");
  63433. + return -DWC_E_INVALID;
  63434. + }
  63435. +
  63436. + core_if->core_params->otg_ver = val;
  63437. + return retval;
  63438. +}
  63439. +
  63440. +int32_t dwc_otg_get_param_otg_ver(dwc_otg_core_if_t * core_if)
  63441. +{
  63442. + return core_if->core_params->otg_ver;
  63443. +}
  63444. +
  63445. +uint32_t dwc_otg_get_hnpstatus(dwc_otg_core_if_t * core_if)
  63446. +{
  63447. + gotgctl_data_t otgctl;
  63448. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  63449. + return otgctl.b.hstnegscs;
  63450. +}
  63451. +
  63452. +uint32_t dwc_otg_get_srpstatus(dwc_otg_core_if_t * core_if)
  63453. +{
  63454. + gotgctl_data_t otgctl;
  63455. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  63456. + return otgctl.b.sesreqscs;
  63457. +}
  63458. +
  63459. +void dwc_otg_set_hnpreq(dwc_otg_core_if_t * core_if, uint32_t val)
  63460. +{
  63461. + if(core_if->otg_ver == 0) {
  63462. + gotgctl_data_t otgctl;
  63463. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  63464. + otgctl.b.hnpreq = val;
  63465. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, otgctl.d32);
  63466. + } else {
  63467. + core_if->otg_sts = val;
  63468. + }
  63469. +}
  63470. +
  63471. +uint32_t dwc_otg_get_gsnpsid(dwc_otg_core_if_t * core_if)
  63472. +{
  63473. + return core_if->snpsid;
  63474. +}
  63475. +
  63476. +uint32_t dwc_otg_get_mode(dwc_otg_core_if_t * core_if)
  63477. +{
  63478. + gintsts_data_t gintsts;
  63479. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  63480. + return gintsts.b.curmode;
  63481. +}
  63482. +
  63483. +uint32_t dwc_otg_get_hnpcapable(dwc_otg_core_if_t * core_if)
  63484. +{
  63485. + gusbcfg_data_t usbcfg;
  63486. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  63487. + return usbcfg.b.hnpcap;
  63488. +}
  63489. +
  63490. +void dwc_otg_set_hnpcapable(dwc_otg_core_if_t * core_if, uint32_t val)
  63491. +{
  63492. + gusbcfg_data_t usbcfg;
  63493. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  63494. + usbcfg.b.hnpcap = val;
  63495. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, usbcfg.d32);
  63496. +}
  63497. +
  63498. +uint32_t dwc_otg_get_srpcapable(dwc_otg_core_if_t * core_if)
  63499. +{
  63500. + gusbcfg_data_t usbcfg;
  63501. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  63502. + return usbcfg.b.srpcap;
  63503. +}
  63504. +
  63505. +void dwc_otg_set_srpcapable(dwc_otg_core_if_t * core_if, uint32_t val)
  63506. +{
  63507. + gusbcfg_data_t usbcfg;
  63508. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  63509. + usbcfg.b.srpcap = val;
  63510. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, usbcfg.d32);
  63511. +}
  63512. +
  63513. +uint32_t dwc_otg_get_devspeed(dwc_otg_core_if_t * core_if)
  63514. +{
  63515. + dcfg_data_t dcfg;
  63516. + /* originally: dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg); */
  63517. +
  63518. + dcfg.d32 = -1; //GRAYG
  63519. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)\n", __func__, core_if);
  63520. + if (NULL == core_if)
  63521. + DWC_ERROR("reg request with NULL core_if\n");
  63522. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)->dev_if(%p)\n", __func__,
  63523. + core_if, core_if->dev_if);
  63524. + if (NULL == core_if->dev_if)
  63525. + DWC_ERROR("reg request with NULL dev_if\n");
  63526. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)->dev_if(%p)->"
  63527. + "dev_global_regs(%p)\n", __func__,
  63528. + core_if, core_if->dev_if,
  63529. + core_if->dev_if->dev_global_regs);
  63530. + if (NULL == core_if->dev_if->dev_global_regs)
  63531. + DWC_ERROR("reg request with NULL dev_global_regs\n");
  63532. + else {
  63533. + DWC_DEBUGPL(DBG_CILV, "%s - &core_if(%p)->dev_if(%p)->"
  63534. + "dev_global_regs(%p)->dcfg = %p\n", __func__,
  63535. + core_if, core_if->dev_if,
  63536. + core_if->dev_if->dev_global_regs,
  63537. + &core_if->dev_if->dev_global_regs->dcfg);
  63538. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  63539. + }
  63540. + return dcfg.b.devspd;
  63541. +}
  63542. +
  63543. +void dwc_otg_set_devspeed(dwc_otg_core_if_t * core_if, uint32_t val)
  63544. +{
  63545. + dcfg_data_t dcfg;
  63546. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  63547. + dcfg.b.devspd = val;
  63548. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  63549. +}
  63550. +
  63551. +uint32_t dwc_otg_get_busconnected(dwc_otg_core_if_t * core_if)
  63552. +{
  63553. + hprt0_data_t hprt0;
  63554. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  63555. + return hprt0.b.prtconnsts;
  63556. +}
  63557. +
  63558. +uint32_t dwc_otg_get_enumspeed(dwc_otg_core_if_t * core_if)
  63559. +{
  63560. + dsts_data_t dsts;
  63561. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  63562. + return dsts.b.enumspd;
  63563. +}
  63564. +
  63565. +uint32_t dwc_otg_get_prtpower(dwc_otg_core_if_t * core_if)
  63566. +{
  63567. + hprt0_data_t hprt0;
  63568. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  63569. + return hprt0.b.prtpwr;
  63570. +
  63571. +}
  63572. +
  63573. +uint32_t dwc_otg_get_core_state(dwc_otg_core_if_t * core_if)
  63574. +{
  63575. + return core_if->hibernation_suspend;
  63576. +}
  63577. +
  63578. +void dwc_otg_set_prtpower(dwc_otg_core_if_t * core_if, uint32_t val)
  63579. +{
  63580. + hprt0_data_t hprt0;
  63581. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  63582. + hprt0.b.prtpwr = val;
  63583. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  63584. +}
  63585. +
  63586. +uint32_t dwc_otg_get_prtsuspend(dwc_otg_core_if_t * core_if)
  63587. +{
  63588. + hprt0_data_t hprt0;
  63589. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  63590. + return hprt0.b.prtsusp;
  63591. +
  63592. +}
  63593. +
  63594. +void dwc_otg_set_prtsuspend(dwc_otg_core_if_t * core_if, uint32_t val)
  63595. +{
  63596. + hprt0_data_t hprt0;
  63597. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  63598. + hprt0.b.prtsusp = val;
  63599. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  63600. +}
  63601. +
  63602. +uint32_t dwc_otg_get_fr_interval(dwc_otg_core_if_t * core_if)
  63603. +{
  63604. + hfir_data_t hfir;
  63605. + hfir.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  63606. + return hfir.b.frint;
  63607. +
  63608. +}
  63609. +
  63610. +void dwc_otg_set_fr_interval(dwc_otg_core_if_t * core_if, uint32_t val)
  63611. +{
  63612. + hfir_data_t hfir;
  63613. + uint32_t fram_int;
  63614. + fram_int = calc_frame_interval(core_if);
  63615. + hfir.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  63616. + if (!core_if->core_params->reload_ctl) {
  63617. + DWC_WARN("\nCannot reload HFIR register.HFIR.HFIRRldCtrl bit is"
  63618. + "not set to 1.\nShould load driver with reload_ctl=1"
  63619. + " module parameter\n");
  63620. + return;
  63621. + }
  63622. + switch (fram_int) {
  63623. + case 3750:
  63624. + if ((val < 3350) || (val > 4150)) {
  63625. + DWC_WARN("HFIR interval for HS core and 30 MHz"
  63626. + "clock freq should be from 3350 to 4150\n");
  63627. + return;
  63628. + }
  63629. + break;
  63630. + case 30000:
  63631. + if ((val < 26820) || (val > 33180)) {
  63632. + DWC_WARN("HFIR interval for FS/LS core and 30 MHz"
  63633. + "clock freq should be from 26820 to 33180\n");
  63634. + return;
  63635. + }
  63636. + break;
  63637. + case 6000:
  63638. + if ((val < 5360) || (val > 6640)) {
  63639. + DWC_WARN("HFIR interval for HS core and 48 MHz"
  63640. + "clock freq should be from 5360 to 6640\n");
  63641. + return;
  63642. + }
  63643. + break;
  63644. + case 48000:
  63645. + if ((val < 42912) || (val > 53088)) {
  63646. + DWC_WARN("HFIR interval for FS/LS core and 48 MHz"
  63647. + "clock freq should be from 42912 to 53088\n");
  63648. + return;
  63649. + }
  63650. + break;
  63651. + case 7500:
  63652. + if ((val < 6700) || (val > 8300)) {
  63653. + DWC_WARN("HFIR interval for HS core and 60 MHz"
  63654. + "clock freq should be from 6700 to 8300\n");
  63655. + return;
  63656. + }
  63657. + break;
  63658. + case 60000:
  63659. + if ((val < 53640) || (val > 65536)) {
  63660. + DWC_WARN("HFIR interval for FS/LS core and 60 MHz"
  63661. + "clock freq should be from 53640 to 65536\n");
  63662. + return;
  63663. + }
  63664. + break;
  63665. + default:
  63666. + DWC_WARN("Unknown frame interval\n");
  63667. + return;
  63668. + break;
  63669. +
  63670. + }
  63671. + hfir.b.frint = val;
  63672. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hfir, hfir.d32);
  63673. +}
  63674. +
  63675. +uint32_t dwc_otg_get_mode_ch_tim(dwc_otg_core_if_t * core_if)
  63676. +{
  63677. + hcfg_data_t hcfg;
  63678. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  63679. + return hcfg.b.modechtimen;
  63680. +
  63681. +}
  63682. +
  63683. +void dwc_otg_set_mode_ch_tim(dwc_otg_core_if_t * core_if, uint32_t val)
  63684. +{
  63685. + hcfg_data_t hcfg;
  63686. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  63687. + hcfg.b.modechtimen = val;
  63688. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  63689. +}
  63690. +
  63691. +void dwc_otg_set_prtresume(dwc_otg_core_if_t * core_if, uint32_t val)
  63692. +{
  63693. + hprt0_data_t hprt0;
  63694. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  63695. + hprt0.b.prtres = val;
  63696. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  63697. +}
  63698. +
  63699. +uint32_t dwc_otg_get_remotewakesig(dwc_otg_core_if_t * core_if)
  63700. +{
  63701. + dctl_data_t dctl;
  63702. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  63703. + return dctl.b.rmtwkupsig;
  63704. +}
  63705. +
  63706. +uint32_t dwc_otg_get_lpm_portsleepstatus(dwc_otg_core_if_t * core_if)
  63707. +{
  63708. + glpmcfg_data_t lpmcfg;
  63709. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  63710. +
  63711. + DWC_ASSERT(!
  63712. + ((core_if->lx_state == DWC_OTG_L1) ^ lpmcfg.b.prt_sleep_sts),
  63713. + "lx_state = %d, lmpcfg.prt_sleep_sts = %d\n",
  63714. + core_if->lx_state, lpmcfg.b.prt_sleep_sts);
  63715. +
  63716. + return lpmcfg.b.prt_sleep_sts;
  63717. +}
  63718. +
  63719. +uint32_t dwc_otg_get_lpm_remotewakeenabled(dwc_otg_core_if_t * core_if)
  63720. +{
  63721. + glpmcfg_data_t lpmcfg;
  63722. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  63723. + return lpmcfg.b.rem_wkup_en;
  63724. +}
  63725. +
  63726. +uint32_t dwc_otg_get_lpmresponse(dwc_otg_core_if_t * core_if)
  63727. +{
  63728. + glpmcfg_data_t lpmcfg;
  63729. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  63730. + return lpmcfg.b.appl_resp;
  63731. +}
  63732. +
  63733. +void dwc_otg_set_lpmresponse(dwc_otg_core_if_t * core_if, uint32_t val)
  63734. +{
  63735. + glpmcfg_data_t lpmcfg;
  63736. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  63737. + lpmcfg.b.appl_resp = val;
  63738. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  63739. +}
  63740. +
  63741. +uint32_t dwc_otg_get_hsic_connect(dwc_otg_core_if_t * core_if)
  63742. +{
  63743. + glpmcfg_data_t lpmcfg;
  63744. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  63745. + return lpmcfg.b.hsic_connect;
  63746. +}
  63747. +
  63748. +void dwc_otg_set_hsic_connect(dwc_otg_core_if_t * core_if, uint32_t val)
  63749. +{
  63750. + glpmcfg_data_t lpmcfg;
  63751. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  63752. + lpmcfg.b.hsic_connect = val;
  63753. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  63754. +}
  63755. +
  63756. +uint32_t dwc_otg_get_inv_sel_hsic(dwc_otg_core_if_t * core_if)
  63757. +{
  63758. + glpmcfg_data_t lpmcfg;
  63759. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  63760. + return lpmcfg.b.inv_sel_hsic;
  63761. +
  63762. +}
  63763. +
  63764. +void dwc_otg_set_inv_sel_hsic(dwc_otg_core_if_t * core_if, uint32_t val)
  63765. +{
  63766. + glpmcfg_data_t lpmcfg;
  63767. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  63768. + lpmcfg.b.inv_sel_hsic = val;
  63769. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  63770. +}
  63771. +
  63772. +uint32_t dwc_otg_get_gotgctl(dwc_otg_core_if_t * core_if)
  63773. +{
  63774. + return DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  63775. +}
  63776. +
  63777. +void dwc_otg_set_gotgctl(dwc_otg_core_if_t * core_if, uint32_t val)
  63778. +{
  63779. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, val);
  63780. +}
  63781. +
  63782. +uint32_t dwc_otg_get_gusbcfg(dwc_otg_core_if_t * core_if)
  63783. +{
  63784. + return DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  63785. +}
  63786. +
  63787. +void dwc_otg_set_gusbcfg(dwc_otg_core_if_t * core_if, uint32_t val)
  63788. +{
  63789. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, val);
  63790. +}
  63791. +
  63792. +uint32_t dwc_otg_get_grxfsiz(dwc_otg_core_if_t * core_if)
  63793. +{
  63794. + return DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  63795. +}
  63796. +
  63797. +void dwc_otg_set_grxfsiz(dwc_otg_core_if_t * core_if, uint32_t val)
  63798. +{
  63799. + DWC_WRITE_REG32(&core_if->core_global_regs->grxfsiz, val);
  63800. +}
  63801. +
  63802. +uint32_t dwc_otg_get_gnptxfsiz(dwc_otg_core_if_t * core_if)
  63803. +{
  63804. + return DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz);
  63805. +}
  63806. +
  63807. +void dwc_otg_set_gnptxfsiz(dwc_otg_core_if_t * core_if, uint32_t val)
  63808. +{
  63809. + DWC_WRITE_REG32(&core_if->core_global_regs->gnptxfsiz, val);
  63810. +}
  63811. +
  63812. +uint32_t dwc_otg_get_gpvndctl(dwc_otg_core_if_t * core_if)
  63813. +{
  63814. + return DWC_READ_REG32(&core_if->core_global_regs->gpvndctl);
  63815. +}
  63816. +
  63817. +void dwc_otg_set_gpvndctl(dwc_otg_core_if_t * core_if, uint32_t val)
  63818. +{
  63819. + DWC_WRITE_REG32(&core_if->core_global_regs->gpvndctl, val);
  63820. +}
  63821. +
  63822. +uint32_t dwc_otg_get_ggpio(dwc_otg_core_if_t * core_if)
  63823. +{
  63824. + return DWC_READ_REG32(&core_if->core_global_regs->ggpio);
  63825. +}
  63826. +
  63827. +void dwc_otg_set_ggpio(dwc_otg_core_if_t * core_if, uint32_t val)
  63828. +{
  63829. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, val);
  63830. +}
  63831. +
  63832. +uint32_t dwc_otg_get_hprt0(dwc_otg_core_if_t * core_if)
  63833. +{
  63834. + return DWC_READ_REG32(core_if->host_if->hprt0);
  63835. +
  63836. +}
  63837. +
  63838. +void dwc_otg_set_hprt0(dwc_otg_core_if_t * core_if, uint32_t val)
  63839. +{
  63840. + DWC_WRITE_REG32(core_if->host_if->hprt0, val);
  63841. +}
  63842. +
  63843. +uint32_t dwc_otg_get_guid(dwc_otg_core_if_t * core_if)
  63844. +{
  63845. + return DWC_READ_REG32(&core_if->core_global_regs->guid);
  63846. +}
  63847. +
  63848. +void dwc_otg_set_guid(dwc_otg_core_if_t * core_if, uint32_t val)
  63849. +{
  63850. + DWC_WRITE_REG32(&core_if->core_global_regs->guid, val);
  63851. +}
  63852. +
  63853. +uint32_t dwc_otg_get_hptxfsiz(dwc_otg_core_if_t * core_if)
  63854. +{
  63855. + return DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  63856. +}
  63857. +
  63858. +uint16_t dwc_otg_get_otg_version(dwc_otg_core_if_t * core_if)
  63859. +{
  63860. + return ((core_if->otg_ver == 1) ? (uint16_t)0x0200 : (uint16_t)0x0103);
  63861. +}
  63862. +
  63863. +/**
  63864. + * Start the SRP timer to detect when the SRP does not complete within
  63865. + * 6 seconds.
  63866. + *
  63867. + * @param core_if the pointer to core_if strucure.
  63868. + */
  63869. +void dwc_otg_pcd_start_srp_timer(dwc_otg_core_if_t * core_if)
  63870. +{
  63871. + core_if->srp_timer_started = 1;
  63872. + DWC_TIMER_SCHEDULE(core_if->srp_timer, 6000 /* 6 secs */ );
  63873. +}
  63874. +
  63875. +void dwc_otg_initiate_srp(dwc_otg_core_if_t * core_if)
  63876. +{
  63877. + uint32_t *addr = (uint32_t *) & (core_if->core_global_regs->gotgctl);
  63878. + gotgctl_data_t mem;
  63879. + gotgctl_data_t val;
  63880. +
  63881. + val.d32 = DWC_READ_REG32(addr);
  63882. + if (val.b.sesreq) {
  63883. + DWC_ERROR("Session Request Already active!\n");
  63884. + return;
  63885. + }
  63886. +
  63887. + DWC_INFO("Session Request Initated\n"); //NOTICE
  63888. + mem.d32 = DWC_READ_REG32(addr);
  63889. + mem.b.sesreq = 1;
  63890. + DWC_WRITE_REG32(addr, mem.d32);
  63891. +
  63892. + /* Start the SRP timer */
  63893. + dwc_otg_pcd_start_srp_timer(core_if);
  63894. + return;
  63895. +}
  63896. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_cil.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil.h
  63897. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_cil.h 1970-01-01 01:00:00.000000000 +0100
  63898. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil.h 2014-07-07 10:45:43.000000000 +0200
  63899. @@ -0,0 +1,1464 @@
  63900. +/* ==========================================================================
  63901. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.h $
  63902. + * $Revision: #123 $
  63903. + * $Date: 2012/08/10 $
  63904. + * $Change: 2047372 $
  63905. + *
  63906. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  63907. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  63908. + * otherwise expressly agreed to in writing between Synopsys and you.
  63909. + *
  63910. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  63911. + * any End User Software License Agreement or Agreement for Licensed Product
  63912. + * with Synopsys or any supplement thereto. You are permitted to use and
  63913. + * redistribute this Software in source and binary forms, with or without
  63914. + * modification, provided that redistributions of source code must retain this
  63915. + * notice. You may not view, use, disclose, copy or distribute this file or
  63916. + * any information contained herein except pursuant to this license grant from
  63917. + * Synopsys. If you do not agree with this notice, including the disclaimer
  63918. + * below, then you are not authorized to use the Software.
  63919. + *
  63920. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  63921. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  63922. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  63923. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  63924. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  63925. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  63926. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  63927. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  63928. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  63929. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  63930. + * DAMAGE.
  63931. + * ========================================================================== */
  63932. +
  63933. +#if !defined(__DWC_CIL_H__)
  63934. +#define __DWC_CIL_H__
  63935. +
  63936. +#include "dwc_list.h"
  63937. +#include "dwc_otg_dbg.h"
  63938. +#include "dwc_otg_regs.h"
  63939. +
  63940. +#include "dwc_otg_core_if.h"
  63941. +#include "dwc_otg_adp.h"
  63942. +
  63943. +/**
  63944. + * @file
  63945. + * This file contains the interface to the Core Interface Layer.
  63946. + */
  63947. +
  63948. +#ifdef DWC_UTE_CFI
  63949. +
  63950. +#define MAX_DMA_DESCS_PER_EP 256
  63951. +
  63952. +/**
  63953. + * Enumeration for the data buffer mode
  63954. + */
  63955. +typedef enum _data_buffer_mode {
  63956. + BM_STANDARD = 0, /* data buffer is in normal mode */
  63957. + BM_SG = 1, /* data buffer uses the scatter/gather mode */
  63958. + BM_CONCAT = 2, /* data buffer uses the concatenation mode */
  63959. + BM_CIRCULAR = 3, /* data buffer uses the circular DMA mode */
  63960. + BM_ALIGN = 4 /* data buffer is in buffer alignment mode */
  63961. +} data_buffer_mode_e;
  63962. +#endif //DWC_UTE_CFI
  63963. +
  63964. +/** Macros defined for DWC OTG HW Release version */
  63965. +
  63966. +#define OTG_CORE_REV_2_60a 0x4F54260A
  63967. +#define OTG_CORE_REV_2_71a 0x4F54271A
  63968. +#define OTG_CORE_REV_2_72a 0x4F54272A
  63969. +#define OTG_CORE_REV_2_80a 0x4F54280A
  63970. +#define OTG_CORE_REV_2_81a 0x4F54281A
  63971. +#define OTG_CORE_REV_2_90a 0x4F54290A
  63972. +#define OTG_CORE_REV_2_91a 0x4F54291A
  63973. +#define OTG_CORE_REV_2_92a 0x4F54292A
  63974. +#define OTG_CORE_REV_2_93a 0x4F54293A
  63975. +#define OTG_CORE_REV_2_94a 0x4F54294A
  63976. +#define OTG_CORE_REV_3_00a 0x4F54300A
  63977. +
  63978. +/**
  63979. + * Information for each ISOC packet.
  63980. + */
  63981. +typedef struct iso_pkt_info {
  63982. + uint32_t offset;
  63983. + uint32_t length;
  63984. + int32_t status;
  63985. +} iso_pkt_info_t;
  63986. +
  63987. +/**
  63988. + * The <code>dwc_ep</code> structure represents the state of a single
  63989. + * endpoint when acting in device mode. It contains the data items
  63990. + * needed for an endpoint to be activated and transfer packets.
  63991. + */
  63992. +typedef struct dwc_ep {
  63993. + /** EP number used for register address lookup */
  63994. + uint8_t num;
  63995. + /** EP direction 0 = OUT */
  63996. + unsigned is_in:1;
  63997. + /** EP active. */
  63998. + unsigned active:1;
  63999. +
  64000. + /**
  64001. + * Periodic Tx FIFO # for IN EPs For INTR EP set to 0 to use non-periodic
  64002. + * Tx FIFO. If dedicated Tx FIFOs are enabled Tx FIFO # FOR IN EPs*/
  64003. + unsigned tx_fifo_num:4;
  64004. + /** EP type: 0 - Control, 1 - ISOC, 2 - BULK, 3 - INTR */
  64005. + unsigned type:2;
  64006. +#define DWC_OTG_EP_TYPE_CONTROL 0
  64007. +#define DWC_OTG_EP_TYPE_ISOC 1
  64008. +#define DWC_OTG_EP_TYPE_BULK 2
  64009. +#define DWC_OTG_EP_TYPE_INTR 3
  64010. +
  64011. + /** DATA start PID for INTR and BULK EP */
  64012. + unsigned data_pid_start:1;
  64013. + /** Frame (even/odd) for ISOC EP */
  64014. + unsigned even_odd_frame:1;
  64015. + /** Max Packet bytes */
  64016. + unsigned maxpacket:11;
  64017. +
  64018. + /** Max Transfer size */
  64019. + uint32_t maxxfer;
  64020. +
  64021. + /** @name Transfer state */
  64022. + /** @{ */
  64023. +
  64024. + /**
  64025. + * Pointer to the beginning of the transfer buffer -- do not modify
  64026. + * during transfer.
  64027. + */
  64028. +
  64029. + dwc_dma_t dma_addr;
  64030. +
  64031. + dwc_dma_t dma_desc_addr;
  64032. + dwc_otg_dev_dma_desc_t *desc_addr;
  64033. +
  64034. + uint8_t *start_xfer_buff;
  64035. + /** pointer to the transfer buffer */
  64036. + uint8_t *xfer_buff;
  64037. + /** Number of bytes to transfer */
  64038. + unsigned xfer_len:19;
  64039. + /** Number of bytes transferred. */
  64040. + unsigned xfer_count:19;
  64041. + /** Sent ZLP */
  64042. + unsigned sent_zlp:1;
  64043. + /** Total len for control transfer */
  64044. + unsigned total_len:19;
  64045. +
  64046. + /** stall clear flag */
  64047. + unsigned stall_clear_flag:1;
  64048. +
  64049. + /** SETUP pkt cnt rollover flag for EP0 out*/
  64050. + unsigned stp_rollover;
  64051. +
  64052. +#ifdef DWC_UTE_CFI
  64053. + /* The buffer mode */
  64054. + data_buffer_mode_e buff_mode;
  64055. +
  64056. + /* The chain of DMA descriptors.
  64057. + * MAX_DMA_DESCS_PER_EP will be allocated for each active EP.
  64058. + */
  64059. + dwc_otg_dma_desc_t *descs;
  64060. +
  64061. + /* The DMA address of the descriptors chain start */
  64062. + dma_addr_t descs_dma_addr;
  64063. + /** This variable stores the length of the last enqueued request */
  64064. + uint32_t cfi_req_len;
  64065. +#endif //DWC_UTE_CFI
  64066. +
  64067. +/** Max DMA Descriptor count for any EP */
  64068. +#define MAX_DMA_DESC_CNT 256
  64069. + /** Allocated DMA Desc count */
  64070. + uint32_t desc_cnt;
  64071. +
  64072. + /** bInterval */
  64073. + uint32_t bInterval;
  64074. + /** Next frame num to setup next ISOC transfer */
  64075. + uint32_t frame_num;
  64076. + /** Indicates SOF number overrun in DSTS */
  64077. + uint8_t frm_overrun;
  64078. +
  64079. +#ifdef DWC_UTE_PER_IO
  64080. + /** Next frame num for which will be setup DMA Desc */
  64081. + uint32_t xiso_frame_num;
  64082. + /** bInterval */
  64083. + uint32_t xiso_bInterval;
  64084. + /** Count of currently active transfers - shall be either 0 or 1 */
  64085. + int xiso_active_xfers;
  64086. + int xiso_queued_xfers;
  64087. +#endif
  64088. +#ifdef DWC_EN_ISOC
  64089. + /**
  64090. + * Variables specific for ISOC EPs
  64091. + *
  64092. + */
  64093. + /** DMA addresses of ISOC buffers */
  64094. + dwc_dma_t dma_addr0;
  64095. + dwc_dma_t dma_addr1;
  64096. +
  64097. + dwc_dma_t iso_dma_desc_addr;
  64098. + dwc_otg_dev_dma_desc_t *iso_desc_addr;
  64099. +
  64100. + /** pointer to the transfer buffers */
  64101. + uint8_t *xfer_buff0;
  64102. + uint8_t *xfer_buff1;
  64103. +
  64104. + /** number of ISOC Buffer is processing */
  64105. + uint32_t proc_buf_num;
  64106. + /** Interval of ISOC Buffer processing */
  64107. + uint32_t buf_proc_intrvl;
  64108. + /** Data size for regular frame */
  64109. + uint32_t data_per_frame;
  64110. +
  64111. + /* todo - pattern data support is to be implemented in the future */
  64112. + /** Data size for pattern frame */
  64113. + uint32_t data_pattern_frame;
  64114. + /** Frame number of pattern data */
  64115. + uint32_t sync_frame;
  64116. +
  64117. + /** bInterval */
  64118. + uint32_t bInterval;
  64119. + /** ISO Packet number per frame */
  64120. + uint32_t pkt_per_frm;
  64121. + /** Next frame num for which will be setup DMA Desc */
  64122. + uint32_t next_frame;
  64123. + /** Number of packets per buffer processing */
  64124. + uint32_t pkt_cnt;
  64125. + /** Info for all isoc packets */
  64126. + iso_pkt_info_t *pkt_info;
  64127. + /** current pkt number */
  64128. + uint32_t cur_pkt;
  64129. + /** current pkt number */
  64130. + uint8_t *cur_pkt_addr;
  64131. + /** current pkt number */
  64132. + uint32_t cur_pkt_dma_addr;
  64133. +#endif /* DWC_EN_ISOC */
  64134. +
  64135. +/** @} */
  64136. +} dwc_ep_t;
  64137. +
  64138. +/*
  64139. + * Reasons for halting a host channel.
  64140. + */
  64141. +typedef enum dwc_otg_halt_status {
  64142. + DWC_OTG_HC_XFER_NO_HALT_STATUS,
  64143. + DWC_OTG_HC_XFER_COMPLETE,
  64144. + DWC_OTG_HC_XFER_URB_COMPLETE,
  64145. + DWC_OTG_HC_XFER_ACK,
  64146. + DWC_OTG_HC_XFER_NAK,
  64147. + DWC_OTG_HC_XFER_NYET,
  64148. + DWC_OTG_HC_XFER_STALL,
  64149. + DWC_OTG_HC_XFER_XACT_ERR,
  64150. + DWC_OTG_HC_XFER_FRAME_OVERRUN,
  64151. + DWC_OTG_HC_XFER_BABBLE_ERR,
  64152. + DWC_OTG_HC_XFER_DATA_TOGGLE_ERR,
  64153. + DWC_OTG_HC_XFER_AHB_ERR,
  64154. + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE,
  64155. + DWC_OTG_HC_XFER_URB_DEQUEUE
  64156. +} dwc_otg_halt_status_e;
  64157. +
  64158. +/**
  64159. + * Host channel descriptor. This structure represents the state of a single
  64160. + * host channel when acting in host mode. It contains the data items needed to
  64161. + * transfer packets to an endpoint via a host channel.
  64162. + */
  64163. +typedef struct dwc_hc {
  64164. + /** Host channel number used for register address lookup */
  64165. + uint8_t hc_num;
  64166. +
  64167. + /** Device to access */
  64168. + unsigned dev_addr:7;
  64169. +
  64170. + /** EP to access */
  64171. + unsigned ep_num:4;
  64172. +
  64173. + /** EP direction. 0: OUT, 1: IN */
  64174. + unsigned ep_is_in:1;
  64175. +
  64176. + /**
  64177. + * EP speed.
  64178. + * One of the following values:
  64179. + * - DWC_OTG_EP_SPEED_LOW
  64180. + * - DWC_OTG_EP_SPEED_FULL
  64181. + * - DWC_OTG_EP_SPEED_HIGH
  64182. + */
  64183. + unsigned speed:2;
  64184. +#define DWC_OTG_EP_SPEED_LOW 0
  64185. +#define DWC_OTG_EP_SPEED_FULL 1
  64186. +#define DWC_OTG_EP_SPEED_HIGH 2
  64187. +
  64188. + /**
  64189. + * Endpoint type.
  64190. + * One of the following values:
  64191. + * - DWC_OTG_EP_TYPE_CONTROL: 0
  64192. + * - DWC_OTG_EP_TYPE_ISOC: 1
  64193. + * - DWC_OTG_EP_TYPE_BULK: 2
  64194. + * - DWC_OTG_EP_TYPE_INTR: 3
  64195. + */
  64196. + unsigned ep_type:2;
  64197. +
  64198. + /** Max packet size in bytes */
  64199. + unsigned max_packet:11;
  64200. +
  64201. + /**
  64202. + * PID for initial transaction.
  64203. + * 0: DATA0,<br>
  64204. + * 1: DATA2,<br>
  64205. + * 2: DATA1,<br>
  64206. + * 3: MDATA (non-Control EP),
  64207. + * SETUP (Control EP)
  64208. + */
  64209. + unsigned data_pid_start:2;
  64210. +#define DWC_OTG_HC_PID_DATA0 0
  64211. +#define DWC_OTG_HC_PID_DATA2 1
  64212. +#define DWC_OTG_HC_PID_DATA1 2
  64213. +#define DWC_OTG_HC_PID_MDATA 3
  64214. +#define DWC_OTG_HC_PID_SETUP 3
  64215. +
  64216. + /** Number of periodic transactions per (micro)frame */
  64217. + unsigned multi_count:2;
  64218. +
  64219. + /** @name Transfer State */
  64220. + /** @{ */
  64221. +
  64222. + /** Pointer to the current transfer buffer position. */
  64223. + uint8_t *xfer_buff;
  64224. + /**
  64225. + * In Buffer DMA mode this buffer will be used
  64226. + * if xfer_buff is not DWORD aligned.
  64227. + */
  64228. + dwc_dma_t align_buff;
  64229. + /** Total number of bytes to transfer. */
  64230. + uint32_t xfer_len;
  64231. + /** Number of bytes transferred so far. */
  64232. + uint32_t xfer_count;
  64233. + /** Packet count at start of transfer.*/
  64234. + uint16_t start_pkt_count;
  64235. +
  64236. + /**
  64237. + * Flag to indicate whether the transfer has been started. Set to 1 if
  64238. + * it has been started, 0 otherwise.
  64239. + */
  64240. + uint8_t xfer_started;
  64241. +
  64242. + /**
  64243. + * Set to 1 to indicate that a PING request should be issued on this
  64244. + * channel. If 0, process normally.
  64245. + */
  64246. + uint8_t do_ping;
  64247. +
  64248. + /**
  64249. + * Set to 1 to indicate that the error count for this transaction is
  64250. + * non-zero. Set to 0 if the error count is 0.
  64251. + */
  64252. + uint8_t error_state;
  64253. +
  64254. + /**
  64255. + * Set to 1 to indicate that this channel should be halted the next
  64256. + * time a request is queued for the channel. This is necessary in
  64257. + * slave mode if no request queue space is available when an attempt
  64258. + * is made to halt the channel.
  64259. + */
  64260. + uint8_t halt_on_queue;
  64261. +
  64262. + /**
  64263. + * Set to 1 if the host channel has been halted, but the core is not
  64264. + * finished flushing queued requests. Otherwise 0.
  64265. + */
  64266. + uint8_t halt_pending;
  64267. +
  64268. + /**
  64269. + * Reason for halting the host channel.
  64270. + */
  64271. + dwc_otg_halt_status_e halt_status;
  64272. +
  64273. + /*
  64274. + * Split settings for the host channel
  64275. + */
  64276. + uint8_t do_split; /**< Enable split for the channel */
  64277. + uint8_t complete_split; /**< Enable complete split */
  64278. + uint8_t hub_addr; /**< Address of high speed hub */
  64279. +
  64280. + uint8_t port_addr; /**< Port of the low/full speed device */
  64281. + /** Split transaction position
  64282. + * One of the following values:
  64283. + * - DWC_HCSPLIT_XACTPOS_MID
  64284. + * - DWC_HCSPLIT_XACTPOS_BEGIN
  64285. + * - DWC_HCSPLIT_XACTPOS_END
  64286. + * - DWC_HCSPLIT_XACTPOS_ALL */
  64287. + uint8_t xact_pos;
  64288. +
  64289. + /** Set when the host channel does a short read. */
  64290. + uint8_t short_read;
  64291. +
  64292. + /**
  64293. + * Number of requests issued for this channel since it was assigned to
  64294. + * the current transfer (not counting PINGs).
  64295. + */
  64296. + uint8_t requests;
  64297. +
  64298. + /**
  64299. + * Queue Head for the transfer being processed by this channel.
  64300. + */
  64301. + struct dwc_otg_qh *qh;
  64302. +
  64303. + /** @} */
  64304. +
  64305. + /** Entry in list of host channels. */
  64306. + DWC_CIRCLEQ_ENTRY(dwc_hc) hc_list_entry;
  64307. +
  64308. + /** @name Descriptor DMA support */
  64309. + /** @{ */
  64310. +
  64311. + /** Number of Transfer Descriptors */
  64312. + uint16_t ntd;
  64313. +
  64314. + /** Descriptor List DMA address */
  64315. + dwc_dma_t desc_list_addr;
  64316. +
  64317. + /** Scheduling micro-frame bitmap. */
  64318. + uint8_t schinfo;
  64319. +
  64320. + /** @} */
  64321. +} dwc_hc_t;
  64322. +
  64323. +/**
  64324. + * The following parameters may be specified when starting the module. These
  64325. + * parameters define how the DWC_otg controller should be configured.
  64326. + */
  64327. +typedef struct dwc_otg_core_params {
  64328. + int32_t opt;
  64329. +
  64330. + /**
  64331. + * Specifies the OTG capabilities. The driver will automatically
  64332. + * detect the value for this parameter if none is specified.
  64333. + * 0 - HNP and SRP capable (default)
  64334. + * 1 - SRP Only capable
  64335. + * 2 - No HNP/SRP capable
  64336. + */
  64337. + int32_t otg_cap;
  64338. +
  64339. + /**
  64340. + * Specifies whether to use slave or DMA mode for accessing the data
  64341. + * FIFOs. The driver will automatically detect the value for this
  64342. + * parameter if none is specified.
  64343. + * 0 - Slave
  64344. + * 1 - DMA (default, if available)
  64345. + */
  64346. + int32_t dma_enable;
  64347. +
  64348. + /**
  64349. + * When DMA mode is enabled specifies whether to use address DMA or DMA
  64350. + * Descriptor mode for accessing the data FIFOs in device mode. The driver
  64351. + * will automatically detect the value for this if none is specified.
  64352. + * 0 - address DMA
  64353. + * 1 - DMA Descriptor(default, if available)
  64354. + */
  64355. + int32_t dma_desc_enable;
  64356. + /** The DMA Burst size (applicable only for External DMA
  64357. + * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  64358. + */
  64359. + int32_t dma_burst_size; /* Translate this to GAHBCFG values */
  64360. +
  64361. + /**
  64362. + * Specifies the maximum speed of operation in host and device mode.
  64363. + * The actual speed depends on the speed of the attached device and
  64364. + * the value of phy_type. The actual speed depends on the speed of the
  64365. + * attached device.
  64366. + * 0 - High Speed (default)
  64367. + * 1 - Full Speed
  64368. + */
  64369. + int32_t speed;
  64370. + /** Specifies whether low power mode is supported when attached
  64371. + * to a Full Speed or Low Speed device in host mode.
  64372. + * 0 - Don't support low power mode (default)
  64373. + * 1 - Support low power mode
  64374. + */
  64375. + int32_t host_support_fs_ls_low_power;
  64376. +
  64377. + /** Specifies the PHY clock rate in low power mode when connected to a
  64378. + * Low Speed device in host mode. This parameter is applicable only if
  64379. + * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
  64380. + * then defaults to 6 MHZ otherwise 48 MHZ.
  64381. + *
  64382. + * 0 - 48 MHz
  64383. + * 1 - 6 MHz
  64384. + */
  64385. + int32_t host_ls_low_power_phy_clk;
  64386. +
  64387. + /**
  64388. + * 0 - Use cC FIFO size parameters
  64389. + * 1 - Allow dynamic FIFO sizing (default)
  64390. + */
  64391. + int32_t enable_dynamic_fifo;
  64392. +
  64393. + /** Total number of 4-byte words in the data FIFO memory. This
  64394. + * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
  64395. + * Tx FIFOs.
  64396. + * 32 to 32768 (default 8192)
  64397. + * Note: The total FIFO memory depth in the FPGA configuration is 8192.
  64398. + */
  64399. + int32_t data_fifo_size;
  64400. +
  64401. + /** Number of 4-byte words in the Rx FIFO in device mode when dynamic
  64402. + * FIFO sizing is enabled.
  64403. + * 16 to 32768 (default 1064)
  64404. + */
  64405. + int32_t dev_rx_fifo_size;
  64406. +
  64407. + /** Number of 4-byte words in the non-periodic Tx FIFO in device mode
  64408. + * when dynamic FIFO sizing is enabled.
  64409. + * 16 to 32768 (default 1024)
  64410. + */
  64411. + int32_t dev_nperio_tx_fifo_size;
  64412. +
  64413. + /** Number of 4-byte words in each of the periodic Tx FIFOs in device
  64414. + * mode when dynamic FIFO sizing is enabled.
  64415. + * 4 to 768 (default 256)
  64416. + */
  64417. + uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
  64418. +
  64419. + /** Number of 4-byte words in the Rx FIFO in host mode when dynamic
  64420. + * FIFO sizing is enabled.
  64421. + * 16 to 32768 (default 1024)
  64422. + */
  64423. + int32_t host_rx_fifo_size;
  64424. +
  64425. + /** Number of 4-byte words in the non-periodic Tx FIFO in host mode
  64426. + * when Dynamic FIFO sizing is enabled in the core.
  64427. + * 16 to 32768 (default 1024)
  64428. + */
  64429. + int32_t host_nperio_tx_fifo_size;
  64430. +
  64431. + /** Number of 4-byte words in the host periodic Tx FIFO when dynamic
  64432. + * FIFO sizing is enabled.
  64433. + * 16 to 32768 (default 1024)
  64434. + */
  64435. + int32_t host_perio_tx_fifo_size;
  64436. +
  64437. + /** The maximum transfer size supported in bytes.
  64438. + * 2047 to 65,535 (default 65,535)
  64439. + */
  64440. + int32_t max_transfer_size;
  64441. +
  64442. + /** The maximum number of packets in a transfer.
  64443. + * 15 to 511 (default 511)
  64444. + */
  64445. + int32_t max_packet_count;
  64446. +
  64447. + /** The number of host channel registers to use.
  64448. + * 1 to 16 (default 12)
  64449. + * Note: The FPGA configuration supports a maximum of 12 host channels.
  64450. + */
  64451. + int32_t host_channels;
  64452. +
  64453. + /** The number of endpoints in addition to EP0 available for device
  64454. + * mode operations.
  64455. + * 1 to 15 (default 6 IN and OUT)
  64456. + * Note: The FPGA configuration supports a maximum of 6 IN and OUT
  64457. + * endpoints in addition to EP0.
  64458. + */
  64459. + int32_t dev_endpoints;
  64460. +
  64461. + /**
  64462. + * Specifies the type of PHY interface to use. By default, the driver
  64463. + * will automatically detect the phy_type.
  64464. + *
  64465. + * 0 - Full Speed PHY
  64466. + * 1 - UTMI+ (default)
  64467. + * 2 - ULPI
  64468. + */
  64469. + int32_t phy_type;
  64470. +
  64471. + /**
  64472. + * Specifies the UTMI+ Data Width. This parameter is
  64473. + * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
  64474. + * PHY_TYPE, this parameter indicates the data width between
  64475. + * the MAC and the ULPI Wrapper.) Also, this parameter is
  64476. + * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
  64477. + * to "8 and 16 bits", meaning that the core has been
  64478. + * configured to work at either data path width.
  64479. + *
  64480. + * 8 or 16 bits (default 16)
  64481. + */
  64482. + int32_t phy_utmi_width;
  64483. +
  64484. + /**
  64485. + * Specifies whether the ULPI operates at double or single
  64486. + * data rate. This parameter is only applicable if PHY_TYPE is
  64487. + * ULPI.
  64488. + *
  64489. + * 0 - single data rate ULPI interface with 8 bit wide data
  64490. + * bus (default)
  64491. + * 1 - double data rate ULPI interface with 4 bit wide data
  64492. + * bus
  64493. + */
  64494. + int32_t phy_ulpi_ddr;
  64495. +
  64496. + /**
  64497. + * Specifies whether to use the internal or external supply to
  64498. + * drive the vbus with a ULPI phy.
  64499. + */
  64500. + int32_t phy_ulpi_ext_vbus;
  64501. +
  64502. + /**
  64503. + * Specifies whether to use the I2Cinterface for full speed PHY. This
  64504. + * parameter is only applicable if PHY_TYPE is FS.
  64505. + * 0 - No (default)
  64506. + * 1 - Yes
  64507. + */
  64508. + int32_t i2c_enable;
  64509. +
  64510. + int32_t ulpi_fs_ls;
  64511. +
  64512. + int32_t ts_dline;
  64513. +
  64514. + /**
  64515. + * Specifies whether dedicated transmit FIFOs are
  64516. + * enabled for non periodic IN endpoints in device mode
  64517. + * 0 - No
  64518. + * 1 - Yes
  64519. + */
  64520. + int32_t en_multiple_tx_fifo;
  64521. +
  64522. + /** Number of 4-byte words in each of the Tx FIFOs in device
  64523. + * mode when dynamic FIFO sizing is enabled.
  64524. + * 4 to 768 (default 256)
  64525. + */
  64526. + uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
  64527. +
  64528. + /** Thresholding enable flag-
  64529. + * bit 0 - enable non-ISO Tx thresholding
  64530. + * bit 1 - enable ISO Tx thresholding
  64531. + * bit 2 - enable Rx thresholding
  64532. + */
  64533. + uint32_t thr_ctl;
  64534. +
  64535. + /** Thresholding length for Tx
  64536. + * FIFOs in 32 bit DWORDs
  64537. + */
  64538. + uint32_t tx_thr_length;
  64539. +
  64540. + /** Thresholding length for Rx
  64541. + * FIFOs in 32 bit DWORDs
  64542. + */
  64543. + uint32_t rx_thr_length;
  64544. +
  64545. + /**
  64546. + * Specifies whether LPM (Link Power Management) support is enabled
  64547. + */
  64548. + int32_t lpm_enable;
  64549. +
  64550. + /** Per Transfer Interrupt
  64551. + * mode enable flag
  64552. + * 1 - Enabled
  64553. + * 0 - Disabled
  64554. + */
  64555. + int32_t pti_enable;
  64556. +
  64557. + /** Multi Processor Interrupt
  64558. + * mode enable flag
  64559. + * 1 - Enabled
  64560. + * 0 - Disabled
  64561. + */
  64562. + int32_t mpi_enable;
  64563. +
  64564. + /** IS_USB Capability
  64565. + * 1 - Enabled
  64566. + * 0 - Disabled
  64567. + */
  64568. + int32_t ic_usb_cap;
  64569. +
  64570. + /** AHB Threshold Ratio
  64571. + * 2'b00 AHB Threshold = MAC Threshold
  64572. + * 2'b01 AHB Threshold = 1/2 MAC Threshold
  64573. + * 2'b10 AHB Threshold = 1/4 MAC Threshold
  64574. + * 2'b11 AHB Threshold = 1/8 MAC Threshold
  64575. + */
  64576. + int32_t ahb_thr_ratio;
  64577. +
  64578. + /** ADP Support
  64579. + * 1 - Enabled
  64580. + * 0 - Disabled
  64581. + */
  64582. + int32_t adp_supp_enable;
  64583. +
  64584. + /** HFIR Reload Control
  64585. + * 0 - The HFIR cannot be reloaded dynamically.
  64586. + * 1 - Allow dynamic reloading of the HFIR register during runtime.
  64587. + */
  64588. + int32_t reload_ctl;
  64589. +
  64590. + /** DCFG: Enable device Out NAK
  64591. + * 0 - The core does not set NAK after Bulk Out transfer complete.
  64592. + * 1 - The core sets NAK after Bulk OUT transfer complete.
  64593. + */
  64594. + int32_t dev_out_nak;
  64595. +
  64596. + /** DCFG: Enable Continue on BNA
  64597. + * After receiving BNA interrupt the core disables the endpoint,when the
  64598. + * endpoint is re-enabled by the application the core starts processing
  64599. + * 0 - from the DOEPDMA descriptor
  64600. + * 1 - from the descriptor which received the BNA.
  64601. + */
  64602. + int32_t cont_on_bna;
  64603. +
  64604. + /** GAHBCFG: AHB Single Support
  64605. + * This bit when programmed supports SINGLE transfers for remainder
  64606. + * data in a transfer for DMA mode of operation.
  64607. + * 0 - in this case the remainder data will be sent using INCR burst size.
  64608. + * 1 - in this case the remainder data will be sent using SINGLE burst size.
  64609. + */
  64610. + int32_t ahb_single;
  64611. +
  64612. + /** Core Power down mode
  64613. + * 0 - No Power Down is enabled
  64614. + * 1 - Reserved
  64615. + * 2 - Complete Power Down (Hibernation)
  64616. + */
  64617. + int32_t power_down;
  64618. +
  64619. + /** OTG revision supported
  64620. + * 0 - OTG 1.3 revision
  64621. + * 1 - OTG 2.0 revision
  64622. + */
  64623. + int32_t otg_ver;
  64624. +
  64625. +} dwc_otg_core_params_t;
  64626. +
  64627. +#ifdef DEBUG
  64628. +struct dwc_otg_core_if;
  64629. +typedef struct hc_xfer_info {
  64630. + struct dwc_otg_core_if *core_if;
  64631. + dwc_hc_t *hc;
  64632. +} hc_xfer_info_t;
  64633. +#endif
  64634. +
  64635. +typedef struct ep_xfer_info {
  64636. + struct dwc_otg_core_if *core_if;
  64637. + dwc_ep_t *ep;
  64638. + uint8_t state;
  64639. +} ep_xfer_info_t;
  64640. +/*
  64641. + * Device States
  64642. + */
  64643. +typedef enum dwc_otg_lx_state {
  64644. + /** On state */
  64645. + DWC_OTG_L0,
  64646. + /** LPM sleep state*/
  64647. + DWC_OTG_L1,
  64648. + /** USB suspend state*/
  64649. + DWC_OTG_L2,
  64650. + /** Off state*/
  64651. + DWC_OTG_L3
  64652. +} dwc_otg_lx_state_e;
  64653. +
  64654. +struct dwc_otg_global_regs_backup {
  64655. + uint32_t gotgctl_local;
  64656. + uint32_t gintmsk_local;
  64657. + uint32_t gahbcfg_local;
  64658. + uint32_t gusbcfg_local;
  64659. + uint32_t grxfsiz_local;
  64660. + uint32_t gnptxfsiz_local;
  64661. +#ifdef CONFIG_USB_DWC_OTG_LPM
  64662. + uint32_t glpmcfg_local;
  64663. +#endif
  64664. + uint32_t gi2cctl_local;
  64665. + uint32_t hptxfsiz_local;
  64666. + uint32_t pcgcctl_local;
  64667. + uint32_t gdfifocfg_local;
  64668. + uint32_t dtxfsiz_local[MAX_EPS_CHANNELS];
  64669. + uint32_t gpwrdn_local;
  64670. + uint32_t xhib_pcgcctl;
  64671. + uint32_t xhib_gpwrdn;
  64672. +};
  64673. +
  64674. +struct dwc_otg_host_regs_backup {
  64675. + uint32_t hcfg_local;
  64676. + uint32_t haintmsk_local;
  64677. + uint32_t hcintmsk_local[MAX_EPS_CHANNELS];
  64678. + uint32_t hprt0_local;
  64679. + uint32_t hfir_local;
  64680. +};
  64681. +
  64682. +struct dwc_otg_dev_regs_backup {
  64683. + uint32_t dcfg;
  64684. + uint32_t dctl;
  64685. + uint32_t daintmsk;
  64686. + uint32_t diepmsk;
  64687. + uint32_t doepmsk;
  64688. + uint32_t diepctl[MAX_EPS_CHANNELS];
  64689. + uint32_t dieptsiz[MAX_EPS_CHANNELS];
  64690. + uint32_t diepdma[MAX_EPS_CHANNELS];
  64691. +};
  64692. +/**
  64693. + * The <code>dwc_otg_core_if</code> structure contains information needed to manage
  64694. + * the DWC_otg controller acting in either host or device mode. It
  64695. + * represents the programming view of the controller as a whole.
  64696. + */
  64697. +struct dwc_otg_core_if {
  64698. + /** Parameters that define how the core should be configured.*/
  64699. + dwc_otg_core_params_t *core_params;
  64700. +
  64701. + /** Core Global registers starting at offset 000h. */
  64702. + dwc_otg_core_global_regs_t *core_global_regs;
  64703. +
  64704. + /** Device-specific information */
  64705. + dwc_otg_dev_if_t *dev_if;
  64706. + /** Host-specific information */
  64707. + dwc_otg_host_if_t *host_if;
  64708. +
  64709. + /** Value from SNPSID register */
  64710. + uint32_t snpsid;
  64711. +
  64712. + /*
  64713. + * Set to 1 if the core PHY interface bits in USBCFG have been
  64714. + * initialized.
  64715. + */
  64716. + uint8_t phy_init_done;
  64717. +
  64718. + /*
  64719. + * SRP Success flag, set by srp success interrupt in FS I2C mode
  64720. + */
  64721. + uint8_t srp_success;
  64722. + uint8_t srp_timer_started;
  64723. + /** Timer for SRP. If it expires before SRP is successful
  64724. + * clear the SRP. */
  64725. + dwc_timer_t *srp_timer;
  64726. +
  64727. +#ifdef DWC_DEV_SRPCAP
  64728. + /* This timer is needed to power on the hibernated host core if SRP is not
  64729. + * initiated on connected SRP capable device for limited period of time
  64730. + */
  64731. + uint8_t pwron_timer_started;
  64732. + dwc_timer_t *pwron_timer;
  64733. +#endif
  64734. + /* Common configuration information */
  64735. + /** Power and Clock Gating Control Register */
  64736. + volatile uint32_t *pcgcctl;
  64737. +#define DWC_OTG_PCGCCTL_OFFSET 0xE00
  64738. +
  64739. + /** Push/pop addresses for endpoints or host channels.*/
  64740. + uint32_t *data_fifo[MAX_EPS_CHANNELS];
  64741. +#define DWC_OTG_DATA_FIFO_OFFSET 0x1000
  64742. +#define DWC_OTG_DATA_FIFO_SIZE 0x1000
  64743. +
  64744. + /** Total RAM for FIFOs (Bytes) */
  64745. + uint16_t total_fifo_size;
  64746. + /** Size of Rx FIFO (Bytes) */
  64747. + uint16_t rx_fifo_size;
  64748. + /** Size of Non-periodic Tx FIFO (Bytes) */
  64749. + uint16_t nperio_tx_fifo_size;
  64750. +
  64751. + /** 1 if DMA is enabled, 0 otherwise. */
  64752. + uint8_t dma_enable;
  64753. +
  64754. + /** 1 if DMA descriptor is enabled, 0 otherwise. */
  64755. + uint8_t dma_desc_enable;
  64756. +
  64757. + /** 1 if PTI Enhancement mode is enabled, 0 otherwise. */
  64758. + uint8_t pti_enh_enable;
  64759. +
  64760. + /** 1 if MPI Enhancement mode is enabled, 0 otherwise. */
  64761. + uint8_t multiproc_int_enable;
  64762. +
  64763. + /** 1 if dedicated Tx FIFOs are enabled, 0 otherwise. */
  64764. + uint8_t en_multiple_tx_fifo;
  64765. +
  64766. + /** Set to 1 if multiple packets of a high-bandwidth transfer is in
  64767. + * process of being queued */
  64768. + uint8_t queuing_high_bandwidth;
  64769. +
  64770. + /** Hardware Configuration -- stored here for convenience.*/
  64771. + hwcfg1_data_t hwcfg1;
  64772. + hwcfg2_data_t hwcfg2;
  64773. + hwcfg3_data_t hwcfg3;
  64774. + hwcfg4_data_t hwcfg4;
  64775. + fifosize_data_t hptxfsiz;
  64776. +
  64777. + /** Host and Device Configuration -- stored here for convenience.*/
  64778. + hcfg_data_t hcfg;
  64779. + dcfg_data_t dcfg;
  64780. +
  64781. + /** The operational State, during transations
  64782. + * (a_host>>a_peripherial and b_device=>b_host) this may not
  64783. + * match the core but allows the software to determine
  64784. + * transitions.
  64785. + */
  64786. + uint8_t op_state;
  64787. +
  64788. + /**
  64789. + * Set to 1 if the HCD needs to be restarted on a session request
  64790. + * interrupt. This is required if no connector ID status change has
  64791. + * occurred since the HCD was last disconnected.
  64792. + */
  64793. + uint8_t restart_hcd_on_session_req;
  64794. +
  64795. + /** HCD callbacks */
  64796. + /** A-Device is a_host */
  64797. +#define A_HOST (1)
  64798. + /** A-Device is a_suspend */
  64799. +#define A_SUSPEND (2)
  64800. + /** A-Device is a_peripherial */
  64801. +#define A_PERIPHERAL (3)
  64802. + /** B-Device is operating as a Peripheral. */
  64803. +#define B_PERIPHERAL (4)
  64804. + /** B-Device is operating as a Host. */
  64805. +#define B_HOST (5)
  64806. +
  64807. + /** HCD callbacks */
  64808. + struct dwc_otg_cil_callbacks *hcd_cb;
  64809. + /** PCD callbacks */
  64810. + struct dwc_otg_cil_callbacks *pcd_cb;
  64811. +
  64812. + /** Device mode Periodic Tx FIFO Mask */
  64813. + uint32_t p_tx_msk;
  64814. + /** Device mode Periodic Tx FIFO Mask */
  64815. + uint32_t tx_msk;
  64816. +
  64817. + /** Workqueue object used for handling several interrupts */
  64818. + dwc_workq_t *wq_otg;
  64819. +
  64820. + /** Timer object used for handling "Wakeup Detected" Interrupt */
  64821. + dwc_timer_t *wkp_timer;
  64822. + /** This arrays used for debug purposes for DEV OUT NAK enhancement */
  64823. + uint32_t start_doeptsiz_val[MAX_EPS_CHANNELS];
  64824. + ep_xfer_info_t ep_xfer_info[MAX_EPS_CHANNELS];
  64825. + dwc_timer_t *ep_xfer_timer[MAX_EPS_CHANNELS];
  64826. +#ifdef DEBUG
  64827. + uint32_t start_hcchar_val[MAX_EPS_CHANNELS];
  64828. +
  64829. + hc_xfer_info_t hc_xfer_info[MAX_EPS_CHANNELS];
  64830. + dwc_timer_t *hc_xfer_timer[MAX_EPS_CHANNELS];
  64831. +
  64832. + uint32_t hfnum_7_samples;
  64833. + uint64_t hfnum_7_frrem_accum;
  64834. + uint32_t hfnum_0_samples;
  64835. + uint64_t hfnum_0_frrem_accum;
  64836. + uint32_t hfnum_other_samples;
  64837. + uint64_t hfnum_other_frrem_accum;
  64838. +#endif
  64839. +
  64840. +#ifdef DWC_UTE_CFI
  64841. + uint16_t pwron_rxfsiz;
  64842. + uint16_t pwron_gnptxfsiz;
  64843. + uint16_t pwron_txfsiz[15];
  64844. +
  64845. + uint16_t init_rxfsiz;
  64846. + uint16_t init_gnptxfsiz;
  64847. + uint16_t init_txfsiz[15];
  64848. +#endif
  64849. +
  64850. + /** Lx state of device */
  64851. + dwc_otg_lx_state_e lx_state;
  64852. +
  64853. + /** Saved Core Global registers */
  64854. + struct dwc_otg_global_regs_backup *gr_backup;
  64855. + /** Saved Host registers */
  64856. + struct dwc_otg_host_regs_backup *hr_backup;
  64857. + /** Saved Device registers */
  64858. + struct dwc_otg_dev_regs_backup *dr_backup;
  64859. +
  64860. + /** Power Down Enable */
  64861. + uint32_t power_down;
  64862. +
  64863. + /** ADP support Enable */
  64864. + uint32_t adp_enable;
  64865. +
  64866. + /** ADP structure object */
  64867. + dwc_otg_adp_t adp;
  64868. +
  64869. + /** hibernation/suspend flag */
  64870. + int hibernation_suspend;
  64871. +
  64872. + /** Device mode extended hibernation flag */
  64873. + int xhib;
  64874. +
  64875. + /** OTG revision supported */
  64876. + uint32_t otg_ver;
  64877. +
  64878. + /** OTG status flag used for HNP polling */
  64879. + uint8_t otg_sts;
  64880. +
  64881. + /** Pointer to either hcd->lock or pcd->lock */
  64882. + dwc_spinlock_t *lock;
  64883. +
  64884. + /** Start predict NextEP based on Learning Queue if equal 1,
  64885. + * also used as counter of disabled NP IN EP's */
  64886. + uint8_t start_predict;
  64887. +
  64888. + /** NextEp sequence, including EP0: nextep_seq[] = EP if non-periodic and
  64889. + * active, 0xff otherwise */
  64890. + uint8_t nextep_seq[MAX_EPS_CHANNELS];
  64891. +
  64892. + /** Index of fisrt EP in nextep_seq array which should be re-enabled **/
  64893. + uint8_t first_in_nextep_seq;
  64894. +
  64895. + /** Frame number while entering to ISR - needed for ISOCs **/
  64896. + uint32_t frame_num;
  64897. +
  64898. +};
  64899. +
  64900. +#ifdef DEBUG
  64901. +/*
  64902. + * This function is called when transfer is timed out.
  64903. + */
  64904. +extern void hc_xfer_timeout(void *ptr);
  64905. +#endif
  64906. +
  64907. +/*
  64908. + * This function is called when transfer is timed out on endpoint.
  64909. + */
  64910. +extern void ep_xfer_timeout(void *ptr);
  64911. +
  64912. +/*
  64913. + * The following functions are functions for works
  64914. + * using during handling some interrupts
  64915. + */
  64916. +extern void w_conn_id_status_change(void *p);
  64917. +
  64918. +extern void w_wakeup_detected(void *p);
  64919. +
  64920. +/** Saves global register values into system memory. */
  64921. +extern int dwc_otg_save_global_regs(dwc_otg_core_if_t * core_if);
  64922. +/** Saves device register values into system memory. */
  64923. +extern int dwc_otg_save_dev_regs(dwc_otg_core_if_t * core_if);
  64924. +/** Saves host register values into system memory. */
  64925. +extern int dwc_otg_save_host_regs(dwc_otg_core_if_t * core_if);
  64926. +/** Restore global register values. */
  64927. +extern int dwc_otg_restore_global_regs(dwc_otg_core_if_t * core_if);
  64928. +/** Restore host register values. */
  64929. +extern int dwc_otg_restore_host_regs(dwc_otg_core_if_t * core_if, int reset);
  64930. +/** Restore device register values. */
  64931. +extern int dwc_otg_restore_dev_regs(dwc_otg_core_if_t * core_if,
  64932. + int rem_wakeup);
  64933. +extern int restore_lpm_i2c_regs(dwc_otg_core_if_t * core_if);
  64934. +extern int restore_essential_regs(dwc_otg_core_if_t * core_if, int rmode,
  64935. + int is_host);
  64936. +
  64937. +extern int dwc_otg_host_hibernation_restore(dwc_otg_core_if_t * core_if,
  64938. + int restore_mode, int reset);
  64939. +extern int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  64940. + int rem_wakeup, int reset);
  64941. +
  64942. +/*
  64943. + * The following functions support initialization of the CIL driver component
  64944. + * and the DWC_otg controller.
  64945. + */
  64946. +extern void dwc_otg_core_host_init(dwc_otg_core_if_t * _core_if);
  64947. +extern void dwc_otg_core_dev_init(dwc_otg_core_if_t * _core_if);
  64948. +
  64949. +/** @name Device CIL Functions
  64950. + * The following functions support managing the DWC_otg controller in device
  64951. + * mode.
  64952. + */
  64953. +/**@{*/
  64954. +extern void dwc_otg_wakeup(dwc_otg_core_if_t * _core_if);
  64955. +extern void dwc_otg_read_setup_packet(dwc_otg_core_if_t * _core_if,
  64956. + uint32_t * _dest);
  64957. +extern uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t * _core_if);
  64958. +extern void dwc_otg_ep0_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  64959. +extern void dwc_otg_ep_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  64960. +extern void dwc_otg_ep_deactivate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  64961. +extern void dwc_otg_ep_start_transfer(dwc_otg_core_if_t * _core_if,
  64962. + dwc_ep_t * _ep);
  64963. +extern void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t * _core_if,
  64964. + dwc_ep_t * _ep);
  64965. +extern void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t * _core_if,
  64966. + dwc_ep_t * _ep);
  64967. +extern void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t * _core_if,
  64968. + dwc_ep_t * _ep);
  64969. +extern void dwc_otg_ep_write_packet(dwc_otg_core_if_t * _core_if,
  64970. + dwc_ep_t * _ep, int _dma);
  64971. +extern void dwc_otg_ep_set_stall(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  64972. +extern void dwc_otg_ep_clear_stall(dwc_otg_core_if_t * _core_if,
  64973. + dwc_ep_t * _ep);
  64974. +extern void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t * _core_if);
  64975. +
  64976. +#ifdef DWC_EN_ISOC
  64977. +extern void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t * core_if,
  64978. + dwc_ep_t * ep);
  64979. +extern void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t * core_if,
  64980. + dwc_ep_t * ep);
  64981. +#endif /* DWC_EN_ISOC */
  64982. +/**@}*/
  64983. +
  64984. +/** @name Host CIL Functions
  64985. + * The following functions support managing the DWC_otg controller in host
  64986. + * mode.
  64987. + */
  64988. +/**@{*/
  64989. +extern void dwc_otg_hc_init(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  64990. +extern void dwc_otg_hc_halt(dwc_otg_core_if_t * _core_if,
  64991. + dwc_hc_t * _hc, dwc_otg_halt_status_e _halt_status);
  64992. +extern void dwc_otg_hc_cleanup(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  64993. +extern void dwc_otg_hc_start_transfer(dwc_otg_core_if_t * _core_if,
  64994. + dwc_hc_t * _hc);
  64995. +extern int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t * _core_if,
  64996. + dwc_hc_t * _hc);
  64997. +extern void dwc_otg_hc_do_ping(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  64998. +extern void dwc_otg_hc_write_packet(dwc_otg_core_if_t * _core_if,
  64999. + dwc_hc_t * _hc);
  65000. +extern void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t * _core_if);
  65001. +extern void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t * _core_if);
  65002. +
  65003. +extern void dwc_otg_hc_start_transfer_ddma(dwc_otg_core_if_t * core_if,
  65004. + dwc_hc_t * hc);
  65005. +
  65006. +extern uint32_t calc_frame_interval(dwc_otg_core_if_t * core_if);
  65007. +
  65008. +/* Macro used to clear one channel interrupt */
  65009. +#define clear_hc_int(_hc_regs_, _intr_) \
  65010. +do { \
  65011. + hcint_data_t hcint_clear = {.d32 = 0}; \
  65012. + hcint_clear.b._intr_ = 1; \
  65013. + DWC_WRITE_REG32(&(_hc_regs_)->hcint, hcint_clear.d32); \
  65014. +} while (0)
  65015. +
  65016. +/*
  65017. + * Macro used to disable one channel interrupt. Channel interrupts are
  65018. + * disabled when the channel is halted or released by the interrupt handler.
  65019. + * There is no need to handle further interrupts of that type until the
  65020. + * channel is re-assigned. In fact, subsequent handling may cause crashes
  65021. + * because the channel structures are cleaned up when the channel is released.
  65022. + */
  65023. +#define disable_hc_int(_hc_regs_, _intr_) \
  65024. +do { \
  65025. + hcintmsk_data_t hcintmsk = {.d32 = 0}; \
  65026. + hcintmsk.b._intr_ = 1; \
  65027. + DWC_MODIFY_REG32(&(_hc_regs_)->hcintmsk, hcintmsk.d32, 0); \
  65028. +} while (0)
  65029. +
  65030. +/**
  65031. + * This function Reads HPRT0 in preparation to modify. It keeps the
  65032. + * WC bits 0 so that if they are read as 1, they won't clear when you
  65033. + * write it back
  65034. + */
  65035. +static inline uint32_t dwc_otg_read_hprt0(dwc_otg_core_if_t * _core_if)
  65036. +{
  65037. + hprt0_data_t hprt0;
  65038. + hprt0.d32 = DWC_READ_REG32(_core_if->host_if->hprt0);
  65039. + hprt0.b.prtena = 0;
  65040. + hprt0.b.prtconndet = 0;
  65041. + hprt0.b.prtenchng = 0;
  65042. + hprt0.b.prtovrcurrchng = 0;
  65043. + return hprt0.d32;
  65044. +}
  65045. +
  65046. +/**@}*/
  65047. +
  65048. +/** @name Common CIL Functions
  65049. + * The following functions support managing the DWC_otg controller in either
  65050. + * device or host mode.
  65051. + */
  65052. +/**@{*/
  65053. +
  65054. +extern void dwc_otg_read_packet(dwc_otg_core_if_t * core_if,
  65055. + uint8_t * dest, uint16_t bytes);
  65056. +
  65057. +extern void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t * _core_if, const int _num);
  65058. +extern void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t * _core_if);
  65059. +extern void dwc_otg_core_reset(dwc_otg_core_if_t * _core_if);
  65060. +
  65061. +/**
  65062. + * This function returns the Core Interrupt register.
  65063. + */
  65064. +static inline uint32_t dwc_otg_read_core_intr(dwc_otg_core_if_t * core_if)
  65065. +{
  65066. + return (DWC_READ_REG32(&core_if->core_global_regs->gintsts) &
  65067. + DWC_READ_REG32(&core_if->core_global_regs->gintmsk));
  65068. +}
  65069. +
  65070. +/**
  65071. + * This function returns the OTG Interrupt register.
  65072. + */
  65073. +static inline uint32_t dwc_otg_read_otg_intr(dwc_otg_core_if_t * core_if)
  65074. +{
  65075. + return (DWC_READ_REG32(&core_if->core_global_regs->gotgint));
  65076. +}
  65077. +
  65078. +/**
  65079. + * This function reads the Device All Endpoints Interrupt register and
  65080. + * returns the IN endpoint interrupt bits.
  65081. + */
  65082. +static inline uint32_t dwc_otg_read_dev_all_in_ep_intr(dwc_otg_core_if_t *
  65083. + core_if)
  65084. +{
  65085. +
  65086. + uint32_t v;
  65087. +
  65088. + if (core_if->multiproc_int_enable) {
  65089. + v = DWC_READ_REG32(&core_if->dev_if->
  65090. + dev_global_regs->deachint) &
  65091. + DWC_READ_REG32(&core_if->
  65092. + dev_if->dev_global_regs->deachintmsk);
  65093. + } else {
  65094. + v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
  65095. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  65096. + }
  65097. + return (v & 0xffff);
  65098. +}
  65099. +
  65100. +/**
  65101. + * This function reads the Device All Endpoints Interrupt register and
  65102. + * returns the OUT endpoint interrupt bits.
  65103. + */
  65104. +static inline uint32_t dwc_otg_read_dev_all_out_ep_intr(dwc_otg_core_if_t *
  65105. + core_if)
  65106. +{
  65107. + uint32_t v;
  65108. +
  65109. + if (core_if->multiproc_int_enable) {
  65110. + v = DWC_READ_REG32(&core_if->dev_if->
  65111. + dev_global_regs->deachint) &
  65112. + DWC_READ_REG32(&core_if->
  65113. + dev_if->dev_global_regs->deachintmsk);
  65114. + } else {
  65115. + v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
  65116. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  65117. + }
  65118. +
  65119. + return ((v & 0xffff0000) >> 16);
  65120. +}
  65121. +
  65122. +/**
  65123. + * This function returns the Device IN EP Interrupt register
  65124. + */
  65125. +static inline uint32_t dwc_otg_read_dev_in_ep_intr(dwc_otg_core_if_t * core_if,
  65126. + dwc_ep_t * ep)
  65127. +{
  65128. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  65129. + uint32_t v, msk, emp;
  65130. +
  65131. + if (core_if->multiproc_int_enable) {
  65132. + msk =
  65133. + DWC_READ_REG32(&dev_if->
  65134. + dev_global_regs->diepeachintmsk[ep->num]);
  65135. + emp =
  65136. + DWC_READ_REG32(&dev_if->
  65137. + dev_global_regs->dtknqr4_fifoemptymsk);
  65138. + msk |= ((emp >> ep->num) & 0x1) << 7;
  65139. + v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
  65140. + } else {
  65141. + msk = DWC_READ_REG32(&dev_if->dev_global_regs->diepmsk);
  65142. + emp =
  65143. + DWC_READ_REG32(&dev_if->
  65144. + dev_global_regs->dtknqr4_fifoemptymsk);
  65145. + msk |= ((emp >> ep->num) & 0x1) << 7;
  65146. + v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
  65147. + }
  65148. +
  65149. + return v;
  65150. +}
  65151. +
  65152. +/**
  65153. + * This function returns the Device OUT EP Interrupt register
  65154. + */
  65155. +static inline uint32_t dwc_otg_read_dev_out_ep_intr(dwc_otg_core_if_t *
  65156. + _core_if, dwc_ep_t * _ep)
  65157. +{
  65158. + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
  65159. + uint32_t v;
  65160. + doepmsk_data_t msk = {.d32 = 0 };
  65161. +
  65162. + if (_core_if->multiproc_int_enable) {
  65163. + msk.d32 =
  65164. + DWC_READ_REG32(&dev_if->
  65165. + dev_global_regs->doepeachintmsk[_ep->num]);
  65166. + if (_core_if->pti_enh_enable) {
  65167. + msk.b.pktdrpsts = 1;
  65168. + }
  65169. + v = DWC_READ_REG32(&dev_if->
  65170. + out_ep_regs[_ep->num]->doepint) & msk.d32;
  65171. + } else {
  65172. + msk.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->doepmsk);
  65173. + if (_core_if->pti_enh_enable) {
  65174. + msk.b.pktdrpsts = 1;
  65175. + }
  65176. + v = DWC_READ_REG32(&dev_if->
  65177. + out_ep_regs[_ep->num]->doepint) & msk.d32;
  65178. + }
  65179. + return v;
  65180. +}
  65181. +
  65182. +/**
  65183. + * This function returns the Host All Channel Interrupt register
  65184. + */
  65185. +static inline uint32_t dwc_otg_read_host_all_channels_intr(dwc_otg_core_if_t *
  65186. + _core_if)
  65187. +{
  65188. + return (DWC_READ_REG32(&_core_if->host_if->host_global_regs->haint));
  65189. +}
  65190. +
  65191. +static inline uint32_t dwc_otg_read_host_channel_intr(dwc_otg_core_if_t *
  65192. + _core_if, dwc_hc_t * _hc)
  65193. +{
  65194. + return (DWC_READ_REG32
  65195. + (&_core_if->host_if->hc_regs[_hc->hc_num]->hcint));
  65196. +}
  65197. +
  65198. +/**
  65199. + * This function returns the mode of the operation, host or device.
  65200. + *
  65201. + * @return 0 - Device Mode, 1 - Host Mode
  65202. + */
  65203. +static inline uint32_t dwc_otg_mode(dwc_otg_core_if_t * _core_if)
  65204. +{
  65205. + return (DWC_READ_REG32(&_core_if->core_global_regs->gintsts) & 0x1);
  65206. +}
  65207. +
  65208. +/**@}*/
  65209. +
  65210. +/**
  65211. + * DWC_otg CIL callback structure. This structure allows the HCD and
  65212. + * PCD to register functions used for starting and stopping the PCD
  65213. + * and HCD for role change on for a DRD.
  65214. + */
  65215. +typedef struct dwc_otg_cil_callbacks {
  65216. + /** Start function for role change */
  65217. + int (*start) (void *_p);
  65218. + /** Stop Function for role change */
  65219. + int (*stop) (void *_p);
  65220. + /** Disconnect Function for role change */
  65221. + int (*disconnect) (void *_p);
  65222. + /** Resume/Remote wakeup Function */
  65223. + int (*resume_wakeup) (void *_p);
  65224. + /** Suspend function */
  65225. + int (*suspend) (void *_p);
  65226. + /** Session Start (SRP) */
  65227. + int (*session_start) (void *_p);
  65228. +#ifdef CONFIG_USB_DWC_OTG_LPM
  65229. + /** Sleep (switch to L0 state) */
  65230. + int (*sleep) (void *_p);
  65231. +#endif
  65232. + /** Pointer passed to start() and stop() */
  65233. + void *p;
  65234. +} dwc_otg_cil_callbacks_t;
  65235. +
  65236. +extern void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t * _core_if,
  65237. + dwc_otg_cil_callbacks_t * _cb,
  65238. + void *_p);
  65239. +extern void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t * _core_if,
  65240. + dwc_otg_cil_callbacks_t * _cb,
  65241. + void *_p);
  65242. +
  65243. +void dwc_otg_initiate_srp(dwc_otg_core_if_t * core_if);
  65244. +
  65245. +//////////////////////////////////////////////////////////////////////
  65246. +/** Start the HCD. Helper function for using the HCD callbacks.
  65247. + *
  65248. + * @param core_if Programming view of DWC_otg controller.
  65249. + */
  65250. +static inline void cil_hcd_start(dwc_otg_core_if_t * core_if)
  65251. +{
  65252. + if (core_if->hcd_cb && core_if->hcd_cb->start) {
  65253. + core_if->hcd_cb->start(core_if->hcd_cb->p);
  65254. + }
  65255. +}
  65256. +
  65257. +/** Stop the HCD. Helper function for using the HCD callbacks.
  65258. + *
  65259. + * @param core_if Programming view of DWC_otg controller.
  65260. + */
  65261. +static inline void cil_hcd_stop(dwc_otg_core_if_t * core_if)
  65262. +{
  65263. + if (core_if->hcd_cb && core_if->hcd_cb->stop) {
  65264. + core_if->hcd_cb->stop(core_if->hcd_cb->p);
  65265. + }
  65266. +}
  65267. +
  65268. +/** Disconnect the HCD. Helper function for using the HCD callbacks.
  65269. + *
  65270. + * @param core_if Programming view of DWC_otg controller.
  65271. + */
  65272. +static inline void cil_hcd_disconnect(dwc_otg_core_if_t * core_if)
  65273. +{
  65274. + if (core_if->hcd_cb && core_if->hcd_cb->disconnect) {
  65275. + core_if->hcd_cb->disconnect(core_if->hcd_cb->p);
  65276. + }
  65277. +}
  65278. +
  65279. +/** Inform the HCD the a New Session has begun. Helper function for
  65280. + * using the HCD callbacks.
  65281. + *
  65282. + * @param core_if Programming view of DWC_otg controller.
  65283. + */
  65284. +static inline void cil_hcd_session_start(dwc_otg_core_if_t * core_if)
  65285. +{
  65286. + if (core_if->hcd_cb && core_if->hcd_cb->session_start) {
  65287. + core_if->hcd_cb->session_start(core_if->hcd_cb->p);
  65288. + }
  65289. +}
  65290. +
  65291. +#ifdef CONFIG_USB_DWC_OTG_LPM
  65292. +/**
  65293. + * Inform the HCD about LPM sleep.
  65294. + * Helper function for using the HCD callbacks.
  65295. + *
  65296. + * @param core_if Programming view of DWC_otg controller.
  65297. + */
  65298. +static inline void cil_hcd_sleep(dwc_otg_core_if_t * core_if)
  65299. +{
  65300. + if (core_if->hcd_cb && core_if->hcd_cb->sleep) {
  65301. + core_if->hcd_cb->sleep(core_if->hcd_cb->p);
  65302. + }
  65303. +}
  65304. +#endif
  65305. +
  65306. +/** Resume the HCD. Helper function for using the HCD callbacks.
  65307. + *
  65308. + * @param core_if Programming view of DWC_otg controller.
  65309. + */
  65310. +static inline void cil_hcd_resume(dwc_otg_core_if_t * core_if)
  65311. +{
  65312. + if (core_if->hcd_cb && core_if->hcd_cb->resume_wakeup) {
  65313. + core_if->hcd_cb->resume_wakeup(core_if->hcd_cb->p);
  65314. + }
  65315. +}
  65316. +
  65317. +/** Start the PCD. Helper function for using the PCD callbacks.
  65318. + *
  65319. + * @param core_if Programming view of DWC_otg controller.
  65320. + */
  65321. +static inline void cil_pcd_start(dwc_otg_core_if_t * core_if)
  65322. +{
  65323. + if (core_if->pcd_cb && core_if->pcd_cb->start) {
  65324. + core_if->pcd_cb->start(core_if->pcd_cb->p);
  65325. + }
  65326. +}
  65327. +
  65328. +/** Stop the PCD. Helper function for using the PCD callbacks.
  65329. + *
  65330. + * @param core_if Programming view of DWC_otg controller.
  65331. + */
  65332. +static inline void cil_pcd_stop(dwc_otg_core_if_t * core_if)
  65333. +{
  65334. + if (core_if->pcd_cb && core_if->pcd_cb->stop) {
  65335. + core_if->pcd_cb->stop(core_if->pcd_cb->p);
  65336. + }
  65337. +}
  65338. +
  65339. +/** Suspend the PCD. Helper function for using the PCD callbacks.
  65340. + *
  65341. + * @param core_if Programming view of DWC_otg controller.
  65342. + */
  65343. +static inline void cil_pcd_suspend(dwc_otg_core_if_t * core_if)
  65344. +{
  65345. + if (core_if->pcd_cb && core_if->pcd_cb->suspend) {
  65346. + core_if->pcd_cb->suspend(core_if->pcd_cb->p);
  65347. + }
  65348. +}
  65349. +
  65350. +/** Resume the PCD. Helper function for using the PCD callbacks.
  65351. + *
  65352. + * @param core_if Programming view of DWC_otg controller.
  65353. + */
  65354. +static inline void cil_pcd_resume(dwc_otg_core_if_t * core_if)
  65355. +{
  65356. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  65357. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  65358. + }
  65359. +}
  65360. +
  65361. +//////////////////////////////////////////////////////////////////////
  65362. +
  65363. +#endif
  65364. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c
  65365. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c 1970-01-01 01:00:00.000000000 +0100
  65366. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c 2014-07-07 10:45:43.000000000 +0200
  65367. @@ -0,0 +1,1594 @@
  65368. +/* ==========================================================================
  65369. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil_intr.c $
  65370. + * $Revision: #32 $
  65371. + * $Date: 2012/08/10 $
  65372. + * $Change: 2047372 $
  65373. + *
  65374. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  65375. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  65376. + * otherwise expressly agreed to in writing between Synopsys and you.
  65377. + *
  65378. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  65379. + * any End User Software License Agreement or Agreement for Licensed Product
  65380. + * with Synopsys or any supplement thereto. You are permitted to use and
  65381. + * redistribute this Software in source and binary forms, with or without
  65382. + * modification, provided that redistributions of source code must retain this
  65383. + * notice. You may not view, use, disclose, copy or distribute this file or
  65384. + * any information contained herein except pursuant to this license grant from
  65385. + * Synopsys. If you do not agree with this notice, including the disclaimer
  65386. + * below, then you are not authorized to use the Software.
  65387. + *
  65388. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  65389. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  65390. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  65391. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  65392. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  65393. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  65394. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  65395. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  65396. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  65397. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  65398. + * DAMAGE.
  65399. + * ========================================================================== */
  65400. +
  65401. +/** @file
  65402. + *
  65403. + * The Core Interface Layer provides basic services for accessing and
  65404. + * managing the DWC_otg hardware. These services are used by both the
  65405. + * Host Controller Driver and the Peripheral Controller Driver.
  65406. + *
  65407. + * This file contains the Common Interrupt handlers.
  65408. + */
  65409. +#include "dwc_os.h"
  65410. +#include "dwc_otg_regs.h"
  65411. +#include "dwc_otg_cil.h"
  65412. +#include "dwc_otg_driver.h"
  65413. +#include "dwc_otg_pcd.h"
  65414. +#include "dwc_otg_hcd.h"
  65415. +
  65416. +#ifdef DEBUG
  65417. +inline const char *op_state_str(dwc_otg_core_if_t * core_if)
  65418. +{
  65419. + return (core_if->op_state == A_HOST ? "a_host" :
  65420. + (core_if->op_state == A_SUSPEND ? "a_suspend" :
  65421. + (core_if->op_state == A_PERIPHERAL ? "a_peripheral" :
  65422. + (core_if->op_state == B_PERIPHERAL ? "b_peripheral" :
  65423. + (core_if->op_state == B_HOST ? "b_host" : "unknown")))));
  65424. +}
  65425. +#endif
  65426. +
  65427. +/** This function will log a debug message
  65428. + *
  65429. + * @param core_if Programming view of DWC_otg controller.
  65430. + */
  65431. +int32_t dwc_otg_handle_mode_mismatch_intr(dwc_otg_core_if_t * core_if)
  65432. +{
  65433. + gintsts_data_t gintsts;
  65434. + DWC_WARN("Mode Mismatch Interrupt: currently in %s mode\n",
  65435. + dwc_otg_mode(core_if) ? "Host" : "Device");
  65436. +
  65437. + /* Clear interrupt */
  65438. + gintsts.d32 = 0;
  65439. + gintsts.b.modemismatch = 1;
  65440. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  65441. + return 1;
  65442. +}
  65443. +
  65444. +/**
  65445. + * This function handles the OTG Interrupts. It reads the OTG
  65446. + * Interrupt Register (GOTGINT) to determine what interrupt has
  65447. + * occurred.
  65448. + *
  65449. + * @param core_if Programming view of DWC_otg controller.
  65450. + */
  65451. +int32_t dwc_otg_handle_otg_intr(dwc_otg_core_if_t * core_if)
  65452. +{
  65453. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  65454. + gotgint_data_t gotgint;
  65455. + gotgctl_data_t gotgctl;
  65456. + gintmsk_data_t gintmsk;
  65457. + gpwrdn_data_t gpwrdn;
  65458. +
  65459. + gotgint.d32 = DWC_READ_REG32(&global_regs->gotgint);
  65460. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  65461. + DWC_DEBUGPL(DBG_CIL, "++OTG Interrupt gotgint=%0x [%s]\n", gotgint.d32,
  65462. + op_state_str(core_if));
  65463. +
  65464. + if (gotgint.b.sesenddet) {
  65465. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  65466. + "Session End Detected++ (%s)\n",
  65467. + op_state_str(core_if));
  65468. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  65469. +
  65470. + if (core_if->op_state == B_HOST) {
  65471. + cil_pcd_start(core_if);
  65472. + core_if->op_state = B_PERIPHERAL;
  65473. + } else {
  65474. + /* If not B_HOST and Device HNP still set. HNP
  65475. + * Did not succeed!*/
  65476. + if (gotgctl.b.devhnpen) {
  65477. + DWC_DEBUGPL(DBG_ANY, "Session End Detected\n");
  65478. + __DWC_ERROR("Device Not Connected/Responding!\n");
  65479. + }
  65480. +
  65481. + /* If Session End Detected the B-Cable has
  65482. + * been disconnected. */
  65483. + /* Reset PCD and Gadget driver to a
  65484. + * clean state. */
  65485. + core_if->lx_state = DWC_OTG_L0;
  65486. + DWC_SPINUNLOCK(core_if->lock);
  65487. + cil_pcd_stop(core_if);
  65488. + DWC_SPINLOCK(core_if->lock);
  65489. +
  65490. + if (core_if->adp_enable) {
  65491. + if (core_if->power_down == 2) {
  65492. + gpwrdn.d32 = 0;
  65493. + gpwrdn.b.pwrdnswtch = 1;
  65494. + DWC_MODIFY_REG32(&core_if->
  65495. + core_global_regs->
  65496. + gpwrdn, gpwrdn.d32, 0);
  65497. + }
  65498. +
  65499. + gpwrdn.d32 = 0;
  65500. + gpwrdn.b.pmuintsel = 1;
  65501. + gpwrdn.b.pmuactv = 1;
  65502. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  65503. + gpwrdn, 0, gpwrdn.d32);
  65504. +
  65505. + dwc_otg_adp_sense_start(core_if);
  65506. + }
  65507. + }
  65508. +
  65509. + gotgctl.d32 = 0;
  65510. + gotgctl.b.devhnpen = 1;
  65511. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  65512. + }
  65513. + if (gotgint.b.sesreqsucstschng) {
  65514. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  65515. + "Session Reqeust Success Status Change++\n");
  65516. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  65517. + if (gotgctl.b.sesreqscs) {
  65518. +
  65519. + if ((core_if->core_params->phy_type ==
  65520. + DWC_PHY_TYPE_PARAM_FS) && (core_if->core_params->i2c_enable)) {
  65521. + core_if->srp_success = 1;
  65522. + } else {
  65523. + DWC_SPINUNLOCK(core_if->lock);
  65524. + cil_pcd_resume(core_if);
  65525. + DWC_SPINLOCK(core_if->lock);
  65526. + /* Clear Session Request */
  65527. + gotgctl.d32 = 0;
  65528. + gotgctl.b.sesreq = 1;
  65529. + DWC_MODIFY_REG32(&global_regs->gotgctl,
  65530. + gotgctl.d32, 0);
  65531. + }
  65532. + }
  65533. + }
  65534. + if (gotgint.b.hstnegsucstschng) {
  65535. + /* Print statements during the HNP interrupt handling
  65536. + * can cause it to fail.*/
  65537. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  65538. + /* WA for 3.00a- HW is not setting cur_mode, even sometimes
  65539. + * this does not help*/
  65540. + if (core_if->snpsid >= OTG_CORE_REV_3_00a)
  65541. + dwc_udelay(100);
  65542. + if (gotgctl.b.hstnegscs) {
  65543. + if (dwc_otg_is_host_mode(core_if)) {
  65544. + core_if->op_state = B_HOST;
  65545. + /*
  65546. + * Need to disable SOF interrupt immediately.
  65547. + * When switching from device to host, the PCD
  65548. + * interrupt handler won't handle the
  65549. + * interrupt if host mode is already set. The
  65550. + * HCD interrupt handler won't get called if
  65551. + * the HCD state is HALT. This means that the
  65552. + * interrupt does not get handled and Linux
  65553. + * complains loudly.
  65554. + */
  65555. + gintmsk.d32 = 0;
  65556. + gintmsk.b.sofintr = 1;
  65557. + DWC_MODIFY_REG32(&global_regs->gintmsk,
  65558. + gintmsk.d32, 0);
  65559. + /* Call callback function with spin lock released */
  65560. + DWC_SPINUNLOCK(core_if->lock);
  65561. + cil_pcd_stop(core_if);
  65562. + /*
  65563. + * Initialize the Core for Host mode.
  65564. + */
  65565. + cil_hcd_start(core_if);
  65566. + DWC_SPINLOCK(core_if->lock);
  65567. + core_if->op_state = B_HOST;
  65568. + }
  65569. + } else {
  65570. + gotgctl.d32 = 0;
  65571. + gotgctl.b.hnpreq = 1;
  65572. + gotgctl.b.devhnpen = 1;
  65573. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  65574. + DWC_DEBUGPL(DBG_ANY, "HNP Failed\n");
  65575. + __DWC_ERROR("Device Not Connected/Responding\n");
  65576. + }
  65577. + }
  65578. + if (gotgint.b.hstnegdet) {
  65579. + /* The disconnect interrupt is set at the same time as
  65580. + * Host Negotiation Detected. During the mode
  65581. + * switch all interrupts are cleared so the disconnect
  65582. + * interrupt handler will not get executed.
  65583. + */
  65584. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  65585. + "Host Negotiation Detected++ (%s)\n",
  65586. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  65587. + "Device"));
  65588. + if (dwc_otg_is_device_mode(core_if)) {
  65589. + DWC_DEBUGPL(DBG_ANY, "a_suspend->a_peripheral (%d)\n",
  65590. + core_if->op_state);
  65591. + DWC_SPINUNLOCK(core_if->lock);
  65592. + cil_hcd_disconnect(core_if);
  65593. + cil_pcd_start(core_if);
  65594. + DWC_SPINLOCK(core_if->lock);
  65595. + core_if->op_state = A_PERIPHERAL;
  65596. + } else {
  65597. + /*
  65598. + * Need to disable SOF interrupt immediately. When
  65599. + * switching from device to host, the PCD interrupt
  65600. + * handler won't handle the interrupt if host mode is
  65601. + * already set. The HCD interrupt handler won't get
  65602. + * called if the HCD state is HALT. This means that
  65603. + * the interrupt does not get handled and Linux
  65604. + * complains loudly.
  65605. + */
  65606. + gintmsk.d32 = 0;
  65607. + gintmsk.b.sofintr = 1;
  65608. + DWC_MODIFY_REG32(&global_regs->gintmsk, gintmsk.d32, 0);
  65609. + DWC_SPINUNLOCK(core_if->lock);
  65610. + cil_pcd_stop(core_if);
  65611. + cil_hcd_start(core_if);
  65612. + DWC_SPINLOCK(core_if->lock);
  65613. + core_if->op_state = A_HOST;
  65614. + }
  65615. + }
  65616. + if (gotgint.b.adevtoutchng) {
  65617. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  65618. + "A-Device Timeout Change++\n");
  65619. + }
  65620. + if (gotgint.b.debdone) {
  65621. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: " "Debounce Done++\n");
  65622. + }
  65623. +
  65624. + /* Clear GOTGINT */
  65625. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgint, gotgint.d32);
  65626. +
  65627. + return 1;
  65628. +}
  65629. +
  65630. +void w_conn_id_status_change(void *p)
  65631. +{
  65632. + dwc_otg_core_if_t *core_if = p;
  65633. + uint32_t count = 0;
  65634. + gotgctl_data_t gotgctl = {.d32 = 0 };
  65635. +
  65636. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  65637. + DWC_DEBUGPL(DBG_CIL, "gotgctl=%0x\n", gotgctl.d32);
  65638. + DWC_DEBUGPL(DBG_CIL, "gotgctl.b.conidsts=%d\n", gotgctl.b.conidsts);
  65639. +
  65640. + /* B-Device connector (Device Mode) */
  65641. + if (gotgctl.b.conidsts) {
  65642. + /* Wait for switch to device mode. */
  65643. + while (!dwc_otg_is_device_mode(core_if)) {
  65644. + DWC_PRINTF("Waiting for Peripheral Mode, Mode=%s\n",
  65645. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  65646. + "Peripheral"));
  65647. + dwc_mdelay(100);
  65648. + if (++count > 10000)
  65649. + break;
  65650. + }
  65651. + DWC_ASSERT(++count < 10000,
  65652. + "Connection id status change timed out");
  65653. + core_if->op_state = B_PERIPHERAL;
  65654. + dwc_otg_core_init(core_if);
  65655. + dwc_otg_enable_global_interrupts(core_if);
  65656. + cil_pcd_start(core_if);
  65657. + } else {
  65658. + /* A-Device connector (Host Mode) */
  65659. + while (!dwc_otg_is_host_mode(core_if)) {
  65660. + DWC_PRINTF("Waiting for Host Mode, Mode=%s\n",
  65661. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  65662. + "Peripheral"));
  65663. + dwc_mdelay(100);
  65664. + if (++count > 10000)
  65665. + break;
  65666. + }
  65667. + DWC_ASSERT(++count < 10000,
  65668. + "Connection id status change timed out");
  65669. + core_if->op_state = A_HOST;
  65670. + /*
  65671. + * Initialize the Core for Host mode.
  65672. + */
  65673. + dwc_otg_core_init(core_if);
  65674. + dwc_otg_enable_global_interrupts(core_if);
  65675. + cil_hcd_start(core_if);
  65676. + }
  65677. +}
  65678. +
  65679. +/**
  65680. + * This function handles the Connector ID Status Change Interrupt. It
  65681. + * reads the OTG Interrupt Register (GOTCTL) to determine whether this
  65682. + * is a Device to Host Mode transition or a Host Mode to Device
  65683. + * Transition.
  65684. + *
  65685. + * This only occurs when the cable is connected/removed from the PHY
  65686. + * connector.
  65687. + *
  65688. + * @param core_if Programming view of DWC_otg controller.
  65689. + */
  65690. +int32_t dwc_otg_handle_conn_id_status_change_intr(dwc_otg_core_if_t * core_if)
  65691. +{
  65692. +
  65693. + /*
  65694. + * Need to disable SOF interrupt immediately. If switching from device
  65695. + * to host, the PCD interrupt handler won't handle the interrupt if
  65696. + * host mode is already set. The HCD interrupt handler won't get
  65697. + * called if the HCD state is HALT. This means that the interrupt does
  65698. + * not get handled and Linux complains loudly.
  65699. + */
  65700. + gintmsk_data_t gintmsk = {.d32 = 0 };
  65701. + gintsts_data_t gintsts = {.d32 = 0 };
  65702. +
  65703. + gintmsk.b.sofintr = 1;
  65704. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
  65705. +
  65706. + DWC_DEBUGPL(DBG_CIL,
  65707. + " ++Connector ID Status Change Interrupt++ (%s)\n",
  65708. + (dwc_otg_is_host_mode(core_if) ? "Host" : "Device"));
  65709. +
  65710. + DWC_SPINUNLOCK(core_if->lock);
  65711. +
  65712. + /*
  65713. + * Need to schedule a work, as there are possible DELAY function calls
  65714. + * Release lock before scheduling workq as it holds spinlock during scheduling
  65715. + */
  65716. +
  65717. + DWC_WORKQ_SCHEDULE(core_if->wq_otg, w_conn_id_status_change,
  65718. + core_if, "connection id status change");
  65719. + DWC_SPINLOCK(core_if->lock);
  65720. +
  65721. + /* Set flag and clear interrupt */
  65722. + gintsts.b.conidstschng = 1;
  65723. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  65724. +
  65725. + return 1;
  65726. +}
  65727. +
  65728. +/**
  65729. + * This interrupt indicates that a device is initiating the Session
  65730. + * Request Protocol to request the host to turn on bus power so a new
  65731. + * session can begin. The handler responds by turning on bus power. If
  65732. + * the DWC_otg controller is in low power mode, the handler brings the
  65733. + * controller out of low power mode before turning on bus power.
  65734. + *
  65735. + * @param core_if Programming view of DWC_otg controller.
  65736. + */
  65737. +int32_t dwc_otg_handle_session_req_intr(dwc_otg_core_if_t * core_if)
  65738. +{
  65739. + gintsts_data_t gintsts;
  65740. +
  65741. +#ifndef DWC_HOST_ONLY
  65742. + DWC_DEBUGPL(DBG_ANY, "++Session Request Interrupt++\n");
  65743. +
  65744. + if (dwc_otg_is_device_mode(core_if)) {
  65745. + DWC_PRINTF("SRP: Device mode\n");
  65746. + } else {
  65747. + hprt0_data_t hprt0;
  65748. + DWC_PRINTF("SRP: Host mode\n");
  65749. +
  65750. + /* Turn on the port power bit. */
  65751. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  65752. + hprt0.b.prtpwr = 1;
  65753. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  65754. +
  65755. + /* Start the Connection timer. So a message can be displayed
  65756. + * if connect does not occur within 10 seconds. */
  65757. + cil_hcd_session_start(core_if);
  65758. + }
  65759. +#endif
  65760. +
  65761. + /* Clear interrupt */
  65762. + gintsts.d32 = 0;
  65763. + gintsts.b.sessreqintr = 1;
  65764. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  65765. +
  65766. + return 1;
  65767. +}
  65768. +
  65769. +void w_wakeup_detected(void *p)
  65770. +{
  65771. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) p;
  65772. + /*
  65773. + * Clear the Resume after 70ms. (Need 20 ms minimum. Use 70 ms
  65774. + * so that OPT tests pass with all PHYs).
  65775. + */
  65776. + hprt0_data_t hprt0 = {.d32 = 0 };
  65777. +#if 0
  65778. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  65779. + /* Restart the Phy Clock */
  65780. + pcgcctl.b.stoppclk = 1;
  65781. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  65782. + dwc_udelay(10);
  65783. +#endif //0
  65784. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  65785. + DWC_DEBUGPL(DBG_ANY, "Resume: HPRT0=%0x\n", hprt0.d32);
  65786. +// dwc_mdelay(70);
  65787. + hprt0.b.prtres = 0; /* Resume */
  65788. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  65789. + DWC_DEBUGPL(DBG_ANY, "Clear Resume: HPRT0=%0x\n",
  65790. + DWC_READ_REG32(core_if->host_if->hprt0));
  65791. +
  65792. + cil_hcd_resume(core_if);
  65793. +
  65794. + /** Change to L0 state*/
  65795. + core_if->lx_state = DWC_OTG_L0;
  65796. +}
  65797. +
  65798. +/**
  65799. + * This interrupt indicates that the DWC_otg controller has detected a
  65800. + * resume or remote wakeup sequence. If the DWC_otg controller is in
  65801. + * low power mode, the handler must brings the controller out of low
  65802. + * power mode. The controller automatically begins resume
  65803. + * signaling. The handler schedules a time to stop resume signaling.
  65804. + */
  65805. +int32_t dwc_otg_handle_wakeup_detected_intr(dwc_otg_core_if_t * core_if)
  65806. +{
  65807. + gintsts_data_t gintsts;
  65808. +
  65809. + DWC_DEBUGPL(DBG_ANY,
  65810. + "++Resume and Remote Wakeup Detected Interrupt++\n");
  65811. +
  65812. + DWC_PRINTF("%s lxstate = %d\n", __func__, core_if->lx_state);
  65813. +
  65814. + if (dwc_otg_is_device_mode(core_if)) {
  65815. + dctl_data_t dctl = {.d32 = 0 };
  65816. + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n",
  65817. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->
  65818. + dsts));
  65819. + if (core_if->lx_state == DWC_OTG_L2) {
  65820. +#ifdef PARTIAL_POWER_DOWN
  65821. + if (core_if->hwcfg4.b.power_optimiz) {
  65822. + pcgcctl_data_t power = {.d32 = 0 };
  65823. +
  65824. + power.d32 = DWC_READ_REG32(core_if->pcgcctl);
  65825. + DWC_DEBUGPL(DBG_CIL, "PCGCCTL=%0x\n",
  65826. + power.d32);
  65827. +
  65828. + power.b.stoppclk = 0;
  65829. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  65830. +
  65831. + power.b.pwrclmp = 0;
  65832. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  65833. +
  65834. + power.b.rstpdwnmodule = 0;
  65835. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  65836. + }
  65837. +#endif
  65838. + /* Clear the Remote Wakeup Signaling */
  65839. + dctl.b.rmtwkupsig = 1;
  65840. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  65841. + dctl, dctl.d32, 0);
  65842. +
  65843. + DWC_SPINUNLOCK(core_if->lock);
  65844. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  65845. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  65846. + }
  65847. + DWC_SPINLOCK(core_if->lock);
  65848. + } else {
  65849. + glpmcfg_data_t lpmcfg;
  65850. + lpmcfg.d32 =
  65851. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  65852. + lpmcfg.b.hird_thres &= (~(1 << 4));
  65853. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg,
  65854. + lpmcfg.d32);
  65855. + }
  65856. + /** Change to L0 state*/
  65857. + core_if->lx_state = DWC_OTG_L0;
  65858. + } else {
  65859. + if (core_if->lx_state != DWC_OTG_L1) {
  65860. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  65861. +
  65862. + /* Restart the Phy Clock */
  65863. + pcgcctl.b.stoppclk = 1;
  65864. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  65865. + DWC_TIMER_SCHEDULE(core_if->wkp_timer, 71);
  65866. + } else {
  65867. + /** Change to L0 state*/
  65868. + core_if->lx_state = DWC_OTG_L0;
  65869. + }
  65870. + }
  65871. +
  65872. + /* Clear interrupt */
  65873. + gintsts.d32 = 0;
  65874. + gintsts.b.wkupintr = 1;
  65875. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  65876. +
  65877. + return 1;
  65878. +}
  65879. +
  65880. +/**
  65881. + * This interrupt indicates that the Wakeup Logic has detected a
  65882. + * Device disconnect.
  65883. + */
  65884. +static int32_t dwc_otg_handle_pwrdn_disconnect_intr(dwc_otg_core_if_t *core_if)
  65885. +{
  65886. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  65887. + gpwrdn_data_t gpwrdn_temp = { .d32 = 0 };
  65888. + gpwrdn_temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65889. +
  65890. + DWC_PRINTF("%s called\n", __FUNCTION__);
  65891. +
  65892. + if (!core_if->hibernation_suspend) {
  65893. + DWC_PRINTF("Already exited from Hibernation\n");
  65894. + return 1;
  65895. + }
  65896. +
  65897. + /* Switch on the voltage to the core */
  65898. + gpwrdn.b.pwrdnswtch = 1;
  65899. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65900. + dwc_udelay(10);
  65901. +
  65902. + /* Reset the core */
  65903. + gpwrdn.d32 = 0;
  65904. + gpwrdn.b.pwrdnrstn = 1;
  65905. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65906. + dwc_udelay(10);
  65907. +
  65908. + /* Disable power clamps*/
  65909. + gpwrdn.d32 = 0;
  65910. + gpwrdn.b.pwrdnclmp = 1;
  65911. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65912. +
  65913. + /* Remove reset the core signal */
  65914. + gpwrdn.d32 = 0;
  65915. + gpwrdn.b.pwrdnrstn = 1;
  65916. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  65917. + dwc_udelay(10);
  65918. +
  65919. + /* Disable PMU interrupt */
  65920. + gpwrdn.d32 = 0;
  65921. + gpwrdn.b.pmuintsel = 1;
  65922. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65923. +
  65924. + core_if->hibernation_suspend = 0;
  65925. +
  65926. + /* Disable PMU */
  65927. + gpwrdn.d32 = 0;
  65928. + gpwrdn.b.pmuactv = 1;
  65929. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65930. + dwc_udelay(10);
  65931. +
  65932. + if (gpwrdn_temp.b.idsts) {
  65933. + core_if->op_state = B_PERIPHERAL;
  65934. + dwc_otg_core_init(core_if);
  65935. + dwc_otg_enable_global_interrupts(core_if);
  65936. + cil_pcd_start(core_if);
  65937. + } else {
  65938. + core_if->op_state = A_HOST;
  65939. + dwc_otg_core_init(core_if);
  65940. + dwc_otg_enable_global_interrupts(core_if);
  65941. + cil_hcd_start(core_if);
  65942. + }
  65943. +
  65944. + return 1;
  65945. +}
  65946. +
  65947. +/**
  65948. + * This interrupt indicates that the Wakeup Logic has detected a
  65949. + * remote wakeup sequence.
  65950. + */
  65951. +static int32_t dwc_otg_handle_pwrdn_wakeup_detected_intr(dwc_otg_core_if_t * core_if)
  65952. +{
  65953. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65954. + DWC_DEBUGPL(DBG_ANY,
  65955. + "++Powerdown Remote Wakeup Detected Interrupt++\n");
  65956. +
  65957. + if (!core_if->hibernation_suspend) {
  65958. + DWC_PRINTF("Already exited from Hibernation\n");
  65959. + return 1;
  65960. + }
  65961. +
  65962. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65963. + if (gpwrdn.b.idsts) { // Device Mode
  65964. + if ((core_if->power_down == 2)
  65965. + && (core_if->hibernation_suspend == 1)) {
  65966. + dwc_otg_device_hibernation_restore(core_if, 0, 0);
  65967. + }
  65968. + } else {
  65969. + if ((core_if->power_down == 2)
  65970. + && (core_if->hibernation_suspend == 1)) {
  65971. + dwc_otg_host_hibernation_restore(core_if, 1, 0);
  65972. + }
  65973. + }
  65974. + return 1;
  65975. +}
  65976. +
  65977. +static int32_t dwc_otg_handle_pwrdn_idsts_change(dwc_otg_device_t *otg_dev)
  65978. +{
  65979. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65980. + gpwrdn_data_t gpwrdn_temp = {.d32 = 0 };
  65981. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  65982. +
  65983. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  65984. + gpwrdn_temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65985. + if (core_if->power_down == 2) {
  65986. + if (!core_if->hibernation_suspend) {
  65987. + DWC_PRINTF("Already exited from Hibernation\n");
  65988. + return 1;
  65989. + }
  65990. + DWC_DEBUGPL(DBG_ANY, "Exit from hibernation on ID sts change\n");
  65991. + /* Switch on the voltage to the core */
  65992. + gpwrdn.b.pwrdnswtch = 1;
  65993. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65994. + dwc_udelay(10);
  65995. +
  65996. + /* Reset the core */
  65997. + gpwrdn.d32 = 0;
  65998. + gpwrdn.b.pwrdnrstn = 1;
  65999. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  66000. + dwc_udelay(10);
  66001. +
  66002. + /* Disable power clamps */
  66003. + gpwrdn.d32 = 0;
  66004. + gpwrdn.b.pwrdnclmp = 1;
  66005. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  66006. +
  66007. + /* Remove reset the core signal */
  66008. + gpwrdn.d32 = 0;
  66009. + gpwrdn.b.pwrdnrstn = 1;
  66010. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  66011. + dwc_udelay(10);
  66012. +
  66013. + /* Disable PMU interrupt */
  66014. + gpwrdn.d32 = 0;
  66015. + gpwrdn.b.pmuintsel = 1;
  66016. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  66017. +
  66018. + /*Indicates that we are exiting from hibernation */
  66019. + core_if->hibernation_suspend = 0;
  66020. +
  66021. + /* Disable PMU */
  66022. + gpwrdn.d32 = 0;
  66023. + gpwrdn.b.pmuactv = 1;
  66024. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  66025. + dwc_udelay(10);
  66026. +
  66027. + gpwrdn.d32 = core_if->gr_backup->gpwrdn_local;
  66028. + if (gpwrdn.b.dis_vbus == 1) {
  66029. + gpwrdn.d32 = 0;
  66030. + gpwrdn.b.dis_vbus = 1;
  66031. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  66032. + }
  66033. +
  66034. + if (gpwrdn_temp.b.idsts) {
  66035. + core_if->op_state = B_PERIPHERAL;
  66036. + dwc_otg_core_init(core_if);
  66037. + dwc_otg_enable_global_interrupts(core_if);
  66038. + cil_pcd_start(core_if);
  66039. + } else {
  66040. + core_if->op_state = A_HOST;
  66041. + dwc_otg_core_init(core_if);
  66042. + dwc_otg_enable_global_interrupts(core_if);
  66043. + cil_hcd_start(core_if);
  66044. + }
  66045. + }
  66046. +
  66047. + if (core_if->adp_enable) {
  66048. + uint8_t is_host = 0;
  66049. + DWC_SPINUNLOCK(core_if->lock);
  66050. + /* Change the core_if's lock to hcd/pcd lock depend on mode? */
  66051. +#ifndef DWC_HOST_ONLY
  66052. + if (gpwrdn_temp.b.idsts)
  66053. + core_if->lock = otg_dev->pcd->lock;
  66054. +#endif
  66055. +#ifndef DWC_DEVICE_ONLY
  66056. + if (!gpwrdn_temp.b.idsts) {
  66057. + core_if->lock = otg_dev->hcd->lock;
  66058. + is_host = 1;
  66059. + }
  66060. +#endif
  66061. + DWC_PRINTF("RESTART ADP\n");
  66062. + if (core_if->adp.probe_enabled)
  66063. + dwc_otg_adp_probe_stop(core_if);
  66064. + if (core_if->adp.sense_enabled)
  66065. + dwc_otg_adp_sense_stop(core_if);
  66066. + if (core_if->adp.sense_timer_started)
  66067. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  66068. + if (core_if->adp.vbuson_timer_started)
  66069. + DWC_TIMER_CANCEL(core_if->adp.vbuson_timer);
  66070. + core_if->adp.probe_timer_values[0] = -1;
  66071. + core_if->adp.probe_timer_values[1] = -1;
  66072. + core_if->adp.sense_timer_started = 0;
  66073. + core_if->adp.vbuson_timer_started = 0;
  66074. + core_if->adp.probe_counter = 0;
  66075. + core_if->adp.gpwrdn = 0;
  66076. +
  66077. + /* Disable PMU and restart ADP */
  66078. + gpwrdn_temp.d32 = 0;
  66079. + gpwrdn_temp.b.pmuactv = 1;
  66080. + gpwrdn_temp.b.pmuintsel = 1;
  66081. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  66082. + DWC_PRINTF("Check point 1\n");
  66083. + dwc_mdelay(110);
  66084. + dwc_otg_adp_start(core_if, is_host);
  66085. + DWC_SPINLOCK(core_if->lock);
  66086. + }
  66087. +
  66088. +
  66089. + return 1;
  66090. +}
  66091. +
  66092. +static int32_t dwc_otg_handle_pwrdn_session_change(dwc_otg_core_if_t * core_if)
  66093. +{
  66094. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  66095. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  66096. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  66097. +
  66098. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  66099. + if (core_if->power_down == 2) {
  66100. + if (!core_if->hibernation_suspend) {
  66101. + DWC_PRINTF("Already exited from Hibernation\n");
  66102. + return 1;
  66103. + }
  66104. +
  66105. + if ((otg_cap_param != DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE ||
  66106. + otg_cap_param != DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE) &&
  66107. + gpwrdn.b.bsessvld == 0) {
  66108. + /* Save gpwrdn register for further usage if stschng interrupt */
  66109. + core_if->gr_backup->gpwrdn_local =
  66110. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  66111. + /*Exit from ISR and wait for stschng interrupt with bsessvld = 1 */
  66112. + return 1;
  66113. + }
  66114. +
  66115. + /* Switch on the voltage to the core */
  66116. + gpwrdn.d32 = 0;
  66117. + gpwrdn.b.pwrdnswtch = 1;
  66118. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  66119. + dwc_udelay(10);
  66120. +
  66121. + /* Reset the core */
  66122. + gpwrdn.d32 = 0;
  66123. + gpwrdn.b.pwrdnrstn = 1;
  66124. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  66125. + dwc_udelay(10);
  66126. +
  66127. + /* Disable power clamps */
  66128. + gpwrdn.d32 = 0;
  66129. + gpwrdn.b.pwrdnclmp = 1;
  66130. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  66131. +
  66132. + /* Remove reset the core signal */
  66133. + gpwrdn.d32 = 0;
  66134. + gpwrdn.b.pwrdnrstn = 1;
  66135. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  66136. + dwc_udelay(10);
  66137. +
  66138. + /* Disable PMU interrupt */
  66139. + gpwrdn.d32 = 0;
  66140. + gpwrdn.b.pmuintsel = 1;
  66141. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  66142. + dwc_udelay(10);
  66143. +
  66144. + /*Indicates that we are exiting from hibernation */
  66145. + core_if->hibernation_suspend = 0;
  66146. +
  66147. + /* Disable PMU */
  66148. + gpwrdn.d32 = 0;
  66149. + gpwrdn.b.pmuactv = 1;
  66150. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  66151. + dwc_udelay(10);
  66152. +
  66153. + core_if->op_state = B_PERIPHERAL;
  66154. + dwc_otg_core_init(core_if);
  66155. + dwc_otg_enable_global_interrupts(core_if);
  66156. + cil_pcd_start(core_if);
  66157. +
  66158. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE ||
  66159. + otg_cap_param == DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE) {
  66160. + /*
  66161. + * Initiate SRP after initial ADP probe.
  66162. + */
  66163. + dwc_otg_initiate_srp(core_if);
  66164. + }
  66165. + }
  66166. +
  66167. + return 1;
  66168. +}
  66169. +/**
  66170. + * This interrupt indicates that the Wakeup Logic has detected a
  66171. + * status change either on IDDIG or BSessVld.
  66172. + */
  66173. +static uint32_t dwc_otg_handle_pwrdn_stschng_intr(dwc_otg_device_t *otg_dev)
  66174. +{
  66175. + int retval;
  66176. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  66177. + gpwrdn_data_t gpwrdn_temp = {.d32 = 0 };
  66178. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  66179. +
  66180. + DWC_PRINTF("%s called\n", __FUNCTION__);
  66181. +
  66182. + if (core_if->power_down == 2) {
  66183. + if (core_if->hibernation_suspend <= 0) {
  66184. + DWC_PRINTF("Already exited from Hibernation\n");
  66185. + return 1;
  66186. + } else
  66187. + gpwrdn_temp.d32 = core_if->gr_backup->gpwrdn_local;
  66188. +
  66189. + } else {
  66190. + gpwrdn_temp.d32 = core_if->adp.gpwrdn;
  66191. + }
  66192. +
  66193. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  66194. +
  66195. + if (gpwrdn.b.idsts ^ gpwrdn_temp.b.idsts) {
  66196. + retval = dwc_otg_handle_pwrdn_idsts_change(otg_dev);
  66197. + } else if (gpwrdn.b.bsessvld ^ gpwrdn_temp.b.bsessvld) {
  66198. + retval = dwc_otg_handle_pwrdn_session_change(core_if);
  66199. + }
  66200. +
  66201. + return retval;
  66202. +}
  66203. +
  66204. +/**
  66205. + * This interrupt indicates that the Wakeup Logic has detected a
  66206. + * SRP.
  66207. + */
  66208. +static int32_t dwc_otg_handle_pwrdn_srp_intr(dwc_otg_core_if_t * core_if)
  66209. +{
  66210. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  66211. +
  66212. + DWC_PRINTF("%s called\n", __FUNCTION__);
  66213. +
  66214. + if (!core_if->hibernation_suspend) {
  66215. + DWC_PRINTF("Already exited from Hibernation\n");
  66216. + return 1;
  66217. + }
  66218. +#ifdef DWC_DEV_SRPCAP
  66219. + if (core_if->pwron_timer_started) {
  66220. + core_if->pwron_timer_started = 0;
  66221. + DWC_TIMER_CANCEL(core_if->pwron_timer);
  66222. + }
  66223. +#endif
  66224. +
  66225. + /* Switch on the voltage to the core */
  66226. + gpwrdn.b.pwrdnswtch = 1;
  66227. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  66228. + dwc_udelay(10);
  66229. +
  66230. + /* Reset the core */
  66231. + gpwrdn.d32 = 0;
  66232. + gpwrdn.b.pwrdnrstn = 1;
  66233. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  66234. + dwc_udelay(10);
  66235. +
  66236. + /* Disable power clamps */
  66237. + gpwrdn.d32 = 0;
  66238. + gpwrdn.b.pwrdnclmp = 1;
  66239. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  66240. +
  66241. + /* Remove reset the core signal */
  66242. + gpwrdn.d32 = 0;
  66243. + gpwrdn.b.pwrdnrstn = 1;
  66244. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  66245. + dwc_udelay(10);
  66246. +
  66247. + /* Disable PMU interrupt */
  66248. + gpwrdn.d32 = 0;
  66249. + gpwrdn.b.pmuintsel = 1;
  66250. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  66251. +
  66252. + /* Indicates that we are exiting from hibernation */
  66253. + core_if->hibernation_suspend = 0;
  66254. +
  66255. + /* Disable PMU */
  66256. + gpwrdn.d32 = 0;
  66257. + gpwrdn.b.pmuactv = 1;
  66258. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  66259. + dwc_udelay(10);
  66260. +
  66261. + /* Programm Disable VBUS to 0 */
  66262. + gpwrdn.d32 = 0;
  66263. + gpwrdn.b.dis_vbus = 1;
  66264. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  66265. +
  66266. + /*Initialize the core as Host */
  66267. + core_if->op_state = A_HOST;
  66268. + dwc_otg_core_init(core_if);
  66269. + dwc_otg_enable_global_interrupts(core_if);
  66270. + cil_hcd_start(core_if);
  66271. +
  66272. + return 1;
  66273. +}
  66274. +
  66275. +/** This interrupt indicates that restore command after Hibernation
  66276. + * was completed by the core. */
  66277. +int32_t dwc_otg_handle_restore_done_intr(dwc_otg_core_if_t * core_if)
  66278. +{
  66279. + pcgcctl_data_t pcgcctl;
  66280. + DWC_DEBUGPL(DBG_ANY, "++Restore Done Interrupt++\n");
  66281. +
  66282. + //TODO De-assert restore signal. 8.a
  66283. + pcgcctl.d32 = DWC_READ_REG32(core_if->pcgcctl);
  66284. + if (pcgcctl.b.restoremode == 1) {
  66285. + gintmsk_data_t gintmsk = {.d32 = 0 };
  66286. + /*
  66287. + * If restore mode is Remote Wakeup,
  66288. + * unmask Remote Wakeup interrupt.
  66289. + */
  66290. + gintmsk.b.wkupintr = 1;
  66291. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  66292. + 0, gintmsk.d32);
  66293. + }
  66294. +
  66295. + return 1;
  66296. +}
  66297. +
  66298. +/**
  66299. + * This interrupt indicates that a device has been disconnected from
  66300. + * the root port.
  66301. + */
  66302. +int32_t dwc_otg_handle_disconnect_intr(dwc_otg_core_if_t * core_if)
  66303. +{
  66304. + gintsts_data_t gintsts;
  66305. +
  66306. + DWC_DEBUGPL(DBG_ANY, "++Disconnect Detected Interrupt++ (%s) %s\n",
  66307. + (dwc_otg_is_host_mode(core_if) ? "Host" : "Device"),
  66308. + op_state_str(core_if));
  66309. +
  66310. +/** @todo Consolidate this if statement. */
  66311. +#ifndef DWC_HOST_ONLY
  66312. + if (core_if->op_state == B_HOST) {
  66313. + /* If in device mode Disconnect and stop the HCD, then
  66314. + * start the PCD. */
  66315. + DWC_SPINUNLOCK(core_if->lock);
  66316. + cil_hcd_disconnect(core_if);
  66317. + cil_pcd_start(core_if);
  66318. + DWC_SPINLOCK(core_if->lock);
  66319. + core_if->op_state = B_PERIPHERAL;
  66320. + } else if (dwc_otg_is_device_mode(core_if)) {
  66321. + gotgctl_data_t gotgctl = {.d32 = 0 };
  66322. + gotgctl.d32 =
  66323. + DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  66324. + if (gotgctl.b.hstsethnpen == 1) {
  66325. + /* Do nothing, if HNP in process the OTG
  66326. + * interrupt "Host Negotiation Detected"
  66327. + * interrupt will do the mode switch.
  66328. + */
  66329. + } else if (gotgctl.b.devhnpen == 0) {
  66330. + /* If in device mode Disconnect and stop the HCD, then
  66331. + * start the PCD. */
  66332. + DWC_SPINUNLOCK(core_if->lock);
  66333. + cil_hcd_disconnect(core_if);
  66334. + cil_pcd_start(core_if);
  66335. + DWC_SPINLOCK(core_if->lock);
  66336. + core_if->op_state = B_PERIPHERAL;
  66337. + } else {
  66338. + DWC_DEBUGPL(DBG_ANY, "!a_peripheral && !devhnpen\n");
  66339. + }
  66340. + } else {
  66341. + if (core_if->op_state == A_HOST) {
  66342. + /* A-Cable still connected but device disconnected. */
  66343. + cil_hcd_disconnect(core_if);
  66344. + if (core_if->adp_enable) {
  66345. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  66346. + cil_hcd_stop(core_if);
  66347. + /* Enable Power Down Logic */
  66348. + gpwrdn.b.pmuintsel = 1;
  66349. + gpwrdn.b.pmuactv = 1;
  66350. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  66351. + gpwrdn, 0, gpwrdn.d32);
  66352. + dwc_otg_adp_probe_start(core_if);
  66353. +
  66354. + /* Power off the core */
  66355. + if (core_if->power_down == 2) {
  66356. + gpwrdn.d32 = 0;
  66357. + gpwrdn.b.pwrdnswtch = 1;
  66358. + DWC_MODIFY_REG32
  66359. + (&core_if->core_global_regs->gpwrdn,
  66360. + gpwrdn.d32, 0);
  66361. + }
  66362. + }
  66363. + }
  66364. + }
  66365. +#endif
  66366. + /* Change to L3(OFF) state */
  66367. + core_if->lx_state = DWC_OTG_L3;
  66368. +
  66369. + gintsts.d32 = 0;
  66370. + gintsts.b.disconnect = 1;
  66371. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  66372. + return 1;
  66373. +}
  66374. +
  66375. +/**
  66376. + * This interrupt indicates that SUSPEND state has been detected on
  66377. + * the USB.
  66378. + *
  66379. + * For HNP the USB Suspend interrupt signals the change from
  66380. + * "a_peripheral" to "a_host".
  66381. + *
  66382. + * When power management is enabled the core will be put in low power
  66383. + * mode.
  66384. + */
  66385. +int32_t dwc_otg_handle_usb_suspend_intr(dwc_otg_core_if_t * core_if)
  66386. +{
  66387. + dsts_data_t dsts;
  66388. + gintsts_data_t gintsts;
  66389. + dcfg_data_t dcfg;
  66390. +
  66391. + DWC_DEBUGPL(DBG_ANY, "USB SUSPEND\n");
  66392. +
  66393. + if (dwc_otg_is_device_mode(core_if)) {
  66394. + /* Check the Device status register to determine if the Suspend
  66395. + * state is active. */
  66396. + dsts.d32 =
  66397. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  66398. + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n", dsts.d32);
  66399. + DWC_DEBUGPL(DBG_PCD, "DSTS.Suspend Status=%d "
  66400. + "HWCFG4.power Optimize=%d\n",
  66401. + dsts.b.suspsts, core_if->hwcfg4.b.power_optimiz);
  66402. +
  66403. +#ifdef PARTIAL_POWER_DOWN
  66404. +/** @todo Add a module parameter for power management. */
  66405. +
  66406. + if (dsts.b.suspsts && core_if->hwcfg4.b.power_optimiz) {
  66407. + pcgcctl_data_t power = {.d32 = 0 };
  66408. + DWC_DEBUGPL(DBG_CIL, "suspend\n");
  66409. +
  66410. + power.b.pwrclmp = 1;
  66411. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  66412. +
  66413. + power.b.rstpdwnmodule = 1;
  66414. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, power.d32);
  66415. +
  66416. + power.b.stoppclk = 1;
  66417. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, power.d32);
  66418. +
  66419. + } else {
  66420. + DWC_DEBUGPL(DBG_ANY, "disconnect?\n");
  66421. + }
  66422. +#endif
  66423. + /* PCD callback for suspend. Release the lock inside of callback function */
  66424. + cil_pcd_suspend(core_if);
  66425. + if (core_if->power_down == 2)
  66426. + {
  66427. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  66428. + DWC_DEBUGPL(DBG_ANY,"lx_state = %08x\n",core_if->lx_state);
  66429. + DWC_DEBUGPL(DBG_ANY," device address = %08d\n",dcfg.b.devaddr);
  66430. +
  66431. + if (core_if->lx_state != DWC_OTG_L3 && dcfg.b.devaddr) {
  66432. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  66433. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  66434. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  66435. +
  66436. + /* Change to L2(suspend) state */
  66437. + core_if->lx_state = DWC_OTG_L2;
  66438. +
  66439. + /* Clear interrupt in gintsts */
  66440. + gintsts.d32 = 0;
  66441. + gintsts.b.usbsuspend = 1;
  66442. + DWC_WRITE_REG32(&core_if->core_global_regs->
  66443. + gintsts, gintsts.d32);
  66444. + DWC_PRINTF("Start of hibernation completed\n");
  66445. + dwc_otg_save_global_regs(core_if);
  66446. + dwc_otg_save_dev_regs(core_if);
  66447. +
  66448. + gusbcfg.d32 =
  66449. + DWC_READ_REG32(&core_if->core_global_regs->
  66450. + gusbcfg);
  66451. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  66452. + /* ULPI interface */
  66453. + /* Suspend the Phy Clock */
  66454. + pcgcctl.d32 = 0;
  66455. + pcgcctl.b.stoppclk = 1;
  66456. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  66457. + pcgcctl.d32);
  66458. + dwc_udelay(10);
  66459. + gpwrdn.b.pmuactv = 1;
  66460. + DWC_MODIFY_REG32(&core_if->
  66461. + core_global_regs->
  66462. + gpwrdn, 0, gpwrdn.d32);
  66463. + } else {
  66464. + /* UTMI+ Interface */
  66465. + gpwrdn.b.pmuactv = 1;
  66466. + DWC_MODIFY_REG32(&core_if->
  66467. + core_global_regs->
  66468. + gpwrdn, 0, gpwrdn.d32);
  66469. + dwc_udelay(10);
  66470. + pcgcctl.b.stoppclk = 1;
  66471. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  66472. + pcgcctl.d32);
  66473. + dwc_udelay(10);
  66474. + }
  66475. +
  66476. + /* Set flag to indicate that we are in hibernation */
  66477. + core_if->hibernation_suspend = 1;
  66478. + /* Enable interrupts from wake up logic */
  66479. + gpwrdn.d32 = 0;
  66480. + gpwrdn.b.pmuintsel = 1;
  66481. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  66482. + gpwrdn, 0, gpwrdn.d32);
  66483. + dwc_udelay(10);
  66484. +
  66485. + /* Unmask device mode interrupts in GPWRDN */
  66486. + gpwrdn.d32 = 0;
  66487. + gpwrdn.b.rst_det_msk = 1;
  66488. + gpwrdn.b.lnstchng_msk = 1;
  66489. + gpwrdn.b.sts_chngint_msk = 1;
  66490. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  66491. + gpwrdn, 0, gpwrdn.d32);
  66492. + dwc_udelay(10);
  66493. +
  66494. + /* Enable Power Down Clamp */
  66495. + gpwrdn.d32 = 0;
  66496. + gpwrdn.b.pwrdnclmp = 1;
  66497. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  66498. + gpwrdn, 0, gpwrdn.d32);
  66499. + dwc_udelay(10);
  66500. +
  66501. + /* Switch off VDD */
  66502. + gpwrdn.d32 = 0;
  66503. + gpwrdn.b.pwrdnswtch = 1;
  66504. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  66505. + gpwrdn, 0, gpwrdn.d32);
  66506. +
  66507. + /* Save gpwrdn register for further usage if stschng interrupt */
  66508. + core_if->gr_backup->gpwrdn_local =
  66509. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  66510. + DWC_PRINTF("Hibernation completed\n");
  66511. +
  66512. + return 1;
  66513. + }
  66514. + } else if (core_if->power_down == 3) {
  66515. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  66516. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  66517. + DWC_DEBUGPL(DBG_ANY, "lx_state = %08x\n",core_if->lx_state);
  66518. + DWC_DEBUGPL(DBG_ANY, " device address = %08d\n",dcfg.b.devaddr);
  66519. +
  66520. + if (core_if->lx_state != DWC_OTG_L3 && dcfg.b.devaddr) {
  66521. + DWC_DEBUGPL(DBG_ANY, "Start entering to extended hibernation\n");
  66522. + core_if->xhib = 1;
  66523. +
  66524. + /* Clear interrupt in gintsts */
  66525. + gintsts.d32 = 0;
  66526. + gintsts.b.usbsuspend = 1;
  66527. + DWC_WRITE_REG32(&core_if->core_global_regs->
  66528. + gintsts, gintsts.d32);
  66529. +
  66530. + dwc_otg_save_global_regs(core_if);
  66531. + dwc_otg_save_dev_regs(core_if);
  66532. +
  66533. + /* Wait for 10 PHY clocks */
  66534. + dwc_udelay(10);
  66535. +
  66536. + /* Program GPIO register while entering to xHib */
  66537. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, 0x1);
  66538. +
  66539. + pcgcctl.b.enbl_extnd_hiber = 1;
  66540. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  66541. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  66542. +
  66543. + pcgcctl.d32 = 0;
  66544. + pcgcctl.b.extnd_hiber_pwrclmp = 1;
  66545. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  66546. +
  66547. + pcgcctl.d32 = 0;
  66548. + pcgcctl.b.extnd_hiber_switch = 1;
  66549. + core_if->gr_backup->xhib_gpwrdn = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  66550. + core_if->gr_backup->xhib_pcgcctl = DWC_READ_REG32(core_if->pcgcctl) | pcgcctl.d32;
  66551. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  66552. +
  66553. + DWC_DEBUGPL(DBG_ANY, "Finished entering to extended hibernation\n");
  66554. +
  66555. + return 1;
  66556. + }
  66557. + }
  66558. + } else {
  66559. + if (core_if->op_state == A_PERIPHERAL) {
  66560. + DWC_DEBUGPL(DBG_ANY, "a_peripheral->a_host\n");
  66561. + /* Clear the a_peripheral flag, back to a_host. */
  66562. + DWC_SPINUNLOCK(core_if->lock);
  66563. + cil_pcd_stop(core_if);
  66564. + cil_hcd_start(core_if);
  66565. + DWC_SPINLOCK(core_if->lock);
  66566. + core_if->op_state = A_HOST;
  66567. + }
  66568. + }
  66569. +
  66570. + /* Change to L2(suspend) state */
  66571. + core_if->lx_state = DWC_OTG_L2;
  66572. +
  66573. + /* Clear interrupt */
  66574. + gintsts.d32 = 0;
  66575. + gintsts.b.usbsuspend = 1;
  66576. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  66577. +
  66578. + return 1;
  66579. +}
  66580. +
  66581. +static int32_t dwc_otg_handle_xhib_exit_intr(dwc_otg_core_if_t * core_if)
  66582. +{
  66583. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  66584. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  66585. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  66586. +
  66587. + dwc_udelay(10);
  66588. +
  66589. + /* Program GPIO register while entering to xHib */
  66590. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, 0x0);
  66591. +
  66592. + pcgcctl.d32 = core_if->gr_backup->xhib_pcgcctl;
  66593. + pcgcctl.b.extnd_hiber_pwrclmp = 0;
  66594. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  66595. + dwc_udelay(10);
  66596. +
  66597. + gpwrdn.d32 = core_if->gr_backup->xhib_gpwrdn;
  66598. + gpwrdn.b.restore = 1;
  66599. + DWC_WRITE_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32);
  66600. + dwc_udelay(10);
  66601. +
  66602. + restore_lpm_i2c_regs(core_if);
  66603. +
  66604. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  66605. + pcgcctl.b.max_xcvrselect = 1;
  66606. + pcgcctl.b.ess_reg_restored = 0;
  66607. + pcgcctl.b.extnd_hiber_switch = 0;
  66608. + pcgcctl.b.extnd_hiber_pwrclmp = 0;
  66609. + pcgcctl.b.enbl_extnd_hiber = 1;
  66610. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  66611. +
  66612. + gahbcfg.d32 = core_if->gr_backup->gahbcfg_local;
  66613. + gahbcfg.b.glblintrmsk = 1;
  66614. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gahbcfg.d32);
  66615. +
  66616. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  66617. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0x1 << 16);
  66618. +
  66619. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  66620. + core_if->gr_backup->gusbcfg_local);
  66621. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  66622. + core_if->dr_backup->dcfg);
  66623. +
  66624. + pcgcctl.d32 = 0;
  66625. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  66626. + pcgcctl.b.max_xcvrselect = 1;
  66627. + pcgcctl.d32 |= 0x608;
  66628. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  66629. + dwc_udelay(10);
  66630. +
  66631. + pcgcctl.d32 = 0;
  66632. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  66633. + pcgcctl.b.max_xcvrselect = 1;
  66634. + pcgcctl.b.ess_reg_restored = 1;
  66635. + pcgcctl.b.enbl_extnd_hiber = 1;
  66636. + pcgcctl.b.rstpdwnmodule = 1;
  66637. + pcgcctl.b.restoremode = 1;
  66638. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  66639. +
  66640. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  66641. +
  66642. + return 1;
  66643. +}
  66644. +
  66645. +#ifdef CONFIG_USB_DWC_OTG_LPM
  66646. +/**
  66647. + * This function hadles LPM transaction received interrupt.
  66648. + */
  66649. +static int32_t dwc_otg_handle_lpm_intr(dwc_otg_core_if_t * core_if)
  66650. +{
  66651. + glpmcfg_data_t lpmcfg;
  66652. + gintsts_data_t gintsts;
  66653. +
  66654. + if (!core_if->core_params->lpm_enable) {
  66655. + DWC_PRINTF("Unexpected LPM interrupt\n");
  66656. + }
  66657. +
  66658. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  66659. + DWC_PRINTF("LPM config register = 0x%08x\n", lpmcfg.d32);
  66660. +
  66661. + if (dwc_otg_is_host_mode(core_if)) {
  66662. + cil_hcd_sleep(core_if);
  66663. + } else {
  66664. + lpmcfg.b.hird_thres |= (1 << 4);
  66665. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg,
  66666. + lpmcfg.d32);
  66667. + }
  66668. +
  66669. + /* Examine prt_sleep_sts after TL1TokenTetry period max (10 us) */
  66670. + dwc_udelay(10);
  66671. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  66672. + if (lpmcfg.b.prt_sleep_sts) {
  66673. + /* Save the current state */
  66674. + core_if->lx_state = DWC_OTG_L1;
  66675. + }
  66676. +
  66677. + /* Clear interrupt */
  66678. + gintsts.d32 = 0;
  66679. + gintsts.b.lpmtranrcvd = 1;
  66680. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  66681. + return 1;
  66682. +}
  66683. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  66684. +
  66685. +/**
  66686. + * This function returns the Core Interrupt register.
  66687. + */
  66688. +static inline uint32_t dwc_otg_read_common_intr(dwc_otg_core_if_t * core_if, gintmsk_data_t *reenable_gintmsk, dwc_otg_hcd_t *hcd)
  66689. +{
  66690. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  66691. + gintsts_data_t gintsts;
  66692. + gintmsk_data_t gintmsk;
  66693. + gintmsk_data_t gintmsk_common = {.d32 = 0 };
  66694. + gintmsk_common.b.wkupintr = 1;
  66695. + gintmsk_common.b.sessreqintr = 1;
  66696. + gintmsk_common.b.conidstschng = 1;
  66697. + gintmsk_common.b.otgintr = 1;
  66698. + gintmsk_common.b.modemismatch = 1;
  66699. + gintmsk_common.b.disconnect = 1;
  66700. + gintmsk_common.b.usbsuspend = 1;
  66701. +#ifdef CONFIG_USB_DWC_OTG_LPM
  66702. + gintmsk_common.b.lpmtranrcvd = 1;
  66703. +#endif
  66704. + gintmsk_common.b.restoredone = 1;
  66705. + if(dwc_otg_is_device_mode(core_if))
  66706. + {
  66707. + /** @todo: The port interrupt occurs while in device
  66708. + * mode. Added code to CIL to clear the interrupt for now!
  66709. + */
  66710. + gintmsk_common.b.portintr = 1;
  66711. + }
  66712. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  66713. + gintmsk.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  66714. + if(fiq_enable) {
  66715. + local_fiq_disable();
  66716. + /* Pull in the interrupts that the FIQ has masked */
  66717. + gintmsk.d32 |= ~(hcd->fiq_state->gintmsk_saved.d32);
  66718. + gintmsk.d32 |= gintmsk_common.d32;
  66719. + /* for the upstairs function to reenable - have to read it here in case FIQ triggers again */
  66720. + reenable_gintmsk->d32 = gintmsk.d32;
  66721. + local_fiq_enable();
  66722. + }
  66723. +
  66724. + gahbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gahbcfg);
  66725. +
  66726. +#ifdef DEBUG
  66727. + /* if any common interrupts set */
  66728. + if (gintsts.d32 & gintmsk_common.d32) {
  66729. + DWC_DEBUGPL(DBG_ANY, "common_intr: gintsts=%08x gintmsk=%08x\n",
  66730. + gintsts.d32, gintmsk.d32);
  66731. + }
  66732. +#endif
  66733. + if (!fiq_enable){
  66734. + if (gahbcfg.b.glblintrmsk)
  66735. + return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
  66736. + else
  66737. + return 0;
  66738. + } else {
  66739. + /* Our IRQ kicker is no longer the USB hardware, it's the MPHI interface.
  66740. + * Can't trust the global interrupt mask bit in this case.
  66741. + */
  66742. + return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
  66743. + }
  66744. +
  66745. +}
  66746. +
  66747. +/* MACRO for clearing interupt bits in GPWRDN register */
  66748. +#define CLEAR_GPWRDN_INTR(__core_if,__intr) \
  66749. +do { \
  66750. + gpwrdn_data_t gpwrdn = {.d32=0}; \
  66751. + gpwrdn.b.__intr = 1; \
  66752. + DWC_MODIFY_REG32(&__core_if->core_global_regs->gpwrdn, \
  66753. + 0, gpwrdn.d32); \
  66754. +} while (0)
  66755. +
  66756. +/**
  66757. + * Common interrupt handler.
  66758. + *
  66759. + * The common interrupts are those that occur in both Host and Device mode.
  66760. + * This handler handles the following interrupts:
  66761. + * - Mode Mismatch Interrupt
  66762. + * - Disconnect Interrupt
  66763. + * - OTG Interrupt
  66764. + * - Connector ID Status Change Interrupt
  66765. + * - Session Request Interrupt.
  66766. + * - Resume / Remote Wakeup Detected Interrupt.
  66767. + * - LPM Transaction Received Interrupt
  66768. + * - ADP Transaction Received Interrupt
  66769. + *
  66770. + */
  66771. +int32_t dwc_otg_handle_common_intr(void *dev)
  66772. +{
  66773. + int retval = 0;
  66774. + gintsts_data_t gintsts;
  66775. + gintmsk_data_t gintmsk_reenable = { .d32 = 0 };
  66776. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  66777. + dwc_otg_device_t *otg_dev = dev;
  66778. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  66779. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  66780. + if (dwc_otg_is_device_mode(core_if))
  66781. + core_if->frame_num = dwc_otg_get_frame_number(core_if);
  66782. +
  66783. + if (core_if->lock)
  66784. + DWC_SPINLOCK(core_if->lock);
  66785. +
  66786. + if (core_if->power_down == 3 && core_if->xhib == 1) {
  66787. + DWC_DEBUGPL(DBG_ANY, "Exiting from xHIB state\n");
  66788. + retval |= dwc_otg_handle_xhib_exit_intr(core_if);
  66789. + core_if->xhib = 2;
  66790. + if (core_if->lock)
  66791. + DWC_SPINUNLOCK(core_if->lock);
  66792. +
  66793. + return retval;
  66794. + }
  66795. +
  66796. + if (core_if->hibernation_suspend <= 0) {
  66797. + /* read_common will have to poke the FIQ's saved mask. We must then clear this mask at the end
  66798. + * of this handler - god only knows why it's done like this
  66799. + */
  66800. + gintsts.d32 = dwc_otg_read_common_intr(core_if, &gintmsk_reenable, otg_dev->hcd);
  66801. +
  66802. + if (gintsts.b.modemismatch) {
  66803. + retval |= dwc_otg_handle_mode_mismatch_intr(core_if);
  66804. + }
  66805. + if (gintsts.b.otgintr) {
  66806. + retval |= dwc_otg_handle_otg_intr(core_if);
  66807. + }
  66808. + if (gintsts.b.conidstschng) {
  66809. + retval |=
  66810. + dwc_otg_handle_conn_id_status_change_intr(core_if);
  66811. + }
  66812. + if (gintsts.b.disconnect) {
  66813. + retval |= dwc_otg_handle_disconnect_intr(core_if);
  66814. + }
  66815. + if (gintsts.b.sessreqintr) {
  66816. + retval |= dwc_otg_handle_session_req_intr(core_if);
  66817. + }
  66818. + if (gintsts.b.wkupintr) {
  66819. + retval |= dwc_otg_handle_wakeup_detected_intr(core_if);
  66820. + }
  66821. + if (gintsts.b.usbsuspend) {
  66822. + retval |= dwc_otg_handle_usb_suspend_intr(core_if);
  66823. + }
  66824. +#ifdef CONFIG_USB_DWC_OTG_LPM
  66825. + if (gintsts.b.lpmtranrcvd) {
  66826. + retval |= dwc_otg_handle_lpm_intr(core_if);
  66827. + }
  66828. +#endif
  66829. + if (gintsts.b.restoredone) {
  66830. + gintsts.d32 = 0;
  66831. + if (core_if->power_down == 2)
  66832. + core_if->hibernation_suspend = -1;
  66833. + else if (core_if->power_down == 3 && core_if->xhib == 2) {
  66834. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  66835. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  66836. + dctl_data_t dctl = {.d32 = 0 };
  66837. +
  66838. + DWC_WRITE_REG32(&core_if->core_global_regs->
  66839. + gintsts, 0xFFFFFFFF);
  66840. +
  66841. + DWC_DEBUGPL(DBG_ANY,
  66842. + "RESTORE DONE generated\n");
  66843. +
  66844. + gpwrdn.b.restore = 1;
  66845. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  66846. + dwc_udelay(10);
  66847. +
  66848. + pcgcctl.b.rstpdwnmodule = 1;
  66849. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  66850. +
  66851. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, core_if->gr_backup->gusbcfg_local);
  66852. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, core_if->dr_backup->dcfg);
  66853. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, core_if->dr_backup->dctl);
  66854. + dwc_udelay(50);
  66855. +
  66856. + dctl.b.pwronprgdone = 1;
  66857. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  66858. + dwc_udelay(10);
  66859. +
  66860. + dwc_otg_restore_global_regs(core_if);
  66861. + dwc_otg_restore_dev_regs(core_if, 0);
  66862. +
  66863. + dctl.d32 = 0;
  66864. + dctl.b.pwronprgdone = 1;
  66865. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  66866. + dwc_udelay(10);
  66867. +
  66868. + pcgcctl.d32 = 0;
  66869. + pcgcctl.b.enbl_extnd_hiber = 1;
  66870. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  66871. +
  66872. + /* The core will be in ON STATE */
  66873. + core_if->lx_state = DWC_OTG_L0;
  66874. + core_if->xhib = 0;
  66875. +
  66876. + DWC_SPINUNLOCK(core_if->lock);
  66877. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  66878. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  66879. + }
  66880. + DWC_SPINLOCK(core_if->lock);
  66881. +
  66882. + }
  66883. +
  66884. + gintsts.b.restoredone = 1;
  66885. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts,gintsts.d32);
  66886. + DWC_PRINTF(" --Restore done interrupt received-- \n");
  66887. + retval |= 1;
  66888. + }
  66889. + if (gintsts.b.portintr && dwc_otg_is_device_mode(core_if)) {
  66890. + /* The port interrupt occurs while in device mode with HPRT0
  66891. + * Port Enable/Disable.
  66892. + */
  66893. + gintsts.d32 = 0;
  66894. + gintsts.b.portintr = 1;
  66895. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts,gintsts.d32);
  66896. + retval |= 1;
  66897. + gintmsk_reenable.b.portintr = 1;
  66898. +
  66899. + }
  66900. + /* Did we actually handle anything? if so, unmask the interrupt */
  66901. +// fiq_print(FIQDBG_INT, otg_dev->hcd->fiq_state, "CILOUT %1d", retval);
  66902. +// fiq_print(FIQDBG_INT, otg_dev->hcd->fiq_state, "%08x", gintsts.d32);
  66903. +// fiq_print(FIQDBG_INT, otg_dev->hcd->fiq_state, "%08x", gintmsk_reenable.d32);
  66904. + if (retval && fiq_enable) {
  66905. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk_reenable.d32);
  66906. + }
  66907. +
  66908. + } else {
  66909. + DWC_DEBUGPL(DBG_ANY, "gpwrdn=%08x\n", gpwrdn.d32);
  66910. +
  66911. + if (gpwrdn.b.disconn_det && gpwrdn.b.disconn_det_msk) {
  66912. + CLEAR_GPWRDN_INTR(core_if, disconn_det);
  66913. + if (gpwrdn.b.linestate == 0) {
  66914. + dwc_otg_handle_pwrdn_disconnect_intr(core_if);
  66915. + } else {
  66916. + DWC_PRINTF("Disconnect detected while linestate is not 0\n");
  66917. + }
  66918. +
  66919. + retval |= 1;
  66920. + }
  66921. + if (gpwrdn.b.lnstschng && gpwrdn.b.lnstchng_msk) {
  66922. + CLEAR_GPWRDN_INTR(core_if, lnstschng);
  66923. + /* remote wakeup from hibernation */
  66924. + if (gpwrdn.b.linestate == 2 || gpwrdn.b.linestate == 1) {
  66925. + dwc_otg_handle_pwrdn_wakeup_detected_intr(core_if);
  66926. + } else {
  66927. + DWC_PRINTF("gpwrdn.linestate = %d\n", gpwrdn.b.linestate);
  66928. + }
  66929. + retval |= 1;
  66930. + }
  66931. + if (gpwrdn.b.rst_det && gpwrdn.b.rst_det_msk) {
  66932. + CLEAR_GPWRDN_INTR(core_if, rst_det);
  66933. + if (gpwrdn.b.linestate == 0) {
  66934. + DWC_PRINTF("Reset detected\n");
  66935. + retval |= dwc_otg_device_hibernation_restore(core_if, 0, 1);
  66936. + }
  66937. + }
  66938. + if (gpwrdn.b.srp_det && gpwrdn.b.srp_det_msk) {
  66939. + CLEAR_GPWRDN_INTR(core_if, srp_det);
  66940. + dwc_otg_handle_pwrdn_srp_intr(core_if);
  66941. + retval |= 1;
  66942. + }
  66943. + }
  66944. + /* Handle ADP interrupt here */
  66945. + if (gpwrdn.b.adp_int) {
  66946. + DWC_PRINTF("ADP interrupt\n");
  66947. + CLEAR_GPWRDN_INTR(core_if, adp_int);
  66948. + dwc_otg_adp_handle_intr(core_if);
  66949. + retval |= 1;
  66950. + }
  66951. + if (gpwrdn.b.sts_chngint && gpwrdn.b.sts_chngint_msk) {
  66952. + DWC_PRINTF("STS CHNG interrupt asserted\n");
  66953. + CLEAR_GPWRDN_INTR(core_if, sts_chngint);
  66954. + dwc_otg_handle_pwrdn_stschng_intr(otg_dev);
  66955. +
  66956. + retval |= 1;
  66957. + }
  66958. + if (core_if->lock)
  66959. + DWC_SPINUNLOCK(core_if->lock);
  66960. + return retval;
  66961. +}
  66962. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_core_if.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_core_if.h
  66963. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_core_if.h 1970-01-01 01:00:00.000000000 +0100
  66964. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_core_if.h 2014-07-07 10:45:43.000000000 +0200
  66965. @@ -0,0 +1,705 @@
  66966. +/* ==========================================================================
  66967. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_core_if.h $
  66968. + * $Revision: #13 $
  66969. + * $Date: 2012/08/10 $
  66970. + * $Change: 2047372 $
  66971. + *
  66972. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  66973. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  66974. + * otherwise expressly agreed to in writing between Synopsys and you.
  66975. + *
  66976. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  66977. + * any End User Software License Agreement or Agreement for Licensed Product
  66978. + * with Synopsys or any supplement thereto. You are permitted to use and
  66979. + * redistribute this Software in source and binary forms, with or without
  66980. + * modification, provided that redistributions of source code must retain this
  66981. + * notice. You may not view, use, disclose, copy or distribute this file or
  66982. + * any information contained herein except pursuant to this license grant from
  66983. + * Synopsys. If you do not agree with this notice, including the disclaimer
  66984. + * below, then you are not authorized to use the Software.
  66985. + *
  66986. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  66987. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  66988. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  66989. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  66990. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  66991. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  66992. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  66993. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  66994. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  66995. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  66996. + * DAMAGE.
  66997. + * ========================================================================== */
  66998. +#if !defined(__DWC_CORE_IF_H__)
  66999. +#define __DWC_CORE_IF_H__
  67000. +
  67001. +#include "dwc_os.h"
  67002. +
  67003. +/** @file
  67004. + * This file defines DWC_OTG Core API
  67005. + */
  67006. +
  67007. +struct dwc_otg_core_if;
  67008. +typedef struct dwc_otg_core_if dwc_otg_core_if_t;
  67009. +
  67010. +/** Maximum number of Periodic FIFOs */
  67011. +#define MAX_PERIO_FIFOS 15
  67012. +/** Maximum number of Periodic FIFOs */
  67013. +#define MAX_TX_FIFOS 15
  67014. +
  67015. +/** Maximum number of Endpoints/HostChannels */
  67016. +#define MAX_EPS_CHANNELS 16
  67017. +
  67018. +extern dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t * _reg_base_addr);
  67019. +extern void dwc_otg_core_init(dwc_otg_core_if_t * _core_if);
  67020. +extern void dwc_otg_cil_remove(dwc_otg_core_if_t * _core_if);
  67021. +
  67022. +extern void dwc_otg_enable_global_interrupts(dwc_otg_core_if_t * _core_if);
  67023. +extern void dwc_otg_disable_global_interrupts(dwc_otg_core_if_t * _core_if);
  67024. +
  67025. +extern uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t * _core_if);
  67026. +extern uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t * _core_if);
  67027. +
  67028. +extern uint8_t dwc_otg_is_dma_enable(dwc_otg_core_if_t * core_if);
  67029. +
  67030. +/** This function should be called on every hardware interrupt. */
  67031. +extern int32_t dwc_otg_handle_common_intr(void *otg_dev);
  67032. +
  67033. +/** @name OTG Core Parameters */
  67034. +/** @{ */
  67035. +
  67036. +/**
  67037. + * Specifies the OTG capabilities. The driver will automatically
  67038. + * detect the value for this parameter if none is specified.
  67039. + * 0 - HNP and SRP capable (default)
  67040. + * 1 - SRP Only capable
  67041. + * 2 - No HNP/SRP capable
  67042. + */
  67043. +extern int dwc_otg_set_param_otg_cap(dwc_otg_core_if_t * core_if, int32_t val);
  67044. +extern int32_t dwc_otg_get_param_otg_cap(dwc_otg_core_if_t * core_if);
  67045. +#define DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE 0
  67046. +#define DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE 1
  67047. +#define DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
  67048. +#define dwc_param_otg_cap_default DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE
  67049. +
  67050. +extern int dwc_otg_set_param_opt(dwc_otg_core_if_t * core_if, int32_t val);
  67051. +extern int32_t dwc_otg_get_param_opt(dwc_otg_core_if_t * core_if);
  67052. +#define dwc_param_opt_default 1
  67053. +
  67054. +/**
  67055. + * Specifies whether to use slave or DMA mode for accessing the data
  67056. + * FIFOs. The driver will automatically detect the value for this
  67057. + * parameter if none is specified.
  67058. + * 0 - Slave
  67059. + * 1 - DMA (default, if available)
  67060. + */
  67061. +extern int dwc_otg_set_param_dma_enable(dwc_otg_core_if_t * core_if,
  67062. + int32_t val);
  67063. +extern int32_t dwc_otg_get_param_dma_enable(dwc_otg_core_if_t * core_if);
  67064. +#define dwc_param_dma_enable_default 1
  67065. +
  67066. +/**
  67067. + * When DMA mode is enabled specifies whether to use
  67068. + * address DMA or DMA Descritor mode for accessing the data
  67069. + * FIFOs in device mode. The driver will automatically detect
  67070. + * the value for this parameter if none is specified.
  67071. + * 0 - address DMA
  67072. + * 1 - DMA Descriptor(default, if available)
  67073. + */
  67074. +extern int dwc_otg_set_param_dma_desc_enable(dwc_otg_core_if_t * core_if,
  67075. + int32_t val);
  67076. +extern int32_t dwc_otg_get_param_dma_desc_enable(dwc_otg_core_if_t * core_if);
  67077. +//#define dwc_param_dma_desc_enable_default 1
  67078. +#define dwc_param_dma_desc_enable_default 0 // Broadcom BCM2708
  67079. +
  67080. +/** The DMA Burst size (applicable only for External DMA
  67081. + * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  67082. + */
  67083. +extern int dwc_otg_set_param_dma_burst_size(dwc_otg_core_if_t * core_if,
  67084. + int32_t val);
  67085. +extern int32_t dwc_otg_get_param_dma_burst_size(dwc_otg_core_if_t * core_if);
  67086. +#define dwc_param_dma_burst_size_default 32
  67087. +
  67088. +/**
  67089. + * Specifies the maximum speed of operation in host and device mode.
  67090. + * The actual speed depends on the speed of the attached device and
  67091. + * the value of phy_type. The actual speed depends on the speed of the
  67092. + * attached device.
  67093. + * 0 - High Speed (default)
  67094. + * 1 - Full Speed
  67095. + */
  67096. +extern int dwc_otg_set_param_speed(dwc_otg_core_if_t * core_if, int32_t val);
  67097. +extern int32_t dwc_otg_get_param_speed(dwc_otg_core_if_t * core_if);
  67098. +#define dwc_param_speed_default 0
  67099. +#define DWC_SPEED_PARAM_HIGH 0
  67100. +#define DWC_SPEED_PARAM_FULL 1
  67101. +
  67102. +/** Specifies whether low power mode is supported when attached
  67103. + * to a Full Speed or Low Speed device in host mode.
  67104. + * 0 - Don't support low power mode (default)
  67105. + * 1 - Support low power mode
  67106. + */
  67107. +extern int dwc_otg_set_param_host_support_fs_ls_low_power(dwc_otg_core_if_t *
  67108. + core_if, int32_t val);
  67109. +extern int32_t dwc_otg_get_param_host_support_fs_ls_low_power(dwc_otg_core_if_t
  67110. + * core_if);
  67111. +#define dwc_param_host_support_fs_ls_low_power_default 0
  67112. +
  67113. +/** Specifies the PHY clock rate in low power mode when connected to a
  67114. + * Low Speed device in host mode. This parameter is applicable only if
  67115. + * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
  67116. + * then defaults to 6 MHZ otherwise 48 MHZ.
  67117. + *
  67118. + * 0 - 48 MHz
  67119. + * 1 - 6 MHz
  67120. + */
  67121. +extern int dwc_otg_set_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t *
  67122. + core_if, int32_t val);
  67123. +extern int32_t dwc_otg_get_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t *
  67124. + core_if);
  67125. +#define dwc_param_host_ls_low_power_phy_clk_default 0
  67126. +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
  67127. +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
  67128. +
  67129. +/**
  67130. + * 0 - Use cC FIFO size parameters
  67131. + * 1 - Allow dynamic FIFO sizing (default)
  67132. + */
  67133. +extern int dwc_otg_set_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if,
  67134. + int32_t val);
  67135. +extern int32_t dwc_otg_get_param_enable_dynamic_fifo(dwc_otg_core_if_t *
  67136. + core_if);
  67137. +#define dwc_param_enable_dynamic_fifo_default 1
  67138. +
  67139. +/** Total number of 4-byte words in the data FIFO memory. This
  67140. + * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
  67141. + * Tx FIFOs.
  67142. + * 32 to 32768 (default 8192)
  67143. + * Note: The total FIFO memory depth in the FPGA configuration is 8192.
  67144. + */
  67145. +extern int dwc_otg_set_param_data_fifo_size(dwc_otg_core_if_t * core_if,
  67146. + int32_t val);
  67147. +extern int32_t dwc_otg_get_param_data_fifo_size(dwc_otg_core_if_t * core_if);
  67148. +//#define dwc_param_data_fifo_size_default 8192
  67149. +#define dwc_param_data_fifo_size_default 0xFF0 // Broadcom BCM2708
  67150. +
  67151. +/** Number of 4-byte words in the Rx FIFO in device mode when dynamic
  67152. + * FIFO sizing is enabled.
  67153. + * 16 to 32768 (default 1064)
  67154. + */
  67155. +extern int dwc_otg_set_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if,
  67156. + int32_t val);
  67157. +extern int32_t dwc_otg_get_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if);
  67158. +#define dwc_param_dev_rx_fifo_size_default 1064
  67159. +
  67160. +/** Number of 4-byte words in the non-periodic Tx FIFO in device mode
  67161. + * when dynamic FIFO sizing is enabled.
  67162. + * 16 to 32768 (default 1024)
  67163. + */
  67164. +extern int dwc_otg_set_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t *
  67165. + core_if, int32_t val);
  67166. +extern int32_t dwc_otg_get_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t *
  67167. + core_if);
  67168. +#define dwc_param_dev_nperio_tx_fifo_size_default 1024
  67169. +
  67170. +/** Number of 4-byte words in each of the periodic Tx FIFOs in device
  67171. + * mode when dynamic FIFO sizing is enabled.
  67172. + * 4 to 768 (default 256)
  67173. + */
  67174. +extern int dwc_otg_set_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  67175. + int32_t val, int fifo_num);
  67176. +extern int32_t dwc_otg_get_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t *
  67177. + core_if, int fifo_num);
  67178. +#define dwc_param_dev_perio_tx_fifo_size_default 256
  67179. +
  67180. +/** Number of 4-byte words in the Rx FIFO in host mode when dynamic
  67181. + * FIFO sizing is enabled.
  67182. + * 16 to 32768 (default 1024)
  67183. + */
  67184. +extern int dwc_otg_set_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if,
  67185. + int32_t val);
  67186. +extern int32_t dwc_otg_get_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if);
  67187. +//#define dwc_param_host_rx_fifo_size_default 1024
  67188. +#define dwc_param_host_rx_fifo_size_default 774 // Broadcom BCM2708
  67189. +
  67190. +/** Number of 4-byte words in the non-periodic Tx FIFO in host mode
  67191. + * when Dynamic FIFO sizing is enabled in the core.
  67192. + * 16 to 32768 (default 1024)
  67193. + */
  67194. +extern int dwc_otg_set_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t *
  67195. + core_if, int32_t val);
  67196. +extern int32_t dwc_otg_get_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t *
  67197. + core_if);
  67198. +//#define dwc_param_host_nperio_tx_fifo_size_default 1024
  67199. +#define dwc_param_host_nperio_tx_fifo_size_default 0x100 // Broadcom BCM2708
  67200. +
  67201. +/** Number of 4-byte words in the host periodic Tx FIFO when dynamic
  67202. + * FIFO sizing is enabled.
  67203. + * 16 to 32768 (default 1024)
  67204. + */
  67205. +extern int dwc_otg_set_param_host_perio_tx_fifo_size(dwc_otg_core_if_t *
  67206. + core_if, int32_t val);
  67207. +extern int32_t dwc_otg_get_param_host_perio_tx_fifo_size(dwc_otg_core_if_t *
  67208. + core_if);
  67209. +//#define dwc_param_host_perio_tx_fifo_size_default 1024
  67210. +#define dwc_param_host_perio_tx_fifo_size_default 0x200 // Broadcom BCM2708
  67211. +
  67212. +/** The maximum transfer size supported in bytes.
  67213. + * 2047 to 65,535 (default 65,535)
  67214. + */
  67215. +extern int dwc_otg_set_param_max_transfer_size(dwc_otg_core_if_t * core_if,
  67216. + int32_t val);
  67217. +extern int32_t dwc_otg_get_param_max_transfer_size(dwc_otg_core_if_t * core_if);
  67218. +#define dwc_param_max_transfer_size_default 65535
  67219. +
  67220. +/** The maximum number of packets in a transfer.
  67221. + * 15 to 511 (default 511)
  67222. + */
  67223. +extern int dwc_otg_set_param_max_packet_count(dwc_otg_core_if_t * core_if,
  67224. + int32_t val);
  67225. +extern int32_t dwc_otg_get_param_max_packet_count(dwc_otg_core_if_t * core_if);
  67226. +#define dwc_param_max_packet_count_default 511
  67227. +
  67228. +/** The number of host channel registers to use.
  67229. + * 1 to 16 (default 12)
  67230. + * Note: The FPGA configuration supports a maximum of 12 host channels.
  67231. + */
  67232. +extern int dwc_otg_set_param_host_channels(dwc_otg_core_if_t * core_if,
  67233. + int32_t val);
  67234. +extern int32_t dwc_otg_get_param_host_channels(dwc_otg_core_if_t * core_if);
  67235. +//#define dwc_param_host_channels_default 12
  67236. +#define dwc_param_host_channels_default 8 // Broadcom BCM2708
  67237. +
  67238. +/** The number of endpoints in addition to EP0 available for device
  67239. + * mode operations.
  67240. + * 1 to 15 (default 6 IN and OUT)
  67241. + * Note: The FPGA configuration supports a maximum of 6 IN and OUT
  67242. + * endpoints in addition to EP0.
  67243. + */
  67244. +extern int dwc_otg_set_param_dev_endpoints(dwc_otg_core_if_t * core_if,
  67245. + int32_t val);
  67246. +extern int32_t dwc_otg_get_param_dev_endpoints(dwc_otg_core_if_t * core_if);
  67247. +#define dwc_param_dev_endpoints_default 6
  67248. +
  67249. +/**
  67250. + * Specifies the type of PHY interface to use. By default, the driver
  67251. + * will automatically detect the phy_type.
  67252. + *
  67253. + * 0 - Full Speed PHY
  67254. + * 1 - UTMI+ (default)
  67255. + * 2 - ULPI
  67256. + */
  67257. +extern int dwc_otg_set_param_phy_type(dwc_otg_core_if_t * core_if, int32_t val);
  67258. +extern int32_t dwc_otg_get_param_phy_type(dwc_otg_core_if_t * core_if);
  67259. +#define DWC_PHY_TYPE_PARAM_FS 0
  67260. +#define DWC_PHY_TYPE_PARAM_UTMI 1
  67261. +#define DWC_PHY_TYPE_PARAM_ULPI 2
  67262. +#define dwc_param_phy_type_default DWC_PHY_TYPE_PARAM_UTMI
  67263. +
  67264. +/**
  67265. + * Specifies the UTMI+ Data Width. This parameter is
  67266. + * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
  67267. + * PHY_TYPE, this parameter indicates the data width between
  67268. + * the MAC and the ULPI Wrapper.) Also, this parameter is
  67269. + * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
  67270. + * to "8 and 16 bits", meaning that the core has been
  67271. + * configured to work at either data path width.
  67272. + *
  67273. + * 8 or 16 bits (default 16)
  67274. + */
  67275. +extern int dwc_otg_set_param_phy_utmi_width(dwc_otg_core_if_t * core_if,
  67276. + int32_t val);
  67277. +extern int32_t dwc_otg_get_param_phy_utmi_width(dwc_otg_core_if_t * core_if);
  67278. +//#define dwc_param_phy_utmi_width_default 16
  67279. +#define dwc_param_phy_utmi_width_default 8 // Broadcom BCM2708
  67280. +
  67281. +/**
  67282. + * Specifies whether the ULPI operates at double or single
  67283. + * data rate. This parameter is only applicable if PHY_TYPE is
  67284. + * ULPI.
  67285. + *
  67286. + * 0 - single data rate ULPI interface with 8 bit wide data
  67287. + * bus (default)
  67288. + * 1 - double data rate ULPI interface with 4 bit wide data
  67289. + * bus
  67290. + */
  67291. +extern int dwc_otg_set_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if,
  67292. + int32_t val);
  67293. +extern int32_t dwc_otg_get_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if);
  67294. +#define dwc_param_phy_ulpi_ddr_default 0
  67295. +
  67296. +/**
  67297. + * Specifies whether to use the internal or external supply to
  67298. + * drive the vbus with a ULPI phy.
  67299. + */
  67300. +extern int dwc_otg_set_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if,
  67301. + int32_t val);
  67302. +extern int32_t dwc_otg_get_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if);
  67303. +#define DWC_PHY_ULPI_INTERNAL_VBUS 0
  67304. +#define DWC_PHY_ULPI_EXTERNAL_VBUS 1
  67305. +#define dwc_param_phy_ulpi_ext_vbus_default DWC_PHY_ULPI_INTERNAL_VBUS
  67306. +
  67307. +/**
  67308. + * Specifies whether to use the I2Cinterface for full speed PHY. This
  67309. + * parameter is only applicable if PHY_TYPE is FS.
  67310. + * 0 - No (default)
  67311. + * 1 - Yes
  67312. + */
  67313. +extern int dwc_otg_set_param_i2c_enable(dwc_otg_core_if_t * core_if,
  67314. + int32_t val);
  67315. +extern int32_t dwc_otg_get_param_i2c_enable(dwc_otg_core_if_t * core_if);
  67316. +#define dwc_param_i2c_enable_default 0
  67317. +
  67318. +extern int dwc_otg_set_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if,
  67319. + int32_t val);
  67320. +extern int32_t dwc_otg_get_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if);
  67321. +#define dwc_param_ulpi_fs_ls_default 0
  67322. +
  67323. +extern int dwc_otg_set_param_ts_dline(dwc_otg_core_if_t * core_if, int32_t val);
  67324. +extern int32_t dwc_otg_get_param_ts_dline(dwc_otg_core_if_t * core_if);
  67325. +#define dwc_param_ts_dline_default 0
  67326. +
  67327. +/**
  67328. + * Specifies whether dedicated transmit FIFOs are
  67329. + * enabled for non periodic IN endpoints in device mode
  67330. + * 0 - No
  67331. + * 1 - Yes
  67332. + */
  67333. +extern int dwc_otg_set_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if,
  67334. + int32_t val);
  67335. +extern int32_t dwc_otg_get_param_en_multiple_tx_fifo(dwc_otg_core_if_t *
  67336. + core_if);
  67337. +#define dwc_param_en_multiple_tx_fifo_default 1
  67338. +
  67339. +/** Number of 4-byte words in each of the Tx FIFOs in device
  67340. + * mode when dynamic FIFO sizing is enabled.
  67341. + * 4 to 768 (default 256)
  67342. + */
  67343. +extern int dwc_otg_set_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  67344. + int fifo_num, int32_t val);
  67345. +extern int32_t dwc_otg_get_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  67346. + int fifo_num);
  67347. +#define dwc_param_dev_tx_fifo_size_default 768
  67348. +
  67349. +/** Thresholding enable flag-
  67350. + * bit 0 - enable non-ISO Tx thresholding
  67351. + * bit 1 - enable ISO Tx thresholding
  67352. + * bit 2 - enable Rx thresholding
  67353. + */
  67354. +extern int dwc_otg_set_param_thr_ctl(dwc_otg_core_if_t * core_if, int32_t val);
  67355. +extern int32_t dwc_otg_get_thr_ctl(dwc_otg_core_if_t * core_if, int fifo_num);
  67356. +#define dwc_param_thr_ctl_default 0
  67357. +
  67358. +/** Thresholding length for Tx
  67359. + * FIFOs in 32 bit DWORDs
  67360. + */
  67361. +extern int dwc_otg_set_param_tx_thr_length(dwc_otg_core_if_t * core_if,
  67362. + int32_t val);
  67363. +extern int32_t dwc_otg_get_tx_thr_length(dwc_otg_core_if_t * core_if);
  67364. +#define dwc_param_tx_thr_length_default 64
  67365. +
  67366. +/** Thresholding length for Rx
  67367. + * FIFOs in 32 bit DWORDs
  67368. + */
  67369. +extern int dwc_otg_set_param_rx_thr_length(dwc_otg_core_if_t * core_if,
  67370. + int32_t val);
  67371. +extern int32_t dwc_otg_get_rx_thr_length(dwc_otg_core_if_t * core_if);
  67372. +#define dwc_param_rx_thr_length_default 64
  67373. +
  67374. +/**
  67375. + * Specifies whether LPM (Link Power Management) support is enabled
  67376. + */
  67377. +extern int dwc_otg_set_param_lpm_enable(dwc_otg_core_if_t * core_if,
  67378. + int32_t val);
  67379. +extern int32_t dwc_otg_get_param_lpm_enable(dwc_otg_core_if_t * core_if);
  67380. +#define dwc_param_lpm_enable_default 1
  67381. +
  67382. +/**
  67383. + * Specifies whether PTI enhancement is enabled
  67384. + */
  67385. +extern int dwc_otg_set_param_pti_enable(dwc_otg_core_if_t * core_if,
  67386. + int32_t val);
  67387. +extern int32_t dwc_otg_get_param_pti_enable(dwc_otg_core_if_t * core_if);
  67388. +#define dwc_param_pti_enable_default 0
  67389. +
  67390. +/**
  67391. + * Specifies whether MPI enhancement is enabled
  67392. + */
  67393. +extern int dwc_otg_set_param_mpi_enable(dwc_otg_core_if_t * core_if,
  67394. + int32_t val);
  67395. +extern int32_t dwc_otg_get_param_mpi_enable(dwc_otg_core_if_t * core_if);
  67396. +#define dwc_param_mpi_enable_default 0
  67397. +
  67398. +/**
  67399. + * Specifies whether ADP capability is enabled
  67400. + */
  67401. +extern int dwc_otg_set_param_adp_enable(dwc_otg_core_if_t * core_if,
  67402. + int32_t val);
  67403. +extern int32_t dwc_otg_get_param_adp_enable(dwc_otg_core_if_t * core_if);
  67404. +#define dwc_param_adp_enable_default 0
  67405. +
  67406. +/**
  67407. + * Specifies whether IC_USB capability is enabled
  67408. + */
  67409. +
  67410. +extern int dwc_otg_set_param_ic_usb_cap(dwc_otg_core_if_t * core_if,
  67411. + int32_t val);
  67412. +extern int32_t dwc_otg_get_param_ic_usb_cap(dwc_otg_core_if_t * core_if);
  67413. +#define dwc_param_ic_usb_cap_default 0
  67414. +
  67415. +extern int dwc_otg_set_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if,
  67416. + int32_t val);
  67417. +extern int32_t dwc_otg_get_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if);
  67418. +#define dwc_param_ahb_thr_ratio_default 0
  67419. +
  67420. +extern int dwc_otg_set_param_power_down(dwc_otg_core_if_t * core_if,
  67421. + int32_t val);
  67422. +extern int32_t dwc_otg_get_param_power_down(dwc_otg_core_if_t * core_if);
  67423. +#define dwc_param_power_down_default 0
  67424. +
  67425. +extern int dwc_otg_set_param_reload_ctl(dwc_otg_core_if_t * core_if,
  67426. + int32_t val);
  67427. +extern int32_t dwc_otg_get_param_reload_ctl(dwc_otg_core_if_t * core_if);
  67428. +#define dwc_param_reload_ctl_default 0
  67429. +
  67430. +extern int dwc_otg_set_param_dev_out_nak(dwc_otg_core_if_t * core_if,
  67431. + int32_t val);
  67432. +extern int32_t dwc_otg_get_param_dev_out_nak(dwc_otg_core_if_t * core_if);
  67433. +#define dwc_param_dev_out_nak_default 0
  67434. +
  67435. +extern int dwc_otg_set_param_cont_on_bna(dwc_otg_core_if_t * core_if,
  67436. + int32_t val);
  67437. +extern int32_t dwc_otg_get_param_cont_on_bna(dwc_otg_core_if_t * core_if);
  67438. +#define dwc_param_cont_on_bna_default 0
  67439. +
  67440. +extern int dwc_otg_set_param_ahb_single(dwc_otg_core_if_t * core_if,
  67441. + int32_t val);
  67442. +extern int32_t dwc_otg_get_param_ahb_single(dwc_otg_core_if_t * core_if);
  67443. +#define dwc_param_ahb_single_default 0
  67444. +
  67445. +extern int dwc_otg_set_param_otg_ver(dwc_otg_core_if_t * core_if, int32_t val);
  67446. +extern int32_t dwc_otg_get_param_otg_ver(dwc_otg_core_if_t * core_if);
  67447. +#define dwc_param_otg_ver_default 0
  67448. +
  67449. +/** @} */
  67450. +
  67451. +/** @name Access to registers and bit-fields */
  67452. +
  67453. +/**
  67454. + * Dump core registers and SPRAM
  67455. + */
  67456. +extern void dwc_otg_dump_dev_registers(dwc_otg_core_if_t * _core_if);
  67457. +extern void dwc_otg_dump_spram(dwc_otg_core_if_t * _core_if);
  67458. +extern void dwc_otg_dump_host_registers(dwc_otg_core_if_t * _core_if);
  67459. +extern void dwc_otg_dump_global_registers(dwc_otg_core_if_t * _core_if);
  67460. +
  67461. +/**
  67462. + * Get host negotiation status.
  67463. + */
  67464. +extern uint32_t dwc_otg_get_hnpstatus(dwc_otg_core_if_t * core_if);
  67465. +
  67466. +/**
  67467. + * Get srp status
  67468. + */
  67469. +extern uint32_t dwc_otg_get_srpstatus(dwc_otg_core_if_t * core_if);
  67470. +
  67471. +/**
  67472. + * Set hnpreq bit in the GOTGCTL register.
  67473. + */
  67474. +extern void dwc_otg_set_hnpreq(dwc_otg_core_if_t * core_if, uint32_t val);
  67475. +
  67476. +/**
  67477. + * Get Content of SNPSID register.
  67478. + */
  67479. +extern uint32_t dwc_otg_get_gsnpsid(dwc_otg_core_if_t * core_if);
  67480. +
  67481. +/**
  67482. + * Get current mode.
  67483. + * Returns 0 if in device mode, and 1 if in host mode.
  67484. + */
  67485. +extern uint32_t dwc_otg_get_mode(dwc_otg_core_if_t * core_if);
  67486. +
  67487. +/**
  67488. + * Get value of hnpcapable field in the GUSBCFG register
  67489. + */
  67490. +extern uint32_t dwc_otg_get_hnpcapable(dwc_otg_core_if_t * core_if);
  67491. +/**
  67492. + * Set value of hnpcapable field in the GUSBCFG register
  67493. + */
  67494. +extern void dwc_otg_set_hnpcapable(dwc_otg_core_if_t * core_if, uint32_t val);
  67495. +
  67496. +/**
  67497. + * Get value of srpcapable field in the GUSBCFG register
  67498. + */
  67499. +extern uint32_t dwc_otg_get_srpcapable(dwc_otg_core_if_t * core_if);
  67500. +/**
  67501. + * Set value of srpcapable field in the GUSBCFG register
  67502. + */
  67503. +extern void dwc_otg_set_srpcapable(dwc_otg_core_if_t * core_if, uint32_t val);
  67504. +
  67505. +/**
  67506. + * Get value of devspeed field in the DCFG register
  67507. + */
  67508. +extern uint32_t dwc_otg_get_devspeed(dwc_otg_core_if_t * core_if);
  67509. +/**
  67510. + * Set value of devspeed field in the DCFG register
  67511. + */
  67512. +extern void dwc_otg_set_devspeed(dwc_otg_core_if_t * core_if, uint32_t val);
  67513. +
  67514. +/**
  67515. + * Get the value of busconnected field from the HPRT0 register
  67516. + */
  67517. +extern uint32_t dwc_otg_get_busconnected(dwc_otg_core_if_t * core_if);
  67518. +
  67519. +/**
  67520. + * Gets the device enumeration Speed.
  67521. + */
  67522. +extern uint32_t dwc_otg_get_enumspeed(dwc_otg_core_if_t * core_if);
  67523. +
  67524. +/**
  67525. + * Get value of prtpwr field from the HPRT0 register
  67526. + */
  67527. +extern uint32_t dwc_otg_get_prtpower(dwc_otg_core_if_t * core_if);
  67528. +
  67529. +/**
  67530. + * Get value of flag indicating core state - hibernated or not
  67531. + */
  67532. +extern uint32_t dwc_otg_get_core_state(dwc_otg_core_if_t * core_if);
  67533. +
  67534. +/**
  67535. + * Set value of prtpwr field from the HPRT0 register
  67536. + */
  67537. +extern void dwc_otg_set_prtpower(dwc_otg_core_if_t * core_if, uint32_t val);
  67538. +
  67539. +/**
  67540. + * Get value of prtsusp field from the HPRT0 regsiter
  67541. + */
  67542. +extern uint32_t dwc_otg_get_prtsuspend(dwc_otg_core_if_t * core_if);
  67543. +/**
  67544. + * Set value of prtpwr field from the HPRT0 register
  67545. + */
  67546. +extern void dwc_otg_set_prtsuspend(dwc_otg_core_if_t * core_if, uint32_t val);
  67547. +
  67548. +/**
  67549. + * Get value of ModeChTimEn field from the HCFG regsiter
  67550. + */
  67551. +extern uint32_t dwc_otg_get_mode_ch_tim(dwc_otg_core_if_t * core_if);
  67552. +/**
  67553. + * Set value of ModeChTimEn field from the HCFG regsiter
  67554. + */
  67555. +extern void dwc_otg_set_mode_ch_tim(dwc_otg_core_if_t * core_if, uint32_t val);
  67556. +
  67557. +/**
  67558. + * Get value of Fram Interval field from the HFIR regsiter
  67559. + */
  67560. +extern uint32_t dwc_otg_get_fr_interval(dwc_otg_core_if_t * core_if);
  67561. +/**
  67562. + * Set value of Frame Interval field from the HFIR regsiter
  67563. + */
  67564. +extern void dwc_otg_set_fr_interval(dwc_otg_core_if_t * core_if, uint32_t val);
  67565. +
  67566. +/**
  67567. + * Set value of prtres field from the HPRT0 register
  67568. + *FIXME Remove?
  67569. + */
  67570. +extern void dwc_otg_set_prtresume(dwc_otg_core_if_t * core_if, uint32_t val);
  67571. +
  67572. +/**
  67573. + * Get value of rmtwkupsig bit in DCTL register
  67574. + */
  67575. +extern uint32_t dwc_otg_get_remotewakesig(dwc_otg_core_if_t * core_if);
  67576. +
  67577. +/**
  67578. + * Get value of prt_sleep_sts field from the GLPMCFG register
  67579. + */
  67580. +extern uint32_t dwc_otg_get_lpm_portsleepstatus(dwc_otg_core_if_t * core_if);
  67581. +
  67582. +/**
  67583. + * Get value of rem_wkup_en field from the GLPMCFG register
  67584. + */
  67585. +extern uint32_t dwc_otg_get_lpm_remotewakeenabled(dwc_otg_core_if_t * core_if);
  67586. +
  67587. +/**
  67588. + * Get value of appl_resp field from the GLPMCFG register
  67589. + */
  67590. +extern uint32_t dwc_otg_get_lpmresponse(dwc_otg_core_if_t * core_if);
  67591. +/**
  67592. + * Set value of appl_resp field from the GLPMCFG register
  67593. + */
  67594. +extern void dwc_otg_set_lpmresponse(dwc_otg_core_if_t * core_if, uint32_t val);
  67595. +
  67596. +/**
  67597. + * Get value of hsic_connect field from the GLPMCFG register
  67598. + */
  67599. +extern uint32_t dwc_otg_get_hsic_connect(dwc_otg_core_if_t * core_if);
  67600. +/**
  67601. + * Set value of hsic_connect field from the GLPMCFG register
  67602. + */
  67603. +extern void dwc_otg_set_hsic_connect(dwc_otg_core_if_t * core_if, uint32_t val);
  67604. +
  67605. +/**
  67606. + * Get value of inv_sel_hsic field from the GLPMCFG register.
  67607. + */
  67608. +extern uint32_t dwc_otg_get_inv_sel_hsic(dwc_otg_core_if_t * core_if);
  67609. +/**
  67610. + * Set value of inv_sel_hsic field from the GLPMFG register.
  67611. + */
  67612. +extern void dwc_otg_set_inv_sel_hsic(dwc_otg_core_if_t * core_if, uint32_t val);
  67613. +
  67614. +/*
  67615. + * Some functions for accessing registers
  67616. + */
  67617. +
  67618. +/**
  67619. + * GOTGCTL register
  67620. + */
  67621. +extern uint32_t dwc_otg_get_gotgctl(dwc_otg_core_if_t * core_if);
  67622. +extern void dwc_otg_set_gotgctl(dwc_otg_core_if_t * core_if, uint32_t val);
  67623. +
  67624. +/**
  67625. + * GUSBCFG register
  67626. + */
  67627. +extern uint32_t dwc_otg_get_gusbcfg(dwc_otg_core_if_t * core_if);
  67628. +extern void dwc_otg_set_gusbcfg(dwc_otg_core_if_t * core_if, uint32_t val);
  67629. +
  67630. +/**
  67631. + * GRXFSIZ register
  67632. + */
  67633. +extern uint32_t dwc_otg_get_grxfsiz(dwc_otg_core_if_t * core_if);
  67634. +extern void dwc_otg_set_grxfsiz(dwc_otg_core_if_t * core_if, uint32_t val);
  67635. +
  67636. +/**
  67637. + * GNPTXFSIZ register
  67638. + */
  67639. +extern uint32_t dwc_otg_get_gnptxfsiz(dwc_otg_core_if_t * core_if);
  67640. +extern void dwc_otg_set_gnptxfsiz(dwc_otg_core_if_t * core_if, uint32_t val);
  67641. +
  67642. +extern uint32_t dwc_otg_get_gpvndctl(dwc_otg_core_if_t * core_if);
  67643. +extern void dwc_otg_set_gpvndctl(dwc_otg_core_if_t * core_if, uint32_t val);
  67644. +
  67645. +/**
  67646. + * GGPIO register
  67647. + */
  67648. +extern uint32_t dwc_otg_get_ggpio(dwc_otg_core_if_t * core_if);
  67649. +extern void dwc_otg_set_ggpio(dwc_otg_core_if_t * core_if, uint32_t val);
  67650. +
  67651. +/**
  67652. + * GUID register
  67653. + */
  67654. +extern uint32_t dwc_otg_get_guid(dwc_otg_core_if_t * core_if);
  67655. +extern void dwc_otg_set_guid(dwc_otg_core_if_t * core_if, uint32_t val);
  67656. +
  67657. +/**
  67658. + * HPRT0 register
  67659. + */
  67660. +extern uint32_t dwc_otg_get_hprt0(dwc_otg_core_if_t * core_if);
  67661. +extern void dwc_otg_set_hprt0(dwc_otg_core_if_t * core_if, uint32_t val);
  67662. +
  67663. +/**
  67664. + * GHPTXFSIZE
  67665. + */
  67666. +extern uint32_t dwc_otg_get_hptxfsiz(dwc_otg_core_if_t * core_if);
  67667. +
  67668. +/** @} */
  67669. +
  67670. +#endif /* __DWC_CORE_IF_H__ */
  67671. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_dbg.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_dbg.h
  67672. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_dbg.h 1970-01-01 01:00:00.000000000 +0100
  67673. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_dbg.h 2014-07-07 10:45:43.000000000 +0200
  67674. @@ -0,0 +1,117 @@
  67675. +/* ==========================================================================
  67676. + *
  67677. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  67678. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  67679. + * otherwise expressly agreed to in writing between Synopsys and you.
  67680. + *
  67681. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  67682. + * any End User Software License Agreement or Agreement for Licensed Product
  67683. + * with Synopsys or any supplement thereto. You are permitted to use and
  67684. + * redistribute this Software in source and binary forms, with or without
  67685. + * modification, provided that redistributions of source code must retain this
  67686. + * notice. You may not view, use, disclose, copy or distribute this file or
  67687. + * any information contained herein except pursuant to this license grant from
  67688. + * Synopsys. If you do not agree with this notice, including the disclaimer
  67689. + * below, then you are not authorized to use the Software.
  67690. + *
  67691. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  67692. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  67693. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  67694. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  67695. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  67696. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  67697. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  67698. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  67699. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  67700. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  67701. + * DAMAGE.
  67702. + * ========================================================================== */
  67703. +
  67704. +#ifndef __DWC_OTG_DBG_H__
  67705. +#define __DWC_OTG_DBG_H__
  67706. +
  67707. +/** @file
  67708. + * This file defines debug levels.
  67709. + * Debugging support vanishes in non-debug builds.
  67710. + */
  67711. +
  67712. +/**
  67713. + * The Debug Level bit-mask variable.
  67714. + */
  67715. +extern uint32_t g_dbg_lvl;
  67716. +/**
  67717. + * Set the Debug Level variable.
  67718. + */
  67719. +static inline uint32_t SET_DEBUG_LEVEL(const uint32_t new)
  67720. +{
  67721. + uint32_t old = g_dbg_lvl;
  67722. + g_dbg_lvl = new;
  67723. + return old;
  67724. +}
  67725. +
  67726. +#define DBG_USER (0x1)
  67727. +/** When debug level has the DBG_CIL bit set, display CIL Debug messages. */
  67728. +#define DBG_CIL (0x2)
  67729. +/** When debug level has the DBG_CILV bit set, display CIL Verbose debug
  67730. + * messages */
  67731. +#define DBG_CILV (0x20)
  67732. +/** When debug level has the DBG_PCD bit set, display PCD (Device) debug
  67733. + * messages */
  67734. +#define DBG_PCD (0x4)
  67735. +/** When debug level has the DBG_PCDV set, display PCD (Device) Verbose debug
  67736. + * messages */
  67737. +#define DBG_PCDV (0x40)
  67738. +/** When debug level has the DBG_HCD bit set, display Host debug messages */
  67739. +#define DBG_HCD (0x8)
  67740. +/** When debug level has the DBG_HCDV bit set, display Verbose Host debug
  67741. + * messages */
  67742. +#define DBG_HCDV (0x80)
  67743. +/** When debug level has the DBG_HCD_URB bit set, display enqueued URBs in host
  67744. + * mode. */
  67745. +#define DBG_HCD_URB (0x800)
  67746. +/** When debug level has the DBG_HCDI bit set, display host interrupt
  67747. + * messages. */
  67748. +#define DBG_HCDI (0x1000)
  67749. +
  67750. +/** When debug level has any bit set, display debug messages */
  67751. +#define DBG_ANY (0xFF)
  67752. +
  67753. +/** All debug messages off */
  67754. +#define DBG_OFF 0
  67755. +
  67756. +/** Prefix string for DWC_DEBUG print macros. */
  67757. +#define USB_DWC "DWC_otg: "
  67758. +
  67759. +/**
  67760. + * Print a debug message when the Global debug level variable contains
  67761. + * the bit defined in <code>lvl</code>.
  67762. + *
  67763. + * @param[in] lvl - Debug level, use one of the DBG_ constants above.
  67764. + * @param[in] x - like printf
  67765. + *
  67766. + * Example:<p>
  67767. + * <code>
  67768. + * DWC_DEBUGPL( DBG_ANY, "%s(%p)\n", __func__, _reg_base_addr);
  67769. + * </code>
  67770. + * <br>
  67771. + * results in:<br>
  67772. + * <code>
  67773. + * usb-DWC_otg: dwc_otg_cil_init(ca867000)
  67774. + * </code>
  67775. + */
  67776. +#ifdef DEBUG
  67777. +
  67778. +# define DWC_DEBUGPL(lvl, x...) do{ if ((lvl)&g_dbg_lvl)__DWC_DEBUG(USB_DWC x ); }while(0)
  67779. +# define DWC_DEBUGP(x...) DWC_DEBUGPL(DBG_ANY, x )
  67780. +
  67781. +# define CHK_DEBUG_LEVEL(level) ((level) & g_dbg_lvl)
  67782. +
  67783. +#else
  67784. +
  67785. +# define DWC_DEBUGPL(lvl, x...) do{}while(0)
  67786. +# define DWC_DEBUGP(x...)
  67787. +
  67788. +# define CHK_DEBUG_LEVEL(level) (0)
  67789. +
  67790. +#endif /*DEBUG*/
  67791. +#endif
  67792. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_driver.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_driver.c
  67793. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_driver.c 1970-01-01 01:00:00.000000000 +0100
  67794. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_driver.c 2014-07-07 10:45:43.000000000 +0200
  67795. @@ -0,0 +1,1749 @@
  67796. +/* ==========================================================================
  67797. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_driver.c $
  67798. + * $Revision: #92 $
  67799. + * $Date: 2012/08/10 $
  67800. + * $Change: 2047372 $
  67801. + *
  67802. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  67803. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  67804. + * otherwise expressly agreed to in writing between Synopsys and you.
  67805. + *
  67806. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  67807. + * any End User Software License Agreement or Agreement for Licensed Product
  67808. + * with Synopsys or any supplement thereto. You are permitted to use and
  67809. + * redistribute this Software in source and binary forms, with or without
  67810. + * modification, provided that redistributions of source code must retain this
  67811. + * notice. You may not view, use, disclose, copy or distribute this file or
  67812. + * any information contained herein except pursuant to this license grant from
  67813. + * Synopsys. If you do not agree with this notice, including the disclaimer
  67814. + * below, then you are not authorized to use the Software.
  67815. + *
  67816. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  67817. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  67818. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  67819. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  67820. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  67821. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  67822. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  67823. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  67824. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  67825. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  67826. + * DAMAGE.
  67827. + * ========================================================================== */
  67828. +
  67829. +/** @file
  67830. + * The dwc_otg_driver module provides the initialization and cleanup entry
  67831. + * points for the DWC_otg driver. This module will be dynamically installed
  67832. + * after Linux is booted using the insmod command. When the module is
  67833. + * installed, the dwc_otg_driver_init function is called. When the module is
  67834. + * removed (using rmmod), the dwc_otg_driver_cleanup function is called.
  67835. + *
  67836. + * This module also defines a data structure for the dwc_otg_driver, which is
  67837. + * used in conjunction with the standard ARM lm_device structure. These
  67838. + * structures allow the OTG driver to comply with the standard Linux driver
  67839. + * model in which devices and drivers are registered with a bus driver. This
  67840. + * has the benefit that Linux can expose attributes of the driver and device
  67841. + * in its special sysfs file system. Users can then read or write files in
  67842. + * this file system to perform diagnostics on the driver components or the
  67843. + * device.
  67844. + */
  67845. +
  67846. +#include "dwc_otg_os_dep.h"
  67847. +#include "dwc_os.h"
  67848. +#include "dwc_otg_dbg.h"
  67849. +#include "dwc_otg_driver.h"
  67850. +#include "dwc_otg_attr.h"
  67851. +#include "dwc_otg_core_if.h"
  67852. +#include "dwc_otg_pcd_if.h"
  67853. +#include "dwc_otg_hcd_if.h"
  67854. +#include "dwc_otg_fiq_fsm.h"
  67855. +
  67856. +#define DWC_DRIVER_VERSION "3.00a 10-AUG-2012"
  67857. +#define DWC_DRIVER_DESC "HS OTG USB Controller driver"
  67858. +
  67859. +bool microframe_schedule=true;
  67860. +
  67861. +static const char dwc_driver_name[] = "dwc_otg";
  67862. +
  67863. +
  67864. +extern int pcd_init(
  67865. +#ifdef LM_INTERFACE
  67866. + struct lm_device *_dev
  67867. +#elif defined(PCI_INTERFACE)
  67868. + struct pci_dev *_dev
  67869. +#elif defined(PLATFORM_INTERFACE)
  67870. + struct platform_device *dev
  67871. +#endif
  67872. + );
  67873. +extern int hcd_init(
  67874. +#ifdef LM_INTERFACE
  67875. + struct lm_device *_dev
  67876. +#elif defined(PCI_INTERFACE)
  67877. + struct pci_dev *_dev
  67878. +#elif defined(PLATFORM_INTERFACE)
  67879. + struct platform_device *dev
  67880. +#endif
  67881. + );
  67882. +
  67883. +extern int pcd_remove(
  67884. +#ifdef LM_INTERFACE
  67885. + struct lm_device *_dev
  67886. +#elif defined(PCI_INTERFACE)
  67887. + struct pci_dev *_dev
  67888. +#elif defined(PLATFORM_INTERFACE)
  67889. + struct platform_device *_dev
  67890. +#endif
  67891. + );
  67892. +
  67893. +extern void hcd_remove(
  67894. +#ifdef LM_INTERFACE
  67895. + struct lm_device *_dev
  67896. +#elif defined(PCI_INTERFACE)
  67897. + struct pci_dev *_dev
  67898. +#elif defined(PLATFORM_INTERFACE)
  67899. + struct platform_device *_dev
  67900. +#endif
  67901. + );
  67902. +
  67903. +extern void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host);
  67904. +
  67905. +/*-------------------------------------------------------------------------*/
  67906. +/* Encapsulate the module parameter settings */
  67907. +
  67908. +struct dwc_otg_driver_module_params {
  67909. + int32_t opt;
  67910. + int32_t otg_cap;
  67911. + int32_t dma_enable;
  67912. + int32_t dma_desc_enable;
  67913. + int32_t dma_burst_size;
  67914. + int32_t speed;
  67915. + int32_t host_support_fs_ls_low_power;
  67916. + int32_t host_ls_low_power_phy_clk;
  67917. + int32_t enable_dynamic_fifo;
  67918. + int32_t data_fifo_size;
  67919. + int32_t dev_rx_fifo_size;
  67920. + int32_t dev_nperio_tx_fifo_size;
  67921. + uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
  67922. + int32_t host_rx_fifo_size;
  67923. + int32_t host_nperio_tx_fifo_size;
  67924. + int32_t host_perio_tx_fifo_size;
  67925. + int32_t max_transfer_size;
  67926. + int32_t max_packet_count;
  67927. + int32_t host_channels;
  67928. + int32_t dev_endpoints;
  67929. + int32_t phy_type;
  67930. + int32_t phy_utmi_width;
  67931. + int32_t phy_ulpi_ddr;
  67932. + int32_t phy_ulpi_ext_vbus;
  67933. + int32_t i2c_enable;
  67934. + int32_t ulpi_fs_ls;
  67935. + int32_t ts_dline;
  67936. + int32_t en_multiple_tx_fifo;
  67937. + uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
  67938. + uint32_t thr_ctl;
  67939. + uint32_t tx_thr_length;
  67940. + uint32_t rx_thr_length;
  67941. + int32_t pti_enable;
  67942. + int32_t mpi_enable;
  67943. + int32_t lpm_enable;
  67944. + int32_t ic_usb_cap;
  67945. + int32_t ahb_thr_ratio;
  67946. + int32_t power_down;
  67947. + int32_t reload_ctl;
  67948. + int32_t dev_out_nak;
  67949. + int32_t cont_on_bna;
  67950. + int32_t ahb_single;
  67951. + int32_t otg_ver;
  67952. + int32_t adp_enable;
  67953. +};
  67954. +
  67955. +static struct dwc_otg_driver_module_params dwc_otg_module_params = {
  67956. + .opt = -1,
  67957. + .otg_cap = -1,
  67958. + .dma_enable = -1,
  67959. + .dma_desc_enable = -1,
  67960. + .dma_burst_size = -1,
  67961. + .speed = -1,
  67962. + .host_support_fs_ls_low_power = -1,
  67963. + .host_ls_low_power_phy_clk = -1,
  67964. + .enable_dynamic_fifo = -1,
  67965. + .data_fifo_size = -1,
  67966. + .dev_rx_fifo_size = -1,
  67967. + .dev_nperio_tx_fifo_size = -1,
  67968. + .dev_perio_tx_fifo_size = {
  67969. + /* dev_perio_tx_fifo_size_1 */
  67970. + -1,
  67971. + -1,
  67972. + -1,
  67973. + -1,
  67974. + -1,
  67975. + -1,
  67976. + -1,
  67977. + -1,
  67978. + -1,
  67979. + -1,
  67980. + -1,
  67981. + -1,
  67982. + -1,
  67983. + -1,
  67984. + -1
  67985. + /* 15 */
  67986. + },
  67987. + .host_rx_fifo_size = -1,
  67988. + .host_nperio_tx_fifo_size = -1,
  67989. + .host_perio_tx_fifo_size = -1,
  67990. + .max_transfer_size = -1,
  67991. + .max_packet_count = -1,
  67992. + .host_channels = -1,
  67993. + .dev_endpoints = -1,
  67994. + .phy_type = -1,
  67995. + .phy_utmi_width = -1,
  67996. + .phy_ulpi_ddr = -1,
  67997. + .phy_ulpi_ext_vbus = -1,
  67998. + .i2c_enable = -1,
  67999. + .ulpi_fs_ls = -1,
  68000. + .ts_dline = -1,
  68001. + .en_multiple_tx_fifo = -1,
  68002. + .dev_tx_fifo_size = {
  68003. + /* dev_tx_fifo_size */
  68004. + -1,
  68005. + -1,
  68006. + -1,
  68007. + -1,
  68008. + -1,
  68009. + -1,
  68010. + -1,
  68011. + -1,
  68012. + -1,
  68013. + -1,
  68014. + -1,
  68015. + -1,
  68016. + -1,
  68017. + -1,
  68018. + -1
  68019. + /* 15 */
  68020. + },
  68021. + .thr_ctl = -1,
  68022. + .tx_thr_length = -1,
  68023. + .rx_thr_length = -1,
  68024. + .pti_enable = -1,
  68025. + .mpi_enable = -1,
  68026. + .lpm_enable = 0,
  68027. + .ic_usb_cap = -1,
  68028. + .ahb_thr_ratio = -1,
  68029. + .power_down = -1,
  68030. + .reload_ctl = -1,
  68031. + .dev_out_nak = -1,
  68032. + .cont_on_bna = -1,
  68033. + .ahb_single = -1,
  68034. + .otg_ver = -1,
  68035. + .adp_enable = -1,
  68036. +};
  68037. +
  68038. +//Global variable to switch the fiq fix on or off
  68039. +bool fiq_enable = 1;
  68040. +// Global variable to enable the split transaction fix
  68041. +bool fiq_fsm_enable = true;
  68042. +//Bulk split-transaction NAK holdoff in microframes
  68043. +uint16_t nak_holdoff = 8;
  68044. +
  68045. +unsigned short fiq_fsm_mask = 0x07;
  68046. +
  68047. +/**
  68048. + * This function shows the Driver Version.
  68049. + */
  68050. +static ssize_t version_show(struct device_driver *dev, char *buf)
  68051. +{
  68052. + return snprintf(buf, sizeof(DWC_DRIVER_VERSION) + 2, "%s\n",
  68053. + DWC_DRIVER_VERSION);
  68054. +}
  68055. +
  68056. +static DRIVER_ATTR(version, S_IRUGO, version_show, NULL);
  68057. +
  68058. +/**
  68059. + * Global Debug Level Mask.
  68060. + */
  68061. +uint32_t g_dbg_lvl = 0; /* OFF */
  68062. +
  68063. +/**
  68064. + * This function shows the driver Debug Level.
  68065. + */
  68066. +static ssize_t dbg_level_show(struct device_driver *drv, char *buf)
  68067. +{
  68068. + return sprintf(buf, "0x%0x\n", g_dbg_lvl);
  68069. +}
  68070. +
  68071. +/**
  68072. + * This function stores the driver Debug Level.
  68073. + */
  68074. +static ssize_t dbg_level_store(struct device_driver *drv, const char *buf,
  68075. + size_t count)
  68076. +{
  68077. + g_dbg_lvl = simple_strtoul(buf, NULL, 16);
  68078. + return count;
  68079. +}
  68080. +
  68081. +static DRIVER_ATTR(debuglevel, S_IRUGO | S_IWUSR, dbg_level_show,
  68082. + dbg_level_store);
  68083. +
  68084. +/**
  68085. + * This function is called during module intialization
  68086. + * to pass module parameters to the DWC_OTG CORE.
  68087. + */
  68088. +static int set_parameters(dwc_otg_core_if_t * core_if)
  68089. +{
  68090. + int retval = 0;
  68091. + int i;
  68092. +
  68093. + if (dwc_otg_module_params.otg_cap != -1) {
  68094. + retval +=
  68095. + dwc_otg_set_param_otg_cap(core_if,
  68096. + dwc_otg_module_params.otg_cap);
  68097. + }
  68098. + if (dwc_otg_module_params.dma_enable != -1) {
  68099. + retval +=
  68100. + dwc_otg_set_param_dma_enable(core_if,
  68101. + dwc_otg_module_params.
  68102. + dma_enable);
  68103. + }
  68104. + if (dwc_otg_module_params.dma_desc_enable != -1) {
  68105. + retval +=
  68106. + dwc_otg_set_param_dma_desc_enable(core_if,
  68107. + dwc_otg_module_params.
  68108. + dma_desc_enable);
  68109. + }
  68110. + if (dwc_otg_module_params.opt != -1) {
  68111. + retval +=
  68112. + dwc_otg_set_param_opt(core_if, dwc_otg_module_params.opt);
  68113. + }
  68114. + if (dwc_otg_module_params.dma_burst_size != -1) {
  68115. + retval +=
  68116. + dwc_otg_set_param_dma_burst_size(core_if,
  68117. + dwc_otg_module_params.
  68118. + dma_burst_size);
  68119. + }
  68120. + if (dwc_otg_module_params.host_support_fs_ls_low_power != -1) {
  68121. + retval +=
  68122. + dwc_otg_set_param_host_support_fs_ls_low_power(core_if,
  68123. + dwc_otg_module_params.
  68124. + host_support_fs_ls_low_power);
  68125. + }
  68126. + if (dwc_otg_module_params.enable_dynamic_fifo != -1) {
  68127. + retval +=
  68128. + dwc_otg_set_param_enable_dynamic_fifo(core_if,
  68129. + dwc_otg_module_params.
  68130. + enable_dynamic_fifo);
  68131. + }
  68132. + if (dwc_otg_module_params.data_fifo_size != -1) {
  68133. + retval +=
  68134. + dwc_otg_set_param_data_fifo_size(core_if,
  68135. + dwc_otg_module_params.
  68136. + data_fifo_size);
  68137. + }
  68138. + if (dwc_otg_module_params.dev_rx_fifo_size != -1) {
  68139. + retval +=
  68140. + dwc_otg_set_param_dev_rx_fifo_size(core_if,
  68141. + dwc_otg_module_params.
  68142. + dev_rx_fifo_size);
  68143. + }
  68144. + if (dwc_otg_module_params.dev_nperio_tx_fifo_size != -1) {
  68145. + retval +=
  68146. + dwc_otg_set_param_dev_nperio_tx_fifo_size(core_if,
  68147. + dwc_otg_module_params.
  68148. + dev_nperio_tx_fifo_size);
  68149. + }
  68150. + if (dwc_otg_module_params.host_rx_fifo_size != -1) {
  68151. + retval +=
  68152. + dwc_otg_set_param_host_rx_fifo_size(core_if,
  68153. + dwc_otg_module_params.host_rx_fifo_size);
  68154. + }
  68155. + if (dwc_otg_module_params.host_nperio_tx_fifo_size != -1) {
  68156. + retval +=
  68157. + dwc_otg_set_param_host_nperio_tx_fifo_size(core_if,
  68158. + dwc_otg_module_params.
  68159. + host_nperio_tx_fifo_size);
  68160. + }
  68161. + if (dwc_otg_module_params.host_perio_tx_fifo_size != -1) {
  68162. + retval +=
  68163. + dwc_otg_set_param_host_perio_tx_fifo_size(core_if,
  68164. + dwc_otg_module_params.
  68165. + host_perio_tx_fifo_size);
  68166. + }
  68167. + if (dwc_otg_module_params.max_transfer_size != -1) {
  68168. + retval +=
  68169. + dwc_otg_set_param_max_transfer_size(core_if,
  68170. + dwc_otg_module_params.
  68171. + max_transfer_size);
  68172. + }
  68173. + if (dwc_otg_module_params.max_packet_count != -1) {
  68174. + retval +=
  68175. + dwc_otg_set_param_max_packet_count(core_if,
  68176. + dwc_otg_module_params.
  68177. + max_packet_count);
  68178. + }
  68179. + if (dwc_otg_module_params.host_channels != -1) {
  68180. + retval +=
  68181. + dwc_otg_set_param_host_channels(core_if,
  68182. + dwc_otg_module_params.
  68183. + host_channels);
  68184. + }
  68185. + if (dwc_otg_module_params.dev_endpoints != -1) {
  68186. + retval +=
  68187. + dwc_otg_set_param_dev_endpoints(core_if,
  68188. + dwc_otg_module_params.
  68189. + dev_endpoints);
  68190. + }
  68191. + if (dwc_otg_module_params.phy_type != -1) {
  68192. + retval +=
  68193. + dwc_otg_set_param_phy_type(core_if,
  68194. + dwc_otg_module_params.phy_type);
  68195. + }
  68196. + if (dwc_otg_module_params.speed != -1) {
  68197. + retval +=
  68198. + dwc_otg_set_param_speed(core_if,
  68199. + dwc_otg_module_params.speed);
  68200. + }
  68201. + if (dwc_otg_module_params.host_ls_low_power_phy_clk != -1) {
  68202. + retval +=
  68203. + dwc_otg_set_param_host_ls_low_power_phy_clk(core_if,
  68204. + dwc_otg_module_params.
  68205. + host_ls_low_power_phy_clk);
  68206. + }
  68207. + if (dwc_otg_module_params.phy_ulpi_ddr != -1) {
  68208. + retval +=
  68209. + dwc_otg_set_param_phy_ulpi_ddr(core_if,
  68210. + dwc_otg_module_params.
  68211. + phy_ulpi_ddr);
  68212. + }
  68213. + if (dwc_otg_module_params.phy_ulpi_ext_vbus != -1) {
  68214. + retval +=
  68215. + dwc_otg_set_param_phy_ulpi_ext_vbus(core_if,
  68216. + dwc_otg_module_params.
  68217. + phy_ulpi_ext_vbus);
  68218. + }
  68219. + if (dwc_otg_module_params.phy_utmi_width != -1) {
  68220. + retval +=
  68221. + dwc_otg_set_param_phy_utmi_width(core_if,
  68222. + dwc_otg_module_params.
  68223. + phy_utmi_width);
  68224. + }
  68225. + if (dwc_otg_module_params.ulpi_fs_ls != -1) {
  68226. + retval +=
  68227. + dwc_otg_set_param_ulpi_fs_ls(core_if,
  68228. + dwc_otg_module_params.ulpi_fs_ls);
  68229. + }
  68230. + if (dwc_otg_module_params.ts_dline != -1) {
  68231. + retval +=
  68232. + dwc_otg_set_param_ts_dline(core_if,
  68233. + dwc_otg_module_params.ts_dline);
  68234. + }
  68235. + if (dwc_otg_module_params.i2c_enable != -1) {
  68236. + retval +=
  68237. + dwc_otg_set_param_i2c_enable(core_if,
  68238. + dwc_otg_module_params.
  68239. + i2c_enable);
  68240. + }
  68241. + if (dwc_otg_module_params.en_multiple_tx_fifo != -1) {
  68242. + retval +=
  68243. + dwc_otg_set_param_en_multiple_tx_fifo(core_if,
  68244. + dwc_otg_module_params.
  68245. + en_multiple_tx_fifo);
  68246. + }
  68247. + for (i = 0; i < 15; i++) {
  68248. + if (dwc_otg_module_params.dev_perio_tx_fifo_size[i] != -1) {
  68249. + retval +=
  68250. + dwc_otg_set_param_dev_perio_tx_fifo_size(core_if,
  68251. + dwc_otg_module_params.
  68252. + dev_perio_tx_fifo_size
  68253. + [i], i);
  68254. + }
  68255. + }
  68256. +
  68257. + for (i = 0; i < 15; i++) {
  68258. + if (dwc_otg_module_params.dev_tx_fifo_size[i] != -1) {
  68259. + retval += dwc_otg_set_param_dev_tx_fifo_size(core_if,
  68260. + dwc_otg_module_params.
  68261. + dev_tx_fifo_size
  68262. + [i], i);
  68263. + }
  68264. + }
  68265. + if (dwc_otg_module_params.thr_ctl != -1) {
  68266. + retval +=
  68267. + dwc_otg_set_param_thr_ctl(core_if,
  68268. + dwc_otg_module_params.thr_ctl);
  68269. + }
  68270. + if (dwc_otg_module_params.mpi_enable != -1) {
  68271. + retval +=
  68272. + dwc_otg_set_param_mpi_enable(core_if,
  68273. + dwc_otg_module_params.
  68274. + mpi_enable);
  68275. + }
  68276. + if (dwc_otg_module_params.pti_enable != -1) {
  68277. + retval +=
  68278. + dwc_otg_set_param_pti_enable(core_if,
  68279. + dwc_otg_module_params.
  68280. + pti_enable);
  68281. + }
  68282. + if (dwc_otg_module_params.lpm_enable != -1) {
  68283. + retval +=
  68284. + dwc_otg_set_param_lpm_enable(core_if,
  68285. + dwc_otg_module_params.
  68286. + lpm_enable);
  68287. + }
  68288. + if (dwc_otg_module_params.ic_usb_cap != -1) {
  68289. + retval +=
  68290. + dwc_otg_set_param_ic_usb_cap(core_if,
  68291. + dwc_otg_module_params.
  68292. + ic_usb_cap);
  68293. + }
  68294. + if (dwc_otg_module_params.tx_thr_length != -1) {
  68295. + retval +=
  68296. + dwc_otg_set_param_tx_thr_length(core_if,
  68297. + dwc_otg_module_params.tx_thr_length);
  68298. + }
  68299. + if (dwc_otg_module_params.rx_thr_length != -1) {
  68300. + retval +=
  68301. + dwc_otg_set_param_rx_thr_length(core_if,
  68302. + dwc_otg_module_params.
  68303. + rx_thr_length);
  68304. + }
  68305. + if (dwc_otg_module_params.ahb_thr_ratio != -1) {
  68306. + retval +=
  68307. + dwc_otg_set_param_ahb_thr_ratio(core_if,
  68308. + dwc_otg_module_params.ahb_thr_ratio);
  68309. + }
  68310. + if (dwc_otg_module_params.power_down != -1) {
  68311. + retval +=
  68312. + dwc_otg_set_param_power_down(core_if,
  68313. + dwc_otg_module_params.power_down);
  68314. + }
  68315. + if (dwc_otg_module_params.reload_ctl != -1) {
  68316. + retval +=
  68317. + dwc_otg_set_param_reload_ctl(core_if,
  68318. + dwc_otg_module_params.reload_ctl);
  68319. + }
  68320. +
  68321. + if (dwc_otg_module_params.dev_out_nak != -1) {
  68322. + retval +=
  68323. + dwc_otg_set_param_dev_out_nak(core_if,
  68324. + dwc_otg_module_params.dev_out_nak);
  68325. + }
  68326. +
  68327. + if (dwc_otg_module_params.cont_on_bna != -1) {
  68328. + retval +=
  68329. + dwc_otg_set_param_cont_on_bna(core_if,
  68330. + dwc_otg_module_params.cont_on_bna);
  68331. + }
  68332. +
  68333. + if (dwc_otg_module_params.ahb_single != -1) {
  68334. + retval +=
  68335. + dwc_otg_set_param_ahb_single(core_if,
  68336. + dwc_otg_module_params.ahb_single);
  68337. + }
  68338. +
  68339. + if (dwc_otg_module_params.otg_ver != -1) {
  68340. + retval +=
  68341. + dwc_otg_set_param_otg_ver(core_if,
  68342. + dwc_otg_module_params.otg_ver);
  68343. + }
  68344. + if (dwc_otg_module_params.adp_enable != -1) {
  68345. + retval +=
  68346. + dwc_otg_set_param_adp_enable(core_if,
  68347. + dwc_otg_module_params.
  68348. + adp_enable);
  68349. + }
  68350. + return retval;
  68351. +}
  68352. +
  68353. +/**
  68354. + * This function is the top level interrupt handler for the Common
  68355. + * (Device and host modes) interrupts.
  68356. + */
  68357. +static irqreturn_t dwc_otg_common_irq(int irq, void *dev)
  68358. +{
  68359. + int32_t retval = IRQ_NONE;
  68360. +
  68361. + retval = dwc_otg_handle_common_intr(dev);
  68362. + if (retval != 0) {
  68363. + S3C2410X_CLEAR_EINTPEND();
  68364. + }
  68365. + return IRQ_RETVAL(retval);
  68366. +}
  68367. +
  68368. +/**
  68369. + * This function is called when a lm_device is unregistered with the
  68370. + * dwc_otg_driver. This happens, for example, when the rmmod command is
  68371. + * executed. The device may or may not be electrically present. If it is
  68372. + * present, the driver stops device processing. Any resources used on behalf
  68373. + * of this device are freed.
  68374. + *
  68375. + * @param _dev
  68376. + */
  68377. +#ifdef LM_INTERFACE
  68378. +#define REM_RETVAL(n)
  68379. +static void dwc_otg_driver_remove( struct lm_device *_dev )
  68380. +{ dwc_otg_device_t *otg_dev = lm_get_drvdata(_dev);
  68381. +#elif defined(PCI_INTERFACE)
  68382. +#define REM_RETVAL(n)
  68383. +static void dwc_otg_driver_remove( struct pci_dev *_dev )
  68384. +{ dwc_otg_device_t *otg_dev = pci_get_drvdata(_dev);
  68385. +#elif defined(PLATFORM_INTERFACE)
  68386. +#define REM_RETVAL(n) n
  68387. +static int dwc_otg_driver_remove( struct platform_device *_dev )
  68388. +{ dwc_otg_device_t *otg_dev = platform_get_drvdata(_dev);
  68389. +#endif
  68390. +
  68391. + DWC_DEBUGPL(DBG_ANY, "%s(%p) otg_dev %p\n", __func__, _dev, otg_dev);
  68392. +
  68393. + if (!otg_dev) {
  68394. + /* Memory allocation for the dwc_otg_device failed. */
  68395. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev NULL!\n", __func__);
  68396. + return REM_RETVAL(-ENOMEM);
  68397. + }
  68398. +#ifndef DWC_DEVICE_ONLY
  68399. + if (otg_dev->hcd) {
  68400. + hcd_remove(_dev);
  68401. + } else {
  68402. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->hcd NULL!\n", __func__);
  68403. + return REM_RETVAL(-EINVAL);
  68404. + }
  68405. +#endif
  68406. +
  68407. +#ifndef DWC_HOST_ONLY
  68408. + if (otg_dev->pcd) {
  68409. + pcd_remove(_dev);
  68410. + } else {
  68411. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->pcd NULL!\n", __func__);
  68412. + return REM_RETVAL(-EINVAL);
  68413. + }
  68414. +#endif
  68415. + /*
  68416. + * Free the IRQ
  68417. + */
  68418. + if (otg_dev->common_irq_installed) {
  68419. +#ifdef PLATFORM_INTERFACE
  68420. + free_irq(platform_get_irq(_dev, 0), otg_dev);
  68421. +#else
  68422. + free_irq(_dev->irq, otg_dev);
  68423. +#endif
  68424. + } else {
  68425. + DWC_DEBUGPL(DBG_ANY, "%s: There is no installed irq!\n", __func__);
  68426. + return REM_RETVAL(-ENXIO);
  68427. + }
  68428. +
  68429. + if (otg_dev->core_if) {
  68430. + dwc_otg_cil_remove(otg_dev->core_if);
  68431. + } else {
  68432. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->core_if NULL!\n", __func__);
  68433. + return REM_RETVAL(-ENXIO);
  68434. + }
  68435. +
  68436. + /*
  68437. + * Remove the device attributes
  68438. + */
  68439. + dwc_otg_attr_remove(_dev);
  68440. +
  68441. + /*
  68442. + * Return the memory.
  68443. + */
  68444. + if (otg_dev->os_dep.base) {
  68445. + iounmap(otg_dev->os_dep.base);
  68446. + }
  68447. + DWC_FREE(otg_dev);
  68448. +
  68449. + /*
  68450. + * Clear the drvdata pointer.
  68451. + */
  68452. +#ifdef LM_INTERFACE
  68453. + lm_set_drvdata(_dev, 0);
  68454. +#elif defined(PCI_INTERFACE)
  68455. + release_mem_region(otg_dev->os_dep.rsrc_start,
  68456. + otg_dev->os_dep.rsrc_len);
  68457. + pci_set_drvdata(_dev, 0);
  68458. +#elif defined(PLATFORM_INTERFACE)
  68459. + platform_set_drvdata(_dev, 0);
  68460. +#endif
  68461. + return REM_RETVAL(0);
  68462. +}
  68463. +
  68464. +/**
  68465. + * This function is called when an lm_device is bound to a
  68466. + * dwc_otg_driver. It creates the driver components required to
  68467. + * control the device (CIL, HCD, and PCD) and it initializes the
  68468. + * device. The driver components are stored in a dwc_otg_device
  68469. + * structure. A reference to the dwc_otg_device is saved in the
  68470. + * lm_device. This allows the driver to access the dwc_otg_device
  68471. + * structure on subsequent calls to driver methods for this device.
  68472. + *
  68473. + * @param _dev Bus device
  68474. + */
  68475. +static int dwc_otg_driver_probe(
  68476. +#ifdef LM_INTERFACE
  68477. + struct lm_device *_dev
  68478. +#elif defined(PCI_INTERFACE)
  68479. + struct pci_dev *_dev,
  68480. + const struct pci_device_id *id
  68481. +#elif defined(PLATFORM_INTERFACE)
  68482. + struct platform_device *_dev
  68483. +#endif
  68484. + )
  68485. +{
  68486. + int retval = 0;
  68487. + dwc_otg_device_t *dwc_otg_device;
  68488. + int devirq;
  68489. +
  68490. + dev_dbg(&_dev->dev, "dwc_otg_driver_probe(%p)\n", _dev);
  68491. +#ifdef LM_INTERFACE
  68492. + dev_dbg(&_dev->dev, "start=0x%08x\n", (unsigned)_dev->resource.start);
  68493. +#elif defined(PCI_INTERFACE)
  68494. + if (!id) {
  68495. + DWC_ERROR("Invalid pci_device_id %p", id);
  68496. + return -EINVAL;
  68497. + }
  68498. +
  68499. + if (!_dev || (pci_enable_device(_dev) < 0)) {
  68500. + DWC_ERROR("Invalid pci_device %p", _dev);
  68501. + return -ENODEV;
  68502. + }
  68503. + dev_dbg(&_dev->dev, "start=0x%08x\n", (unsigned)pci_resource_start(_dev,0));
  68504. + /* other stuff needed as well? */
  68505. +
  68506. +#elif defined(PLATFORM_INTERFACE)
  68507. + dev_dbg(&_dev->dev, "start=0x%08x (len 0x%x)\n",
  68508. + (unsigned)_dev->resource->start,
  68509. + (unsigned)(_dev->resource->end - _dev->resource->start));
  68510. +#endif
  68511. +
  68512. + dwc_otg_device = DWC_ALLOC(sizeof(dwc_otg_device_t));
  68513. +
  68514. + if (!dwc_otg_device) {
  68515. + dev_err(&_dev->dev, "kmalloc of dwc_otg_device failed\n");
  68516. + return -ENOMEM;
  68517. + }
  68518. +
  68519. + memset(dwc_otg_device, 0, sizeof(*dwc_otg_device));
  68520. + dwc_otg_device->os_dep.reg_offset = 0xFFFFFFFF;
  68521. +
  68522. + /*
  68523. + * Map the DWC_otg Core memory into virtual address space.
  68524. + */
  68525. +#ifdef LM_INTERFACE
  68526. + dwc_otg_device->os_dep.base = ioremap(_dev->resource.start, SZ_256K);
  68527. +
  68528. + if (!dwc_otg_device->os_dep.base) {
  68529. + dev_err(&_dev->dev, "ioremap() failed\n");
  68530. + DWC_FREE(dwc_otg_device);
  68531. + return -ENOMEM;
  68532. + }
  68533. + dev_dbg(&_dev->dev, "base=0x%08x\n",
  68534. + (unsigned)dwc_otg_device->os_dep.base);
  68535. +#elif defined(PCI_INTERFACE)
  68536. + _dev->current_state = PCI_D0;
  68537. + _dev->dev.power.power_state = PMSG_ON;
  68538. +
  68539. + if (!_dev->irq) {
  68540. + DWC_ERROR("Found HC with no IRQ. Check BIOS/PCI %s setup!",
  68541. + pci_name(_dev));
  68542. + iounmap(dwc_otg_device->os_dep.base);
  68543. + DWC_FREE(dwc_otg_device);
  68544. + return -ENODEV;
  68545. + }
  68546. +
  68547. + dwc_otg_device->os_dep.rsrc_start = pci_resource_start(_dev, 0);
  68548. + dwc_otg_device->os_dep.rsrc_len = pci_resource_len(_dev, 0);
  68549. + DWC_DEBUGPL(DBG_ANY, "PCI resource: start=%08x, len=%08x\n",
  68550. + (unsigned)dwc_otg_device->os_dep.rsrc_start,
  68551. + (unsigned)dwc_otg_device->os_dep.rsrc_len);
  68552. + if (!request_mem_region
  68553. + (dwc_otg_device->os_dep.rsrc_start, dwc_otg_device->os_dep.rsrc_len,
  68554. + "dwc_otg")) {
  68555. + dev_dbg(&_dev->dev, "error requesting memory\n");
  68556. + iounmap(dwc_otg_device->os_dep.base);
  68557. + DWC_FREE(dwc_otg_device);
  68558. + return -EFAULT;
  68559. + }
  68560. +
  68561. + dwc_otg_device->os_dep.base =
  68562. + ioremap_nocache(dwc_otg_device->os_dep.rsrc_start,
  68563. + dwc_otg_device->os_dep.rsrc_len);
  68564. + if (dwc_otg_device->os_dep.base == NULL) {
  68565. + dev_dbg(&_dev->dev, "error mapping memory\n");
  68566. + release_mem_region(dwc_otg_device->os_dep.rsrc_start,
  68567. + dwc_otg_device->os_dep.rsrc_len);
  68568. + iounmap(dwc_otg_device->os_dep.base);
  68569. + DWC_FREE(dwc_otg_device);
  68570. + return -EFAULT;
  68571. + }
  68572. + dev_dbg(&_dev->dev, "base=0x%p (before adjust) \n",
  68573. + dwc_otg_device->os_dep.base);
  68574. + dwc_otg_device->os_dep.base = (char *)dwc_otg_device->os_dep.base;
  68575. + dev_dbg(&_dev->dev, "base=0x%p (after adjust) \n",
  68576. + dwc_otg_device->os_dep.base);
  68577. + dev_dbg(&_dev->dev, "%s: mapped PA 0x%x to VA 0x%p\n", __func__,
  68578. + (unsigned)dwc_otg_device->os_dep.rsrc_start,
  68579. + dwc_otg_device->os_dep.base);
  68580. +
  68581. + pci_set_master(_dev);
  68582. + pci_set_drvdata(_dev, dwc_otg_device);
  68583. +#elif defined(PLATFORM_INTERFACE)
  68584. + DWC_DEBUGPL(DBG_ANY,"Platform resource: start=%08x, len=%08x\n",
  68585. + _dev->resource->start,
  68586. + _dev->resource->end - _dev->resource->start + 1);
  68587. +#if 1
  68588. + if (!request_mem_region(_dev->resource[0].start,
  68589. + _dev->resource[0].end - _dev->resource[0].start + 1,
  68590. + "dwc_otg")) {
  68591. + dev_dbg(&_dev->dev, "error reserving mapped memory\n");
  68592. + retval = -EFAULT;
  68593. + goto fail;
  68594. + }
  68595. +
  68596. + dwc_otg_device->os_dep.base = ioremap_nocache(_dev->resource[0].start,
  68597. + _dev->resource[0].end -
  68598. + _dev->resource[0].start+1);
  68599. + if (fiq_enable)
  68600. + {
  68601. + if (!request_mem_region(_dev->resource[1].start,
  68602. + _dev->resource[1].end - _dev->resource[1].start + 1,
  68603. + "dwc_otg")) {
  68604. + dev_dbg(&_dev->dev, "error reserving mapped memory\n");
  68605. + retval = -EFAULT;
  68606. + goto fail;
  68607. + }
  68608. +
  68609. + dwc_otg_device->os_dep.mphi_base = ioremap_nocache(_dev->resource[1].start,
  68610. + _dev->resource[1].end -
  68611. + _dev->resource[1].start + 1);
  68612. + }
  68613. +
  68614. +#else
  68615. + {
  68616. + struct map_desc desc = {
  68617. + .virtual = IO_ADDRESS((unsigned)_dev->resource->start),
  68618. + .pfn = __phys_to_pfn((unsigned)_dev->resource->start),
  68619. + .length = SZ_128K,
  68620. + .type = MT_DEVICE
  68621. + };
  68622. + iotable_init(&desc, 1);
  68623. + dwc_otg_device->os_dep.base = (void *)desc.virtual;
  68624. + }
  68625. +#endif
  68626. + if (!dwc_otg_device->os_dep.base) {
  68627. + dev_err(&_dev->dev, "ioremap() failed\n");
  68628. + retval = -ENOMEM;
  68629. + goto fail;
  68630. + }
  68631. + dev_dbg(&_dev->dev, "base=0x%08x\n",
  68632. + (unsigned)dwc_otg_device->os_dep.base);
  68633. +#endif
  68634. +
  68635. + /*
  68636. + * Initialize driver data to point to the global DWC_otg
  68637. + * Device structure.
  68638. + */
  68639. +#ifdef LM_INTERFACE
  68640. + lm_set_drvdata(_dev, dwc_otg_device);
  68641. +#elif defined(PLATFORM_INTERFACE)
  68642. + platform_set_drvdata(_dev, dwc_otg_device);
  68643. +#endif
  68644. + dev_dbg(&_dev->dev, "dwc_otg_device=0x%p\n", dwc_otg_device);
  68645. +
  68646. + dwc_otg_device->core_if = dwc_otg_cil_init(dwc_otg_device->os_dep.base);
  68647. + DWC_DEBUGPL(DBG_HCDV, "probe of device %p given core_if %p\n",
  68648. + dwc_otg_device, dwc_otg_device->core_if);//GRAYG
  68649. +
  68650. + if (!dwc_otg_device->core_if) {
  68651. + dev_err(&_dev->dev, "CIL initialization failed!\n");
  68652. + retval = -ENOMEM;
  68653. + goto fail;
  68654. + }
  68655. +
  68656. + dev_dbg(&_dev->dev, "Calling get_gsnpsid\n");
  68657. + /*
  68658. + * Attempt to ensure this device is really a DWC_otg Controller.
  68659. + * Read and verify the SNPSID register contents. The value should be
  68660. + * 0x45F42XXX or 0x45F42XXX, which corresponds to either "OT2" or "OTG3",
  68661. + * as in "OTG version 2.XX" or "OTG version 3.XX".
  68662. + */
  68663. +
  68664. + if (((dwc_otg_get_gsnpsid(dwc_otg_device->core_if) & 0xFFFFF000) != 0x4F542000) &&
  68665. + ((dwc_otg_get_gsnpsid(dwc_otg_device->core_if) & 0xFFFFF000) != 0x4F543000)) {
  68666. + dev_err(&_dev->dev, "Bad value for SNPSID: 0x%08x\n",
  68667. + dwc_otg_get_gsnpsid(dwc_otg_device->core_if));
  68668. + retval = -EINVAL;
  68669. + goto fail;
  68670. + }
  68671. +
  68672. + /*
  68673. + * Validate parameter values.
  68674. + */
  68675. + dev_dbg(&_dev->dev, "Calling set_parameters\n");
  68676. + if (set_parameters(dwc_otg_device->core_if)) {
  68677. + retval = -EINVAL;
  68678. + goto fail;
  68679. + }
  68680. +
  68681. + /*
  68682. + * Create Device Attributes in sysfs
  68683. + */
  68684. + dev_dbg(&_dev->dev, "Calling attr_create\n");
  68685. + dwc_otg_attr_create(_dev);
  68686. +
  68687. + /*
  68688. + * Disable the global interrupt until all the interrupt
  68689. + * handlers are installed.
  68690. + */
  68691. + dev_dbg(&_dev->dev, "Calling disable_global_interrupts\n");
  68692. + dwc_otg_disable_global_interrupts(dwc_otg_device->core_if);
  68693. +
  68694. + /*
  68695. + * Install the interrupt handler for the common interrupts before
  68696. + * enabling common interrupts in core_init below.
  68697. + */
  68698. +
  68699. +#if defined(PLATFORM_INTERFACE)
  68700. + devirq = platform_get_irq(_dev, fiq_enable ? 0 : 1);
  68701. +#else
  68702. + devirq = _dev->irq;
  68703. +#endif
  68704. + DWC_DEBUGPL(DBG_CIL, "registering (common) handler for irq%d\n",
  68705. + devirq);
  68706. + dev_dbg(&_dev->dev, "Calling request_irq(%d)\n", devirq);
  68707. + retval = request_irq(devirq, dwc_otg_common_irq,
  68708. + IRQF_SHARED,
  68709. + "dwc_otg", dwc_otg_device);
  68710. + if (retval) {
  68711. + DWC_ERROR("request of irq%d failed\n", devirq);
  68712. + retval = -EBUSY;
  68713. + goto fail;
  68714. + } else {
  68715. + dwc_otg_device->common_irq_installed = 1;
  68716. + }
  68717. +
  68718. +#ifndef IRQF_TRIGGER_LOW
  68719. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  68720. + dev_dbg(&_dev->dev, "Calling set_irq_type\n");
  68721. + set_irq_type(devirq,
  68722. +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30))
  68723. + IRQT_LOW
  68724. +#else
  68725. + IRQ_TYPE_LEVEL_LOW
  68726. +#endif
  68727. + );
  68728. +#endif
  68729. +#endif /*IRQF_TRIGGER_LOW*/
  68730. +
  68731. + /*
  68732. + * Initialize the DWC_otg core.
  68733. + */
  68734. + dev_dbg(&_dev->dev, "Calling dwc_otg_core_init\n");
  68735. + dwc_otg_core_init(dwc_otg_device->core_if);
  68736. +
  68737. +#ifndef DWC_HOST_ONLY
  68738. + /*
  68739. + * Initialize the PCD
  68740. + */
  68741. + dev_dbg(&_dev->dev, "Calling pcd_init\n");
  68742. + retval = pcd_init(_dev);
  68743. + if (retval != 0) {
  68744. + DWC_ERROR("pcd_init failed\n");
  68745. + dwc_otg_device->pcd = NULL;
  68746. + goto fail;
  68747. + }
  68748. +#endif
  68749. +#ifndef DWC_DEVICE_ONLY
  68750. + /*
  68751. + * Initialize the HCD
  68752. + */
  68753. + dev_dbg(&_dev->dev, "Calling hcd_init\n");
  68754. + retval = hcd_init(_dev);
  68755. + if (retval != 0) {
  68756. + DWC_ERROR("hcd_init failed\n");
  68757. + dwc_otg_device->hcd = NULL;
  68758. + goto fail;
  68759. + }
  68760. +#endif
  68761. + /* Recover from drvdata having been overwritten by hcd_init() */
  68762. +#ifdef LM_INTERFACE
  68763. + lm_set_drvdata(_dev, dwc_otg_device);
  68764. +#elif defined(PLATFORM_INTERFACE)
  68765. + platform_set_drvdata(_dev, dwc_otg_device);
  68766. +#elif defined(PCI_INTERFACE)
  68767. + pci_set_drvdata(_dev, dwc_otg_device);
  68768. + dwc_otg_device->os_dep.pcidev = _dev;
  68769. +#endif
  68770. +
  68771. + /*
  68772. + * Enable the global interrupt after all the interrupt
  68773. + * handlers are installed if there is no ADP support else
  68774. + * perform initial actions required for Internal ADP logic.
  68775. + */
  68776. + if (!dwc_otg_get_param_adp_enable(dwc_otg_device->core_if)) {
  68777. + dev_dbg(&_dev->dev, "Calling enable_global_interrupts\n");
  68778. + dwc_otg_enable_global_interrupts(dwc_otg_device->core_if);
  68779. + dev_dbg(&_dev->dev, "Done\n");
  68780. + } else
  68781. + dwc_otg_adp_start(dwc_otg_device->core_if,
  68782. + dwc_otg_is_host_mode(dwc_otg_device->core_if));
  68783. +
  68784. + return 0;
  68785. +
  68786. +fail:
  68787. + dwc_otg_driver_remove(_dev);
  68788. + return retval;
  68789. +}
  68790. +
  68791. +/**
  68792. + * This structure defines the methods to be called by a bus driver
  68793. + * during the lifecycle of a device on that bus. Both drivers and
  68794. + * devices are registered with a bus driver. The bus driver matches
  68795. + * devices to drivers based on information in the device and driver
  68796. + * structures.
  68797. + *
  68798. + * The probe function is called when the bus driver matches a device
  68799. + * to this driver. The remove function is called when a device is
  68800. + * unregistered with the bus driver.
  68801. + */
  68802. +#ifdef LM_INTERFACE
  68803. +static struct lm_driver dwc_otg_driver = {
  68804. + .drv = {.name = (char *)dwc_driver_name,},
  68805. + .probe = dwc_otg_driver_probe,
  68806. + .remove = dwc_otg_driver_remove,
  68807. + // 'suspend' and 'resume' absent
  68808. +};
  68809. +#elif defined(PCI_INTERFACE)
  68810. +static const struct pci_device_id pci_ids[] = { {
  68811. + PCI_DEVICE(0x16c3, 0xabcd),
  68812. + .driver_data =
  68813. + (unsigned long)0xdeadbeef,
  68814. + }, { /* end: all zeroes */ }
  68815. +};
  68816. +
  68817. +MODULE_DEVICE_TABLE(pci, pci_ids);
  68818. +
  68819. +/* pci driver glue; this is a "new style" PCI driver module */
  68820. +static struct pci_driver dwc_otg_driver = {
  68821. + .name = "dwc_otg",
  68822. + .id_table = pci_ids,
  68823. +
  68824. + .probe = dwc_otg_driver_probe,
  68825. + .remove = dwc_otg_driver_remove,
  68826. +
  68827. + .driver = {
  68828. + .name = (char *)dwc_driver_name,
  68829. + },
  68830. +};
  68831. +#elif defined(PLATFORM_INTERFACE)
  68832. +static struct platform_device_id platform_ids[] = {
  68833. + {
  68834. + .name = "bcm2708_usb",
  68835. + .driver_data = (kernel_ulong_t) 0xdeadbeef,
  68836. + },
  68837. + { /* end: all zeroes */ }
  68838. +};
  68839. +MODULE_DEVICE_TABLE(platform, platform_ids);
  68840. +
  68841. +static struct platform_driver dwc_otg_driver = {
  68842. + .driver = {
  68843. + .name = (char *)dwc_driver_name,
  68844. + },
  68845. + .id_table = platform_ids,
  68846. +
  68847. + .probe = dwc_otg_driver_probe,
  68848. + .remove = dwc_otg_driver_remove,
  68849. + // no 'shutdown', 'suspend', 'resume', 'suspend_late' or 'resume_early'
  68850. +};
  68851. +#endif
  68852. +
  68853. +/**
  68854. + * This function is called when the dwc_otg_driver is installed with the
  68855. + * insmod command. It registers the dwc_otg_driver structure with the
  68856. + * appropriate bus driver. This will cause the dwc_otg_driver_probe function
  68857. + * to be called. In addition, the bus driver will automatically expose
  68858. + * attributes defined for the device and driver in the special sysfs file
  68859. + * system.
  68860. + *
  68861. + * @return
  68862. + */
  68863. +static int __init dwc_otg_driver_init(void)
  68864. +{
  68865. + int retval = 0;
  68866. + int error;
  68867. + struct device_driver *drv;
  68868. +
  68869. + if(fiq_fsm_enable && !fiq_enable) {
  68870. + printk(KERN_WARNING "dwc_otg: fiq_fsm_enable was set without fiq_enable! Correcting.\n");
  68871. + fiq_enable = 1;
  68872. + }
  68873. +
  68874. + printk(KERN_INFO "%s: version %s (%s bus)\n", dwc_driver_name,
  68875. + DWC_DRIVER_VERSION,
  68876. +#ifdef LM_INTERFACE
  68877. + "logicmodule");
  68878. + retval = lm_driver_register(&dwc_otg_driver);
  68879. + drv = &dwc_otg_driver.drv;
  68880. +#elif defined(PCI_INTERFACE)
  68881. + "pci");
  68882. + retval = pci_register_driver(&dwc_otg_driver);
  68883. + drv = &dwc_otg_driver.driver;
  68884. +#elif defined(PLATFORM_INTERFACE)
  68885. + "platform");
  68886. + retval = platform_driver_register(&dwc_otg_driver);
  68887. + drv = &dwc_otg_driver.driver;
  68888. +#endif
  68889. + if (retval < 0) {
  68890. + printk(KERN_ERR "%s retval=%d\n", __func__, retval);
  68891. + return retval;
  68892. + }
  68893. + printk(KERN_DEBUG "dwc_otg: FIQ %s\n", fiq_enable ? "enabled":"disabled");
  68894. + printk(KERN_DEBUG "dwc_otg: NAK holdoff %s\n", nak_holdoff ? "enabled":"disabled");
  68895. + printk(KERN_DEBUG "dwc_otg: FIQ split-transaction FSM %s\n", fiq_fsm_enable ? "enabled":"disabled");
  68896. +
  68897. + error = driver_create_file(drv, &driver_attr_version);
  68898. +#ifdef DEBUG
  68899. + error = driver_create_file(drv, &driver_attr_debuglevel);
  68900. +#endif
  68901. + return retval;
  68902. +}
  68903. +
  68904. +module_init(dwc_otg_driver_init);
  68905. +
  68906. +/**
  68907. + * This function is called when the driver is removed from the kernel
  68908. + * with the rmmod command. The driver unregisters itself with its bus
  68909. + * driver.
  68910. + *
  68911. + */
  68912. +static void __exit dwc_otg_driver_cleanup(void)
  68913. +{
  68914. + printk(KERN_DEBUG "dwc_otg_driver_cleanup()\n");
  68915. +
  68916. +#ifdef LM_INTERFACE
  68917. + driver_remove_file(&dwc_otg_driver.drv, &driver_attr_debuglevel);
  68918. + driver_remove_file(&dwc_otg_driver.drv, &driver_attr_version);
  68919. + lm_driver_unregister(&dwc_otg_driver);
  68920. +#elif defined(PCI_INTERFACE)
  68921. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
  68922. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
  68923. + pci_unregister_driver(&dwc_otg_driver);
  68924. +#elif defined(PLATFORM_INTERFACE)
  68925. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
  68926. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
  68927. + platform_driver_unregister(&dwc_otg_driver);
  68928. +#endif
  68929. +
  68930. + printk(KERN_INFO "%s module removed\n", dwc_driver_name);
  68931. +}
  68932. +
  68933. +module_exit(dwc_otg_driver_cleanup);
  68934. +
  68935. +MODULE_DESCRIPTION(DWC_DRIVER_DESC);
  68936. +MODULE_AUTHOR("Synopsys Inc.");
  68937. +MODULE_LICENSE("GPL");
  68938. +
  68939. +module_param_named(otg_cap, dwc_otg_module_params.otg_cap, int, 0444);
  68940. +MODULE_PARM_DESC(otg_cap, "OTG Capabilities 0=HNP&SRP 1=SRP Only 2=None");
  68941. +module_param_named(opt, dwc_otg_module_params.opt, int, 0444);
  68942. +MODULE_PARM_DESC(opt, "OPT Mode");
  68943. +module_param_named(dma_enable, dwc_otg_module_params.dma_enable, int, 0444);
  68944. +MODULE_PARM_DESC(dma_enable, "DMA Mode 0=Slave 1=DMA enabled");
  68945. +
  68946. +module_param_named(dma_desc_enable, dwc_otg_module_params.dma_desc_enable, int,
  68947. + 0444);
  68948. +MODULE_PARM_DESC(dma_desc_enable,
  68949. + "DMA Desc Mode 0=Address DMA 1=DMA Descriptor enabled");
  68950. +
  68951. +module_param_named(dma_burst_size, dwc_otg_module_params.dma_burst_size, int,
  68952. + 0444);
  68953. +MODULE_PARM_DESC(dma_burst_size,
  68954. + "DMA Burst Size 1, 4, 8, 16, 32, 64, 128, 256");
  68955. +module_param_named(speed, dwc_otg_module_params.speed, int, 0444);
  68956. +MODULE_PARM_DESC(speed, "Speed 0=High Speed 1=Full Speed");
  68957. +module_param_named(host_support_fs_ls_low_power,
  68958. + dwc_otg_module_params.host_support_fs_ls_low_power, int,
  68959. + 0444);
  68960. +MODULE_PARM_DESC(host_support_fs_ls_low_power,
  68961. + "Support Low Power w/FS or LS 0=Support 1=Don't Support");
  68962. +module_param_named(host_ls_low_power_phy_clk,
  68963. + dwc_otg_module_params.host_ls_low_power_phy_clk, int, 0444);
  68964. +MODULE_PARM_DESC(host_ls_low_power_phy_clk,
  68965. + "Low Speed Low Power Clock 0=48Mhz 1=6Mhz");
  68966. +module_param_named(enable_dynamic_fifo,
  68967. + dwc_otg_module_params.enable_dynamic_fifo, int, 0444);
  68968. +MODULE_PARM_DESC(enable_dynamic_fifo, "0=cC Setting 1=Allow Dynamic Sizing");
  68969. +module_param_named(data_fifo_size, dwc_otg_module_params.data_fifo_size, int,
  68970. + 0444);
  68971. +MODULE_PARM_DESC(data_fifo_size,
  68972. + "Total number of words in the data FIFO memory 32-32768");
  68973. +module_param_named(dev_rx_fifo_size, dwc_otg_module_params.dev_rx_fifo_size,
  68974. + int, 0444);
  68975. +MODULE_PARM_DESC(dev_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
  68976. +module_param_named(dev_nperio_tx_fifo_size,
  68977. + dwc_otg_module_params.dev_nperio_tx_fifo_size, int, 0444);
  68978. +MODULE_PARM_DESC(dev_nperio_tx_fifo_size,
  68979. + "Number of words in the non-periodic Tx FIFO 16-32768");
  68980. +module_param_named(dev_perio_tx_fifo_size_1,
  68981. + dwc_otg_module_params.dev_perio_tx_fifo_size[0], int, 0444);
  68982. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_1,
  68983. + "Number of words in the periodic Tx FIFO 4-768");
  68984. +module_param_named(dev_perio_tx_fifo_size_2,
  68985. + dwc_otg_module_params.dev_perio_tx_fifo_size[1], int, 0444);
  68986. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_2,
  68987. + "Number of words in the periodic Tx FIFO 4-768");
  68988. +module_param_named(dev_perio_tx_fifo_size_3,
  68989. + dwc_otg_module_params.dev_perio_tx_fifo_size[2], int, 0444);
  68990. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_3,
  68991. + "Number of words in the periodic Tx FIFO 4-768");
  68992. +module_param_named(dev_perio_tx_fifo_size_4,
  68993. + dwc_otg_module_params.dev_perio_tx_fifo_size[3], int, 0444);
  68994. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_4,
  68995. + "Number of words in the periodic Tx FIFO 4-768");
  68996. +module_param_named(dev_perio_tx_fifo_size_5,
  68997. + dwc_otg_module_params.dev_perio_tx_fifo_size[4], int, 0444);
  68998. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_5,
  68999. + "Number of words in the periodic Tx FIFO 4-768");
  69000. +module_param_named(dev_perio_tx_fifo_size_6,
  69001. + dwc_otg_module_params.dev_perio_tx_fifo_size[5], int, 0444);
  69002. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_6,
  69003. + "Number of words in the periodic Tx FIFO 4-768");
  69004. +module_param_named(dev_perio_tx_fifo_size_7,
  69005. + dwc_otg_module_params.dev_perio_tx_fifo_size[6], int, 0444);
  69006. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_7,
  69007. + "Number of words in the periodic Tx FIFO 4-768");
  69008. +module_param_named(dev_perio_tx_fifo_size_8,
  69009. + dwc_otg_module_params.dev_perio_tx_fifo_size[7], int, 0444);
  69010. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_8,
  69011. + "Number of words in the periodic Tx FIFO 4-768");
  69012. +module_param_named(dev_perio_tx_fifo_size_9,
  69013. + dwc_otg_module_params.dev_perio_tx_fifo_size[8], int, 0444);
  69014. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_9,
  69015. + "Number of words in the periodic Tx FIFO 4-768");
  69016. +module_param_named(dev_perio_tx_fifo_size_10,
  69017. + dwc_otg_module_params.dev_perio_tx_fifo_size[9], int, 0444);
  69018. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_10,
  69019. + "Number of words in the periodic Tx FIFO 4-768");
  69020. +module_param_named(dev_perio_tx_fifo_size_11,
  69021. + dwc_otg_module_params.dev_perio_tx_fifo_size[10], int, 0444);
  69022. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_11,
  69023. + "Number of words in the periodic Tx FIFO 4-768");
  69024. +module_param_named(dev_perio_tx_fifo_size_12,
  69025. + dwc_otg_module_params.dev_perio_tx_fifo_size[11], int, 0444);
  69026. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_12,
  69027. + "Number of words in the periodic Tx FIFO 4-768");
  69028. +module_param_named(dev_perio_tx_fifo_size_13,
  69029. + dwc_otg_module_params.dev_perio_tx_fifo_size[12], int, 0444);
  69030. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_13,
  69031. + "Number of words in the periodic Tx FIFO 4-768");
  69032. +module_param_named(dev_perio_tx_fifo_size_14,
  69033. + dwc_otg_module_params.dev_perio_tx_fifo_size[13], int, 0444);
  69034. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_14,
  69035. + "Number of words in the periodic Tx FIFO 4-768");
  69036. +module_param_named(dev_perio_tx_fifo_size_15,
  69037. + dwc_otg_module_params.dev_perio_tx_fifo_size[14], int, 0444);
  69038. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_15,
  69039. + "Number of words in the periodic Tx FIFO 4-768");
  69040. +module_param_named(host_rx_fifo_size, dwc_otg_module_params.host_rx_fifo_size,
  69041. + int, 0444);
  69042. +MODULE_PARM_DESC(host_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
  69043. +module_param_named(host_nperio_tx_fifo_size,
  69044. + dwc_otg_module_params.host_nperio_tx_fifo_size, int, 0444);
  69045. +MODULE_PARM_DESC(host_nperio_tx_fifo_size,
  69046. + "Number of words in the non-periodic Tx FIFO 16-32768");
  69047. +module_param_named(host_perio_tx_fifo_size,
  69048. + dwc_otg_module_params.host_perio_tx_fifo_size, int, 0444);
  69049. +MODULE_PARM_DESC(host_perio_tx_fifo_size,
  69050. + "Number of words in the host periodic Tx FIFO 16-32768");
  69051. +module_param_named(max_transfer_size, dwc_otg_module_params.max_transfer_size,
  69052. + int, 0444);
  69053. +/** @todo Set the max to 512K, modify checks */
  69054. +MODULE_PARM_DESC(max_transfer_size,
  69055. + "The maximum transfer size supported in bytes 2047-65535");
  69056. +module_param_named(max_packet_count, dwc_otg_module_params.max_packet_count,
  69057. + int, 0444);
  69058. +MODULE_PARM_DESC(max_packet_count,
  69059. + "The maximum number of packets in a transfer 15-511");
  69060. +module_param_named(host_channels, dwc_otg_module_params.host_channels, int,
  69061. + 0444);
  69062. +MODULE_PARM_DESC(host_channels,
  69063. + "The number of host channel registers to use 1-16");
  69064. +module_param_named(dev_endpoints, dwc_otg_module_params.dev_endpoints, int,
  69065. + 0444);
  69066. +MODULE_PARM_DESC(dev_endpoints,
  69067. + "The number of endpoints in addition to EP0 available for device mode 1-15");
  69068. +module_param_named(phy_type, dwc_otg_module_params.phy_type, int, 0444);
  69069. +MODULE_PARM_DESC(phy_type, "0=Reserved 1=UTMI+ 2=ULPI");
  69070. +module_param_named(phy_utmi_width, dwc_otg_module_params.phy_utmi_width, int,
  69071. + 0444);
  69072. +MODULE_PARM_DESC(phy_utmi_width, "Specifies the UTMI+ Data Width 8 or 16 bits");
  69073. +module_param_named(phy_ulpi_ddr, dwc_otg_module_params.phy_ulpi_ddr, int, 0444);
  69074. +MODULE_PARM_DESC(phy_ulpi_ddr,
  69075. + "ULPI at double or single data rate 0=Single 1=Double");
  69076. +module_param_named(phy_ulpi_ext_vbus, dwc_otg_module_params.phy_ulpi_ext_vbus,
  69077. + int, 0444);
  69078. +MODULE_PARM_DESC(phy_ulpi_ext_vbus,
  69079. + "ULPI PHY using internal or external vbus 0=Internal");
  69080. +module_param_named(i2c_enable, dwc_otg_module_params.i2c_enable, int, 0444);
  69081. +MODULE_PARM_DESC(i2c_enable, "FS PHY Interface");
  69082. +module_param_named(ulpi_fs_ls, dwc_otg_module_params.ulpi_fs_ls, int, 0444);
  69083. +MODULE_PARM_DESC(ulpi_fs_ls, "ULPI PHY FS/LS mode only");
  69084. +module_param_named(ts_dline, dwc_otg_module_params.ts_dline, int, 0444);
  69085. +MODULE_PARM_DESC(ts_dline, "Term select Dline pulsing for all PHYs");
  69086. +module_param_named(debug, g_dbg_lvl, int, 0444);
  69087. +MODULE_PARM_DESC(debug, "");
  69088. +
  69089. +module_param_named(en_multiple_tx_fifo,
  69090. + dwc_otg_module_params.en_multiple_tx_fifo, int, 0444);
  69091. +MODULE_PARM_DESC(en_multiple_tx_fifo,
  69092. + "Dedicated Non Periodic Tx FIFOs 0=disabled 1=enabled");
  69093. +module_param_named(dev_tx_fifo_size_1,
  69094. + dwc_otg_module_params.dev_tx_fifo_size[0], int, 0444);
  69095. +MODULE_PARM_DESC(dev_tx_fifo_size_1, "Number of words in the Tx FIFO 4-768");
  69096. +module_param_named(dev_tx_fifo_size_2,
  69097. + dwc_otg_module_params.dev_tx_fifo_size[1], int, 0444);
  69098. +MODULE_PARM_DESC(dev_tx_fifo_size_2, "Number of words in the Tx FIFO 4-768");
  69099. +module_param_named(dev_tx_fifo_size_3,
  69100. + dwc_otg_module_params.dev_tx_fifo_size[2], int, 0444);
  69101. +MODULE_PARM_DESC(dev_tx_fifo_size_3, "Number of words in the Tx FIFO 4-768");
  69102. +module_param_named(dev_tx_fifo_size_4,
  69103. + dwc_otg_module_params.dev_tx_fifo_size[3], int, 0444);
  69104. +MODULE_PARM_DESC(dev_tx_fifo_size_4, "Number of words in the Tx FIFO 4-768");
  69105. +module_param_named(dev_tx_fifo_size_5,
  69106. + dwc_otg_module_params.dev_tx_fifo_size[4], int, 0444);
  69107. +MODULE_PARM_DESC(dev_tx_fifo_size_5, "Number of words in the Tx FIFO 4-768");
  69108. +module_param_named(dev_tx_fifo_size_6,
  69109. + dwc_otg_module_params.dev_tx_fifo_size[5], int, 0444);
  69110. +MODULE_PARM_DESC(dev_tx_fifo_size_6, "Number of words in the Tx FIFO 4-768");
  69111. +module_param_named(dev_tx_fifo_size_7,
  69112. + dwc_otg_module_params.dev_tx_fifo_size[6], int, 0444);
  69113. +MODULE_PARM_DESC(dev_tx_fifo_size_7, "Number of words in the Tx FIFO 4-768");
  69114. +module_param_named(dev_tx_fifo_size_8,
  69115. + dwc_otg_module_params.dev_tx_fifo_size[7], int, 0444);
  69116. +MODULE_PARM_DESC(dev_tx_fifo_size_8, "Number of words in the Tx FIFO 4-768");
  69117. +module_param_named(dev_tx_fifo_size_9,
  69118. + dwc_otg_module_params.dev_tx_fifo_size[8], int, 0444);
  69119. +MODULE_PARM_DESC(dev_tx_fifo_size_9, "Number of words in the Tx FIFO 4-768");
  69120. +module_param_named(dev_tx_fifo_size_10,
  69121. + dwc_otg_module_params.dev_tx_fifo_size[9], int, 0444);
  69122. +MODULE_PARM_DESC(dev_tx_fifo_size_10, "Number of words in the Tx FIFO 4-768");
  69123. +module_param_named(dev_tx_fifo_size_11,
  69124. + dwc_otg_module_params.dev_tx_fifo_size[10], int, 0444);
  69125. +MODULE_PARM_DESC(dev_tx_fifo_size_11, "Number of words in the Tx FIFO 4-768");
  69126. +module_param_named(dev_tx_fifo_size_12,
  69127. + dwc_otg_module_params.dev_tx_fifo_size[11], int, 0444);
  69128. +MODULE_PARM_DESC(dev_tx_fifo_size_12, "Number of words in the Tx FIFO 4-768");
  69129. +module_param_named(dev_tx_fifo_size_13,
  69130. + dwc_otg_module_params.dev_tx_fifo_size[12], int, 0444);
  69131. +MODULE_PARM_DESC(dev_tx_fifo_size_13, "Number of words in the Tx FIFO 4-768");
  69132. +module_param_named(dev_tx_fifo_size_14,
  69133. + dwc_otg_module_params.dev_tx_fifo_size[13], int, 0444);
  69134. +MODULE_PARM_DESC(dev_tx_fifo_size_14, "Number of words in the Tx FIFO 4-768");
  69135. +module_param_named(dev_tx_fifo_size_15,
  69136. + dwc_otg_module_params.dev_tx_fifo_size[14], int, 0444);
  69137. +MODULE_PARM_DESC(dev_tx_fifo_size_15, "Number of words in the Tx FIFO 4-768");
  69138. +
  69139. +module_param_named(thr_ctl, dwc_otg_module_params.thr_ctl, int, 0444);
  69140. +MODULE_PARM_DESC(thr_ctl,
  69141. + "Thresholding enable flag bit 0 - non ISO Tx thr., 1 - ISO Tx thr., 2 - Rx thr.- bit 0=disabled 1=enabled");
  69142. +module_param_named(tx_thr_length, dwc_otg_module_params.tx_thr_length, int,
  69143. + 0444);
  69144. +MODULE_PARM_DESC(tx_thr_length, "Tx Threshold length in 32 bit DWORDs");
  69145. +module_param_named(rx_thr_length, dwc_otg_module_params.rx_thr_length, int,
  69146. + 0444);
  69147. +MODULE_PARM_DESC(rx_thr_length, "Rx Threshold length in 32 bit DWORDs");
  69148. +
  69149. +module_param_named(pti_enable, dwc_otg_module_params.pti_enable, int, 0444);
  69150. +module_param_named(mpi_enable, dwc_otg_module_params.mpi_enable, int, 0444);
  69151. +module_param_named(lpm_enable, dwc_otg_module_params.lpm_enable, int, 0444);
  69152. +MODULE_PARM_DESC(lpm_enable, "LPM Enable 0=LPM Disabled 1=LPM Enabled");
  69153. +module_param_named(ic_usb_cap, dwc_otg_module_params.ic_usb_cap, int, 0444);
  69154. +MODULE_PARM_DESC(ic_usb_cap,
  69155. + "IC_USB Capability 0=IC_USB Disabled 1=IC_USB Enabled");
  69156. +module_param_named(ahb_thr_ratio, dwc_otg_module_params.ahb_thr_ratio, int,
  69157. + 0444);
  69158. +MODULE_PARM_DESC(ahb_thr_ratio, "AHB Threshold Ratio");
  69159. +module_param_named(power_down, dwc_otg_module_params.power_down, int, 0444);
  69160. +MODULE_PARM_DESC(power_down, "Power Down Mode");
  69161. +module_param_named(reload_ctl, dwc_otg_module_params.reload_ctl, int, 0444);
  69162. +MODULE_PARM_DESC(reload_ctl, "HFIR Reload Control");
  69163. +module_param_named(dev_out_nak, dwc_otg_module_params.dev_out_nak, int, 0444);
  69164. +MODULE_PARM_DESC(dev_out_nak, "Enable Device OUT NAK");
  69165. +module_param_named(cont_on_bna, dwc_otg_module_params.cont_on_bna, int, 0444);
  69166. +MODULE_PARM_DESC(cont_on_bna, "Enable Enable Continue on BNA");
  69167. +module_param_named(ahb_single, dwc_otg_module_params.ahb_single, int, 0444);
  69168. +MODULE_PARM_DESC(ahb_single, "Enable AHB Single Support");
  69169. +module_param_named(adp_enable, dwc_otg_module_params.adp_enable, int, 0444);
  69170. +MODULE_PARM_DESC(adp_enable, "ADP Enable 0=ADP Disabled 1=ADP Enabled");
  69171. +module_param_named(otg_ver, dwc_otg_module_params.otg_ver, int, 0444);
  69172. +MODULE_PARM_DESC(otg_ver, "OTG revision supported 0=OTG 1.3 1=OTG 2.0");
  69173. +module_param(microframe_schedule, bool, 0444);
  69174. +MODULE_PARM_DESC(microframe_schedule, "Enable the microframe scheduler");
  69175. +
  69176. +module_param(fiq_enable, bool, 0444);
  69177. +MODULE_PARM_DESC(fiq_enable, "Enable the FIQ");
  69178. +module_param(nak_holdoff, ushort, 0644);
  69179. +MODULE_PARM_DESC(nak_holdoff, "Throttle duration for bulk split-transaction endpoints on a NAK. Default 8");
  69180. +module_param(fiq_fsm_enable, bool, 0444);
  69181. +MODULE_PARM_DESC(fiq_fsm_enable, "Enable the FIQ to perform split transactions as defined by fiq_fsm_mask");
  69182. +module_param(fiq_fsm_mask, ushort, 0444);
  69183. +MODULE_PARM_DESC(fiq_fsm_mask, "Bitmask of transactions to perform in the FIQ.\n"
  69184. + "Bit 0 : Non-periodic split transactions\n"
  69185. + "Bit 1 : Periodic split transactions\n"
  69186. + "Bit 2 : High-speed multi-transfer isochronous\n"
  69187. + "All other bits should be set 0.");
  69188. +
  69189. +
  69190. +/** @page "Module Parameters"
  69191. + *
  69192. + * The following parameters may be specified when starting the module.
  69193. + * These parameters define how the DWC_otg controller should be
  69194. + * configured. Parameter values are passed to the CIL initialization
  69195. + * function dwc_otg_cil_init
  69196. + *
  69197. + * Example: <code>modprobe dwc_otg speed=1 otg_cap=1</code>
  69198. + *
  69199. +
  69200. + <table>
  69201. + <tr><td>Parameter Name</td><td>Meaning</td></tr>
  69202. +
  69203. + <tr>
  69204. + <td>otg_cap</td>
  69205. + <td>Specifies the OTG capabilities. The driver will automatically detect the
  69206. + value for this parameter if none is specified.
  69207. + - 0: HNP and SRP capable (default, if available)
  69208. + - 1: SRP Only capable
  69209. + - 2: No HNP/SRP capable
  69210. + </td></tr>
  69211. +
  69212. + <tr>
  69213. + <td>dma_enable</td>
  69214. + <td>Specifies whether to use slave or DMA mode for accessing the data FIFOs.
  69215. + The driver will automatically detect the value for this parameter if none is
  69216. + specified.
  69217. + - 0: Slave
  69218. + - 1: DMA (default, if available)
  69219. + </td></tr>
  69220. +
  69221. + <tr>
  69222. + <td>dma_burst_size</td>
  69223. + <td>The DMA Burst size (applicable only for External DMA Mode).
  69224. + - Values: 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  69225. + </td></tr>
  69226. +
  69227. + <tr>
  69228. + <td>speed</td>
  69229. + <td>Specifies the maximum speed of operation in host and device mode. The
  69230. + actual speed depends on the speed of the attached device and the value of
  69231. + phy_type.
  69232. + - 0: High Speed (default)
  69233. + - 1: Full Speed
  69234. + </td></tr>
  69235. +
  69236. + <tr>
  69237. + <td>host_support_fs_ls_low_power</td>
  69238. + <td>Specifies whether low power mode is supported when attached to a Full
  69239. + Speed or Low Speed device in host mode.
  69240. + - 0: Don't support low power mode (default)
  69241. + - 1: Support low power mode
  69242. + </td></tr>
  69243. +
  69244. + <tr>
  69245. + <td>host_ls_low_power_phy_clk</td>
  69246. + <td>Specifies the PHY clock rate in low power mode when connected to a Low
  69247. + Speed device in host mode. This parameter is applicable only if
  69248. + HOST_SUPPORT_FS_LS_LOW_POWER is enabled.
  69249. + - 0: 48 MHz (default)
  69250. + - 1: 6 MHz
  69251. + </td></tr>
  69252. +
  69253. + <tr>
  69254. + <td>enable_dynamic_fifo</td>
  69255. + <td> Specifies whether FIFOs may be resized by the driver software.
  69256. + - 0: Use cC FIFO size parameters
  69257. + - 1: Allow dynamic FIFO sizing (default)
  69258. + </td></tr>
  69259. +
  69260. + <tr>
  69261. + <td>data_fifo_size</td>
  69262. + <td>Total number of 4-byte words in the data FIFO memory. This memory
  69263. + includes the Rx FIFO, non-periodic Tx FIFO, and periodic Tx FIFOs.
  69264. + - Values: 32 to 32768 (default 8192)
  69265. +
  69266. + Note: The total FIFO memory depth in the FPGA configuration is 8192.
  69267. + </td></tr>
  69268. +
  69269. + <tr>
  69270. + <td>dev_rx_fifo_size</td>
  69271. + <td>Number of 4-byte words in the Rx FIFO in device mode when dynamic
  69272. + FIFO sizing is enabled.
  69273. + - Values: 16 to 32768 (default 1064)
  69274. + </td></tr>
  69275. +
  69276. + <tr>
  69277. + <td>dev_nperio_tx_fifo_size</td>
  69278. + <td>Number of 4-byte words in the non-periodic Tx FIFO in device mode when
  69279. + dynamic FIFO sizing is enabled.
  69280. + - Values: 16 to 32768 (default 1024)
  69281. + </td></tr>
  69282. +
  69283. + <tr>
  69284. + <td>dev_perio_tx_fifo_size_n (n = 1 to 15)</td>
  69285. + <td>Number of 4-byte words in each of the periodic Tx FIFOs in device mode
  69286. + when dynamic FIFO sizing is enabled.
  69287. + - Values: 4 to 768 (default 256)
  69288. + </td></tr>
  69289. +
  69290. + <tr>
  69291. + <td>host_rx_fifo_size</td>
  69292. + <td>Number of 4-byte words in the Rx FIFO in host mode when dynamic FIFO
  69293. + sizing is enabled.
  69294. + - Values: 16 to 32768 (default 1024)
  69295. + </td></tr>
  69296. +
  69297. + <tr>
  69298. + <td>host_nperio_tx_fifo_size</td>
  69299. + <td>Number of 4-byte words in the non-periodic Tx FIFO in host mode when
  69300. + dynamic FIFO sizing is enabled in the core.
  69301. + - Values: 16 to 32768 (default 1024)
  69302. + </td></tr>
  69303. +
  69304. + <tr>
  69305. + <td>host_perio_tx_fifo_size</td>
  69306. + <td>Number of 4-byte words in the host periodic Tx FIFO when dynamic FIFO
  69307. + sizing is enabled.
  69308. + - Values: 16 to 32768 (default 1024)
  69309. + </td></tr>
  69310. +
  69311. + <tr>
  69312. + <td>max_transfer_size</td>
  69313. + <td>The maximum transfer size supported in bytes.
  69314. + - Values: 2047 to 65,535 (default 65,535)
  69315. + </td></tr>
  69316. +
  69317. + <tr>
  69318. + <td>max_packet_count</td>
  69319. + <td>The maximum number of packets in a transfer.
  69320. + - Values: 15 to 511 (default 511)
  69321. + </td></tr>
  69322. +
  69323. + <tr>
  69324. + <td>host_channels</td>
  69325. + <td>The number of host channel registers to use.
  69326. + - Values: 1 to 16 (default 12)
  69327. +
  69328. + Note: The FPGA configuration supports a maximum of 12 host channels.
  69329. + </td></tr>
  69330. +
  69331. + <tr>
  69332. + <td>dev_endpoints</td>
  69333. + <td>The number of endpoints in addition to EP0 available for device mode
  69334. + operations.
  69335. + - Values: 1 to 15 (default 6 IN and OUT)
  69336. +
  69337. + Note: The FPGA configuration supports a maximum of 6 IN and OUT endpoints in
  69338. + addition to EP0.
  69339. + </td></tr>
  69340. +
  69341. + <tr>
  69342. + <td>phy_type</td>
  69343. + <td>Specifies the type of PHY interface to use. By default, the driver will
  69344. + automatically detect the phy_type.
  69345. + - 0: Full Speed
  69346. + - 1: UTMI+ (default, if available)
  69347. + - 2: ULPI
  69348. + </td></tr>
  69349. +
  69350. + <tr>
  69351. + <td>phy_utmi_width</td>
  69352. + <td>Specifies the UTMI+ Data Width. This parameter is applicable for a
  69353. + phy_type of UTMI+. Also, this parameter is applicable only if the
  69354. + OTG_HSPHY_WIDTH cC parameter was set to "8 and 16 bits", meaning that the
  69355. + core has been configured to work at either data path width.
  69356. + - Values: 8 or 16 bits (default 16)
  69357. + </td></tr>
  69358. +
  69359. + <tr>
  69360. + <td>phy_ulpi_ddr</td>
  69361. + <td>Specifies whether the ULPI operates at double or single data rate. This
  69362. + parameter is only applicable if phy_type is ULPI.
  69363. + - 0: single data rate ULPI interface with 8 bit wide data bus (default)
  69364. + - 1: double data rate ULPI interface with 4 bit wide data bus
  69365. + </td></tr>
  69366. +
  69367. + <tr>
  69368. + <td>i2c_enable</td>
  69369. + <td>Specifies whether to use the I2C interface for full speed PHY. This
  69370. + parameter is only applicable if PHY_TYPE is FS.
  69371. + - 0: Disabled (default)
  69372. + - 1: Enabled
  69373. + </td></tr>
  69374. +
  69375. + <tr>
  69376. + <td>ulpi_fs_ls</td>
  69377. + <td>Specifies whether to use ULPI FS/LS mode only.
  69378. + - 0: Disabled (default)
  69379. + - 1: Enabled
  69380. + </td></tr>
  69381. +
  69382. + <tr>
  69383. + <td>ts_dline</td>
  69384. + <td>Specifies whether term select D-Line pulsing for all PHYs is enabled.
  69385. + - 0: Disabled (default)
  69386. + - 1: Enabled
  69387. + </td></tr>
  69388. +
  69389. + <tr>
  69390. + <td>en_multiple_tx_fifo</td>
  69391. + <td>Specifies whether dedicatedto tx fifos are enabled for non periodic IN EPs.
  69392. + The driver will automatically detect the value for this parameter if none is
  69393. + specified.
  69394. + - 0: Disabled
  69395. + - 1: Enabled (default, if available)
  69396. + </td></tr>
  69397. +
  69398. + <tr>
  69399. + <td>dev_tx_fifo_size_n (n = 1 to 15)</td>
  69400. + <td>Number of 4-byte words in each of the Tx FIFOs in device mode
  69401. + when dynamic FIFO sizing is enabled.
  69402. + - Values: 4 to 768 (default 256)
  69403. + </td></tr>
  69404. +
  69405. + <tr>
  69406. + <td>tx_thr_length</td>
  69407. + <td>Transmit Threshold length in 32 bit double words
  69408. + - Values: 8 to 128 (default 64)
  69409. + </td></tr>
  69410. +
  69411. + <tr>
  69412. + <td>rx_thr_length</td>
  69413. + <td>Receive Threshold length in 32 bit double words
  69414. + - Values: 8 to 128 (default 64)
  69415. + </td></tr>
  69416. +
  69417. +<tr>
  69418. + <td>thr_ctl</td>
  69419. + <td>Specifies whether to enable Thresholding for Device mode. Bits 0, 1, 2 of
  69420. + this parmater specifies if thresholding is enabled for non-Iso Tx, Iso Tx and
  69421. + Rx transfers accordingly.
  69422. + The driver will automatically detect the value for this parameter if none is
  69423. + specified.
  69424. + - Values: 0 to 7 (default 0)
  69425. + Bit values indicate:
  69426. + - 0: Thresholding disabled
  69427. + - 1: Thresholding enabled
  69428. + </td></tr>
  69429. +
  69430. +<tr>
  69431. + <td>dma_desc_enable</td>
  69432. + <td>Specifies whether to enable Descriptor DMA mode.
  69433. + The driver will automatically detect the value for this parameter if none is
  69434. + specified.
  69435. + - 0: Descriptor DMA disabled
  69436. + - 1: Descriptor DMA (default, if available)
  69437. + </td></tr>
  69438. +
  69439. +<tr>
  69440. + <td>mpi_enable</td>
  69441. + <td>Specifies whether to enable MPI enhancement mode.
  69442. + The driver will automatically detect the value for this parameter if none is
  69443. + specified.
  69444. + - 0: MPI disabled (default)
  69445. + - 1: MPI enable
  69446. + </td></tr>
  69447. +
  69448. +<tr>
  69449. + <td>pti_enable</td>
  69450. + <td>Specifies whether to enable PTI enhancement support.
  69451. + The driver will automatically detect the value for this parameter if none is
  69452. + specified.
  69453. + - 0: PTI disabled (default)
  69454. + - 1: PTI enable
  69455. + </td></tr>
  69456. +
  69457. +<tr>
  69458. + <td>lpm_enable</td>
  69459. + <td>Specifies whether to enable LPM support.
  69460. + The driver will automatically detect the value for this parameter if none is
  69461. + specified.
  69462. + - 0: LPM disabled
  69463. + - 1: LPM enable (default, if available)
  69464. + </td></tr>
  69465. +
  69466. +<tr>
  69467. + <td>ic_usb_cap</td>
  69468. + <td>Specifies whether to enable IC_USB capability.
  69469. + The driver will automatically detect the value for this parameter if none is
  69470. + specified.
  69471. + - 0: IC_USB disabled (default, if available)
  69472. + - 1: IC_USB enable
  69473. + </td></tr>
  69474. +
  69475. +<tr>
  69476. + <td>ahb_thr_ratio</td>
  69477. + <td>Specifies AHB Threshold ratio.
  69478. + - Values: 0 to 3 (default 0)
  69479. + </td></tr>
  69480. +
  69481. +<tr>
  69482. + <td>power_down</td>
  69483. + <td>Specifies Power Down(Hibernation) Mode.
  69484. + The driver will automatically detect the value for this parameter if none is
  69485. + specified.
  69486. + - 0: Power Down disabled (default)
  69487. + - 2: Power Down enabled
  69488. + </td></tr>
  69489. +
  69490. + <tr>
  69491. + <td>reload_ctl</td>
  69492. + <td>Specifies whether dynamic reloading of the HFIR register is allowed during
  69493. + run time. The driver will automatically detect the value for this parameter if
  69494. + none is specified. In case the HFIR value is reloaded when HFIR.RldCtrl == 1'b0
  69495. + the core might misbehave.
  69496. + - 0: Reload Control disabled (default)
  69497. + - 1: Reload Control enabled
  69498. + </td></tr>
  69499. +
  69500. + <tr>
  69501. + <td>dev_out_nak</td>
  69502. + <td>Specifies whether Device OUT NAK enhancement enabled or no.
  69503. + The driver will automatically detect the value for this parameter if
  69504. + none is specified. This parameter is valid only when OTG_EN_DESC_DMA == 1b1.
  69505. + - 0: The core does not set NAK after Bulk OUT transfer complete (default)
  69506. + - 1: The core sets NAK after Bulk OUT transfer complete
  69507. + </td></tr>
  69508. +
  69509. + <tr>
  69510. + <td>cont_on_bna</td>
  69511. + <td>Specifies whether Enable Continue on BNA enabled or no.
  69512. + After receiving BNA interrupt the core disables the endpoint,when the
  69513. + endpoint is re-enabled by the application the
  69514. + - 0: Core starts processing from the DOEPDMA descriptor (default)
  69515. + - 1: Core starts processing from the descriptor which received the BNA.
  69516. + This parameter is valid only when OTG_EN_DESC_DMA == 1b1.
  69517. + </td></tr>
  69518. +
  69519. + <tr>
  69520. + <td>ahb_single</td>
  69521. + <td>This bit when programmed supports SINGLE transfers for remainder data
  69522. + in a transfer for DMA mode of operation.
  69523. + - 0: The remainder data will be sent using INCR burst size (default)
  69524. + - 1: The remainder data will be sent using SINGLE burst size.
  69525. + </td></tr>
  69526. +
  69527. +<tr>
  69528. + <td>adp_enable</td>
  69529. + <td>Specifies whether ADP feature is enabled.
  69530. + The driver will automatically detect the value for this parameter if none is
  69531. + specified.
  69532. + - 0: ADP feature disabled (default)
  69533. + - 1: ADP feature enabled
  69534. + </td></tr>
  69535. +
  69536. + <tr>
  69537. + <td>otg_ver</td>
  69538. + <td>Specifies whether OTG is performing as USB OTG Revision 2.0 or Revision 1.3
  69539. + USB OTG device.
  69540. + - 0: OTG 2.0 support disabled (default)
  69541. + - 1: OTG 2.0 support enabled
  69542. + </td></tr>
  69543. +
  69544. +*/
  69545. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_driver.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_driver.h
  69546. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_driver.h 1970-01-01 01:00:00.000000000 +0100
  69547. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_driver.h 2014-07-07 10:45:43.000000000 +0200
  69548. @@ -0,0 +1,86 @@
  69549. +/* ==========================================================================
  69550. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_driver.h $
  69551. + * $Revision: #19 $
  69552. + * $Date: 2010/11/15 $
  69553. + * $Change: 1627671 $
  69554. + *
  69555. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  69556. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  69557. + * otherwise expressly agreed to in writing between Synopsys and you.
  69558. + *
  69559. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  69560. + * any End User Software License Agreement or Agreement for Licensed Product
  69561. + * with Synopsys or any supplement thereto. You are permitted to use and
  69562. + * redistribute this Software in source and binary forms, with or without
  69563. + * modification, provided that redistributions of source code must retain this
  69564. + * notice. You may not view, use, disclose, copy or distribute this file or
  69565. + * any information contained herein except pursuant to this license grant from
  69566. + * Synopsys. If you do not agree with this notice, including the disclaimer
  69567. + * below, then you are not authorized to use the Software.
  69568. + *
  69569. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  69570. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  69571. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  69572. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  69573. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  69574. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  69575. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  69576. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  69577. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  69578. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  69579. + * DAMAGE.
  69580. + * ========================================================================== */
  69581. +
  69582. +#ifndef __DWC_OTG_DRIVER_H__
  69583. +#define __DWC_OTG_DRIVER_H__
  69584. +
  69585. +/** @file
  69586. + * This file contains the interface to the Linux driver.
  69587. + */
  69588. +#include "dwc_otg_os_dep.h"
  69589. +#include "dwc_otg_core_if.h"
  69590. +
  69591. +/* Type declarations */
  69592. +struct dwc_otg_pcd;
  69593. +struct dwc_otg_hcd;
  69594. +
  69595. +/**
  69596. + * This structure is a wrapper that encapsulates the driver components used to
  69597. + * manage a single DWC_otg controller.
  69598. + */
  69599. +typedef struct dwc_otg_device {
  69600. + /** Structure containing OS-dependent stuff. KEEP THIS STRUCT AT THE
  69601. + * VERY BEGINNING OF THE DEVICE STRUCT. OSes such as FreeBSD and NetBSD
  69602. + * require this. */
  69603. + struct os_dependent os_dep;
  69604. +
  69605. + /** Pointer to the core interface structure. */
  69606. + dwc_otg_core_if_t *core_if;
  69607. +
  69608. + /** Pointer to the PCD structure. */
  69609. + struct dwc_otg_pcd *pcd;
  69610. +
  69611. + /** Pointer to the HCD structure. */
  69612. + struct dwc_otg_hcd *hcd;
  69613. +
  69614. + /** Flag to indicate whether the common IRQ handler is installed. */
  69615. + uint8_t common_irq_installed;
  69616. +
  69617. +} dwc_otg_device_t;
  69618. +
  69619. +/*We must clear S3C24XX_EINTPEND external interrupt register
  69620. + * because after clearing in this register trigerred IRQ from
  69621. + * H/W core in kernel interrupt can be occured again before OTG
  69622. + * handlers clear all IRQ sources of Core registers because of
  69623. + * timing latencies and Low Level IRQ Type.
  69624. + */
  69625. +#ifdef CONFIG_MACH_IPMATE
  69626. +#define S3C2410X_CLEAR_EINTPEND() \
  69627. +do { \
  69628. + __raw_writel(1UL << 11,S3C24XX_EINTPEND); \
  69629. +} while (0)
  69630. +#else
  69631. +#define S3C2410X_CLEAR_EINTPEND() do { } while (0)
  69632. +#endif
  69633. +
  69634. +#endif
  69635. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c
  69636. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c 1970-01-01 01:00:00.000000000 +0100
  69637. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c 2014-07-07 10:45:43.000000000 +0200
  69638. @@ -0,0 +1,1294 @@
  69639. +/*
  69640. + * dwc_otg_fiq_fsm.c - The finite state machine FIQ
  69641. + *
  69642. + * Copyright (c) 2013 Raspberry Pi Foundation
  69643. + *
  69644. + * Author: Jonathan Bell <jonathan@raspberrypi.org>
  69645. + * All rights reserved.
  69646. + *
  69647. + * Redistribution and use in source and binary forms, with or without
  69648. + * modification, are permitted provided that the following conditions are met:
  69649. + * * Redistributions of source code must retain the above copyright
  69650. + * notice, this list of conditions and the following disclaimer.
  69651. + * * Redistributions in binary form must reproduce the above copyright
  69652. + * notice, this list of conditions and the following disclaimer in the
  69653. + * documentation and/or other materials provided with the distribution.
  69654. + * * Neither the name of Raspberry Pi nor the
  69655. + * names of its contributors may be used to endorse or promote products
  69656. + * derived from this software without specific prior written permission.
  69657. + *
  69658. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  69659. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  69660. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  69661. + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  69662. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  69663. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  69664. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  69665. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  69666. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  69667. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  69668. + *
  69669. + * This FIQ implements functionality that performs split transactions on
  69670. + * the dwc_otg hardware without any outside intervention. A split transaction
  69671. + * is "queued" by nominating a specific host channel to perform the entirety
  69672. + * of a split transaction. This FIQ will then perform the microframe-precise
  69673. + * scheduling required in each phase of the transaction until completion.
  69674. + *
  69675. + * The FIQ functionality is glued into the Synopsys driver via the entry point
  69676. + * in the FSM enqueue function, and at the exit point in handling a HC interrupt
  69677. + * for a FSM-enabled channel.
  69678. + *
  69679. + * NB: Large parts of this implementation have architecture-specific code.
  69680. + * For porting this functionality to other ARM machines, the minimum is required:
  69681. + * - An interrupt controller allowing the top-level dwc USB interrupt to be routed
  69682. + * to the FIQ
  69683. + * - A method of forcing a software generated interrupt from FIQ mode that then
  69684. + * triggers an IRQ entry (with the dwc USB handler called by this IRQ number)
  69685. + * - Guaranteed interrupt routing such that both the FIQ and SGI occur on the same
  69686. + * processor core - there is no locking between the FIQ and IRQ (aside from
  69687. + * local_fiq_disable)
  69688. + *
  69689. + */
  69690. +
  69691. +#include "dwc_otg_fiq_fsm.h"
  69692. +
  69693. +
  69694. +char buffer[1000*16];
  69695. +int wptr;
  69696. +void notrace _fiq_print(enum fiq_debug_level dbg_lvl, volatile struct fiq_state *state, char *fmt, ...)
  69697. +{
  69698. + enum fiq_debug_level dbg_lvl_req = FIQDBG_ERR;
  69699. + va_list args;
  69700. + char text[17];
  69701. + hfnum_data_t hfnum = { .d32 = FIQ_READ(state->dwc_regs_base + 0x408) };
  69702. +
  69703. + if((dbg_lvl & dbg_lvl_req) || dbg_lvl == FIQDBG_ERR)
  69704. + {
  69705. + snprintf(text, 9, " %4d:%1u ", hfnum.b.frnum/8, hfnum.b.frnum & 7);
  69706. + va_start(args, fmt);
  69707. + vsnprintf(text+8, 9, fmt, args);
  69708. + va_end(args);
  69709. +
  69710. + memcpy(buffer + wptr, text, 16);
  69711. + wptr = (wptr + 16) % sizeof(buffer);
  69712. + }
  69713. +}
  69714. +
  69715. +/**
  69716. + * fiq_fsm_restart_channel() - Poke channel enable bit for a split transaction
  69717. + * @channel: channel to re-enable
  69718. + */
  69719. +static void fiq_fsm_restart_channel(struct fiq_state *st, int n, int force)
  69720. +{
  69721. + hcchar_data_t hcchar = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR) };
  69722. +
  69723. + hcchar.b.chen = 0;
  69724. + if (st->channel[n].hcchar_copy.b.eptype & 0x1) {
  69725. + hfnum_data_t hfnum = { .d32 = FIQ_READ(st->dwc_regs_base + HFNUM) };
  69726. + /* Hardware bug workaround: update the ssplit index */
  69727. + if (st->channel[n].hcsplt_copy.b.spltena)
  69728. + st->channel[n].expected_uframe = (hfnum.b.frnum + 1) & 0x3FFF;
  69729. +
  69730. + hcchar.b.oddfrm = (hfnum.b.frnum & 0x1) ? 0 : 1;
  69731. + }
  69732. +
  69733. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR, hcchar.d32);
  69734. + hcchar.d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  69735. + hcchar.b.chen = 1;
  69736. +
  69737. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR, hcchar.d32);
  69738. + fiq_print(FIQDBG_INT, st, "HCGO %01d %01d", n, force);
  69739. +}
  69740. +
  69741. +/**
  69742. + * fiq_fsm_setup_csplit() - Prepare a host channel for a CSplit transaction stage
  69743. + * @st: Pointer to the channel's state
  69744. + * @n : channel number
  69745. + *
  69746. + * Change host channel registers to perform a complete-split transaction. Being mindful of the
  69747. + * endpoint direction, set control regs up correctly.
  69748. + */
  69749. +static void notrace fiq_fsm_setup_csplit(struct fiq_state *st, int n)
  69750. +{
  69751. + hcsplt_data_t hcsplt = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT) };
  69752. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ) };
  69753. +
  69754. + hcsplt.b.compsplt = 1;
  69755. + if (st->channel[n].hcchar_copy.b.epdir == 1) {
  69756. + // If IN, the CSPLIT result contains the data or a hub handshake. hctsiz = maxpacket.
  69757. + hctsiz.b.xfersize = st->channel[n].hctsiz_copy.b.xfersize;
  69758. + } else {
  69759. + // If OUT, the CSPLIT result contains handshake only.
  69760. + hctsiz.b.xfersize = 0;
  69761. + }
  69762. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT, hcsplt.d32);
  69763. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, hctsiz.d32);
  69764. + mb();
  69765. +}
  69766. +
  69767. +static inline int notrace fiq_get_xfer_len(struct fiq_state *st, int n)
  69768. +{
  69769. + /* The xfersize register is a bit wonky. For IN transfers, it decrements by the packet size. */
  69770. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ) };
  69771. +
  69772. + if (st->channel[n].hcchar_copy.b.epdir == 0) {
  69773. + return st->channel[n].hctsiz_copy.b.xfersize;
  69774. + } else {
  69775. + return st->channel[n].hctsiz_copy.b.xfersize - hctsiz.b.xfersize;
  69776. + }
  69777. +
  69778. +}
  69779. +
  69780. +
  69781. +/**
  69782. + * fiq_increment_dma_buf() - update DMA address for bounce buffers after a CSPLIT
  69783. + *
  69784. + * Of use only for IN periodic transfers.
  69785. + */
  69786. +static int notrace fiq_increment_dma_buf(struct fiq_state *st, int num_channels, int n)
  69787. +{
  69788. + hcdma_data_t hcdma;
  69789. + int i = st->channel[n].dma_info.index;
  69790. + int len;
  69791. + struct fiq_dma_blob *blob = (struct fiq_dma_blob *) st->dma_base;
  69792. +
  69793. + len = fiq_get_xfer_len(st, n);
  69794. + fiq_print(FIQDBG_INT, st, "LEN: %03d", len);
  69795. + st->channel[n].dma_info.slot_len[i] = len;
  69796. + i++;
  69797. + if (i > 6)
  69798. + BUG();
  69799. +
  69800. + hcdma.d32 = (dma_addr_t) &blob->channel[n].index[i].buf[0];
  69801. + FIQ_WRITE(st->dwc_regs_base + HC_DMA + (HC_OFFSET * n), hcdma.d32);
  69802. + st->channel[n].dma_info.index = i;
  69803. + return 0;
  69804. +}
  69805. +
  69806. +/**
  69807. + * fiq_reload_hctsiz() - for IN transactions, reset HCTSIZ
  69808. + */
  69809. +static void notrace fiq_fsm_reload_hctsiz(struct fiq_state *st, int n)
  69810. +{
  69811. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ) };
  69812. + hctsiz.b.xfersize = st->channel[n].hctsiz_copy.b.xfersize;
  69813. + hctsiz.b.pktcnt = 1;
  69814. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, hctsiz.d32);
  69815. +}
  69816. +
  69817. +/**
  69818. + * fiq_iso_out_advance() - update DMA address and split position bits
  69819. + * for isochronous OUT transactions.
  69820. + *
  69821. + * Returns 1 if this is the last packet queued, 0 otherwise. Split-ALL and
  69822. + * Split-BEGIN states are not handled - this is done when the transaction was queued.
  69823. + *
  69824. + * This function must only be called from the FIQ_ISO_OUT_ACTIVE state.
  69825. + */
  69826. +static int notrace fiq_iso_out_advance(struct fiq_state *st, int num_channels, int n)
  69827. +{
  69828. + hcsplt_data_t hcsplt;
  69829. + hctsiz_data_t hctsiz;
  69830. + hcdma_data_t hcdma;
  69831. + struct fiq_dma_blob *blob = (struct fiq_dma_blob *) st->dma_base;
  69832. + int last = 0;
  69833. + int i = st->channel[n].dma_info.index;
  69834. +
  69835. + fiq_print(FIQDBG_INT, st, "ADV %01d %01d ", n, i);
  69836. + i++;
  69837. + if (i == 4)
  69838. + last = 1;
  69839. + if (st->channel[n].dma_info.slot_len[i+1] == 255)
  69840. + last = 1;
  69841. +
  69842. + /* New DMA address - address of bounce buffer referred to in index */
  69843. + hcdma.d32 = (uint32_t) &blob->channel[n].index[i].buf[0];
  69844. + //hcdma.d32 = FIQ_READ(st->dwc_regs_base + HC_DMA + (HC_OFFSET * n));
  69845. + //hcdma.d32 += st->channel[n].dma_info.slot_len[i];
  69846. + fiq_print(FIQDBG_INT, st, "LAST: %01d ", last);
  69847. + fiq_print(FIQDBG_INT, st, "LEN: %03d", st->channel[n].dma_info.slot_len[i]);
  69848. + hcsplt.d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT);
  69849. + hctsiz.d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ);
  69850. + hcsplt.b.xactpos = (last) ? ISOC_XACTPOS_END : ISOC_XACTPOS_MID;
  69851. + /* Set up new packet length */
  69852. + hctsiz.b.pktcnt = 1;
  69853. + hctsiz.b.xfersize = st->channel[n].dma_info.slot_len[i];
  69854. + fiq_print(FIQDBG_INT, st, "%08x", hctsiz.d32);
  69855. +
  69856. + st->channel[n].dma_info.index++;
  69857. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT, hcsplt.d32);
  69858. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, hctsiz.d32);
  69859. + FIQ_WRITE(st->dwc_regs_base + HC_DMA + (HC_OFFSET * n), hcdma.d32);
  69860. + return last;
  69861. +}
  69862. +
  69863. +/**
  69864. + * fiq_fsm_tt_next_isoc() - queue next pending isochronous out start-split on a TT
  69865. + *
  69866. + * Despite the limitations of the DWC core, we can force a microframe pipeline of
  69867. + * isochronous OUT start-split transactions while waiting for a corresponding other-type
  69868. + * of endpoint to finish its CSPLITs. TTs have big periodic buffers therefore it
  69869. + * is very unlikely that filling the start-split FIFO will cause data loss.
  69870. + * This allows much better interleaving of transactions in an order-independent way-
  69871. + * there is no requirement to prioritise isochronous, just a state-space search has
  69872. + * to be performed on each periodic start-split complete interrupt.
  69873. + */
  69874. +static int notrace fiq_fsm_tt_next_isoc(struct fiq_state *st, int num_channels, int n)
  69875. +{
  69876. + int hub_addr = st->channel[n].hub_addr;
  69877. + int port_addr = st->channel[n].port_addr;
  69878. + int i, poked = 0;
  69879. + for (i = 0; i < num_channels; i++) {
  69880. + if (i == n || st->channel[i].fsm == FIQ_PASSTHROUGH)
  69881. + continue;
  69882. + if (st->channel[i].hub_addr == hub_addr &&
  69883. + st->channel[i].port_addr == port_addr) {
  69884. + switch (st->channel[i].fsm) {
  69885. + case FIQ_PER_ISO_OUT_PENDING:
  69886. + if (st->channel[i].nrpackets == 1) {
  69887. + st->channel[i].fsm = FIQ_PER_ISO_OUT_LAST;
  69888. + } else {
  69889. + st->channel[i].fsm = FIQ_PER_ISO_OUT_ACTIVE;
  69890. + }
  69891. + fiq_fsm_restart_channel(st, i, 0);
  69892. + poked = 1;
  69893. + break;
  69894. +
  69895. + default:
  69896. + break;
  69897. + }
  69898. + }
  69899. + if (poked)
  69900. + break;
  69901. + }
  69902. + return poked;
  69903. +}
  69904. +
  69905. +/**
  69906. + * fiq_fsm_tt_in_use() - search for host channels using this TT
  69907. + * @n: Channel to use as reference
  69908. + *
  69909. + */
  69910. +int notrace noinline fiq_fsm_tt_in_use(struct fiq_state *st, int num_channels, int n)
  69911. +{
  69912. + int hub_addr = st->channel[n].hub_addr;
  69913. + int port_addr = st->channel[n].port_addr;
  69914. + int i, in_use = 0;
  69915. + for (i = 0; i < num_channels; i++) {
  69916. + if (i == n || st->channel[i].fsm == FIQ_PASSTHROUGH)
  69917. + continue;
  69918. + switch (st->channel[i].fsm) {
  69919. + /* TT is reserved for channels that are in the middle of a periodic
  69920. + * split transaction.
  69921. + */
  69922. + case FIQ_PER_SSPLIT_STARTED:
  69923. + case FIQ_PER_CSPLIT_WAIT:
  69924. + case FIQ_PER_CSPLIT_NYET1:
  69925. + //case FIQ_PER_CSPLIT_POLL:
  69926. + case FIQ_PER_ISO_OUT_ACTIVE:
  69927. + case FIQ_PER_ISO_OUT_LAST:
  69928. + if (st->channel[i].hub_addr == hub_addr &&
  69929. + st->channel[i].port_addr == port_addr) {
  69930. + in_use = 1;
  69931. + }
  69932. + break;
  69933. + default:
  69934. + break;
  69935. + }
  69936. + if (in_use)
  69937. + break;
  69938. + }
  69939. + return in_use;
  69940. +}
  69941. +
  69942. +/**
  69943. + * fiq_fsm_more_csplits() - determine whether additional CSPLITs need
  69944. + * to be issued for this IN transaction.
  69945. + *
  69946. + * We cannot tell the inbound PID of a data packet due to hardware limitations.
  69947. + * we need to make an educated guess as to whether we need to queue another CSPLIT
  69948. + * or not. A no-brainer is when we have received enough data to fill the endpoint
  69949. + * size, but for endpoints that give variable-length data then we have to resort
  69950. + * to heuristics.
  69951. + *
  69952. + * We also return whether this is the last CSPLIT to be queued, again based on
  69953. + * heuristics. This is to allow a 1-uframe overlap of periodic split transactions.
  69954. + * Note: requires at least 1 CSPLIT to have been performed prior to being called.
  69955. + */
  69956. +
  69957. +/*
  69958. + * We need some way of guaranteeing if a returned periodic packet of size X
  69959. + * has a DATA0 PID.
  69960. + * The heuristic value of 144 bytes assumes that the received data has maximal
  69961. + * bit-stuffing and the clock frequency of the transmitting device is at the lowest
  69962. + * permissible limit. If the transfer length results in a final packet size
  69963. + * 144 < p <= 188, then an erroneous CSPLIT will be issued.
  69964. + * Also used to ensure that an endpoint will nominally only return a single
  69965. + * complete-split worth of data.
  69966. + */
  69967. +#define DATA0_PID_HEURISTIC 144
  69968. +
  69969. +static int notrace noinline fiq_fsm_more_csplits(struct fiq_state *state, int n, int *probably_last)
  69970. +{
  69971. +
  69972. + int i;
  69973. + int total_len = 0;
  69974. + int more_needed = 1;
  69975. + struct fiq_channel_state *st = &state->channel[n];
  69976. +
  69977. + for (i = 0; i < st->dma_info.index; i++) {
  69978. + total_len += st->dma_info.slot_len[i];
  69979. + }
  69980. +
  69981. + *probably_last = 0;
  69982. +
  69983. + if (st->hcchar_copy.b.eptype == 0x3) {
  69984. + /*
  69985. + * An interrupt endpoint will take max 2 CSPLITs. if we are receiving data
  69986. + * then this is definitely the last CSPLIT.
  69987. + */
  69988. + *probably_last = 1;
  69989. + } else {
  69990. + /* Isoc IN. This is a bit risky if we are the first transaction:
  69991. + * we may have been held off slightly. */
  69992. + if (i > 1 && st->dma_info.slot_len[st->dma_info.index-1] <= DATA0_PID_HEURISTIC) {
  69993. + more_needed = 0;
  69994. + }
  69995. + /* If in the next uframe we will receive enough data to fill the endpoint,
  69996. + * then only issue 1 more csplit.
  69997. + */
  69998. + if (st->hctsiz_copy.b.xfersize - total_len <= DATA0_PID_HEURISTIC)
  69999. + *probably_last = 1;
  70000. + }
  70001. +
  70002. + if (total_len >= st->hctsiz_copy.b.xfersize ||
  70003. + i == 6 || total_len == 0)
  70004. + /* Note: due to bit stuffing it is possible to have > 6 CSPLITs for
  70005. + * a single endpoint. Accepting more would completely break our scheduling mechanism though
  70006. + * - in these extreme cases we will pass through a truncated packet.
  70007. + */
  70008. + more_needed = 0;
  70009. +
  70010. + return more_needed;
  70011. +}
  70012. +
  70013. +/**
  70014. + * fiq_fsm_too_late() - Test transaction for lateness
  70015. + *
  70016. + * If a SSPLIT for a large IN transaction is issued too late in a frame,
  70017. + * the hub will disable the port to the device and respond with ERR handshakes.
  70018. + * The hub status endpoint will not reflect this change.
  70019. + * Returns 1 if we will issue a SSPLIT that will result in a device babble.
  70020. + */
  70021. +int notrace fiq_fsm_too_late(struct fiq_state *st, int n)
  70022. +{
  70023. + int uframe;
  70024. + hfnum_data_t hfnum = { .d32 = FIQ_READ(st->dwc_regs_base + HFNUM) };
  70025. + uframe = hfnum.b.frnum & 0x7;
  70026. + if ((uframe < 6) && (st->channel[n].nrpackets + 1 + uframe > 7)) {
  70027. + return 1;
  70028. + } else {
  70029. + return 0;
  70030. + }
  70031. +}
  70032. +
  70033. +
  70034. +/**
  70035. + * fiq_fsm_start_next_periodic() - A half-arsed attempt at a microframe pipeline
  70036. + *
  70037. + * Search pending transactions in the start-split pending state and queue them.
  70038. + * Don't queue packets in uframe .5 (comes out in .6) (USB2.0 11.18.4).
  70039. + * Note: we specifically don't do isochronous OUT transactions first because better
  70040. + * use of the TT's start-split fifo can be achieved by pipelining an IN before an OUT.
  70041. + */
  70042. +static void notrace noinline fiq_fsm_start_next_periodic(struct fiq_state *st, int num_channels)
  70043. +{
  70044. + int n;
  70045. + hfnum_data_t hfnum = { .d32 = FIQ_READ(st->dwc_regs_base + HFNUM) };
  70046. + if ((hfnum.b.frnum & 0x7) == 5)
  70047. + return;
  70048. + for (n = 0; n < num_channels; n++) {
  70049. + if (st->channel[n].fsm == FIQ_PER_SSPLIT_QUEUED) {
  70050. + /* Check to see if any other transactions are using this TT */
  70051. + if(!fiq_fsm_tt_in_use(st, num_channels, n)) {
  70052. + if (!fiq_fsm_too_late(st, n)) {
  70053. + st->channel[n].fsm = FIQ_PER_SSPLIT_STARTED;
  70054. + fiq_print(FIQDBG_INT, st, "NEXTPER ");
  70055. + fiq_fsm_restart_channel(st, n, 0);
  70056. + } else {
  70057. + st->channel[n].fsm = FIQ_PER_SPLIT_TIMEOUT;
  70058. + }
  70059. + break;
  70060. + }
  70061. + }
  70062. + }
  70063. + for (n = 0; n < num_channels; n++) {
  70064. + if (st->channel[n].fsm == FIQ_PER_ISO_OUT_PENDING) {
  70065. + if (!fiq_fsm_tt_in_use(st, num_channels, n)) {
  70066. + fiq_print(FIQDBG_INT, st, "NEXTISO ");
  70067. + st->channel[n].fsm = FIQ_PER_ISO_OUT_ACTIVE;
  70068. + fiq_fsm_restart_channel(st, n, 0);
  70069. + break;
  70070. + }
  70071. + }
  70072. + }
  70073. +}
  70074. +
  70075. +/**
  70076. + * fiq_fsm_update_hs_isoc() - update isochronous frame and transfer data
  70077. + * @state: Pointer to fiq_state
  70078. + * @n: Channel transaction is active on
  70079. + * @hcint: Copy of host channel interrupt register
  70080. + *
  70081. + * Returns 0 if there are no more transactions for this HC to do, 1
  70082. + * otherwise.
  70083. + */
  70084. +static int notrace noinline fiq_fsm_update_hs_isoc(struct fiq_state *state, int n, hcint_data_t hcint)
  70085. +{
  70086. + struct fiq_channel_state *st = &state->channel[n];
  70087. + int xfer_len = 0, nrpackets = 0;
  70088. + hcdma_data_t hcdma;
  70089. + fiq_print(FIQDBG_INT, state, "HSISO %02d", n);
  70090. +
  70091. + xfer_len = fiq_get_xfer_len(state, n);
  70092. + st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].actual_length = xfer_len;
  70093. +
  70094. + st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].status = hcint.d32;
  70095. +
  70096. + st->hs_isoc_info.index++;
  70097. + if (st->hs_isoc_info.index == st->hs_isoc_info.nrframes) {
  70098. + return 0;
  70099. + }
  70100. +
  70101. + /* grab the next DMA address offset from the array */
  70102. + hcdma.d32 = st->hcdma_copy.d32 + st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].offset;
  70103. + FIQ_WRITE(state->dwc_regs_base + HC_DMA + (HC_OFFSET * n), hcdma.d32);
  70104. +
  70105. + /* We need to set multi_count. This is a bit tricky - has to be set per-transaction as
  70106. + * the core needs to be told to send the correct number. Caution: for IN transfers,
  70107. + * this is always set to the maximum size of the endpoint. */
  70108. + xfer_len = st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].length;
  70109. + /* Integer divide in a FIQ: fun. FIXME: make this not suck */
  70110. + nrpackets = (xfer_len + st->hcchar_copy.b.mps - 1) / st->hcchar_copy.b.mps;
  70111. + if (nrpackets == 0)
  70112. + nrpackets = 1;
  70113. + st->hcchar_copy.b.multicnt = nrpackets;
  70114. + st->hctsiz_copy.b.pktcnt = nrpackets;
  70115. +
  70116. + /* Initial PID also needs to be set */
  70117. + if (st->hcchar_copy.b.epdir == 0) {
  70118. + st->hctsiz_copy.b.xfersize = xfer_len;
  70119. + switch (st->hcchar_copy.b.multicnt) {
  70120. + case 1:
  70121. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  70122. + break;
  70123. + case 2:
  70124. + case 3:
  70125. + st->hctsiz_copy.b.pid = DWC_PID_MDATA;
  70126. + break;
  70127. + }
  70128. +
  70129. + } else {
  70130. + switch (st->hcchar_copy.b.multicnt) {
  70131. + st->hctsiz_copy.b.xfersize = nrpackets * st->hcchar_copy.b.mps;
  70132. + case 1:
  70133. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  70134. + break;
  70135. + case 2:
  70136. + st->hctsiz_copy.b.pid = DWC_PID_DATA1;
  70137. + break;
  70138. + case 3:
  70139. + st->hctsiz_copy.b.pid = DWC_PID_DATA2;
  70140. + break;
  70141. + }
  70142. + }
  70143. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, st->hctsiz_copy.d32);
  70144. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR, st->hcchar_copy.d32);
  70145. + /* Channel is enabled on hcint handler exit */
  70146. + fiq_print(FIQDBG_INT, state, "HSISOOUT");
  70147. + return 1;
  70148. +}
  70149. +
  70150. +
  70151. +/**
  70152. + * fiq_fsm_do_sof() - FSM start-of-frame interrupt handler
  70153. + * @state: Pointer to the state struct passed from banked FIQ mode registers.
  70154. + * @num_channels: set according to the DWC hardware configuration
  70155. + *
  70156. + * The SOF handler in FSM mode has two functions
  70157. + * 1. Hold off SOF from causing schedule advancement in IRQ context if there's
  70158. + * nothing to do
  70159. + * 2. Advance certain FSM states that require either a microframe delay, or a microframe
  70160. + * of holdoff.
  70161. + *
  70162. + * The second part is architecture-specific to mach-bcm2835 -
  70163. + * a sane interrupt controller would have a mask register for ARM interrupt sources
  70164. + * to be promoted to the nFIQ line, but it doesn't. Instead a single interrupt
  70165. + * number (USB) can be enabled. This means that certain parts of the USB specification
  70166. + * that require "wait a little while, then issue another packet" cannot be fulfilled with
  70167. + * the timing granularity required to achieve optimal throughout. The workaround is to use
  70168. + * the SOF "timer" (125uS) to perform this task.
  70169. + */
  70170. +static int notrace noinline fiq_fsm_do_sof(struct fiq_state *state, int num_channels)
  70171. +{
  70172. + hfnum_data_t hfnum = { .d32 = FIQ_READ(state->dwc_regs_base + HFNUM) };
  70173. + int n;
  70174. + int kick_irq = 0;
  70175. +
  70176. + if ((hfnum.b.frnum & 0x7) == 1) {
  70177. + /* We cannot issue csplits for transactions in the last frame past (n+1).1
  70178. + * Check to see if there are any transactions that are stale.
  70179. + * Boot them out.
  70180. + */
  70181. + for (n = 0; n < num_channels; n++) {
  70182. + switch (state->channel[n].fsm) {
  70183. + case FIQ_PER_CSPLIT_WAIT:
  70184. + case FIQ_PER_CSPLIT_NYET1:
  70185. + case FIQ_PER_CSPLIT_POLL:
  70186. + case FIQ_PER_CSPLIT_LAST:
  70187. + /* Check if we are no longer in the same full-speed frame. */
  70188. + if (((state->channel[n].expected_uframe & 0x3FFF) & ~0x7) <
  70189. + (hfnum.b.frnum & ~0x7))
  70190. + state->channel[n].fsm = FIQ_PER_SPLIT_TIMEOUT;
  70191. + break;
  70192. + default:
  70193. + break;
  70194. + }
  70195. + }
  70196. + }
  70197. +
  70198. + for (n = 0; n < num_channels; n++) {
  70199. + switch (state->channel[n].fsm) {
  70200. +
  70201. + case FIQ_NP_SSPLIT_RETRY:
  70202. + case FIQ_NP_IN_CSPLIT_RETRY:
  70203. + case FIQ_NP_OUT_CSPLIT_RETRY:
  70204. + fiq_fsm_restart_channel(state, n, 0);
  70205. + break;
  70206. +
  70207. + case FIQ_HS_ISOC_SLEEPING:
  70208. + state->channel[n].fsm = FIQ_HS_ISOC_TURBO;
  70209. + fiq_fsm_restart_channel(state, n, 0);
  70210. + break;
  70211. +
  70212. + case FIQ_PER_SSPLIT_QUEUED:
  70213. + if ((hfnum.b.frnum & 0x7) == 5)
  70214. + break;
  70215. + if(!fiq_fsm_tt_in_use(state, num_channels, n)) {
  70216. + if (!fiq_fsm_too_late(state, n)) {
  70217. + fiq_print(FIQDBG_INT, st, "SOF GO %01d", n);
  70218. + fiq_fsm_restart_channel(state, n, 0);
  70219. + state->channel[n].fsm = FIQ_PER_SSPLIT_STARTED;
  70220. + } else {
  70221. + /* Transaction cannot be started without risking a device babble error */
  70222. + state->channel[n].fsm = FIQ_PER_SPLIT_TIMEOUT;
  70223. + state->haintmsk_saved.b2.chint &= ~(1 << n);
  70224. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK, 0);
  70225. + kick_irq |= 1;
  70226. + }
  70227. + }
  70228. + break;
  70229. +
  70230. + case FIQ_PER_ISO_OUT_PENDING:
  70231. + /* Ordinarily, this should be poked after the SSPLIT
  70232. + * complete interrupt for a competing transfer on the same
  70233. + * TT. Doesn't happen for aborted transactions though.
  70234. + */
  70235. + if ((hfnum.b.frnum & 0x7) >= 5)
  70236. + break;
  70237. + if (!fiq_fsm_tt_in_use(state, num_channels, n)) {
  70238. + /* Hardware bug. SOF can sometimes occur after the channel halt interrupt
  70239. + * that caused this.
  70240. + */
  70241. + fiq_fsm_restart_channel(state, n, 0);
  70242. + fiq_print(FIQDBG_INT, state, "SOF ISOC");
  70243. + if (state->channel[n].nrpackets == 1) {
  70244. + state->channel[n].fsm = FIQ_PER_ISO_OUT_LAST;
  70245. + } else {
  70246. + state->channel[n].fsm = FIQ_PER_ISO_OUT_ACTIVE;
  70247. + }
  70248. + }
  70249. + break;
  70250. +
  70251. + case FIQ_PER_CSPLIT_WAIT:
  70252. + /* we are guaranteed to be in this state if and only if the SSPLIT interrupt
  70253. + * occurred when the bus transaction occurred. The SOF interrupt reversal bug
  70254. + * will utterly bugger this up though.
  70255. + */
  70256. + if (hfnum.b.frnum != state->channel[n].expected_uframe) {
  70257. + fiq_print(FIQDBG_INT, state, "SOFCS %d ", n);
  70258. + state->channel[n].fsm = FIQ_PER_CSPLIT_POLL;
  70259. + fiq_fsm_restart_channel(state, n, 0);
  70260. + fiq_fsm_start_next_periodic(state, num_channels);
  70261. +
  70262. + }
  70263. + break;
  70264. +
  70265. + case FIQ_PER_SPLIT_TIMEOUT:
  70266. + case FIQ_DEQUEUE_ISSUED:
  70267. + /* Ugly: we have to force a HCD interrupt.
  70268. + * Poke the mask for the channel in question.
  70269. + * We will take a fake SOF because of this, but
  70270. + * that's OK.
  70271. + */
  70272. + state->haintmsk_saved.b2.chint &= ~(1 << n);
  70273. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK, 0);
  70274. + kick_irq |= 1;
  70275. + break;
  70276. +
  70277. + default:
  70278. + break;
  70279. + }
  70280. + }
  70281. +
  70282. + if (state->kick_np_queues ||
  70283. + dwc_frame_num_le(state->next_sched_frame, hfnum.b.frnum))
  70284. + kick_irq |= 1;
  70285. +
  70286. + return !kick_irq;
  70287. +}
  70288. +
  70289. +
  70290. +/**
  70291. + * fiq_fsm_do_hcintr() - FSM host channel interrupt handler
  70292. + * @state: Pointer to the FIQ state struct
  70293. + * @num_channels: Number of channels as per hardware config
  70294. + * @n: channel for which HAINT(i) was raised
  70295. + *
  70296. + * An important property is that only the CHHLT interrupt is unmasked. Unfortunately, AHBerr is as well.
  70297. + */
  70298. +static int notrace noinline fiq_fsm_do_hcintr(struct fiq_state *state, int num_channels, int n)
  70299. +{
  70300. + hcint_data_t hcint;
  70301. + hcintmsk_data_t hcintmsk;
  70302. + hcint_data_t hcint_probe;
  70303. + hcchar_data_t hcchar;
  70304. + int handled = 0;
  70305. + int restart = 0;
  70306. + int last_csplit = 0;
  70307. + int start_next_periodic = 0;
  70308. + struct fiq_channel_state *st = &state->channel[n];
  70309. + hfnum_data_t hfnum;
  70310. +
  70311. + hcint.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINT);
  70312. + hcintmsk.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK);
  70313. + hcint_probe.d32 = hcint.d32 & hcintmsk.d32;
  70314. +
  70315. + if (st->fsm != FIQ_PASSTHROUGH) {
  70316. + fiq_print(FIQDBG_INT, state, "HC%01d ST%02d", n, st->fsm);
  70317. + fiq_print(FIQDBG_INT, state, "%08x", hcint.d32);
  70318. + }
  70319. +
  70320. + switch (st->fsm) {
  70321. +
  70322. + case FIQ_PASSTHROUGH:
  70323. + case FIQ_DEQUEUE_ISSUED:
  70324. + /* doesn't belong to us, kick it upstairs */
  70325. + break;
  70326. +
  70327. + case FIQ_PASSTHROUGH_ERRORSTATE:
  70328. + /* We are here to emulate the error recovery mechanism of the dwc HCD.
  70329. + * Several interrupts are unmasked if a previous transaction failed - it's
  70330. + * death for the FIQ to attempt to handle them as the channel isn't halted.
  70331. + * Emulate what the HCD does in this situation: mask and continue.
  70332. + * The FSM has no other state setup so this has to be handled out-of-band.
  70333. + */
  70334. + fiq_print(FIQDBG_ERR, state, "ERRST %02d", n);
  70335. + if (hcint_probe.b.nak || hcint_probe.b.ack || hcint_probe.b.datatglerr) {
  70336. + fiq_print(FIQDBG_ERR, state, "RESET %02d", n);
  70337. + /* In some random cases we can get a NAK interrupt coincident with a Xacterr
  70338. + * interrupt, after the device has disappeared.
  70339. + */
  70340. + if (!hcint.b.xacterr)
  70341. + st->nr_errors = 0;
  70342. + hcintmsk.b.nak = 0;
  70343. + hcintmsk.b.ack = 0;
  70344. + hcintmsk.b.datatglerr = 0;
  70345. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK, hcintmsk.d32);
  70346. + return 1;
  70347. + }
  70348. + if (hcint_probe.b.chhltd) {
  70349. + fiq_print(FIQDBG_ERR, state, "CHHLT %02d", n);
  70350. + fiq_print(FIQDBG_ERR, state, "%08x", hcint.d32);
  70351. + return 0;
  70352. + }
  70353. + break;
  70354. +
  70355. + /* Non-periodic state groups */
  70356. + case FIQ_NP_SSPLIT_STARTED:
  70357. + case FIQ_NP_SSPLIT_RETRY:
  70358. + /* Got a HCINT for a NP SSPLIT. Expected ACK / NAK / fail */
  70359. + if (hcint.b.ack) {
  70360. + /* SSPLIT complete. For OUT, the data has been sent. For IN, the LS transaction
  70361. + * will start shortly. SOF needs to kick the transaction to prevent a NYET flood.
  70362. + */
  70363. + if(st->hcchar_copy.b.epdir == 1)
  70364. + st->fsm = FIQ_NP_IN_CSPLIT_RETRY;
  70365. + else
  70366. + st->fsm = FIQ_NP_OUT_CSPLIT_RETRY;
  70367. + st->nr_errors = 0;
  70368. + handled = 1;
  70369. + fiq_fsm_setup_csplit(state, n);
  70370. + } else if (hcint.b.nak) {
  70371. + // No buffer space in TT. Retry on a uframe boundary.
  70372. + st->fsm = FIQ_NP_SSPLIT_RETRY;
  70373. + handled = 1;
  70374. + } else if (hcint.b.xacterr) {
  70375. + // The only other one we care about is xacterr. This implies HS bus error - retry.
  70376. + st->nr_errors++;
  70377. + st->fsm = FIQ_NP_SSPLIT_RETRY;
  70378. + if (st->nr_errors >= 3) {
  70379. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  70380. + } else {
  70381. + handled = 1;
  70382. + restart = 1;
  70383. + }
  70384. + } else {
  70385. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  70386. + handled = 0;
  70387. + restart = 0;
  70388. + }
  70389. + break;
  70390. +
  70391. + case FIQ_NP_IN_CSPLIT_RETRY:
  70392. + /* Received a CSPLIT done interrupt.
  70393. + * Expected Data/NAK/STALL/NYET for IN.
  70394. + */
  70395. + if (hcint.b.xfercomp) {
  70396. + /* For IN, data is present. */
  70397. + st->fsm = FIQ_NP_SPLIT_DONE;
  70398. + } else if (hcint.b.nak) {
  70399. + /* no endpoint data. Punt it upstairs */
  70400. + st->fsm = FIQ_NP_SPLIT_DONE;
  70401. + } else if (hcint.b.nyet) {
  70402. + /* CSPLIT NYET - retry on a uframe boundary. */
  70403. + handled = 1;
  70404. + st->nr_errors = 0;
  70405. + } else if (hcint.b.datatglerr) {
  70406. + /* data toggle errors do not set the xfercomp bit. */
  70407. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  70408. + } else if (hcint.b.xacterr) {
  70409. + /* HS error. Retry immediate */
  70410. + st->fsm = FIQ_NP_IN_CSPLIT_RETRY;
  70411. + st->nr_errors++;
  70412. + if (st->nr_errors >= 3) {
  70413. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  70414. + } else {
  70415. + handled = 1;
  70416. + restart = 1;
  70417. + }
  70418. + } else if (hcint.b.stall || hcint.b.bblerr) {
  70419. + /* A STALL implies either a LS bus error or a genuine STALL. */
  70420. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  70421. + } else {
  70422. + /* Hardware bug. It's possible in some cases to
  70423. + * get a channel halt with nothing else set when
  70424. + * the response was a NYET. Treat as local 3-strikes retry.
  70425. + */
  70426. + hcint_data_t hcint_test = hcint;
  70427. + hcint_test.b.chhltd = 0;
  70428. + if (!hcint_test.d32) {
  70429. + st->nr_errors++;
  70430. + if (st->nr_errors >= 3) {
  70431. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  70432. + } else {
  70433. + handled = 1;
  70434. + }
  70435. + } else {
  70436. + /* Bail out if something unexpected happened */
  70437. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  70438. + }
  70439. + }
  70440. + break;
  70441. +
  70442. + case FIQ_NP_OUT_CSPLIT_RETRY:
  70443. + /* Received a CSPLIT done interrupt.
  70444. + * Expected ACK/NAK/STALL/NYET/XFERCOMP for OUT.*/
  70445. + if (hcint.b.xfercomp) {
  70446. + st->fsm = FIQ_NP_SPLIT_DONE;
  70447. + } else if (hcint.b.nak) {
  70448. + // The HCD will implement the holdoff on frame boundaries.
  70449. + st->fsm = FIQ_NP_SPLIT_DONE;
  70450. + } else if (hcint.b.nyet) {
  70451. + // Hub still processing.
  70452. + st->fsm = FIQ_NP_OUT_CSPLIT_RETRY;
  70453. + handled = 1;
  70454. + st->nr_errors = 0;
  70455. + //restart = 1;
  70456. + } else if (hcint.b.xacterr) {
  70457. + /* HS error. retry immediate */
  70458. + st->fsm = FIQ_NP_OUT_CSPLIT_RETRY;
  70459. + st->nr_errors++;
  70460. + if (st->nr_errors >= 3) {
  70461. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  70462. + } else {
  70463. + handled = 1;
  70464. + restart = 1;
  70465. + }
  70466. + } else if (hcint.b.stall) {
  70467. + /* LS bus error or genuine stall */
  70468. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  70469. + } else {
  70470. + /*
  70471. + * Hardware bug. It's possible in some cases to get a
  70472. + * channel halt with nothing else set when the response was a NYET.
  70473. + * Treat as local 3-strikes retry.
  70474. + */
  70475. + hcint_data_t hcint_test = hcint;
  70476. + hcint_test.b.chhltd = 0;
  70477. + if (!hcint_test.d32) {
  70478. + st->nr_errors++;
  70479. + if (st->nr_errors >= 3) {
  70480. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  70481. + } else {
  70482. + handled = 1;
  70483. + }
  70484. + } else {
  70485. + // Something unexpected happened. AHBerror or babble perhaps. Let the IRQ deal with it.
  70486. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  70487. + }
  70488. + }
  70489. + break;
  70490. +
  70491. + /* Periodic split states (except isoc out) */
  70492. + case FIQ_PER_SSPLIT_STARTED:
  70493. + /* Expect an ACK or failure for SSPLIT */
  70494. + if (hcint.b.ack) {
  70495. + /*
  70496. + * SSPLIT transfer complete interrupt - the generation of this interrupt is fraught with bugs.
  70497. + * For a packet queued in microframe n-3 to appear in n-2, if the channel is enabled near the EOF1
  70498. + * point for microframe n-3, the packet will not appear on the bus until microframe n.
  70499. + * Additionally, the generation of the actual interrupt is dodgy. For a packet appearing on the bus
  70500. + * in microframe n, sometimes the interrupt is generated immediately. Sometimes, it appears in n+1
  70501. + * coincident with SOF for n+1.
  70502. + * SOF is also buggy. It can sometimes be raised AFTER the first bus transaction has taken place.
  70503. + * These appear to be caused by timing/clock crossing bugs within the core itself.
  70504. + * State machine workaround.
  70505. + */
  70506. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  70507. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  70508. + fiq_fsm_setup_csplit(state, n);
  70509. + /* Poke the oddfrm bit. If we are equivalent, we received the interrupt at the correct
  70510. + * time. If not, then we're in the next SOF.
  70511. + */
  70512. + if ((hfnum.b.frnum & 0x1) == hcchar.b.oddfrm) {
  70513. + fiq_print(FIQDBG_INT, state, "CSWAIT %01d", n);
  70514. + st->expected_uframe = hfnum.b.frnum;
  70515. + st->fsm = FIQ_PER_CSPLIT_WAIT;
  70516. + } else {
  70517. + fiq_print(FIQDBG_INT, state, "CSPOL %01d", n);
  70518. + /* For isochronous IN endpoints,
  70519. + * we need to hold off if we are expecting a lot of data */
  70520. + if (st->hcchar_copy.b.mps < DATA0_PID_HEURISTIC) {
  70521. + start_next_periodic = 1;
  70522. + }
  70523. + /* Danger will robinson: we are in a broken state. If our first interrupt after
  70524. + * this is a NYET, it will be delayed by 1 uframe and result in an unrecoverable
  70525. + * lag. Unmask the NYET interrupt.
  70526. + */
  70527. + st->expected_uframe = (hfnum.b.frnum + 1) & 0x3FFF;
  70528. + st->fsm = FIQ_PER_CSPLIT_BROKEN_NYET1;
  70529. + restart = 1;
  70530. + }
  70531. + handled = 1;
  70532. + } else if (hcint.b.xacterr) {
  70533. + /* 3-strikes retry is enabled, we have hit our max nr_errors */
  70534. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  70535. + start_next_periodic = 1;
  70536. + } else {
  70537. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  70538. + start_next_periodic = 1;
  70539. + }
  70540. + /* We can now queue the next isochronous OUT transaction, if one is pending. */
  70541. + if(fiq_fsm_tt_next_isoc(state, num_channels, n)) {
  70542. + fiq_print(FIQDBG_INT, state, "NEXTISO ");
  70543. + }
  70544. + break;
  70545. +
  70546. + case FIQ_PER_CSPLIT_NYET1:
  70547. + /* First CSPLIT attempt was a NYET. If we get a subsequent NYET,
  70548. + * we are too late and the TT has dropped its CSPLIT fifo.
  70549. + */
  70550. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  70551. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  70552. + start_next_periodic = 1;
  70553. + if (hcint.b.nak) {
  70554. + st->fsm = FIQ_PER_SPLIT_DONE;
  70555. + } else if (hcint.b.xfercomp) {
  70556. + fiq_increment_dma_buf(state, num_channels, n);
  70557. + st->fsm = FIQ_PER_CSPLIT_POLL;
  70558. + st->nr_errors = 0;
  70559. + if (fiq_fsm_more_csplits(state, n, &last_csplit)) {
  70560. + handled = 1;
  70561. + restart = 1;
  70562. + if (!last_csplit)
  70563. + start_next_periodic = 0;
  70564. + } else {
  70565. + st->fsm = FIQ_PER_SPLIT_DONE;
  70566. + }
  70567. + } else if (hcint.b.nyet) {
  70568. + /* Doh. Data lost. */
  70569. + st->fsm = FIQ_PER_SPLIT_NYET_ABORTED;
  70570. + } else if (hcint.b.xacterr || hcint.b.stall || hcint.b.bblerr) {
  70571. + st->fsm = FIQ_PER_SPLIT_LS_ABORTED;
  70572. + } else {
  70573. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  70574. + }
  70575. + break;
  70576. +
  70577. + case FIQ_PER_CSPLIT_BROKEN_NYET1:
  70578. + /*
  70579. + * we got here because our host channel is in the delayed-interrupt
  70580. + * state and we cannot take a NYET interrupt any later than when it
  70581. + * occurred. Disable then re-enable the channel if this happens to force
  70582. + * CSPLITs to occur at the right time.
  70583. + */
  70584. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  70585. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  70586. + fiq_print(FIQDBG_INT, state, "BROK: %01d ", n);
  70587. + if (hcint.b.nak) {
  70588. + st->fsm = FIQ_PER_SPLIT_DONE;
  70589. + start_next_periodic = 1;
  70590. + } else if (hcint.b.xfercomp) {
  70591. + fiq_increment_dma_buf(state, num_channels, n);
  70592. + if (fiq_fsm_more_csplits(state, n, &last_csplit)) {
  70593. + st->fsm = FIQ_PER_CSPLIT_POLL;
  70594. + handled = 1;
  70595. + restart = 1;
  70596. + start_next_periodic = 1;
  70597. + /* Reload HCTSIZ for the next transfer */
  70598. + fiq_fsm_reload_hctsiz(state, n);
  70599. + if (!last_csplit)
  70600. + start_next_periodic = 0;
  70601. + } else {
  70602. + st->fsm = FIQ_PER_SPLIT_DONE;
  70603. + }
  70604. + } else if (hcint.b.nyet) {
  70605. + st->fsm = FIQ_PER_SPLIT_NYET_ABORTED;
  70606. + start_next_periodic = 1;
  70607. + } else if (hcint.b.xacterr || hcint.b.stall || hcint.b.bblerr) {
  70608. + /* Local 3-strikes retry is handled by the core. This is a ERR response.*/
  70609. + st->fsm = FIQ_PER_SPLIT_LS_ABORTED;
  70610. + } else {
  70611. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  70612. + }
  70613. + break;
  70614. +
  70615. + case FIQ_PER_CSPLIT_POLL:
  70616. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  70617. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  70618. + start_next_periodic = 1;
  70619. + if (hcint.b.nak) {
  70620. + st->fsm = FIQ_PER_SPLIT_DONE;
  70621. + } else if (hcint.b.xfercomp) {
  70622. + fiq_increment_dma_buf(state, num_channels, n);
  70623. + if (fiq_fsm_more_csplits(state, n, &last_csplit)) {
  70624. + handled = 1;
  70625. + restart = 1;
  70626. + /* Reload HCTSIZ for the next transfer */
  70627. + fiq_fsm_reload_hctsiz(state, n);
  70628. + if (!last_csplit)
  70629. + start_next_periodic = 0;
  70630. + } else {
  70631. + st->fsm = FIQ_PER_SPLIT_DONE;
  70632. + }
  70633. + } else if (hcint.b.nyet) {
  70634. + /* Are we a NYET after the first data packet? */
  70635. + if (st->nrpackets == 0) {
  70636. + st->fsm = FIQ_PER_CSPLIT_NYET1;
  70637. + handled = 1;
  70638. + restart = 1;
  70639. + } else {
  70640. + /* We got a NYET when polling CSPLITs. Can happen
  70641. + * if our heuristic fails, or if someone disables us
  70642. + * for any significant length of time.
  70643. + */
  70644. + if (st->nr_errors >= 3) {
  70645. + st->fsm = FIQ_PER_SPLIT_NYET_ABORTED;
  70646. + } else {
  70647. + st->fsm = FIQ_PER_SPLIT_DONE;
  70648. + }
  70649. + }
  70650. + } else if (hcint.b.xacterr || hcint.b.stall || hcint.b.bblerr) {
  70651. + /* For xacterr, Local 3-strikes retry is handled by the core. This is a ERR response.*/
  70652. + st->fsm = FIQ_PER_SPLIT_LS_ABORTED;
  70653. + } else {
  70654. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  70655. + }
  70656. + break;
  70657. +
  70658. + case FIQ_HS_ISOC_TURBO:
  70659. + if (fiq_fsm_update_hs_isoc(state, n, hcint)) {
  70660. + /* more transactions to come */
  70661. + handled = 1;
  70662. + restart = 1;
  70663. + fiq_print(FIQDBG_INT, state, "HSISO M ");
  70664. + } else {
  70665. + st->fsm = FIQ_HS_ISOC_DONE;
  70666. + fiq_print(FIQDBG_INT, state, "HSISO F ");
  70667. + }
  70668. + break;
  70669. +
  70670. + case FIQ_HS_ISOC_ABORTED:
  70671. + /* This abort is called by the driver rewriting the state mid-transaction
  70672. + * which allows the dequeue mechanism to work more effectively.
  70673. + */
  70674. + break;
  70675. +
  70676. + case FIQ_PER_ISO_OUT_ACTIVE:
  70677. + if (hcint.b.ack) {
  70678. + if(fiq_iso_out_advance(state, num_channels, n)) {
  70679. + /* last OUT transfer */
  70680. + st->fsm = FIQ_PER_ISO_OUT_LAST;
  70681. + /*
  70682. + * Assuming the periodic FIFO in the dwc core
  70683. + * actually does its job properly, we can queue
  70684. + * the next ssplit now and in theory, the wire
  70685. + * transactions will be in-order.
  70686. + */
  70687. + // No it doesn't. It appears to process requests in host channel order.
  70688. + //start_next_periodic = 1;
  70689. + }
  70690. + handled = 1;
  70691. + restart = 1;
  70692. + } else {
  70693. + /*
  70694. + * Isochronous transactions carry on regardless. Log the error
  70695. + * and continue.
  70696. + */
  70697. + //explode += 1;
  70698. + st->nr_errors++;
  70699. + if(fiq_iso_out_advance(state, num_channels, n)) {
  70700. + st->fsm = FIQ_PER_ISO_OUT_LAST;
  70701. + //start_next_periodic = 1;
  70702. + }
  70703. + handled = 1;
  70704. + restart = 1;
  70705. + }
  70706. + break;
  70707. +
  70708. + case FIQ_PER_ISO_OUT_LAST:
  70709. + if (hcint.b.ack) {
  70710. + /* All done here */
  70711. + st->fsm = FIQ_PER_ISO_OUT_DONE;
  70712. + } else {
  70713. + st->fsm = FIQ_PER_ISO_OUT_DONE;
  70714. + st->nr_errors++;
  70715. + }
  70716. + start_next_periodic = 1;
  70717. + break;
  70718. +
  70719. + case FIQ_PER_SPLIT_TIMEOUT:
  70720. + /* SOF kicked us because we overran. */
  70721. + start_next_periodic = 1;
  70722. + break;
  70723. +
  70724. + default:
  70725. + break;
  70726. + }
  70727. +
  70728. + if (handled) {
  70729. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINT, hcint.d32);
  70730. + } else {
  70731. + /* Copy the regs into the state so the IRQ knows what to do */
  70732. + st->hcint_copy.d32 = hcint.d32;
  70733. + }
  70734. +
  70735. + if (restart) {
  70736. + /* Restart always implies handled. */
  70737. + if (restart == 2) {
  70738. + /* For complete-split INs, the show must go on.
  70739. + * Force a channel restart */
  70740. + fiq_fsm_restart_channel(state, n, 1);
  70741. + } else {
  70742. + fiq_fsm_restart_channel(state, n, 0);
  70743. + }
  70744. + }
  70745. + if (start_next_periodic) {
  70746. + fiq_fsm_start_next_periodic(state, num_channels);
  70747. + }
  70748. + if (st->fsm != FIQ_PASSTHROUGH)
  70749. + fiq_print(FIQDBG_INT, state, "FSMOUT%02d", st->fsm);
  70750. +
  70751. + return handled;
  70752. +}
  70753. +
  70754. +
  70755. +/**
  70756. + * dwc_otg_fiq_fsm() - Flying State Machine (monster) FIQ
  70757. + * @state: pointer to state struct passed from the banked FIQ mode registers.
  70758. + * @num_channels: set according to the DWC hardware configuration
  70759. + * @dma: pointer to DMA bounce buffers for split transaction slots
  70760. + *
  70761. + * The FSM FIQ performs the low-level tasks that normally would be performed by the microcode
  70762. + * inside an EHCI or similar host controller regarding split transactions. The DWC core
  70763. + * interrupts each and every time a split transaction packet is received or sent successfully.
  70764. + * This results in either an interrupt storm when everything is working "properly", or
  70765. + * the interrupt latency of the system in general breaks time-sensitive periodic split
  70766. + * transactions. Pushing the low-level, but relatively easy state machine work into the FIQ
  70767. + * solves these problems.
  70768. + *
  70769. + * Return: void
  70770. + */
  70771. +void notrace dwc_otg_fiq_fsm(struct fiq_state *state, int num_channels)
  70772. +{
  70773. + gintsts_data_t gintsts, gintsts_handled;
  70774. + gintmsk_data_t gintmsk;
  70775. + //hfnum_data_t hfnum;
  70776. + haint_data_t haint, haint_handled;
  70777. + haintmsk_data_t haintmsk;
  70778. + int kick_irq = 0;
  70779. +
  70780. + gintsts_handled.d32 = 0;
  70781. + haint_handled.d32 = 0;
  70782. +
  70783. + gintsts.d32 = FIQ_READ(state->dwc_regs_base + GINTSTS);
  70784. + gintmsk.d32 = FIQ_READ(state->dwc_regs_base + GINTMSK);
  70785. + gintsts.d32 &= gintmsk.d32;
  70786. +
  70787. + if (gintsts.b.sofintr) {
  70788. + /* For FSM mode, SOF is required to keep the state machine advance for
  70789. + * certain stages of the periodic pipeline. It's death to mask this
  70790. + * interrupt in that case.
  70791. + */
  70792. +
  70793. + if (!fiq_fsm_do_sof(state, num_channels)) {
  70794. + /* Kick IRQ once. Queue advancement means that all pending transactions
  70795. + * will get serviced when the IRQ finally executes.
  70796. + */
  70797. + if (state->gintmsk_saved.b.sofintr == 1)
  70798. + kick_irq |= 1;
  70799. + state->gintmsk_saved.b.sofintr = 0;
  70800. + }
  70801. + gintsts_handled.b.sofintr = 1;
  70802. + }
  70803. +
  70804. + if (gintsts.b.hcintr) {
  70805. + int i;
  70806. + haint.d32 = FIQ_READ(state->dwc_regs_base + HAINT);
  70807. + haintmsk.d32 = FIQ_READ(state->dwc_regs_base + HAINTMSK);
  70808. + haint.d32 &= haintmsk.d32;
  70809. + haint_handled.d32 = 0;
  70810. + for (i=0; i<num_channels; i++) {
  70811. + if (haint.b2.chint & (1 << i)) {
  70812. + if(!fiq_fsm_do_hcintr(state, num_channels, i)) {
  70813. + /* HCINT was not handled in FIQ
  70814. + * HAINT is level-sensitive, leading to level-sensitive ginststs.b.hcint bit.
  70815. + * Mask HAINT(i) but keep top-level hcint unmasked.
  70816. + */
  70817. + state->haintmsk_saved.b2.chint &= ~(1 << i);
  70818. + } else {
  70819. + /* do_hcintr cleaned up after itself, but clear haint */
  70820. + haint_handled.b2.chint |= (1 << i);
  70821. + }
  70822. + }
  70823. + }
  70824. +
  70825. + if (haint_handled.b2.chint) {
  70826. + FIQ_WRITE(state->dwc_regs_base + HAINT, haint_handled.d32);
  70827. + }
  70828. +
  70829. + if (haintmsk.d32 != (haintmsk.d32 & state->haintmsk_saved.d32)) {
  70830. + /*
  70831. + * This is necessary to avoid multiple retriggers of the MPHI in the case
  70832. + * where interrupts are held off and HCINTs start to pile up.
  70833. + * Only wake up the IRQ if a new interrupt came in, was not handled and was
  70834. + * masked.
  70835. + */
  70836. + haintmsk.d32 &= state->haintmsk_saved.d32;
  70837. + FIQ_WRITE(state->dwc_regs_base + HAINTMSK, haintmsk.d32);
  70838. + kick_irq |= 1;
  70839. + }
  70840. + /* Top-Level interrupt - always handled because it's level-sensitive */
  70841. + gintsts_handled.b.hcintr = 1;
  70842. + }
  70843. +
  70844. +
  70845. + /* Clear the bits in the saved register that were not handled but were triggered. */
  70846. + state->gintmsk_saved.d32 &= ~(gintsts.d32 & ~gintsts_handled.d32);
  70847. +
  70848. + /* FIQ didn't handle something - mask has changed - write new mask */
  70849. + if (gintmsk.d32 != (gintmsk.d32 & state->gintmsk_saved.d32)) {
  70850. + gintmsk.d32 &= state->gintmsk_saved.d32;
  70851. + gintmsk.b.sofintr = 1;
  70852. + FIQ_WRITE(state->dwc_regs_base + GINTMSK, gintmsk.d32);
  70853. +// fiq_print(FIQDBG_INT, state, "KICKGINT");
  70854. +// fiq_print(FIQDBG_INT, state, "%08x", gintmsk.d32);
  70855. +// fiq_print(FIQDBG_INT, state, "%08x", state->gintmsk_saved.d32);
  70856. + kick_irq |= 1;
  70857. + }
  70858. +
  70859. + if (gintsts_handled.d32) {
  70860. + /* Only applies to edge-sensitive bits in GINTSTS */
  70861. + FIQ_WRITE(state->dwc_regs_base + GINTSTS, gintsts_handled.d32);
  70862. + }
  70863. +
  70864. + /* We got an interrupt, didn't handle it. */
  70865. + if (kick_irq) {
  70866. + state->mphi_int_count++;
  70867. + FIQ_WRITE(state->mphi_regs.outdda, (int) state->dummy_send);
  70868. + FIQ_WRITE(state->mphi_regs.outddb, (1<<29));
  70869. +
  70870. + }
  70871. + state->fiq_done++;
  70872. + mb();
  70873. +}
  70874. +
  70875. +
  70876. +/**
  70877. + * dwc_otg_fiq_nop() - FIQ "lite"
  70878. + * @state: pointer to state struct passed from the banked FIQ mode registers.
  70879. + *
  70880. + * The "nop" handler does not intervene on any interrupts other than SOF.
  70881. + * It is limited in scope to deciding at each SOF if the IRQ SOF handler (which deals
  70882. + * with non-periodic/periodic queues) needs to be kicked.
  70883. + *
  70884. + * This is done to hold off the SOF interrupt, which occurs at a rate of 8000 per second.
  70885. + *
  70886. + * Return: void
  70887. + */
  70888. +void notrace dwc_otg_fiq_nop(struct fiq_state *state)
  70889. +{
  70890. + gintsts_data_t gintsts, gintsts_handled;
  70891. + gintmsk_data_t gintmsk;
  70892. + hfnum_data_t hfnum;
  70893. +
  70894. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  70895. + gintsts.d32 = FIQ_READ(state->dwc_regs_base + GINTSTS);
  70896. + gintmsk.d32 = FIQ_READ(state->dwc_regs_base + GINTMSK);
  70897. + gintsts.d32 &= gintmsk.d32;
  70898. + gintsts_handled.d32 = 0;
  70899. +
  70900. + if (gintsts.b.sofintr) {
  70901. + if (!state->kick_np_queues &&
  70902. + dwc_frame_num_gt(state->next_sched_frame, hfnum.b.frnum)) {
  70903. + /* SOF handled, no work to do, just ACK interrupt */
  70904. + gintsts_handled.b.sofintr = 1;
  70905. + } else {
  70906. + /* Kick IRQ */
  70907. + state->gintmsk_saved.b.sofintr = 0;
  70908. + }
  70909. + }
  70910. +
  70911. + /* Reset handled interrupts */
  70912. + if(gintsts_handled.d32) {
  70913. + FIQ_WRITE(state->dwc_regs_base + GINTSTS, gintsts_handled.d32);
  70914. + }
  70915. +
  70916. + /* Clear the bits in the saved register that were not handled but were triggered. */
  70917. + state->gintmsk_saved.d32 &= ~(gintsts.d32 & ~gintsts_handled.d32);
  70918. +
  70919. + /* We got an interrupt, didn't handle it and want to mask it */
  70920. + if (~(state->gintmsk_saved.d32)) {
  70921. + state->mphi_int_count++;
  70922. + gintmsk.d32 &= state->gintmsk_saved.d32;
  70923. + FIQ_WRITE(state->dwc_regs_base + GINTMSK, gintmsk.d32);
  70924. + /* Force a clear before another dummy send */
  70925. + FIQ_WRITE(state->mphi_regs.intstat, (1<<29));
  70926. + FIQ_WRITE(state->mphi_regs.outdda, (int) state->dummy_send);
  70927. + FIQ_WRITE(state->mphi_regs.outddb, (1<<29));
  70928. +
  70929. + }
  70930. + state->fiq_done++;
  70931. + mb();
  70932. +}
  70933. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h
  70934. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h 1970-01-01 01:00:00.000000000 +0100
  70935. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h 2014-07-07 10:45:43.000000000 +0200
  70936. @@ -0,0 +1,353 @@
  70937. +/*
  70938. + * dwc_otg_fiq_fsm.h - Finite state machine FIQ header definitions
  70939. + *
  70940. + * Copyright (c) 2013 Raspberry Pi Foundation
  70941. + *
  70942. + * Author: Jonathan Bell <jonathan@raspberrypi.org>
  70943. + * All rights reserved.
  70944. + *
  70945. + * Redistribution and use in source and binary forms, with or without
  70946. + * modification, are permitted provided that the following conditions are met:
  70947. + * * Redistributions of source code must retain the above copyright
  70948. + * notice, this list of conditions and the following disclaimer.
  70949. + * * Redistributions in binary form must reproduce the above copyright
  70950. + * notice, this list of conditions and the following disclaimer in the
  70951. + * documentation and/or other materials provided with the distribution.
  70952. + * * Neither the name of Raspberry Pi nor the
  70953. + * names of its contributors may be used to endorse or promote products
  70954. + * derived from this software without specific prior written permission.
  70955. + *
  70956. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  70957. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  70958. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  70959. + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  70960. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  70961. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  70962. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  70963. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  70964. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  70965. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  70966. + *
  70967. + * This FIQ implements functionality that performs split transactions on
  70968. + * the dwc_otg hardware without any outside intervention. A split transaction
  70969. + * is "queued" by nominating a specific host channel to perform the entirety
  70970. + * of a split transaction. This FIQ will then perform the microframe-precise
  70971. + * scheduling required in each phase of the transaction until completion.
  70972. + *
  70973. + * The FIQ functionality has been surgically implanted into the Synopsys
  70974. + * vendor-provided driver.
  70975. + *
  70976. + */
  70977. +
  70978. +#ifndef DWC_OTG_FIQ_FSM_H_
  70979. +#define DWC_OTG_FIQ_FSM_H_
  70980. +
  70981. +#include "dwc_otg_regs.h"
  70982. +#include "dwc_otg_cil.h"
  70983. +#include "dwc_otg_hcd.h"
  70984. +#include <linux/kernel.h>
  70985. +#include <linux/irqflags.h>
  70986. +#include <linux/string.h>
  70987. +#include <asm/barrier.h>
  70988. +
  70989. +#if 0
  70990. +#define FLAME_ON(x) \
  70991. +do { \
  70992. + int gpioreg; \
  70993. + \
  70994. + gpioreg = readl(__io_address(0x20200000+0x8)); \
  70995. + gpioreg &= ~(7 << (x-20)*3); \
  70996. + gpioreg |= 0x1 << (x-20)*3; \
  70997. + writel(gpioreg, __io_address(0x20200000+0x8)); \
  70998. + \
  70999. + writel(1<<x, __io_address(0x20200000+(0x1C))); \
  71000. +} while (0)
  71001. +
  71002. +#define FLAME_OFF(x) \
  71003. +do { \
  71004. + writel(1<<x, __io_address(0x20200000+(0x28))); \
  71005. +} while (0)
  71006. +#else
  71007. +#define FLAME_ON(x) do { } while (0)
  71008. +#define FLAME_OFF(X) do { } while (0)
  71009. +#endif
  71010. +
  71011. +/* This is a quick-and-dirty arch-specific register read/write. We know that
  71012. + * writes to a peripheral on BCM2835 will always arrive in-order, also that
  71013. + * reads and writes are executed in-order therefore the need for memory barriers
  71014. + * is obviated if we're only talking to USB.
  71015. + */
  71016. +#define FIQ_WRITE(_addr_,_data_) (*(volatile unsigned int *) (_addr_) = (_data_))
  71017. +#define FIQ_READ(_addr_) (*(volatile unsigned int *) (_addr_))
  71018. +
  71019. +/* FIQ-ified register definitions. Offsets are from dwc_regs_base. */
  71020. +#define GINTSTS 0x014
  71021. +#define GINTMSK 0x018
  71022. +/* Debug register. Poll the top of the received packets FIFO. */
  71023. +#define GRXSTSR 0x01C
  71024. +#define HFNUM 0x408
  71025. +#define HAINT 0x414
  71026. +#define HAINTMSK 0x418
  71027. +#define HPRT0 0x440
  71028. +
  71029. +/* HC_regs start from an offset of 0x500 */
  71030. +#define HC_START 0x500
  71031. +#define HC_OFFSET 0x020
  71032. +
  71033. +#define HC_DMA 0x514
  71034. +
  71035. +#define HCCHAR 0x00
  71036. +#define HCSPLT 0x04
  71037. +#define HCINT 0x08
  71038. +#define HCINTMSK 0x0C
  71039. +#define HCTSIZ 0x10
  71040. +
  71041. +#define ISOC_XACTPOS_ALL 0b11
  71042. +#define ISOC_XACTPOS_BEGIN 0b10
  71043. +#define ISOC_XACTPOS_MID 0b00
  71044. +#define ISOC_XACTPOS_END 0b01
  71045. +
  71046. +#define DWC_PID_DATA2 0b01
  71047. +#define DWC_PID_MDATA 0b11
  71048. +#define DWC_PID_DATA1 0b10
  71049. +#define DWC_PID_DATA0 0b00
  71050. +
  71051. +typedef struct {
  71052. + volatile void* base;
  71053. + volatile void* ctrl;
  71054. + volatile void* outdda;
  71055. + volatile void* outddb;
  71056. + volatile void* intstat;
  71057. +} mphi_regs_t;
  71058. +
  71059. +
  71060. +enum fiq_debug_level {
  71061. + FIQDBG_SCHED = (1 << 0),
  71062. + FIQDBG_INT = (1 << 1),
  71063. + FIQDBG_ERR = (1 << 2),
  71064. + FIQDBG_PORTHUB = (1 << 3),
  71065. +};
  71066. +
  71067. +struct fiq_state;
  71068. +
  71069. +extern void _fiq_print (enum fiq_debug_level dbg_lvl, volatile struct fiq_state *state, char *fmt, ...);
  71070. +#if 0
  71071. +#define fiq_print _fiq_print
  71072. +#else
  71073. +#define fiq_print(x, y, ...)
  71074. +#endif
  71075. +
  71076. +extern bool fiq_enable, fiq_fsm_enable;
  71077. +extern ushort nak_holdoff;
  71078. +
  71079. +/**
  71080. + * enum fiq_fsm_state - The FIQ FSM states.
  71081. + *
  71082. + * This is the "core" of the FIQ FSM. Broadly, the FSM states follow the
  71083. + * USB2.0 specification for host responses to various transaction states.
  71084. + * There are modifications to this host state machine because of a variety of
  71085. + * quirks and limitations in the dwc_otg hardware.
  71086. + *
  71087. + * The fsm state is also used to communicate back to the driver on completion of
  71088. + * a split transaction. The end states are used in conjunction with the interrupts
  71089. + * raised by the final transaction.
  71090. + */
  71091. +enum fiq_fsm_state {
  71092. + /* FIQ isn't enabled for this host channel */
  71093. + FIQ_PASSTHROUGH = 0,
  71094. + /* For the first interrupt received for this channel,
  71095. + * the FIQ has to ack any interrupts indicating success. */
  71096. + FIQ_PASSTHROUGH_ERRORSTATE = 31,
  71097. + /* Nonperiodic state groups */
  71098. + FIQ_NP_SSPLIT_STARTED = 1,
  71099. + FIQ_NP_SSPLIT_RETRY = 2,
  71100. + FIQ_NP_OUT_CSPLIT_RETRY = 3,
  71101. + FIQ_NP_IN_CSPLIT_RETRY = 4,
  71102. + FIQ_NP_SPLIT_DONE = 5,
  71103. + FIQ_NP_SPLIT_LS_ABORTED = 6,
  71104. + /* This differentiates a HS transaction error from a LS one
  71105. + * (handling the hub state is different) */
  71106. + FIQ_NP_SPLIT_HS_ABORTED = 7,
  71107. +
  71108. + /* Periodic state groups */
  71109. + /* Periodic transactions are either started directly by the IRQ handler
  71110. + * or deferred if the TT is already in use.
  71111. + */
  71112. + FIQ_PER_SSPLIT_QUEUED = 8,
  71113. + FIQ_PER_SSPLIT_STARTED = 9,
  71114. + FIQ_PER_SSPLIT_LAST = 10,
  71115. +
  71116. +
  71117. + FIQ_PER_ISO_OUT_PENDING = 11,
  71118. + FIQ_PER_ISO_OUT_ACTIVE = 12,
  71119. + FIQ_PER_ISO_OUT_LAST = 13,
  71120. + FIQ_PER_ISO_OUT_DONE = 27,
  71121. +
  71122. + FIQ_PER_CSPLIT_WAIT = 14,
  71123. + FIQ_PER_CSPLIT_NYET1 = 15,
  71124. + FIQ_PER_CSPLIT_BROKEN_NYET1 = 28,
  71125. + FIQ_PER_CSPLIT_NYET_FAFF = 29,
  71126. + /* For multiple CSPLITs (large isoc IN, or delayed interrupt) */
  71127. + FIQ_PER_CSPLIT_POLL = 16,
  71128. + /* The last CSPLIT for a transaction has been issued, differentiates
  71129. + * for the state machine to queue the next packet.
  71130. + */
  71131. + FIQ_PER_CSPLIT_LAST = 17,
  71132. +
  71133. + FIQ_PER_SPLIT_DONE = 18,
  71134. + FIQ_PER_SPLIT_LS_ABORTED = 19,
  71135. + FIQ_PER_SPLIT_HS_ABORTED = 20,
  71136. + FIQ_PER_SPLIT_NYET_ABORTED = 21,
  71137. + /* Frame rollover has occurred without the transaction finishing. */
  71138. + FIQ_PER_SPLIT_TIMEOUT = 22,
  71139. +
  71140. + /* FIQ-accelerated HS Isochronous state groups */
  71141. + FIQ_HS_ISOC_TURBO = 23,
  71142. + /* For interval > 1, SOF wakes up the isochronous FSM */
  71143. + FIQ_HS_ISOC_SLEEPING = 24,
  71144. + FIQ_HS_ISOC_DONE = 25,
  71145. + FIQ_HS_ISOC_ABORTED = 26,
  71146. + FIQ_DEQUEUE_ISSUED = 30,
  71147. + FIQ_TEST = 32,
  71148. +};
  71149. +
  71150. +struct fiq_stack {
  71151. + int magic1;
  71152. + uint8_t stack[2048];
  71153. + int magic2;
  71154. +};
  71155. +
  71156. +
  71157. +/**
  71158. + * struct fiq_dma_info - DMA bounce buffer utilisation information (per-channel)
  71159. + * @index: Number of slots reported used for IN transactions / number of slots
  71160. + * transmitted for an OUT transaction
  71161. + * @slot_len[6]: Number of actual transfer bytes in each slot (255 if unused)
  71162. + *
  71163. + * Split transaction transfers can have variable length depending on other bus
  71164. + * traffic. The OTG core DMA engine requires 4-byte aligned addresses therefore
  71165. + * each transaction needs a guaranteed aligned address. A maximum of 6 split transfers
  71166. + * can happen per-frame.
  71167. + */
  71168. +struct fiq_dma_info {
  71169. + u8 index;
  71170. + u8 slot_len[6];
  71171. +};
  71172. +
  71173. +struct __attribute__((packed)) fiq_split_dma_slot {
  71174. + u8 buf[188];
  71175. +};
  71176. +
  71177. +struct fiq_dma_channel {
  71178. + struct __attribute__((packed)) fiq_split_dma_slot index[6];
  71179. +};
  71180. +
  71181. +struct fiq_dma_blob {
  71182. + struct __attribute__((packed)) fiq_dma_channel channel[0];
  71183. +};
  71184. +
  71185. +/**
  71186. + * struct fiq_hs_isoc_info - USB2.0 isochronous data
  71187. + * @iso_frame: Pointer to the array of OTG URB iso_frame_descs.
  71188. + * @nrframes: Total length of iso_frame_desc array
  71189. + * @index: Current index (FIQ-maintained)
  71190. + *
  71191. + */
  71192. +struct fiq_hs_isoc_info {
  71193. + struct dwc_otg_hcd_iso_packet_desc *iso_desc;
  71194. + unsigned int nrframes;
  71195. + unsigned int index;
  71196. +};
  71197. +
  71198. +/**
  71199. + * struct fiq_channel_state - FIQ state machine storage
  71200. + * @fsm: Current state of the channel as understood by the FIQ
  71201. + * @nr_errors: Number of transaction errors on this split-transaction
  71202. + * @hub_addr: SSPLIT/CSPLIT destination hub
  71203. + * @port_addr: SSPLIT/CSPLIT destination port - always 1 if single TT hub
  71204. + * @nrpackets: For isoc OUT, the number of split-OUT packets to transmit. For
  71205. + * split-IN, number of CSPLIT data packets that were received.
  71206. + * @hcchar_copy:
  71207. + * @hcsplt_copy:
  71208. + * @hcintmsk_copy:
  71209. + * @hctsiz_copy: Copies of the host channel registers.
  71210. + * For use as scratch, or for returning state.
  71211. + *
  71212. + * The fiq_channel_state is state storage between interrupts for a host channel. The
  71213. + * FSM state is stored here. Members of this structure must only be set up by the
  71214. + * driver prior to enabling the FIQ for this host channel, and not touched until the FIQ
  71215. + * has updated the state to either a COMPLETE state group or ABORT state group.
  71216. + */
  71217. +
  71218. +struct fiq_channel_state {
  71219. + enum fiq_fsm_state fsm;
  71220. + unsigned int nr_errors;
  71221. + unsigned int hub_addr;
  71222. + unsigned int port_addr;
  71223. + /* Hardware bug workaround: sometimes channel halt interrupts are
  71224. + * delayed until the next SOF. Keep track of when we expected to get interrupted. */
  71225. + unsigned int expected_uframe;
  71226. + /* in/out for communicating number of dma buffers used, or number of ISOC to do */
  71227. + unsigned int nrpackets;
  71228. + struct fiq_dma_info dma_info;
  71229. + struct fiq_hs_isoc_info hs_isoc_info;
  71230. + /* Copies of HC registers - in/out communication from/to IRQ handler
  71231. + * and for ease of channel setup. A bit of mungeing is performed - for
  71232. + * example the hctsiz.b.maxp is _always_ the max packet size of the endpoint.
  71233. + */
  71234. + hcchar_data_t hcchar_copy;
  71235. + hcsplt_data_t hcsplt_copy;
  71236. + hcint_data_t hcint_copy;
  71237. + hcintmsk_data_t hcintmsk_copy;
  71238. + hctsiz_data_t hctsiz_copy;
  71239. + hcdma_data_t hcdma_copy;
  71240. +};
  71241. +
  71242. +/**
  71243. + * struct fiq_state - top-level FIQ state machine storage
  71244. + * @mphi_regs: virtual address of the MPHI peripheral register file
  71245. + * @dwc_regs_base: virtual address of the base of the DWC core register file
  71246. + * @dma_base: physical address for the base of the DMA bounce buffers
  71247. + * @dummy_send: Scratch area for sending a fake message to the MPHI peripheral
  71248. + * @gintmsk_saved: Top-level mask of interrupts that the FIQ has not handled.
  71249. + * Used for determining which interrupts fired to set off the IRQ handler.
  71250. + * @haintmsk_saved: Mask of interrupts from host channels that the FIQ did not handle internally.
  71251. + * @np_count: Non-periodic transactions in the active queue
  71252. + * @np_sent: Count of non-periodic transactions that have completed
  71253. + * @next_sched_frame: For periodic transactions handled by the driver's SOF-driven queuing mechanism,
  71254. + * this is the next frame on which a SOF interrupt is required. Used to hold off
  71255. + * passing SOF through to the driver until necessary.
  71256. + * @channel[n]: Per-channel FIQ state. Allocated during init depending on the number of host
  71257. + * channels configured into the core logic.
  71258. + *
  71259. + * This is passed as the first argument to the dwc_otg_fiq_fsm top-level FIQ handler from the asm stub.
  71260. + * It contains top-level state information.
  71261. + */
  71262. +struct fiq_state {
  71263. + mphi_regs_t mphi_regs;
  71264. + void *dwc_regs_base;
  71265. + dma_addr_t dma_base;
  71266. + struct fiq_dma_blob *fiq_dmab;
  71267. + void *dummy_send;
  71268. + gintmsk_data_t gintmsk_saved;
  71269. + haintmsk_data_t haintmsk_saved;
  71270. + int mphi_int_count;
  71271. + unsigned int fiq_done;
  71272. + unsigned int kick_np_queues;
  71273. + unsigned int next_sched_frame;
  71274. +#ifdef FIQ_DEBUG
  71275. + char * buffer;
  71276. + unsigned int bufsiz;
  71277. +#endif
  71278. + struct fiq_channel_state channel[0];
  71279. +};
  71280. +
  71281. +extern int fiq_fsm_too_late(struct fiq_state *st, int n);
  71282. +
  71283. +extern int fiq_fsm_tt_in_use(struct fiq_state *st, int num_channels, int n);
  71284. +
  71285. +extern void dwc_otg_fiq_fsm(struct fiq_state *state, int num_channels);
  71286. +
  71287. +extern void dwc_otg_fiq_nop(struct fiq_state *state);
  71288. +
  71289. +#endif /* DWC_OTG_FIQ_FSM_H_ */
  71290. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S
  71291. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S 1970-01-01 01:00:00.000000000 +0100
  71292. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S 2014-07-07 10:45:43.000000000 +0200
  71293. @@ -0,0 +1,81 @@
  71294. +/*
  71295. + * dwc_otg_fiq_fsm.S - assembly stub for the FSM FIQ
  71296. + *
  71297. + * Copyright (c) 2013 Raspberry Pi Foundation
  71298. + *
  71299. + * Author: Jonathan Bell <jonathan@raspberrypi.org>
  71300. + * All rights reserved.
  71301. + *
  71302. + * Redistribution and use in source and binary forms, with or without
  71303. + * modification, are permitted provided that the following conditions are met:
  71304. + * * Redistributions of source code must retain the above copyright
  71305. + * notice, this list of conditions and the following disclaimer.
  71306. + * * Redistributions in binary form must reproduce the above copyright
  71307. + * notice, this list of conditions and the following disclaimer in the
  71308. + * documentation and/or other materials provided with the distribution.
  71309. + * * Neither the name of Raspberry Pi nor the
  71310. + * names of its contributors may be used to endorse or promote products
  71311. + * derived from this software without specific prior written permission.
  71312. + *
  71313. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  71314. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  71315. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  71316. + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  71317. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  71318. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  71319. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  71320. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  71321. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  71322. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  71323. + */
  71324. +
  71325. +
  71326. +#include <asm/assembler.h>
  71327. +#include <linux/linkage.h>
  71328. +
  71329. +
  71330. +.text
  71331. +
  71332. +.global _dwc_otg_fiq_stub_end;
  71333. +
  71334. +/**
  71335. + * _dwc_otg_fiq_stub() - entry copied to the FIQ vector page to allow
  71336. + * a C-style function call with arguments from the FIQ banked registers.
  71337. + * r0 = &hcd->fiq_state
  71338. + * r1 = &hcd->num_channels
  71339. + * r2 = &hcd->dma_buffers
  71340. + * Tramples: r0, r1, r2, r4, fp, ip
  71341. + */
  71342. +
  71343. +ENTRY(_dwc_otg_fiq_stub)
  71344. + /* Stash unbanked regs - SP will have been set up for us */
  71345. + mov ip, sp;
  71346. + stmdb sp!, {r0-r12, lr};
  71347. +#ifdef FIQ_DEBUG
  71348. + // Cycle profiling - read cycle counter at start
  71349. + mrc p15, 0, r5, c15, c12, 1;
  71350. +#endif
  71351. + /* r11 = fp, don't trample it */
  71352. + mov r4, fp;
  71353. + /* set EABI frame size */
  71354. + sub fp, ip, #512;
  71355. +
  71356. + /* for fiq NOP mode - just need state */
  71357. + mov r0, r8;
  71358. + /* r9 = num_channels */
  71359. + mov r1, r9;
  71360. + /* r10 = struct *dma_bufs */
  71361. +// mov r2, r10;
  71362. +
  71363. + /* r4 = &fiq_c_function */
  71364. + blx r4;
  71365. +#ifdef FIQ_DEBUG
  71366. + mrc p15, 0, r4, c15, c12, 1;
  71367. + subs r5, r5, r4;
  71368. + // r5 is now the cycle count time for executing the FIQ. Store it somewhere?
  71369. +#endif
  71370. + ldmia sp!, {r0-r12, lr};
  71371. + subs pc, lr, #4;
  71372. +_dwc_otg_fiq_stub_end:
  71373. +END(_dwc_otg_fiq_stub)
  71374. +
  71375. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_hcd.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd.c
  71376. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_hcd.c 1970-01-01 01:00:00.000000000 +0100
  71377. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd.c 2014-07-07 10:45:43.000000000 +0200
  71378. @@ -0,0 +1,4212 @@
  71379. +
  71380. +/* ==========================================================================
  71381. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd.c $
  71382. + * $Revision: #104 $
  71383. + * $Date: 2011/10/24 $
  71384. + * $Change: 1871159 $
  71385. + *
  71386. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  71387. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  71388. + * otherwise expressly agreed to in writing between Synopsys and you.
  71389. + *
  71390. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  71391. + * any End User Software License Agreement or Agreement for Licensed Product
  71392. + * with Synopsys or any supplement thereto. You are permitted to use and
  71393. + * redistribute this Software in source and binary forms, with or without
  71394. + * modification, provided that redistributions of source code must retain this
  71395. + * notice. You may not view, use, disclose, copy or distribute this file or
  71396. + * any information contained herein except pursuant to this license grant from
  71397. + * Synopsys. If you do not agree with this notice, including the disclaimer
  71398. + * below, then you are not authorized to use the Software.
  71399. + *
  71400. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  71401. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  71402. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  71403. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  71404. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  71405. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  71406. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  71407. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  71408. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  71409. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  71410. + * DAMAGE.
  71411. + * ========================================================================== */
  71412. +#ifndef DWC_DEVICE_ONLY
  71413. +
  71414. +/** @file
  71415. + * This file implements HCD Core. All code in this file is portable and doesn't
  71416. + * use any OS specific functions.
  71417. + * Interface provided by HCD Core is defined in <code><hcd_if.h></code>
  71418. + * header file.
  71419. + */
  71420. +
  71421. +#include <linux/usb.h>
  71422. +#include <linux/usb/hcd.h>
  71423. +
  71424. +#include "dwc_otg_hcd.h"
  71425. +#include "dwc_otg_regs.h"
  71426. +#include "dwc_otg_fiq_fsm.h"
  71427. +
  71428. +extern bool microframe_schedule;
  71429. +extern uint16_t fiq_fsm_mask, nak_holdoff;
  71430. +
  71431. +//#define DEBUG_HOST_CHANNELS
  71432. +#ifdef DEBUG_HOST_CHANNELS
  71433. +static int last_sel_trans_num_per_scheduled = 0;
  71434. +static int last_sel_trans_num_nonper_scheduled = 0;
  71435. +static int last_sel_trans_num_avail_hc_at_start = 0;
  71436. +static int last_sel_trans_num_avail_hc_at_end = 0;
  71437. +#endif /* DEBUG_HOST_CHANNELS */
  71438. +
  71439. +
  71440. +dwc_otg_hcd_t *dwc_otg_hcd_alloc_hcd(void)
  71441. +{
  71442. + return DWC_ALLOC(sizeof(dwc_otg_hcd_t));
  71443. +}
  71444. +
  71445. +/**
  71446. + * Connection timeout function. An OTG host is required to display a
  71447. + * message if the device does not connect within 10 seconds.
  71448. + */
  71449. +void dwc_otg_hcd_connect_timeout(void *ptr)
  71450. +{
  71451. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, ptr);
  71452. + DWC_PRINTF("Connect Timeout\n");
  71453. + __DWC_ERROR("Device Not Connected/Responding\n");
  71454. +}
  71455. +
  71456. +#if defined(DEBUG)
  71457. +static void dump_channel_info(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  71458. +{
  71459. + if (qh->channel != NULL) {
  71460. + dwc_hc_t *hc = qh->channel;
  71461. + dwc_list_link_t *item;
  71462. + dwc_otg_qh_t *qh_item;
  71463. + int num_channels = hcd->core_if->core_params->host_channels;
  71464. + int i;
  71465. +
  71466. + dwc_otg_hc_regs_t *hc_regs;
  71467. + hcchar_data_t hcchar;
  71468. + hcsplt_data_t hcsplt;
  71469. + hctsiz_data_t hctsiz;
  71470. + uint32_t hcdma;
  71471. +
  71472. + hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
  71473. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  71474. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  71475. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  71476. + hcdma = DWC_READ_REG32(&hc_regs->hcdma);
  71477. +
  71478. + DWC_PRINTF(" Assigned to channel %p:\n", hc);
  71479. + DWC_PRINTF(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32,
  71480. + hcsplt.d32);
  71481. + DWC_PRINTF(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32,
  71482. + hcdma);
  71483. + DWC_PRINTF(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
  71484. + hc->dev_addr, hc->ep_num, hc->ep_is_in);
  71485. + DWC_PRINTF(" ep_type: %d\n", hc->ep_type);
  71486. + DWC_PRINTF(" max_packet: %d\n", hc->max_packet);
  71487. + DWC_PRINTF(" data_pid_start: %d\n", hc->data_pid_start);
  71488. + DWC_PRINTF(" xfer_started: %d\n", hc->xfer_started);
  71489. + DWC_PRINTF(" halt_status: %d\n", hc->halt_status);
  71490. + DWC_PRINTF(" xfer_buff: %p\n", hc->xfer_buff);
  71491. + DWC_PRINTF(" xfer_len: %d\n", hc->xfer_len);
  71492. + DWC_PRINTF(" qh: %p\n", hc->qh);
  71493. + DWC_PRINTF(" NP inactive sched:\n");
  71494. + DWC_LIST_FOREACH(item, &hcd->non_periodic_sched_inactive) {
  71495. + qh_item =
  71496. + DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  71497. + DWC_PRINTF(" %p\n", qh_item);
  71498. + }
  71499. + DWC_PRINTF(" NP active sched:\n");
  71500. + DWC_LIST_FOREACH(item, &hcd->non_periodic_sched_active) {
  71501. + qh_item =
  71502. + DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  71503. + DWC_PRINTF(" %p\n", qh_item);
  71504. + }
  71505. + DWC_PRINTF(" Channels: \n");
  71506. + for (i = 0; i < num_channels; i++) {
  71507. + dwc_hc_t *hc = hcd->hc_ptr_array[i];
  71508. + DWC_PRINTF(" %2d: %p\n", i, hc);
  71509. + }
  71510. + }
  71511. +}
  71512. +#else
  71513. +#define dump_channel_info(hcd, qh)
  71514. +#endif /* DEBUG */
  71515. +
  71516. +/**
  71517. + * Work queue function for starting the HCD when A-Cable is connected.
  71518. + * The hcd_start() must be called in a process context.
  71519. + */
  71520. +static void hcd_start_func(void *_vp)
  71521. +{
  71522. + dwc_otg_hcd_t *hcd = (dwc_otg_hcd_t *) _vp;
  71523. +
  71524. + DWC_DEBUGPL(DBG_HCDV, "%s() %p\n", __func__, hcd);
  71525. + if (hcd) {
  71526. + hcd->fops->start(hcd);
  71527. + }
  71528. +}
  71529. +
  71530. +static void del_xfer_timers(dwc_otg_hcd_t * hcd)
  71531. +{
  71532. +#ifdef DEBUG
  71533. + int i;
  71534. + int num_channels = hcd->core_if->core_params->host_channels;
  71535. + for (i = 0; i < num_channels; i++) {
  71536. + DWC_TIMER_CANCEL(hcd->core_if->hc_xfer_timer[i]);
  71537. + }
  71538. +#endif
  71539. +}
  71540. +
  71541. +static void del_timers(dwc_otg_hcd_t * hcd)
  71542. +{
  71543. + del_xfer_timers(hcd);
  71544. + DWC_TIMER_CANCEL(hcd->conn_timer);
  71545. +}
  71546. +
  71547. +/**
  71548. + * Processes all the URBs in a single list of QHs. Completes them with
  71549. + * -ESHUTDOWN and frees the QTD.
  71550. + */
  71551. +static void kill_urbs_in_qh_list(dwc_otg_hcd_t * hcd, dwc_list_link_t * qh_list)
  71552. +{
  71553. + dwc_list_link_t *qh_item, *qh_tmp;
  71554. + dwc_otg_qh_t *qh;
  71555. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  71556. +
  71557. + DWC_LIST_FOREACH_SAFE(qh_item, qh_tmp, qh_list) {
  71558. + qh = DWC_LIST_ENTRY(qh_item, dwc_otg_qh_t, qh_list_entry);
  71559. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp,
  71560. + &qh->qtd_list, qtd_list_entry) {
  71561. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  71562. + if (qtd->urb != NULL) {
  71563. + hcd->fops->complete(hcd, qtd->urb->priv,
  71564. + qtd->urb, -DWC_E_SHUTDOWN);
  71565. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  71566. + }
  71567. +
  71568. + }
  71569. + if(qh->channel) {
  71570. + /* Using hcchar.chen == 1 is not a reliable test.
  71571. + * It is possible that the channel has already halted
  71572. + * but not yet been through the IRQ handler.
  71573. + */
  71574. + dwc_otg_hc_halt(hcd->core_if, qh->channel,
  71575. + DWC_OTG_HC_XFER_URB_DEQUEUE);
  71576. + if(microframe_schedule)
  71577. + hcd->available_host_channels++;
  71578. + qh->channel = NULL;
  71579. + }
  71580. + dwc_otg_hcd_qh_remove(hcd, qh);
  71581. + }
  71582. +}
  71583. +
  71584. +/**
  71585. + * Responds with an error status of ESHUTDOWN to all URBs in the non-periodic
  71586. + * and periodic schedules. The QTD associated with each URB is removed from
  71587. + * the schedule and freed. This function may be called when a disconnect is
  71588. + * detected or when the HCD is being stopped.
  71589. + */
  71590. +static void kill_all_urbs(dwc_otg_hcd_t * hcd)
  71591. +{
  71592. + kill_urbs_in_qh_list(hcd, &hcd->non_periodic_sched_inactive);
  71593. + kill_urbs_in_qh_list(hcd, &hcd->non_periodic_sched_active);
  71594. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_inactive);
  71595. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_ready);
  71596. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_assigned);
  71597. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_queued);
  71598. +}
  71599. +
  71600. +/**
  71601. + * Start the connection timer. An OTG host is required to display a
  71602. + * message if the device does not connect within 10 seconds. The
  71603. + * timer is deleted if a port connect interrupt occurs before the
  71604. + * timer expires.
  71605. + */
  71606. +static void dwc_otg_hcd_start_connect_timer(dwc_otg_hcd_t * hcd)
  71607. +{
  71608. + DWC_TIMER_SCHEDULE(hcd->conn_timer, 10000 /* 10 secs */ );
  71609. +}
  71610. +
  71611. +/**
  71612. + * HCD Callback function for disconnect of the HCD.
  71613. + *
  71614. + * @param p void pointer to the <code>struct usb_hcd</code>
  71615. + */
  71616. +static int32_t dwc_otg_hcd_session_start_cb(void *p)
  71617. +{
  71618. + dwc_otg_hcd_t *dwc_otg_hcd;
  71619. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, p);
  71620. + dwc_otg_hcd = p;
  71621. + dwc_otg_hcd_start_connect_timer(dwc_otg_hcd);
  71622. + return 1;
  71623. +}
  71624. +
  71625. +/**
  71626. + * HCD Callback function for starting the HCD when A-Cable is
  71627. + * connected.
  71628. + *
  71629. + * @param p void pointer to the <code>struct usb_hcd</code>
  71630. + */
  71631. +static int32_t dwc_otg_hcd_start_cb(void *p)
  71632. +{
  71633. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  71634. + dwc_otg_core_if_t *core_if;
  71635. + hprt0_data_t hprt0;
  71636. +
  71637. + core_if = dwc_otg_hcd->core_if;
  71638. +
  71639. + if (core_if->op_state == B_HOST) {
  71640. + /*
  71641. + * Reset the port. During a HNP mode switch the reset
  71642. + * needs to occur within 1ms and have a duration of at
  71643. + * least 50ms.
  71644. + */
  71645. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  71646. + hprt0.b.prtrst = 1;
  71647. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71648. + }
  71649. + DWC_WORKQ_SCHEDULE_DELAYED(core_if->wq_otg,
  71650. + hcd_start_func, dwc_otg_hcd, 50,
  71651. + "start hcd");
  71652. +
  71653. + return 1;
  71654. +}
  71655. +
  71656. +/**
  71657. + * HCD Callback function for disconnect of the HCD.
  71658. + *
  71659. + * @param p void pointer to the <code>struct usb_hcd</code>
  71660. + */
  71661. +static int32_t dwc_otg_hcd_disconnect_cb(void *p)
  71662. +{
  71663. + gintsts_data_t intr;
  71664. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  71665. +
  71666. + /*
  71667. + * Set status flags for the hub driver.
  71668. + */
  71669. + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
  71670. + dwc_otg_hcd->flags.b.port_connect_status = 0;
  71671. + if(fiq_enable)
  71672. + local_fiq_disable();
  71673. + /*
  71674. + * Shutdown any transfers in process by clearing the Tx FIFO Empty
  71675. + * interrupt mask and status bits and disabling subsequent host
  71676. + * channel interrupts.
  71677. + */
  71678. + intr.d32 = 0;
  71679. + intr.b.nptxfempty = 1;
  71680. + intr.b.ptxfempty = 1;
  71681. + intr.b.hcintr = 1;
  71682. + DWC_MODIFY_REG32(&dwc_otg_hcd->core_if->core_global_regs->gintmsk,
  71683. + intr.d32, 0);
  71684. + DWC_MODIFY_REG32(&dwc_otg_hcd->core_if->core_global_regs->gintsts,
  71685. + intr.d32, 0);
  71686. +
  71687. + del_timers(dwc_otg_hcd);
  71688. +
  71689. + /*
  71690. + * Turn off the vbus power only if the core has transitioned to device
  71691. + * mode. If still in host mode, need to keep power on to detect a
  71692. + * reconnection.
  71693. + */
  71694. + if (dwc_otg_is_device_mode(dwc_otg_hcd->core_if)) {
  71695. + if (dwc_otg_hcd->core_if->op_state != A_SUSPEND) {
  71696. + hprt0_data_t hprt0 = {.d32 = 0 };
  71697. + DWC_PRINTF("Disconnect: PortPower off\n");
  71698. + hprt0.b.prtpwr = 0;
  71699. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0,
  71700. + hprt0.d32);
  71701. + }
  71702. +
  71703. + dwc_otg_disable_host_interrupts(dwc_otg_hcd->core_if);
  71704. + }
  71705. +
  71706. + /* Respond with an error status to all URBs in the schedule. */
  71707. + kill_all_urbs(dwc_otg_hcd);
  71708. +
  71709. + if (dwc_otg_is_host_mode(dwc_otg_hcd->core_if)) {
  71710. + /* Clean up any host channels that were in use. */
  71711. + int num_channels;
  71712. + int i;
  71713. + dwc_hc_t *channel;
  71714. + dwc_otg_hc_regs_t *hc_regs;
  71715. + hcchar_data_t hcchar;
  71716. +
  71717. + num_channels = dwc_otg_hcd->core_if->core_params->host_channels;
  71718. +
  71719. + if (!dwc_otg_hcd->core_if->dma_enable) {
  71720. + /* Flush out any channel requests in slave mode. */
  71721. + for (i = 0; i < num_channels; i++) {
  71722. + channel = dwc_otg_hcd->hc_ptr_array[i];
  71723. + if (DWC_CIRCLEQ_EMPTY_ENTRY
  71724. + (channel, hc_list_entry)) {
  71725. + hc_regs =
  71726. + dwc_otg_hcd->core_if->
  71727. + host_if->hc_regs[i];
  71728. + hcchar.d32 =
  71729. + DWC_READ_REG32(&hc_regs->hcchar);
  71730. + if (hcchar.b.chen) {
  71731. + hcchar.b.chen = 0;
  71732. + hcchar.b.chdis = 1;
  71733. + hcchar.b.epdir = 0;
  71734. + DWC_WRITE_REG32
  71735. + (&hc_regs->hcchar,
  71736. + hcchar.d32);
  71737. + }
  71738. + }
  71739. + }
  71740. + }
  71741. +
  71742. + for (i = 0; i < num_channels; i++) {
  71743. + channel = dwc_otg_hcd->hc_ptr_array[i];
  71744. + if (DWC_CIRCLEQ_EMPTY_ENTRY(channel, hc_list_entry)) {
  71745. + hc_regs =
  71746. + dwc_otg_hcd->core_if->host_if->hc_regs[i];
  71747. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  71748. + if (hcchar.b.chen) {
  71749. + /* Halt the channel. */
  71750. + hcchar.b.chdis = 1;
  71751. + DWC_WRITE_REG32(&hc_regs->hcchar,
  71752. + hcchar.d32);
  71753. + }
  71754. +
  71755. + dwc_otg_hc_cleanup(dwc_otg_hcd->core_if,
  71756. + channel);
  71757. + DWC_CIRCLEQ_INSERT_TAIL
  71758. + (&dwc_otg_hcd->free_hc_list, channel,
  71759. + hc_list_entry);
  71760. + /*
  71761. + * Added for Descriptor DMA to prevent channel double cleanup
  71762. + * in release_channel_ddma(). Which called from ep_disable
  71763. + * when device disconnect.
  71764. + */
  71765. + channel->qh = NULL;
  71766. + }
  71767. + }
  71768. + if(fiq_fsm_enable) {
  71769. + for(i=0; i < 128; i++) {
  71770. + dwc_otg_hcd->hub_port[i] = 0;
  71771. + }
  71772. + }
  71773. +
  71774. + }
  71775. +
  71776. + if(fiq_enable)
  71777. + local_fiq_enable();
  71778. +
  71779. + if (dwc_otg_hcd->fops->disconnect) {
  71780. + dwc_otg_hcd->fops->disconnect(dwc_otg_hcd);
  71781. + }
  71782. +
  71783. + return 1;
  71784. +}
  71785. +
  71786. +/**
  71787. + * HCD Callback function for stopping the HCD.
  71788. + *
  71789. + * @param p void pointer to the <code>struct usb_hcd</code>
  71790. + */
  71791. +static int32_t dwc_otg_hcd_stop_cb(void *p)
  71792. +{
  71793. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  71794. +
  71795. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, p);
  71796. + dwc_otg_hcd_stop(dwc_otg_hcd);
  71797. + return 1;
  71798. +}
  71799. +
  71800. +#ifdef CONFIG_USB_DWC_OTG_LPM
  71801. +/**
  71802. + * HCD Callback function for sleep of HCD.
  71803. + *
  71804. + * @param p void pointer to the <code>struct usb_hcd</code>
  71805. + */
  71806. +static int dwc_otg_hcd_sleep_cb(void *p)
  71807. +{
  71808. + dwc_otg_hcd_t *hcd = p;
  71809. +
  71810. + dwc_otg_hcd_free_hc_from_lpm(hcd);
  71811. +
  71812. + return 0;
  71813. +}
  71814. +#endif
  71815. +
  71816. +
  71817. +/**
  71818. + * HCD Callback function for Remote Wakeup.
  71819. + *
  71820. + * @param p void pointer to the <code>struct usb_hcd</code>
  71821. + */
  71822. +static int dwc_otg_hcd_rem_wakeup_cb(void *p)
  71823. +{
  71824. + dwc_otg_hcd_t *hcd = p;
  71825. +
  71826. + if (hcd->core_if->lx_state == DWC_OTG_L2) {
  71827. + hcd->flags.b.port_suspend_change = 1;
  71828. + }
  71829. +#ifdef CONFIG_USB_DWC_OTG_LPM
  71830. + else {
  71831. + hcd->flags.b.port_l1_change = 1;
  71832. + }
  71833. +#endif
  71834. + return 0;
  71835. +}
  71836. +
  71837. +/**
  71838. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  71839. + * stopped.
  71840. + */
  71841. +void dwc_otg_hcd_stop(dwc_otg_hcd_t * hcd)
  71842. +{
  71843. + hprt0_data_t hprt0 = {.d32 = 0 };
  71844. +
  71845. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD STOP\n");
  71846. +
  71847. + /*
  71848. + * The root hub should be disconnected before this function is called.
  71849. + * The disconnect will clear the QTD lists (via ..._hcd_urb_dequeue)
  71850. + * and the QH lists (via ..._hcd_endpoint_disable).
  71851. + */
  71852. +
  71853. + /* Turn off all host-specific interrupts. */
  71854. + dwc_otg_disable_host_interrupts(hcd->core_if);
  71855. +
  71856. + /* Turn off the vbus power */
  71857. + DWC_PRINTF("PortPower off\n");
  71858. + hprt0.b.prtpwr = 0;
  71859. + DWC_WRITE_REG32(hcd->core_if->host_if->hprt0, hprt0.d32);
  71860. + dwc_mdelay(1);
  71861. +}
  71862. +
  71863. +int dwc_otg_hcd_urb_enqueue(dwc_otg_hcd_t * hcd,
  71864. + dwc_otg_hcd_urb_t * dwc_otg_urb, void **ep_handle,
  71865. + int atomic_alloc)
  71866. +{
  71867. + int retval = 0;
  71868. + uint8_t needs_scheduling = 0;
  71869. + dwc_otg_transaction_type_e tr_type;
  71870. + dwc_otg_qtd_t *qtd;
  71871. + gintmsk_data_t intr_mask = {.d32 = 0 };
  71872. + hprt0_data_t hprt0 = { .d32 = 0 };
  71873. +
  71874. +#ifdef DEBUG /* integrity checks (Broadcom) */
  71875. + if (NULL == hcd->core_if) {
  71876. + DWC_ERROR("**** DWC OTG HCD URB Enqueue - HCD has NULL core_if\n");
  71877. + /* No longer connected. */
  71878. + return -DWC_E_INVALID;
  71879. + }
  71880. +#endif
  71881. + if (!hcd->flags.b.port_connect_status) {
  71882. + /* No longer connected. */
  71883. + DWC_ERROR("Not connected\n");
  71884. + return -DWC_E_NO_DEVICE;
  71885. + }
  71886. +
  71887. + /* Some core configurations cannot support LS traffic on a FS root port */
  71888. + if ((hcd->fops->speed(hcd, dwc_otg_urb->priv) == USB_SPEED_LOW) &&
  71889. + (hcd->core_if->hwcfg2.b.fs_phy_type == 1) &&
  71890. + (hcd->core_if->hwcfg2.b.hs_phy_type == 1)) {
  71891. + hprt0.d32 = DWC_READ_REG32(hcd->core_if->host_if->hprt0);
  71892. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_FULL_SPEED) {
  71893. + return -DWC_E_NO_DEVICE;
  71894. + }
  71895. + }
  71896. +
  71897. + qtd = dwc_otg_hcd_qtd_create(dwc_otg_urb, atomic_alloc);
  71898. + if (qtd == NULL) {
  71899. + DWC_ERROR("DWC OTG HCD URB Enqueue failed creating QTD\n");
  71900. + return -DWC_E_NO_MEMORY;
  71901. + }
  71902. +#ifdef DEBUG /* integrity checks (Broadcom) */
  71903. + if (qtd->urb == NULL) {
  71904. + DWC_ERROR("**** DWC OTG HCD URB Enqueue created QTD with no URBs\n");
  71905. + return -DWC_E_NO_MEMORY;
  71906. + }
  71907. + if (qtd->urb->priv == NULL) {
  71908. + DWC_ERROR("**** DWC OTG HCD URB Enqueue created QTD URB with no URB handle\n");
  71909. + return -DWC_E_NO_MEMORY;
  71910. + }
  71911. +#endif
  71912. + intr_mask.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->gintmsk);
  71913. + if(!intr_mask.b.sofintr || fiq_enable) needs_scheduling = 1;
  71914. + if((((dwc_otg_qh_t *)ep_handle)->ep_type == UE_BULK) && !(qtd->urb->flags & URB_GIVEBACK_ASAP))
  71915. + /* Do not schedule SG transactions until qtd has URB_GIVEBACK_ASAP set */
  71916. + needs_scheduling = 0;
  71917. +
  71918. + retval = dwc_otg_hcd_qtd_add(qtd, hcd, (dwc_otg_qh_t **) ep_handle, atomic_alloc);
  71919. + // creates a new queue in ep_handle if it doesn't exist already
  71920. + if (retval < 0) {
  71921. + DWC_ERROR("DWC OTG HCD URB Enqueue failed adding QTD. "
  71922. + "Error status %d\n", retval);
  71923. + dwc_otg_hcd_qtd_free(qtd);
  71924. + return retval;
  71925. + }
  71926. +
  71927. + if(needs_scheduling) {
  71928. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  71929. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  71930. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  71931. + }
  71932. + }
  71933. + return retval;
  71934. +}
  71935. +
  71936. +int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_t * hcd,
  71937. + dwc_otg_hcd_urb_t * dwc_otg_urb)
  71938. +{
  71939. + dwc_otg_qh_t *qh;
  71940. + dwc_otg_qtd_t *urb_qtd;
  71941. + BUG_ON(!hcd);
  71942. + BUG_ON(!dwc_otg_urb);
  71943. +
  71944. +#ifdef DEBUG /* integrity checks (Broadcom) */
  71945. +
  71946. + if (hcd == NULL) {
  71947. + DWC_ERROR("**** DWC OTG HCD URB Dequeue has NULL HCD\n");
  71948. + return -DWC_E_INVALID;
  71949. + }
  71950. + if (dwc_otg_urb == NULL) {
  71951. + DWC_ERROR("**** DWC OTG HCD URB Dequeue has NULL URB\n");
  71952. + return -DWC_E_INVALID;
  71953. + }
  71954. + if (dwc_otg_urb->qtd == NULL) {
  71955. + DWC_ERROR("**** DWC OTG HCD URB Dequeue with NULL QTD\n");
  71956. + return -DWC_E_INVALID;
  71957. + }
  71958. + urb_qtd = dwc_otg_urb->qtd;
  71959. + BUG_ON(!urb_qtd);
  71960. + if (urb_qtd->qh == NULL) {
  71961. + DWC_ERROR("**** DWC OTG HCD URB Dequeue with QTD with NULL Q handler\n");
  71962. + return -DWC_E_INVALID;
  71963. + }
  71964. +#else
  71965. + urb_qtd = dwc_otg_urb->qtd;
  71966. + BUG_ON(!urb_qtd);
  71967. +#endif
  71968. + qh = urb_qtd->qh;
  71969. + BUG_ON(!qh);
  71970. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  71971. + if (urb_qtd->in_process) {
  71972. + dump_channel_info(hcd, qh);
  71973. + }
  71974. + }
  71975. +#ifdef DEBUG /* integrity checks (Broadcom) */
  71976. + if (hcd->core_if == NULL) {
  71977. + DWC_ERROR("**** DWC OTG HCD URB Dequeue HCD has NULL core_if\n");
  71978. + return -DWC_E_INVALID;
  71979. + }
  71980. +#endif
  71981. + if (urb_qtd->in_process && qh->channel) {
  71982. + /* The QTD is in process (it has been assigned to a channel). */
  71983. + if (hcd->flags.b.port_connect_status) {
  71984. + int n = qh->channel->hc_num;
  71985. + /*
  71986. + * If still connected (i.e. in host mode), halt the
  71987. + * channel so it can be used for other transfers. If
  71988. + * no longer connected, the host registers can't be
  71989. + * written to halt the channel since the core is in
  71990. + * device mode.
  71991. + */
  71992. + /* In FIQ FSM mode, we need to shut down carefully.
  71993. + * The FIQ may attempt to restart a disabled channel */
  71994. + if (fiq_fsm_enable && (hcd->fiq_state->channel[n].fsm != FIQ_PASSTHROUGH)) {
  71995. + qh->channel->halt_status = DWC_OTG_HC_XFER_URB_DEQUEUE;
  71996. + qh->channel->halt_pending = 1;
  71997. + hcd->fiq_state->channel[n].fsm = FIQ_DEQUEUE_ISSUED;
  71998. + } else {
  71999. + dwc_otg_hc_halt(hcd->core_if, qh->channel,
  72000. + DWC_OTG_HC_XFER_URB_DEQUEUE);
  72001. + }
  72002. + }
  72003. + }
  72004. +
  72005. + /*
  72006. + * Free the QTD and clean up the associated QH. Leave the QH in the
  72007. + * schedule if it has any remaining QTDs.
  72008. + */
  72009. +
  72010. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue - "
  72011. + "delete %sQueue handler\n",
  72012. + hcd->core_if->dma_desc_enable?"DMA ":"");
  72013. + if (!hcd->core_if->dma_desc_enable) {
  72014. + uint8_t b = urb_qtd->in_process;
  72015. + dwc_otg_hcd_qtd_remove_and_free(hcd, urb_qtd, qh);
  72016. + if (b) {
  72017. + dwc_otg_hcd_qh_deactivate(hcd, qh, 0);
  72018. + qh->channel = NULL;
  72019. + } else if (DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  72020. + dwc_otg_hcd_qh_remove(hcd, qh);
  72021. + }
  72022. + } else {
  72023. + dwc_otg_hcd_qtd_remove_and_free(hcd, urb_qtd, qh);
  72024. + }
  72025. + return 0;
  72026. +}
  72027. +
  72028. +int dwc_otg_hcd_endpoint_disable(dwc_otg_hcd_t * hcd, void *ep_handle,
  72029. + int retry)
  72030. +{
  72031. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  72032. + int retval = 0;
  72033. + dwc_irqflags_t flags;
  72034. +
  72035. + if (retry < 0) {
  72036. + retval = -DWC_E_INVALID;
  72037. + goto done;
  72038. + }
  72039. +
  72040. + if (!qh) {
  72041. + retval = -DWC_E_INVALID;
  72042. + goto done;
  72043. + }
  72044. +
  72045. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  72046. +
  72047. + while (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list) && retry) {
  72048. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  72049. + retry--;
  72050. + dwc_msleep(5);
  72051. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  72052. + }
  72053. +
  72054. + dwc_otg_hcd_qh_remove(hcd, qh);
  72055. +
  72056. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  72057. + /*
  72058. + * Split dwc_otg_hcd_qh_remove_and_free() into qh_remove
  72059. + * and qh_free to prevent stack dump on DWC_DMA_FREE() with
  72060. + * irq_disabled (spinlock_irqsave) in dwc_otg_hcd_desc_list_free()
  72061. + * and dwc_otg_hcd_frame_list_alloc().
  72062. + */
  72063. + dwc_otg_hcd_qh_free(hcd, qh);
  72064. +
  72065. +done:
  72066. + return retval;
  72067. +}
  72068. +
  72069. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  72070. +int dwc_otg_hcd_endpoint_reset(dwc_otg_hcd_t * hcd, void *ep_handle)
  72071. +{
  72072. + int retval = 0;
  72073. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  72074. + if (!qh)
  72075. + return -DWC_E_INVALID;
  72076. +
  72077. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  72078. + return retval;
  72079. +}
  72080. +#endif
  72081. +
  72082. +/**
  72083. + * HCD Callback structure for handling mode switching.
  72084. + */
  72085. +static dwc_otg_cil_callbacks_t hcd_cil_callbacks = {
  72086. + .start = dwc_otg_hcd_start_cb,
  72087. + .stop = dwc_otg_hcd_stop_cb,
  72088. + .disconnect = dwc_otg_hcd_disconnect_cb,
  72089. + .session_start = dwc_otg_hcd_session_start_cb,
  72090. + .resume_wakeup = dwc_otg_hcd_rem_wakeup_cb,
  72091. +#ifdef CONFIG_USB_DWC_OTG_LPM
  72092. + .sleep = dwc_otg_hcd_sleep_cb,
  72093. +#endif
  72094. + .p = 0,
  72095. +};
  72096. +
  72097. +/**
  72098. + * Reset tasklet function
  72099. + */
  72100. +static void reset_tasklet_func(void *data)
  72101. +{
  72102. + dwc_otg_hcd_t *dwc_otg_hcd = (dwc_otg_hcd_t *) data;
  72103. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  72104. + hprt0_data_t hprt0;
  72105. +
  72106. + DWC_DEBUGPL(DBG_HCDV, "USB RESET tasklet called\n");
  72107. +
  72108. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  72109. + hprt0.b.prtrst = 1;
  72110. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  72111. + dwc_mdelay(60);
  72112. +
  72113. + hprt0.b.prtrst = 0;
  72114. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  72115. + dwc_otg_hcd->flags.b.port_reset_change = 1;
  72116. +}
  72117. +
  72118. +static void completion_tasklet_func(void *ptr)
  72119. +{
  72120. + dwc_otg_hcd_t *hcd = (dwc_otg_hcd_t *) ptr;
  72121. + struct urb *urb;
  72122. + urb_tq_entry_t *item;
  72123. + dwc_irqflags_t flags;
  72124. +
  72125. + /* This could just be spin_lock_irq */
  72126. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  72127. + while (!DWC_TAILQ_EMPTY(&hcd->completed_urb_list)) {
  72128. + item = DWC_TAILQ_FIRST(&hcd->completed_urb_list);
  72129. + urb = item->urb;
  72130. + DWC_TAILQ_REMOVE(&hcd->completed_urb_list, item,
  72131. + urb_tq_entries);
  72132. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  72133. + DWC_FREE(item);
  72134. +
  72135. + usb_hcd_giveback_urb(hcd->priv, urb, urb->status);
  72136. +
  72137. +
  72138. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  72139. + }
  72140. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  72141. + return;
  72142. +}
  72143. +
  72144. +static void qh_list_free(dwc_otg_hcd_t * hcd, dwc_list_link_t * qh_list)
  72145. +{
  72146. + dwc_list_link_t *item;
  72147. + dwc_otg_qh_t *qh;
  72148. + dwc_irqflags_t flags;
  72149. +
  72150. + if (!qh_list->next) {
  72151. + /* The list hasn't been initialized yet. */
  72152. + return;
  72153. + }
  72154. + /*
  72155. + * Hold spinlock here. Not needed in that case if bellow
  72156. + * function is being called from ISR
  72157. + */
  72158. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  72159. + /* Ensure there are no QTDs or URBs left. */
  72160. + kill_urbs_in_qh_list(hcd, qh_list);
  72161. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  72162. +
  72163. + DWC_LIST_FOREACH(item, qh_list) {
  72164. + qh = DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  72165. + dwc_otg_hcd_qh_remove_and_free(hcd, qh);
  72166. + }
  72167. +}
  72168. +
  72169. +/**
  72170. + * Exit from Hibernation if Host did not detect SRP from connected SRP capable
  72171. + * Device during SRP time by host power up.
  72172. + */
  72173. +void dwc_otg_hcd_power_up(void *ptr)
  72174. +{
  72175. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  72176. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  72177. +
  72178. + DWC_PRINTF("%s called\n", __FUNCTION__);
  72179. +
  72180. + if (!core_if->hibernation_suspend) {
  72181. + DWC_PRINTF("Already exited from Hibernation\n");
  72182. + return;
  72183. + }
  72184. +
  72185. + /* Switch on the voltage to the core */
  72186. + gpwrdn.b.pwrdnswtch = 1;
  72187. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  72188. + dwc_udelay(10);
  72189. +
  72190. + /* Reset the core */
  72191. + gpwrdn.d32 = 0;
  72192. + gpwrdn.b.pwrdnrstn = 1;
  72193. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  72194. + dwc_udelay(10);
  72195. +
  72196. + /* Disable power clamps */
  72197. + gpwrdn.d32 = 0;
  72198. + gpwrdn.b.pwrdnclmp = 1;
  72199. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  72200. +
  72201. + /* Remove reset the core signal */
  72202. + gpwrdn.d32 = 0;
  72203. + gpwrdn.b.pwrdnrstn = 1;
  72204. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  72205. + dwc_udelay(10);
  72206. +
  72207. + /* Disable PMU interrupt */
  72208. + gpwrdn.d32 = 0;
  72209. + gpwrdn.b.pmuintsel = 1;
  72210. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  72211. +
  72212. + core_if->hibernation_suspend = 0;
  72213. +
  72214. + /* Disable PMU */
  72215. + gpwrdn.d32 = 0;
  72216. + gpwrdn.b.pmuactv = 1;
  72217. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  72218. + dwc_udelay(10);
  72219. +
  72220. + /* Enable VBUS */
  72221. + gpwrdn.d32 = 0;
  72222. + gpwrdn.b.dis_vbus = 1;
  72223. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  72224. +
  72225. + core_if->op_state = A_HOST;
  72226. + dwc_otg_core_init(core_if);
  72227. + dwc_otg_enable_global_interrupts(core_if);
  72228. + cil_hcd_start(core_if);
  72229. +}
  72230. +
  72231. +void dwc_otg_cleanup_fiq_channel(dwc_otg_hcd_t *hcd, uint32_t num)
  72232. +{
  72233. + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
  72234. + struct fiq_dma_blob *blob = hcd->fiq_dmab;
  72235. + int i;
  72236. +
  72237. + st->fsm = FIQ_PASSTHROUGH;
  72238. + st->hcchar_copy.d32 = 0;
  72239. + st->hcsplt_copy.d32 = 0;
  72240. + st->hcint_copy.d32 = 0;
  72241. + st->hcintmsk_copy.d32 = 0;
  72242. + st->hctsiz_copy.d32 = 0;
  72243. + st->hcdma_copy.d32 = 0;
  72244. + st->nr_errors = 0;
  72245. + st->hub_addr = 0;
  72246. + st->port_addr = 0;
  72247. + st->expected_uframe = 0;
  72248. + st->nrpackets = 0;
  72249. + st->dma_info.index = 0;
  72250. + for (i = 0; i < 6; i++)
  72251. + st->dma_info.slot_len[i] = 255;
  72252. + st->hs_isoc_info.index = 0;
  72253. + st->hs_isoc_info.iso_desc = NULL;
  72254. + st->hs_isoc_info.nrframes = 0;
  72255. +
  72256. + DWC_MEMSET(&blob->channel[num].index[0], 0x6b, 1128);
  72257. +}
  72258. +
  72259. +/**
  72260. + * Frees secondary storage associated with the dwc_otg_hcd structure contained
  72261. + * in the struct usb_hcd field.
  72262. + */
  72263. +static void dwc_otg_hcd_free(dwc_otg_hcd_t * dwc_otg_hcd)
  72264. +{
  72265. + int i;
  72266. +
  72267. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD FREE\n");
  72268. +
  72269. + del_timers(dwc_otg_hcd);
  72270. +
  72271. + /* Free memory for QH/QTD lists */
  72272. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_inactive);
  72273. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_active);
  72274. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_inactive);
  72275. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_ready);
  72276. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_assigned);
  72277. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_queued);
  72278. +
  72279. + /* Free memory for the host channels. */
  72280. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  72281. + dwc_hc_t *hc = dwc_otg_hcd->hc_ptr_array[i];
  72282. +
  72283. +#ifdef DEBUG
  72284. + if (dwc_otg_hcd->core_if->hc_xfer_timer[i]) {
  72285. + DWC_TIMER_FREE(dwc_otg_hcd->core_if->hc_xfer_timer[i]);
  72286. + }
  72287. +#endif
  72288. + if (hc != NULL) {
  72289. + DWC_DEBUGPL(DBG_HCDV, "HCD Free channel #%i, hc=%p\n",
  72290. + i, hc);
  72291. + DWC_FREE(hc);
  72292. + }
  72293. + }
  72294. +
  72295. + if (dwc_otg_hcd->core_if->dma_enable) {
  72296. + if (dwc_otg_hcd->status_buf_dma) {
  72297. + DWC_DMA_FREE(DWC_OTG_HCD_STATUS_BUF_SIZE,
  72298. + dwc_otg_hcd->status_buf,
  72299. + dwc_otg_hcd->status_buf_dma);
  72300. + }
  72301. + } else if (dwc_otg_hcd->status_buf != NULL) {
  72302. + DWC_FREE(dwc_otg_hcd->status_buf);
  72303. + }
  72304. + DWC_SPINLOCK_FREE(dwc_otg_hcd->channel_lock);
  72305. + DWC_SPINLOCK_FREE(dwc_otg_hcd->lock);
  72306. + /* Set core_if's lock pointer to NULL */
  72307. + dwc_otg_hcd->core_if->lock = NULL;
  72308. +
  72309. + DWC_TIMER_FREE(dwc_otg_hcd->conn_timer);
  72310. + DWC_TASK_FREE(dwc_otg_hcd->reset_tasklet);
  72311. + DWC_TASK_FREE(dwc_otg_hcd->completion_tasklet);
  72312. + DWC_FREE(dwc_otg_hcd->fiq_state);
  72313. +
  72314. +#ifdef DWC_DEV_SRPCAP
  72315. + if (dwc_otg_hcd->core_if->power_down == 2 &&
  72316. + dwc_otg_hcd->core_if->pwron_timer) {
  72317. + DWC_TIMER_FREE(dwc_otg_hcd->core_if->pwron_timer);
  72318. + }
  72319. +#endif
  72320. + DWC_FREE(dwc_otg_hcd);
  72321. +}
  72322. +
  72323. +int init_hcd_usecs(dwc_otg_hcd_t *_hcd);
  72324. +
  72325. +int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd, dwc_otg_core_if_t * core_if)
  72326. +{
  72327. + int retval = 0;
  72328. + int num_channels;
  72329. + int i;
  72330. + dwc_hc_t *channel;
  72331. +
  72332. + hcd->lock = DWC_SPINLOCK_ALLOC();
  72333. + hcd->channel_lock = DWC_SPINLOCK_ALLOC();
  72334. + DWC_DEBUGPL(DBG_HCDV, "init of HCD %p given core_if %p\n",
  72335. + hcd, core_if);
  72336. + if (!hcd->lock) {
  72337. + DWC_ERROR("Could not allocate lock for pcd");
  72338. + DWC_FREE(hcd);
  72339. + retval = -DWC_E_NO_MEMORY;
  72340. + goto out;
  72341. + }
  72342. + hcd->core_if = core_if;
  72343. +
  72344. + /* Register the HCD CIL Callbacks */
  72345. + dwc_otg_cil_register_hcd_callbacks(hcd->core_if,
  72346. + &hcd_cil_callbacks, hcd);
  72347. +
  72348. + /* Initialize the non-periodic schedule. */
  72349. + DWC_LIST_INIT(&hcd->non_periodic_sched_inactive);
  72350. + DWC_LIST_INIT(&hcd->non_periodic_sched_active);
  72351. +
  72352. + /* Initialize the periodic schedule. */
  72353. + DWC_LIST_INIT(&hcd->periodic_sched_inactive);
  72354. + DWC_LIST_INIT(&hcd->periodic_sched_ready);
  72355. + DWC_LIST_INIT(&hcd->periodic_sched_assigned);
  72356. + DWC_LIST_INIT(&hcd->periodic_sched_queued);
  72357. + DWC_TAILQ_INIT(&hcd->completed_urb_list);
  72358. + /*
  72359. + * Create a host channel descriptor for each host channel implemented
  72360. + * in the controller. Initialize the channel descriptor array.
  72361. + */
  72362. + DWC_CIRCLEQ_INIT(&hcd->free_hc_list);
  72363. + num_channels = hcd->core_if->core_params->host_channels;
  72364. + DWC_MEMSET(hcd->hc_ptr_array, 0, sizeof(hcd->hc_ptr_array));
  72365. + for (i = 0; i < num_channels; i++) {
  72366. + channel = DWC_ALLOC(sizeof(dwc_hc_t));
  72367. + if (channel == NULL) {
  72368. + retval = -DWC_E_NO_MEMORY;
  72369. + DWC_ERROR("%s: host channel allocation failed\n",
  72370. + __func__);
  72371. + dwc_otg_hcd_free(hcd);
  72372. + goto out;
  72373. + }
  72374. + channel->hc_num = i;
  72375. + hcd->hc_ptr_array[i] = channel;
  72376. +#ifdef DEBUG
  72377. + hcd->core_if->hc_xfer_timer[i] =
  72378. + DWC_TIMER_ALLOC("hc timer", hc_xfer_timeout,
  72379. + &hcd->core_if->hc_xfer_info[i]);
  72380. +#endif
  72381. + DWC_DEBUGPL(DBG_HCDV, "HCD Added channel #%d, hc=%p\n", i,
  72382. + channel);
  72383. + }
  72384. +
  72385. + if (fiq_enable) {
  72386. + hcd->fiq_state = DWC_ALLOC(sizeof(struct fiq_state) + (sizeof(struct fiq_channel_state) * num_channels));
  72387. + if (!hcd->fiq_state) {
  72388. + retval = -DWC_E_NO_MEMORY;
  72389. + DWC_ERROR("%s: cannot allocate fiq_state structure\n", __func__);
  72390. + dwc_otg_hcd_free(hcd);
  72391. + goto out;
  72392. + }
  72393. + DWC_MEMSET(hcd->fiq_state, 0, (sizeof(struct fiq_state) + (sizeof(struct fiq_channel_state) * num_channels)));
  72394. +
  72395. + for (i = 0; i < num_channels; i++) {
  72396. + hcd->fiq_state->channel[i].fsm = FIQ_PASSTHROUGH;
  72397. + }
  72398. + hcd->fiq_state->dummy_send = DWC_ALLOC_ATOMIC(16);
  72399. +
  72400. + hcd->fiq_stack = DWC_ALLOC(sizeof(struct fiq_stack));
  72401. + if (!hcd->fiq_stack) {
  72402. + retval = -DWC_E_NO_MEMORY;
  72403. + DWC_ERROR("%s: cannot allocate fiq_stack structure\n", __func__);
  72404. + dwc_otg_hcd_free(hcd);
  72405. + goto out;
  72406. + }
  72407. + hcd->fiq_stack->magic1 = 0xDEADBEEF;
  72408. + hcd->fiq_stack->magic2 = 0xD00DFEED;
  72409. + hcd->fiq_state->gintmsk_saved.d32 = ~0;
  72410. + hcd->fiq_state->haintmsk_saved.b2.chint = ~0;
  72411. +
  72412. + /* This bit is terrible and uses no API, but necessary. The FIQ has no concept of DMA pools
  72413. + * (and if it did, would be a lot slower). This allocates a chunk of memory (~9kiB for 8 host channels)
  72414. + * for use as transaction bounce buffers in a 2-D array. Our access into this chunk is done by some
  72415. + * moderately readable array casts.
  72416. + */
  72417. + hcd->fiq_dmab = DWC_DMA_ALLOC((sizeof(struct fiq_dma_channel) * num_channels), &hcd->fiq_state->dma_base);
  72418. + DWC_WARN("FIQ DMA bounce buffers: virt = 0x%08x dma = 0x%08x len=%d",
  72419. + (unsigned int)hcd->fiq_dmab, (unsigned int)hcd->fiq_state->dma_base,
  72420. + sizeof(struct fiq_dma_channel) * num_channels);
  72421. +
  72422. + DWC_MEMSET(hcd->fiq_dmab, 0x6b, 9024);
  72423. +
  72424. + /* pointer for debug in fiq_print */
  72425. + hcd->fiq_state->fiq_dmab = hcd->fiq_dmab;
  72426. + if (fiq_fsm_enable) {
  72427. + int i;
  72428. + for (i=0; i < hcd->core_if->core_params->host_channels; i++) {
  72429. + dwc_otg_cleanup_fiq_channel(hcd, i);
  72430. + }
  72431. + DWC_PRINTF("FIQ FSM acceleration enabled for :\n%s%s%s%s",
  72432. + (fiq_fsm_mask & 0x1) ? "Non-periodic Split Transactions\n" : "",
  72433. + (fiq_fsm_mask & 0x2) ? "Periodic Split Transactions\n" : "",
  72434. + (fiq_fsm_mask & 0x4) ? "High-Speed Isochronous Endpoints\n" : "",
  72435. + (fiq_fsm_mask & 0x8) ? "Interrupt/Control Split Transaction hack enabled\n" : "");
  72436. + }
  72437. + }
  72438. +
  72439. + /* Initialize the Connection timeout timer. */
  72440. + hcd->conn_timer = DWC_TIMER_ALLOC("Connection timer",
  72441. + dwc_otg_hcd_connect_timeout, 0);
  72442. +
  72443. + printk(KERN_DEBUG "dwc_otg: Microframe scheduler %s\n", microframe_schedule ? "enabled":"disabled");
  72444. + if (microframe_schedule)
  72445. + init_hcd_usecs(hcd);
  72446. +
  72447. + /* Initialize reset tasklet. */
  72448. + hcd->reset_tasklet = DWC_TASK_ALLOC("reset_tasklet", reset_tasklet_func, hcd);
  72449. +
  72450. + hcd->completion_tasklet = DWC_TASK_ALLOC("completion_tasklet",
  72451. + completion_tasklet_func, hcd);
  72452. +#ifdef DWC_DEV_SRPCAP
  72453. + if (hcd->core_if->power_down == 2) {
  72454. + /* Initialize Power on timer for Host power up in case hibernation */
  72455. + hcd->core_if->pwron_timer = DWC_TIMER_ALLOC("PWRON TIMER",
  72456. + dwc_otg_hcd_power_up, core_if);
  72457. + }
  72458. +#endif
  72459. +
  72460. + /*
  72461. + * Allocate space for storing data on status transactions. Normally no
  72462. + * data is sent, but this space acts as a bit bucket. This must be
  72463. + * done after usb_add_hcd since that function allocates the DMA buffer
  72464. + * pool.
  72465. + */
  72466. + if (hcd->core_if->dma_enable) {
  72467. + hcd->status_buf =
  72468. + DWC_DMA_ALLOC(DWC_OTG_HCD_STATUS_BUF_SIZE,
  72469. + &hcd->status_buf_dma);
  72470. + } else {
  72471. + hcd->status_buf = DWC_ALLOC(DWC_OTG_HCD_STATUS_BUF_SIZE);
  72472. + }
  72473. + if (!hcd->status_buf) {
  72474. + retval = -DWC_E_NO_MEMORY;
  72475. + DWC_ERROR("%s: status_buf allocation failed\n", __func__);
  72476. + dwc_otg_hcd_free(hcd);
  72477. + goto out;
  72478. + }
  72479. +
  72480. + hcd->otg_port = 1;
  72481. + hcd->frame_list = NULL;
  72482. + hcd->frame_list_dma = 0;
  72483. + hcd->periodic_qh_count = 0;
  72484. +
  72485. + DWC_MEMSET(hcd->hub_port, 0, sizeof(hcd->hub_port));
  72486. +#ifdef FIQ_DEBUG
  72487. + DWC_MEMSET(hcd->hub_port_alloc, -1, sizeof(hcd->hub_port_alloc));
  72488. +#endif
  72489. +
  72490. +out:
  72491. + return retval;
  72492. +}
  72493. +
  72494. +void dwc_otg_hcd_remove(dwc_otg_hcd_t * hcd)
  72495. +{
  72496. + /* Turn off all host-specific interrupts. */
  72497. + dwc_otg_disable_host_interrupts(hcd->core_if);
  72498. +
  72499. + dwc_otg_hcd_free(hcd);
  72500. +}
  72501. +
  72502. +/**
  72503. + * Initializes dynamic portions of the DWC_otg HCD state.
  72504. + */
  72505. +static void dwc_otg_hcd_reinit(dwc_otg_hcd_t * hcd)
  72506. +{
  72507. + int num_channels;
  72508. + int i;
  72509. + dwc_hc_t *channel;
  72510. + dwc_hc_t *channel_tmp;
  72511. +
  72512. + hcd->flags.d32 = 0;
  72513. +
  72514. + hcd->non_periodic_qh_ptr = &hcd->non_periodic_sched_active;
  72515. + if (!microframe_schedule) {
  72516. + hcd->non_periodic_channels = 0;
  72517. + hcd->periodic_channels = 0;
  72518. + } else {
  72519. + hcd->available_host_channels = hcd->core_if->core_params->host_channels;
  72520. + }
  72521. + /*
  72522. + * Put all channels in the free channel list and clean up channel
  72523. + * states.
  72524. + */
  72525. + DWC_CIRCLEQ_FOREACH_SAFE(channel, channel_tmp,
  72526. + &hcd->free_hc_list, hc_list_entry) {
  72527. + DWC_CIRCLEQ_REMOVE(&hcd->free_hc_list, channel, hc_list_entry);
  72528. + }
  72529. +
  72530. + num_channels = hcd->core_if->core_params->host_channels;
  72531. + for (i = 0; i < num_channels; i++) {
  72532. + channel = hcd->hc_ptr_array[i];
  72533. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, channel,
  72534. + hc_list_entry);
  72535. + dwc_otg_hc_cleanup(hcd->core_if, channel);
  72536. + }
  72537. +
  72538. + /* Initialize the DWC core for host mode operation. */
  72539. + dwc_otg_core_host_init(hcd->core_if);
  72540. +
  72541. + /* Set core_if's lock pointer to the hcd->lock */
  72542. + hcd->core_if->lock = hcd->lock;
  72543. +}
  72544. +
  72545. +/**
  72546. + * Assigns transactions from a QTD to a free host channel and initializes the
  72547. + * host channel to perform the transactions. The host channel is removed from
  72548. + * the free list.
  72549. + *
  72550. + * @param hcd The HCD state structure.
  72551. + * @param qh Transactions from the first QTD for this QH are selected and
  72552. + * assigned to a free host channel.
  72553. + */
  72554. +static void assign_and_init_hc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  72555. +{
  72556. + dwc_hc_t *hc;
  72557. + dwc_otg_qtd_t *qtd;
  72558. + dwc_otg_hcd_urb_t *urb;
  72559. + void* ptr = NULL;
  72560. +
  72561. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  72562. +
  72563. + urb = qtd->urb;
  72564. +
  72565. + DWC_DEBUGPL(DBG_HCDV, "%s(%p,%p) - urb %x, actual_length %d\n", __func__, hcd, qh, (unsigned int)urb, urb->actual_length);
  72566. +
  72567. + if (((urb->actual_length < 0) || (urb->actual_length > urb->length)) && !dwc_otg_hcd_is_pipe_in(&urb->pipe_info))
  72568. + urb->actual_length = urb->length;
  72569. +
  72570. +
  72571. + hc = DWC_CIRCLEQ_FIRST(&hcd->free_hc_list);
  72572. +
  72573. + /* Remove the host channel from the free list. */
  72574. + DWC_CIRCLEQ_REMOVE_INIT(&hcd->free_hc_list, hc, hc_list_entry);
  72575. +
  72576. + qh->channel = hc;
  72577. +
  72578. + qtd->in_process = 1;
  72579. +
  72580. + /*
  72581. + * Use usb_pipedevice to determine device address. This address is
  72582. + * 0 before the SET_ADDRESS command and the correct address afterward.
  72583. + */
  72584. + hc->dev_addr = dwc_otg_hcd_get_dev_addr(&urb->pipe_info);
  72585. + hc->ep_num = dwc_otg_hcd_get_ep_num(&urb->pipe_info);
  72586. + hc->speed = qh->dev_speed;
  72587. + hc->max_packet = dwc_max_packet(qh->maxp);
  72588. +
  72589. + hc->xfer_started = 0;
  72590. + hc->halt_status = DWC_OTG_HC_XFER_NO_HALT_STATUS;
  72591. + hc->error_state = (qtd->error_count > 0);
  72592. + hc->halt_on_queue = 0;
  72593. + hc->halt_pending = 0;
  72594. + hc->requests = 0;
  72595. +
  72596. + /*
  72597. + * The following values may be modified in the transfer type section
  72598. + * below. The xfer_len value may be reduced when the transfer is
  72599. + * started to accommodate the max widths of the XferSize and PktCnt
  72600. + * fields in the HCTSIZn register.
  72601. + */
  72602. +
  72603. + hc->ep_is_in = (dwc_otg_hcd_is_pipe_in(&urb->pipe_info) != 0);
  72604. + if (hc->ep_is_in) {
  72605. + hc->do_ping = 0;
  72606. + } else {
  72607. + hc->do_ping = qh->ping_state;
  72608. + }
  72609. +
  72610. + hc->data_pid_start = qh->data_toggle;
  72611. + hc->multi_count = 1;
  72612. +
  72613. + if (hcd->core_if->dma_enable) {
  72614. + hc->xfer_buff = (uint8_t *) urb->dma + urb->actual_length;
  72615. +
  72616. + /* For non-dword aligned case */
  72617. + if (((unsigned long)hc->xfer_buff & 0x3)
  72618. + && !hcd->core_if->dma_desc_enable) {
  72619. + ptr = (uint8_t *) urb->buf + urb->actual_length;
  72620. + }
  72621. + } else {
  72622. + hc->xfer_buff = (uint8_t *) urb->buf + urb->actual_length;
  72623. + }
  72624. + hc->xfer_len = urb->length - urb->actual_length;
  72625. + hc->xfer_count = 0;
  72626. +
  72627. + /*
  72628. + * Set the split attributes
  72629. + */
  72630. + hc->do_split = 0;
  72631. + if (qh->do_split) {
  72632. + uint32_t hub_addr, port_addr;
  72633. + hc->do_split = 1;
  72634. + hc->xact_pos = qtd->isoc_split_pos;
  72635. + /* We don't need to do complete splits anymore */
  72636. +// if(fiq_fsm_enable)
  72637. + if (0)
  72638. + hc->complete_split = qtd->complete_split = 0;
  72639. + else
  72640. + hc->complete_split = qtd->complete_split;
  72641. +
  72642. + hcd->fops->hub_info(hcd, urb->priv, &hub_addr, &port_addr);
  72643. + hc->hub_addr = (uint8_t) hub_addr;
  72644. + hc->port_addr = (uint8_t) port_addr;
  72645. + }
  72646. +
  72647. + switch (dwc_otg_hcd_get_pipe_type(&urb->pipe_info)) {
  72648. + case UE_CONTROL:
  72649. + hc->ep_type = DWC_OTG_EP_TYPE_CONTROL;
  72650. + switch (qtd->control_phase) {
  72651. + case DWC_OTG_CONTROL_SETUP:
  72652. + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction\n");
  72653. + hc->do_ping = 0;
  72654. + hc->ep_is_in = 0;
  72655. + hc->data_pid_start = DWC_OTG_HC_PID_SETUP;
  72656. + if (hcd->core_if->dma_enable) {
  72657. + hc->xfer_buff = (uint8_t *) urb->setup_dma;
  72658. + } else {
  72659. + hc->xfer_buff = (uint8_t *) urb->setup_packet;
  72660. + }
  72661. + hc->xfer_len = 8;
  72662. + ptr = NULL;
  72663. + break;
  72664. + case DWC_OTG_CONTROL_DATA:
  72665. + DWC_DEBUGPL(DBG_HCDV, " Control data transaction\n");
  72666. + hc->data_pid_start = qtd->data_toggle;
  72667. + break;
  72668. + case DWC_OTG_CONTROL_STATUS:
  72669. + /*
  72670. + * Direction is opposite of data direction or IN if no
  72671. + * data.
  72672. + */
  72673. + DWC_DEBUGPL(DBG_HCDV, " Control status transaction\n");
  72674. + if (urb->length == 0) {
  72675. + hc->ep_is_in = 1;
  72676. + } else {
  72677. + hc->ep_is_in =
  72678. + dwc_otg_hcd_is_pipe_out(&urb->pipe_info);
  72679. + }
  72680. + if (hc->ep_is_in) {
  72681. + hc->do_ping = 0;
  72682. + }
  72683. +
  72684. + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
  72685. +
  72686. + hc->xfer_len = 0;
  72687. + if (hcd->core_if->dma_enable) {
  72688. + hc->xfer_buff = (uint8_t *) hcd->status_buf_dma;
  72689. + } else {
  72690. + hc->xfer_buff = (uint8_t *) hcd->status_buf;
  72691. + }
  72692. + ptr = NULL;
  72693. + break;
  72694. + }
  72695. + break;
  72696. + case UE_BULK:
  72697. + hc->ep_type = DWC_OTG_EP_TYPE_BULK;
  72698. + break;
  72699. + case UE_INTERRUPT:
  72700. + hc->ep_type = DWC_OTG_EP_TYPE_INTR;
  72701. + break;
  72702. + case UE_ISOCHRONOUS:
  72703. + {
  72704. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  72705. +
  72706. + hc->ep_type = DWC_OTG_EP_TYPE_ISOC;
  72707. +
  72708. + if (hcd->core_if->dma_desc_enable)
  72709. + break;
  72710. +
  72711. + frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
  72712. +
  72713. + frame_desc->status = 0;
  72714. +
  72715. + if (hcd->core_if->dma_enable) {
  72716. + hc->xfer_buff = (uint8_t *) urb->dma;
  72717. + } else {
  72718. + hc->xfer_buff = (uint8_t *) urb->buf;
  72719. + }
  72720. + hc->xfer_buff +=
  72721. + frame_desc->offset + qtd->isoc_split_offset;
  72722. + hc->xfer_len =
  72723. + frame_desc->length - qtd->isoc_split_offset;
  72724. +
  72725. + /* For non-dword aligned buffers */
  72726. + if (((unsigned long)hc->xfer_buff & 0x3)
  72727. + && hcd->core_if->dma_enable) {
  72728. + ptr =
  72729. + (uint8_t *) urb->buf + frame_desc->offset +
  72730. + qtd->isoc_split_offset;
  72731. + } else
  72732. + ptr = NULL;
  72733. +
  72734. + if (hc->xact_pos == DWC_HCSPLIT_XACTPOS_ALL) {
  72735. + if (hc->xfer_len <= 188) {
  72736. + hc->xact_pos = DWC_HCSPLIT_XACTPOS_ALL;
  72737. + } else {
  72738. + hc->xact_pos =
  72739. + DWC_HCSPLIT_XACTPOS_BEGIN;
  72740. + }
  72741. + }
  72742. + }
  72743. + break;
  72744. + }
  72745. + /* non DWORD-aligned buffer case */
  72746. + if (ptr) {
  72747. + uint32_t buf_size;
  72748. + if (hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  72749. + buf_size = hcd->core_if->core_params->max_transfer_size;
  72750. + } else {
  72751. + buf_size = 4096;
  72752. + }
  72753. + if (!qh->dw_align_buf) {
  72754. + qh->dw_align_buf = DWC_DMA_ALLOC_ATOMIC(buf_size,
  72755. + &qh->dw_align_buf_dma);
  72756. + if (!qh->dw_align_buf) {
  72757. + DWC_ERROR
  72758. + ("%s: Failed to allocate memory to handle "
  72759. + "non-dword aligned buffer case\n",
  72760. + __func__);
  72761. + return;
  72762. + }
  72763. + }
  72764. + if (!hc->ep_is_in) {
  72765. + dwc_memcpy(qh->dw_align_buf, ptr, hc->xfer_len);
  72766. + }
  72767. + hc->align_buff = qh->dw_align_buf_dma;
  72768. + } else {
  72769. + hc->align_buff = 0;
  72770. + }
  72771. +
  72772. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  72773. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  72774. + /*
  72775. + * This value may be modified when the transfer is started to
  72776. + * reflect the actual transfer length.
  72777. + */
  72778. + hc->multi_count = dwc_hb_mult(qh->maxp);
  72779. + }
  72780. +
  72781. + if (hcd->core_if->dma_desc_enable)
  72782. + hc->desc_list_addr = qh->desc_list_dma;
  72783. +
  72784. + dwc_otg_hc_init(hcd->core_if, hc);
  72785. + hc->qh = qh;
  72786. +}
  72787. +
  72788. +
  72789. +/**
  72790. + * fiq_fsm_transaction_suitable() - Test a QH for compatibility with the FIQ
  72791. + * @qh: pointer to the endpoint's queue head
  72792. + *
  72793. + * Transaction start/end control flow is grafted onto the existing dwc_otg
  72794. + * mechanisms, to avoid spaghettifying the functions more than they already are.
  72795. + * This function's eligibility check is altered by debug parameter.
  72796. + *
  72797. + * Returns: 0 for unsuitable, 1 implies the FIQ can be enabled for this transaction.
  72798. + */
  72799. +
  72800. +int fiq_fsm_transaction_suitable(dwc_otg_qh_t *qh)
  72801. +{
  72802. + if (qh->do_split) {
  72803. + switch (qh->ep_type) {
  72804. + case UE_CONTROL:
  72805. + case UE_BULK:
  72806. + if (fiq_fsm_mask & (1 << 0))
  72807. + return 1;
  72808. + break;
  72809. + case UE_INTERRUPT:
  72810. + case UE_ISOCHRONOUS:
  72811. + if (fiq_fsm_mask & (1 << 1))
  72812. + return 1;
  72813. + break;
  72814. + default:
  72815. + break;
  72816. + }
  72817. + } else if (qh->ep_type == UE_ISOCHRONOUS) {
  72818. + if (fiq_fsm_mask & (1 << 2)) {
  72819. + /* HS ISOCH support. We test for compatibility:
  72820. + * - DWORD aligned buffers
  72821. + * - Must be at least 2 transfers (otherwise pointless to use the FIQ)
  72822. + * If yes, then the fsm enqueue function will handle the state machine setup.
  72823. + */
  72824. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  72825. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  72826. + struct dwc_otg_hcd_iso_packet_desc (*iso_descs)[0] = &urb->iso_descs;
  72827. + int nr_iso_frames = urb->packet_count;
  72828. + int i;
  72829. + uint32_t ptr;
  72830. +
  72831. + if (nr_iso_frames < 2)
  72832. + return 0;
  72833. + for (i = 0; i < nr_iso_frames; i++) {
  72834. + ptr = urb->dma + iso_descs[i]->offset;
  72835. + if (ptr & 0x3) {
  72836. + printk_ratelimited("%s: Non-Dword aligned isochronous frame offset."
  72837. + " Cannot queue FIQ-accelerated transfer to device %d endpoint %d\n",
  72838. + __FUNCTION__, qh->channel->dev_addr, qh->channel->ep_num);
  72839. + return 0;
  72840. + }
  72841. + }
  72842. + return 1;
  72843. + }
  72844. + }
  72845. + return 0;
  72846. +}
  72847. +
  72848. +/**
  72849. + * fiq_fsm_setup_periodic_dma() - Set up DMA bounce buffers
  72850. + * @hcd: Pointer to the dwc_otg_hcd struct
  72851. + * @qh: Pointer to the endpoint's queue head
  72852. + *
  72853. + * Periodic split transactions are transmitted modulo 188 bytes.
  72854. + * This necessitates slicing data up into buckets for isochronous out
  72855. + * and fixing up the DMA address for all IN transfers.
  72856. + *
  72857. + * Returns 1 if the DMA bounce buffers have been used, 0 if the default
  72858. + * HC buffer has been used.
  72859. + */
  72860. +int fiq_fsm_setup_periodic_dma(dwc_otg_hcd_t *hcd, struct fiq_channel_state *st, dwc_otg_qh_t *qh)
  72861. + {
  72862. + int frame_length, i = 0;
  72863. + uint8_t *ptr = NULL;
  72864. + dwc_hc_t *hc = qh->channel;
  72865. + struct fiq_dma_blob *blob;
  72866. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  72867. +
  72868. + for (i = 0; i < 6; i++) {
  72869. + st->dma_info.slot_len[i] = 255;
  72870. + }
  72871. + st->dma_info.index = 0;
  72872. + i = 0;
  72873. + if (hc->ep_is_in) {
  72874. + /*
  72875. + * Set dma_regs to bounce buffer. FIQ will update the
  72876. + * state depending on transaction progress.
  72877. + */
  72878. + blob = (struct fiq_dma_blob *) hcd->fiq_state->dma_base;
  72879. + st->hcdma_copy.d32 = (uint32_t) &blob->channel[hc->hc_num].index[0].buf[0];
  72880. + /* Calculate the max number of CSPLITS such that the FIQ can time out
  72881. + * a transaction if it fails.
  72882. + */
  72883. + frame_length = st->hcchar_copy.b.mps;
  72884. + do {
  72885. + i++;
  72886. + frame_length -= 188;
  72887. + } while (frame_length >= 0);
  72888. + st->nrpackets = i;
  72889. + return 1;
  72890. + } else {
  72891. + if (qh->ep_type == UE_ISOCHRONOUS) {
  72892. +
  72893. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  72894. +
  72895. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  72896. + frame_length = frame_desc->length;
  72897. +
  72898. + /* Virtual address for bounce buffers */
  72899. + blob = hcd->fiq_dmab;
  72900. +
  72901. + ptr = qtd->urb->buf + frame_desc->offset;
  72902. + if (frame_length == 0) {
  72903. + /*
  72904. + * for isochronous transactions, we must still transmit a packet
  72905. + * even if the length is zero.
  72906. + */
  72907. + st->dma_info.slot_len[0] = 0;
  72908. + st->nrpackets = 1;
  72909. + } else {
  72910. + do {
  72911. + if (frame_length <= 188) {
  72912. + dwc_memcpy(&blob->channel[hc->hc_num].index[i].buf[0], ptr, frame_length);
  72913. + st->dma_info.slot_len[i] = frame_length;
  72914. + ptr += frame_length;
  72915. + } else {
  72916. + dwc_memcpy(&blob->channel[hc->hc_num].index[i].buf[0], ptr, 188);
  72917. + st->dma_info.slot_len[i] = 188;
  72918. + ptr += 188;
  72919. + }
  72920. + i++;
  72921. + frame_length -= 188;
  72922. + } while (frame_length > 0);
  72923. + st->nrpackets = i;
  72924. + }
  72925. + ptr = qtd->urb->buf + frame_desc->offset;
  72926. + /* Point the HC at the DMA address of the bounce buffers */
  72927. + blob = (struct fiq_dma_blob *) hcd->fiq_state->dma_base;
  72928. + st->hcdma_copy.d32 = (uint32_t) &blob->channel[hc->hc_num].index[0].buf[0];
  72929. +
  72930. + /* fixup xfersize to the actual packet size */
  72931. + st->hctsiz_copy.b.pid = 0;
  72932. + st->hctsiz_copy.b.xfersize = st->dma_info.slot_len[0];
  72933. + return 1;
  72934. + } else {
  72935. + /* For interrupt, single OUT packet required, goes in the SSPLIT from hc_buff. */
  72936. + return 0;
  72937. + }
  72938. + }
  72939. +}
  72940. +
  72941. +/*
  72942. + * Pushing a periodic request into the queue near the EOF1 point
  72943. + * in a microframe causes erroneous behaviour (frmovrun) interrupt.
  72944. + * Usually, the request goes out on the bus causing a transfer but
  72945. + * the core does not transfer the data to memory.
  72946. + * This guard interval (in number of 60MHz clocks) is required which
  72947. + * must cater for CPU latency between reading the value and enabling
  72948. + * the channel.
  72949. + */
  72950. +#define PERIODIC_FRREM_BACKOFF 1000
  72951. +
  72952. +int fiq_fsm_queue_isoc_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
  72953. +{
  72954. + dwc_hc_t *hc = qh->channel;
  72955. + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
  72956. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  72957. + int frame;
  72958. + struct fiq_channel_state *st = &hcd->fiq_state->channel[hc->hc_num];
  72959. + int xfer_len, nrpackets;
  72960. + hcdma_data_t hcdma;
  72961. + hfnum_data_t hfnum;
  72962. +
  72963. + if (st->fsm != FIQ_PASSTHROUGH)
  72964. + return 0;
  72965. +
  72966. + st->nr_errors = 0;
  72967. +
  72968. + st->hcchar_copy.d32 = 0;
  72969. + st->hcchar_copy.b.mps = hc->max_packet;
  72970. + st->hcchar_copy.b.epdir = hc->ep_is_in;
  72971. + st->hcchar_copy.b.devaddr = hc->dev_addr;
  72972. + st->hcchar_copy.b.epnum = hc->ep_num;
  72973. + st->hcchar_copy.b.eptype = hc->ep_type;
  72974. +
  72975. + st->hcintmsk_copy.b.chhltd = 1;
  72976. +
  72977. + frame = dwc_otg_hcd_get_frame_number(hcd);
  72978. + st->hcchar_copy.b.oddfrm = (frame & 0x1) ? 0 : 1;
  72979. +
  72980. + st->hcchar_copy.b.lspddev = 0;
  72981. + /* Enable the channel later as a final register write. */
  72982. +
  72983. + st->hcsplt_copy.d32 = 0;
  72984. +
  72985. + st->hs_isoc_info.iso_desc = (struct dwc_otg_hcd_iso_packet_desc *) &qtd->urb->iso_descs;
  72986. + st->hs_isoc_info.nrframes = qtd->urb->packet_count;
  72987. + /* grab the next DMA address offset from the array */
  72988. + st->hcdma_copy.d32 = qtd->urb->dma;
  72989. + hcdma.d32 = st->hcdma_copy.d32 + st->hs_isoc_info.iso_desc[0].offset;
  72990. +
  72991. + /* We need to set multi_count. This is a bit tricky - has to be set per-transaction as
  72992. + * the core needs to be told to send the correct number. Caution: for IN transfers,
  72993. + * this is always set to the maximum size of the endpoint. */
  72994. + xfer_len = st->hs_isoc_info.iso_desc[0].length;
  72995. + nrpackets = (xfer_len + st->hcchar_copy.b.mps - 1) / st->hcchar_copy.b.mps;
  72996. + if (nrpackets == 0)
  72997. + nrpackets = 1;
  72998. + st->hcchar_copy.b.multicnt = nrpackets;
  72999. + st->hctsiz_copy.b.pktcnt = nrpackets;
  73000. +
  73001. + /* Initial PID also needs to be set */
  73002. + if (st->hcchar_copy.b.epdir == 0) {
  73003. + st->hctsiz_copy.b.xfersize = xfer_len;
  73004. + switch (st->hcchar_copy.b.multicnt) {
  73005. + case 1:
  73006. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  73007. + break;
  73008. + case 2:
  73009. + case 3:
  73010. + st->hctsiz_copy.b.pid = DWC_PID_MDATA;
  73011. + break;
  73012. + }
  73013. +
  73014. + } else {
  73015. + st->hctsiz_copy.b.xfersize = nrpackets * st->hcchar_copy.b.mps;
  73016. + switch (st->hcchar_copy.b.multicnt) {
  73017. + case 1:
  73018. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  73019. + break;
  73020. + case 2:
  73021. + st->hctsiz_copy.b.pid = DWC_PID_DATA1;
  73022. + break;
  73023. + case 3:
  73024. + st->hctsiz_copy.b.pid = DWC_PID_DATA2;
  73025. + break;
  73026. + }
  73027. + }
  73028. +
  73029. + fiq_print(FIQDBG_INT, hcd->fiq_state, "FSMQ %01d ", hc->hc_num);
  73030. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcchar_copy.d32);
  73031. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hctsiz_copy.d32);
  73032. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcdma_copy.d32);
  73033. + hfnum.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
  73034. + local_fiq_disable();
  73035. + DWC_WRITE_REG32(&hc_regs->hctsiz, st->hctsiz_copy.d32);
  73036. + DWC_WRITE_REG32(&hc_regs->hcsplt, st->hcsplt_copy.d32);
  73037. + DWC_WRITE_REG32(&hc_regs->hcdma, st->hcdma_copy.d32);
  73038. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  73039. + DWC_WRITE_REG32(&hc_regs->hcintmsk, st->hcintmsk_copy.d32);
  73040. + if (hfnum.b.frrem < PERIODIC_FRREM_BACKOFF) {
  73041. + /* Prevent queueing near EOF1. Bad things happen if a periodic
  73042. + * split transaction is queued very close to EOF.
  73043. + */
  73044. + st->fsm = FIQ_HS_ISOC_SLEEPING;
  73045. + } else {
  73046. + st->fsm = FIQ_HS_ISOC_TURBO;
  73047. + st->hcchar_copy.b.chen = 1;
  73048. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  73049. + }
  73050. + mb();
  73051. + st->hcchar_copy.b.chen = 0;
  73052. + local_fiq_enable();
  73053. + return 0;
  73054. +}
  73055. +
  73056. +
  73057. +/**
  73058. + * fiq_fsm_queue_split_transaction() - Set up a host channel and FIQ state
  73059. + * @hcd: Pointer to the dwc_otg_hcd struct
  73060. + * @qh: Pointer to the endpoint's queue head
  73061. + *
  73062. + * This overrides the dwc_otg driver's normal method of queueing a transaction.
  73063. + * Called from dwc_otg_hcd_queue_transactions(), this performs specific setup
  73064. + * for the nominated host channel.
  73065. + *
  73066. + * For periodic transfers, it also peeks at the FIQ state to see if an immediate
  73067. + * start is possible. If not, then the FIQ is left to start the transfer.
  73068. + */
  73069. +int fiq_fsm_queue_split_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
  73070. +{
  73071. + int start_immediate = 1, i;
  73072. + hfnum_data_t hfnum;
  73073. + dwc_hc_t *hc = qh->channel;
  73074. + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
  73075. + /* Program HC registers, setup FIQ_state, examine FIQ if periodic, start transfer (not if uframe 5) */
  73076. + int hub_addr, port_addr, frame, uframe;
  73077. + struct fiq_channel_state *st = &hcd->fiq_state->channel[hc->hc_num];
  73078. +
  73079. + if (st->fsm != FIQ_PASSTHROUGH)
  73080. + return 0;
  73081. + st->nr_errors = 0;
  73082. +
  73083. + st->hcchar_copy.d32 = 0;
  73084. + st->hcchar_copy.b.mps = hc->max_packet;
  73085. + st->hcchar_copy.b.epdir = hc->ep_is_in;
  73086. + st->hcchar_copy.b.devaddr = hc->dev_addr;
  73087. + st->hcchar_copy.b.epnum = hc->ep_num;
  73088. + st->hcchar_copy.b.eptype = hc->ep_type;
  73089. + if (hc->ep_type & 0x1) {
  73090. + if (hc->ep_is_in)
  73091. + st->hcchar_copy.b.multicnt = 3;
  73092. + else
  73093. + /* Docs say set this to 1, but driver sets to 0! */
  73094. + st->hcchar_copy.b.multicnt = 0;
  73095. + } else {
  73096. + st->hcchar_copy.b.multicnt = 1;
  73097. + st->hcchar_copy.b.oddfrm = 0;
  73098. + }
  73099. + st->hcchar_copy.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW) ? 1 : 0;
  73100. + /* Enable the channel later as a final register write. */
  73101. +
  73102. + st->hcsplt_copy.d32 = 0;
  73103. + if(qh->do_split) {
  73104. + hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
  73105. + st->hcsplt_copy.b.compsplt = 0;
  73106. + st->hcsplt_copy.b.spltena = 1;
  73107. + // XACTPOS is for isoc-out only but needs initialising anyway.
  73108. + st->hcsplt_copy.b.xactpos = ISOC_XACTPOS_ALL;
  73109. + if((qh->ep_type == DWC_OTG_EP_TYPE_ISOC) && (!qh->ep_is_in)) {
  73110. + /* For packetsize 0 < L < 188, ISOC_XACTPOS_ALL.
  73111. + * for longer than this, ISOC_XACTPOS_BEGIN and the FIQ
  73112. + * will update as necessary.
  73113. + */
  73114. + if (hc->xfer_len > 188) {
  73115. + st->hcsplt_copy.b.xactpos = ISOC_XACTPOS_BEGIN;
  73116. + }
  73117. + }
  73118. + st->hcsplt_copy.b.hubaddr = (uint8_t) hub_addr;
  73119. + st->hcsplt_copy.b.prtaddr = (uint8_t) port_addr;
  73120. + st->hub_addr = hub_addr;
  73121. + st->port_addr = port_addr;
  73122. + }
  73123. +
  73124. + st->hctsiz_copy.d32 = 0;
  73125. + st->hctsiz_copy.b.dopng = 0;
  73126. + st->hctsiz_copy.b.pid = hc->data_pid_start;
  73127. +
  73128. + if (hc->ep_is_in || (hc->xfer_len > hc->max_packet)) {
  73129. + hc->xfer_len = hc->max_packet;
  73130. + } else if (!hc->ep_is_in && (hc->xfer_len > 188)) {
  73131. + hc->xfer_len = 188;
  73132. + }
  73133. + st->hctsiz_copy.b.xfersize = hc->xfer_len;
  73134. +
  73135. + st->hctsiz_copy.b.pktcnt = 1;
  73136. +
  73137. + if (hc->ep_type & 0x1) {
  73138. + /*
  73139. + * For potentially multi-packet transfers, must use the DMA bounce buffers. For IN transfers,
  73140. + * the DMA address is the address of the first 188byte slot buffer in the bounce buffer array.
  73141. + * For multi-packet OUT transfers, we need to copy the data into the bounce buffer array so the FIQ can punt
  73142. + * the right address out as necessary. hc->xfer_buff and hc->xfer_len have already been set
  73143. + * in assign_and_init_hc(), but this is for the eventual transaction completion only. The FIQ
  73144. + * must not touch internal driver state.
  73145. + */
  73146. + if(!fiq_fsm_setup_periodic_dma(hcd, st, qh)) {
  73147. + if (hc->align_buff) {
  73148. + st->hcdma_copy.d32 = hc->align_buff;
  73149. + } else {
  73150. + st->hcdma_copy.d32 = ((unsigned long) hc->xfer_buff & 0xFFFFFFFF);
  73151. + }
  73152. + }
  73153. + } else {
  73154. + if (hc->align_buff) {
  73155. + st->hcdma_copy.d32 = hc->align_buff;
  73156. + } else {
  73157. + st->hcdma_copy.d32 = ((unsigned long) hc->xfer_buff & 0xFFFFFFFF);
  73158. + }
  73159. + }
  73160. + /* The FIQ depends upon no other interrupts being enabled except channel halt.
  73161. + * Fixup channel interrupt mask. */
  73162. + st->hcintmsk_copy.d32 = 0;
  73163. + st->hcintmsk_copy.b.chhltd = 1;
  73164. + st->hcintmsk_copy.b.ahberr = 1;
  73165. +
  73166. + /* Hack courtesy of FreeBSD: apparently forcing Interrupt Split transactions
  73167. + * as Control puts the transfer into the non-periodic request queue and the
  73168. + * non-periodic handler in the hub. Makes things lots easier.
  73169. + */
  73170. + if ((fiq_fsm_mask & 0x8) && hc->ep_type == UE_INTERRUPT) {
  73171. + st->hcchar_copy.b.multicnt = 0;
  73172. + st->hcchar_copy.b.oddfrm = 0;
  73173. + st->hcchar_copy.b.eptype = UE_CONTROL;
  73174. + if (hc->align_buff) {
  73175. + st->hcdma_copy.d32 = hc->align_buff;
  73176. + } else {
  73177. + st->hcdma_copy.d32 = ((unsigned long) hc->xfer_buff & 0xFFFFFFFF);
  73178. + }
  73179. + }
  73180. + DWC_WRITE_REG32(&hc_regs->hcdma, st->hcdma_copy.d32);
  73181. + DWC_WRITE_REG32(&hc_regs->hctsiz, st->hctsiz_copy.d32);
  73182. + DWC_WRITE_REG32(&hc_regs->hcsplt, st->hcsplt_copy.d32);
  73183. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  73184. + DWC_WRITE_REG32(&hc_regs->hcintmsk, st->hcintmsk_copy.d32);
  73185. +
  73186. + local_fiq_disable();
  73187. + mb();
  73188. +
  73189. + if (hc->ep_type & 0x1) {
  73190. + hfnum.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
  73191. + frame = (hfnum.b.frnum & ~0x7) >> 3;
  73192. + uframe = hfnum.b.frnum & 0x7;
  73193. + if (hfnum.b.frrem < PERIODIC_FRREM_BACKOFF) {
  73194. + /* Prevent queueing near EOF1. Bad things happen if a periodic
  73195. + * split transaction is queued very close to EOF.
  73196. + */
  73197. + start_immediate = 0;
  73198. + } else if (uframe == 5) {
  73199. + start_immediate = 0;
  73200. + } else if (hc->ep_type == UE_ISOCHRONOUS && !hc->ep_is_in) {
  73201. + start_immediate = 0;
  73202. + } else if (hc->ep_is_in && fiq_fsm_too_late(hcd->fiq_state, hc->hc_num)) {
  73203. + start_immediate = 0;
  73204. + } else {
  73205. + /* Search through all host channels to determine if a transaction
  73206. + * is currently in progress */
  73207. + for (i = 0; i < hcd->core_if->core_params->host_channels; i++) {
  73208. + if (i == hc->hc_num || hcd->fiq_state->channel[i].fsm == FIQ_PASSTHROUGH)
  73209. + continue;
  73210. + switch (hcd->fiq_state->channel[i].fsm) {
  73211. + /* TT is reserved for channels that are in the middle of a periodic
  73212. + * split transaction.
  73213. + */
  73214. + case FIQ_PER_SSPLIT_STARTED:
  73215. + case FIQ_PER_CSPLIT_WAIT:
  73216. + case FIQ_PER_CSPLIT_NYET1:
  73217. + case FIQ_PER_CSPLIT_POLL:
  73218. + case FIQ_PER_ISO_OUT_ACTIVE:
  73219. + case FIQ_PER_ISO_OUT_LAST:
  73220. + if (hcd->fiq_state->channel[i].hub_addr == hub_addr &&
  73221. + hcd->fiq_state->channel[i].port_addr == port_addr) {
  73222. + start_immediate = 0;
  73223. + }
  73224. + break;
  73225. + default:
  73226. + break;
  73227. + }
  73228. + if (!start_immediate)
  73229. + break;
  73230. + }
  73231. + }
  73232. + }
  73233. + if ((fiq_fsm_mask & 0x8) && hc->ep_type == UE_INTERRUPT)
  73234. + start_immediate = 1;
  73235. +
  73236. + fiq_print(FIQDBG_INT, hcd->fiq_state, "FSMQ %01d %01d", hc->hc_num, start_immediate);
  73237. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08d", hfnum.b.frrem);
  73238. + //fiq_print(FIQDBG_INT, hcd->fiq_state, "H:%02dP:%02d", hub_addr, port_addr);
  73239. + //fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hctsiz_copy.d32);
  73240. + //fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcdma_copy.d32);
  73241. + switch (hc->ep_type) {
  73242. + case UE_CONTROL:
  73243. + case UE_BULK:
  73244. + st->fsm = FIQ_NP_SSPLIT_STARTED;
  73245. + break;
  73246. + case UE_ISOCHRONOUS:
  73247. + if (hc->ep_is_in) {
  73248. + if (start_immediate) {
  73249. + st->fsm = FIQ_PER_SSPLIT_STARTED;
  73250. + } else {
  73251. + st->fsm = FIQ_PER_SSPLIT_QUEUED;
  73252. + }
  73253. + } else {
  73254. + if (start_immediate) {
  73255. + /* Single-isoc OUT packets don't require FIQ involvement */
  73256. + if (st->nrpackets == 1) {
  73257. + st->fsm = FIQ_PER_ISO_OUT_LAST;
  73258. + } else {
  73259. + st->fsm = FIQ_PER_ISO_OUT_ACTIVE;
  73260. + }
  73261. + } else {
  73262. + st->fsm = FIQ_PER_ISO_OUT_PENDING;
  73263. + }
  73264. + }
  73265. + break;
  73266. + case UE_INTERRUPT:
  73267. + if (fiq_fsm_mask & 0x8) {
  73268. + st->fsm = FIQ_NP_SSPLIT_STARTED;
  73269. + } else if (start_immediate) {
  73270. + st->fsm = FIQ_PER_SSPLIT_STARTED;
  73271. + } else {
  73272. + st->fsm = FIQ_PER_SSPLIT_QUEUED;
  73273. + }
  73274. + default:
  73275. + break;
  73276. + }
  73277. + if (start_immediate) {
  73278. + /* Set the oddfrm bit as close as possible to actual queueing */
  73279. + frame = dwc_otg_hcd_get_frame_number(hcd);
  73280. + st->expected_uframe = (frame + 1) & 0x3FFF;
  73281. + st->hcchar_copy.b.oddfrm = (frame & 0x1) ? 0 : 1;
  73282. + st->hcchar_copy.b.chen = 1;
  73283. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  73284. + }
  73285. + mb();
  73286. + local_fiq_enable();
  73287. + return 0;
  73288. +}
  73289. +
  73290. +
  73291. +/**
  73292. + * This function selects transactions from the HCD transfer schedule and
  73293. + * assigns them to available host channels. It is called from HCD interrupt
  73294. + * handler functions.
  73295. + *
  73296. + * @param hcd The HCD state structure.
  73297. + *
  73298. + * @return The types of new transactions that were assigned to host channels.
  73299. + */
  73300. +dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t * hcd)
  73301. +{
  73302. + dwc_list_link_t *qh_ptr;
  73303. + dwc_otg_qh_t *qh;
  73304. + int num_channels;
  73305. + dwc_irqflags_t flags;
  73306. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  73307. + dwc_otg_transaction_type_e ret_val = DWC_OTG_TRANSACTION_NONE;
  73308. +
  73309. +#ifdef DEBUG_HOST_CHANNELS
  73310. + last_sel_trans_num_per_scheduled = 0;
  73311. + last_sel_trans_num_nonper_scheduled = 0;
  73312. + last_sel_trans_num_avail_hc_at_start = hcd->available_host_channels;
  73313. +#endif /* DEBUG_HOST_CHANNELS */
  73314. +
  73315. + /* Process entries in the periodic ready list. */
  73316. + qh_ptr = DWC_LIST_FIRST(&hcd->periodic_sched_ready);
  73317. +
  73318. + while (qh_ptr != &hcd->periodic_sched_ready &&
  73319. + !DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  73320. +
  73321. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  73322. +
  73323. + if (microframe_schedule) {
  73324. + // Make sure we leave one channel for non periodic transactions.
  73325. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  73326. + if (hcd->available_host_channels <= 1) {
  73327. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  73328. + break;
  73329. + }
  73330. + hcd->available_host_channels--;
  73331. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  73332. +#ifdef DEBUG_HOST_CHANNELS
  73333. + last_sel_trans_num_per_scheduled++;
  73334. +#endif /* DEBUG_HOST_CHANNELS */
  73335. + }
  73336. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  73337. + assign_and_init_hc(hcd, qh);
  73338. +
  73339. + /*
  73340. + * Move the QH from the periodic ready schedule to the
  73341. + * periodic assigned schedule.
  73342. + */
  73343. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  73344. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  73345. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  73346. + &qh->qh_list_entry);
  73347. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  73348. + }
  73349. +
  73350. + /*
  73351. + * Process entries in the inactive portion of the non-periodic
  73352. + * schedule. Some free host channels may not be used if they are
  73353. + * reserved for periodic transfers.
  73354. + */
  73355. + qh_ptr = hcd->non_periodic_sched_inactive.next;
  73356. + num_channels = hcd->core_if->core_params->host_channels;
  73357. + while (qh_ptr != &hcd->non_periodic_sched_inactive &&
  73358. + (microframe_schedule || hcd->non_periodic_channels <
  73359. + num_channels - hcd->periodic_channels) &&
  73360. + !DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  73361. +
  73362. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  73363. + /*
  73364. + * Check to see if this is a NAK'd retransmit, in which case ignore for retransmission
  73365. + * we hold off on bulk retransmissions to reduce NAK interrupt overhead for full-speed
  73366. + * cheeky devices that just hold off using NAKs
  73367. + */
  73368. + if (nak_holdoff && qh->do_split) {
  73369. + if (qh->nak_frame != 0xffff) {
  73370. + uint16_t next_frame = dwc_frame_num_inc(qh->nak_frame, (qh->ep_type == UE_BULK) ? nak_holdoff : 8);
  73371. + uint16_t frame = dwc_otg_hcd_get_frame_number(hcd);
  73372. + if (dwc_frame_num_le(frame, next_frame)) {
  73373. + if(dwc_frame_num_le(next_frame, hcd->fiq_state->next_sched_frame)) {
  73374. + hcd->fiq_state->next_sched_frame = next_frame;
  73375. + }
  73376. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  73377. + continue;
  73378. + } else {
  73379. + qh->nak_frame = 0xFFFF;
  73380. + }
  73381. + }
  73382. + }
  73383. +
  73384. + if (microframe_schedule) {
  73385. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  73386. + if (hcd->available_host_channels < 1) {
  73387. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  73388. + break;
  73389. + }
  73390. + hcd->available_host_channels--;
  73391. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  73392. +#ifdef DEBUG_HOST_CHANNELS
  73393. + last_sel_trans_num_nonper_scheduled++;
  73394. +#endif /* DEBUG_HOST_CHANNELS */
  73395. + }
  73396. +
  73397. + assign_and_init_hc(hcd, qh);
  73398. +
  73399. + /*
  73400. + * Move the QH from the non-periodic inactive schedule to the
  73401. + * non-periodic active schedule.
  73402. + */
  73403. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  73404. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  73405. + DWC_LIST_MOVE_HEAD(&hcd->non_periodic_sched_active,
  73406. + &qh->qh_list_entry);
  73407. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  73408. +
  73409. +
  73410. + if (!microframe_schedule)
  73411. + hcd->non_periodic_channels++;
  73412. + }
  73413. + /* we moved a non-periodic QH to the active schedule. If the inactive queue is empty,
  73414. + * stop the FIQ from kicking us. We could potentially still have elements here if we
  73415. + * ran out of host channels.
  73416. + */
  73417. + if (fiq_enable) {
  73418. + if (DWC_LIST_EMPTY(&hcd->non_periodic_sched_inactive)) {
  73419. + hcd->fiq_state->kick_np_queues = 0;
  73420. + } else {
  73421. + /* For each entry remaining in the NP inactive queue,
  73422. + * if this a NAK'd retransmit then don't set the kick flag.
  73423. + */
  73424. + if(nak_holdoff) {
  73425. + DWC_LIST_FOREACH(qh_ptr, &hcd->non_periodic_sched_inactive) {
  73426. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  73427. + if (qh->nak_frame == 0xFFFF) {
  73428. + hcd->fiq_state->kick_np_queues = 1;
  73429. + }
  73430. + }
  73431. + }
  73432. + }
  73433. + }
  73434. + if(!DWC_LIST_EMPTY(&hcd->periodic_sched_assigned))
  73435. + ret_val |= DWC_OTG_TRANSACTION_PERIODIC;
  73436. +
  73437. + if(!DWC_LIST_EMPTY(&hcd->non_periodic_sched_active))
  73438. + ret_val |= DWC_OTG_TRANSACTION_NON_PERIODIC;
  73439. +
  73440. +
  73441. +#ifdef DEBUG_HOST_CHANNELS
  73442. + last_sel_trans_num_avail_hc_at_end = hcd->available_host_channels;
  73443. +#endif /* DEBUG_HOST_CHANNELS */
  73444. + return ret_val;
  73445. +}
  73446. +
  73447. +/**
  73448. + * Attempts to queue a single transaction request for a host channel
  73449. + * associated with either a periodic or non-periodic transfer. This function
  73450. + * assumes that there is space available in the appropriate request queue. For
  73451. + * an OUT transfer or SETUP transaction in Slave mode, it checks whether space
  73452. + * is available in the appropriate Tx FIFO.
  73453. + *
  73454. + * @param hcd The HCD state structure.
  73455. + * @param hc Host channel descriptor associated with either a periodic or
  73456. + * non-periodic transfer.
  73457. + * @param fifo_dwords_avail Number of DWORDs available in the periodic Tx
  73458. + * FIFO for periodic transfers or the non-periodic Tx FIFO for non-periodic
  73459. + * transfers.
  73460. + *
  73461. + * @return 1 if a request is queued and more requests may be needed to
  73462. + * complete the transfer, 0 if no more requests are required for this
  73463. + * transfer, -1 if there is insufficient space in the Tx FIFO.
  73464. + */
  73465. +static int queue_transaction(dwc_otg_hcd_t * hcd,
  73466. + dwc_hc_t * hc, uint16_t fifo_dwords_avail)
  73467. +{
  73468. + int retval;
  73469. +
  73470. + if (hcd->core_if->dma_enable) {
  73471. + if (hcd->core_if->dma_desc_enable) {
  73472. + if (!hc->xfer_started
  73473. + || (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)) {
  73474. + dwc_otg_hcd_start_xfer_ddma(hcd, hc->qh);
  73475. + hc->qh->ping_state = 0;
  73476. + }
  73477. + } else if (!hc->xfer_started) {
  73478. + if (fiq_fsm_enable && hc->error_state) {
  73479. + hcd->fiq_state->channel[hc->hc_num].nr_errors =
  73480. + DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list)->error_count;
  73481. + hcd->fiq_state->channel[hc->hc_num].fsm =
  73482. + FIQ_PASSTHROUGH_ERRORSTATE;
  73483. + }
  73484. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  73485. + hc->qh->ping_state = 0;
  73486. + }
  73487. + retval = 0;
  73488. + } else if (hc->halt_pending) {
  73489. + /* Don't queue a request if the channel has been halted. */
  73490. + retval = 0;
  73491. + } else if (hc->halt_on_queue) {
  73492. + dwc_otg_hc_halt(hcd->core_if, hc, hc->halt_status);
  73493. + retval = 0;
  73494. + } else if (hc->do_ping) {
  73495. + if (!hc->xfer_started) {
  73496. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  73497. + }
  73498. + retval = 0;
  73499. + } else if (!hc->ep_is_in || hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
  73500. + if ((fifo_dwords_avail * 4) >= hc->max_packet) {
  73501. + if (!hc->xfer_started) {
  73502. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  73503. + retval = 1;
  73504. + } else {
  73505. + retval =
  73506. + dwc_otg_hc_continue_transfer(hcd->core_if,
  73507. + hc);
  73508. + }
  73509. + } else {
  73510. + retval = -1;
  73511. + }
  73512. + } else {
  73513. + if (!hc->xfer_started) {
  73514. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  73515. + retval = 1;
  73516. + } else {
  73517. + retval = dwc_otg_hc_continue_transfer(hcd->core_if, hc);
  73518. + }
  73519. + }
  73520. +
  73521. + return retval;
  73522. +}
  73523. +
  73524. +/**
  73525. + * Processes periodic channels for the next frame and queues transactions for
  73526. + * these channels to the DWC_otg controller. After queueing transactions, the
  73527. + * Periodic Tx FIFO Empty interrupt is enabled if there are more transactions
  73528. + * to queue as Periodic Tx FIFO or request queue space becomes available.
  73529. + * Otherwise, the Periodic Tx FIFO Empty interrupt is disabled.
  73530. + */
  73531. +static void process_periodic_channels(dwc_otg_hcd_t * hcd)
  73532. +{
  73533. + hptxsts_data_t tx_status;
  73534. + dwc_list_link_t *qh_ptr;
  73535. + dwc_otg_qh_t *qh;
  73536. + int status = 0;
  73537. + int no_queue_space = 0;
  73538. + int no_fifo_space = 0;
  73539. +
  73540. + dwc_otg_host_global_regs_t *host_regs;
  73541. + host_regs = hcd->core_if->host_if->host_global_regs;
  73542. +
  73543. + DWC_DEBUGPL(DBG_HCDV, "Queue periodic transactions\n");
  73544. +#ifdef DEBUG
  73545. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  73546. + DWC_DEBUGPL(DBG_HCDV,
  73547. + " P Tx Req Queue Space Avail (before queue): %d\n",
  73548. + tx_status.b.ptxqspcavail);
  73549. + DWC_DEBUGPL(DBG_HCDV, " P Tx FIFO Space Avail (before queue): %d\n",
  73550. + tx_status.b.ptxfspcavail);
  73551. +#endif
  73552. +
  73553. + qh_ptr = hcd->periodic_sched_assigned.next;
  73554. + while (qh_ptr != &hcd->periodic_sched_assigned) {
  73555. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  73556. + if (tx_status.b.ptxqspcavail == 0) {
  73557. + no_queue_space = 1;
  73558. + break;
  73559. + }
  73560. +
  73561. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  73562. +
  73563. + // Do not send a split start transaction any later than frame .6
  73564. + // Note, we have to schedule a periodic in .5 to make it go in .6
  73565. + if(fiq_fsm_enable && qh->do_split && ((dwc_otg_hcd_get_frame_number(hcd) + 1) & 7) > 6)
  73566. + {
  73567. + qh_ptr = qh_ptr->next;
  73568. + hcd->fiq_state->next_sched_frame = dwc_otg_hcd_get_frame_number(hcd) | 7;
  73569. + continue;
  73570. + }
  73571. +
  73572. + if (fiq_fsm_enable && fiq_fsm_transaction_suitable(qh)) {
  73573. + if (qh->do_split)
  73574. + fiq_fsm_queue_split_transaction(hcd, qh);
  73575. + else
  73576. + fiq_fsm_queue_isoc_transaction(hcd, qh);
  73577. + } else {
  73578. +
  73579. + /*
  73580. + * Set a flag if we're queueing high-bandwidth in slave mode.
  73581. + * The flag prevents any halts to get into the request queue in
  73582. + * the middle of multiple high-bandwidth packets getting queued.
  73583. + */
  73584. + if (!hcd->core_if->dma_enable && qh->channel->multi_count > 1) {
  73585. + hcd->core_if->queuing_high_bandwidth = 1;
  73586. + }
  73587. + status = queue_transaction(hcd, qh->channel,
  73588. + tx_status.b.ptxfspcavail);
  73589. + if (status < 0) {
  73590. + no_fifo_space = 1;
  73591. + break;
  73592. + }
  73593. + }
  73594. +
  73595. + /*
  73596. + * In Slave mode, stay on the current transfer until there is
  73597. + * nothing more to do or the high-bandwidth request count is
  73598. + * reached. In DMA mode, only need to queue one request. The
  73599. + * controller automatically handles multiple packets for
  73600. + * high-bandwidth transfers.
  73601. + */
  73602. + if (hcd->core_if->dma_enable || status == 0 ||
  73603. + qh->channel->requests == qh->channel->multi_count) {
  73604. + qh_ptr = qh_ptr->next;
  73605. + /*
  73606. + * Move the QH from the periodic assigned schedule to
  73607. + * the periodic queued schedule.
  73608. + */
  73609. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_queued,
  73610. + &qh->qh_list_entry);
  73611. +
  73612. + /* done queuing high bandwidth */
  73613. + hcd->core_if->queuing_high_bandwidth = 0;
  73614. + }
  73615. + }
  73616. +
  73617. + if (!hcd->core_if->dma_enable) {
  73618. + dwc_otg_core_global_regs_t *global_regs;
  73619. + gintmsk_data_t intr_mask = {.d32 = 0 };
  73620. +
  73621. + global_regs = hcd->core_if->core_global_regs;
  73622. + intr_mask.b.ptxfempty = 1;
  73623. +#ifdef DEBUG
  73624. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  73625. + DWC_DEBUGPL(DBG_HCDV,
  73626. + " P Tx Req Queue Space Avail (after queue): %d\n",
  73627. + tx_status.b.ptxqspcavail);
  73628. + DWC_DEBUGPL(DBG_HCDV,
  73629. + " P Tx FIFO Space Avail (after queue): %d\n",
  73630. + tx_status.b.ptxfspcavail);
  73631. +#endif
  73632. + if (!DWC_LIST_EMPTY(&hcd->periodic_sched_assigned) ||
  73633. + no_queue_space || no_fifo_space) {
  73634. + /*
  73635. + * May need to queue more transactions as the request
  73636. + * queue or Tx FIFO empties. Enable the periodic Tx
  73637. + * FIFO empty interrupt. (Always use the half-empty
  73638. + * level to ensure that new requests are loaded as
  73639. + * soon as possible.)
  73640. + */
  73641. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0,
  73642. + intr_mask.d32);
  73643. + } else {
  73644. + /*
  73645. + * Disable the Tx FIFO empty interrupt since there are
  73646. + * no more transactions that need to be queued right
  73647. + * now. This function is called from interrupt
  73648. + * handlers to queue more transactions as transfer
  73649. + * states change.
  73650. + */
  73651. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32,
  73652. + 0);
  73653. + }
  73654. + }
  73655. +}
  73656. +
  73657. +/**
  73658. + * Processes active non-periodic channels and queues transactions for these
  73659. + * channels to the DWC_otg controller. After queueing transactions, the NP Tx
  73660. + * FIFO Empty interrupt is enabled if there are more transactions to queue as
  73661. + * NP Tx FIFO or request queue space becomes available. Otherwise, the NP Tx
  73662. + * FIFO Empty interrupt is disabled.
  73663. + */
  73664. +static void process_non_periodic_channels(dwc_otg_hcd_t * hcd)
  73665. +{
  73666. + gnptxsts_data_t tx_status;
  73667. + dwc_list_link_t *orig_qh_ptr;
  73668. + dwc_otg_qh_t *qh;
  73669. + int status;
  73670. + int no_queue_space = 0;
  73671. + int no_fifo_space = 0;
  73672. + int more_to_do = 0;
  73673. +
  73674. + dwc_otg_core_global_regs_t *global_regs =
  73675. + hcd->core_if->core_global_regs;
  73676. +
  73677. + DWC_DEBUGPL(DBG_HCDV, "Queue non-periodic transactions\n");
  73678. +#ifdef DEBUG
  73679. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  73680. + DWC_DEBUGPL(DBG_HCDV,
  73681. + " NP Tx Req Queue Space Avail (before queue): %d\n",
  73682. + tx_status.b.nptxqspcavail);
  73683. + DWC_DEBUGPL(DBG_HCDV, " NP Tx FIFO Space Avail (before queue): %d\n",
  73684. + tx_status.b.nptxfspcavail);
  73685. +#endif
  73686. + /*
  73687. + * Keep track of the starting point. Skip over the start-of-list
  73688. + * entry.
  73689. + */
  73690. + if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
  73691. + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
  73692. + }
  73693. + orig_qh_ptr = hcd->non_periodic_qh_ptr;
  73694. +
  73695. + /*
  73696. + * Process once through the active list or until no more space is
  73697. + * available in the request queue or the Tx FIFO.
  73698. + */
  73699. + do {
  73700. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  73701. + if (!hcd->core_if->dma_enable && tx_status.b.nptxqspcavail == 0) {
  73702. + no_queue_space = 1;
  73703. + break;
  73704. + }
  73705. +
  73706. + qh = DWC_LIST_ENTRY(hcd->non_periodic_qh_ptr, dwc_otg_qh_t,
  73707. + qh_list_entry);
  73708. +
  73709. + if(fiq_fsm_enable && fiq_fsm_transaction_suitable(qh)) {
  73710. + fiq_fsm_queue_split_transaction(hcd, qh);
  73711. + } else {
  73712. + status = queue_transaction(hcd, qh->channel,
  73713. + tx_status.b.nptxfspcavail);
  73714. +
  73715. + if (status > 0) {
  73716. + more_to_do = 1;
  73717. + } else if (status < 0) {
  73718. + no_fifo_space = 1;
  73719. + break;
  73720. + }
  73721. + }
  73722. + /* Advance to next QH, skipping start-of-list entry. */
  73723. + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
  73724. + if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
  73725. + hcd->non_periodic_qh_ptr =
  73726. + hcd->non_periodic_qh_ptr->next;
  73727. + }
  73728. +
  73729. + } while (hcd->non_periodic_qh_ptr != orig_qh_ptr);
  73730. +
  73731. + if (!hcd->core_if->dma_enable) {
  73732. + gintmsk_data_t intr_mask = {.d32 = 0 };
  73733. + intr_mask.b.nptxfempty = 1;
  73734. +
  73735. +#ifdef DEBUG
  73736. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  73737. + DWC_DEBUGPL(DBG_HCDV,
  73738. + " NP Tx Req Queue Space Avail (after queue): %d\n",
  73739. + tx_status.b.nptxqspcavail);
  73740. + DWC_DEBUGPL(DBG_HCDV,
  73741. + " NP Tx FIFO Space Avail (after queue): %d\n",
  73742. + tx_status.b.nptxfspcavail);
  73743. +#endif
  73744. + if (more_to_do || no_queue_space || no_fifo_space) {
  73745. + /*
  73746. + * May need to queue more transactions as the request
  73747. + * queue or Tx FIFO empties. Enable the non-periodic
  73748. + * Tx FIFO empty interrupt. (Always use the half-empty
  73749. + * level to ensure that new requests are loaded as
  73750. + * soon as possible.)
  73751. + */
  73752. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0,
  73753. + intr_mask.d32);
  73754. + } else {
  73755. + /*
  73756. + * Disable the Tx FIFO empty interrupt since there are
  73757. + * no more transactions that need to be queued right
  73758. + * now. This function is called from interrupt
  73759. + * handlers to queue more transactions as transfer
  73760. + * states change.
  73761. + */
  73762. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32,
  73763. + 0);
  73764. + }
  73765. + }
  73766. +}
  73767. +
  73768. +/**
  73769. + * This function processes the currently active host channels and queues
  73770. + * transactions for these channels to the DWC_otg controller. It is called
  73771. + * from HCD interrupt handler functions.
  73772. + *
  73773. + * @param hcd The HCD state structure.
  73774. + * @param tr_type The type(s) of transactions to queue (non-periodic,
  73775. + * periodic, or both).
  73776. + */
  73777. +void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t * hcd,
  73778. + dwc_otg_transaction_type_e tr_type)
  73779. +{
  73780. +#ifdef DEBUG_SOF
  73781. + DWC_DEBUGPL(DBG_HCD, "Queue Transactions\n");
  73782. +#endif
  73783. + /* Process host channels associated with periodic transfers. */
  73784. + if ((tr_type == DWC_OTG_TRANSACTION_PERIODIC ||
  73785. + tr_type == DWC_OTG_TRANSACTION_ALL) &&
  73786. + !DWC_LIST_EMPTY(&hcd->periodic_sched_assigned)) {
  73787. +
  73788. + process_periodic_channels(hcd);
  73789. + }
  73790. +
  73791. + /* Process host channels associated with non-periodic transfers. */
  73792. + if (tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC ||
  73793. + tr_type == DWC_OTG_TRANSACTION_ALL) {
  73794. + if (!DWC_LIST_EMPTY(&hcd->non_periodic_sched_active)) {
  73795. + process_non_periodic_channels(hcd);
  73796. + } else {
  73797. + /*
  73798. + * Ensure NP Tx FIFO empty interrupt is disabled when
  73799. + * there are no non-periodic transfers to process.
  73800. + */
  73801. + gintmsk_data_t gintmsk = {.d32 = 0 };
  73802. + gintmsk.b.nptxfempty = 1;
  73803. + DWC_MODIFY_REG32(&hcd->core_if->
  73804. + core_global_regs->gintmsk, gintmsk.d32,
  73805. + 0);
  73806. + }
  73807. + }
  73808. +}
  73809. +
  73810. +#ifdef DWC_HS_ELECT_TST
  73811. +/*
  73812. + * Quick and dirty hack to implement the HS Electrical Test
  73813. + * SINGLE_STEP_GET_DEVICE_DESCRIPTOR feature.
  73814. + *
  73815. + * This code was copied from our userspace app "hset". It sends a
  73816. + * Get Device Descriptor control sequence in two parts, first the
  73817. + * Setup packet by itself, followed some time later by the In and
  73818. + * Ack packets. Rather than trying to figure out how to add this
  73819. + * functionality to the normal driver code, we just hijack the
  73820. + * hardware, using these two function to drive the hardware
  73821. + * directly.
  73822. + */
  73823. +
  73824. +static dwc_otg_core_global_regs_t *global_regs;
  73825. +static dwc_otg_host_global_regs_t *hc_global_regs;
  73826. +static dwc_otg_hc_regs_t *hc_regs;
  73827. +static uint32_t *data_fifo;
  73828. +
  73829. +static void do_setup(void)
  73830. +{
  73831. + gintsts_data_t gintsts;
  73832. + hctsiz_data_t hctsiz;
  73833. + hcchar_data_t hcchar;
  73834. + haint_data_t haint;
  73835. + hcint_data_t hcint;
  73836. +
  73837. + /* Enable HAINTs */
  73838. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0001);
  73839. +
  73840. + /* Enable HCINTs */
  73841. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x04a3);
  73842. +
  73843. + /* Read GINTSTS */
  73844. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73845. +
  73846. + /* Read HAINT */
  73847. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  73848. +
  73849. + /* Read HCINT */
  73850. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  73851. +
  73852. + /* Read HCCHAR */
  73853. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73854. +
  73855. + /* Clear HCINT */
  73856. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  73857. +
  73858. + /* Clear HAINT */
  73859. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  73860. +
  73861. + /* Clear GINTSTS */
  73862. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  73863. +
  73864. + /* Read GINTSTS */
  73865. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73866. +
  73867. + /*
  73868. + * Send Setup packet (Get Device Descriptor)
  73869. + */
  73870. +
  73871. + /* Make sure channel is disabled */
  73872. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73873. + if (hcchar.b.chen) {
  73874. + hcchar.b.chdis = 1;
  73875. +// hcchar.b.chen = 1;
  73876. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  73877. + //sleep(1);
  73878. + dwc_mdelay(1000);
  73879. +
  73880. + /* Read GINTSTS */
  73881. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73882. +
  73883. + /* Read HAINT */
  73884. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  73885. +
  73886. + /* Read HCINT */
  73887. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  73888. +
  73889. + /* Read HCCHAR */
  73890. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73891. +
  73892. + /* Clear HCINT */
  73893. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  73894. +
  73895. + /* Clear HAINT */
  73896. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  73897. +
  73898. + /* Clear GINTSTS */
  73899. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  73900. +
  73901. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73902. + }
  73903. +
  73904. + /* Set HCTSIZ */
  73905. + hctsiz.d32 = 0;
  73906. + hctsiz.b.xfersize = 8;
  73907. + hctsiz.b.pktcnt = 1;
  73908. + hctsiz.b.pid = DWC_OTG_HC_PID_SETUP;
  73909. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  73910. +
  73911. + /* Set HCCHAR */
  73912. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73913. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  73914. + hcchar.b.epdir = 0;
  73915. + hcchar.b.epnum = 0;
  73916. + hcchar.b.mps = 8;
  73917. + hcchar.b.chen = 1;
  73918. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  73919. +
  73920. + /* Fill FIFO with Setup data for Get Device Descriptor */
  73921. + data_fifo = (uint32_t *) ((char *)global_regs + 0x1000);
  73922. + DWC_WRITE_REG32(data_fifo++, 0x01000680);
  73923. + DWC_WRITE_REG32(data_fifo++, 0x00080000);
  73924. +
  73925. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73926. +
  73927. + /* Wait for host channel interrupt */
  73928. + do {
  73929. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73930. + } while (gintsts.b.hcintr == 0);
  73931. +
  73932. + /* Disable HCINTs */
  73933. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x0000);
  73934. +
  73935. + /* Disable HAINTs */
  73936. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0000);
  73937. +
  73938. + /* Read HAINT */
  73939. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  73940. +
  73941. + /* Read HCINT */
  73942. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  73943. +
  73944. + /* Read HCCHAR */
  73945. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73946. +
  73947. + /* Clear HCINT */
  73948. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  73949. +
  73950. + /* Clear HAINT */
  73951. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  73952. +
  73953. + /* Clear GINTSTS */
  73954. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  73955. +
  73956. + /* Read GINTSTS */
  73957. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73958. +}
  73959. +
  73960. +static void do_in_ack(void)
  73961. +{
  73962. + gintsts_data_t gintsts;
  73963. + hctsiz_data_t hctsiz;
  73964. + hcchar_data_t hcchar;
  73965. + haint_data_t haint;
  73966. + hcint_data_t hcint;
  73967. + host_grxsts_data_t grxsts;
  73968. +
  73969. + /* Enable HAINTs */
  73970. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0001);
  73971. +
  73972. + /* Enable HCINTs */
  73973. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x04a3);
  73974. +
  73975. + /* Read GINTSTS */
  73976. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73977. +
  73978. + /* Read HAINT */
  73979. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  73980. +
  73981. + /* Read HCINT */
  73982. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  73983. +
  73984. + /* Read HCCHAR */
  73985. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73986. +
  73987. + /* Clear HCINT */
  73988. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  73989. +
  73990. + /* Clear HAINT */
  73991. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  73992. +
  73993. + /* Clear GINTSTS */
  73994. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  73995. +
  73996. + /* Read GINTSTS */
  73997. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73998. +
  73999. + /*
  74000. + * Receive Control In packet
  74001. + */
  74002. +
  74003. + /* Make sure channel is disabled */
  74004. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  74005. + if (hcchar.b.chen) {
  74006. + hcchar.b.chdis = 1;
  74007. + hcchar.b.chen = 1;
  74008. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  74009. + //sleep(1);
  74010. + dwc_mdelay(1000);
  74011. +
  74012. + /* Read GINTSTS */
  74013. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  74014. +
  74015. + /* Read HAINT */
  74016. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  74017. +
  74018. + /* Read HCINT */
  74019. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  74020. +
  74021. + /* Read HCCHAR */
  74022. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  74023. +
  74024. + /* Clear HCINT */
  74025. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  74026. +
  74027. + /* Clear HAINT */
  74028. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  74029. +
  74030. + /* Clear GINTSTS */
  74031. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  74032. +
  74033. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  74034. + }
  74035. +
  74036. + /* Set HCTSIZ */
  74037. + hctsiz.d32 = 0;
  74038. + hctsiz.b.xfersize = 8;
  74039. + hctsiz.b.pktcnt = 1;
  74040. + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
  74041. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  74042. +
  74043. + /* Set HCCHAR */
  74044. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  74045. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  74046. + hcchar.b.epdir = 1;
  74047. + hcchar.b.epnum = 0;
  74048. + hcchar.b.mps = 8;
  74049. + hcchar.b.chen = 1;
  74050. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  74051. +
  74052. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  74053. +
  74054. + /* Wait for receive status queue interrupt */
  74055. + do {
  74056. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  74057. + } while (gintsts.b.rxstsqlvl == 0);
  74058. +
  74059. + /* Read RXSTS */
  74060. + grxsts.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  74061. +
  74062. + /* Clear RXSTSQLVL in GINTSTS */
  74063. + gintsts.d32 = 0;
  74064. + gintsts.b.rxstsqlvl = 1;
  74065. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  74066. +
  74067. + switch (grxsts.b.pktsts) {
  74068. + case DWC_GRXSTS_PKTSTS_IN:
  74069. + /* Read the data into the host buffer */
  74070. + if (grxsts.b.bcnt > 0) {
  74071. + int i;
  74072. + int word_count = (grxsts.b.bcnt + 3) / 4;
  74073. +
  74074. + data_fifo = (uint32_t *) ((char *)global_regs + 0x1000);
  74075. +
  74076. + for (i = 0; i < word_count; i++) {
  74077. + (void)DWC_READ_REG32(data_fifo++);
  74078. + }
  74079. + }
  74080. + break;
  74081. +
  74082. + default:
  74083. + break;
  74084. + }
  74085. +
  74086. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  74087. +
  74088. + /* Wait for receive status queue interrupt */
  74089. + do {
  74090. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  74091. + } while (gintsts.b.rxstsqlvl == 0);
  74092. +
  74093. + /* Read RXSTS */
  74094. + grxsts.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  74095. +
  74096. + /* Clear RXSTSQLVL in GINTSTS */
  74097. + gintsts.d32 = 0;
  74098. + gintsts.b.rxstsqlvl = 1;
  74099. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  74100. +
  74101. + switch (grxsts.b.pktsts) {
  74102. + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
  74103. + break;
  74104. +
  74105. + default:
  74106. + break;
  74107. + }
  74108. +
  74109. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  74110. +
  74111. + /* Wait for host channel interrupt */
  74112. + do {
  74113. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  74114. + } while (gintsts.b.hcintr == 0);
  74115. +
  74116. + /* Read HAINT */
  74117. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  74118. +
  74119. + /* Read HCINT */
  74120. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  74121. +
  74122. + /* Read HCCHAR */
  74123. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  74124. +
  74125. + /* Clear HCINT */
  74126. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  74127. +
  74128. + /* Clear HAINT */
  74129. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  74130. +
  74131. + /* Clear GINTSTS */
  74132. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  74133. +
  74134. + /* Read GINTSTS */
  74135. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  74136. +
  74137. +// usleep(100000);
  74138. +// mdelay(100);
  74139. + dwc_mdelay(1);
  74140. +
  74141. + /*
  74142. + * Send handshake packet
  74143. + */
  74144. +
  74145. + /* Read HAINT */
  74146. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  74147. +
  74148. + /* Read HCINT */
  74149. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  74150. +
  74151. + /* Read HCCHAR */
  74152. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  74153. +
  74154. + /* Clear HCINT */
  74155. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  74156. +
  74157. + /* Clear HAINT */
  74158. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  74159. +
  74160. + /* Clear GINTSTS */
  74161. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  74162. +
  74163. + /* Read GINTSTS */
  74164. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  74165. +
  74166. + /* Make sure channel is disabled */
  74167. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  74168. + if (hcchar.b.chen) {
  74169. + hcchar.b.chdis = 1;
  74170. + hcchar.b.chen = 1;
  74171. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  74172. + //sleep(1);
  74173. + dwc_mdelay(1000);
  74174. +
  74175. + /* Read GINTSTS */
  74176. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  74177. +
  74178. + /* Read HAINT */
  74179. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  74180. +
  74181. + /* Read HCINT */
  74182. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  74183. +
  74184. + /* Read HCCHAR */
  74185. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  74186. +
  74187. + /* Clear HCINT */
  74188. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  74189. +
  74190. + /* Clear HAINT */
  74191. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  74192. +
  74193. + /* Clear GINTSTS */
  74194. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  74195. +
  74196. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  74197. + }
  74198. +
  74199. + /* Set HCTSIZ */
  74200. + hctsiz.d32 = 0;
  74201. + hctsiz.b.xfersize = 0;
  74202. + hctsiz.b.pktcnt = 1;
  74203. + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
  74204. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  74205. +
  74206. + /* Set HCCHAR */
  74207. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  74208. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  74209. + hcchar.b.epdir = 0;
  74210. + hcchar.b.epnum = 0;
  74211. + hcchar.b.mps = 8;
  74212. + hcchar.b.chen = 1;
  74213. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  74214. +
  74215. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  74216. +
  74217. + /* Wait for host channel interrupt */
  74218. + do {
  74219. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  74220. + } while (gintsts.b.hcintr == 0);
  74221. +
  74222. + /* Disable HCINTs */
  74223. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x0000);
  74224. +
  74225. + /* Disable HAINTs */
  74226. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0000);
  74227. +
  74228. + /* Read HAINT */
  74229. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  74230. +
  74231. + /* Read HCINT */
  74232. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  74233. +
  74234. + /* Read HCCHAR */
  74235. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  74236. +
  74237. + /* Clear HCINT */
  74238. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  74239. +
  74240. + /* Clear HAINT */
  74241. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  74242. +
  74243. + /* Clear GINTSTS */
  74244. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  74245. +
  74246. + /* Read GINTSTS */
  74247. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  74248. +}
  74249. +#endif
  74250. +
  74251. +/** Handles hub class-specific requests. */
  74252. +int dwc_otg_hcd_hub_control(dwc_otg_hcd_t * dwc_otg_hcd,
  74253. + uint16_t typeReq,
  74254. + uint16_t wValue,
  74255. + uint16_t wIndex, uint8_t * buf, uint16_t wLength)
  74256. +{
  74257. + int retval = 0;
  74258. +
  74259. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  74260. + usb_hub_descriptor_t *hub_desc;
  74261. + hprt0_data_t hprt0 = {.d32 = 0 };
  74262. +
  74263. + uint32_t port_status;
  74264. +
  74265. + switch (typeReq) {
  74266. + case UCR_CLEAR_HUB_FEATURE:
  74267. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  74268. + "ClearHubFeature 0x%x\n", wValue);
  74269. + switch (wValue) {
  74270. + case UHF_C_HUB_LOCAL_POWER:
  74271. + case UHF_C_HUB_OVER_CURRENT:
  74272. + /* Nothing required here */
  74273. + break;
  74274. + default:
  74275. + retval = -DWC_E_INVALID;
  74276. + DWC_ERROR("DWC OTG HCD - "
  74277. + "ClearHubFeature request %xh unknown\n",
  74278. + wValue);
  74279. + }
  74280. + break;
  74281. + case UCR_CLEAR_PORT_FEATURE:
  74282. +#ifdef CONFIG_USB_DWC_OTG_LPM
  74283. + if (wValue != UHF_PORT_L1)
  74284. +#endif
  74285. + if (!wIndex || wIndex > 1)
  74286. + goto error;
  74287. +
  74288. + switch (wValue) {
  74289. + case UHF_PORT_ENABLE:
  74290. + DWC_DEBUGPL(DBG_ANY, "DWC OTG HCD HUB CONTROL - "
  74291. + "ClearPortFeature USB_PORT_FEAT_ENABLE\n");
  74292. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  74293. + hprt0.b.prtena = 1;
  74294. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  74295. + break;
  74296. + case UHF_PORT_SUSPEND:
  74297. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  74298. + "ClearPortFeature USB_PORT_FEAT_SUSPEND\n");
  74299. +
  74300. + if (core_if->power_down == 2) {
  74301. + dwc_otg_host_hibernation_restore(core_if, 0, 0);
  74302. + } else {
  74303. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  74304. + dwc_mdelay(5);
  74305. +
  74306. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  74307. + hprt0.b.prtres = 1;
  74308. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  74309. + hprt0.b.prtsusp = 0;
  74310. + /* Clear Resume bit */
  74311. + dwc_mdelay(100);
  74312. + hprt0.b.prtres = 0;
  74313. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  74314. + }
  74315. + break;
  74316. +#ifdef CONFIG_USB_DWC_OTG_LPM
  74317. + case UHF_PORT_L1:
  74318. + {
  74319. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  74320. + glpmcfg_data_t lpmcfg = {.d32 = 0 };
  74321. +
  74322. + lpmcfg.d32 =
  74323. + DWC_READ_REG32(&core_if->
  74324. + core_global_regs->glpmcfg);
  74325. + lpmcfg.b.en_utmi_sleep = 0;
  74326. + lpmcfg.b.hird_thres &= (~(1 << 4));
  74327. + lpmcfg.b.prt_sleep_sts = 1;
  74328. + DWC_WRITE_REG32(&core_if->
  74329. + core_global_regs->glpmcfg,
  74330. + lpmcfg.d32);
  74331. +
  74332. + /* Clear Enbl_L1Gating bit. */
  74333. + pcgcctl.b.enbl_sleep_gating = 1;
  74334. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32,
  74335. + 0);
  74336. +
  74337. + dwc_mdelay(5);
  74338. +
  74339. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  74340. + hprt0.b.prtres = 1;
  74341. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  74342. + hprt0.d32);
  74343. + /* This bit will be cleared in wakeup interrupt handle */
  74344. + break;
  74345. + }
  74346. +#endif
  74347. + case UHF_PORT_POWER:
  74348. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  74349. + "ClearPortFeature USB_PORT_FEAT_POWER\n");
  74350. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  74351. + hprt0.b.prtpwr = 0;
  74352. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  74353. + break;
  74354. + case UHF_PORT_INDICATOR:
  74355. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  74356. + "ClearPortFeature USB_PORT_FEAT_INDICATOR\n");
  74357. + /* Port inidicator not supported */
  74358. + break;
  74359. + case UHF_C_PORT_CONNECTION:
  74360. + /* Clears drivers internal connect status change
  74361. + * flag */
  74362. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  74363. + "ClearPortFeature USB_PORT_FEAT_C_CONNECTION\n");
  74364. + dwc_otg_hcd->flags.b.port_connect_status_change = 0;
  74365. + break;
  74366. + case UHF_C_PORT_RESET:
  74367. + /* Clears the driver's internal Port Reset Change
  74368. + * flag */
  74369. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  74370. + "ClearPortFeature USB_PORT_FEAT_C_RESET\n");
  74371. + dwc_otg_hcd->flags.b.port_reset_change = 0;
  74372. + break;
  74373. + case UHF_C_PORT_ENABLE:
  74374. + /* Clears the driver's internal Port
  74375. + * Enable/Disable Change flag */
  74376. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  74377. + "ClearPortFeature USB_PORT_FEAT_C_ENABLE\n");
  74378. + dwc_otg_hcd->flags.b.port_enable_change = 0;
  74379. + break;
  74380. + case UHF_C_PORT_SUSPEND:
  74381. + /* Clears the driver's internal Port Suspend
  74382. + * Change flag, which is set when resume signaling on
  74383. + * the host port is complete */
  74384. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  74385. + "ClearPortFeature USB_PORT_FEAT_C_SUSPEND\n");
  74386. + dwc_otg_hcd->flags.b.port_suspend_change = 0;
  74387. + break;
  74388. +#ifdef CONFIG_USB_DWC_OTG_LPM
  74389. + case UHF_C_PORT_L1:
  74390. + dwc_otg_hcd->flags.b.port_l1_change = 0;
  74391. + break;
  74392. +#endif
  74393. + case UHF_C_PORT_OVER_CURRENT:
  74394. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  74395. + "ClearPortFeature USB_PORT_FEAT_C_OVER_CURRENT\n");
  74396. + dwc_otg_hcd->flags.b.port_over_current_change = 0;
  74397. + break;
  74398. + default:
  74399. + retval = -DWC_E_INVALID;
  74400. + DWC_ERROR("DWC OTG HCD - "
  74401. + "ClearPortFeature request %xh "
  74402. + "unknown or unsupported\n", wValue);
  74403. + }
  74404. + break;
  74405. + case UCR_GET_HUB_DESCRIPTOR:
  74406. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  74407. + "GetHubDescriptor\n");
  74408. + hub_desc = (usb_hub_descriptor_t *) buf;
  74409. + hub_desc->bDescLength = 9;
  74410. + hub_desc->bDescriptorType = 0x29;
  74411. + hub_desc->bNbrPorts = 1;
  74412. + USETW(hub_desc->wHubCharacteristics, 0x08);
  74413. + hub_desc->bPwrOn2PwrGood = 1;
  74414. + hub_desc->bHubContrCurrent = 0;
  74415. + hub_desc->DeviceRemovable[0] = 0;
  74416. + hub_desc->DeviceRemovable[1] = 0xff;
  74417. + break;
  74418. + case UCR_GET_HUB_STATUS:
  74419. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  74420. + "GetHubStatus\n");
  74421. + DWC_MEMSET(buf, 0, 4);
  74422. + break;
  74423. + case UCR_GET_PORT_STATUS:
  74424. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  74425. + "GetPortStatus wIndex = 0x%04x FLAGS=0x%08x\n",
  74426. + wIndex, dwc_otg_hcd->flags.d32);
  74427. + if (!wIndex || wIndex > 1)
  74428. + goto error;
  74429. +
  74430. + port_status = 0;
  74431. +
  74432. + if (dwc_otg_hcd->flags.b.port_connect_status_change)
  74433. + port_status |= (1 << UHF_C_PORT_CONNECTION);
  74434. +
  74435. + if (dwc_otg_hcd->flags.b.port_enable_change)
  74436. + port_status |= (1 << UHF_C_PORT_ENABLE);
  74437. +
  74438. + if (dwc_otg_hcd->flags.b.port_suspend_change)
  74439. + port_status |= (1 << UHF_C_PORT_SUSPEND);
  74440. +
  74441. + if (dwc_otg_hcd->flags.b.port_l1_change)
  74442. + port_status |= (1 << UHF_C_PORT_L1);
  74443. +
  74444. + if (dwc_otg_hcd->flags.b.port_reset_change) {
  74445. + port_status |= (1 << UHF_C_PORT_RESET);
  74446. + }
  74447. +
  74448. + if (dwc_otg_hcd->flags.b.port_over_current_change) {
  74449. + DWC_WARN("Overcurrent change detected\n");
  74450. + port_status |= (1 << UHF_C_PORT_OVER_CURRENT);
  74451. + }
  74452. +
  74453. + if (!dwc_otg_hcd->flags.b.port_connect_status) {
  74454. + /*
  74455. + * The port is disconnected, which means the core is
  74456. + * either in device mode or it soon will be. Just
  74457. + * return 0's for the remainder of the port status
  74458. + * since the port register can't be read if the core
  74459. + * is in device mode.
  74460. + */
  74461. + *((__le32 *) buf) = dwc_cpu_to_le32(&port_status);
  74462. + break;
  74463. + }
  74464. +
  74465. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  74466. + DWC_DEBUGPL(DBG_HCDV, " HPRT0: 0x%08x\n", hprt0.d32);
  74467. +
  74468. + if (hprt0.b.prtconnsts)
  74469. + port_status |= (1 << UHF_PORT_CONNECTION);
  74470. +
  74471. + if (hprt0.b.prtena)
  74472. + port_status |= (1 << UHF_PORT_ENABLE);
  74473. +
  74474. + if (hprt0.b.prtsusp)
  74475. + port_status |= (1 << UHF_PORT_SUSPEND);
  74476. +
  74477. + if (hprt0.b.prtovrcurract)
  74478. + port_status |= (1 << UHF_PORT_OVER_CURRENT);
  74479. +
  74480. + if (hprt0.b.prtrst)
  74481. + port_status |= (1 << UHF_PORT_RESET);
  74482. +
  74483. + if (hprt0.b.prtpwr)
  74484. + port_status |= (1 << UHF_PORT_POWER);
  74485. +
  74486. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED)
  74487. + port_status |= (1 << UHF_PORT_HIGH_SPEED);
  74488. + else if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED)
  74489. + port_status |= (1 << UHF_PORT_LOW_SPEED);
  74490. +
  74491. + if (hprt0.b.prttstctl)
  74492. + port_status |= (1 << UHF_PORT_TEST);
  74493. + if (dwc_otg_get_lpm_portsleepstatus(dwc_otg_hcd->core_if)) {
  74494. + port_status |= (1 << UHF_PORT_L1);
  74495. + }
  74496. + /*
  74497. + For Synopsys HW emulation of Power down wkup_control asserts the
  74498. + hreset_n and prst_n on suspned. This causes the HPRT0 to be zero.
  74499. + We intentionally tell the software that port is in L2Suspend state.
  74500. + Only for STE.
  74501. + */
  74502. + if ((core_if->power_down == 2)
  74503. + && (core_if->hibernation_suspend == 1)) {
  74504. + port_status |= (1 << UHF_PORT_SUSPEND);
  74505. + }
  74506. + /* USB_PORT_FEAT_INDICATOR unsupported always 0 */
  74507. +
  74508. + *((__le32 *) buf) = dwc_cpu_to_le32(&port_status);
  74509. +
  74510. + break;
  74511. + case UCR_SET_HUB_FEATURE:
  74512. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  74513. + "SetHubFeature\n");
  74514. + /* No HUB features supported */
  74515. + break;
  74516. + case UCR_SET_PORT_FEATURE:
  74517. + if (wValue != UHF_PORT_TEST && (!wIndex || wIndex > 1))
  74518. + goto error;
  74519. +
  74520. + if (!dwc_otg_hcd->flags.b.port_connect_status) {
  74521. + /*
  74522. + * The port is disconnected, which means the core is
  74523. + * either in device mode or it soon will be. Just
  74524. + * return without doing anything since the port
  74525. + * register can't be written if the core is in device
  74526. + * mode.
  74527. + */
  74528. + break;
  74529. + }
  74530. +
  74531. + switch (wValue) {
  74532. + case UHF_PORT_SUSPEND:
  74533. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  74534. + "SetPortFeature - USB_PORT_FEAT_SUSPEND\n");
  74535. + if (dwc_otg_hcd_otg_port(dwc_otg_hcd) != wIndex) {
  74536. + goto error;
  74537. + }
  74538. + if (core_if->power_down == 2) {
  74539. + int timeout = 300;
  74540. + dwc_irqflags_t flags;
  74541. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  74542. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  74543. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  74544. +#ifdef DWC_DEV_SRPCAP
  74545. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  74546. +#endif
  74547. + DWC_PRINTF("Preparing for complete power-off\n");
  74548. +
  74549. + /* Save registers before hibernation */
  74550. + dwc_otg_save_global_regs(core_if);
  74551. + dwc_otg_save_host_regs(core_if);
  74552. +
  74553. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  74554. + hprt0.b.prtsusp = 1;
  74555. + hprt0.b.prtena = 0;
  74556. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  74557. + /* Spin hprt0.b.prtsusp to became 1 */
  74558. + do {
  74559. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  74560. + if (hprt0.b.prtsusp) {
  74561. + break;
  74562. + }
  74563. + dwc_mdelay(1);
  74564. + } while (--timeout);
  74565. + if (!timeout) {
  74566. + DWC_WARN("Suspend wasn't genereted\n");
  74567. + }
  74568. + dwc_udelay(10);
  74569. +
  74570. + /*
  74571. + * We need to disable interrupts to prevent servicing of any IRQ
  74572. + * during going to hibernation
  74573. + */
  74574. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  74575. + core_if->lx_state = DWC_OTG_L2;
  74576. +#ifdef DWC_DEV_SRPCAP
  74577. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  74578. + hprt0.b.prtpwr = 0;
  74579. + hprt0.b.prtena = 0;
  74580. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  74581. + hprt0.d32);
  74582. +#endif
  74583. + gusbcfg.d32 =
  74584. + DWC_READ_REG32(&core_if->core_global_regs->
  74585. + gusbcfg);
  74586. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  74587. + /* ULPI interface */
  74588. + /* Suspend the Phy Clock */
  74589. + pcgcctl.d32 = 0;
  74590. + pcgcctl.b.stoppclk = 1;
  74591. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  74592. + pcgcctl.d32);
  74593. + dwc_udelay(10);
  74594. + gpwrdn.b.pmuactv = 1;
  74595. + DWC_MODIFY_REG32(&core_if->
  74596. + core_global_regs->
  74597. + gpwrdn, 0, gpwrdn.d32);
  74598. + } else {
  74599. + /* UTMI+ Interface */
  74600. + gpwrdn.b.pmuactv = 1;
  74601. + DWC_MODIFY_REG32(&core_if->
  74602. + core_global_regs->
  74603. + gpwrdn, 0, gpwrdn.d32);
  74604. + dwc_udelay(10);
  74605. + pcgcctl.b.stoppclk = 1;
  74606. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  74607. + dwc_udelay(10);
  74608. + }
  74609. +#ifdef DWC_DEV_SRPCAP
  74610. + gpwrdn.d32 = 0;
  74611. + gpwrdn.b.dis_vbus = 1;
  74612. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  74613. + gpwrdn, 0, gpwrdn.d32);
  74614. +#endif
  74615. + gpwrdn.d32 = 0;
  74616. + gpwrdn.b.pmuintsel = 1;
  74617. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  74618. + gpwrdn, 0, gpwrdn.d32);
  74619. + dwc_udelay(10);
  74620. +
  74621. + gpwrdn.d32 = 0;
  74622. +#ifdef DWC_DEV_SRPCAP
  74623. + gpwrdn.b.srp_det_msk = 1;
  74624. +#endif
  74625. + gpwrdn.b.disconn_det_msk = 1;
  74626. + gpwrdn.b.lnstchng_msk = 1;
  74627. + gpwrdn.b.sts_chngint_msk = 1;
  74628. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  74629. + gpwrdn, 0, gpwrdn.d32);
  74630. + dwc_udelay(10);
  74631. +
  74632. + /* Enable Power Down Clamp and all interrupts in GPWRDN */
  74633. + gpwrdn.d32 = 0;
  74634. + gpwrdn.b.pwrdnclmp = 1;
  74635. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  74636. + gpwrdn, 0, gpwrdn.d32);
  74637. + dwc_udelay(10);
  74638. +
  74639. + /* Switch off VDD */
  74640. + gpwrdn.d32 = 0;
  74641. + gpwrdn.b.pwrdnswtch = 1;
  74642. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  74643. + gpwrdn, 0, gpwrdn.d32);
  74644. +
  74645. +#ifdef DWC_DEV_SRPCAP
  74646. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE)
  74647. + {
  74648. + core_if->pwron_timer_started = 1;
  74649. + DWC_TIMER_SCHEDULE(core_if->pwron_timer, 6000 /* 6 secs */ );
  74650. + }
  74651. +#endif
  74652. + /* Save gpwrdn register for further usage if stschng interrupt */
  74653. + core_if->gr_backup->gpwrdn_local =
  74654. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  74655. +
  74656. + /* Set flag to indicate that we are in hibernation */
  74657. + core_if->hibernation_suspend = 1;
  74658. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock,flags);
  74659. +
  74660. + DWC_PRINTF("Host hibernation completed\n");
  74661. + // Exit from case statement
  74662. + break;
  74663. +
  74664. + }
  74665. + if (dwc_otg_hcd_otg_port(dwc_otg_hcd) == wIndex &&
  74666. + dwc_otg_hcd->fops->get_b_hnp_enable(dwc_otg_hcd)) {
  74667. + gotgctl_data_t gotgctl = {.d32 = 0 };
  74668. + gotgctl.b.hstsethnpen = 1;
  74669. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  74670. + gotgctl, 0, gotgctl.d32);
  74671. + core_if->op_state = A_SUSPEND;
  74672. + }
  74673. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  74674. + hprt0.b.prtsusp = 1;
  74675. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  74676. + {
  74677. + dwc_irqflags_t flags;
  74678. + /* Update lx_state */
  74679. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  74680. + core_if->lx_state = DWC_OTG_L2;
  74681. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  74682. + }
  74683. + /* Suspend the Phy Clock */
  74684. + {
  74685. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  74686. + pcgcctl.b.stoppclk = 1;
  74687. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  74688. + pcgcctl.d32);
  74689. + dwc_udelay(10);
  74690. + }
  74691. +
  74692. + /* For HNP the bus must be suspended for at least 200ms. */
  74693. + if (dwc_otg_hcd->fops->get_b_hnp_enable(dwc_otg_hcd)) {
  74694. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  74695. + pcgcctl.b.stoppclk = 1;
  74696. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  74697. + dwc_mdelay(200);
  74698. + }
  74699. +
  74700. + /** @todo - check how sw can wait for 1 sec to check asesvld??? */
  74701. +#if 0 //vahrama !!!!!!!!!!!!!!!!!!
  74702. + if (core_if->adp_enable) {
  74703. + gotgctl_data_t gotgctl = {.d32 = 0 };
  74704. + gpwrdn_data_t gpwrdn;
  74705. +
  74706. + while (gotgctl.b.asesvld == 1) {
  74707. + gotgctl.d32 =
  74708. + DWC_READ_REG32(&core_if->
  74709. + core_global_regs->
  74710. + gotgctl);
  74711. + dwc_mdelay(100);
  74712. + }
  74713. +
  74714. + /* Enable Power Down Logic */
  74715. + gpwrdn.d32 = 0;
  74716. + gpwrdn.b.pmuactv = 1;
  74717. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  74718. + gpwrdn, 0, gpwrdn.d32);
  74719. +
  74720. + /* Unmask SRP detected interrupt from Power Down Logic */
  74721. + gpwrdn.d32 = 0;
  74722. + gpwrdn.b.srp_det_msk = 1;
  74723. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  74724. + gpwrdn, 0, gpwrdn.d32);
  74725. +
  74726. + dwc_otg_adp_probe_start(core_if);
  74727. + }
  74728. +#endif
  74729. + break;
  74730. + case UHF_PORT_POWER:
  74731. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  74732. + "SetPortFeature - USB_PORT_FEAT_POWER\n");
  74733. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  74734. + hprt0.b.prtpwr = 1;
  74735. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  74736. + break;
  74737. + case UHF_PORT_RESET:
  74738. + if ((core_if->power_down == 2)
  74739. + && (core_if->hibernation_suspend == 1)) {
  74740. + /* If we are going to exit from Hibernated
  74741. + * state via USB RESET.
  74742. + */
  74743. + dwc_otg_host_hibernation_restore(core_if, 0, 1);
  74744. + } else {
  74745. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  74746. +
  74747. + DWC_DEBUGPL(DBG_HCD,
  74748. + "DWC OTG HCD HUB CONTROL - "
  74749. + "SetPortFeature - USB_PORT_FEAT_RESET\n");
  74750. + {
  74751. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  74752. + pcgcctl.b.enbl_sleep_gating = 1;
  74753. + pcgcctl.b.stoppclk = 1;
  74754. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  74755. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  74756. + }
  74757. +#ifdef CONFIG_USB_DWC_OTG_LPM
  74758. + {
  74759. + glpmcfg_data_t lpmcfg;
  74760. + lpmcfg.d32 =
  74761. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  74762. + if (lpmcfg.b.prt_sleep_sts) {
  74763. + lpmcfg.b.en_utmi_sleep = 0;
  74764. + lpmcfg.b.hird_thres &= (~(1 << 4));
  74765. + DWC_WRITE_REG32
  74766. + (&core_if->core_global_regs->glpmcfg,
  74767. + lpmcfg.d32);
  74768. + dwc_mdelay(1);
  74769. + }
  74770. + }
  74771. +#endif
  74772. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  74773. + /* Clear suspend bit if resetting from suspended state. */
  74774. + hprt0.b.prtsusp = 0;
  74775. + /* When B-Host the Port reset bit is set in
  74776. + * the Start HCD Callback function, so that
  74777. + * the reset is started within 1ms of the HNP
  74778. + * success interrupt. */
  74779. + if (!dwc_otg_hcd_is_b_host(dwc_otg_hcd)) {
  74780. + hprt0.b.prtpwr = 1;
  74781. + hprt0.b.prtrst = 1;
  74782. + DWC_PRINTF("Indeed it is in host mode hprt0 = %08x\n",hprt0.d32);
  74783. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  74784. + hprt0.d32);
  74785. + }
  74786. + /* Clear reset bit in 10ms (FS/LS) or 50ms (HS) */
  74787. + dwc_mdelay(60);
  74788. + hprt0.b.prtrst = 0;
  74789. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  74790. + core_if->lx_state = DWC_OTG_L0; /* Now back to the on state */
  74791. + }
  74792. + break;
  74793. +#ifdef DWC_HS_ELECT_TST
  74794. + case UHF_PORT_TEST:
  74795. + {
  74796. + uint32_t t;
  74797. + gintmsk_data_t gintmsk;
  74798. +
  74799. + t = (wIndex >> 8); /* MSB wIndex USB */
  74800. + DWC_DEBUGPL(DBG_HCD,
  74801. + "DWC OTG HCD HUB CONTROL - "
  74802. + "SetPortFeature - USB_PORT_FEAT_TEST %d\n",
  74803. + t);
  74804. + DWC_WARN("USB_PORT_FEAT_TEST %d\n", t);
  74805. + if (t < 6) {
  74806. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  74807. + hprt0.b.prttstctl = t;
  74808. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  74809. + hprt0.d32);
  74810. + } else {
  74811. + /* Setup global vars with reg addresses (quick and
  74812. + * dirty hack, should be cleaned up)
  74813. + */
  74814. + global_regs = core_if->core_global_regs;
  74815. + hc_global_regs =
  74816. + core_if->host_if->host_global_regs;
  74817. + hc_regs =
  74818. + (dwc_otg_hc_regs_t *) ((char *)
  74819. + global_regs +
  74820. + 0x500);
  74821. + data_fifo =
  74822. + (uint32_t *) ((char *)global_regs +
  74823. + 0x1000);
  74824. +
  74825. + if (t == 6) { /* HS_HOST_PORT_SUSPEND_RESUME */
  74826. + /* Save current interrupt mask */
  74827. + gintmsk.d32 =
  74828. + DWC_READ_REG32
  74829. + (&global_regs->gintmsk);
  74830. +
  74831. + /* Disable all interrupts while we muck with
  74832. + * the hardware directly
  74833. + */
  74834. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  74835. +
  74836. + /* 15 second delay per the test spec */
  74837. + dwc_mdelay(15000);
  74838. +
  74839. + /* Drive suspend on the root port */
  74840. + hprt0.d32 =
  74841. + dwc_otg_read_hprt0(core_if);
  74842. + hprt0.b.prtsusp = 1;
  74843. + hprt0.b.prtres = 0;
  74844. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  74845. +
  74846. + /* 15 second delay per the test spec */
  74847. + dwc_mdelay(15000);
  74848. +
  74849. + /* Drive resume on the root port */
  74850. + hprt0.d32 =
  74851. + dwc_otg_read_hprt0(core_if);
  74852. + hprt0.b.prtsusp = 0;
  74853. + hprt0.b.prtres = 1;
  74854. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  74855. + dwc_mdelay(100);
  74856. +
  74857. + /* Clear the resume bit */
  74858. + hprt0.b.prtres = 0;
  74859. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  74860. +
  74861. + /* Restore interrupts */
  74862. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  74863. + } else if (t == 7) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
  74864. + /* Save current interrupt mask */
  74865. + gintmsk.d32 =
  74866. + DWC_READ_REG32
  74867. + (&global_regs->gintmsk);
  74868. +
  74869. + /* Disable all interrupts while we muck with
  74870. + * the hardware directly
  74871. + */
  74872. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  74873. +
  74874. + /* 15 second delay per the test spec */
  74875. + dwc_mdelay(15000);
  74876. +
  74877. + /* Send the Setup packet */
  74878. + do_setup();
  74879. +
  74880. + /* 15 second delay so nothing else happens for awhile */
  74881. + dwc_mdelay(15000);
  74882. +
  74883. + /* Restore interrupts */
  74884. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  74885. + } else if (t == 8) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
  74886. + /* Save current interrupt mask */
  74887. + gintmsk.d32 =
  74888. + DWC_READ_REG32
  74889. + (&global_regs->gintmsk);
  74890. +
  74891. + /* Disable all interrupts while we muck with
  74892. + * the hardware directly
  74893. + */
  74894. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  74895. +
  74896. + /* Send the Setup packet */
  74897. + do_setup();
  74898. +
  74899. + /* 15 second delay so nothing else happens for awhile */
  74900. + dwc_mdelay(15000);
  74901. +
  74902. + /* Send the In and Ack packets */
  74903. + do_in_ack();
  74904. +
  74905. + /* 15 second delay so nothing else happens for awhile */
  74906. + dwc_mdelay(15000);
  74907. +
  74908. + /* Restore interrupts */
  74909. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  74910. + }
  74911. + }
  74912. + break;
  74913. + }
  74914. +#endif /* DWC_HS_ELECT_TST */
  74915. +
  74916. + case UHF_PORT_INDICATOR:
  74917. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  74918. + "SetPortFeature - USB_PORT_FEAT_INDICATOR\n");
  74919. + /* Not supported */
  74920. + break;
  74921. + default:
  74922. + retval = -DWC_E_INVALID;
  74923. + DWC_ERROR("DWC OTG HCD - "
  74924. + "SetPortFeature request %xh "
  74925. + "unknown or unsupported\n", wValue);
  74926. + break;
  74927. + }
  74928. + break;
  74929. +#ifdef CONFIG_USB_DWC_OTG_LPM
  74930. + case UCR_SET_AND_TEST_PORT_FEATURE:
  74931. + if (wValue != UHF_PORT_L1) {
  74932. + goto error;
  74933. + }
  74934. + {
  74935. + int portnum, hird, devaddr, remwake;
  74936. + glpmcfg_data_t lpmcfg;
  74937. + uint32_t time_usecs;
  74938. + gintsts_data_t gintsts;
  74939. + gintmsk_data_t gintmsk;
  74940. +
  74941. + if (!dwc_otg_get_param_lpm_enable(core_if)) {
  74942. + goto error;
  74943. + }
  74944. + if (wValue != UHF_PORT_L1 || wLength != 1) {
  74945. + goto error;
  74946. + }
  74947. + /* Check if the port currently is in SLEEP state */
  74948. + lpmcfg.d32 =
  74949. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  74950. + if (lpmcfg.b.prt_sleep_sts) {
  74951. + DWC_INFO("Port is already in sleep mode\n");
  74952. + buf[0] = 0; /* Return success */
  74953. + break;
  74954. + }
  74955. +
  74956. + portnum = wIndex & 0xf;
  74957. + hird = (wIndex >> 4) & 0xf;
  74958. + devaddr = (wIndex >> 8) & 0x7f;
  74959. + remwake = (wIndex >> 15);
  74960. +
  74961. + if (portnum != 1) {
  74962. + retval = -DWC_E_INVALID;
  74963. + DWC_WARN
  74964. + ("Wrong port number(%d) in SetandTestPortFeature request\n",
  74965. + portnum);
  74966. + break;
  74967. + }
  74968. +
  74969. + DWC_PRINTF
  74970. + ("SetandTestPortFeature request: portnum = %d, hird = %d, devaddr = %d, rewake = %d\n",
  74971. + portnum, hird, devaddr, remwake);
  74972. + /* Disable LPM interrupt */
  74973. + gintmsk.d32 = 0;
  74974. + gintmsk.b.lpmtranrcvd = 1;
  74975. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  74976. + gintmsk.d32, 0);
  74977. +
  74978. + if (dwc_otg_hcd_send_lpm
  74979. + (dwc_otg_hcd, devaddr, hird, remwake)) {
  74980. + retval = -DWC_E_INVALID;
  74981. + break;
  74982. + }
  74983. +
  74984. + time_usecs = 10 * (lpmcfg.b.retry_count + 1);
  74985. + /* We will consider timeout if time_usecs microseconds pass,
  74986. + * and we don't receive LPM transaction status.
  74987. + * After receiving non-error responce(ACK/NYET/STALL) from device,
  74988. + * core will set lpmtranrcvd bit.
  74989. + */
  74990. + do {
  74991. + gintsts.d32 =
  74992. + DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  74993. + if (gintsts.b.lpmtranrcvd) {
  74994. + break;
  74995. + }
  74996. + dwc_udelay(1);
  74997. + } while (--time_usecs);
  74998. + /* lpm_int bit will be cleared in LPM interrupt handler */
  74999. +
  75000. + /* Now fill status
  75001. + * 0x00 - Success
  75002. + * 0x10 - NYET
  75003. + * 0x11 - Timeout
  75004. + */
  75005. + if (!gintsts.b.lpmtranrcvd) {
  75006. + buf[0] = 0x3; /* Completion code is Timeout */
  75007. + dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd);
  75008. + } else {
  75009. + lpmcfg.d32 =
  75010. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  75011. + if (lpmcfg.b.lpm_resp == 0x3) {
  75012. + /* ACK responce from the device */
  75013. + buf[0] = 0x00; /* Success */
  75014. + } else if (lpmcfg.b.lpm_resp == 0x2) {
  75015. + /* NYET responce from the device */
  75016. + buf[0] = 0x2;
  75017. + } else {
  75018. + /* Otherwise responce with Timeout */
  75019. + buf[0] = 0x3;
  75020. + }
  75021. + }
  75022. + DWC_PRINTF("Device responce to LPM trans is %x\n",
  75023. + lpmcfg.b.lpm_resp);
  75024. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0,
  75025. + gintmsk.d32);
  75026. +
  75027. + break;
  75028. + }
  75029. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  75030. + default:
  75031. +error:
  75032. + retval = -DWC_E_INVALID;
  75033. + DWC_WARN("DWC OTG HCD - "
  75034. + "Unknown hub control request type or invalid typeReq: %xh wIndex: %xh wValue: %xh\n",
  75035. + typeReq, wIndex, wValue);
  75036. + break;
  75037. + }
  75038. +
  75039. + return retval;
  75040. +}
  75041. +
  75042. +#ifdef CONFIG_USB_DWC_OTG_LPM
  75043. +/** Returns index of host channel to perform LPM transaction. */
  75044. +int dwc_otg_hcd_get_hc_for_lpm_tran(dwc_otg_hcd_t * hcd, uint8_t devaddr)
  75045. +{
  75046. + dwc_otg_core_if_t *core_if = hcd->core_if;
  75047. + dwc_hc_t *hc;
  75048. + hcchar_data_t hcchar;
  75049. + gintmsk_data_t gintmsk = {.d32 = 0 };
  75050. +
  75051. + if (DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  75052. + DWC_PRINTF("No free channel to select for LPM transaction\n");
  75053. + return -1;
  75054. + }
  75055. +
  75056. + hc = DWC_CIRCLEQ_FIRST(&hcd->free_hc_list);
  75057. +
  75058. + /* Mask host channel interrupts. */
  75059. + gintmsk.b.hcintr = 1;
  75060. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
  75061. +
  75062. + /* Fill fields that core needs for LPM transaction */
  75063. + hcchar.b.devaddr = devaddr;
  75064. + hcchar.b.epnum = 0;
  75065. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  75066. + hcchar.b.mps = 64;
  75067. + hcchar.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW);
  75068. + hcchar.b.epdir = 0; /* OUT */
  75069. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[hc->hc_num]->hcchar,
  75070. + hcchar.d32);
  75071. +
  75072. + /* Remove the host channel from the free list. */
  75073. + DWC_CIRCLEQ_REMOVE_INIT(&hcd->free_hc_list, hc, hc_list_entry);
  75074. +
  75075. + DWC_PRINTF("hcnum = %d devaddr = %d\n", hc->hc_num, devaddr);
  75076. +
  75077. + return hc->hc_num;
  75078. +}
  75079. +
  75080. +/** Release hc after performing LPM transaction */
  75081. +void dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd_t * hcd)
  75082. +{
  75083. + dwc_hc_t *hc;
  75084. + glpmcfg_data_t lpmcfg;
  75085. + uint8_t hc_num;
  75086. +
  75087. + lpmcfg.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->glpmcfg);
  75088. + hc_num = lpmcfg.b.lpm_chan_index;
  75089. +
  75090. + hc = hcd->hc_ptr_array[hc_num];
  75091. +
  75092. + DWC_PRINTF("Freeing channel %d after LPM\n", hc_num);
  75093. + /* Return host channel to free list */
  75094. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  75095. +}
  75096. +
  75097. +int dwc_otg_hcd_send_lpm(dwc_otg_hcd_t * hcd, uint8_t devaddr, uint8_t hird,
  75098. + uint8_t bRemoteWake)
  75099. +{
  75100. + glpmcfg_data_t lpmcfg;
  75101. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  75102. + int channel;
  75103. +
  75104. + channel = dwc_otg_hcd_get_hc_for_lpm_tran(hcd, devaddr);
  75105. + if (channel < 0) {
  75106. + return channel;
  75107. + }
  75108. +
  75109. + pcgcctl.b.enbl_sleep_gating = 1;
  75110. + DWC_MODIFY_REG32(hcd->core_if->pcgcctl, 0, pcgcctl.d32);
  75111. +
  75112. + /* Read LPM config register */
  75113. + lpmcfg.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->glpmcfg);
  75114. +
  75115. + /* Program LPM transaction fields */
  75116. + lpmcfg.b.rem_wkup_en = bRemoteWake;
  75117. + lpmcfg.b.hird = hird;
  75118. + lpmcfg.b.hird_thres = 0x1c;
  75119. + lpmcfg.b.lpm_chan_index = channel;
  75120. + lpmcfg.b.en_utmi_sleep = 1;
  75121. + /* Program LPM config register */
  75122. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  75123. +
  75124. + /* Send LPM transaction */
  75125. + lpmcfg.b.send_lpm = 1;
  75126. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  75127. +
  75128. + return 0;
  75129. +}
  75130. +
  75131. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  75132. +
  75133. +int dwc_otg_hcd_is_status_changed(dwc_otg_hcd_t * hcd, int port)
  75134. +{
  75135. + int retval;
  75136. +
  75137. + if (port != 1) {
  75138. + return -DWC_E_INVALID;
  75139. + }
  75140. +
  75141. + retval = (hcd->flags.b.port_connect_status_change ||
  75142. + hcd->flags.b.port_reset_change ||
  75143. + hcd->flags.b.port_enable_change ||
  75144. + hcd->flags.b.port_suspend_change ||
  75145. + hcd->flags.b.port_over_current_change);
  75146. +#ifdef DEBUG
  75147. + if (retval) {
  75148. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB STATUS DATA:"
  75149. + " Root port status changed\n");
  75150. + DWC_DEBUGPL(DBG_HCDV, " port_connect_status_change: %d\n",
  75151. + hcd->flags.b.port_connect_status_change);
  75152. + DWC_DEBUGPL(DBG_HCDV, " port_reset_change: %d\n",
  75153. + hcd->flags.b.port_reset_change);
  75154. + DWC_DEBUGPL(DBG_HCDV, " port_enable_change: %d\n",
  75155. + hcd->flags.b.port_enable_change);
  75156. + DWC_DEBUGPL(DBG_HCDV, " port_suspend_change: %d\n",
  75157. + hcd->flags.b.port_suspend_change);
  75158. + DWC_DEBUGPL(DBG_HCDV, " port_over_current_change: %d\n",
  75159. + hcd->flags.b.port_over_current_change);
  75160. + }
  75161. +#endif
  75162. + return retval;
  75163. +}
  75164. +
  75165. +int dwc_otg_hcd_get_frame_number(dwc_otg_hcd_t * dwc_otg_hcd)
  75166. +{
  75167. + hfnum_data_t hfnum;
  75168. + hfnum.d32 =
  75169. + DWC_READ_REG32(&dwc_otg_hcd->core_if->host_if->host_global_regs->
  75170. + hfnum);
  75171. +
  75172. +#ifdef DEBUG_SOF
  75173. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD GET FRAME NUMBER %d\n",
  75174. + hfnum.b.frnum);
  75175. +#endif
  75176. + return hfnum.b.frnum;
  75177. +}
  75178. +
  75179. +int dwc_otg_hcd_start(dwc_otg_hcd_t * hcd,
  75180. + struct dwc_otg_hcd_function_ops *fops)
  75181. +{
  75182. + int retval = 0;
  75183. +
  75184. + hcd->fops = fops;
  75185. + if (!dwc_otg_is_device_mode(hcd->core_if) &&
  75186. + (!hcd->core_if->adp_enable || hcd->core_if->adp.adp_started)) {
  75187. + dwc_otg_hcd_reinit(hcd);
  75188. + } else {
  75189. + retval = -DWC_E_NO_DEVICE;
  75190. + }
  75191. +
  75192. + return retval;
  75193. +}
  75194. +
  75195. +void *dwc_otg_hcd_get_priv_data(dwc_otg_hcd_t * hcd)
  75196. +{
  75197. + return hcd->priv;
  75198. +}
  75199. +
  75200. +void dwc_otg_hcd_set_priv_data(dwc_otg_hcd_t * hcd, void *priv_data)
  75201. +{
  75202. + hcd->priv = priv_data;
  75203. +}
  75204. +
  75205. +uint32_t dwc_otg_hcd_otg_port(dwc_otg_hcd_t * hcd)
  75206. +{
  75207. + return hcd->otg_port;
  75208. +}
  75209. +
  75210. +uint32_t dwc_otg_hcd_is_b_host(dwc_otg_hcd_t * hcd)
  75211. +{
  75212. + uint32_t is_b_host;
  75213. + if (hcd->core_if->op_state == B_HOST) {
  75214. + is_b_host = 1;
  75215. + } else {
  75216. + is_b_host = 0;
  75217. + }
  75218. +
  75219. + return is_b_host;
  75220. +}
  75221. +
  75222. +dwc_otg_hcd_urb_t *dwc_otg_hcd_urb_alloc(dwc_otg_hcd_t * hcd,
  75223. + int iso_desc_count, int atomic_alloc)
  75224. +{
  75225. + dwc_otg_hcd_urb_t *dwc_otg_urb;
  75226. + uint32_t size;
  75227. +
  75228. + size =
  75229. + sizeof(*dwc_otg_urb) +
  75230. + iso_desc_count * sizeof(struct dwc_otg_hcd_iso_packet_desc);
  75231. + if (atomic_alloc)
  75232. + dwc_otg_urb = DWC_ALLOC_ATOMIC(size);
  75233. + else
  75234. + dwc_otg_urb = DWC_ALLOC(size);
  75235. +
  75236. + if (dwc_otg_urb)
  75237. + dwc_otg_urb->packet_count = iso_desc_count;
  75238. + else {
  75239. + DWC_ERROR("**** DWC OTG HCD URB alloc - "
  75240. + "%salloc of %db failed\n",
  75241. + atomic_alloc?"atomic ":"", size);
  75242. + }
  75243. + return dwc_otg_urb;
  75244. +}
  75245. +
  75246. +void dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_hcd_urb_t * dwc_otg_urb,
  75247. + uint8_t dev_addr, uint8_t ep_num,
  75248. + uint8_t ep_type, uint8_t ep_dir, uint16_t mps)
  75249. +{
  75250. + dwc_otg_hcd_fill_pipe(&dwc_otg_urb->pipe_info, dev_addr, ep_num,
  75251. + ep_type, ep_dir, mps);
  75252. +#if 0
  75253. + DWC_PRINTF
  75254. + ("addr = %d, ep_num = %d, ep_dir = 0x%x, ep_type = 0x%x, mps = %d\n",
  75255. + dev_addr, ep_num, ep_dir, ep_type, mps);
  75256. +#endif
  75257. +}
  75258. +
  75259. +void dwc_otg_hcd_urb_set_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  75260. + void *urb_handle, void *buf, dwc_dma_t dma,
  75261. + uint32_t buflen, void *setup_packet,
  75262. + dwc_dma_t setup_dma, uint32_t flags,
  75263. + uint16_t interval)
  75264. +{
  75265. + dwc_otg_urb->priv = urb_handle;
  75266. + dwc_otg_urb->buf = buf;
  75267. + dwc_otg_urb->dma = dma;
  75268. + dwc_otg_urb->length = buflen;
  75269. + dwc_otg_urb->setup_packet = setup_packet;
  75270. + dwc_otg_urb->setup_dma = setup_dma;
  75271. + dwc_otg_urb->flags = flags;
  75272. + dwc_otg_urb->interval = interval;
  75273. + dwc_otg_urb->status = -DWC_E_IN_PROGRESS;
  75274. +}
  75275. +
  75276. +uint32_t dwc_otg_hcd_urb_get_status(dwc_otg_hcd_urb_t * dwc_otg_urb)
  75277. +{
  75278. + return dwc_otg_urb->status;
  75279. +}
  75280. +
  75281. +uint32_t dwc_otg_hcd_urb_get_actual_length(dwc_otg_hcd_urb_t * dwc_otg_urb)
  75282. +{
  75283. + return dwc_otg_urb->actual_length;
  75284. +}
  75285. +
  75286. +uint32_t dwc_otg_hcd_urb_get_error_count(dwc_otg_hcd_urb_t * dwc_otg_urb)
  75287. +{
  75288. + return dwc_otg_urb->error_count;
  75289. +}
  75290. +
  75291. +void dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  75292. + int desc_num, uint32_t offset,
  75293. + uint32_t length)
  75294. +{
  75295. + dwc_otg_urb->iso_descs[desc_num].offset = offset;
  75296. + dwc_otg_urb->iso_descs[desc_num].length = length;
  75297. +}
  75298. +
  75299. +uint32_t dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_hcd_urb_t * dwc_otg_urb,
  75300. + int desc_num)
  75301. +{
  75302. + return dwc_otg_urb->iso_descs[desc_num].status;
  75303. +}
  75304. +
  75305. +uint32_t dwc_otg_hcd_urb_get_iso_desc_actual_length(dwc_otg_hcd_urb_t *
  75306. + dwc_otg_urb, int desc_num)
  75307. +{
  75308. + return dwc_otg_urb->iso_descs[desc_num].actual_length;
  75309. +}
  75310. +
  75311. +int dwc_otg_hcd_is_bandwidth_allocated(dwc_otg_hcd_t * hcd, void *ep_handle)
  75312. +{
  75313. + int allocated = 0;
  75314. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  75315. +
  75316. + if (qh) {
  75317. + if (!DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  75318. + allocated = 1;
  75319. + }
  75320. + }
  75321. + return allocated;
  75322. +}
  75323. +
  75324. +int dwc_otg_hcd_is_bandwidth_freed(dwc_otg_hcd_t * hcd, void *ep_handle)
  75325. +{
  75326. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  75327. + int freed = 0;
  75328. + DWC_ASSERT(qh, "qh is not allocated\n");
  75329. +
  75330. + if (DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  75331. + freed = 1;
  75332. + }
  75333. +
  75334. + return freed;
  75335. +}
  75336. +
  75337. +uint8_t dwc_otg_hcd_get_ep_bandwidth(dwc_otg_hcd_t * hcd, void *ep_handle)
  75338. +{
  75339. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  75340. + DWC_ASSERT(qh, "qh is not allocated\n");
  75341. + return qh->usecs;
  75342. +}
  75343. +
  75344. +void dwc_otg_hcd_dump_state(dwc_otg_hcd_t * hcd)
  75345. +{
  75346. +#ifdef DEBUG
  75347. + int num_channels;
  75348. + int i;
  75349. + gnptxsts_data_t np_tx_status;
  75350. + hptxsts_data_t p_tx_status;
  75351. +
  75352. + num_channels = hcd->core_if->core_params->host_channels;
  75353. + DWC_PRINTF("\n");
  75354. + DWC_PRINTF
  75355. + ("************************************************************\n");
  75356. + DWC_PRINTF("HCD State:\n");
  75357. + DWC_PRINTF(" Num channels: %d\n", num_channels);
  75358. + for (i = 0; i < num_channels; i++) {
  75359. + dwc_hc_t *hc = hcd->hc_ptr_array[i];
  75360. + DWC_PRINTF(" Channel %d:\n", i);
  75361. + DWC_PRINTF(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
  75362. + hc->dev_addr, hc->ep_num, hc->ep_is_in);
  75363. + DWC_PRINTF(" speed: %d\n", hc->speed);
  75364. + DWC_PRINTF(" ep_type: %d\n", hc->ep_type);
  75365. + DWC_PRINTF(" max_packet: %d\n", hc->max_packet);
  75366. + DWC_PRINTF(" data_pid_start: %d\n", hc->data_pid_start);
  75367. + DWC_PRINTF(" multi_count: %d\n", hc->multi_count);
  75368. + DWC_PRINTF(" xfer_started: %d\n", hc->xfer_started);
  75369. + DWC_PRINTF(" xfer_buff: %p\n", hc->xfer_buff);
  75370. + DWC_PRINTF(" xfer_len: %d\n", hc->xfer_len);
  75371. + DWC_PRINTF(" xfer_count: %d\n", hc->xfer_count);
  75372. + DWC_PRINTF(" halt_on_queue: %d\n", hc->halt_on_queue);
  75373. + DWC_PRINTF(" halt_pending: %d\n", hc->halt_pending);
  75374. + DWC_PRINTF(" halt_status: %d\n", hc->halt_status);
  75375. + DWC_PRINTF(" do_split: %d\n", hc->do_split);
  75376. + DWC_PRINTF(" complete_split: %d\n", hc->complete_split);
  75377. + DWC_PRINTF(" hub_addr: %d\n", hc->hub_addr);
  75378. + DWC_PRINTF(" port_addr: %d\n", hc->port_addr);
  75379. + DWC_PRINTF(" xact_pos: %d\n", hc->xact_pos);
  75380. + DWC_PRINTF(" requests: %d\n", hc->requests);
  75381. + DWC_PRINTF(" qh: %p\n", hc->qh);
  75382. + if (hc->xfer_started) {
  75383. + hfnum_data_t hfnum;
  75384. + hcchar_data_t hcchar;
  75385. + hctsiz_data_t hctsiz;
  75386. + hcint_data_t hcint;
  75387. + hcintmsk_data_t hcintmsk;
  75388. + hfnum.d32 =
  75389. + DWC_READ_REG32(&hcd->core_if->
  75390. + host_if->host_global_regs->hfnum);
  75391. + hcchar.d32 =
  75392. + DWC_READ_REG32(&hcd->core_if->host_if->
  75393. + hc_regs[i]->hcchar);
  75394. + hctsiz.d32 =
  75395. + DWC_READ_REG32(&hcd->core_if->host_if->
  75396. + hc_regs[i]->hctsiz);
  75397. + hcint.d32 =
  75398. + DWC_READ_REG32(&hcd->core_if->host_if->
  75399. + hc_regs[i]->hcint);
  75400. + hcintmsk.d32 =
  75401. + DWC_READ_REG32(&hcd->core_if->host_if->
  75402. + hc_regs[i]->hcintmsk);
  75403. + DWC_PRINTF(" hfnum: 0x%08x\n", hfnum.d32);
  75404. + DWC_PRINTF(" hcchar: 0x%08x\n", hcchar.d32);
  75405. + DWC_PRINTF(" hctsiz: 0x%08x\n", hctsiz.d32);
  75406. + DWC_PRINTF(" hcint: 0x%08x\n", hcint.d32);
  75407. + DWC_PRINTF(" hcintmsk: 0x%08x\n", hcintmsk.d32);
  75408. + }
  75409. + if (hc->xfer_started && hc->qh) {
  75410. + dwc_otg_qtd_t *qtd;
  75411. + dwc_otg_hcd_urb_t *urb;
  75412. +
  75413. + DWC_CIRCLEQ_FOREACH(qtd, &hc->qh->qtd_list, qtd_list_entry) {
  75414. + if (!qtd->in_process)
  75415. + break;
  75416. +
  75417. + urb = qtd->urb;
  75418. + DWC_PRINTF(" URB Info:\n");
  75419. + DWC_PRINTF(" qtd: %p, urb: %p\n", qtd, urb);
  75420. + if (urb) {
  75421. + DWC_PRINTF(" Dev: %d, EP: %d %s\n",
  75422. + dwc_otg_hcd_get_dev_addr(&urb->
  75423. + pipe_info),
  75424. + dwc_otg_hcd_get_ep_num(&urb->
  75425. + pipe_info),
  75426. + dwc_otg_hcd_is_pipe_in(&urb->
  75427. + pipe_info) ?
  75428. + "IN" : "OUT");
  75429. + DWC_PRINTF(" Max packet size: %d\n",
  75430. + dwc_otg_hcd_get_mps(&urb->
  75431. + pipe_info));
  75432. + DWC_PRINTF(" transfer_buffer: %p\n",
  75433. + urb->buf);
  75434. + DWC_PRINTF(" transfer_dma: %p\n",
  75435. + (void *)urb->dma);
  75436. + DWC_PRINTF(" transfer_buffer_length: %d\n",
  75437. + urb->length);
  75438. + DWC_PRINTF(" actual_length: %d\n",
  75439. + urb->actual_length);
  75440. + }
  75441. + }
  75442. + }
  75443. + }
  75444. + DWC_PRINTF(" non_periodic_channels: %d\n", hcd->non_periodic_channels);
  75445. + DWC_PRINTF(" periodic_channels: %d\n", hcd->periodic_channels);
  75446. + DWC_PRINTF(" periodic_usecs: %d\n", hcd->periodic_usecs);
  75447. + np_tx_status.d32 =
  75448. + DWC_READ_REG32(&hcd->core_if->core_global_regs->gnptxsts);
  75449. + DWC_PRINTF(" NP Tx Req Queue Space Avail: %d\n",
  75450. + np_tx_status.b.nptxqspcavail);
  75451. + DWC_PRINTF(" NP Tx FIFO Space Avail: %d\n",
  75452. + np_tx_status.b.nptxfspcavail);
  75453. + p_tx_status.d32 =
  75454. + DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hptxsts);
  75455. + DWC_PRINTF(" P Tx Req Queue Space Avail: %d\n",
  75456. + p_tx_status.b.ptxqspcavail);
  75457. + DWC_PRINTF(" P Tx FIFO Space Avail: %d\n", p_tx_status.b.ptxfspcavail);
  75458. + dwc_otg_hcd_dump_frrem(hcd);
  75459. + dwc_otg_dump_global_registers(hcd->core_if);
  75460. + dwc_otg_dump_host_registers(hcd->core_if);
  75461. + DWC_PRINTF
  75462. + ("************************************************************\n");
  75463. + DWC_PRINTF("\n");
  75464. +#endif
  75465. +}
  75466. +
  75467. +#ifdef DEBUG
  75468. +void dwc_print_setup_data(uint8_t * setup)
  75469. +{
  75470. + int i;
  75471. + if (CHK_DEBUG_LEVEL(DBG_HCD)) {
  75472. + DWC_PRINTF("Setup Data = MSB ");
  75473. + for (i = 7; i >= 0; i--)
  75474. + DWC_PRINTF("%02x ", setup[i]);
  75475. + DWC_PRINTF("\n");
  75476. + DWC_PRINTF(" bmRequestType Tranfer = %s\n",
  75477. + (setup[0] & 0x80) ? "Device-to-Host" :
  75478. + "Host-to-Device");
  75479. + DWC_PRINTF(" bmRequestType Type = ");
  75480. + switch ((setup[0] & 0x60) >> 5) {
  75481. + case 0:
  75482. + DWC_PRINTF("Standard\n");
  75483. + break;
  75484. + case 1:
  75485. + DWC_PRINTF("Class\n");
  75486. + break;
  75487. + case 2:
  75488. + DWC_PRINTF("Vendor\n");
  75489. + break;
  75490. + case 3:
  75491. + DWC_PRINTF("Reserved\n");
  75492. + break;
  75493. + }
  75494. + DWC_PRINTF(" bmRequestType Recipient = ");
  75495. + switch (setup[0] & 0x1f) {
  75496. + case 0:
  75497. + DWC_PRINTF("Device\n");
  75498. + break;
  75499. + case 1:
  75500. + DWC_PRINTF("Interface\n");
  75501. + break;
  75502. + case 2:
  75503. + DWC_PRINTF("Endpoint\n");
  75504. + break;
  75505. + case 3:
  75506. + DWC_PRINTF("Other\n");
  75507. + break;
  75508. + default:
  75509. + DWC_PRINTF("Reserved\n");
  75510. + break;
  75511. + }
  75512. + DWC_PRINTF(" bRequest = 0x%0x\n", setup[1]);
  75513. + DWC_PRINTF(" wValue = 0x%0x\n", *((uint16_t *) & setup[2]));
  75514. + DWC_PRINTF(" wIndex = 0x%0x\n", *((uint16_t *) & setup[4]));
  75515. + DWC_PRINTF(" wLength = 0x%0x\n\n", *((uint16_t *) & setup[6]));
  75516. + }
  75517. +}
  75518. +#endif
  75519. +
  75520. +void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t * hcd)
  75521. +{
  75522. +#if 0
  75523. + DWC_PRINTF("Frame remaining at SOF:\n");
  75524. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  75525. + hcd->frrem_samples, hcd->frrem_accum,
  75526. + (hcd->frrem_samples > 0) ?
  75527. + hcd->frrem_accum / hcd->frrem_samples : 0);
  75528. +
  75529. + DWC_PRINTF("\n");
  75530. + DWC_PRINTF("Frame remaining at start_transfer (uframe 7):\n");
  75531. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  75532. + hcd->core_if->hfnum_7_samples,
  75533. + hcd->core_if->hfnum_7_frrem_accum,
  75534. + (hcd->core_if->hfnum_7_samples >
  75535. + 0) ? hcd->core_if->hfnum_7_frrem_accum /
  75536. + hcd->core_if->hfnum_7_samples : 0);
  75537. + DWC_PRINTF("Frame remaining at start_transfer (uframe 0):\n");
  75538. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  75539. + hcd->core_if->hfnum_0_samples,
  75540. + hcd->core_if->hfnum_0_frrem_accum,
  75541. + (hcd->core_if->hfnum_0_samples >
  75542. + 0) ? hcd->core_if->hfnum_0_frrem_accum /
  75543. + hcd->core_if->hfnum_0_samples : 0);
  75544. + DWC_PRINTF("Frame remaining at start_transfer (uframe 1-6):\n");
  75545. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  75546. + hcd->core_if->hfnum_other_samples,
  75547. + hcd->core_if->hfnum_other_frrem_accum,
  75548. + (hcd->core_if->hfnum_other_samples >
  75549. + 0) ? hcd->core_if->hfnum_other_frrem_accum /
  75550. + hcd->core_if->hfnum_other_samples : 0);
  75551. +
  75552. + DWC_PRINTF("\n");
  75553. + DWC_PRINTF("Frame remaining at sample point A (uframe 7):\n");
  75554. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  75555. + hcd->hfnum_7_samples_a, hcd->hfnum_7_frrem_accum_a,
  75556. + (hcd->hfnum_7_samples_a > 0) ?
  75557. + hcd->hfnum_7_frrem_accum_a / hcd->hfnum_7_samples_a : 0);
  75558. + DWC_PRINTF("Frame remaining at sample point A (uframe 0):\n");
  75559. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  75560. + hcd->hfnum_0_samples_a, hcd->hfnum_0_frrem_accum_a,
  75561. + (hcd->hfnum_0_samples_a > 0) ?
  75562. + hcd->hfnum_0_frrem_accum_a / hcd->hfnum_0_samples_a : 0);
  75563. + DWC_PRINTF("Frame remaining at sample point A (uframe 1-6):\n");
  75564. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  75565. + hcd->hfnum_other_samples_a, hcd->hfnum_other_frrem_accum_a,
  75566. + (hcd->hfnum_other_samples_a > 0) ?
  75567. + hcd->hfnum_other_frrem_accum_a /
  75568. + hcd->hfnum_other_samples_a : 0);
  75569. +
  75570. + DWC_PRINTF("\n");
  75571. + DWC_PRINTF("Frame remaining at sample point B (uframe 7):\n");
  75572. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  75573. + hcd->hfnum_7_samples_b, hcd->hfnum_7_frrem_accum_b,
  75574. + (hcd->hfnum_7_samples_b > 0) ?
  75575. + hcd->hfnum_7_frrem_accum_b / hcd->hfnum_7_samples_b : 0);
  75576. + DWC_PRINTF("Frame remaining at sample point B (uframe 0):\n");
  75577. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  75578. + hcd->hfnum_0_samples_b, hcd->hfnum_0_frrem_accum_b,
  75579. + (hcd->hfnum_0_samples_b > 0) ?
  75580. + hcd->hfnum_0_frrem_accum_b / hcd->hfnum_0_samples_b : 0);
  75581. + DWC_PRINTF("Frame remaining at sample point B (uframe 1-6):\n");
  75582. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  75583. + hcd->hfnum_other_samples_b, hcd->hfnum_other_frrem_accum_b,
  75584. + (hcd->hfnum_other_samples_b > 0) ?
  75585. + hcd->hfnum_other_frrem_accum_b /
  75586. + hcd->hfnum_other_samples_b : 0);
  75587. +#endif
  75588. +}
  75589. +
  75590. +#endif /* DWC_DEVICE_ONLY */
  75591. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c
  75592. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c 1970-01-01 01:00:00.000000000 +0100
  75593. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c 2014-07-07 10:45:43.000000000 +0200
  75594. @@ -0,0 +1,1132 @@
  75595. +/*==========================================================================
  75596. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_ddma.c $
  75597. + * $Revision: #10 $
  75598. + * $Date: 2011/10/20 $
  75599. + * $Change: 1869464 $
  75600. + *
  75601. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  75602. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  75603. + * otherwise expressly agreed to in writing between Synopsys and you.
  75604. + *
  75605. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  75606. + * any End User Software License Agreement or Agreement for Licensed Product
  75607. + * with Synopsys or any supplement thereto. You are permitted to use and
  75608. + * redistribute this Software in source and binary forms, with or without
  75609. + * modification, provided that redistributions of source code must retain this
  75610. + * notice. You may not view, use, disclose, copy or distribute this file or
  75611. + * any information contained herein except pursuant to this license grant from
  75612. + * Synopsys. If you do not agree with this notice, including the disclaimer
  75613. + * below, then you are not authorized to use the Software.
  75614. + *
  75615. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  75616. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  75617. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  75618. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  75619. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  75620. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  75621. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  75622. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  75623. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  75624. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  75625. + * DAMAGE.
  75626. + * ========================================================================== */
  75627. +#ifndef DWC_DEVICE_ONLY
  75628. +
  75629. +/** @file
  75630. + * This file contains Descriptor DMA support implementation for host mode.
  75631. + */
  75632. +
  75633. +#include "dwc_otg_hcd.h"
  75634. +#include "dwc_otg_regs.h"
  75635. +
  75636. +extern bool microframe_schedule;
  75637. +
  75638. +static inline uint8_t frame_list_idx(uint16_t frame)
  75639. +{
  75640. + return (frame & (MAX_FRLIST_EN_NUM - 1));
  75641. +}
  75642. +
  75643. +static inline uint16_t desclist_idx_inc(uint16_t idx, uint16_t inc, uint8_t speed)
  75644. +{
  75645. + return (idx + inc) &
  75646. + (((speed ==
  75647. + DWC_OTG_EP_SPEED_HIGH) ? MAX_DMA_DESC_NUM_HS_ISOC :
  75648. + MAX_DMA_DESC_NUM_GENERIC) - 1);
  75649. +}
  75650. +
  75651. +static inline uint16_t desclist_idx_dec(uint16_t idx, uint16_t inc, uint8_t speed)
  75652. +{
  75653. + return (idx - inc) &
  75654. + (((speed ==
  75655. + DWC_OTG_EP_SPEED_HIGH) ? MAX_DMA_DESC_NUM_HS_ISOC :
  75656. + MAX_DMA_DESC_NUM_GENERIC) - 1);
  75657. +}
  75658. +
  75659. +static inline uint16_t max_desc_num(dwc_otg_qh_t * qh)
  75660. +{
  75661. + return (((qh->ep_type == UE_ISOCHRONOUS)
  75662. + && (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH))
  75663. + ? MAX_DMA_DESC_NUM_HS_ISOC : MAX_DMA_DESC_NUM_GENERIC);
  75664. +}
  75665. +static inline uint16_t frame_incr_val(dwc_otg_qh_t * qh)
  75666. +{
  75667. + return ((qh->dev_speed == DWC_OTG_EP_SPEED_HIGH)
  75668. + ? ((qh->interval + 8 - 1) / 8)
  75669. + : qh->interval);
  75670. +}
  75671. +
  75672. +static int desc_list_alloc(dwc_otg_qh_t * qh)
  75673. +{
  75674. + int retval = 0;
  75675. +
  75676. + qh->desc_list = (dwc_otg_host_dma_desc_t *)
  75677. + DWC_DMA_ALLOC(sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh),
  75678. + &qh->desc_list_dma);
  75679. +
  75680. + if (!qh->desc_list) {
  75681. + retval = -DWC_E_NO_MEMORY;
  75682. + DWC_ERROR("%s: DMA descriptor list allocation failed\n", __func__);
  75683. +
  75684. + }
  75685. +
  75686. + dwc_memset(qh->desc_list, 0x00,
  75687. + sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh));
  75688. +
  75689. + qh->n_bytes =
  75690. + (uint32_t *) DWC_ALLOC(sizeof(uint32_t) * max_desc_num(qh));
  75691. +
  75692. + if (!qh->n_bytes) {
  75693. + retval = -DWC_E_NO_MEMORY;
  75694. + DWC_ERROR
  75695. + ("%s: Failed to allocate array for descriptors' size actual values\n",
  75696. + __func__);
  75697. +
  75698. + }
  75699. + return retval;
  75700. +
  75701. +}
  75702. +
  75703. +static void desc_list_free(dwc_otg_qh_t * qh)
  75704. +{
  75705. + if (qh->desc_list) {
  75706. + DWC_DMA_FREE(max_desc_num(qh), qh->desc_list,
  75707. + qh->desc_list_dma);
  75708. + qh->desc_list = NULL;
  75709. + }
  75710. +
  75711. + if (qh->n_bytes) {
  75712. + DWC_FREE(qh->n_bytes);
  75713. + qh->n_bytes = NULL;
  75714. + }
  75715. +}
  75716. +
  75717. +static int frame_list_alloc(dwc_otg_hcd_t * hcd)
  75718. +{
  75719. + int retval = 0;
  75720. + if (hcd->frame_list)
  75721. + return 0;
  75722. +
  75723. + hcd->frame_list = DWC_DMA_ALLOC(4 * MAX_FRLIST_EN_NUM,
  75724. + &hcd->frame_list_dma);
  75725. + if (!hcd->frame_list) {
  75726. + retval = -DWC_E_NO_MEMORY;
  75727. + DWC_ERROR("%s: Frame List allocation failed\n", __func__);
  75728. + }
  75729. +
  75730. + dwc_memset(hcd->frame_list, 0x00, 4 * MAX_FRLIST_EN_NUM);
  75731. +
  75732. + return retval;
  75733. +}
  75734. +
  75735. +static void frame_list_free(dwc_otg_hcd_t * hcd)
  75736. +{
  75737. + if (!hcd->frame_list)
  75738. + return;
  75739. +
  75740. + DWC_DMA_FREE(4 * MAX_FRLIST_EN_NUM, hcd->frame_list, hcd->frame_list_dma);
  75741. + hcd->frame_list = NULL;
  75742. +}
  75743. +
  75744. +static void per_sched_enable(dwc_otg_hcd_t * hcd, uint16_t fr_list_en)
  75745. +{
  75746. +
  75747. + hcfg_data_t hcfg;
  75748. +
  75749. + hcfg.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hcfg);
  75750. +
  75751. + if (hcfg.b.perschedena) {
  75752. + /* already enabled */
  75753. + return;
  75754. + }
  75755. +
  75756. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hflbaddr,
  75757. + hcd->frame_list_dma);
  75758. +
  75759. + switch (fr_list_en) {
  75760. + case 64:
  75761. + hcfg.b.frlisten = 3;
  75762. + break;
  75763. + case 32:
  75764. + hcfg.b.frlisten = 2;
  75765. + break;
  75766. + case 16:
  75767. + hcfg.b.frlisten = 1;
  75768. + break;
  75769. + case 8:
  75770. + hcfg.b.frlisten = 0;
  75771. + break;
  75772. + default:
  75773. + break;
  75774. + }
  75775. +
  75776. + hcfg.b.perschedena = 1;
  75777. +
  75778. + DWC_DEBUGPL(DBG_HCD, "Enabling Periodic schedule\n");
  75779. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  75780. +
  75781. +}
  75782. +
  75783. +static void per_sched_disable(dwc_otg_hcd_t * hcd)
  75784. +{
  75785. + hcfg_data_t hcfg;
  75786. +
  75787. + hcfg.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hcfg);
  75788. +
  75789. + if (!hcfg.b.perschedena) {
  75790. + /* already disabled */
  75791. + return;
  75792. + }
  75793. + hcfg.b.perschedena = 0;
  75794. +
  75795. + DWC_DEBUGPL(DBG_HCD, "Disabling Periodic schedule\n");
  75796. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  75797. +}
  75798. +
  75799. +/*
  75800. + * Activates/Deactivates FrameList entries for the channel
  75801. + * based on endpoint servicing period.
  75802. + */
  75803. +void update_frame_list(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, uint8_t enable)
  75804. +{
  75805. + uint16_t i, j, inc;
  75806. + dwc_hc_t *hc = NULL;
  75807. +
  75808. + if (!qh->channel) {
  75809. + DWC_ERROR("qh->channel = %p", qh->channel);
  75810. + return;
  75811. + }
  75812. +
  75813. + if (!hcd) {
  75814. + DWC_ERROR("------hcd = %p", hcd);
  75815. + return;
  75816. + }
  75817. +
  75818. + if (!hcd->frame_list) {
  75819. + DWC_ERROR("-------hcd->frame_list = %p", hcd->frame_list);
  75820. + return;
  75821. + }
  75822. +
  75823. + hc = qh->channel;
  75824. + inc = frame_incr_val(qh);
  75825. + if (qh->ep_type == UE_ISOCHRONOUS)
  75826. + i = frame_list_idx(qh->sched_frame);
  75827. + else
  75828. + i = 0;
  75829. +
  75830. + j = i;
  75831. + do {
  75832. + if (enable)
  75833. + hcd->frame_list[j] |= (1 << hc->hc_num);
  75834. + else
  75835. + hcd->frame_list[j] &= ~(1 << hc->hc_num);
  75836. + j = (j + inc) & (MAX_FRLIST_EN_NUM - 1);
  75837. + }
  75838. + while (j != i);
  75839. + if (!enable)
  75840. + return;
  75841. + hc->schinfo = 0;
  75842. + if (qh->channel->speed == DWC_OTG_EP_SPEED_HIGH) {
  75843. + j = 1;
  75844. + /* TODO - check this */
  75845. + inc = (8 + qh->interval - 1) / qh->interval;
  75846. + for (i = 0; i < inc; i++) {
  75847. + hc->schinfo |= j;
  75848. + j = j << qh->interval;
  75849. + }
  75850. + } else {
  75851. + hc->schinfo = 0xff;
  75852. + }
  75853. +}
  75854. +
  75855. +#if 1
  75856. +void dump_frame_list(dwc_otg_hcd_t * hcd)
  75857. +{
  75858. + int i = 0;
  75859. + DWC_PRINTF("--FRAME LIST (hex) --\n");
  75860. + for (i = 0; i < MAX_FRLIST_EN_NUM; i++) {
  75861. + DWC_PRINTF("%x\t", hcd->frame_list[i]);
  75862. + if (!(i % 8) && i)
  75863. + DWC_PRINTF("\n");
  75864. + }
  75865. + DWC_PRINTF("\n----\n");
  75866. +
  75867. +}
  75868. +#endif
  75869. +
  75870. +static void release_channel_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  75871. +{
  75872. + dwc_irqflags_t flags;
  75873. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  75874. +
  75875. + dwc_hc_t *hc = qh->channel;
  75876. + if (dwc_qh_is_non_per(qh)) {
  75877. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  75878. + if (!microframe_schedule)
  75879. + hcd->non_periodic_channels--;
  75880. + else
  75881. + hcd->available_host_channels++;
  75882. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  75883. + } else
  75884. + update_frame_list(hcd, qh, 0);
  75885. +
  75886. + /*
  75887. + * The condition is added to prevent double cleanup try in case of device
  75888. + * disconnect. See channel cleanup in dwc_otg_hcd_disconnect_cb().
  75889. + */
  75890. + if (hc->qh) {
  75891. + dwc_otg_hc_cleanup(hcd->core_if, hc);
  75892. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  75893. + hc->qh = NULL;
  75894. + }
  75895. +
  75896. + qh->channel = NULL;
  75897. + qh->ntd = 0;
  75898. +
  75899. + if (qh->desc_list) {
  75900. + dwc_memset(qh->desc_list, 0x00,
  75901. + sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh));
  75902. + }
  75903. +}
  75904. +
  75905. +/**
  75906. + * Initializes a QH structure's Descriptor DMA related members.
  75907. + * Allocates memory for descriptor list.
  75908. + * On first periodic QH, allocates memory for FrameList
  75909. + * and enables periodic scheduling.
  75910. + *
  75911. + * @param hcd The HCD state structure for the DWC OTG controller.
  75912. + * @param qh The QH to init.
  75913. + *
  75914. + * @return 0 if successful, negative error code otherwise.
  75915. + */
  75916. +int dwc_otg_hcd_qh_init_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  75917. +{
  75918. + int retval = 0;
  75919. +
  75920. + if (qh->do_split) {
  75921. + DWC_ERROR("SPLIT Transfers are not supported in Descriptor DMA.\n");
  75922. + return -1;
  75923. + }
  75924. +
  75925. + retval = desc_list_alloc(qh);
  75926. +
  75927. + if ((retval == 0)
  75928. + && (qh->ep_type == UE_ISOCHRONOUS || qh->ep_type == UE_INTERRUPT)) {
  75929. + if (!hcd->frame_list) {
  75930. + retval = frame_list_alloc(hcd);
  75931. + /* Enable periodic schedule on first periodic QH */
  75932. + if (retval == 0)
  75933. + per_sched_enable(hcd, MAX_FRLIST_EN_NUM);
  75934. + }
  75935. + }
  75936. +
  75937. + qh->ntd = 0;
  75938. +
  75939. + return retval;
  75940. +}
  75941. +
  75942. +/**
  75943. + * Frees descriptor list memory associated with the QH.
  75944. + * If QH is periodic and the last, frees FrameList memory
  75945. + * and disables periodic scheduling.
  75946. + *
  75947. + * @param hcd The HCD state structure for the DWC OTG controller.
  75948. + * @param qh The QH to init.
  75949. + */
  75950. +void dwc_otg_hcd_qh_free_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  75951. +{
  75952. + desc_list_free(qh);
  75953. +
  75954. + /*
  75955. + * Channel still assigned due to some reasons.
  75956. + * Seen on Isoc URB dequeue. Channel halted but no subsequent
  75957. + * ChHalted interrupt to release the channel. Afterwards
  75958. + * when it comes here from endpoint disable routine
  75959. + * channel remains assigned.
  75960. + */
  75961. + if (qh->channel)
  75962. + release_channel_ddma(hcd, qh);
  75963. +
  75964. + if ((qh->ep_type == UE_ISOCHRONOUS || qh->ep_type == UE_INTERRUPT)
  75965. + && (microframe_schedule || !hcd->periodic_channels) && hcd->frame_list) {
  75966. +
  75967. + per_sched_disable(hcd);
  75968. + frame_list_free(hcd);
  75969. + }
  75970. +}
  75971. +
  75972. +static uint8_t frame_to_desc_idx(dwc_otg_qh_t * qh, uint16_t frame_idx)
  75973. +{
  75974. + if (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) {
  75975. + /*
  75976. + * Descriptor set(8 descriptors) index
  75977. + * which is 8-aligned.
  75978. + */
  75979. + return (frame_idx & ((MAX_DMA_DESC_NUM_HS_ISOC / 8) - 1)) * 8;
  75980. + } else {
  75981. + return (frame_idx & (MAX_DMA_DESC_NUM_GENERIC - 1));
  75982. + }
  75983. +}
  75984. +
  75985. +/*
  75986. + * Determine starting frame for Isochronous transfer.
  75987. + * Few frames skipped to prevent race condition with HC.
  75988. + */
  75989. +static uint8_t calc_starting_frame(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  75990. + uint8_t * skip_frames)
  75991. +{
  75992. + uint16_t frame = 0;
  75993. + hcd->frame_number = dwc_otg_hcd_get_frame_number(hcd);
  75994. +
  75995. + /* sched_frame is always frame number(not uFrame) both in FS and HS !! */
  75996. +
  75997. + /*
  75998. + * skip_frames is used to limit activated descriptors number
  75999. + * to avoid the situation when HC services the last activated
  76000. + * descriptor firstly.
  76001. + * Example for FS:
  76002. + * Current frame is 1, scheduled frame is 3. Since HC always fetches the descriptor
  76003. + * corresponding to curr_frame+1, the descriptor corresponding to frame 2
  76004. + * will be fetched. If the number of descriptors is max=64 (or greather) the
  76005. + * list will be fully programmed with Active descriptors and it is possible
  76006. + * case(rare) that the latest descriptor(considering rollback) corresponding
  76007. + * to frame 2 will be serviced first. HS case is more probable because, in fact,
  76008. + * up to 11 uframes(16 in the code) may be skipped.
  76009. + */
  76010. + if (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) {
  76011. + /*
  76012. + * Consider uframe counter also, to start xfer asap.
  76013. + * If half of the frame elapsed skip 2 frames otherwise
  76014. + * just 1 frame.
  76015. + * Starting descriptor index must be 8-aligned, so
  76016. + * if the current frame is near to complete the next one
  76017. + * is skipped as well.
  76018. + */
  76019. +
  76020. + if (dwc_micro_frame_num(hcd->frame_number) >= 5) {
  76021. + *skip_frames = 2 * 8;
  76022. + frame = dwc_frame_num_inc(hcd->frame_number, *skip_frames);
  76023. + } else {
  76024. + *skip_frames = 1 * 8;
  76025. + frame = dwc_frame_num_inc(hcd->frame_number, *skip_frames);
  76026. + }
  76027. +
  76028. + frame = dwc_full_frame_num(frame);
  76029. + } else {
  76030. + /*
  76031. + * Two frames are skipped for FS - the current and the next.
  76032. + * But for descriptor programming, 1 frame(descriptor) is enough,
  76033. + * see example above.
  76034. + */
  76035. + *skip_frames = 1;
  76036. + frame = dwc_frame_num_inc(hcd->frame_number, 2);
  76037. + }
  76038. +
  76039. + return frame;
  76040. +}
  76041. +
  76042. +/*
  76043. + * Calculate initial descriptor index for isochronous transfer
  76044. + * based on scheduled frame.
  76045. + */
  76046. +static uint8_t recalc_initial_desc_idx(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  76047. +{
  76048. + uint16_t frame = 0, fr_idx, fr_idx_tmp;
  76049. + uint8_t skip_frames = 0;
  76050. + /*
  76051. + * With current ISOC processing algorithm the channel is being
  76052. + * released when no more QTDs in the list(qh->ntd == 0).
  76053. + * Thus this function is called only when qh->ntd == 0 and qh->channel == 0.
  76054. + *
  76055. + * So qh->channel != NULL branch is not used and just not removed from the
  76056. + * source file. It is required for another possible approach which is,
  76057. + * do not disable and release the channel when ISOC session completed,
  76058. + * just move QH to inactive schedule until new QTD arrives.
  76059. + * On new QTD, the QH moved back to 'ready' schedule,
  76060. + * starting frame and therefore starting desc_index are recalculated.
  76061. + * In this case channel is released only on ep_disable.
  76062. + */
  76063. +
  76064. + /* Calculate starting descriptor index. For INTERRUPT endpoint it is always 0. */
  76065. + if (qh->channel) {
  76066. + frame = calc_starting_frame(hcd, qh, &skip_frames);
  76067. + /*
  76068. + * Calculate initial descriptor index based on FrameList current bitmap
  76069. + * and servicing period.
  76070. + */
  76071. + fr_idx_tmp = frame_list_idx(frame);
  76072. + fr_idx =
  76073. + (MAX_FRLIST_EN_NUM + frame_list_idx(qh->sched_frame) -
  76074. + fr_idx_tmp)
  76075. + % frame_incr_val(qh);
  76076. + fr_idx = (fr_idx + fr_idx_tmp) % MAX_FRLIST_EN_NUM;
  76077. + } else {
  76078. + qh->sched_frame = calc_starting_frame(hcd, qh, &skip_frames);
  76079. + fr_idx = frame_list_idx(qh->sched_frame);
  76080. + }
  76081. +
  76082. + qh->td_first = qh->td_last = frame_to_desc_idx(qh, fr_idx);
  76083. +
  76084. + return skip_frames;
  76085. +}
  76086. +
  76087. +#define ISOC_URB_GIVEBACK_ASAP
  76088. +
  76089. +#define MAX_ISOC_XFER_SIZE_FS 1023
  76090. +#define MAX_ISOC_XFER_SIZE_HS 3072
  76091. +#define DESCNUM_THRESHOLD 4
  76092. +
  76093. +static void init_isoc_dma_desc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  76094. + uint8_t skip_frames)
  76095. +{
  76096. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  76097. + dwc_otg_qtd_t *qtd;
  76098. + dwc_otg_host_dma_desc_t *dma_desc;
  76099. + uint16_t idx, inc, n_desc, ntd_max, max_xfer_size;
  76100. +
  76101. + idx = qh->td_last;
  76102. + inc = qh->interval;
  76103. + n_desc = 0;
  76104. +
  76105. + ntd_max = (max_desc_num(qh) + qh->interval - 1) / qh->interval;
  76106. + if (skip_frames && !qh->channel)
  76107. + ntd_max = ntd_max - skip_frames / qh->interval;
  76108. +
  76109. + max_xfer_size =
  76110. + (qh->dev_speed ==
  76111. + DWC_OTG_EP_SPEED_HIGH) ? MAX_ISOC_XFER_SIZE_HS :
  76112. + MAX_ISOC_XFER_SIZE_FS;
  76113. +
  76114. + DWC_CIRCLEQ_FOREACH(qtd, &qh->qtd_list, qtd_list_entry) {
  76115. + while ((qh->ntd < ntd_max)
  76116. + && (qtd->isoc_frame_index_last <
  76117. + qtd->urb->packet_count)) {
  76118. +
  76119. + dma_desc = &qh->desc_list[idx];
  76120. + dwc_memset(dma_desc, 0x00, sizeof(dwc_otg_host_dma_desc_t));
  76121. +
  76122. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index_last];
  76123. +
  76124. + if (frame_desc->length > max_xfer_size)
  76125. + qh->n_bytes[idx] = max_xfer_size;
  76126. + else
  76127. + qh->n_bytes[idx] = frame_desc->length;
  76128. + dma_desc->status.b_isoc.n_bytes = qh->n_bytes[idx];
  76129. + dma_desc->status.b_isoc.a = 1;
  76130. + dma_desc->status.b_isoc.sts = 0;
  76131. +
  76132. + dma_desc->buf = qtd->urb->dma + frame_desc->offset;
  76133. +
  76134. + qh->ntd++;
  76135. +
  76136. + qtd->isoc_frame_index_last++;
  76137. +
  76138. +#ifdef ISOC_URB_GIVEBACK_ASAP
  76139. + /*
  76140. + * Set IOC for each descriptor corresponding to the
  76141. + * last frame of the URB.
  76142. + */
  76143. + if (qtd->isoc_frame_index_last ==
  76144. + qtd->urb->packet_count)
  76145. + dma_desc->status.b_isoc.ioc = 1;
  76146. +
  76147. +#endif
  76148. + idx = desclist_idx_inc(idx, inc, qh->dev_speed);
  76149. + n_desc++;
  76150. +
  76151. + }
  76152. + qtd->in_process = 1;
  76153. + }
  76154. +
  76155. + qh->td_last = idx;
  76156. +
  76157. +#ifdef ISOC_URB_GIVEBACK_ASAP
  76158. + /* Set IOC for the last descriptor if descriptor list is full */
  76159. + if (qh->ntd == ntd_max) {
  76160. + idx = desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
  76161. + qh->desc_list[idx].status.b_isoc.ioc = 1;
  76162. + }
  76163. +#else
  76164. + /*
  76165. + * Set IOC bit only for one descriptor.
  76166. + * Always try to be ahead of HW processing,
  76167. + * i.e. on IOC generation driver activates next descriptors but
  76168. + * core continues to process descriptors followed the one with IOC set.
  76169. + */
  76170. +
  76171. + if (n_desc > DESCNUM_THRESHOLD) {
  76172. + /*
  76173. + * Move IOC "up". Required even if there is only one QTD
  76174. + * in the list, cause QTDs migth continue to be queued,
  76175. + * but during the activation it was only one queued.
  76176. + * Actually more than one QTD might be in the list if this function called
  76177. + * from XferCompletion - QTDs was queued during HW processing of the previous
  76178. + * descriptor chunk.
  76179. + */
  76180. + idx = dwc_desclist_idx_dec(idx, inc * ((qh->ntd + 1) / 2), qh->dev_speed);
  76181. + } else {
  76182. + /*
  76183. + * Set the IOC for the latest descriptor
  76184. + * if either number of descriptor is not greather than threshold
  76185. + * or no more new descriptors activated.
  76186. + */
  76187. + idx = dwc_desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
  76188. + }
  76189. +
  76190. + qh->desc_list[idx].status.b_isoc.ioc = 1;
  76191. +#endif
  76192. +}
  76193. +
  76194. +static void init_non_isoc_dma_desc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  76195. +{
  76196. +
  76197. + dwc_hc_t *hc;
  76198. + dwc_otg_host_dma_desc_t *dma_desc;
  76199. + dwc_otg_qtd_t *qtd;
  76200. + int num_packets, len, n_desc = 0;
  76201. +
  76202. + hc = qh->channel;
  76203. +
  76204. + /*
  76205. + * Start with hc->xfer_buff initialized in
  76206. + * assign_and_init_hc(), then if SG transfer consists of multiple URBs,
  76207. + * this pointer re-assigned to the buffer of the currently processed QTD.
  76208. + * For non-SG request there is always one QTD active.
  76209. + */
  76210. +
  76211. + DWC_CIRCLEQ_FOREACH(qtd, &qh->qtd_list, qtd_list_entry) {
  76212. +
  76213. + if (n_desc) {
  76214. + /* SG request - more than 1 QTDs */
  76215. + hc->xfer_buff = (uint8_t *)qtd->urb->dma + qtd->urb->actual_length;
  76216. + hc->xfer_len = qtd->urb->length - qtd->urb->actual_length;
  76217. + }
  76218. +
  76219. + qtd->n_desc = 0;
  76220. +
  76221. + do {
  76222. + dma_desc = &qh->desc_list[n_desc];
  76223. + len = hc->xfer_len;
  76224. +
  76225. + if (len > MAX_DMA_DESC_SIZE)
  76226. + len = MAX_DMA_DESC_SIZE - hc->max_packet + 1;
  76227. +
  76228. + if (hc->ep_is_in) {
  76229. + if (len > 0) {
  76230. + num_packets = (len + hc->max_packet - 1) / hc->max_packet;
  76231. + } else {
  76232. + /* Need 1 packet for transfer length of 0. */
  76233. + num_packets = 1;
  76234. + }
  76235. + /* Always program an integral # of max packets for IN transfers. */
  76236. + len = num_packets * hc->max_packet;
  76237. + }
  76238. +
  76239. + dma_desc->status.b.n_bytes = len;
  76240. +
  76241. + qh->n_bytes[n_desc] = len;
  76242. +
  76243. + if ((qh->ep_type == UE_CONTROL)
  76244. + && (qtd->control_phase == DWC_OTG_CONTROL_SETUP))
  76245. + dma_desc->status.b.sup = 1; /* Setup Packet */
  76246. +
  76247. + dma_desc->status.b.a = 1; /* Active descriptor */
  76248. + dma_desc->status.b.sts = 0;
  76249. +
  76250. + dma_desc->buf =
  76251. + ((unsigned long)hc->xfer_buff & 0xffffffff);
  76252. +
  76253. + /*
  76254. + * Last descriptor(or single) of IN transfer
  76255. + * with actual size less than MaxPacket.
  76256. + */
  76257. + if (len > hc->xfer_len) {
  76258. + hc->xfer_len = 0;
  76259. + } else {
  76260. + hc->xfer_buff += len;
  76261. + hc->xfer_len -= len;
  76262. + }
  76263. +
  76264. + qtd->n_desc++;
  76265. + n_desc++;
  76266. + }
  76267. + while ((hc->xfer_len > 0) && (n_desc != MAX_DMA_DESC_NUM_GENERIC));
  76268. +
  76269. +
  76270. + qtd->in_process = 1;
  76271. +
  76272. + if (qh->ep_type == UE_CONTROL)
  76273. + break;
  76274. +
  76275. + if (n_desc == MAX_DMA_DESC_NUM_GENERIC)
  76276. + break;
  76277. + }
  76278. +
  76279. + if (n_desc) {
  76280. + /* Request Transfer Complete interrupt for the last descriptor */
  76281. + qh->desc_list[n_desc - 1].status.b.ioc = 1;
  76282. + /* End of List indicator */
  76283. + qh->desc_list[n_desc - 1].status.b.eol = 1;
  76284. +
  76285. + hc->ntd = n_desc;
  76286. + }
  76287. +}
  76288. +
  76289. +/**
  76290. + * For Control and Bulk endpoints initializes descriptor list
  76291. + * and starts the transfer.
  76292. + *
  76293. + * For Interrupt and Isochronous endpoints initializes descriptor list
  76294. + * then updates FrameList, marking appropriate entries as active.
  76295. + * In case of Isochronous, the starting descriptor index is calculated based
  76296. + * on the scheduled frame, but only on the first transfer descriptor within a session.
  76297. + * Then starts the transfer via enabling the channel.
  76298. + * For Isochronous endpoint the channel is not halted on XferComplete
  76299. + * interrupt so remains assigned to the endpoint(QH) until session is done.
  76300. + *
  76301. + * @param hcd The HCD state structure for the DWC OTG controller.
  76302. + * @param qh The QH to init.
  76303. + *
  76304. + * @return 0 if successful, negative error code otherwise.
  76305. + */
  76306. +void dwc_otg_hcd_start_xfer_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  76307. +{
  76308. + /* Channel is already assigned */
  76309. + dwc_hc_t *hc = qh->channel;
  76310. + uint8_t skip_frames = 0;
  76311. +
  76312. + switch (hc->ep_type) {
  76313. + case DWC_OTG_EP_TYPE_CONTROL:
  76314. + case DWC_OTG_EP_TYPE_BULK:
  76315. + init_non_isoc_dma_desc(hcd, qh);
  76316. +
  76317. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  76318. + break;
  76319. + case DWC_OTG_EP_TYPE_INTR:
  76320. + init_non_isoc_dma_desc(hcd, qh);
  76321. +
  76322. + update_frame_list(hcd, qh, 1);
  76323. +
  76324. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  76325. + break;
  76326. + case DWC_OTG_EP_TYPE_ISOC:
  76327. +
  76328. + if (!qh->ntd)
  76329. + skip_frames = recalc_initial_desc_idx(hcd, qh);
  76330. +
  76331. + init_isoc_dma_desc(hcd, qh, skip_frames);
  76332. +
  76333. + if (!hc->xfer_started) {
  76334. +
  76335. + update_frame_list(hcd, qh, 1);
  76336. +
  76337. + /*
  76338. + * Always set to max, instead of actual size.
  76339. + * Otherwise ntd will be changed with
  76340. + * channel being enabled. Not recommended.
  76341. + *
  76342. + */
  76343. + hc->ntd = max_desc_num(qh);
  76344. + /* Enable channel only once for ISOC */
  76345. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  76346. + }
  76347. +
  76348. + break;
  76349. + default:
  76350. +
  76351. + break;
  76352. + }
  76353. +}
  76354. +
  76355. +static void complete_isoc_xfer_ddma(dwc_otg_hcd_t * hcd,
  76356. + dwc_hc_t * hc,
  76357. + dwc_otg_hc_regs_t * hc_regs,
  76358. + dwc_otg_halt_status_e halt_status)
  76359. +{
  76360. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  76361. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  76362. + dwc_otg_qh_t *qh;
  76363. + dwc_otg_host_dma_desc_t *dma_desc;
  76364. + uint16_t idx, remain;
  76365. + uint8_t urb_compl;
  76366. +
  76367. + qh = hc->qh;
  76368. + idx = qh->td_first;
  76369. +
  76370. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  76371. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry)
  76372. + qtd->in_process = 0;
  76373. + return;
  76374. + } else if ((halt_status == DWC_OTG_HC_XFER_AHB_ERR) ||
  76375. + (halt_status == DWC_OTG_HC_XFER_BABBLE_ERR)) {
  76376. + /*
  76377. + * Channel is halted in these error cases.
  76378. + * Considered as serious issues.
  76379. + * Complete all URBs marking all frames as failed,
  76380. + * irrespective whether some of the descriptors(frames) succeeded or no.
  76381. + * Pass error code to completion routine as well, to
  76382. + * update urb->status, some of class drivers might use it to stop
  76383. + * queing transfer requests.
  76384. + */
  76385. + int err = (halt_status == DWC_OTG_HC_XFER_AHB_ERR)
  76386. + ? (-DWC_E_IO)
  76387. + : (-DWC_E_OVERFLOW);
  76388. +
  76389. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  76390. + for (idx = 0; idx < qtd->urb->packet_count; idx++) {
  76391. + frame_desc = &qtd->urb->iso_descs[idx];
  76392. + frame_desc->status = err;
  76393. + }
  76394. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, err);
  76395. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  76396. + }
  76397. + return;
  76398. + }
  76399. +
  76400. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  76401. +
  76402. + if (!qtd->in_process)
  76403. + break;
  76404. +
  76405. + urb_compl = 0;
  76406. +
  76407. + do {
  76408. +
  76409. + dma_desc = &qh->desc_list[idx];
  76410. +
  76411. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  76412. + remain = hc->ep_is_in ? dma_desc->status.b_isoc.n_bytes : 0;
  76413. +
  76414. + if (dma_desc->status.b_isoc.sts == DMA_DESC_STS_PKTERR) {
  76415. + /*
  76416. + * XactError or, unable to complete all the transactions
  76417. + * in the scheduled micro-frame/frame,
  76418. + * both indicated by DMA_DESC_STS_PKTERR.
  76419. + */
  76420. + qtd->urb->error_count++;
  76421. + frame_desc->actual_length = qh->n_bytes[idx] - remain;
  76422. + frame_desc->status = -DWC_E_PROTOCOL;
  76423. + } else {
  76424. + /* Success */
  76425. +
  76426. + frame_desc->actual_length = qh->n_bytes[idx] - remain;
  76427. + frame_desc->status = 0;
  76428. + }
  76429. +
  76430. + if (++qtd->isoc_frame_index == qtd->urb->packet_count) {
  76431. + /*
  76432. + * urb->status is not used for isoc transfers here.
  76433. + * The individual frame_desc status are used instead.
  76434. + */
  76435. +
  76436. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  76437. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  76438. +
  76439. + /*
  76440. + * This check is necessary because urb_dequeue can be called
  76441. + * from urb complete callback(sound driver example).
  76442. + * All pending URBs are dequeued there, so no need for
  76443. + * further processing.
  76444. + */
  76445. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  76446. + return;
  76447. + }
  76448. +
  76449. + urb_compl = 1;
  76450. +
  76451. + }
  76452. +
  76453. + qh->ntd--;
  76454. +
  76455. + /* Stop if IOC requested descriptor reached */
  76456. + if (dma_desc->status.b_isoc.ioc) {
  76457. + idx = desclist_idx_inc(idx, qh->interval, hc->speed);
  76458. + goto stop_scan;
  76459. + }
  76460. +
  76461. + idx = desclist_idx_inc(idx, qh->interval, hc->speed);
  76462. +
  76463. + if (urb_compl)
  76464. + break;
  76465. + }
  76466. + while (idx != qh->td_first);
  76467. + }
  76468. +stop_scan:
  76469. + qh->td_first = idx;
  76470. +}
  76471. +
  76472. +uint8_t update_non_isoc_urb_state_ddma(dwc_otg_hcd_t * hcd,
  76473. + dwc_hc_t * hc,
  76474. + dwc_otg_qtd_t * qtd,
  76475. + dwc_otg_host_dma_desc_t * dma_desc,
  76476. + dwc_otg_halt_status_e halt_status,
  76477. + uint32_t n_bytes, uint8_t * xfer_done)
  76478. +{
  76479. +
  76480. + uint16_t remain = hc->ep_is_in ? dma_desc->status.b.n_bytes : 0;
  76481. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  76482. +
  76483. + if (halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
  76484. + urb->status = -DWC_E_IO;
  76485. + return 1;
  76486. + }
  76487. + if (dma_desc->status.b.sts == DMA_DESC_STS_PKTERR) {
  76488. + switch (halt_status) {
  76489. + case DWC_OTG_HC_XFER_STALL:
  76490. + urb->status = -DWC_E_PIPE;
  76491. + break;
  76492. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  76493. + urb->status = -DWC_E_OVERFLOW;
  76494. + break;
  76495. + case DWC_OTG_HC_XFER_XACT_ERR:
  76496. + urb->status = -DWC_E_PROTOCOL;
  76497. + break;
  76498. + default:
  76499. + DWC_ERROR("%s: Unhandled descriptor error status (%d)\n", __func__,
  76500. + halt_status);
  76501. + break;
  76502. + }
  76503. + return 1;
  76504. + }
  76505. +
  76506. + if (dma_desc->status.b.a == 1) {
  76507. + DWC_DEBUGPL(DBG_HCDV,
  76508. + "Active descriptor encountered on channel %d\n",
  76509. + hc->hc_num);
  76510. + return 0;
  76511. + }
  76512. +
  76513. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL) {
  76514. + if (qtd->control_phase == DWC_OTG_CONTROL_DATA) {
  76515. + urb->actual_length += n_bytes - remain;
  76516. + if (remain || urb->actual_length == urb->length) {
  76517. + /*
  76518. + * For Control Data stage do not set urb->status=0 to prevent
  76519. + * URB callback. Set it when Status phase done. See below.
  76520. + */
  76521. + *xfer_done = 1;
  76522. + }
  76523. +
  76524. + } else if (qtd->control_phase == DWC_OTG_CONTROL_STATUS) {
  76525. + urb->status = 0;
  76526. + *xfer_done = 1;
  76527. + }
  76528. + /* No handling for SETUP stage */
  76529. + } else {
  76530. + /* BULK and INTR */
  76531. + urb->actual_length += n_bytes - remain;
  76532. + if (remain || urb->actual_length == urb->length) {
  76533. + urb->status = 0;
  76534. + *xfer_done = 1;
  76535. + }
  76536. + }
  76537. +
  76538. + return 0;
  76539. +}
  76540. +
  76541. +static void complete_non_isoc_xfer_ddma(dwc_otg_hcd_t * hcd,
  76542. + dwc_hc_t * hc,
  76543. + dwc_otg_hc_regs_t * hc_regs,
  76544. + dwc_otg_halt_status_e halt_status)
  76545. +{
  76546. + dwc_otg_hcd_urb_t *urb = NULL;
  76547. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  76548. + dwc_otg_qh_t *qh;
  76549. + dwc_otg_host_dma_desc_t *dma_desc;
  76550. + uint32_t n_bytes, n_desc, i;
  76551. + uint8_t failed = 0, xfer_done;
  76552. +
  76553. + n_desc = 0;
  76554. +
  76555. + qh = hc->qh;
  76556. +
  76557. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  76558. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  76559. + qtd->in_process = 0;
  76560. + }
  76561. + return;
  76562. + }
  76563. +
  76564. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) {
  76565. +
  76566. + urb = qtd->urb;
  76567. +
  76568. + n_bytes = 0;
  76569. + xfer_done = 0;
  76570. +
  76571. + for (i = 0; i < qtd->n_desc; i++) {
  76572. + dma_desc = &qh->desc_list[n_desc];
  76573. +
  76574. + n_bytes = qh->n_bytes[n_desc];
  76575. +
  76576. + failed =
  76577. + update_non_isoc_urb_state_ddma(hcd, hc, qtd,
  76578. + dma_desc,
  76579. + halt_status, n_bytes,
  76580. + &xfer_done);
  76581. +
  76582. + if (failed
  76583. + || (xfer_done
  76584. + && (urb->status != -DWC_E_IN_PROGRESS))) {
  76585. +
  76586. + hcd->fops->complete(hcd, urb->priv, urb,
  76587. + urb->status);
  76588. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  76589. +
  76590. + if (failed)
  76591. + goto stop_scan;
  76592. + } else if (qh->ep_type == UE_CONTROL) {
  76593. + if (qtd->control_phase == DWC_OTG_CONTROL_SETUP) {
  76594. + if (urb->length > 0) {
  76595. + qtd->control_phase = DWC_OTG_CONTROL_DATA;
  76596. + } else {
  76597. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  76598. + }
  76599. + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction done\n");
  76600. + } else if (qtd->control_phase == DWC_OTG_CONTROL_DATA) {
  76601. + if (xfer_done) {
  76602. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  76603. + DWC_DEBUGPL(DBG_HCDV, " Control data transfer done\n");
  76604. + } else if (i + 1 == qtd->n_desc) {
  76605. + /*
  76606. + * Last descriptor for Control data stage which is
  76607. + * not completed yet.
  76608. + */
  76609. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  76610. + }
  76611. + }
  76612. + }
  76613. +
  76614. + n_desc++;
  76615. + }
  76616. +
  76617. + }
  76618. +
  76619. +stop_scan:
  76620. +
  76621. + if (qh->ep_type != UE_CONTROL) {
  76622. + /*
  76623. + * Resetting the data toggle for bulk
  76624. + * and interrupt endpoints in case of stall. See handle_hc_stall_intr()
  76625. + */
  76626. + if (halt_status == DWC_OTG_HC_XFER_STALL)
  76627. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  76628. + else
  76629. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  76630. + }
  76631. +
  76632. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  76633. + hcint_data_t hcint;
  76634. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  76635. + if (hcint.b.nyet) {
  76636. + /*
  76637. + * Got a NYET on the last transaction of the transfer. It
  76638. + * means that the endpoint should be in the PING state at the
  76639. + * beginning of the next transfer.
  76640. + */
  76641. + qh->ping_state = 1;
  76642. + clear_hc_int(hc_regs, nyet);
  76643. + }
  76644. +
  76645. + }
  76646. +
  76647. +}
  76648. +
  76649. +/**
  76650. + * This function is called from interrupt handlers.
  76651. + * Scans the descriptor list, updates URB's status and
  76652. + * calls completion routine for the URB if it's done.
  76653. + * Releases the channel to be used by other transfers.
  76654. + * In case of Isochronous endpoint the channel is not halted until
  76655. + * the end of the session, i.e. QTD list is empty.
  76656. + * If periodic channel released the FrameList is updated accordingly.
  76657. + *
  76658. + * Calls transaction selection routines to activate pending transfers.
  76659. + *
  76660. + * @param hcd The HCD state structure for the DWC OTG controller.
  76661. + * @param hc Host channel, the transfer is completed on.
  76662. + * @param hc_regs Host channel registers.
  76663. + * @param halt_status Reason the channel is being halted,
  76664. + * or just XferComplete for isochronous transfer
  76665. + */
  76666. +void dwc_otg_hcd_complete_xfer_ddma(dwc_otg_hcd_t * hcd,
  76667. + dwc_hc_t * hc,
  76668. + dwc_otg_hc_regs_t * hc_regs,
  76669. + dwc_otg_halt_status_e halt_status)
  76670. +{
  76671. + uint8_t continue_isoc_xfer = 0;
  76672. + dwc_otg_transaction_type_e tr_type;
  76673. + dwc_otg_qh_t *qh = hc->qh;
  76674. +
  76675. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  76676. +
  76677. + complete_isoc_xfer_ddma(hcd, hc, hc_regs, halt_status);
  76678. +
  76679. + /* Release the channel if halted or session completed */
  76680. + if (halt_status != DWC_OTG_HC_XFER_COMPLETE ||
  76681. + DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  76682. +
  76683. + /* Halt the channel if session completed */
  76684. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  76685. + dwc_otg_hc_halt(hcd->core_if, hc, halt_status);
  76686. + }
  76687. +
  76688. + release_channel_ddma(hcd, qh);
  76689. + dwc_otg_hcd_qh_remove(hcd, qh);
  76690. + } else {
  76691. + /* Keep in assigned schedule to continue transfer */
  76692. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  76693. + &qh->qh_list_entry);
  76694. + continue_isoc_xfer = 1;
  76695. +
  76696. + }
  76697. + /** @todo Consider the case when period exceeds FrameList size.
  76698. + * Frame Rollover interrupt should be used.
  76699. + */
  76700. + } else {
  76701. + /* Scan descriptor list to complete the URB(s), then release the channel */
  76702. + complete_non_isoc_xfer_ddma(hcd, hc, hc_regs, halt_status);
  76703. +
  76704. + release_channel_ddma(hcd, qh);
  76705. + dwc_otg_hcd_qh_remove(hcd, qh);
  76706. +
  76707. + if (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  76708. + /* Add back to inactive non-periodic schedule on normal completion */
  76709. + dwc_otg_hcd_qh_add(hcd, qh);
  76710. + }
  76711. +
  76712. + }
  76713. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  76714. + if (tr_type != DWC_OTG_TRANSACTION_NONE || continue_isoc_xfer) {
  76715. + if (continue_isoc_xfer) {
  76716. + if (tr_type == DWC_OTG_TRANSACTION_NONE) {
  76717. + tr_type = DWC_OTG_TRANSACTION_PERIODIC;
  76718. + } else if (tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC) {
  76719. + tr_type = DWC_OTG_TRANSACTION_ALL;
  76720. + }
  76721. + }
  76722. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  76723. + }
  76724. +}
  76725. +
  76726. +#endif /* DWC_DEVICE_ONLY */
  76727. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_hcd.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd.h
  76728. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_hcd.h 1970-01-01 01:00:00.000000000 +0100
  76729. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd.h 2014-07-07 10:45:43.000000000 +0200
  76730. @@ -0,0 +1,862 @@
  76731. +/* ==========================================================================
  76732. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd.h $
  76733. + * $Revision: #58 $
  76734. + * $Date: 2011/09/15 $
  76735. + * $Change: 1846647 $
  76736. + *
  76737. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  76738. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  76739. + * otherwise expressly agreed to in writing between Synopsys and you.
  76740. + *
  76741. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  76742. + * any End User Software License Agreement or Agreement for Licensed Product
  76743. + * with Synopsys or any supplement thereto. You are permitted to use and
  76744. + * redistribute this Software in source and binary forms, with or without
  76745. + * modification, provided that redistributions of source code must retain this
  76746. + * notice. You may not view, use, disclose, copy or distribute this file or
  76747. + * any information contained herein except pursuant to this license grant from
  76748. + * Synopsys. If you do not agree with this notice, including the disclaimer
  76749. + * below, then you are not authorized to use the Software.
  76750. + *
  76751. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  76752. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  76753. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  76754. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  76755. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  76756. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  76757. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  76758. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  76759. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  76760. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  76761. + * DAMAGE.
  76762. + * ========================================================================== */
  76763. +#ifndef DWC_DEVICE_ONLY
  76764. +#ifndef __DWC_HCD_H__
  76765. +#define __DWC_HCD_H__
  76766. +
  76767. +#include "dwc_otg_os_dep.h"
  76768. +#include "usb.h"
  76769. +#include "dwc_otg_hcd_if.h"
  76770. +#include "dwc_otg_core_if.h"
  76771. +#include "dwc_list.h"
  76772. +#include "dwc_otg_cil.h"
  76773. +#include "dwc_otg_fiq_fsm.h"
  76774. +
  76775. +
  76776. +/**
  76777. + * @file
  76778. + *
  76779. + * This file contains the structures, constants, and interfaces for
  76780. + * the Host Contoller Driver (HCD).
  76781. + *
  76782. + * The Host Controller Driver (HCD) is responsible for translating requests
  76783. + * from the USB Driver into the appropriate actions on the DWC_otg controller.
  76784. + * It isolates the USBD from the specifics of the controller by providing an
  76785. + * API to the USBD.
  76786. + */
  76787. +
  76788. +struct dwc_otg_hcd_pipe_info {
  76789. + uint8_t dev_addr;
  76790. + uint8_t ep_num;
  76791. + uint8_t pipe_type;
  76792. + uint8_t pipe_dir;
  76793. + uint16_t mps;
  76794. +};
  76795. +
  76796. +struct dwc_otg_hcd_iso_packet_desc {
  76797. + uint32_t offset;
  76798. + uint32_t length;
  76799. + uint32_t actual_length;
  76800. + uint32_t status;
  76801. +};
  76802. +
  76803. +struct dwc_otg_qtd;
  76804. +
  76805. +struct dwc_otg_hcd_urb {
  76806. + void *priv;
  76807. + struct dwc_otg_qtd *qtd;
  76808. + void *buf;
  76809. + dwc_dma_t dma;
  76810. + void *setup_packet;
  76811. + dwc_dma_t setup_dma;
  76812. + uint32_t length;
  76813. + uint32_t actual_length;
  76814. + uint32_t status;
  76815. + uint32_t error_count;
  76816. + uint32_t packet_count;
  76817. + uint32_t flags;
  76818. + uint16_t interval;
  76819. + struct dwc_otg_hcd_pipe_info pipe_info;
  76820. + struct dwc_otg_hcd_iso_packet_desc iso_descs[0];
  76821. +};
  76822. +
  76823. +static inline uint8_t dwc_otg_hcd_get_ep_num(struct dwc_otg_hcd_pipe_info *pipe)
  76824. +{
  76825. + return pipe->ep_num;
  76826. +}
  76827. +
  76828. +static inline uint8_t dwc_otg_hcd_get_pipe_type(struct dwc_otg_hcd_pipe_info
  76829. + *pipe)
  76830. +{
  76831. + return pipe->pipe_type;
  76832. +}
  76833. +
  76834. +static inline uint16_t dwc_otg_hcd_get_mps(struct dwc_otg_hcd_pipe_info *pipe)
  76835. +{
  76836. + return pipe->mps;
  76837. +}
  76838. +
  76839. +static inline uint8_t dwc_otg_hcd_get_dev_addr(struct dwc_otg_hcd_pipe_info
  76840. + *pipe)
  76841. +{
  76842. + return pipe->dev_addr;
  76843. +}
  76844. +
  76845. +static inline uint8_t dwc_otg_hcd_is_pipe_isoc(struct dwc_otg_hcd_pipe_info
  76846. + *pipe)
  76847. +{
  76848. + return (pipe->pipe_type == UE_ISOCHRONOUS);
  76849. +}
  76850. +
  76851. +static inline uint8_t dwc_otg_hcd_is_pipe_int(struct dwc_otg_hcd_pipe_info
  76852. + *pipe)
  76853. +{
  76854. + return (pipe->pipe_type == UE_INTERRUPT);
  76855. +}
  76856. +
  76857. +static inline uint8_t dwc_otg_hcd_is_pipe_bulk(struct dwc_otg_hcd_pipe_info
  76858. + *pipe)
  76859. +{
  76860. + return (pipe->pipe_type == UE_BULK);
  76861. +}
  76862. +
  76863. +static inline uint8_t dwc_otg_hcd_is_pipe_control(struct dwc_otg_hcd_pipe_info
  76864. + *pipe)
  76865. +{
  76866. + return (pipe->pipe_type == UE_CONTROL);
  76867. +}
  76868. +
  76869. +static inline uint8_t dwc_otg_hcd_is_pipe_in(struct dwc_otg_hcd_pipe_info *pipe)
  76870. +{
  76871. + return (pipe->pipe_dir == UE_DIR_IN);
  76872. +}
  76873. +
  76874. +static inline uint8_t dwc_otg_hcd_is_pipe_out(struct dwc_otg_hcd_pipe_info
  76875. + *pipe)
  76876. +{
  76877. + return (!dwc_otg_hcd_is_pipe_in(pipe));
  76878. +}
  76879. +
  76880. +static inline void dwc_otg_hcd_fill_pipe(struct dwc_otg_hcd_pipe_info *pipe,
  76881. + uint8_t devaddr, uint8_t ep_num,
  76882. + uint8_t pipe_type, uint8_t pipe_dir,
  76883. + uint16_t mps)
  76884. +{
  76885. + pipe->dev_addr = devaddr;
  76886. + pipe->ep_num = ep_num;
  76887. + pipe->pipe_type = pipe_type;
  76888. + pipe->pipe_dir = pipe_dir;
  76889. + pipe->mps = mps;
  76890. +}
  76891. +
  76892. +/**
  76893. + * Phases for control transfers.
  76894. + */
  76895. +typedef enum dwc_otg_control_phase {
  76896. + DWC_OTG_CONTROL_SETUP,
  76897. + DWC_OTG_CONTROL_DATA,
  76898. + DWC_OTG_CONTROL_STATUS
  76899. +} dwc_otg_control_phase_e;
  76900. +
  76901. +/** Transaction types. */
  76902. +typedef enum dwc_otg_transaction_type {
  76903. + DWC_OTG_TRANSACTION_NONE = 0,
  76904. + DWC_OTG_TRANSACTION_PERIODIC = 1,
  76905. + DWC_OTG_TRANSACTION_NON_PERIODIC = 2,
  76906. + DWC_OTG_TRANSACTION_ALL = DWC_OTG_TRANSACTION_PERIODIC + DWC_OTG_TRANSACTION_NON_PERIODIC
  76907. +} dwc_otg_transaction_type_e;
  76908. +
  76909. +struct dwc_otg_qh;
  76910. +
  76911. +/**
  76912. + * A Queue Transfer Descriptor (QTD) holds the state of a bulk, control,
  76913. + * interrupt, or isochronous transfer. A single QTD is created for each URB
  76914. + * (of one of these types) submitted to the HCD. The transfer associated with
  76915. + * a QTD may require one or multiple transactions.
  76916. + *
  76917. + * A QTD is linked to a Queue Head, which is entered in either the
  76918. + * non-periodic or periodic schedule for execution. When a QTD is chosen for
  76919. + * execution, some or all of its transactions may be executed. After
  76920. + * execution, the state of the QTD is updated. The QTD may be retired if all
  76921. + * its transactions are complete or if an error occurred. Otherwise, it
  76922. + * remains in the schedule so more transactions can be executed later.
  76923. + */
  76924. +typedef struct dwc_otg_qtd {
  76925. + /**
  76926. + * Determines the PID of the next data packet for the data phase of
  76927. + * control transfers. Ignored for other transfer types.<br>
  76928. + * One of the following values:
  76929. + * - DWC_OTG_HC_PID_DATA0
  76930. + * - DWC_OTG_HC_PID_DATA1
  76931. + */
  76932. + uint8_t data_toggle;
  76933. +
  76934. + /** Current phase for control transfers (Setup, Data, or Status). */
  76935. + dwc_otg_control_phase_e control_phase;
  76936. +
  76937. + /** Keep track of the current split type
  76938. + * for FS/LS endpoints on a HS Hub */
  76939. + uint8_t complete_split;
  76940. +
  76941. + /** How many bytes transferred during SSPLIT OUT */
  76942. + uint32_t ssplit_out_xfer_count;
  76943. +
  76944. + /**
  76945. + * Holds the number of bus errors that have occurred for a transaction
  76946. + * within this transfer.
  76947. + */
  76948. + uint8_t error_count;
  76949. +
  76950. + /**
  76951. + * Index of the next frame descriptor for an isochronous transfer. A
  76952. + * frame descriptor describes the buffer position and length of the
  76953. + * data to be transferred in the next scheduled (micro)frame of an
  76954. + * isochronous transfer. It also holds status for that transaction.
  76955. + * The frame index starts at 0.
  76956. + */
  76957. + uint16_t isoc_frame_index;
  76958. +
  76959. + /** Position of the ISOC split on full/low speed */
  76960. + uint8_t isoc_split_pos;
  76961. +
  76962. + /** Position of the ISOC split in the buffer for the current frame */
  76963. + uint16_t isoc_split_offset;
  76964. +
  76965. + /** URB for this transfer */
  76966. + struct dwc_otg_hcd_urb *urb;
  76967. +
  76968. + struct dwc_otg_qh *qh;
  76969. +
  76970. + /** This list of QTDs */
  76971. + DWC_CIRCLEQ_ENTRY(dwc_otg_qtd) qtd_list_entry;
  76972. +
  76973. + /** Indicates if this QTD is currently processed by HW. */
  76974. + uint8_t in_process;
  76975. +
  76976. + /** Number of DMA descriptors for this QTD */
  76977. + uint8_t n_desc;
  76978. +
  76979. + /**
  76980. + * Last activated frame(packet) index.
  76981. + * Used in Descriptor DMA mode only.
  76982. + */
  76983. + uint16_t isoc_frame_index_last;
  76984. +
  76985. +} dwc_otg_qtd_t;
  76986. +
  76987. +DWC_CIRCLEQ_HEAD(dwc_otg_qtd_list, dwc_otg_qtd);
  76988. +
  76989. +/**
  76990. + * A Queue Head (QH) holds the static characteristics of an endpoint and
  76991. + * maintains a list of transfers (QTDs) for that endpoint. A QH structure may
  76992. + * be entered in either the non-periodic or periodic schedule.
  76993. + */
  76994. +typedef struct dwc_otg_qh {
  76995. + /**
  76996. + * Endpoint type.
  76997. + * One of the following values:
  76998. + * - UE_CONTROL
  76999. + * - UE_BULK
  77000. + * - UE_INTERRUPT
  77001. + * - UE_ISOCHRONOUS
  77002. + */
  77003. + uint8_t ep_type;
  77004. + uint8_t ep_is_in;
  77005. +
  77006. + /** wMaxPacketSize Field of Endpoint Descriptor. */
  77007. + uint16_t maxp;
  77008. +
  77009. + /**
  77010. + * Device speed.
  77011. + * One of the following values:
  77012. + * - DWC_OTG_EP_SPEED_LOW
  77013. + * - DWC_OTG_EP_SPEED_FULL
  77014. + * - DWC_OTG_EP_SPEED_HIGH
  77015. + */
  77016. + uint8_t dev_speed;
  77017. +
  77018. + /**
  77019. + * Determines the PID of the next data packet for non-control
  77020. + * transfers. Ignored for control transfers.<br>
  77021. + * One of the following values:
  77022. + * - DWC_OTG_HC_PID_DATA0
  77023. + * - DWC_OTG_HC_PID_DATA1
  77024. + */
  77025. + uint8_t data_toggle;
  77026. +
  77027. + /** Ping state if 1. */
  77028. + uint8_t ping_state;
  77029. +
  77030. + /**
  77031. + * List of QTDs for this QH.
  77032. + */
  77033. + struct dwc_otg_qtd_list qtd_list;
  77034. +
  77035. + /** Host channel currently processing transfers for this QH. */
  77036. + struct dwc_hc *channel;
  77037. +
  77038. + /** Full/low speed endpoint on high-speed hub requires split. */
  77039. + uint8_t do_split;
  77040. +
  77041. + /** @name Periodic schedule information */
  77042. + /** @{ */
  77043. +
  77044. + /** Bandwidth in microseconds per (micro)frame. */
  77045. + uint16_t usecs;
  77046. +
  77047. + /** Interval between transfers in (micro)frames. */
  77048. + uint16_t interval;
  77049. +
  77050. + /**
  77051. + * (micro)frame to initialize a periodic transfer. The transfer
  77052. + * executes in the following (micro)frame.
  77053. + */
  77054. + uint16_t sched_frame;
  77055. +
  77056. + /*
  77057. + ** Frame a NAK was received on this queue head, used to minimise NAK retransmission
  77058. + */
  77059. + uint16_t nak_frame;
  77060. +
  77061. + /** (micro)frame at which last start split was initialized. */
  77062. + uint16_t start_split_frame;
  77063. +
  77064. + /** @} */
  77065. +
  77066. + /**
  77067. + * Used instead of original buffer if
  77068. + * it(physical address) is not dword-aligned.
  77069. + */
  77070. + uint8_t *dw_align_buf;
  77071. + dwc_dma_t dw_align_buf_dma;
  77072. +
  77073. + /** Entry for QH in either the periodic or non-periodic schedule. */
  77074. + dwc_list_link_t qh_list_entry;
  77075. +
  77076. + /** @name Descriptor DMA support */
  77077. + /** @{ */
  77078. +
  77079. + /** Descriptor List. */
  77080. + dwc_otg_host_dma_desc_t *desc_list;
  77081. +
  77082. + /** Descriptor List physical address. */
  77083. + dwc_dma_t desc_list_dma;
  77084. +
  77085. + /**
  77086. + * Xfer Bytes array.
  77087. + * Each element corresponds to a descriptor and indicates
  77088. + * original XferSize size value for the descriptor.
  77089. + */
  77090. + uint32_t *n_bytes;
  77091. +
  77092. + /** Actual number of transfer descriptors in a list. */
  77093. + uint16_t ntd;
  77094. +
  77095. + /** First activated isochronous transfer descriptor index. */
  77096. + uint8_t td_first;
  77097. + /** Last activated isochronous transfer descriptor index. */
  77098. + uint8_t td_last;
  77099. +
  77100. + /** @} */
  77101. +
  77102. +
  77103. + uint16_t speed;
  77104. + uint16_t frame_usecs[8];
  77105. +
  77106. + uint32_t skip_count;
  77107. +} dwc_otg_qh_t;
  77108. +
  77109. +DWC_CIRCLEQ_HEAD(hc_list, dwc_hc);
  77110. +
  77111. +typedef struct urb_tq_entry {
  77112. + struct urb *urb;
  77113. + DWC_TAILQ_ENTRY(urb_tq_entry) urb_tq_entries;
  77114. +} urb_tq_entry_t;
  77115. +
  77116. +DWC_TAILQ_HEAD(urb_list, urb_tq_entry);
  77117. +
  77118. +/**
  77119. + * This structure holds the state of the HCD, including the non-periodic and
  77120. + * periodic schedules.
  77121. + */
  77122. +struct dwc_otg_hcd {
  77123. + /** The DWC otg device pointer */
  77124. + struct dwc_otg_device *otg_dev;
  77125. + /** DWC OTG Core Interface Layer */
  77126. + dwc_otg_core_if_t *core_if;
  77127. +
  77128. + /** Function HCD driver callbacks */
  77129. + struct dwc_otg_hcd_function_ops *fops;
  77130. +
  77131. + /** Internal DWC HCD Flags */
  77132. + volatile union dwc_otg_hcd_internal_flags {
  77133. + uint32_t d32;
  77134. + struct {
  77135. + unsigned port_connect_status_change:1;
  77136. + unsigned port_connect_status:1;
  77137. + unsigned port_reset_change:1;
  77138. + unsigned port_enable_change:1;
  77139. + unsigned port_suspend_change:1;
  77140. + unsigned port_over_current_change:1;
  77141. + unsigned port_l1_change:1;
  77142. + unsigned reserved:26;
  77143. + } b;
  77144. + } flags;
  77145. +
  77146. + /**
  77147. + * Inactive items in the non-periodic schedule. This is a list of
  77148. + * Queue Heads. Transfers associated with these Queue Heads are not
  77149. + * currently assigned to a host channel.
  77150. + */
  77151. + dwc_list_link_t non_periodic_sched_inactive;
  77152. +
  77153. + /**
  77154. + * Active items in the non-periodic schedule. This is a list of
  77155. + * Queue Heads. Transfers associated with these Queue Heads are
  77156. + * currently assigned to a host channel.
  77157. + */
  77158. + dwc_list_link_t non_periodic_sched_active;
  77159. +
  77160. + /**
  77161. + * Pointer to the next Queue Head to process in the active
  77162. + * non-periodic schedule.
  77163. + */
  77164. + dwc_list_link_t *non_periodic_qh_ptr;
  77165. +
  77166. + /**
  77167. + * Inactive items in the periodic schedule. This is a list of QHs for
  77168. + * periodic transfers that are _not_ scheduled for the next frame.
  77169. + * Each QH in the list has an interval counter that determines when it
  77170. + * needs to be scheduled for execution. This scheduling mechanism
  77171. + * allows only a simple calculation for periodic bandwidth used (i.e.
  77172. + * must assume that all periodic transfers may need to execute in the
  77173. + * same frame). However, it greatly simplifies scheduling and should
  77174. + * be sufficient for the vast majority of OTG hosts, which need to
  77175. + * connect to a small number of peripherals at one time.
  77176. + *
  77177. + * Items move from this list to periodic_sched_ready when the QH
  77178. + * interval counter is 0 at SOF.
  77179. + */
  77180. + dwc_list_link_t periodic_sched_inactive;
  77181. +
  77182. + /**
  77183. + * List of periodic QHs that are ready for execution in the next
  77184. + * frame, but have not yet been assigned to host channels.
  77185. + *
  77186. + * Items move from this list to periodic_sched_assigned as host
  77187. + * channels become available during the current frame.
  77188. + */
  77189. + dwc_list_link_t periodic_sched_ready;
  77190. +
  77191. + /**
  77192. + * List of periodic QHs to be executed in the next frame that are
  77193. + * assigned to host channels.
  77194. + *
  77195. + * Items move from this list to periodic_sched_queued as the
  77196. + * transactions for the QH are queued to the DWC_otg controller.
  77197. + */
  77198. + dwc_list_link_t periodic_sched_assigned;
  77199. +
  77200. + /**
  77201. + * List of periodic QHs that have been queued for execution.
  77202. + *
  77203. + * Items move from this list to either periodic_sched_inactive or
  77204. + * periodic_sched_ready when the channel associated with the transfer
  77205. + * is released. If the interval for the QH is 1, the item moves to
  77206. + * periodic_sched_ready because it must be rescheduled for the next
  77207. + * frame. Otherwise, the item moves to periodic_sched_inactive.
  77208. + */
  77209. + dwc_list_link_t periodic_sched_queued;
  77210. +
  77211. + /**
  77212. + * Total bandwidth claimed so far for periodic transfers. This value
  77213. + * is in microseconds per (micro)frame. The assumption is that all
  77214. + * periodic transfers may occur in the same (micro)frame.
  77215. + */
  77216. + uint16_t periodic_usecs;
  77217. +
  77218. + /**
  77219. + * Total bandwidth claimed so far for all periodic transfers
  77220. + * in a frame.
  77221. + * This will include a mixture of HS and FS transfers.
  77222. + * Units are microseconds per (micro)frame.
  77223. + * We have a budget per frame and have to schedule
  77224. + * transactions accordingly.
  77225. + * Watch out for the fact that things are actually scheduled for the
  77226. + * "next frame".
  77227. + */
  77228. + uint16_t frame_usecs[8];
  77229. +
  77230. +
  77231. + /**
  77232. + * Frame number read from the core at SOF. The value ranges from 0 to
  77233. + * DWC_HFNUM_MAX_FRNUM.
  77234. + */
  77235. + uint16_t frame_number;
  77236. +
  77237. + /**
  77238. + * Count of periodic QHs, if using several eps. For SOF enable/disable.
  77239. + */
  77240. + uint16_t periodic_qh_count;
  77241. +
  77242. + /**
  77243. + * Free host channels in the controller. This is a list of
  77244. + * dwc_hc_t items.
  77245. + */
  77246. + struct hc_list free_hc_list;
  77247. + /**
  77248. + * Number of host channels assigned to periodic transfers. Currently
  77249. + * assuming that there is a dedicated host channel for each periodic
  77250. + * transaction and at least one host channel available for
  77251. + * non-periodic transactions.
  77252. + */
  77253. + int periodic_channels; /* microframe_schedule==0 */
  77254. +
  77255. + /**
  77256. + * Number of host channels assigned to non-periodic transfers.
  77257. + */
  77258. + int non_periodic_channels; /* microframe_schedule==0 */
  77259. +
  77260. + /**
  77261. + * Number of host channels assigned to non-periodic transfers.
  77262. + */
  77263. + int available_host_channels;
  77264. +
  77265. + /**
  77266. + * Array of pointers to the host channel descriptors. Allows accessing
  77267. + * a host channel descriptor given the host channel number. This is
  77268. + * useful in interrupt handlers.
  77269. + */
  77270. + struct dwc_hc *hc_ptr_array[MAX_EPS_CHANNELS];
  77271. +
  77272. + /**
  77273. + * Buffer to use for any data received during the status phase of a
  77274. + * control transfer. Normally no data is transferred during the status
  77275. + * phase. This buffer is used as a bit bucket.
  77276. + */
  77277. + uint8_t *status_buf;
  77278. +
  77279. + /**
  77280. + * DMA address for status_buf.
  77281. + */
  77282. + dma_addr_t status_buf_dma;
  77283. +#define DWC_OTG_HCD_STATUS_BUF_SIZE 64
  77284. +
  77285. + /**
  77286. + * Connection timer. An OTG host must display a message if the device
  77287. + * does not connect. Started when the VBus power is turned on via
  77288. + * sysfs attribute "buspower".
  77289. + */
  77290. + dwc_timer_t *conn_timer;
  77291. +
  77292. + /* Tasket to do a reset */
  77293. + dwc_tasklet_t *reset_tasklet;
  77294. +
  77295. + dwc_tasklet_t *completion_tasklet;
  77296. + struct urb_list completed_urb_list;
  77297. +
  77298. + /* */
  77299. + dwc_spinlock_t *lock;
  77300. + dwc_spinlock_t *channel_lock;
  77301. + /**
  77302. + * Private data that could be used by OS wrapper.
  77303. + */
  77304. + void *priv;
  77305. +
  77306. + uint8_t otg_port;
  77307. +
  77308. + /** Frame List */
  77309. + uint32_t *frame_list;
  77310. +
  77311. + /** Hub - Port assignment */
  77312. + int hub_port[128];
  77313. +#ifdef FIQ_DEBUG
  77314. + int hub_port_alloc[2048];
  77315. +#endif
  77316. +
  77317. + /** Frame List DMA address */
  77318. + dma_addr_t frame_list_dma;
  77319. +
  77320. + struct fiq_stack *fiq_stack;
  77321. + struct fiq_state *fiq_state;
  77322. +
  77323. + /** Virtual address for split transaction DMA bounce buffers */
  77324. + struct fiq_dma_blob *fiq_dmab;
  77325. +
  77326. +#ifdef DEBUG
  77327. + uint32_t frrem_samples;
  77328. + uint64_t frrem_accum;
  77329. +
  77330. + uint32_t hfnum_7_samples_a;
  77331. + uint64_t hfnum_7_frrem_accum_a;
  77332. + uint32_t hfnum_0_samples_a;
  77333. + uint64_t hfnum_0_frrem_accum_a;
  77334. + uint32_t hfnum_other_samples_a;
  77335. + uint64_t hfnum_other_frrem_accum_a;
  77336. +
  77337. + uint32_t hfnum_7_samples_b;
  77338. + uint64_t hfnum_7_frrem_accum_b;
  77339. + uint32_t hfnum_0_samples_b;
  77340. + uint64_t hfnum_0_frrem_accum_b;
  77341. + uint32_t hfnum_other_samples_b;
  77342. + uint64_t hfnum_other_frrem_accum_b;
  77343. +#endif
  77344. +};
  77345. +
  77346. +/** @name Transaction Execution Functions */
  77347. +/** @{ */
  77348. +extern dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t
  77349. + * hcd);
  77350. +extern void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t * hcd,
  77351. + dwc_otg_transaction_type_e tr_type);
  77352. +
  77353. +int dwc_otg_hcd_allocate_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh);
  77354. +void dwc_otg_hcd_release_port(dwc_otg_hcd_t * dwc_otg_hcd, dwc_otg_qh_t *qh);
  77355. +
  77356. +extern int fiq_fsm_queue_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh);
  77357. +extern int fiq_fsm_transaction_suitable(dwc_otg_qh_t *qh);
  77358. +extern void dwc_otg_cleanup_fiq_channel(dwc_otg_hcd_t *hcd, uint32_t num);
  77359. +
  77360. +/** @} */
  77361. +
  77362. +/** @name Interrupt Handler Functions */
  77363. +/** @{ */
  77364. +extern int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  77365. +extern int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  77366. +extern int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t *
  77367. + dwc_otg_hcd);
  77368. +extern int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t *
  77369. + dwc_otg_hcd);
  77370. +extern int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t *
  77371. + dwc_otg_hcd);
  77372. +extern int32_t dwc_otg_hcd_handle_incomplete_periodic_intr(dwc_otg_hcd_t *
  77373. + dwc_otg_hcd);
  77374. +extern int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  77375. +extern int32_t dwc_otg_hcd_handle_conn_id_status_change_intr(dwc_otg_hcd_t *
  77376. + dwc_otg_hcd);
  77377. +extern int32_t dwc_otg_hcd_handle_disconnect_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  77378. +extern int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  77379. +extern int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t * dwc_otg_hcd,
  77380. + uint32_t num);
  77381. +extern int32_t dwc_otg_hcd_handle_session_req_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  77382. +extern int32_t dwc_otg_hcd_handle_wakeup_detected_intr(dwc_otg_hcd_t *
  77383. + dwc_otg_hcd);
  77384. +/** @} */
  77385. +
  77386. +/** @name Schedule Queue Functions */
  77387. +/** @{ */
  77388. +
  77389. +/* Implemented in dwc_otg_hcd_queue.c */
  77390. +extern dwc_otg_qh_t *dwc_otg_hcd_qh_create(dwc_otg_hcd_t * hcd,
  77391. + dwc_otg_hcd_urb_t * urb, int atomic_alloc);
  77392. +extern void dwc_otg_hcd_qh_free(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  77393. +extern int dwc_otg_hcd_qh_add(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  77394. +extern void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  77395. +extern void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  77396. + int sched_csplit);
  77397. +
  77398. +/** Remove and free a QH */
  77399. +static inline void dwc_otg_hcd_qh_remove_and_free(dwc_otg_hcd_t * hcd,
  77400. + dwc_otg_qh_t * qh)
  77401. +{
  77402. + dwc_irqflags_t flags;
  77403. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  77404. + dwc_otg_hcd_qh_remove(hcd, qh);
  77405. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  77406. + dwc_otg_hcd_qh_free(hcd, qh);
  77407. +}
  77408. +
  77409. +/** Allocates memory for a QH structure.
  77410. + * @return Returns the memory allocate or NULL on error. */
  77411. +static inline dwc_otg_qh_t *dwc_otg_hcd_qh_alloc(int atomic_alloc)
  77412. +{
  77413. + if (atomic_alloc)
  77414. + return (dwc_otg_qh_t *) DWC_ALLOC_ATOMIC(sizeof(dwc_otg_qh_t));
  77415. + else
  77416. + return (dwc_otg_qh_t *) DWC_ALLOC(sizeof(dwc_otg_qh_t));
  77417. +}
  77418. +
  77419. +extern dwc_otg_qtd_t *dwc_otg_hcd_qtd_create(dwc_otg_hcd_urb_t * urb,
  77420. + int atomic_alloc);
  77421. +extern void dwc_otg_hcd_qtd_init(dwc_otg_qtd_t * qtd, dwc_otg_hcd_urb_t * urb);
  77422. +extern int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t * qtd, dwc_otg_hcd_t * dwc_otg_hcd,
  77423. + dwc_otg_qh_t ** qh, int atomic_alloc);
  77424. +
  77425. +/** Allocates memory for a QTD structure.
  77426. + * @return Returns the memory allocate or NULL on error. */
  77427. +static inline dwc_otg_qtd_t *dwc_otg_hcd_qtd_alloc(int atomic_alloc)
  77428. +{
  77429. + if (atomic_alloc)
  77430. + return (dwc_otg_qtd_t *) DWC_ALLOC_ATOMIC(sizeof(dwc_otg_qtd_t));
  77431. + else
  77432. + return (dwc_otg_qtd_t *) DWC_ALLOC(sizeof(dwc_otg_qtd_t));
  77433. +}
  77434. +
  77435. +/** Frees the memory for a QTD structure. QTD should already be removed from
  77436. + * list.
  77437. + * @param qtd QTD to free.*/
  77438. +static inline void dwc_otg_hcd_qtd_free(dwc_otg_qtd_t * qtd)
  77439. +{
  77440. + DWC_FREE(qtd);
  77441. +}
  77442. +
  77443. +/** Removes a QTD from list.
  77444. + * @param hcd HCD instance.
  77445. + * @param qtd QTD to remove from list.
  77446. + * @param qh QTD belongs to.
  77447. + */
  77448. +static inline void dwc_otg_hcd_qtd_remove(dwc_otg_hcd_t * hcd,
  77449. + dwc_otg_qtd_t * qtd,
  77450. + dwc_otg_qh_t * qh)
  77451. +{
  77452. + DWC_CIRCLEQ_REMOVE(&qh->qtd_list, qtd, qtd_list_entry);
  77453. +}
  77454. +
  77455. +/** Remove and free a QTD
  77456. + * Need to disable IRQ and hold hcd lock while calling this function out of
  77457. + * interrupt servicing chain */
  77458. +static inline void dwc_otg_hcd_qtd_remove_and_free(dwc_otg_hcd_t * hcd,
  77459. + dwc_otg_qtd_t * qtd,
  77460. + dwc_otg_qh_t * qh)
  77461. +{
  77462. + dwc_otg_hcd_qtd_remove(hcd, qtd, qh);
  77463. + dwc_otg_hcd_qtd_free(qtd);
  77464. +}
  77465. +
  77466. +/** @} */
  77467. +
  77468. +/** @name Descriptor DMA Supporting Functions */
  77469. +/** @{ */
  77470. +
  77471. +extern void dwc_otg_hcd_start_xfer_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  77472. +extern void dwc_otg_hcd_complete_xfer_ddma(dwc_otg_hcd_t * hcd,
  77473. + dwc_hc_t * hc,
  77474. + dwc_otg_hc_regs_t * hc_regs,
  77475. + dwc_otg_halt_status_e halt_status);
  77476. +
  77477. +extern int dwc_otg_hcd_qh_init_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  77478. +extern void dwc_otg_hcd_qh_free_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  77479. +
  77480. +/** @} */
  77481. +
  77482. +/** @name Internal Functions */
  77483. +/** @{ */
  77484. +dwc_otg_qh_t *dwc_urb_to_qh(dwc_otg_hcd_urb_t * urb);
  77485. +/** @} */
  77486. +
  77487. +#ifdef CONFIG_USB_DWC_OTG_LPM
  77488. +extern int dwc_otg_hcd_get_hc_for_lpm_tran(dwc_otg_hcd_t * hcd,
  77489. + uint8_t devaddr);
  77490. +extern void dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd_t * hcd);
  77491. +#endif
  77492. +
  77493. +/** Gets the QH that contains the list_head */
  77494. +#define dwc_list_to_qh(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qh_t, qh_list_entry)
  77495. +
  77496. +/** Gets the QTD that contains the list_head */
  77497. +#define dwc_list_to_qtd(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qtd_t, qtd_list_entry)
  77498. +
  77499. +/** Check if QH is non-periodic */
  77500. +#define dwc_qh_is_non_per(_qh_ptr_) ((_qh_ptr_->ep_type == UE_BULK) || \
  77501. + (_qh_ptr_->ep_type == UE_CONTROL))
  77502. +
  77503. +/** High bandwidth multiplier as encoded in highspeed endpoint descriptors */
  77504. +#define dwc_hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
  77505. +
  77506. +/** Packet size for any kind of endpoint descriptor */
  77507. +#define dwc_max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
  77508. +
  77509. +/**
  77510. + * Returns true if _frame1 is less than or equal to _frame2. The comparison is
  77511. + * done modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the
  77512. + * frame number when the max frame number is reached.
  77513. + */
  77514. +static inline int dwc_frame_num_le(uint16_t frame1, uint16_t frame2)
  77515. +{
  77516. + return ((frame2 - frame1) & DWC_HFNUM_MAX_FRNUM) <=
  77517. + (DWC_HFNUM_MAX_FRNUM >> 1);
  77518. +}
  77519. +
  77520. +/**
  77521. + * Returns true if _frame1 is greater than _frame2. The comparison is done
  77522. + * modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the frame
  77523. + * number when the max frame number is reached.
  77524. + */
  77525. +static inline int dwc_frame_num_gt(uint16_t frame1, uint16_t frame2)
  77526. +{
  77527. + return (frame1 != frame2) &&
  77528. + (((frame1 - frame2) & DWC_HFNUM_MAX_FRNUM) <
  77529. + (DWC_HFNUM_MAX_FRNUM >> 1));
  77530. +}
  77531. +
  77532. +/**
  77533. + * Increments _frame by the amount specified by _inc. The addition is done
  77534. + * modulo DWC_HFNUM_MAX_FRNUM. Returns the incremented value.
  77535. + */
  77536. +static inline uint16_t dwc_frame_num_inc(uint16_t frame, uint16_t inc)
  77537. +{
  77538. + return (frame + inc) & DWC_HFNUM_MAX_FRNUM;
  77539. +}
  77540. +
  77541. +static inline uint16_t dwc_full_frame_num(uint16_t frame)
  77542. +{
  77543. + return (frame & DWC_HFNUM_MAX_FRNUM) >> 3;
  77544. +}
  77545. +
  77546. +static inline uint16_t dwc_micro_frame_num(uint16_t frame)
  77547. +{
  77548. + return frame & 0x7;
  77549. +}
  77550. +
  77551. +void dwc_otg_hcd_save_data_toggle(dwc_hc_t * hc,
  77552. + dwc_otg_hc_regs_t * hc_regs,
  77553. + dwc_otg_qtd_t * qtd);
  77554. +
  77555. +#ifdef DEBUG
  77556. +/**
  77557. + * Macro to sample the remaining PHY clocks left in the current frame. This
  77558. + * may be used during debugging to determine the average time it takes to
  77559. + * execute sections of code. There are two possible sample points, "a" and
  77560. + * "b", so the _letter argument must be one of these values.
  77561. + *
  77562. + * To dump the average sample times, read the "hcd_frrem" sysfs attribute. For
  77563. + * example, "cat /sys/devices/lm0/hcd_frrem".
  77564. + */
  77565. +#define dwc_sample_frrem(_hcd, _qh, _letter) \
  77566. +{ \
  77567. + hfnum_data_t hfnum; \
  77568. + dwc_otg_qtd_t *qtd; \
  77569. + qtd = list_entry(_qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry); \
  77570. + if (usb_pipeint(qtd->urb->pipe) && _qh->start_split_frame != 0 && !qtd->complete_split) { \
  77571. + hfnum.d32 = DWC_READ_REG32(&_hcd->core_if->host_if->host_global_regs->hfnum); \
  77572. + switch (hfnum.b.frnum & 0x7) { \
  77573. + case 7: \
  77574. + _hcd->hfnum_7_samples_##_letter++; \
  77575. + _hcd->hfnum_7_frrem_accum_##_letter += hfnum.b.frrem; \
  77576. + break; \
  77577. + case 0: \
  77578. + _hcd->hfnum_0_samples_##_letter++; \
  77579. + _hcd->hfnum_0_frrem_accum_##_letter += hfnum.b.frrem; \
  77580. + break; \
  77581. + default: \
  77582. + _hcd->hfnum_other_samples_##_letter++; \
  77583. + _hcd->hfnum_other_frrem_accum_##_letter += hfnum.b.frrem; \
  77584. + break; \
  77585. + } \
  77586. + } \
  77587. +}
  77588. +#else
  77589. +#define dwc_sample_frrem(_hcd, _qh, _letter)
  77590. +#endif
  77591. +#endif
  77592. +#endif /* DWC_DEVICE_ONLY */
  77593. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h
  77594. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h 1970-01-01 01:00:00.000000000 +0100
  77595. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h 2014-07-07 10:45:43.000000000 +0200
  77596. @@ -0,0 +1,417 @@
  77597. +/* ==========================================================================
  77598. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_if.h $
  77599. + * $Revision: #12 $
  77600. + * $Date: 2011/10/26 $
  77601. + * $Change: 1873028 $
  77602. + *
  77603. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  77604. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  77605. + * otherwise expressly agreed to in writing between Synopsys and you.
  77606. + *
  77607. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  77608. + * any End User Software License Agreement or Agreement for Licensed Product
  77609. + * with Synopsys or any supplement thereto. You are permitted to use and
  77610. + * redistribute this Software in source and binary forms, with or without
  77611. + * modification, provided that redistributions of source code must retain this
  77612. + * notice. You may not view, use, disclose, copy or distribute this file or
  77613. + * any information contained herein except pursuant to this license grant from
  77614. + * Synopsys. If you do not agree with this notice, including the disclaimer
  77615. + * below, then you are not authorized to use the Software.
  77616. + *
  77617. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  77618. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  77619. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  77620. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  77621. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  77622. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  77623. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  77624. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  77625. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  77626. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  77627. + * DAMAGE.
  77628. + * ========================================================================== */
  77629. +#ifndef DWC_DEVICE_ONLY
  77630. +#ifndef __DWC_HCD_IF_H__
  77631. +#define __DWC_HCD_IF_H__
  77632. +
  77633. +#include "dwc_otg_core_if.h"
  77634. +
  77635. +/** @file
  77636. + * This file defines DWC_OTG HCD Core API.
  77637. + */
  77638. +
  77639. +struct dwc_otg_hcd;
  77640. +typedef struct dwc_otg_hcd dwc_otg_hcd_t;
  77641. +
  77642. +struct dwc_otg_hcd_urb;
  77643. +typedef struct dwc_otg_hcd_urb dwc_otg_hcd_urb_t;
  77644. +
  77645. +/** @name HCD Function Driver Callbacks */
  77646. +/** @{ */
  77647. +
  77648. +/** This function is called whenever core switches to host mode. */
  77649. +typedef int (*dwc_otg_hcd_start_cb_t) (dwc_otg_hcd_t * hcd);
  77650. +
  77651. +/** This function is called when device has been disconnected */
  77652. +typedef int (*dwc_otg_hcd_disconnect_cb_t) (dwc_otg_hcd_t * hcd);
  77653. +
  77654. +/** Wrapper provides this function to HCD to core, so it can get hub information to which device is connected */
  77655. +typedef int (*dwc_otg_hcd_hub_info_from_urb_cb_t) (dwc_otg_hcd_t * hcd,
  77656. + void *urb_handle,
  77657. + uint32_t * hub_addr,
  77658. + uint32_t * port_addr);
  77659. +/** Via this function HCD core gets device speed */
  77660. +typedef int (*dwc_otg_hcd_speed_from_urb_cb_t) (dwc_otg_hcd_t * hcd,
  77661. + void *urb_handle);
  77662. +
  77663. +/** This function is called when urb is completed */
  77664. +typedef int (*dwc_otg_hcd_complete_urb_cb_t) (dwc_otg_hcd_t * hcd,
  77665. + void *urb_handle,
  77666. + dwc_otg_hcd_urb_t * dwc_otg_urb,
  77667. + int32_t status);
  77668. +
  77669. +/** Via this function HCD core gets b_hnp_enable parameter */
  77670. +typedef int (*dwc_otg_hcd_get_b_hnp_enable) (dwc_otg_hcd_t * hcd);
  77671. +
  77672. +struct dwc_otg_hcd_function_ops {
  77673. + dwc_otg_hcd_start_cb_t start;
  77674. + dwc_otg_hcd_disconnect_cb_t disconnect;
  77675. + dwc_otg_hcd_hub_info_from_urb_cb_t hub_info;
  77676. + dwc_otg_hcd_speed_from_urb_cb_t speed;
  77677. + dwc_otg_hcd_complete_urb_cb_t complete;
  77678. + dwc_otg_hcd_get_b_hnp_enable get_b_hnp_enable;
  77679. +};
  77680. +/** @} */
  77681. +
  77682. +/** @name HCD Core API */
  77683. +/** @{ */
  77684. +/** This function allocates dwc_otg_hcd structure and returns pointer on it. */
  77685. +extern dwc_otg_hcd_t *dwc_otg_hcd_alloc_hcd(void);
  77686. +
  77687. +/** This function should be called to initiate HCD Core.
  77688. + *
  77689. + * @param hcd The HCD
  77690. + * @param core_if The DWC_OTG Core
  77691. + *
  77692. + * Returns -DWC_E_NO_MEMORY if no enough memory.
  77693. + * Returns 0 on success
  77694. + */
  77695. +extern int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd, dwc_otg_core_if_t * core_if);
  77696. +
  77697. +/** Frees HCD
  77698. + *
  77699. + * @param hcd The HCD
  77700. + */
  77701. +extern void dwc_otg_hcd_remove(dwc_otg_hcd_t * hcd);
  77702. +
  77703. +/** This function should be called on every hardware interrupt.
  77704. + *
  77705. + * @param dwc_otg_hcd The HCD
  77706. + *
  77707. + * Returns non zero if interrupt is handled
  77708. + * Return 0 if interrupt is not handled
  77709. + */
  77710. +extern int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  77711. +
  77712. +/** This function is used to handle the fast interrupt
  77713. + *
  77714. + */
  77715. +extern void __attribute__ ((naked)) dwc_otg_hcd_handle_fiq(void);
  77716. +
  77717. +/**
  77718. + * Returns private data set by
  77719. + * dwc_otg_hcd_set_priv_data function.
  77720. + *
  77721. + * @param hcd The HCD
  77722. + */
  77723. +extern void *dwc_otg_hcd_get_priv_data(dwc_otg_hcd_t * hcd);
  77724. +
  77725. +/**
  77726. + * Set private data.
  77727. + *
  77728. + * @param hcd The HCD
  77729. + * @param priv_data pointer to be stored in private data
  77730. + */
  77731. +extern void dwc_otg_hcd_set_priv_data(dwc_otg_hcd_t * hcd, void *priv_data);
  77732. +
  77733. +/**
  77734. + * This function initializes the HCD Core.
  77735. + *
  77736. + * @param hcd The HCD
  77737. + * @param fops The Function Driver Operations data structure containing pointers to all callbacks.
  77738. + *
  77739. + * Returns -DWC_E_NO_DEVICE if Core is currently is in device mode.
  77740. + * Returns 0 on success
  77741. + */
  77742. +extern int dwc_otg_hcd_start(dwc_otg_hcd_t * hcd,
  77743. + struct dwc_otg_hcd_function_ops *fops);
  77744. +
  77745. +/**
  77746. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  77747. + * stopped.
  77748. + *
  77749. + * @param hcd The HCD
  77750. + */
  77751. +extern void dwc_otg_hcd_stop(dwc_otg_hcd_t * hcd);
  77752. +
  77753. +/**
  77754. + * Handles hub class-specific requests.
  77755. + *
  77756. + * @param dwc_otg_hcd The HCD
  77757. + * @param typeReq Request Type
  77758. + * @param wValue wValue from control request
  77759. + * @param wIndex wIndex from control request
  77760. + * @param buf data buffer
  77761. + * @param wLength data buffer length
  77762. + *
  77763. + * Returns -DWC_E_INVALID if invalid argument is passed
  77764. + * Returns 0 on success
  77765. + */
  77766. +extern int dwc_otg_hcd_hub_control(dwc_otg_hcd_t * dwc_otg_hcd,
  77767. + uint16_t typeReq, uint16_t wValue,
  77768. + uint16_t wIndex, uint8_t * buf,
  77769. + uint16_t wLength);
  77770. +
  77771. +/**
  77772. + * Returns otg port number.
  77773. + *
  77774. + * @param hcd The HCD
  77775. + */
  77776. +extern uint32_t dwc_otg_hcd_otg_port(dwc_otg_hcd_t * hcd);
  77777. +
  77778. +/**
  77779. + * Returns OTG version - either 1.3 or 2.0.
  77780. + *
  77781. + * @param core_if The core_if structure pointer
  77782. + */
  77783. +extern uint16_t dwc_otg_get_otg_version(dwc_otg_core_if_t * core_if);
  77784. +
  77785. +/**
  77786. + * Returns 1 if currently core is acting as B host, and 0 otherwise.
  77787. + *
  77788. + * @param hcd The HCD
  77789. + */
  77790. +extern uint32_t dwc_otg_hcd_is_b_host(dwc_otg_hcd_t * hcd);
  77791. +
  77792. +/**
  77793. + * Returns current frame number.
  77794. + *
  77795. + * @param hcd The HCD
  77796. + */
  77797. +extern int dwc_otg_hcd_get_frame_number(dwc_otg_hcd_t * hcd);
  77798. +
  77799. +/**
  77800. + * Dumps hcd state.
  77801. + *
  77802. + * @param hcd The HCD
  77803. + */
  77804. +extern void dwc_otg_hcd_dump_state(dwc_otg_hcd_t * hcd);
  77805. +
  77806. +/**
  77807. + * Dump the average frame remaining at SOF. This can be used to
  77808. + * determine average interrupt latency. Frame remaining is also shown for
  77809. + * start transfer and two additional sample points.
  77810. + * Currently this function is not implemented.
  77811. + *
  77812. + * @param hcd The HCD
  77813. + */
  77814. +extern void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t * hcd);
  77815. +
  77816. +/**
  77817. + * Sends LPM transaction to the local device.
  77818. + *
  77819. + * @param hcd The HCD
  77820. + * @param devaddr Device Address
  77821. + * @param hird Host initiated resume duration
  77822. + * @param bRemoteWake Value of bRemoteWake field in LPM transaction
  77823. + *
  77824. + * Returns negative value if sending LPM transaction was not succeeded.
  77825. + * Returns 0 on success.
  77826. + */
  77827. +extern int dwc_otg_hcd_send_lpm(dwc_otg_hcd_t * hcd, uint8_t devaddr,
  77828. + uint8_t hird, uint8_t bRemoteWake);
  77829. +
  77830. +/* URB interface */
  77831. +
  77832. +/**
  77833. + * Allocates memory for dwc_otg_hcd_urb structure.
  77834. + * Allocated memory should be freed by call of DWC_FREE.
  77835. + *
  77836. + * @param hcd The HCD
  77837. + * @param iso_desc_count Count of ISOC descriptors
  77838. + * @param atomic_alloc Specefies whether to perform atomic allocation.
  77839. + */
  77840. +extern dwc_otg_hcd_urb_t *dwc_otg_hcd_urb_alloc(dwc_otg_hcd_t * hcd,
  77841. + int iso_desc_count,
  77842. + int atomic_alloc);
  77843. +
  77844. +/**
  77845. + * Set pipe information in URB.
  77846. + *
  77847. + * @param hcd_urb DWC_OTG URB
  77848. + * @param devaddr Device Address
  77849. + * @param ep_num Endpoint Number
  77850. + * @param ep_type Endpoint Type
  77851. + * @param ep_dir Endpoint Direction
  77852. + * @param mps Max Packet Size
  77853. + */
  77854. +extern void dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_hcd_urb_t * hcd_urb,
  77855. + uint8_t devaddr, uint8_t ep_num,
  77856. + uint8_t ep_type, uint8_t ep_dir,
  77857. + uint16_t mps);
  77858. +
  77859. +/* Transfer flags */
  77860. +#define URB_GIVEBACK_ASAP 0x1
  77861. +#define URB_SEND_ZERO_PACKET 0x2
  77862. +
  77863. +/**
  77864. + * Sets dwc_otg_hcd_urb parameters.
  77865. + *
  77866. + * @param urb DWC_OTG URB allocated by dwc_otg_hcd_urb_alloc function.
  77867. + * @param urb_handle Unique handle for request, this will be passed back
  77868. + * to function driver in completion callback.
  77869. + * @param buf The buffer for the data
  77870. + * @param dma The DMA buffer for the data
  77871. + * @param buflen Transfer length
  77872. + * @param sp Buffer for setup data
  77873. + * @param sp_dma DMA address of setup data buffer
  77874. + * @param flags Transfer flags
  77875. + * @param interval Polling interval for interrupt or isochronous transfers.
  77876. + */
  77877. +extern void dwc_otg_hcd_urb_set_params(dwc_otg_hcd_urb_t * urb,
  77878. + void *urb_handle, void *buf,
  77879. + dwc_dma_t dma, uint32_t buflen, void *sp,
  77880. + dwc_dma_t sp_dma, uint32_t flags,
  77881. + uint16_t interval);
  77882. +
  77883. +/** Gets status from dwc_otg_hcd_urb
  77884. + *
  77885. + * @param dwc_otg_urb DWC_OTG URB
  77886. + */
  77887. +extern uint32_t dwc_otg_hcd_urb_get_status(dwc_otg_hcd_urb_t * dwc_otg_urb);
  77888. +
  77889. +/** Gets actual length from dwc_otg_hcd_urb
  77890. + *
  77891. + * @param dwc_otg_urb DWC_OTG URB
  77892. + */
  77893. +extern uint32_t dwc_otg_hcd_urb_get_actual_length(dwc_otg_hcd_urb_t *
  77894. + dwc_otg_urb);
  77895. +
  77896. +/** Gets error count from dwc_otg_hcd_urb. Only for ISOC URBs
  77897. + *
  77898. + * @param dwc_otg_urb DWC_OTG URB
  77899. + */
  77900. +extern uint32_t dwc_otg_hcd_urb_get_error_count(dwc_otg_hcd_urb_t *
  77901. + dwc_otg_urb);
  77902. +
  77903. +/** Set ISOC descriptor offset and length
  77904. + *
  77905. + * @param dwc_otg_urb DWC_OTG URB
  77906. + * @param desc_num ISOC descriptor number
  77907. + * @param offset Offset from beginig of buffer.
  77908. + * @param length Transaction length
  77909. + */
  77910. +extern void dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  77911. + int desc_num, uint32_t offset,
  77912. + uint32_t length);
  77913. +
  77914. +/** Get status of ISOC descriptor, specified by desc_num
  77915. + *
  77916. + * @param dwc_otg_urb DWC_OTG URB
  77917. + * @param desc_num ISOC descriptor number
  77918. + */
  77919. +extern uint32_t dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_hcd_urb_t *
  77920. + dwc_otg_urb, int desc_num);
  77921. +
  77922. +/** Get actual length of ISOC descriptor, specified by desc_num
  77923. + *
  77924. + * @param dwc_otg_urb DWC_OTG URB
  77925. + * @param desc_num ISOC descriptor number
  77926. + */
  77927. +extern uint32_t dwc_otg_hcd_urb_get_iso_desc_actual_length(dwc_otg_hcd_urb_t *
  77928. + dwc_otg_urb,
  77929. + int desc_num);
  77930. +
  77931. +/** Queue URB. After transfer is completes, the complete callback will be called with the URB status
  77932. + *
  77933. + * @param dwc_otg_hcd The HCD
  77934. + * @param dwc_otg_urb DWC_OTG URB
  77935. + * @param ep_handle Out parameter for returning endpoint handle
  77936. + * @param atomic_alloc Flag to do atomic allocation if needed
  77937. + *
  77938. + * Returns -DWC_E_NO_DEVICE if no device is connected.
  77939. + * Returns -DWC_E_NO_MEMORY if there is no enough memory.
  77940. + * Returns 0 on success.
  77941. + */
  77942. +extern int dwc_otg_hcd_urb_enqueue(dwc_otg_hcd_t * dwc_otg_hcd,
  77943. + dwc_otg_hcd_urb_t * dwc_otg_urb,
  77944. + void **ep_handle, int atomic_alloc);
  77945. +
  77946. +/** De-queue the specified URB
  77947. + *
  77948. + * @param dwc_otg_hcd The HCD
  77949. + * @param dwc_otg_urb DWC_OTG URB
  77950. + */
  77951. +extern int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_t * dwc_otg_hcd,
  77952. + dwc_otg_hcd_urb_t * dwc_otg_urb);
  77953. +
  77954. +/** Frees resources in the DWC_otg controller related to a given endpoint.
  77955. + * Any URBs for the endpoint must already be dequeued.
  77956. + *
  77957. + * @param hcd The HCD
  77958. + * @param ep_handle Endpoint handle, returned by dwc_otg_hcd_urb_enqueue function
  77959. + * @param retry Number of retries if there are queued transfers.
  77960. + *
  77961. + * Returns -DWC_E_INVALID if invalid arguments are passed.
  77962. + * Returns 0 on success
  77963. + */
  77964. +extern int dwc_otg_hcd_endpoint_disable(dwc_otg_hcd_t * hcd, void *ep_handle,
  77965. + int retry);
  77966. +
  77967. +/* Resets the data toggle in qh structure. This function can be called from
  77968. + * usb_clear_halt routine.
  77969. + *
  77970. + * @param hcd The HCD
  77971. + * @param ep_handle Endpoint handle, returned by dwc_otg_hcd_urb_enqueue function
  77972. + *
  77973. + * Returns -DWC_E_INVALID if invalid arguments are passed.
  77974. + * Returns 0 on success
  77975. + */
  77976. +extern int dwc_otg_hcd_endpoint_reset(dwc_otg_hcd_t * hcd, void *ep_handle);
  77977. +
  77978. +/** Returns 1 if status of specified port is changed and 0 otherwise.
  77979. + *
  77980. + * @param hcd The HCD
  77981. + * @param port Port number
  77982. + */
  77983. +extern int dwc_otg_hcd_is_status_changed(dwc_otg_hcd_t * hcd, int port);
  77984. +
  77985. +/** Call this function to check if bandwidth was allocated for specified endpoint.
  77986. + * Only for ISOC and INTERRUPT endpoints.
  77987. + *
  77988. + * @param hcd The HCD
  77989. + * @param ep_handle Endpoint handle
  77990. + */
  77991. +extern int dwc_otg_hcd_is_bandwidth_allocated(dwc_otg_hcd_t * hcd,
  77992. + void *ep_handle);
  77993. +
  77994. +/** Call this function to check if bandwidth was freed for specified endpoint.
  77995. + *
  77996. + * @param hcd The HCD
  77997. + * @param ep_handle Endpoint handle
  77998. + */
  77999. +extern int dwc_otg_hcd_is_bandwidth_freed(dwc_otg_hcd_t * hcd, void *ep_handle);
  78000. +
  78001. +/** Returns bandwidth allocated for specified endpoint in microseconds.
  78002. + * Only for ISOC and INTERRUPT endpoints.
  78003. + *
  78004. + * @param hcd The HCD
  78005. + * @param ep_handle Endpoint handle
  78006. + */
  78007. +extern uint8_t dwc_otg_hcd_get_ep_bandwidth(dwc_otg_hcd_t * hcd,
  78008. + void *ep_handle);
  78009. +
  78010. +/** @} */
  78011. +
  78012. +#endif /* __DWC_HCD_IF_H__ */
  78013. +#endif /* DWC_DEVICE_ONLY */
  78014. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c
  78015. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c 1970-01-01 01:00:00.000000000 +0100
  78016. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c 2014-07-07 10:45:43.000000000 +0200
  78017. @@ -0,0 +1,2688 @@
  78018. +/* ==========================================================================
  78019. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_intr.c $
  78020. + * $Revision: #89 $
  78021. + * $Date: 2011/10/20 $
  78022. + * $Change: 1869487 $
  78023. + *
  78024. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  78025. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  78026. + * otherwise expressly agreed to in writing between Synopsys and you.
  78027. + *
  78028. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  78029. + * any End User Software License Agreement or Agreement for Licensed Product
  78030. + * with Synopsys or any supplement thereto. You are permitted to use and
  78031. + * redistribute this Software in source and binary forms, with or without
  78032. + * modification, provided that redistributions of source code must retain this
  78033. + * notice. You may not view, use, disclose, copy or distribute this file or
  78034. + * any information contained herein except pursuant to this license grant from
  78035. + * Synopsys. If you do not agree with this notice, including the disclaimer
  78036. + * below, then you are not authorized to use the Software.
  78037. + *
  78038. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  78039. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  78040. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  78041. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  78042. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  78043. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  78044. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  78045. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  78046. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  78047. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  78048. + * DAMAGE.
  78049. + * ========================================================================== */
  78050. +#ifndef DWC_DEVICE_ONLY
  78051. +
  78052. +#include "dwc_otg_hcd.h"
  78053. +#include "dwc_otg_regs.h"
  78054. +
  78055. +#include <linux/jiffies.h>
  78056. +#include <mach/hardware.h>
  78057. +#include <asm/fiq.h>
  78058. +
  78059. +
  78060. +extern bool microframe_schedule;
  78061. +
  78062. +/** @file
  78063. + * This file contains the implementation of the HCD Interrupt handlers.
  78064. + */
  78065. +
  78066. +int fiq_done, int_done;
  78067. +
  78068. +#ifdef FIQ_DEBUG
  78069. +char buffer[1000*16];
  78070. +int wptr;
  78071. +void notrace _fiq_print(FIQDBG_T dbg_lvl, char *fmt, ...)
  78072. +{
  78073. + FIQDBG_T dbg_lvl_req = FIQDBG_PORTHUB;
  78074. + va_list args;
  78075. + char text[17];
  78076. + hfnum_data_t hfnum = { .d32 = FIQ_READ(dwc_regs_base + 0x408) };
  78077. +
  78078. + if(dbg_lvl & dbg_lvl_req || dbg_lvl == FIQDBG_ERR)
  78079. + {
  78080. + local_fiq_disable();
  78081. + snprintf(text, 9, "%4d%d:%d ", hfnum.b.frnum/8, hfnum.b.frnum%8, 8 - hfnum.b.frrem/937);
  78082. + va_start(args, fmt);
  78083. + vsnprintf(text+8, 9, fmt, args);
  78084. + va_end(args);
  78085. +
  78086. + memcpy(buffer + wptr, text, 16);
  78087. + wptr = (wptr + 16) % sizeof(buffer);
  78088. + local_fiq_enable();
  78089. + }
  78090. +}
  78091. +#endif
  78092. +
  78093. +/** This function handles interrupts for the HCD. */
  78094. +int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  78095. +{
  78096. + int retval = 0;
  78097. + static int last_time;
  78098. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  78099. + gintsts_data_t gintsts;
  78100. + gintmsk_data_t gintmsk;
  78101. + hfnum_data_t hfnum;
  78102. + haintmsk_data_t haintmsk;
  78103. +
  78104. +#ifdef DEBUG
  78105. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  78106. +
  78107. +#endif
  78108. +
  78109. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  78110. + gintmsk.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  78111. +
  78112. + /* Exit from ISR if core is hibernated */
  78113. + if (core_if->hibernation_suspend == 1) {
  78114. + goto exit_handler_routine;
  78115. + }
  78116. + DWC_SPINLOCK(dwc_otg_hcd->lock);
  78117. + /* Check if HOST Mode */
  78118. + if (dwc_otg_is_host_mode(core_if)) {
  78119. + if (fiq_enable) {
  78120. + local_fiq_disable();
  78121. + /* Pull in from the FIQ's disabled mask */
  78122. + gintmsk.d32 = gintmsk.d32 | ~(dwc_otg_hcd->fiq_state->gintmsk_saved.d32);
  78123. + dwc_otg_hcd->fiq_state->gintmsk_saved.d32 = ~0;
  78124. + }
  78125. +
  78126. + if (fiq_fsm_enable && ( 0x0000FFFF & ~(dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint))) {
  78127. + gintsts.b.hcintr = 1;
  78128. + }
  78129. +
  78130. + /* Danger will robinson: fake a SOF if necessary */
  78131. + if (fiq_fsm_enable && (dwc_otg_hcd->fiq_state->gintmsk_saved.b.sofintr == 1)) {
  78132. + gintsts.b.sofintr = 1;
  78133. + }
  78134. + gintsts.d32 &= gintmsk.d32;
  78135. +
  78136. + if (fiq_enable)
  78137. + local_fiq_enable();
  78138. +
  78139. + if (!gintsts.d32) {
  78140. + goto exit_handler_routine;
  78141. + }
  78142. +
  78143. +#ifdef DEBUG
  78144. + // We should be OK doing this because the common interrupts should already have been serviced
  78145. + /* Don't print debug message in the interrupt handler on SOF */
  78146. +#ifndef DEBUG_SOF
  78147. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  78148. +#endif
  78149. + DWC_DEBUGPL(DBG_HCDI, "\n");
  78150. +#endif
  78151. +
  78152. +#ifdef DEBUG
  78153. +#ifndef DEBUG_SOF
  78154. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  78155. +#endif
  78156. + DWC_DEBUGPL(DBG_HCDI,
  78157. + "DWC OTG HCD Interrupt Detected gintsts&gintmsk=0x%08x core_if=%p\n",
  78158. + gintsts.d32, core_if);
  78159. +#endif
  78160. + hfnum.d32 = DWC_READ_REG32(&dwc_otg_hcd->core_if->host_if->host_global_regs->hfnum);
  78161. + if (gintsts.b.sofintr) {
  78162. + retval |= dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd);
  78163. + }
  78164. +
  78165. + if (gintsts.b.rxstsqlvl) {
  78166. + retval |=
  78167. + dwc_otg_hcd_handle_rx_status_q_level_intr
  78168. + (dwc_otg_hcd);
  78169. + }
  78170. + if (gintsts.b.nptxfempty) {
  78171. + retval |=
  78172. + dwc_otg_hcd_handle_np_tx_fifo_empty_intr
  78173. + (dwc_otg_hcd);
  78174. + }
  78175. + if (gintsts.b.i2cintr) {
  78176. + /** @todo Implement i2cintr handler. */
  78177. + }
  78178. + if (gintsts.b.portintr) {
  78179. +
  78180. + gintmsk_data_t gintmsk = { .b.portintr = 1};
  78181. + retval |= dwc_otg_hcd_handle_port_intr(dwc_otg_hcd);
  78182. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
  78183. + }
  78184. + if (gintsts.b.hcintr) {
  78185. + retval |= dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd);
  78186. + }
  78187. + if (gintsts.b.ptxfempty) {
  78188. + retval |=
  78189. + dwc_otg_hcd_handle_perio_tx_fifo_empty_intr
  78190. + (dwc_otg_hcd);
  78191. + }
  78192. +#ifdef DEBUG
  78193. +#ifndef DEBUG_SOF
  78194. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  78195. +#endif
  78196. + {
  78197. + DWC_DEBUGPL(DBG_HCDI,
  78198. + "DWC OTG HCD Finished Servicing Interrupts\n");
  78199. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintsts=0x%08x\n",
  78200. + DWC_READ_REG32(&global_regs->gintsts));
  78201. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintmsk=0x%08x\n",
  78202. + DWC_READ_REG32(&global_regs->gintmsk));
  78203. + }
  78204. +#endif
  78205. +
  78206. +#ifdef DEBUG
  78207. +#ifndef DEBUG_SOF
  78208. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  78209. +#endif
  78210. + DWC_DEBUGPL(DBG_HCDI, "\n");
  78211. +#endif
  78212. +
  78213. + }
  78214. +
  78215. +exit_handler_routine:
  78216. + if (fiq_enable) {
  78217. + gintmsk_data_t gintmsk_new;
  78218. + haintmsk_data_t haintmsk_new;
  78219. + local_fiq_disable();
  78220. + gintmsk_new.d32 = *(volatile uint32_t *)&dwc_otg_hcd->fiq_state->gintmsk_saved.d32;
  78221. + if(fiq_fsm_enable)
  78222. + haintmsk_new.d32 = *(volatile uint32_t *)&dwc_otg_hcd->fiq_state->haintmsk_saved.d32;
  78223. + else
  78224. + haintmsk_new.d32 = 0x0000FFFF;
  78225. +
  78226. + /* The FIQ could have sneaked another interrupt in. If so, don't clear MPHI */
  78227. + if ((gintmsk_new.d32 == ~0) && (haintmsk_new.d32 == 0x0000FFFF)) {
  78228. + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.intstat, (1<<16));
  78229. + if (dwc_otg_hcd->fiq_state->mphi_int_count >= 50) {
  78230. + fiq_print(FIQDBG_INT, dwc_otg_hcd->fiq_state, "MPHI CLR");
  78231. + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl, ((1<<31) + (1<<16)));
  78232. + while (!(DWC_READ_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl) & (1 << 17)))
  78233. + ;
  78234. + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl, (1<<31));
  78235. + dwc_otg_hcd->fiq_state->mphi_int_count = 0;
  78236. + }
  78237. + int_done++;
  78238. + }
  78239. + haintmsk.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->haintmsk);
  78240. + /* Re-enable interrupts that the FIQ masked (first time round) */
  78241. + FIQ_WRITE(dwc_otg_hcd->fiq_state->dwc_regs_base + GINTMSK, gintmsk.d32);
  78242. + local_fiq_enable();
  78243. +
  78244. + if ((jiffies / HZ) > last_time) {
  78245. + //dwc_otg_qh_t *qh;
  78246. + //dwc_list_link_t *cur;
  78247. + /* Once a second output the fiq and irq numbers, useful for debug */
  78248. + last_time = jiffies / HZ;
  78249. + // DWC_WARN("np_kick=%d AHC=%d sched_frame=%d cur_frame=%d int_done=%d fiq_done=%d",
  78250. + // dwc_otg_hcd->fiq_state->kick_np_queues, dwc_otg_hcd->available_host_channels,
  78251. + // dwc_otg_hcd->fiq_state->next_sched_frame, hfnum.b.frnum, int_done, dwc_otg_hcd->fiq_state->fiq_done);
  78252. + //printk(KERN_WARNING "Periodic queues:\n");
  78253. + }
  78254. + }
  78255. +
  78256. + DWC_SPINUNLOCK(dwc_otg_hcd->lock);
  78257. + return retval;
  78258. +}
  78259. +
  78260. +#ifdef DWC_TRACK_MISSED_SOFS
  78261. +
  78262. +#warning Compiling code to track missed SOFs
  78263. +#define FRAME_NUM_ARRAY_SIZE 1000
  78264. +/**
  78265. + * This function is for debug only.
  78266. + */
  78267. +static inline void track_missed_sofs(uint16_t curr_frame_number)
  78268. +{
  78269. + static uint16_t frame_num_array[FRAME_NUM_ARRAY_SIZE];
  78270. + static uint16_t last_frame_num_array[FRAME_NUM_ARRAY_SIZE];
  78271. + static int frame_num_idx = 0;
  78272. + static uint16_t last_frame_num = DWC_HFNUM_MAX_FRNUM;
  78273. + static int dumped_frame_num_array = 0;
  78274. +
  78275. + if (frame_num_idx < FRAME_NUM_ARRAY_SIZE) {
  78276. + if (((last_frame_num + 1) & DWC_HFNUM_MAX_FRNUM) !=
  78277. + curr_frame_number) {
  78278. + frame_num_array[frame_num_idx] = curr_frame_number;
  78279. + last_frame_num_array[frame_num_idx++] = last_frame_num;
  78280. + }
  78281. + } else if (!dumped_frame_num_array) {
  78282. + int i;
  78283. + DWC_PRINTF("Frame Last Frame\n");
  78284. + DWC_PRINTF("----- ----------\n");
  78285. + for (i = 0; i < FRAME_NUM_ARRAY_SIZE; i++) {
  78286. + DWC_PRINTF("0x%04x 0x%04x\n",
  78287. + frame_num_array[i], last_frame_num_array[i]);
  78288. + }
  78289. + dumped_frame_num_array = 1;
  78290. + }
  78291. + last_frame_num = curr_frame_number;
  78292. +}
  78293. +#endif
  78294. +
  78295. +/**
  78296. + * Handles the start-of-frame interrupt in host mode. Non-periodic
  78297. + * transactions may be queued to the DWC_otg controller for the current
  78298. + * (micro)frame. Periodic transactions may be queued to the controller for the
  78299. + * next (micro)frame.
  78300. + */
  78301. +int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * hcd)
  78302. +{
  78303. + hfnum_data_t hfnum;
  78304. + gintsts_data_t gintsts = { .d32 = 0 };
  78305. + dwc_list_link_t *qh_entry;
  78306. + dwc_otg_qh_t *qh;
  78307. + dwc_otg_transaction_type_e tr_type;
  78308. + int did_something = 0;
  78309. + int32_t next_sched_frame = -1;
  78310. +
  78311. + hfnum.d32 =
  78312. + DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
  78313. +
  78314. +#ifdef DEBUG_SOF
  78315. + DWC_DEBUGPL(DBG_HCD, "--Start of Frame Interrupt--\n");
  78316. +#endif
  78317. + hcd->frame_number = hfnum.b.frnum;
  78318. +
  78319. +#ifdef DEBUG
  78320. + hcd->frrem_accum += hfnum.b.frrem;
  78321. + hcd->frrem_samples++;
  78322. +#endif
  78323. +
  78324. +#ifdef DWC_TRACK_MISSED_SOFS
  78325. + track_missed_sofs(hcd->frame_number);
  78326. +#endif
  78327. + /* Determine whether any periodic QHs should be executed. */
  78328. + qh_entry = DWC_LIST_FIRST(&hcd->periodic_sched_inactive);
  78329. + while (qh_entry != &hcd->periodic_sched_inactive) {
  78330. + qh = DWC_LIST_ENTRY(qh_entry, dwc_otg_qh_t, qh_list_entry);
  78331. + qh_entry = qh_entry->next;
  78332. + if (dwc_frame_num_le(qh->sched_frame, hcd->frame_number)) {
  78333. +
  78334. + /*
  78335. + * Move QH to the ready list to be executed next
  78336. + * (micro)frame.
  78337. + */
  78338. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_ready,
  78339. + &qh->qh_list_entry);
  78340. +
  78341. + did_something = 1;
  78342. + }
  78343. + else
  78344. + {
  78345. + if(next_sched_frame < 0 || dwc_frame_num_le(qh->sched_frame, next_sched_frame))
  78346. + {
  78347. + next_sched_frame = qh->sched_frame;
  78348. + }
  78349. + }
  78350. + }
  78351. + if (fiq_enable)
  78352. + hcd->fiq_state->next_sched_frame = next_sched_frame;
  78353. +
  78354. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  78355. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  78356. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  78357. + did_something = 1;
  78358. + }
  78359. +
  78360. + /* Clear interrupt - but do not trample on the FIQ sof */
  78361. + if (!fiq_fsm_enable) {
  78362. + gintsts.b.sofintr = 1;
  78363. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->gintsts, gintsts.d32);
  78364. + }
  78365. + return 1;
  78366. +}
  78367. +
  78368. +/** Handles the Rx Status Queue Level Interrupt, which indicates that there is at
  78369. + * least one packet in the Rx FIFO. The packets are moved from the FIFO to
  78370. + * memory if the DWC_otg controller is operating in Slave mode. */
  78371. +int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  78372. +{
  78373. + host_grxsts_data_t grxsts;
  78374. + dwc_hc_t *hc = NULL;
  78375. +
  78376. + DWC_DEBUGPL(DBG_HCD, "--RxStsQ Level Interrupt--\n");
  78377. +
  78378. + grxsts.d32 =
  78379. + DWC_READ_REG32(&dwc_otg_hcd->core_if->core_global_regs->grxstsp);
  78380. +
  78381. + hc = dwc_otg_hcd->hc_ptr_array[grxsts.b.chnum];
  78382. + if (!hc) {
  78383. + DWC_ERROR("Unable to get corresponding channel\n");
  78384. + return 0;
  78385. + }
  78386. +
  78387. + /* Packet Status */
  78388. + DWC_DEBUGPL(DBG_HCDV, " Ch num = %d\n", grxsts.b.chnum);
  78389. + DWC_DEBUGPL(DBG_HCDV, " Count = %d\n", grxsts.b.bcnt);
  78390. + DWC_DEBUGPL(DBG_HCDV, " DPID = %d, hc.dpid = %d\n", grxsts.b.dpid,
  78391. + hc->data_pid_start);
  78392. + DWC_DEBUGPL(DBG_HCDV, " PStatus = %d\n", grxsts.b.pktsts);
  78393. +
  78394. + switch (grxsts.b.pktsts) {
  78395. + case DWC_GRXSTS_PKTSTS_IN:
  78396. + /* Read the data into the host buffer. */
  78397. + if (grxsts.b.bcnt > 0) {
  78398. + dwc_otg_read_packet(dwc_otg_hcd->core_if,
  78399. + hc->xfer_buff, grxsts.b.bcnt);
  78400. +
  78401. + /* Update the HC fields for the next packet received. */
  78402. + hc->xfer_count += grxsts.b.bcnt;
  78403. + hc->xfer_buff += grxsts.b.bcnt;
  78404. + }
  78405. +
  78406. + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
  78407. + case DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR:
  78408. + case DWC_GRXSTS_PKTSTS_CH_HALTED:
  78409. + /* Handled in interrupt, just ignore data */
  78410. + break;
  78411. + default:
  78412. + DWC_ERROR("RX_STS_Q Interrupt: Unknown status %d\n",
  78413. + grxsts.b.pktsts);
  78414. + break;
  78415. + }
  78416. +
  78417. + return 1;
  78418. +}
  78419. +
  78420. +/** This interrupt occurs when the non-periodic Tx FIFO is half-empty. More
  78421. + * data packets may be written to the FIFO for OUT transfers. More requests
  78422. + * may be written to the non-periodic request queue for IN transfers. This
  78423. + * interrupt is enabled only in Slave mode. */
  78424. +int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  78425. +{
  78426. + DWC_DEBUGPL(DBG_HCD, "--Non-Periodic TxFIFO Empty Interrupt--\n");
  78427. + dwc_otg_hcd_queue_transactions(dwc_otg_hcd,
  78428. + DWC_OTG_TRANSACTION_NON_PERIODIC);
  78429. + return 1;
  78430. +}
  78431. +
  78432. +/** This interrupt occurs when the periodic Tx FIFO is half-empty. More data
  78433. + * packets may be written to the FIFO for OUT transfers. More requests may be
  78434. + * written to the periodic request queue for IN transfers. This interrupt is
  78435. + * enabled only in Slave mode. */
  78436. +int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  78437. +{
  78438. + DWC_DEBUGPL(DBG_HCD, "--Periodic TxFIFO Empty Interrupt--\n");
  78439. + dwc_otg_hcd_queue_transactions(dwc_otg_hcd,
  78440. + DWC_OTG_TRANSACTION_PERIODIC);
  78441. + return 1;
  78442. +}
  78443. +
  78444. +/** There are multiple conditions that can cause a port interrupt. This function
  78445. + * determines which interrupt conditions have occurred and handles them
  78446. + * appropriately. */
  78447. +int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  78448. +{
  78449. + int retval = 0;
  78450. + hprt0_data_t hprt0;
  78451. + hprt0_data_t hprt0_modify;
  78452. +
  78453. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  78454. + hprt0_modify.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  78455. +
  78456. + /* Clear appropriate bits in HPRT0 to clear the interrupt bit in
  78457. + * GINTSTS */
  78458. +
  78459. + hprt0_modify.b.prtena = 0;
  78460. + hprt0_modify.b.prtconndet = 0;
  78461. + hprt0_modify.b.prtenchng = 0;
  78462. + hprt0_modify.b.prtovrcurrchng = 0;
  78463. +
  78464. + /* Port Connect Detected
  78465. + * Set flag and clear if detected */
  78466. + if (dwc_otg_hcd->core_if->hibernation_suspend == 1) {
  78467. + // Dont modify port status if we are in hibernation state
  78468. + hprt0_modify.b.prtconndet = 1;
  78469. + hprt0_modify.b.prtenchng = 1;
  78470. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
  78471. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  78472. + return retval;
  78473. + }
  78474. +
  78475. + if (hprt0.b.prtconndet) {
  78476. + /** @todo - check if steps performed in 'else' block should be perfromed regardles adp */
  78477. + if (dwc_otg_hcd->core_if->adp_enable &&
  78478. + dwc_otg_hcd->core_if->adp.vbuson_timer_started == 1) {
  78479. + DWC_PRINTF("PORT CONNECT DETECTED ----------------\n");
  78480. + DWC_TIMER_CANCEL(dwc_otg_hcd->core_if->adp.vbuson_timer);
  78481. + dwc_otg_hcd->core_if->adp.vbuson_timer_started = 0;
  78482. + /* TODO - check if this is required, as
  78483. + * host initialization was already performed
  78484. + * after initial ADP probing
  78485. + */
  78486. + /*dwc_otg_hcd->core_if->adp.vbuson_timer_started = 0;
  78487. + dwc_otg_core_init(dwc_otg_hcd->core_if);
  78488. + dwc_otg_enable_global_interrupts(dwc_otg_hcd->core_if);
  78489. + cil_hcd_start(dwc_otg_hcd->core_if);*/
  78490. + } else {
  78491. +
  78492. + DWC_DEBUGPL(DBG_HCD, "--Port Interrupt HPRT0=0x%08x "
  78493. + "Port Connect Detected--\n", hprt0.d32);
  78494. + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
  78495. + dwc_otg_hcd->flags.b.port_connect_status = 1;
  78496. + hprt0_modify.b.prtconndet = 1;
  78497. +
  78498. + /* B-Device has connected, Delete the connection timer. */
  78499. + DWC_TIMER_CANCEL(dwc_otg_hcd->conn_timer);
  78500. + }
  78501. + /* The Hub driver asserts a reset when it sees port connect
  78502. + * status change flag */
  78503. + retval |= 1;
  78504. + }
  78505. +
  78506. + /* Port Enable Changed
  78507. + * Clear if detected - Set internal flag if disabled */
  78508. + if (hprt0.b.prtenchng) {
  78509. + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
  78510. + "Port Enable Changed--\n", hprt0.d32);
  78511. + hprt0_modify.b.prtenchng = 1;
  78512. + if (hprt0.b.prtena == 1) {
  78513. + hfir_data_t hfir;
  78514. + int do_reset = 0;
  78515. + dwc_otg_core_params_t *params =
  78516. + dwc_otg_hcd->core_if->core_params;
  78517. + dwc_otg_core_global_regs_t *global_regs =
  78518. + dwc_otg_hcd->core_if->core_global_regs;
  78519. + dwc_otg_host_if_t *host_if =
  78520. + dwc_otg_hcd->core_if->host_if;
  78521. +
  78522. + /* Every time when port enables calculate
  78523. + * HFIR.FrInterval
  78524. + */
  78525. + hfir.d32 = DWC_READ_REG32(&host_if->host_global_regs->hfir);
  78526. + hfir.b.frint = calc_frame_interval(dwc_otg_hcd->core_if);
  78527. + DWC_WRITE_REG32(&host_if->host_global_regs->hfir, hfir.d32);
  78528. +
  78529. + /* Check if we need to adjust the PHY clock speed for
  78530. + * low power and adjust it */
  78531. + if (params->host_support_fs_ls_low_power) {
  78532. + gusbcfg_data_t usbcfg;
  78533. +
  78534. + usbcfg.d32 =
  78535. + DWC_READ_REG32(&global_regs->gusbcfg);
  78536. +
  78537. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED
  78538. + || hprt0.b.prtspd ==
  78539. + DWC_HPRT0_PRTSPD_FULL_SPEED) {
  78540. + /*
  78541. + * Low power
  78542. + */
  78543. + hcfg_data_t hcfg;
  78544. + if (usbcfg.b.phylpwrclksel == 0) {
  78545. + /* Set PHY low power clock select for FS/LS devices */
  78546. + usbcfg.b.phylpwrclksel = 1;
  78547. + DWC_WRITE_REG32
  78548. + (&global_regs->gusbcfg,
  78549. + usbcfg.d32);
  78550. + do_reset = 1;
  78551. + }
  78552. +
  78553. + hcfg.d32 =
  78554. + DWC_READ_REG32
  78555. + (&host_if->host_global_regs->hcfg);
  78556. +
  78557. + if (hprt0.b.prtspd ==
  78558. + DWC_HPRT0_PRTSPD_LOW_SPEED
  78559. + && params->host_ls_low_power_phy_clk
  78560. + ==
  78561. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ)
  78562. + {
  78563. + /* 6 MHZ */
  78564. + DWC_DEBUGPL(DBG_CIL,
  78565. + "FS_PHY programming HCFG to 6 MHz (Low Power)\n");
  78566. + if (hcfg.b.fslspclksel !=
  78567. + DWC_HCFG_6_MHZ) {
  78568. + hcfg.b.fslspclksel =
  78569. + DWC_HCFG_6_MHZ;
  78570. + DWC_WRITE_REG32
  78571. + (&host_if->host_global_regs->hcfg,
  78572. + hcfg.d32);
  78573. + do_reset = 1;
  78574. + }
  78575. + } else {
  78576. + /* 48 MHZ */
  78577. + DWC_DEBUGPL(DBG_CIL,
  78578. + "FS_PHY programming HCFG to 48 MHz ()\n");
  78579. + if (hcfg.b.fslspclksel !=
  78580. + DWC_HCFG_48_MHZ) {
  78581. + hcfg.b.fslspclksel =
  78582. + DWC_HCFG_48_MHZ;
  78583. + DWC_WRITE_REG32
  78584. + (&host_if->host_global_regs->hcfg,
  78585. + hcfg.d32);
  78586. + do_reset = 1;
  78587. + }
  78588. + }
  78589. + } else {
  78590. + /*
  78591. + * Not low power
  78592. + */
  78593. + if (usbcfg.b.phylpwrclksel == 1) {
  78594. + usbcfg.b.phylpwrclksel = 0;
  78595. + DWC_WRITE_REG32
  78596. + (&global_regs->gusbcfg,
  78597. + usbcfg.d32);
  78598. + do_reset = 1;
  78599. + }
  78600. + }
  78601. +
  78602. + if (do_reset) {
  78603. + DWC_TASK_SCHEDULE(dwc_otg_hcd->reset_tasklet);
  78604. + }
  78605. + }
  78606. +
  78607. + if (!do_reset) {
  78608. + /* Port has been enabled set the reset change flag */
  78609. + dwc_otg_hcd->flags.b.port_reset_change = 1;
  78610. + }
  78611. + } else {
  78612. + dwc_otg_hcd->flags.b.port_enable_change = 1;
  78613. + }
  78614. + retval |= 1;
  78615. + }
  78616. +
  78617. + /** Overcurrent Change Interrupt */
  78618. + if (hprt0.b.prtovrcurrchng) {
  78619. + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
  78620. + "Port Overcurrent Changed--\n", hprt0.d32);
  78621. + dwc_otg_hcd->flags.b.port_over_current_change = 1;
  78622. + hprt0_modify.b.prtovrcurrchng = 1;
  78623. + retval |= 1;
  78624. + }
  78625. +
  78626. + /* Clear Port Interrupts */
  78627. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
  78628. +
  78629. + return retval;
  78630. +}
  78631. +
  78632. +/** This interrupt indicates that one or more host channels has a pending
  78633. + * interrupt. There are multiple conditions that can cause each host channel
  78634. + * interrupt. This function determines which conditions have occurred for each
  78635. + * host channel interrupt and handles them appropriately. */
  78636. +int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  78637. +{
  78638. + int i;
  78639. + int retval = 0;
  78640. + haint_data_t haint = { .d32 = 0 } ;
  78641. +
  78642. + /* Clear appropriate bits in HCINTn to clear the interrupt bit in
  78643. + * GINTSTS */
  78644. +
  78645. + if (!fiq_fsm_enable)
  78646. + haint.d32 = dwc_otg_read_host_all_channels_intr(dwc_otg_hcd->core_if);
  78647. +
  78648. + // Overwrite with saved interrupts from fiq handler
  78649. + if(fiq_fsm_enable)
  78650. + {
  78651. + /* check the mask? */
  78652. + local_fiq_disable();
  78653. + haint.b2.chint |= ~(dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint);
  78654. + dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint = ~0;
  78655. + local_fiq_enable();
  78656. + }
  78657. +
  78658. + for (i = 0; i < dwc_otg_hcd->core_if->core_params->host_channels; i++) {
  78659. + if (haint.b2.chint & (1 << i)) {
  78660. + retval |= dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd, i);
  78661. + }
  78662. + }
  78663. +
  78664. + return retval;
  78665. +}
  78666. +
  78667. +/**
  78668. + * Gets the actual length of a transfer after the transfer halts. _halt_status
  78669. + * holds the reason for the halt.
  78670. + *
  78671. + * For IN transfers where halt_status is DWC_OTG_HC_XFER_COMPLETE,
  78672. + * *short_read is set to 1 upon return if less than the requested
  78673. + * number of bytes were transferred. Otherwise, *short_read is set to 0 upon
  78674. + * return. short_read may also be NULL on entry, in which case it remains
  78675. + * unchanged.
  78676. + */
  78677. +static uint32_t get_actual_xfer_length(dwc_hc_t * hc,
  78678. + dwc_otg_hc_regs_t * hc_regs,
  78679. + dwc_otg_qtd_t * qtd,
  78680. + dwc_otg_halt_status_e halt_status,
  78681. + int *short_read)
  78682. +{
  78683. + hctsiz_data_t hctsiz;
  78684. + uint32_t length;
  78685. +
  78686. + if (short_read != NULL) {
  78687. + *short_read = 0;
  78688. + }
  78689. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  78690. +
  78691. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  78692. + if (hc->ep_is_in) {
  78693. + length = hc->xfer_len - hctsiz.b.xfersize;
  78694. + if (short_read != NULL) {
  78695. + *short_read = (hctsiz.b.xfersize != 0);
  78696. + }
  78697. + } else if (hc->qh->do_split) {
  78698. + //length = split_out_xfersize[hc->hc_num];
  78699. + length = qtd->ssplit_out_xfer_count;
  78700. + } else {
  78701. + length = hc->xfer_len;
  78702. + }
  78703. + } else {
  78704. + /*
  78705. + * Must use the hctsiz.pktcnt field to determine how much data
  78706. + * has been transferred. This field reflects the number of
  78707. + * packets that have been transferred via the USB. This is
  78708. + * always an integral number of packets if the transfer was
  78709. + * halted before its normal completion. (Can't use the
  78710. + * hctsiz.xfersize field because that reflects the number of
  78711. + * bytes transferred via the AHB, not the USB).
  78712. + */
  78713. + length =
  78714. + (hc->start_pkt_count - hctsiz.b.pktcnt) * hc->max_packet;
  78715. + }
  78716. +
  78717. + return length;
  78718. +}
  78719. +
  78720. +/**
  78721. + * Updates the state of the URB after a Transfer Complete interrupt on the
  78722. + * host channel. Updates the actual_length field of the URB based on the
  78723. + * number of bytes transferred via the host channel. Sets the URB status
  78724. + * if the data transfer is finished.
  78725. + *
  78726. + * @return 1 if the data transfer specified by the URB is completely finished,
  78727. + * 0 otherwise.
  78728. + */
  78729. +static int update_urb_state_xfer_comp(dwc_hc_t * hc,
  78730. + dwc_otg_hc_regs_t * hc_regs,
  78731. + dwc_otg_hcd_urb_t * urb,
  78732. + dwc_otg_qtd_t * qtd)
  78733. +{
  78734. + int xfer_done = 0;
  78735. + int short_read = 0;
  78736. +
  78737. + int xfer_length;
  78738. +
  78739. + xfer_length = get_actual_xfer_length(hc, hc_regs, qtd,
  78740. + DWC_OTG_HC_XFER_COMPLETE,
  78741. + &short_read);
  78742. +
  78743. + /* non DWORD-aligned buffer case handling. */
  78744. + if (hc->align_buff && xfer_length && hc->ep_is_in) {
  78745. + dwc_memcpy(urb->buf + urb->actual_length, hc->qh->dw_align_buf,
  78746. + xfer_length);
  78747. + }
  78748. +
  78749. + urb->actual_length += xfer_length;
  78750. +
  78751. + if (xfer_length && (hc->ep_type == DWC_OTG_EP_TYPE_BULK) &&
  78752. + (urb->flags & URB_SEND_ZERO_PACKET)
  78753. + && (urb->actual_length == urb->length)
  78754. + && !(urb->length % hc->max_packet)) {
  78755. + xfer_done = 0;
  78756. + } else if (short_read || urb->actual_length >= urb->length) {
  78757. + xfer_done = 1;
  78758. + urb->status = 0;
  78759. + }
  78760. +
  78761. +#ifdef DEBUG
  78762. + {
  78763. + hctsiz_data_t hctsiz;
  78764. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  78765. + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
  78766. + __func__, (hc->ep_is_in ? "IN" : "OUT"),
  78767. + hc->hc_num);
  78768. + DWC_DEBUGPL(DBG_HCDV, " hc->xfer_len %d\n", hc->xfer_len);
  78769. + DWC_DEBUGPL(DBG_HCDV, " hctsiz.xfersize %d\n",
  78770. + hctsiz.b.xfersize);
  78771. + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
  78772. + urb->length);
  78773. + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n",
  78774. + urb->actual_length);
  78775. + DWC_DEBUGPL(DBG_HCDV, " short_read %d, xfer_done %d\n",
  78776. + short_read, xfer_done);
  78777. + }
  78778. +#endif
  78779. +
  78780. + return xfer_done;
  78781. +}
  78782. +
  78783. +/*
  78784. + * Save the starting data toggle for the next transfer. The data toggle is
  78785. + * saved in the QH for non-control transfers and it's saved in the QTD for
  78786. + * control transfers.
  78787. + */
  78788. +void dwc_otg_hcd_save_data_toggle(dwc_hc_t * hc,
  78789. + dwc_otg_hc_regs_t * hc_regs, dwc_otg_qtd_t * qtd)
  78790. +{
  78791. + hctsiz_data_t hctsiz;
  78792. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  78793. +
  78794. + if (hc->ep_type != DWC_OTG_EP_TYPE_CONTROL) {
  78795. + dwc_otg_qh_t *qh = hc->qh;
  78796. + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
  78797. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  78798. + } else {
  78799. + qh->data_toggle = DWC_OTG_HC_PID_DATA1;
  78800. + }
  78801. + } else {
  78802. + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
  78803. + qtd->data_toggle = DWC_OTG_HC_PID_DATA0;
  78804. + } else {
  78805. + qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
  78806. + }
  78807. + }
  78808. +}
  78809. +
  78810. +/**
  78811. + * Updates the state of an Isochronous URB when the transfer is stopped for
  78812. + * any reason. The fields of the current entry in the frame descriptor array
  78813. + * are set based on the transfer state and the input _halt_status. Completes
  78814. + * the Isochronous URB if all the URB frames have been completed.
  78815. + *
  78816. + * @return DWC_OTG_HC_XFER_COMPLETE if there are more frames remaining to be
  78817. + * transferred in the URB. Otherwise return DWC_OTG_HC_XFER_URB_COMPLETE.
  78818. + */
  78819. +static dwc_otg_halt_status_e
  78820. +update_isoc_urb_state(dwc_otg_hcd_t * hcd,
  78821. + dwc_hc_t * hc,
  78822. + dwc_otg_hc_regs_t * hc_regs,
  78823. + dwc_otg_qtd_t * qtd, dwc_otg_halt_status_e halt_status)
  78824. +{
  78825. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  78826. + dwc_otg_halt_status_e ret_val = halt_status;
  78827. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  78828. +
  78829. + frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
  78830. + switch (halt_status) {
  78831. + case DWC_OTG_HC_XFER_COMPLETE:
  78832. + frame_desc->status = 0;
  78833. + frame_desc->actual_length =
  78834. + get_actual_xfer_length(hc, hc_regs, qtd, halt_status, NULL);
  78835. +
  78836. + /* non DWORD-aligned buffer case handling. */
  78837. + if (hc->align_buff && frame_desc->actual_length && hc->ep_is_in) {
  78838. + dwc_memcpy(urb->buf + frame_desc->offset + qtd->isoc_split_offset,
  78839. + hc->qh->dw_align_buf, frame_desc->actual_length);
  78840. + }
  78841. +
  78842. + break;
  78843. + case DWC_OTG_HC_XFER_FRAME_OVERRUN:
  78844. + urb->error_count++;
  78845. + if (hc->ep_is_in) {
  78846. + frame_desc->status = -DWC_E_NO_STREAM_RES;
  78847. + } else {
  78848. + frame_desc->status = -DWC_E_COMMUNICATION;
  78849. + }
  78850. + frame_desc->actual_length = 0;
  78851. + break;
  78852. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  78853. + urb->error_count++;
  78854. + frame_desc->status = -DWC_E_OVERFLOW;
  78855. + /* Don't need to update actual_length in this case. */
  78856. + break;
  78857. + case DWC_OTG_HC_XFER_XACT_ERR:
  78858. + urb->error_count++;
  78859. + frame_desc->status = -DWC_E_PROTOCOL;
  78860. + frame_desc->actual_length =
  78861. + get_actual_xfer_length(hc, hc_regs, qtd, halt_status, NULL);
  78862. +
  78863. + /* non DWORD-aligned buffer case handling. */
  78864. + if (hc->align_buff && frame_desc->actual_length && hc->ep_is_in) {
  78865. + dwc_memcpy(urb->buf + frame_desc->offset + qtd->isoc_split_offset,
  78866. + hc->qh->dw_align_buf, frame_desc->actual_length);
  78867. + }
  78868. + /* Skip whole frame */
  78869. + if (hc->qh->do_split && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC) &&
  78870. + hc->ep_is_in && hcd->core_if->dma_enable) {
  78871. + qtd->complete_split = 0;
  78872. + qtd->isoc_split_offset = 0;
  78873. + }
  78874. +
  78875. + break;
  78876. + default:
  78877. + DWC_ASSERT(1, "Unhandled _halt_status (%d)\n", halt_status);
  78878. + break;
  78879. + }
  78880. + if (++qtd->isoc_frame_index == urb->packet_count) {
  78881. + /*
  78882. + * urb->status is not used for isoc transfers.
  78883. + * The individual frame_desc statuses are used instead.
  78884. + */
  78885. + hcd->fops->complete(hcd, urb->priv, urb, 0);
  78886. + ret_val = DWC_OTG_HC_XFER_URB_COMPLETE;
  78887. + } else {
  78888. + ret_val = DWC_OTG_HC_XFER_COMPLETE;
  78889. + }
  78890. + return ret_val;
  78891. +}
  78892. +
  78893. +/**
  78894. + * Frees the first QTD in the QH's list if free_qtd is 1. For non-periodic
  78895. + * QHs, removes the QH from the active non-periodic schedule. If any QTDs are
  78896. + * still linked to the QH, the QH is added to the end of the inactive
  78897. + * non-periodic schedule. For periodic QHs, removes the QH from the periodic
  78898. + * schedule if no more QTDs are linked to the QH.
  78899. + */
  78900. +static void deactivate_qh(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, int free_qtd)
  78901. +{
  78902. + int continue_split = 0;
  78903. + dwc_otg_qtd_t *qtd;
  78904. +
  78905. + DWC_DEBUGPL(DBG_HCDV, " %s(%p,%p,%d)\n", __func__, hcd, qh, free_qtd);
  78906. +
  78907. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  78908. +
  78909. + if (qtd->complete_split) {
  78910. + continue_split = 1;
  78911. + } else if (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_MID ||
  78912. + qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_END) {
  78913. + continue_split = 1;
  78914. + }
  78915. +
  78916. + if (free_qtd) {
  78917. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  78918. + continue_split = 0;
  78919. + }
  78920. +
  78921. + qh->channel = NULL;
  78922. + dwc_otg_hcd_qh_deactivate(hcd, qh, continue_split);
  78923. +}
  78924. +
  78925. +/**
  78926. + * Releases a host channel for use by other transfers. Attempts to select and
  78927. + * queue more transactions since at least one host channel is available.
  78928. + *
  78929. + * @param hcd The HCD state structure.
  78930. + * @param hc The host channel to release.
  78931. + * @param qtd The QTD associated with the host channel. This QTD may be freed
  78932. + * if the transfer is complete or an error has occurred.
  78933. + * @param halt_status Reason the channel is being released. This status
  78934. + * determines the actions taken by this function.
  78935. + */
  78936. +static void release_channel(dwc_otg_hcd_t * hcd,
  78937. + dwc_hc_t * hc,
  78938. + dwc_otg_qtd_t * qtd,
  78939. + dwc_otg_halt_status_e halt_status)
  78940. +{
  78941. + dwc_otg_transaction_type_e tr_type;
  78942. + int free_qtd;
  78943. + dwc_irqflags_t flags;
  78944. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  78945. +
  78946. + int hog_port = 0;
  78947. +
  78948. + DWC_DEBUGPL(DBG_HCDV, " %s: channel %d, halt_status %d, xfer_len %d\n",
  78949. + __func__, hc->hc_num, halt_status, hc->xfer_len);
  78950. +
  78951. + if(fiq_fsm_enable && hc->do_split) {
  78952. + if(!hc->ep_is_in && hc->ep_type == UE_ISOCHRONOUS) {
  78953. + if(hc->xact_pos == DWC_HCSPLIT_XACTPOS_MID ||
  78954. + hc->xact_pos == DWC_HCSPLIT_XACTPOS_BEGIN) {
  78955. + hog_port = 0;
  78956. + }
  78957. + }
  78958. + }
  78959. +
  78960. + switch (halt_status) {
  78961. + case DWC_OTG_HC_XFER_URB_COMPLETE:
  78962. + free_qtd = 1;
  78963. + break;
  78964. + case DWC_OTG_HC_XFER_AHB_ERR:
  78965. + case DWC_OTG_HC_XFER_STALL:
  78966. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  78967. + free_qtd = 1;
  78968. + break;
  78969. + case DWC_OTG_HC_XFER_XACT_ERR:
  78970. + if (qtd->error_count >= 3) {
  78971. + DWC_DEBUGPL(DBG_HCDV,
  78972. + " Complete URB with transaction error\n");
  78973. + free_qtd = 1;
  78974. + qtd->urb->status = -DWC_E_PROTOCOL;
  78975. + hcd->fops->complete(hcd, qtd->urb->priv,
  78976. + qtd->urb, -DWC_E_PROTOCOL);
  78977. + } else {
  78978. + free_qtd = 0;
  78979. + }
  78980. + break;
  78981. + case DWC_OTG_HC_XFER_URB_DEQUEUE:
  78982. + /*
  78983. + * The QTD has already been removed and the QH has been
  78984. + * deactivated. Don't want to do anything except release the
  78985. + * host channel and try to queue more transfers.
  78986. + */
  78987. + goto cleanup;
  78988. + case DWC_OTG_HC_XFER_NO_HALT_STATUS:
  78989. + free_qtd = 0;
  78990. + break;
  78991. + case DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE:
  78992. + DWC_DEBUGPL(DBG_HCDV,
  78993. + " Complete URB with I/O error\n");
  78994. + free_qtd = 1;
  78995. + qtd->urb->status = -DWC_E_IO;
  78996. + hcd->fops->complete(hcd, qtd->urb->priv,
  78997. + qtd->urb, -DWC_E_IO);
  78998. + break;
  78999. + default:
  79000. + free_qtd = 0;
  79001. + break;
  79002. + }
  79003. +
  79004. + deactivate_qh(hcd, hc->qh, free_qtd);
  79005. +
  79006. +cleanup:
  79007. + /*
  79008. + * Release the host channel for use by other transfers. The cleanup
  79009. + * function clears the channel interrupt enables and conditions, so
  79010. + * there's no need to clear the Channel Halted interrupt separately.
  79011. + */
  79012. + if (fiq_fsm_enable && hcd->fiq_state->channel[hc->hc_num].fsm != FIQ_PASSTHROUGH)
  79013. + dwc_otg_cleanup_fiq_channel(hcd, hc->hc_num);
  79014. + dwc_otg_hc_cleanup(hcd->core_if, hc);
  79015. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  79016. +
  79017. + if (!microframe_schedule) {
  79018. + switch (hc->ep_type) {
  79019. + case DWC_OTG_EP_TYPE_CONTROL:
  79020. + case DWC_OTG_EP_TYPE_BULK:
  79021. + hcd->non_periodic_channels--;
  79022. + break;
  79023. +
  79024. + default:
  79025. + /*
  79026. + * Don't release reservations for periodic channels here.
  79027. + * That's done when a periodic transfer is descheduled (i.e.
  79028. + * when the QH is removed from the periodic schedule).
  79029. + */
  79030. + break;
  79031. + }
  79032. + } else {
  79033. +
  79034. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  79035. + hcd->available_host_channels++;
  79036. + fiq_print(FIQDBG_INT, hcd->fiq_state, "AHC = %d ", hcd->available_host_channels);
  79037. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  79038. + }
  79039. +
  79040. + /* Try to queue more transfers now that there's a free channel. */
  79041. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  79042. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  79043. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  79044. + }
  79045. +}
  79046. +
  79047. +/**
  79048. + * Halts a host channel. If the channel cannot be halted immediately because
  79049. + * the request queue is full, this function ensures that the FIFO empty
  79050. + * interrupt for the appropriate queue is enabled so that the halt request can
  79051. + * be queued when there is space in the request queue.
  79052. + *
  79053. + * This function may also be called in DMA mode. In that case, the channel is
  79054. + * simply released since the core always halts the channel automatically in
  79055. + * DMA mode.
  79056. + */
  79057. +static void halt_channel(dwc_otg_hcd_t * hcd,
  79058. + dwc_hc_t * hc,
  79059. + dwc_otg_qtd_t * qtd, dwc_otg_halt_status_e halt_status)
  79060. +{
  79061. + if (hcd->core_if->dma_enable) {
  79062. + release_channel(hcd, hc, qtd, halt_status);
  79063. + return;
  79064. + }
  79065. +
  79066. + /* Slave mode processing... */
  79067. + dwc_otg_hc_halt(hcd->core_if, hc, halt_status);
  79068. +
  79069. + if (hc->halt_on_queue) {
  79070. + gintmsk_data_t gintmsk = {.d32 = 0 };
  79071. + dwc_otg_core_global_regs_t *global_regs;
  79072. + global_regs = hcd->core_if->core_global_regs;
  79073. +
  79074. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  79075. + hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
  79076. + /*
  79077. + * Make sure the Non-periodic Tx FIFO empty interrupt
  79078. + * is enabled so that the non-periodic schedule will
  79079. + * be processed.
  79080. + */
  79081. + gintmsk.b.nptxfempty = 1;
  79082. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmsk.d32);
  79083. + } else {
  79084. + /*
  79085. + * Move the QH from the periodic queued schedule to
  79086. + * the periodic assigned schedule. This allows the
  79087. + * halt to be queued when the periodic schedule is
  79088. + * processed.
  79089. + */
  79090. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  79091. + &hc->qh->qh_list_entry);
  79092. +
  79093. + /*
  79094. + * Make sure the Periodic Tx FIFO Empty interrupt is
  79095. + * enabled so that the periodic schedule will be
  79096. + * processed.
  79097. + */
  79098. + gintmsk.b.ptxfempty = 1;
  79099. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmsk.d32);
  79100. + }
  79101. + }
  79102. +}
  79103. +
  79104. +/**
  79105. + * Performs common cleanup for non-periodic transfers after a Transfer
  79106. + * Complete interrupt. This function should be called after any endpoint type
  79107. + * specific handling is finished to release the host channel.
  79108. + */
  79109. +static void complete_non_periodic_xfer(dwc_otg_hcd_t * hcd,
  79110. + dwc_hc_t * hc,
  79111. + dwc_otg_hc_regs_t * hc_regs,
  79112. + dwc_otg_qtd_t * qtd,
  79113. + dwc_otg_halt_status_e halt_status)
  79114. +{
  79115. + hcint_data_t hcint;
  79116. +
  79117. + qtd->error_count = 0;
  79118. +
  79119. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  79120. + if (hcint.b.nyet) {
  79121. + /*
  79122. + * Got a NYET on the last transaction of the transfer. This
  79123. + * means that the endpoint should be in the PING state at the
  79124. + * beginning of the next transfer.
  79125. + */
  79126. + hc->qh->ping_state = 1;
  79127. + clear_hc_int(hc_regs, nyet);
  79128. + }
  79129. +
  79130. + /*
  79131. + * Always halt and release the host channel to make it available for
  79132. + * more transfers. There may still be more phases for a control
  79133. + * transfer or more data packets for a bulk transfer at this point,
  79134. + * but the host channel is still halted. A channel will be reassigned
  79135. + * to the transfer when the non-periodic schedule is processed after
  79136. + * the channel is released. This allows transactions to be queued
  79137. + * properly via dwc_otg_hcd_queue_transactions, which also enables the
  79138. + * Tx FIFO Empty interrupt if necessary.
  79139. + */
  79140. + if (hc->ep_is_in) {
  79141. + /*
  79142. + * IN transfers in Slave mode require an explicit disable to
  79143. + * halt the channel. (In DMA mode, this call simply releases
  79144. + * the channel.)
  79145. + */
  79146. + halt_channel(hcd, hc, qtd, halt_status);
  79147. + } else {
  79148. + /*
  79149. + * The channel is automatically disabled by the core for OUT
  79150. + * transfers in Slave mode.
  79151. + */
  79152. + release_channel(hcd, hc, qtd, halt_status);
  79153. + }
  79154. +}
  79155. +
  79156. +/**
  79157. + * Performs common cleanup for periodic transfers after a Transfer Complete
  79158. + * interrupt. This function should be called after any endpoint type specific
  79159. + * handling is finished to release the host channel.
  79160. + */
  79161. +static void complete_periodic_xfer(dwc_otg_hcd_t * hcd,
  79162. + dwc_hc_t * hc,
  79163. + dwc_otg_hc_regs_t * hc_regs,
  79164. + dwc_otg_qtd_t * qtd,
  79165. + dwc_otg_halt_status_e halt_status)
  79166. +{
  79167. + hctsiz_data_t hctsiz;
  79168. + qtd->error_count = 0;
  79169. +
  79170. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  79171. + if (!hc->ep_is_in || hctsiz.b.pktcnt == 0) {
  79172. + /* Core halts channel in these cases. */
  79173. + release_channel(hcd, hc, qtd, halt_status);
  79174. + } else {
  79175. + /* Flush any outstanding requests from the Tx queue. */
  79176. + halt_channel(hcd, hc, qtd, halt_status);
  79177. + }
  79178. +}
  79179. +
  79180. +static int32_t handle_xfercomp_isoc_split_in(dwc_otg_hcd_t * hcd,
  79181. + dwc_hc_t * hc,
  79182. + dwc_otg_hc_regs_t * hc_regs,
  79183. + dwc_otg_qtd_t * qtd)
  79184. +{
  79185. + uint32_t len;
  79186. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  79187. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  79188. +
  79189. + len = get_actual_xfer_length(hc, hc_regs, qtd,
  79190. + DWC_OTG_HC_XFER_COMPLETE, NULL);
  79191. +
  79192. + if (!len) {
  79193. + qtd->complete_split = 0;
  79194. + qtd->isoc_split_offset = 0;
  79195. + return 0;
  79196. + }
  79197. + frame_desc->actual_length += len;
  79198. +
  79199. + if (hc->align_buff && len)
  79200. + dwc_memcpy(qtd->urb->buf + frame_desc->offset +
  79201. + qtd->isoc_split_offset, hc->qh->dw_align_buf, len);
  79202. + qtd->isoc_split_offset += len;
  79203. +
  79204. + if (frame_desc->length == frame_desc->actual_length) {
  79205. + frame_desc->status = 0;
  79206. + qtd->isoc_frame_index++;
  79207. + qtd->complete_split = 0;
  79208. + qtd->isoc_split_offset = 0;
  79209. + }
  79210. +
  79211. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  79212. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  79213. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  79214. + } else {
  79215. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  79216. + }
  79217. +
  79218. + return 1; /* Indicates that channel released */
  79219. +}
  79220. +
  79221. +/**
  79222. + * Handles a host channel Transfer Complete interrupt. This handler may be
  79223. + * called in either DMA mode or Slave mode.
  79224. + */
  79225. +static int32_t handle_hc_xfercomp_intr(dwc_otg_hcd_t * hcd,
  79226. + dwc_hc_t * hc,
  79227. + dwc_otg_hc_regs_t * hc_regs,
  79228. + dwc_otg_qtd_t * qtd)
  79229. +{
  79230. + int urb_xfer_done;
  79231. + dwc_otg_halt_status_e halt_status = DWC_OTG_HC_XFER_COMPLETE;
  79232. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  79233. + int pipe_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  79234. +
  79235. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  79236. + "Transfer Complete--\n", hc->hc_num);
  79237. +
  79238. + if (hcd->core_if->dma_desc_enable) {
  79239. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs, halt_status);
  79240. + if (pipe_type == UE_ISOCHRONOUS) {
  79241. + /* Do not disable the interrupt, just clear it */
  79242. + clear_hc_int(hc_regs, xfercomp);
  79243. + return 1;
  79244. + }
  79245. + goto handle_xfercomp_done;
  79246. + }
  79247. +
  79248. + /*
  79249. + * Handle xfer complete on CSPLIT.
  79250. + */
  79251. +
  79252. + if (hc->qh->do_split) {
  79253. + if ((hc->ep_type == DWC_OTG_EP_TYPE_ISOC) && hc->ep_is_in
  79254. + && hcd->core_if->dma_enable) {
  79255. + if (qtd->complete_split
  79256. + && handle_xfercomp_isoc_split_in(hcd, hc, hc_regs,
  79257. + qtd))
  79258. + goto handle_xfercomp_done;
  79259. + } else {
  79260. + qtd->complete_split = 0;
  79261. + }
  79262. + }
  79263. +
  79264. + /* Update the QTD and URB states. */
  79265. + switch (pipe_type) {
  79266. + case UE_CONTROL:
  79267. + switch (qtd->control_phase) {
  79268. + case DWC_OTG_CONTROL_SETUP:
  79269. + if (urb->length > 0) {
  79270. + qtd->control_phase = DWC_OTG_CONTROL_DATA;
  79271. + } else {
  79272. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  79273. + }
  79274. + DWC_DEBUGPL(DBG_HCDV,
  79275. + " Control setup transaction done\n");
  79276. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  79277. + break;
  79278. + case DWC_OTG_CONTROL_DATA:{
  79279. + urb_xfer_done =
  79280. + update_urb_state_xfer_comp(hc, hc_regs, urb,
  79281. + qtd);
  79282. + if (urb_xfer_done) {
  79283. + qtd->control_phase =
  79284. + DWC_OTG_CONTROL_STATUS;
  79285. + DWC_DEBUGPL(DBG_HCDV,
  79286. + " Control data transfer done\n");
  79287. + } else {
  79288. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  79289. + }
  79290. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  79291. + break;
  79292. + }
  79293. + case DWC_OTG_CONTROL_STATUS:
  79294. + DWC_DEBUGPL(DBG_HCDV, " Control transfer complete\n");
  79295. + if (urb->status == -DWC_E_IN_PROGRESS) {
  79296. + urb->status = 0;
  79297. + }
  79298. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  79299. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  79300. + break;
  79301. + }
  79302. +
  79303. + complete_non_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  79304. + break;
  79305. + case UE_BULK:
  79306. + DWC_DEBUGPL(DBG_HCDV, " Bulk transfer complete\n");
  79307. + urb_xfer_done =
  79308. + update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
  79309. + if (urb_xfer_done) {
  79310. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  79311. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  79312. + } else {
  79313. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  79314. + }
  79315. +
  79316. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  79317. + complete_non_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  79318. + break;
  79319. + case UE_INTERRUPT:
  79320. + DWC_DEBUGPL(DBG_HCDV, " Interrupt transfer complete\n");
  79321. + urb_xfer_done =
  79322. + update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
  79323. +
  79324. + /*
  79325. + * Interrupt URB is done on the first transfer complete
  79326. + * interrupt.
  79327. + */
  79328. + if (urb_xfer_done) {
  79329. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  79330. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  79331. + } else {
  79332. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  79333. + }
  79334. +
  79335. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  79336. + complete_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  79337. + break;
  79338. + case UE_ISOCHRONOUS:
  79339. + DWC_DEBUGPL(DBG_HCDV, " Isochronous transfer complete\n");
  79340. + if (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_ALL) {
  79341. + halt_status =
  79342. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  79343. + DWC_OTG_HC_XFER_COMPLETE);
  79344. + }
  79345. + complete_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  79346. + break;
  79347. + }
  79348. +
  79349. +handle_xfercomp_done:
  79350. + disable_hc_int(hc_regs, xfercompl);
  79351. +
  79352. + return 1;
  79353. +}
  79354. +
  79355. +/**
  79356. + * Handles a host channel STALL interrupt. This handler may be called in
  79357. + * either DMA mode or Slave mode.
  79358. + */
  79359. +static int32_t handle_hc_stall_intr(dwc_otg_hcd_t * hcd,
  79360. + dwc_hc_t * hc,
  79361. + dwc_otg_hc_regs_t * hc_regs,
  79362. + dwc_otg_qtd_t * qtd)
  79363. +{
  79364. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  79365. + int pipe_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  79366. +
  79367. + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
  79368. + "STALL Received--\n", hc->hc_num);
  79369. +
  79370. + if (hcd->core_if->dma_desc_enable) {
  79371. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs, DWC_OTG_HC_XFER_STALL);
  79372. + goto handle_stall_done;
  79373. + }
  79374. +
  79375. + if (pipe_type == UE_CONTROL) {
  79376. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_PIPE);
  79377. + }
  79378. +
  79379. + if (pipe_type == UE_BULK || pipe_type == UE_INTERRUPT) {
  79380. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_PIPE);
  79381. + /*
  79382. + * USB protocol requires resetting the data toggle for bulk
  79383. + * and interrupt endpoints when a CLEAR_FEATURE(ENDPOINT_HALT)
  79384. + * setup command is issued to the endpoint. Anticipate the
  79385. + * CLEAR_FEATURE command since a STALL has occurred and reset
  79386. + * the data toggle now.
  79387. + */
  79388. + hc->qh->data_toggle = 0;
  79389. + }
  79390. +
  79391. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_STALL);
  79392. +
  79393. +handle_stall_done:
  79394. + disable_hc_int(hc_regs, stall);
  79395. +
  79396. + return 1;
  79397. +}
  79398. +
  79399. +/*
  79400. + * Updates the state of the URB when a transfer has been stopped due to an
  79401. + * abnormal condition before the transfer completes. Modifies the
  79402. + * actual_length field of the URB to reflect the number of bytes that have
  79403. + * actually been transferred via the host channel.
  79404. + */
  79405. +static void update_urb_state_xfer_intr(dwc_hc_t * hc,
  79406. + dwc_otg_hc_regs_t * hc_regs,
  79407. + dwc_otg_hcd_urb_t * urb,
  79408. + dwc_otg_qtd_t * qtd,
  79409. + dwc_otg_halt_status_e halt_status)
  79410. +{
  79411. + uint32_t bytes_transferred = get_actual_xfer_length(hc, hc_regs, qtd,
  79412. + halt_status, NULL);
  79413. + /* non DWORD-aligned buffer case handling. */
  79414. + if (hc->align_buff && bytes_transferred && hc->ep_is_in) {
  79415. + dwc_memcpy(urb->buf + urb->actual_length, hc->qh->dw_align_buf,
  79416. + bytes_transferred);
  79417. + }
  79418. +
  79419. + urb->actual_length += bytes_transferred;
  79420. +
  79421. +#ifdef DEBUG
  79422. + {
  79423. + hctsiz_data_t hctsiz;
  79424. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  79425. + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
  79426. + __func__, (hc->ep_is_in ? "IN" : "OUT"),
  79427. + hc->hc_num);
  79428. + DWC_DEBUGPL(DBG_HCDV, " hc->start_pkt_count %d\n",
  79429. + hc->start_pkt_count);
  79430. + DWC_DEBUGPL(DBG_HCDV, " hctsiz.pktcnt %d\n", hctsiz.b.pktcnt);
  79431. + DWC_DEBUGPL(DBG_HCDV, " hc->max_packet %d\n", hc->max_packet);
  79432. + DWC_DEBUGPL(DBG_HCDV, " bytes_transferred %d\n",
  79433. + bytes_transferred);
  79434. + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n",
  79435. + urb->actual_length);
  79436. + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
  79437. + urb->length);
  79438. + }
  79439. +#endif
  79440. +}
  79441. +
  79442. +/**
  79443. + * Handles a host channel NAK interrupt. This handler may be called in either
  79444. + * DMA mode or Slave mode.
  79445. + */
  79446. +static int32_t handle_hc_nak_intr(dwc_otg_hcd_t * hcd,
  79447. + dwc_hc_t * hc,
  79448. + dwc_otg_hc_regs_t * hc_regs,
  79449. + dwc_otg_qtd_t * qtd)
  79450. +{
  79451. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  79452. + "NAK Received--\n", hc->hc_num);
  79453. +
  79454. + /*
  79455. + * When we get bulk NAKs then remember this so we holdoff on this qh until
  79456. + * the beginning of the next frame
  79457. + */
  79458. + switch(dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  79459. + case UE_BULK:
  79460. + case UE_CONTROL:
  79461. + if (nak_holdoff && qtd->qh->do_split)
  79462. + hc->qh->nak_frame = dwc_otg_hcd_get_frame_number(hcd);
  79463. + }
  79464. +
  79465. + /*
  79466. + * Handle NAK for IN/OUT SSPLIT/CSPLIT transfers, bulk, control, and
  79467. + * interrupt. Re-start the SSPLIT transfer.
  79468. + */
  79469. + if (hc->do_split) {
  79470. + if (hc->complete_split) {
  79471. + qtd->error_count = 0;
  79472. + }
  79473. + qtd->complete_split = 0;
  79474. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  79475. + goto handle_nak_done;
  79476. + }
  79477. +
  79478. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  79479. + case UE_CONTROL:
  79480. + case UE_BULK:
  79481. + if (hcd->core_if->dma_enable && hc->ep_is_in) {
  79482. + /*
  79483. + * NAK interrupts are enabled on bulk/control IN
  79484. + * transfers in DMA mode for the sole purpose of
  79485. + * resetting the error count after a transaction error
  79486. + * occurs. The core will continue transferring data.
  79487. + * Disable other interrupts unmasked for the same
  79488. + * reason.
  79489. + */
  79490. + disable_hc_int(hc_regs, datatglerr);
  79491. + disable_hc_int(hc_regs, ack);
  79492. + qtd->error_count = 0;
  79493. + goto handle_nak_done;
  79494. + }
  79495. +
  79496. + /*
  79497. + * NAK interrupts normally occur during OUT transfers in DMA
  79498. + * or Slave mode. For IN transfers, more requests will be
  79499. + * queued as request queue space is available.
  79500. + */
  79501. + qtd->error_count = 0;
  79502. +
  79503. + if (!hc->qh->ping_state) {
  79504. + update_urb_state_xfer_intr(hc, hc_regs,
  79505. + qtd->urb, qtd,
  79506. + DWC_OTG_HC_XFER_NAK);
  79507. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  79508. +
  79509. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH)
  79510. + hc->qh->ping_state = 1;
  79511. + }
  79512. +
  79513. + /*
  79514. + * Halt the channel so the transfer can be re-started from
  79515. + * the appropriate point or the PING protocol will
  79516. + * start/continue.
  79517. + */
  79518. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  79519. + break;
  79520. + case UE_INTERRUPT:
  79521. + qtd->error_count = 0;
  79522. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  79523. + break;
  79524. + case UE_ISOCHRONOUS:
  79525. + /* Should never get called for isochronous transfers. */
  79526. + DWC_ASSERT(1, "NACK interrupt for ISOC transfer\n");
  79527. + break;
  79528. + }
  79529. +
  79530. +handle_nak_done:
  79531. + disable_hc_int(hc_regs, nak);
  79532. +
  79533. + return 1;
  79534. +}
  79535. +
  79536. +/**
  79537. + * Handles a host channel ACK interrupt. This interrupt is enabled when
  79538. + * performing the PING protocol in Slave mode, when errors occur during
  79539. + * either Slave mode or DMA mode, and during Start Split transactions.
  79540. + */
  79541. +static int32_t handle_hc_ack_intr(dwc_otg_hcd_t * hcd,
  79542. + dwc_hc_t * hc,
  79543. + dwc_otg_hc_regs_t * hc_regs,
  79544. + dwc_otg_qtd_t * qtd)
  79545. +{
  79546. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  79547. + "ACK Received--\n", hc->hc_num);
  79548. +
  79549. + if (hc->do_split) {
  79550. + /*
  79551. + * Handle ACK on SSPLIT.
  79552. + * ACK should not occur in CSPLIT.
  79553. + */
  79554. + if (!hc->ep_is_in && hc->data_pid_start != DWC_OTG_HC_PID_SETUP) {
  79555. + qtd->ssplit_out_xfer_count = hc->xfer_len;
  79556. + }
  79557. + if (!(hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in)) {
  79558. + /* Don't need complete for isochronous out transfers. */
  79559. + qtd->complete_split = 1;
  79560. + }
  79561. +
  79562. + /* ISOC OUT */
  79563. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in) {
  79564. + switch (hc->xact_pos) {
  79565. + case DWC_HCSPLIT_XACTPOS_ALL:
  79566. + break;
  79567. + case DWC_HCSPLIT_XACTPOS_END:
  79568. + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
  79569. + qtd->isoc_split_offset = 0;
  79570. + break;
  79571. + case DWC_HCSPLIT_XACTPOS_BEGIN:
  79572. + case DWC_HCSPLIT_XACTPOS_MID:
  79573. + /*
  79574. + * For BEGIN or MID, calculate the length for
  79575. + * the next microframe to determine the correct
  79576. + * SSPLIT token, either MID or END.
  79577. + */
  79578. + {
  79579. + struct dwc_otg_hcd_iso_packet_desc
  79580. + *frame_desc;
  79581. +
  79582. + frame_desc =
  79583. + &qtd->urb->
  79584. + iso_descs[qtd->isoc_frame_index];
  79585. + qtd->isoc_split_offset += 188;
  79586. +
  79587. + if ((frame_desc->length -
  79588. + qtd->isoc_split_offset) <= 188) {
  79589. + qtd->isoc_split_pos =
  79590. + DWC_HCSPLIT_XACTPOS_END;
  79591. + } else {
  79592. + qtd->isoc_split_pos =
  79593. + DWC_HCSPLIT_XACTPOS_MID;
  79594. + }
  79595. +
  79596. + }
  79597. + break;
  79598. + }
  79599. + } else {
  79600. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_ACK);
  79601. + }
  79602. + } else {
  79603. + /*
  79604. + * An unmasked ACK on a non-split DMA transaction is
  79605. + * for the sole purpose of resetting error counts. Disable other
  79606. + * interrupts unmasked for the same reason.
  79607. + */
  79608. + if(hcd->core_if->dma_enable) {
  79609. + disable_hc_int(hc_regs, datatglerr);
  79610. + disable_hc_int(hc_regs, nak);
  79611. + }
  79612. + qtd->error_count = 0;
  79613. +
  79614. + if (hc->qh->ping_state) {
  79615. + hc->qh->ping_state = 0;
  79616. + /*
  79617. + * Halt the channel so the transfer can be re-started
  79618. + * from the appropriate point. This only happens in
  79619. + * Slave mode. In DMA mode, the ping_state is cleared
  79620. + * when the transfer is started because the core
  79621. + * automatically executes the PING, then the transfer.
  79622. + */
  79623. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_ACK);
  79624. + }
  79625. + }
  79626. +
  79627. + /*
  79628. + * If the ACK occurred when _not_ in the PING state, let the channel
  79629. + * continue transferring data after clearing the error count.
  79630. + */
  79631. +
  79632. + disable_hc_int(hc_regs, ack);
  79633. +
  79634. + return 1;
  79635. +}
  79636. +
  79637. +/**
  79638. + * Handles a host channel NYET interrupt. This interrupt should only occur on
  79639. + * Bulk and Control OUT endpoints and for complete split transactions. If a
  79640. + * NYET occurs at the same time as a Transfer Complete interrupt, it is
  79641. + * handled in the xfercomp interrupt handler, not here. This handler may be
  79642. + * called in either DMA mode or Slave mode.
  79643. + */
  79644. +static int32_t handle_hc_nyet_intr(dwc_otg_hcd_t * hcd,
  79645. + dwc_hc_t * hc,
  79646. + dwc_otg_hc_regs_t * hc_regs,
  79647. + dwc_otg_qtd_t * qtd)
  79648. +{
  79649. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  79650. + "NYET Received--\n", hc->hc_num);
  79651. +
  79652. + /*
  79653. + * NYET on CSPLIT
  79654. + * re-do the CSPLIT immediately on non-periodic
  79655. + */
  79656. + if (hc->do_split && hc->complete_split) {
  79657. + if (hc->ep_is_in && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  79658. + && hcd->core_if->dma_enable) {
  79659. + qtd->complete_split = 0;
  79660. + qtd->isoc_split_offset = 0;
  79661. + if (++qtd->isoc_frame_index == qtd->urb->packet_count) {
  79662. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  79663. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  79664. + }
  79665. + else
  79666. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  79667. + goto handle_nyet_done;
  79668. + }
  79669. +
  79670. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  79671. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  79672. + int frnum = dwc_otg_hcd_get_frame_number(hcd);
  79673. +
  79674. + // With the FIQ running we only ever see the failed NYET
  79675. + if (dwc_full_frame_num(frnum) !=
  79676. + dwc_full_frame_num(hc->qh->sched_frame) ||
  79677. + fiq_fsm_enable) {
  79678. + /*
  79679. + * No longer in the same full speed frame.
  79680. + * Treat this as a transaction error.
  79681. + */
  79682. +#if 0
  79683. + /** @todo Fix system performance so this can
  79684. + * be treated as an error. Right now complete
  79685. + * splits cannot be scheduled precisely enough
  79686. + * due to other system activity, so this error
  79687. + * occurs regularly in Slave mode.
  79688. + */
  79689. + qtd->error_count++;
  79690. +#endif
  79691. + qtd->complete_split = 0;
  79692. + halt_channel(hcd, hc, qtd,
  79693. + DWC_OTG_HC_XFER_XACT_ERR);
  79694. + /** @todo add support for isoc release */
  79695. + goto handle_nyet_done;
  79696. + }
  79697. + }
  79698. +
  79699. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NYET);
  79700. + goto handle_nyet_done;
  79701. + }
  79702. +
  79703. + hc->qh->ping_state = 1;
  79704. + qtd->error_count = 0;
  79705. +
  79706. + update_urb_state_xfer_intr(hc, hc_regs, qtd->urb, qtd,
  79707. + DWC_OTG_HC_XFER_NYET);
  79708. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  79709. +
  79710. + /*
  79711. + * Halt the channel and re-start the transfer so the PING
  79712. + * protocol will start.
  79713. + */
  79714. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NYET);
  79715. +
  79716. +handle_nyet_done:
  79717. + disable_hc_int(hc_regs, nyet);
  79718. + return 1;
  79719. +}
  79720. +
  79721. +/**
  79722. + * Handles a host channel babble interrupt. This handler may be called in
  79723. + * either DMA mode or Slave mode.
  79724. + */
  79725. +static int32_t handle_hc_babble_intr(dwc_otg_hcd_t * hcd,
  79726. + dwc_hc_t * hc,
  79727. + dwc_otg_hc_regs_t * hc_regs,
  79728. + dwc_otg_qtd_t * qtd)
  79729. +{
  79730. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  79731. + "Babble Error--\n", hc->hc_num);
  79732. +
  79733. + if (hcd->core_if->dma_desc_enable) {
  79734. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  79735. + DWC_OTG_HC_XFER_BABBLE_ERR);
  79736. + goto handle_babble_done;
  79737. + }
  79738. +
  79739. + if (hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  79740. + hcd->fops->complete(hcd, qtd->urb->priv,
  79741. + qtd->urb, -DWC_E_OVERFLOW);
  79742. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_BABBLE_ERR);
  79743. + } else {
  79744. + dwc_otg_halt_status_e halt_status;
  79745. + halt_status = update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  79746. + DWC_OTG_HC_XFER_BABBLE_ERR);
  79747. + halt_channel(hcd, hc, qtd, halt_status);
  79748. + }
  79749. +
  79750. +handle_babble_done:
  79751. + disable_hc_int(hc_regs, bblerr);
  79752. + return 1;
  79753. +}
  79754. +
  79755. +/**
  79756. + * Handles a host channel AHB error interrupt. This handler is only called in
  79757. + * DMA mode.
  79758. + */
  79759. +static int32_t handle_hc_ahberr_intr(dwc_otg_hcd_t * hcd,
  79760. + dwc_hc_t * hc,
  79761. + dwc_otg_hc_regs_t * hc_regs,
  79762. + dwc_otg_qtd_t * qtd)
  79763. +{
  79764. + hcchar_data_t hcchar;
  79765. + hcsplt_data_t hcsplt;
  79766. + hctsiz_data_t hctsiz;
  79767. + uint32_t hcdma;
  79768. + char *pipetype, *speed;
  79769. +
  79770. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  79771. +
  79772. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  79773. + "AHB Error--\n", hc->hc_num);
  79774. +
  79775. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  79776. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  79777. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  79778. + hcdma = DWC_READ_REG32(&hc_regs->hcdma);
  79779. +
  79780. + DWC_ERROR("AHB ERROR, Channel %d\n", hc->hc_num);
  79781. + DWC_ERROR(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32, hcsplt.d32);
  79782. + DWC_ERROR(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32, hcdma);
  79783. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Enqueue\n");
  79784. + DWC_ERROR(" Device address: %d\n",
  79785. + dwc_otg_hcd_get_dev_addr(&urb->pipe_info));
  79786. + DWC_ERROR(" Endpoint: %d, %s\n",
  79787. + dwc_otg_hcd_get_ep_num(&urb->pipe_info),
  79788. + (dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT"));
  79789. +
  79790. + switch (dwc_otg_hcd_get_pipe_type(&urb->pipe_info)) {
  79791. + case UE_CONTROL:
  79792. + pipetype = "CONTROL";
  79793. + break;
  79794. + case UE_BULK:
  79795. + pipetype = "BULK";
  79796. + break;
  79797. + case UE_INTERRUPT:
  79798. + pipetype = "INTERRUPT";
  79799. + break;
  79800. + case UE_ISOCHRONOUS:
  79801. + pipetype = "ISOCHRONOUS";
  79802. + break;
  79803. + default:
  79804. + pipetype = "UNKNOWN";
  79805. + break;
  79806. + }
  79807. +
  79808. + DWC_ERROR(" Endpoint type: %s\n", pipetype);
  79809. +
  79810. + switch (hc->speed) {
  79811. + case DWC_OTG_EP_SPEED_HIGH:
  79812. + speed = "HIGH";
  79813. + break;
  79814. + case DWC_OTG_EP_SPEED_FULL:
  79815. + speed = "FULL";
  79816. + break;
  79817. + case DWC_OTG_EP_SPEED_LOW:
  79818. + speed = "LOW";
  79819. + break;
  79820. + default:
  79821. + speed = "UNKNOWN";
  79822. + break;
  79823. + };
  79824. +
  79825. + DWC_ERROR(" Speed: %s\n", speed);
  79826. +
  79827. + DWC_ERROR(" Max packet size: %d\n",
  79828. + dwc_otg_hcd_get_mps(&urb->pipe_info));
  79829. + DWC_ERROR(" Data buffer length: %d\n", urb->length);
  79830. + DWC_ERROR(" Transfer buffer: %p, Transfer DMA: %p\n",
  79831. + urb->buf, (void *)urb->dma);
  79832. + DWC_ERROR(" Setup buffer: %p, Setup DMA: %p\n",
  79833. + urb->setup_packet, (void *)urb->setup_dma);
  79834. + DWC_ERROR(" Interval: %d\n", urb->interval);
  79835. +
  79836. + /* Core haltes the channel for Descriptor DMA mode */
  79837. + if (hcd->core_if->dma_desc_enable) {
  79838. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  79839. + DWC_OTG_HC_XFER_AHB_ERR);
  79840. + goto handle_ahberr_done;
  79841. + }
  79842. +
  79843. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_IO);
  79844. +
  79845. + /*
  79846. + * Force a channel halt. Don't call halt_channel because that won't
  79847. + * write to the HCCHARn register in DMA mode to force the halt.
  79848. + */
  79849. + dwc_otg_hc_halt(hcd->core_if, hc, DWC_OTG_HC_XFER_AHB_ERR);
  79850. +handle_ahberr_done:
  79851. + disable_hc_int(hc_regs, ahberr);
  79852. + return 1;
  79853. +}
  79854. +
  79855. +/**
  79856. + * Handles a host channel transaction error interrupt. This handler may be
  79857. + * called in either DMA mode or Slave mode.
  79858. + */
  79859. +static int32_t handle_hc_xacterr_intr(dwc_otg_hcd_t * hcd,
  79860. + dwc_hc_t * hc,
  79861. + dwc_otg_hc_regs_t * hc_regs,
  79862. + dwc_otg_qtd_t * qtd)
  79863. +{
  79864. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  79865. + "Transaction Error--\n", hc->hc_num);
  79866. +
  79867. + if (hcd->core_if->dma_desc_enable) {
  79868. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  79869. + DWC_OTG_HC_XFER_XACT_ERR);
  79870. + goto handle_xacterr_done;
  79871. + }
  79872. +
  79873. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  79874. + case UE_CONTROL:
  79875. + case UE_BULK:
  79876. + qtd->error_count++;
  79877. + if (!hc->qh->ping_state) {
  79878. +
  79879. + update_urb_state_xfer_intr(hc, hc_regs,
  79880. + qtd->urb, qtd,
  79881. + DWC_OTG_HC_XFER_XACT_ERR);
  79882. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  79883. + if (!hc->ep_is_in && hc->speed == DWC_OTG_EP_SPEED_HIGH) {
  79884. + hc->qh->ping_state = 1;
  79885. + }
  79886. + }
  79887. +
  79888. + /*
  79889. + * Halt the channel so the transfer can be re-started from
  79890. + * the appropriate point or the PING protocol will start.
  79891. + */
  79892. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  79893. + break;
  79894. + case UE_INTERRUPT:
  79895. + qtd->error_count++;
  79896. + if (hc->do_split && hc->complete_split) {
  79897. + qtd->complete_split = 0;
  79898. + }
  79899. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  79900. + break;
  79901. + case UE_ISOCHRONOUS:
  79902. + {
  79903. + dwc_otg_halt_status_e halt_status;
  79904. + halt_status =
  79905. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  79906. + DWC_OTG_HC_XFER_XACT_ERR);
  79907. +
  79908. + halt_channel(hcd, hc, qtd, halt_status);
  79909. + }
  79910. + break;
  79911. + }
  79912. +handle_xacterr_done:
  79913. + disable_hc_int(hc_regs, xacterr);
  79914. +
  79915. + return 1;
  79916. +}
  79917. +
  79918. +/**
  79919. + * Handles a host channel frame overrun interrupt. This handler may be called
  79920. + * in either DMA mode or Slave mode.
  79921. + */
  79922. +static int32_t handle_hc_frmovrun_intr(dwc_otg_hcd_t * hcd,
  79923. + dwc_hc_t * hc,
  79924. + dwc_otg_hc_regs_t * hc_regs,
  79925. + dwc_otg_qtd_t * qtd)
  79926. +{
  79927. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  79928. + "Frame Overrun--\n", hc->hc_num);
  79929. +
  79930. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  79931. + case UE_CONTROL:
  79932. + case UE_BULK:
  79933. + break;
  79934. + case UE_INTERRUPT:
  79935. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_FRAME_OVERRUN);
  79936. + break;
  79937. + case UE_ISOCHRONOUS:
  79938. + {
  79939. + dwc_otg_halt_status_e halt_status;
  79940. + halt_status =
  79941. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  79942. + DWC_OTG_HC_XFER_FRAME_OVERRUN);
  79943. +
  79944. + halt_channel(hcd, hc, qtd, halt_status);
  79945. + }
  79946. + break;
  79947. + }
  79948. +
  79949. + disable_hc_int(hc_regs, frmovrun);
  79950. +
  79951. + return 1;
  79952. +}
  79953. +
  79954. +/**
  79955. + * Handles a host channel data toggle error interrupt. This handler may be
  79956. + * called in either DMA mode or Slave mode.
  79957. + */
  79958. +static int32_t handle_hc_datatglerr_intr(dwc_otg_hcd_t * hcd,
  79959. + dwc_hc_t * hc,
  79960. + dwc_otg_hc_regs_t * hc_regs,
  79961. + dwc_otg_qtd_t * qtd)
  79962. +{
  79963. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  79964. + "Data Toggle Error on %s transfer--\n",
  79965. + hc->hc_num, (hc->ep_is_in ? "IN" : "OUT"));
  79966. +
  79967. + /* Data toggles on split transactions cause the hc to halt.
  79968. + * restart transfer */
  79969. + if(hc->qh->do_split)
  79970. + {
  79971. + qtd->error_count++;
  79972. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  79973. + update_urb_state_xfer_intr(hc, hc_regs,
  79974. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  79975. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  79976. + } else if (hc->ep_is_in) {
  79977. + /* An unmasked data toggle error on a non-split DMA transaction is
  79978. + * for the sole purpose of resetting error counts. Disable other
  79979. + * interrupts unmasked for the same reason.
  79980. + */
  79981. + if(hcd->core_if->dma_enable) {
  79982. + disable_hc_int(hc_regs, ack);
  79983. + disable_hc_int(hc_regs, nak);
  79984. + }
  79985. + qtd->error_count = 0;
  79986. + }
  79987. +
  79988. + disable_hc_int(hc_regs, datatglerr);
  79989. +
  79990. + return 1;
  79991. +}
  79992. +
  79993. +#ifdef DEBUG
  79994. +/**
  79995. + * This function is for debug only. It checks that a valid halt status is set
  79996. + * and that HCCHARn.chdis is clear. If there's a problem, corrective action is
  79997. + * taken and a warning is issued.
  79998. + * @return 1 if halt status is ok, 0 otherwise.
  79999. + */
  80000. +static inline int halt_status_ok(dwc_otg_hcd_t * hcd,
  80001. + dwc_hc_t * hc,
  80002. + dwc_otg_hc_regs_t * hc_regs,
  80003. + dwc_otg_qtd_t * qtd)
  80004. +{
  80005. + hcchar_data_t hcchar;
  80006. + hctsiz_data_t hctsiz;
  80007. + hcint_data_t hcint;
  80008. + hcintmsk_data_t hcintmsk;
  80009. + hcsplt_data_t hcsplt;
  80010. +
  80011. + if (hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS) {
  80012. + /*
  80013. + * This code is here only as a check. This condition should
  80014. + * never happen. Ignore the halt if it does occur.
  80015. + */
  80016. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  80017. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  80018. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  80019. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  80020. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  80021. + DWC_WARN
  80022. + ("%s: hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS, "
  80023. + "channel %d, hcchar 0x%08x, hctsiz 0x%08x, "
  80024. + "hcint 0x%08x, hcintmsk 0x%08x, "
  80025. + "hcsplt 0x%08x, qtd->complete_split %d\n", __func__,
  80026. + hc->hc_num, hcchar.d32, hctsiz.d32, hcint.d32,
  80027. + hcintmsk.d32, hcsplt.d32, qtd->complete_split);
  80028. +
  80029. + DWC_WARN("%s: no halt status, channel %d, ignoring interrupt\n",
  80030. + __func__, hc->hc_num);
  80031. + DWC_WARN("\n");
  80032. + clear_hc_int(hc_regs, chhltd);
  80033. + return 0;
  80034. + }
  80035. +
  80036. + /*
  80037. + * This code is here only as a check. hcchar.chdis should
  80038. + * never be set when the halt interrupt occurs. Halt the
  80039. + * channel again if it does occur.
  80040. + */
  80041. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  80042. + if (hcchar.b.chdis) {
  80043. + DWC_WARN("%s: hcchar.chdis set unexpectedly, "
  80044. + "hcchar 0x%08x, trying to halt again\n",
  80045. + __func__, hcchar.d32);
  80046. + clear_hc_int(hc_regs, chhltd);
  80047. + hc->halt_pending = 0;
  80048. + halt_channel(hcd, hc, qtd, hc->halt_status);
  80049. + return 0;
  80050. + }
  80051. +
  80052. + return 1;
  80053. +}
  80054. +#endif
  80055. +
  80056. +/**
  80057. + * Handles a host Channel Halted interrupt in DMA mode. This handler
  80058. + * determines the reason the channel halted and proceeds accordingly.
  80059. + */
  80060. +static void handle_hc_chhltd_intr_dma(dwc_otg_hcd_t * hcd,
  80061. + dwc_hc_t * hc,
  80062. + dwc_otg_hc_regs_t * hc_regs,
  80063. + dwc_otg_qtd_t * qtd)
  80064. +{
  80065. + int out_nak_enh = 0;
  80066. + hcint_data_t hcint;
  80067. + hcintmsk_data_t hcintmsk;
  80068. + /* For core with OUT NAK enhancement, the flow for high-
  80069. + * speed CONTROL/BULK OUT is handled a little differently.
  80070. + */
  80071. + if (hcd->core_if->snpsid >= OTG_CORE_REV_2_71a) {
  80072. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH && !hc->ep_is_in &&
  80073. + (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  80074. + hc->ep_type == DWC_OTG_EP_TYPE_BULK)) {
  80075. + out_nak_enh = 1;
  80076. + }
  80077. + }
  80078. +
  80079. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
  80080. + (hc->halt_status == DWC_OTG_HC_XFER_AHB_ERR
  80081. + && !hcd->core_if->dma_desc_enable)) {
  80082. + /*
  80083. + * Just release the channel. A dequeue can happen on a
  80084. + * transfer timeout. In the case of an AHB Error, the channel
  80085. + * was forced to halt because there's no way to gracefully
  80086. + * recover.
  80087. + */
  80088. + if (hcd->core_if->dma_desc_enable)
  80089. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  80090. + hc->halt_status);
  80091. + else
  80092. + release_channel(hcd, hc, qtd, hc->halt_status);
  80093. + return;
  80094. + }
  80095. +
  80096. + /* Read the HCINTn register to determine the cause for the halt. */
  80097. +
  80098. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  80099. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  80100. +
  80101. + if (hcint.b.xfercomp) {
  80102. + /** @todo This is here because of a possible hardware bug. Spec
  80103. + * says that on SPLIT-ISOC OUT transfers in DMA mode that a HALT
  80104. + * interrupt w/ACK bit set should occur, but I only see the
  80105. + * XFERCOMP bit, even with it masked out. This is a workaround
  80106. + * for that behavior. Should fix this when hardware is fixed.
  80107. + */
  80108. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in) {
  80109. + handle_hc_ack_intr(hcd, hc, hc_regs, qtd);
  80110. + }
  80111. + handle_hc_xfercomp_intr(hcd, hc, hc_regs, qtd);
  80112. + } else if (hcint.b.stall) {
  80113. + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
  80114. + } else if (hcint.b.xacterr && !hcd->core_if->dma_desc_enable) {
  80115. + if (out_nak_enh) {
  80116. + if (hcint.b.nyet || hcint.b.nak || hcint.b.ack) {
  80117. + DWC_DEBUGPL(DBG_HCD, "XactErr with NYET/NAK/ACK\n");
  80118. + qtd->error_count = 0;
  80119. + } else {
  80120. + DWC_DEBUGPL(DBG_HCD, "XactErr without NYET/NAK/ACK\n");
  80121. + }
  80122. + }
  80123. +
  80124. + /*
  80125. + * Must handle xacterr before nak or ack. Could get a xacterr
  80126. + * at the same time as either of these on a BULK/CONTROL OUT
  80127. + * that started with a PING. The xacterr takes precedence.
  80128. + */
  80129. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  80130. + } else if (hcint.b.xcs_xact && hcd->core_if->dma_desc_enable) {
  80131. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  80132. + } else if (hcint.b.ahberr && hcd->core_if->dma_desc_enable) {
  80133. + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
  80134. + } else if (hcint.b.bblerr) {
  80135. + handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
  80136. + } else if (hcint.b.frmovrun) {
  80137. + handle_hc_frmovrun_intr(hcd, hc, hc_regs, qtd);
  80138. + } else if (hcint.b.datatglerr) {
  80139. + handle_hc_datatglerr_intr(hcd, hc, hc_regs, qtd);
  80140. + } else if (!out_nak_enh) {
  80141. + if (hcint.b.nyet) {
  80142. + /*
  80143. + * Must handle nyet before nak or ack. Could get a nyet at the
  80144. + * same time as either of those on a BULK/CONTROL OUT that
  80145. + * started with a PING. The nyet takes precedence.
  80146. + */
  80147. + handle_hc_nyet_intr(hcd, hc, hc_regs, qtd);
  80148. + } else if (hcint.b.nak && !hcintmsk.b.nak) {
  80149. + /*
  80150. + * If nak is not masked, it's because a non-split IN transfer
  80151. + * is in an error state. In that case, the nak is handled by
  80152. + * the nak interrupt handler, not here. Handle nak here for
  80153. + * BULK/CONTROL OUT transfers, which halt on a NAK to allow
  80154. + * rewinding the buffer pointer.
  80155. + */
  80156. + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
  80157. + } else if (hcint.b.ack && !hcintmsk.b.ack) {
  80158. + /*
  80159. + * If ack is not masked, it's because a non-split IN transfer
  80160. + * is in an error state. In that case, the ack is handled by
  80161. + * the ack interrupt handler, not here. Handle ack here for
  80162. + * split transfers. Start splits halt on ACK.
  80163. + */
  80164. + handle_hc_ack_intr(hcd, hc, hc_regs, qtd);
  80165. + } else {
  80166. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  80167. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  80168. + /*
  80169. + * A periodic transfer halted with no other channel
  80170. + * interrupts set. Assume it was halted by the core
  80171. + * because it could not be completed in its scheduled
  80172. + * (micro)frame.
  80173. + */
  80174. +#ifdef DEBUG
  80175. + DWC_PRINTF
  80176. + ("%s: Halt channel %d (assume incomplete periodic transfer)\n",
  80177. + __func__, hc->hc_num);
  80178. +#endif
  80179. + halt_channel(hcd, hc, qtd,
  80180. + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE);
  80181. + } else {
  80182. + DWC_ERROR
  80183. + ("%s: Channel %d, DMA Mode -- ChHltd set, but reason "
  80184. + "for halting is unknown, hcint 0x%08x, intsts 0x%08x\n",
  80185. + __func__, hc->hc_num, hcint.d32,
  80186. + DWC_READ_REG32(&hcd->
  80187. + core_if->core_global_regs->
  80188. + gintsts));
  80189. + /* Failthrough: use 3-strikes rule */
  80190. + qtd->error_count++;
  80191. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  80192. + update_urb_state_xfer_intr(hc, hc_regs,
  80193. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  80194. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  80195. + }
  80196. +
  80197. + }
  80198. + } else {
  80199. + DWC_PRINTF("NYET/NAK/ACK/other in non-error case, 0x%08x\n",
  80200. + hcint.d32);
  80201. + /* Failthrough: use 3-strikes rule */
  80202. + qtd->error_count++;
  80203. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  80204. + update_urb_state_xfer_intr(hc, hc_regs,
  80205. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  80206. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  80207. + }
  80208. +}
  80209. +
  80210. +/**
  80211. + * Handles a host channel Channel Halted interrupt.
  80212. + *
  80213. + * In slave mode, this handler is called only when the driver specifically
  80214. + * requests a halt. This occurs during handling other host channel interrupts
  80215. + * (e.g. nak, xacterr, stall, nyet, etc.).
  80216. + *
  80217. + * In DMA mode, this is the interrupt that occurs when the core has finished
  80218. + * processing a transfer on a channel. Other host channel interrupts (except
  80219. + * ahberr) are disabled in DMA mode.
  80220. + */
  80221. +static int32_t handle_hc_chhltd_intr(dwc_otg_hcd_t * hcd,
  80222. + dwc_hc_t * hc,
  80223. + dwc_otg_hc_regs_t * hc_regs,
  80224. + dwc_otg_qtd_t * qtd)
  80225. +{
  80226. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  80227. + "Channel Halted--\n", hc->hc_num);
  80228. +
  80229. + if (hcd->core_if->dma_enable) {
  80230. + handle_hc_chhltd_intr_dma(hcd, hc, hc_regs, qtd);
  80231. + } else {
  80232. +#ifdef DEBUG
  80233. + if (!halt_status_ok(hcd, hc, hc_regs, qtd)) {
  80234. + return 1;
  80235. + }
  80236. +#endif
  80237. + release_channel(hcd, hc, qtd, hc->halt_status);
  80238. + }
  80239. +
  80240. + return 1;
  80241. +}
  80242. +
  80243. +
  80244. +/**
  80245. + * dwc_otg_fiq_unmangle_isoc() - Update the iso_frame_desc structure on
  80246. + * FIQ transfer completion
  80247. + * @hcd: Pointer to dwc_otg_hcd struct
  80248. + * @num: Host channel number
  80249. + *
  80250. + * 1. Un-mangle the status as recorded in each iso_frame_desc status
  80251. + * 2. Copy it from the dwc_otg_urb into the real URB
  80252. + */
  80253. +void dwc_otg_fiq_unmangle_isoc(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh, dwc_otg_qtd_t *qtd, uint32_t num)
  80254. +{
  80255. + struct dwc_otg_hcd_urb *dwc_urb = qtd->urb;
  80256. + int nr_frames = dwc_urb->packet_count;
  80257. + int i;
  80258. + hcint_data_t frame_hcint;
  80259. +
  80260. + for (i = 0; i < nr_frames; i++) {
  80261. + frame_hcint.d32 = dwc_urb->iso_descs[i].status;
  80262. + if (frame_hcint.b.xfercomp) {
  80263. + dwc_urb->iso_descs[i].status = 0;
  80264. + dwc_urb->actual_length += dwc_urb->iso_descs[i].actual_length;
  80265. + } else if (frame_hcint.b.frmovrun) {
  80266. + if (qh->ep_is_in)
  80267. + dwc_urb->iso_descs[i].status = -DWC_E_NO_STREAM_RES;
  80268. + else
  80269. + dwc_urb->iso_descs[i].status = -DWC_E_COMMUNICATION;
  80270. + dwc_urb->error_count++;
  80271. + dwc_urb->iso_descs[i].actual_length = 0;
  80272. + } else if (frame_hcint.b.xacterr) {
  80273. + dwc_urb->iso_descs[i].status = -DWC_E_PROTOCOL;
  80274. + dwc_urb->error_count++;
  80275. + dwc_urb->iso_descs[i].actual_length = 0;
  80276. + } else if (frame_hcint.b.bblerr) {
  80277. + dwc_urb->iso_descs[i].status = -DWC_E_OVERFLOW;
  80278. + dwc_urb->error_count++;
  80279. + dwc_urb->iso_descs[i].actual_length = 0;
  80280. + } else {
  80281. + /* Something went wrong */
  80282. + dwc_urb->iso_descs[i].status = -1;
  80283. + dwc_urb->iso_descs[i].actual_length = 0;
  80284. + dwc_urb->error_count++;
  80285. + }
  80286. + }
  80287. + //printk_ratelimited(KERN_INFO "%s: HS isochronous of %d/%d frames with %d errors complete\n",
  80288. + // __FUNCTION__, i, dwc_urb->packet_count, dwc_urb->error_count);
  80289. + hcd->fops->complete(hcd, dwc_urb->priv, dwc_urb, 0);
  80290. + release_channel(hcd, qh->channel, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  80291. +}
  80292. +
  80293. +/**
  80294. + * dwc_otg_fiq_unsetup_per_dma() - Remove data from bounce buffers for split transactions
  80295. + * @hcd: Pointer to dwc_otg_hcd struct
  80296. + * @num: Host channel number
  80297. + *
  80298. + * Copies data from the FIQ bounce buffers into the URB's transfer buffer. Does not modify URB state.
  80299. + * Returns total length of data or -1 if the buffers were not used.
  80300. + *
  80301. + */
  80302. +int dwc_otg_fiq_unsetup_per_dma(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh, dwc_otg_qtd_t *qtd, uint32_t num)
  80303. +{
  80304. + dwc_hc_t *hc = qh->channel;
  80305. + struct fiq_dma_blob *blob = hcd->fiq_dmab;
  80306. + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
  80307. + uint8_t *ptr = NULL;
  80308. + int index = 0, len = 0;
  80309. + int i = 0;
  80310. + if (hc->ep_is_in) {
  80311. + /* Copy data out of the DMA bounce buffers to the URB's buffer.
  80312. + * The align_buf is ignored as this is ignored on FSM enqueue. */
  80313. + ptr = qtd->urb->buf;
  80314. + if (qh->ep_type == UE_ISOCHRONOUS) {
  80315. + /* Isoc IN transactions - grab the offset of the iso_frame_desc into the URB transfer buffer */
  80316. + index = qtd->isoc_frame_index;
  80317. + ptr += qtd->urb->iso_descs[index].offset;
  80318. + } else {
  80319. + /* Need to increment by actual_length for interrupt IN */
  80320. + ptr += qtd->urb->actual_length;
  80321. + }
  80322. +
  80323. + for (i = 0; i < st->dma_info.index; i++) {
  80324. + len += st->dma_info.slot_len[i];
  80325. + dwc_memcpy(ptr, &blob->channel[num].index[i].buf[0], st->dma_info.slot_len[i]);
  80326. + ptr += st->dma_info.slot_len[i];
  80327. + }
  80328. + return len;
  80329. + } else {
  80330. + /* OUT endpoints - nothing to do. */
  80331. + return -1;
  80332. + }
  80333. +
  80334. +}
  80335. +/**
  80336. + * dwc_otg_hcd_handle_hc_fsm() - handle an unmasked channel interrupt
  80337. + * from a channel handled in the FIQ
  80338. + * @hcd: Pointer to dwc_otg_hcd struct
  80339. + * @num: Host channel number
  80340. + *
  80341. + * If a host channel interrupt was received by the IRQ and this was a channel
  80342. + * used by the FIQ, the execution flow for transfer completion is substantially
  80343. + * different from the normal (messy) path. This function and its friends handles
  80344. + * channel cleanup and transaction completion from a FIQ transaction.
  80345. + */
  80346. +int32_t dwc_otg_hcd_handle_hc_fsm(dwc_otg_hcd_t *hcd, uint32_t num)
  80347. +{
  80348. + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
  80349. + dwc_hc_t *hc = hcd->hc_ptr_array[num];
  80350. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list);
  80351. + dwc_otg_qh_t *qh = hc->qh;
  80352. + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[num];
  80353. + hcint_data_t hcint = hcd->fiq_state->channel[num].hcint_copy;
  80354. + int hostchannels = 0;
  80355. + int ret = 0;
  80356. + fiq_print(FIQDBG_INT, hcd->fiq_state, "OUT %01d %01d ", num , st->fsm);
  80357. +
  80358. + hostchannels = hcd->available_host_channels;
  80359. + switch (st->fsm) {
  80360. + case FIQ_TEST:
  80361. + break;
  80362. +
  80363. + case FIQ_DEQUEUE_ISSUED:
  80364. + /* hc_halt was called. QTD no longer exists. */
  80365. + /* TODO: for a nonperiodic split transaction, need to issue a
  80366. + * CLEAR_TT_BUFFER hub command if we were in the start-split phase.
  80367. + */
  80368. + release_channel(hcd, hc, NULL, hc->halt_status);
  80369. + ret = 1;
  80370. + break;
  80371. +
  80372. + case FIQ_NP_SPLIT_DONE:
  80373. + /* Nonperiodic transaction complete. */
  80374. + if (!hc->ep_is_in) {
  80375. + qtd->ssplit_out_xfer_count = hc->xfer_len;
  80376. + }
  80377. + if (hcint.b.xfercomp) {
  80378. + handle_hc_xfercomp_intr(hcd, hc, hc_regs, qtd);
  80379. + } else if (hcint.b.nak) {
  80380. + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
  80381. + }
  80382. + ret = 1;
  80383. + break;
  80384. +
  80385. + case FIQ_NP_SPLIT_HS_ABORTED:
  80386. + /* A HS abort is a 3-strikes on the HS bus at any point in the transaction.
  80387. + * Normally a CLEAR_TT_BUFFER hub command would be required: we can't do that
  80388. + * because there's no guarantee which order a non-periodic split happened in.
  80389. + * We could end up clearing a perfectly good transaction out of the buffer.
  80390. + */
  80391. + if (hcint.b.xacterr) {
  80392. + qtd->error_count += st->nr_errors;
  80393. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  80394. + } else if (hcint.b.ahberr) {
  80395. + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
  80396. + } else {
  80397. + local_fiq_disable();
  80398. + BUG();
  80399. + }
  80400. + break;
  80401. +
  80402. + case FIQ_NP_SPLIT_LS_ABORTED:
  80403. + /* A few cases can cause this - either an unknown state on a SSPLIT or
  80404. + * STALL/data toggle error response on a CSPLIT */
  80405. + if (hcint.b.stall) {
  80406. + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
  80407. + } else if (hcint.b.datatglerr) {
  80408. + handle_hc_datatglerr_intr(hcd, hc, hc_regs, qtd);
  80409. + } else if (hcint.b.bblerr) {
  80410. + handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
  80411. + } else if (hcint.b.ahberr) {
  80412. + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
  80413. + } else {
  80414. + local_fiq_disable();
  80415. + BUG();
  80416. + }
  80417. + break;
  80418. +
  80419. + case FIQ_PER_SPLIT_DONE:
  80420. + /* Isoc IN or Interrupt IN/OUT */
  80421. +
  80422. + /* Flow control here is different from the normal execution by the driver.
  80423. + * We need to completely ignore most of the driver's method of handling
  80424. + * split transactions and do it ourselves.
  80425. + */
  80426. + if (hc->ep_type == UE_INTERRUPT) {
  80427. + if (hcint.b.nak) {
  80428. + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
  80429. + } else if (hc->ep_is_in) {
  80430. + int len;
  80431. + len = dwc_otg_fiq_unsetup_per_dma(hcd, hc->qh, qtd, num);
  80432. + //printk(KERN_NOTICE "FIQ Transaction: hc=%d len=%d urb_len = %d\n", num, len, qtd->urb->length);
  80433. + qtd->urb->actual_length += len;
  80434. + if (qtd->urb->actual_length >= qtd->urb->length) {
  80435. + qtd->urb->status = 0;
  80436. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
  80437. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  80438. + } else {
  80439. + /* Interrupt transfer not complete yet - is it a short read? */
  80440. + if (len < hc->max_packet) {
  80441. + /* Interrupt transaction complete */
  80442. + qtd->urb->status = 0;
  80443. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
  80444. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  80445. + } else {
  80446. + /* Further transactions required */
  80447. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  80448. + }
  80449. + }
  80450. + } else {
  80451. + /* Interrupt OUT complete. */
  80452. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  80453. + qtd->urb->actual_length += hc->xfer_len;
  80454. + if (qtd->urb->actual_length >= qtd->urb->length) {
  80455. + qtd->urb->status = 0;
  80456. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
  80457. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  80458. + } else {
  80459. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  80460. + }
  80461. + }
  80462. + } else {
  80463. + /* ISOC IN complete. */
  80464. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  80465. + int len = 0;
  80466. + /* Record errors, update qtd. */
  80467. + if (st->nr_errors) {
  80468. + frame_desc->actual_length = 0;
  80469. + frame_desc->status = -DWC_E_PROTOCOL;
  80470. + } else {
  80471. + frame_desc->status = 0;
  80472. + /* Unswizzle dma */
  80473. + len = dwc_otg_fiq_unsetup_per_dma(hcd, qh, qtd, num);
  80474. + frame_desc->actual_length = len;
  80475. + }
  80476. + qtd->isoc_frame_index++;
  80477. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  80478. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  80479. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  80480. + } else {
  80481. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  80482. + }
  80483. + }
  80484. + break;
  80485. +
  80486. + case FIQ_PER_ISO_OUT_DONE: {
  80487. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  80488. + /* Record errors, update qtd. */
  80489. + if (st->nr_errors) {
  80490. + frame_desc->actual_length = 0;
  80491. + frame_desc->status = -DWC_E_PROTOCOL;
  80492. + } else {
  80493. + frame_desc->status = 0;
  80494. + frame_desc->actual_length = frame_desc->length;
  80495. + }
  80496. + qtd->isoc_frame_index++;
  80497. + qtd->isoc_split_offset = 0;
  80498. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  80499. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  80500. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  80501. + } else {
  80502. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  80503. + }
  80504. + }
  80505. + break;
  80506. +
  80507. + case FIQ_PER_SPLIT_NYET_ABORTED:
  80508. + /* Doh. lost the data. */
  80509. + printk_ratelimited(KERN_INFO "Transfer to device %d endpoint 0x%x frame %d failed "
  80510. + "- FIQ reported NYET. Data may have been lost.\n",
  80511. + hc->dev_addr, hc->ep_num, dwc_otg_hcd_get_frame_number(hcd) >> 3);
  80512. + if (hc->ep_type == UE_ISOCHRONOUS) {
  80513. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  80514. + /* Record errors, update qtd. */
  80515. + frame_desc->actual_length = 0;
  80516. + frame_desc->status = -DWC_E_PROTOCOL;
  80517. + qtd->isoc_frame_index++;
  80518. + qtd->isoc_split_offset = 0;
  80519. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  80520. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  80521. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  80522. + } else {
  80523. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  80524. + }
  80525. + } else {
  80526. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  80527. + }
  80528. + break;
  80529. +
  80530. + case FIQ_HS_ISOC_DONE:
  80531. + /* The FIQ has performed a whole pile of isochronous transactions.
  80532. + * The status is recorded as the interrupt state should the transaction
  80533. + * fail.
  80534. + */
  80535. + dwc_otg_fiq_unmangle_isoc(hcd, qh, qtd, num);
  80536. + break;
  80537. +
  80538. + case FIQ_PER_SPLIT_LS_ABORTED:
  80539. + if (hcint.b.xacterr) {
  80540. + /* Hub has responded with an ERR packet. Device
  80541. + * has been unplugged or the port has been disabled.
  80542. + * TODO: need to issue a reset to the hub port. */
  80543. + qtd->error_count += 3;
  80544. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  80545. + } else if (hcint.b.stall) {
  80546. + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
  80547. + } else if (hcint.b.bblerr) {
  80548. + handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
  80549. + } else {
  80550. + printk_ratelimited(KERN_INFO "Transfer to device %d endpoint 0x%x failed "
  80551. + "- FIQ reported FSM=%d. Data may have been lost.\n",
  80552. + st->fsm, hc->dev_addr, hc->ep_num);
  80553. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  80554. + }
  80555. + break;
  80556. +
  80557. + case FIQ_PER_SPLIT_HS_ABORTED:
  80558. + /* Either the SSPLIT phase suffered transaction errors or something
  80559. + * unexpected happened.
  80560. + */
  80561. + qtd->error_count += 3;
  80562. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  80563. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  80564. + break;
  80565. +
  80566. + case FIQ_PER_SPLIT_TIMEOUT:
  80567. + /* Couldn't complete in the nominated frame */
  80568. + printk(KERN_INFO "Transfer to device %d endpoint 0x%x frame %d failed "
  80569. + "- FIQ timed out. Data may have been lost.\n",
  80570. + hc->dev_addr, hc->ep_num, dwc_otg_hcd_get_frame_number(hcd) >> 3);
  80571. + if (hc->ep_type == UE_ISOCHRONOUS) {
  80572. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  80573. + /* Record errors, update qtd. */
  80574. + frame_desc->actual_length = 0;
  80575. + if (hc->ep_is_in) {
  80576. + frame_desc->status = -DWC_E_NO_STREAM_RES;
  80577. + } else {
  80578. + frame_desc->status = -DWC_E_COMMUNICATION;
  80579. + }
  80580. + qtd->isoc_frame_index++;
  80581. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  80582. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  80583. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  80584. + } else {
  80585. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  80586. + }
  80587. + } else {
  80588. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  80589. + }
  80590. + break;
  80591. +
  80592. + default:
  80593. + local_fiq_disable();
  80594. + DWC_WARN("unexpected state received on hc=%d fsm=%d", hc->hc_num, st->fsm);
  80595. + BUG();
  80596. + }
  80597. + //if (hostchannels != hcd->available_host_channels) {
  80598. + /* should have incremented by now! */
  80599. + // BUG();
  80600. +// }
  80601. + return ret;
  80602. +}
  80603. +
  80604. +/** Handles interrupt for a specific Host Channel */
  80605. +int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t * dwc_otg_hcd, uint32_t num)
  80606. +{
  80607. + int retval = 0;
  80608. + hcint_data_t hcint;
  80609. + hcintmsk_data_t hcintmsk;
  80610. + dwc_hc_t *hc;
  80611. + dwc_otg_hc_regs_t *hc_regs;
  80612. + dwc_otg_qtd_t *qtd;
  80613. +
  80614. + DWC_DEBUGPL(DBG_HCDV, "--Host Channel Interrupt--, Channel %d\n", num);
  80615. +
  80616. + hc = dwc_otg_hcd->hc_ptr_array[num];
  80617. + hc_regs = dwc_otg_hcd->core_if->host_if->hc_regs[num];
  80618. + if(hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  80619. + /* We are responding to a channel disable. Driver
  80620. + * state is cleared - our qtd has gone away.
  80621. + */
  80622. + release_channel(dwc_otg_hcd, hc, NULL, hc->halt_status);
  80623. + return 1;
  80624. + }
  80625. + qtd = DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list);
  80626. +
  80627. + /*
  80628. + * FSM mode: Check to see if this is a HC interrupt from a channel handled by the FIQ.
  80629. + * Execution path is fundamentally different for the channels after a FIQ has completed
  80630. + * a split transaction.
  80631. + */
  80632. + if (fiq_fsm_enable) {
  80633. + switch (dwc_otg_hcd->fiq_state->channel[num].fsm) {
  80634. + case FIQ_PASSTHROUGH:
  80635. + break;
  80636. + case FIQ_PASSTHROUGH_ERRORSTATE:
  80637. + /* Hook into the error count */
  80638. + fiq_print(FIQDBG_ERR, dwc_otg_hcd->fiq_state, "HCDERR%02d", num);
  80639. + if (!dwc_otg_hcd->fiq_state->channel[num].nr_errors) {
  80640. + qtd->error_count = 0;
  80641. + fiq_print(FIQDBG_ERR, dwc_otg_hcd->fiq_state, "RESET ");
  80642. + }
  80643. + break;
  80644. + default:
  80645. + dwc_otg_hcd_handle_hc_fsm(dwc_otg_hcd, num);
  80646. + return 1;
  80647. + }
  80648. + }
  80649. +
  80650. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  80651. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  80652. + hcint.d32 = hcint.d32 & hcintmsk.d32;
  80653. + if (!dwc_otg_hcd->core_if->dma_enable) {
  80654. + if (hcint.b.chhltd && hcint.d32 != 0x2) {
  80655. + hcint.b.chhltd = 0;
  80656. + }
  80657. + }
  80658. +
  80659. + if (hcint.b.xfercomp) {
  80660. + retval |=
  80661. + handle_hc_xfercomp_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  80662. + /*
  80663. + * If NYET occurred at same time as Xfer Complete, the NYET is
  80664. + * handled by the Xfer Complete interrupt handler. Don't want
  80665. + * to call the NYET interrupt handler in this case.
  80666. + */
  80667. + hcint.b.nyet = 0;
  80668. + }
  80669. + if (hcint.b.chhltd) {
  80670. + retval |= handle_hc_chhltd_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  80671. + }
  80672. + if (hcint.b.ahberr) {
  80673. + retval |= handle_hc_ahberr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  80674. + }
  80675. + if (hcint.b.stall) {
  80676. + retval |= handle_hc_stall_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  80677. + }
  80678. + if (hcint.b.nak) {
  80679. + retval |= handle_hc_nak_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  80680. + }
  80681. + if (hcint.b.ack) {
  80682. + if(!hcint.b.chhltd)
  80683. + retval |= handle_hc_ack_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  80684. + }
  80685. + if (hcint.b.nyet) {
  80686. + retval |= handle_hc_nyet_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  80687. + }
  80688. + if (hcint.b.xacterr) {
  80689. + retval |= handle_hc_xacterr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  80690. + }
  80691. + if (hcint.b.bblerr) {
  80692. + retval |= handle_hc_babble_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  80693. + }
  80694. + if (hcint.b.frmovrun) {
  80695. + retval |=
  80696. + handle_hc_frmovrun_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  80697. + }
  80698. + if (hcint.b.datatglerr) {
  80699. + retval |=
  80700. + handle_hc_datatglerr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  80701. + }
  80702. +
  80703. + return retval;
  80704. +}
  80705. +#endif /* DWC_DEVICE_ONLY */
  80706. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c
  80707. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c 1970-01-01 01:00:00.000000000 +0100
  80708. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c 2014-07-07 10:45:43.000000000 +0200
  80709. @@ -0,0 +1,985 @@
  80710. +
  80711. +/* ==========================================================================
  80712. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_linux.c $
  80713. + * $Revision: #20 $
  80714. + * $Date: 2011/10/26 $
  80715. + * $Change: 1872981 $
  80716. + *
  80717. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  80718. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  80719. + * otherwise expressly agreed to in writing between Synopsys and you.
  80720. + *
  80721. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  80722. + * any End User Software License Agreement or Agreement for Licensed Product
  80723. + * with Synopsys or any supplement thereto. You are permitted to use and
  80724. + * redistribute this Software in source and binary forms, with or without
  80725. + * modification, provided that redistributions of source code must retain this
  80726. + * notice. You may not view, use, disclose, copy or distribute this file or
  80727. + * any information contained herein except pursuant to this license grant from
  80728. + * Synopsys. If you do not agree with this notice, including the disclaimer
  80729. + * below, then you are not authorized to use the Software.
  80730. + *
  80731. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  80732. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  80733. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  80734. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  80735. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  80736. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  80737. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  80738. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  80739. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  80740. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  80741. + * DAMAGE.
  80742. + * ========================================================================== */
  80743. +#ifndef DWC_DEVICE_ONLY
  80744. +
  80745. +/**
  80746. + * @file
  80747. + *
  80748. + * This file contains the implementation of the HCD. In Linux, the HCD
  80749. + * implements the hc_driver API.
  80750. + */
  80751. +#include <linux/kernel.h>
  80752. +#include <linux/module.h>
  80753. +#include <linux/moduleparam.h>
  80754. +#include <linux/init.h>
  80755. +#include <linux/device.h>
  80756. +#include <linux/errno.h>
  80757. +#include <linux/list.h>
  80758. +#include <linux/interrupt.h>
  80759. +#include <linux/string.h>
  80760. +#include <linux/dma-mapping.h>
  80761. +#include <linux/version.h>
  80762. +#include <asm/io.h>
  80763. +#include <asm/fiq.h>
  80764. +#include <linux/usb.h>
  80765. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35)
  80766. +#include <../drivers/usb/core/hcd.h>
  80767. +#else
  80768. +#include <linux/usb/hcd.h>
  80769. +#endif
  80770. +#include <asm/bug.h>
  80771. +
  80772. +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30))
  80773. +#define USB_URB_EP_LINKING 1
  80774. +#else
  80775. +#define USB_URB_EP_LINKING 0
  80776. +#endif
  80777. +
  80778. +#include "dwc_otg_hcd_if.h"
  80779. +#include "dwc_otg_dbg.h"
  80780. +#include "dwc_otg_driver.h"
  80781. +#include "dwc_otg_hcd.h"
  80782. +
  80783. +extern unsigned char _dwc_otg_fiq_stub, _dwc_otg_fiq_stub_end;
  80784. +
  80785. +/**
  80786. + * Gets the endpoint number from a _bEndpointAddress argument. The endpoint is
  80787. + * qualified with its direction (possible 32 endpoints per device).
  80788. + */
  80789. +#define dwc_ep_addr_to_endpoint(_bEndpointAddress_) ((_bEndpointAddress_ & USB_ENDPOINT_NUMBER_MASK) | \
  80790. + ((_bEndpointAddress_ & USB_DIR_IN) != 0) << 4)
  80791. +
  80792. +static const char dwc_otg_hcd_name[] = "dwc_otg_hcd";
  80793. +
  80794. +extern bool fiq_enable;
  80795. +
  80796. +/** @name Linux HC Driver API Functions */
  80797. +/** @{ */
  80798. +/* manage i/o requests, device state */
  80799. +static int dwc_otg_urb_enqueue(struct usb_hcd *hcd,
  80800. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  80801. + struct usb_host_endpoint *ep,
  80802. +#endif
  80803. + struct urb *urb, gfp_t mem_flags);
  80804. +
  80805. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  80806. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  80807. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb);
  80808. +#endif
  80809. +#else /* kernels at or post 2.6.30 */
  80810. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd,
  80811. + struct urb *urb, int status);
  80812. +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30) */
  80813. +
  80814. +static void endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep);
  80815. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  80816. +static void endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep);
  80817. +#endif
  80818. +static irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd);
  80819. +extern int hcd_start(struct usb_hcd *hcd);
  80820. +extern void hcd_stop(struct usb_hcd *hcd);
  80821. +static int get_frame_number(struct usb_hcd *hcd);
  80822. +extern int hub_status_data(struct usb_hcd *hcd, char *buf);
  80823. +extern int hub_control(struct usb_hcd *hcd,
  80824. + u16 typeReq,
  80825. + u16 wValue, u16 wIndex, char *buf, u16 wLength);
  80826. +
  80827. +struct wrapper_priv_data {
  80828. + dwc_otg_hcd_t *dwc_otg_hcd;
  80829. +};
  80830. +
  80831. +/** @} */
  80832. +
  80833. +static struct hc_driver dwc_otg_hc_driver = {
  80834. +
  80835. + .description = dwc_otg_hcd_name,
  80836. + .product_desc = "DWC OTG Controller",
  80837. + .hcd_priv_size = sizeof(struct wrapper_priv_data),
  80838. +
  80839. + .irq = dwc_otg_hcd_irq,
  80840. +
  80841. + .flags = HCD_MEMORY | HCD_USB2,
  80842. +
  80843. + //.reset =
  80844. + .start = hcd_start,
  80845. + //.suspend =
  80846. + //.resume =
  80847. + .stop = hcd_stop,
  80848. +
  80849. + .urb_enqueue = dwc_otg_urb_enqueue,
  80850. + .urb_dequeue = dwc_otg_urb_dequeue,
  80851. + .endpoint_disable = endpoint_disable,
  80852. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  80853. + .endpoint_reset = endpoint_reset,
  80854. +#endif
  80855. + .get_frame_number = get_frame_number,
  80856. +
  80857. + .hub_status_data = hub_status_data,
  80858. + .hub_control = hub_control,
  80859. + //.bus_suspend =
  80860. + //.bus_resume =
  80861. +};
  80862. +
  80863. +/** Gets the dwc_otg_hcd from a struct usb_hcd */
  80864. +static inline dwc_otg_hcd_t *hcd_to_dwc_otg_hcd(struct usb_hcd *hcd)
  80865. +{
  80866. + struct wrapper_priv_data *p;
  80867. + p = (struct wrapper_priv_data *)(hcd->hcd_priv);
  80868. + return p->dwc_otg_hcd;
  80869. +}
  80870. +
  80871. +/** Gets the struct usb_hcd that contains a dwc_otg_hcd_t. */
  80872. +static inline struct usb_hcd *dwc_otg_hcd_to_hcd(dwc_otg_hcd_t * dwc_otg_hcd)
  80873. +{
  80874. + return dwc_otg_hcd_get_priv_data(dwc_otg_hcd);
  80875. +}
  80876. +
  80877. +/** Gets the usb_host_endpoint associated with an URB. */
  80878. +inline struct usb_host_endpoint *dwc_urb_to_endpoint(struct urb *urb)
  80879. +{
  80880. + struct usb_device *dev = urb->dev;
  80881. + int ep_num = usb_pipeendpoint(urb->pipe);
  80882. +
  80883. + if (usb_pipein(urb->pipe))
  80884. + return dev->ep_in[ep_num];
  80885. + else
  80886. + return dev->ep_out[ep_num];
  80887. +}
  80888. +
  80889. +static int _disconnect(dwc_otg_hcd_t * hcd)
  80890. +{
  80891. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  80892. +
  80893. + usb_hcd->self.is_b_host = 0;
  80894. + return 0;
  80895. +}
  80896. +
  80897. +static int _start(dwc_otg_hcd_t * hcd)
  80898. +{
  80899. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  80900. +
  80901. + usb_hcd->self.is_b_host = dwc_otg_hcd_is_b_host(hcd);
  80902. + hcd_start(usb_hcd);
  80903. +
  80904. + return 0;
  80905. +}
  80906. +
  80907. +static int _hub_info(dwc_otg_hcd_t * hcd, void *urb_handle, uint32_t * hub_addr,
  80908. + uint32_t * port_addr)
  80909. +{
  80910. + struct urb *urb = (struct urb *)urb_handle;
  80911. + struct usb_bus *bus;
  80912. +#if 1 //GRAYG - temporary
  80913. + if (NULL == urb_handle)
  80914. + DWC_ERROR("**** %s - NULL URB handle\n", __func__);//GRAYG
  80915. + if (NULL == urb->dev)
  80916. + DWC_ERROR("**** %s - URB has no device\n", __func__);//GRAYG
  80917. + if (NULL == port_addr)
  80918. + DWC_ERROR("**** %s - NULL port_address\n", __func__);//GRAYG
  80919. +#endif
  80920. + if (urb->dev->tt) {
  80921. + if (NULL == urb->dev->tt->hub) {
  80922. + DWC_ERROR("**** %s - (URB's transactor has no TT - giving no hub)\n",
  80923. + __func__); //GRAYG
  80924. + //*hub_addr = (u8)usb_pipedevice(urb->pipe); //GRAYG
  80925. + *hub_addr = 0; //GRAYG
  80926. + // we probably shouldn't have a transaction translator if
  80927. + // there's no associated hub?
  80928. + } else {
  80929. + bus = hcd_to_bus(dwc_otg_hcd_to_hcd(hcd));
  80930. + if (urb->dev->tt->hub == bus->root_hub)
  80931. + *hub_addr = 0;
  80932. + else
  80933. + *hub_addr = urb->dev->tt->hub->devnum;
  80934. + }
  80935. + *port_addr = urb->dev->tt->multi ? urb->dev->ttport : 1;
  80936. + } else {
  80937. + *hub_addr = 0;
  80938. + *port_addr = urb->dev->ttport;
  80939. + }
  80940. + return 0;
  80941. +}
  80942. +
  80943. +static int _speed(dwc_otg_hcd_t * hcd, void *urb_handle)
  80944. +{
  80945. + struct urb *urb = (struct urb *)urb_handle;
  80946. + return urb->dev->speed;
  80947. +}
  80948. +
  80949. +static int _get_b_hnp_enable(dwc_otg_hcd_t * hcd)
  80950. +{
  80951. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  80952. + return usb_hcd->self.b_hnp_enable;
  80953. +}
  80954. +
  80955. +static void allocate_bus_bandwidth(struct usb_hcd *hcd, uint32_t bw,
  80956. + struct urb *urb)
  80957. +{
  80958. + hcd_to_bus(hcd)->bandwidth_allocated += bw / urb->interval;
  80959. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  80960. + hcd_to_bus(hcd)->bandwidth_isoc_reqs++;
  80961. + } else {
  80962. + hcd_to_bus(hcd)->bandwidth_int_reqs++;
  80963. + }
  80964. +}
  80965. +
  80966. +static void free_bus_bandwidth(struct usb_hcd *hcd, uint32_t bw,
  80967. + struct urb *urb)
  80968. +{
  80969. + hcd_to_bus(hcd)->bandwidth_allocated -= bw / urb->interval;
  80970. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  80971. + hcd_to_bus(hcd)->bandwidth_isoc_reqs--;
  80972. + } else {
  80973. + hcd_to_bus(hcd)->bandwidth_int_reqs--;
  80974. + }
  80975. +}
  80976. +
  80977. +/**
  80978. + * Sets the final status of an URB and returns it to the device driver. Any
  80979. + * required cleanup of the URB is performed. The HCD lock should be held on
  80980. + * entry.
  80981. + */
  80982. +static int _complete(dwc_otg_hcd_t * hcd, void *urb_handle,
  80983. + dwc_otg_hcd_urb_t * dwc_otg_urb, int32_t status)
  80984. +{
  80985. + struct urb *urb = (struct urb *)urb_handle;
  80986. + urb_tq_entry_t *new_entry;
  80987. + int rc = 0;
  80988. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  80989. + DWC_PRINTF("%s: urb %p, device %d, ep %d %s, status=%d\n",
  80990. + __func__, urb, usb_pipedevice(urb->pipe),
  80991. + usb_pipeendpoint(urb->pipe),
  80992. + usb_pipein(urb->pipe) ? "IN" : "OUT", status);
  80993. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  80994. + int i;
  80995. + for (i = 0; i < urb->number_of_packets; i++) {
  80996. + DWC_PRINTF(" ISO Desc %d status: %d\n",
  80997. + i, urb->iso_frame_desc[i].status);
  80998. + }
  80999. + }
  81000. + }
  81001. + new_entry = DWC_ALLOC_ATOMIC(sizeof(urb_tq_entry_t));
  81002. + urb->actual_length = dwc_otg_hcd_urb_get_actual_length(dwc_otg_urb);
  81003. + /* Convert status value. */
  81004. + switch (status) {
  81005. + case -DWC_E_PROTOCOL:
  81006. + status = -EPROTO;
  81007. + break;
  81008. + case -DWC_E_IN_PROGRESS:
  81009. + status = -EINPROGRESS;
  81010. + break;
  81011. + case -DWC_E_PIPE:
  81012. + status = -EPIPE;
  81013. + break;
  81014. + case -DWC_E_IO:
  81015. + status = -EIO;
  81016. + break;
  81017. + case -DWC_E_TIMEOUT:
  81018. + status = -ETIMEDOUT;
  81019. + break;
  81020. + case -DWC_E_OVERFLOW:
  81021. + status = -EOVERFLOW;
  81022. + break;
  81023. + case -DWC_E_SHUTDOWN:
  81024. + status = -ESHUTDOWN;
  81025. + break;
  81026. + default:
  81027. + if (status) {
  81028. + DWC_PRINTF("Uknown urb status %d\n", status);
  81029. +
  81030. + }
  81031. + }
  81032. +
  81033. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  81034. + int i;
  81035. +
  81036. + urb->error_count = dwc_otg_hcd_urb_get_error_count(dwc_otg_urb);
  81037. + for (i = 0; i < urb->number_of_packets; ++i) {
  81038. + urb->iso_frame_desc[i].actual_length =
  81039. + dwc_otg_hcd_urb_get_iso_desc_actual_length
  81040. + (dwc_otg_urb, i);
  81041. + urb->iso_frame_desc[i].status =
  81042. + dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_urb, i);
  81043. + }
  81044. + }
  81045. +
  81046. + urb->status = status;
  81047. + urb->hcpriv = NULL;
  81048. + if (!status) {
  81049. + if ((urb->transfer_flags & URB_SHORT_NOT_OK) &&
  81050. + (urb->actual_length < urb->transfer_buffer_length)) {
  81051. + urb->status = -EREMOTEIO;
  81052. + }
  81053. + }
  81054. +
  81055. + if ((usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) ||
  81056. + (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)) {
  81057. + struct usb_host_endpoint *ep = dwc_urb_to_endpoint(urb);
  81058. + if (ep) {
  81059. + free_bus_bandwidth(dwc_otg_hcd_to_hcd(hcd),
  81060. + dwc_otg_hcd_get_ep_bandwidth(hcd,
  81061. + ep->hcpriv),
  81062. + urb);
  81063. + }
  81064. + }
  81065. + DWC_FREE(dwc_otg_urb);
  81066. + if (!new_entry) {
  81067. + DWC_ERROR("dwc_otg_hcd: complete: cannot allocate URB TQ entry\n");
  81068. + urb->status = -EPROTO;
  81069. + /* don't schedule the tasklet -
  81070. + * directly return the packet here with error. */
  81071. +#if USB_URB_EP_LINKING
  81072. + usb_hcd_unlink_urb_from_ep(dwc_otg_hcd_to_hcd(hcd), urb);
  81073. +#endif
  81074. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  81075. + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(hcd), urb);
  81076. +#else
  81077. + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(hcd), urb, urb->status);
  81078. +#endif
  81079. + } else {
  81080. + new_entry->urb = urb;
  81081. +#if USB_URB_EP_LINKING
  81082. + rc = usb_hcd_check_unlink_urb(dwc_otg_hcd_to_hcd(hcd), urb, urb->status);
  81083. + if(0 == rc) {
  81084. + usb_hcd_unlink_urb_from_ep(dwc_otg_hcd_to_hcd(hcd), urb);
  81085. + }
  81086. +#endif
  81087. + if(0 == rc) {
  81088. + DWC_TAILQ_INSERT_TAIL(&hcd->completed_urb_list, new_entry,
  81089. + urb_tq_entries);
  81090. + DWC_TASK_HI_SCHEDULE(hcd->completion_tasklet);
  81091. + }
  81092. + }
  81093. + return 0;
  81094. +}
  81095. +
  81096. +static struct dwc_otg_hcd_function_ops hcd_fops = {
  81097. + .start = _start,
  81098. + .disconnect = _disconnect,
  81099. + .hub_info = _hub_info,
  81100. + .speed = _speed,
  81101. + .complete = _complete,
  81102. + .get_b_hnp_enable = _get_b_hnp_enable,
  81103. +};
  81104. +
  81105. +static struct fiq_handler fh = {
  81106. + .name = "usb_fiq",
  81107. +};
  81108. +
  81109. +
  81110. +
  81111. +/**
  81112. + * Initializes the HCD. This function allocates memory for and initializes the
  81113. + * static parts of the usb_hcd and dwc_otg_hcd structures. It also registers the
  81114. + * USB bus with the core and calls the hc_driver->start() function. It returns
  81115. + * a negative error on failure.
  81116. + */
  81117. +int hcd_init(dwc_bus_dev_t *_dev)
  81118. +{
  81119. + struct usb_hcd *hcd = NULL;
  81120. + dwc_otg_hcd_t *dwc_otg_hcd = NULL;
  81121. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  81122. + int retval = 0;
  81123. + u64 dmamask;
  81124. + struct pt_regs regs;
  81125. +
  81126. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD INIT otg_dev=%p\n", otg_dev);
  81127. +
  81128. + /* Set device flags indicating whether the HCD supports DMA. */
  81129. + if (dwc_otg_is_dma_enable(otg_dev->core_if))
  81130. + dmamask = DMA_BIT_MASK(32);
  81131. + else
  81132. + dmamask = 0;
  81133. +
  81134. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  81135. + dma_set_mask(&_dev->dev, dmamask);
  81136. + dma_set_coherent_mask(&_dev->dev, dmamask);
  81137. +#elif defined(PCI_INTERFACE)
  81138. + pci_set_dma_mask(_dev, dmamask);
  81139. + pci_set_consistent_dma_mask(_dev, dmamask);
  81140. +#endif
  81141. +
  81142. + /*
  81143. + * Allocate memory for the base HCD plus the DWC OTG HCD.
  81144. + * Initialize the base HCD.
  81145. + */
  81146. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  81147. + hcd = usb_create_hcd(&dwc_otg_hc_driver, &_dev->dev, _dev->dev.bus_id);
  81148. +#else
  81149. + hcd = usb_create_hcd(&dwc_otg_hc_driver, &_dev->dev, dev_name(&_dev->dev));
  81150. + hcd->has_tt = 1;
  81151. +// hcd->uses_new_polling = 1;
  81152. +// hcd->poll_rh = 0;
  81153. +#endif
  81154. + if (!hcd) {
  81155. + retval = -ENOMEM;
  81156. + goto error1;
  81157. + }
  81158. +
  81159. + hcd->regs = otg_dev->os_dep.base;
  81160. +
  81161. +
  81162. + /* Initialize the DWC OTG HCD. */
  81163. + dwc_otg_hcd = dwc_otg_hcd_alloc_hcd();
  81164. + if (!dwc_otg_hcd) {
  81165. + goto error2;
  81166. + }
  81167. + ((struct wrapper_priv_data *)(hcd->hcd_priv))->dwc_otg_hcd =
  81168. + dwc_otg_hcd;
  81169. + otg_dev->hcd = dwc_otg_hcd;
  81170. +
  81171. + if (dwc_otg_hcd_init(dwc_otg_hcd, otg_dev->core_if)) {
  81172. + goto error2;
  81173. + }
  81174. +
  81175. + if (fiq_enable)
  81176. + {
  81177. + if (claim_fiq(&fh)) {
  81178. + DWC_ERROR("Can't claim FIQ");
  81179. + goto error2;
  81180. + }
  81181. +
  81182. + DWC_WARN("FIQ at 0x%08x", (fiq_fsm_enable ? (int)&dwc_otg_fiq_fsm : (int)&dwc_otg_fiq_nop));
  81183. + DWC_WARN("FIQ ASM at 0x%08x length %d", (int)&_dwc_otg_fiq_stub, (int)(&_dwc_otg_fiq_stub_end - &_dwc_otg_fiq_stub));
  81184. +
  81185. + set_fiq_handler((void *) &_dwc_otg_fiq_stub, &_dwc_otg_fiq_stub_end - &_dwc_otg_fiq_stub);
  81186. + memset(&regs,0,sizeof(regs));
  81187. +
  81188. + regs.ARM_r8 = (long) dwc_otg_hcd->fiq_state;
  81189. + if (fiq_fsm_enable) {
  81190. + regs.ARM_r9 = dwc_otg_hcd->core_if->core_params->host_channels;
  81191. + //regs.ARM_r10 = dwc_otg_hcd->dma;
  81192. + regs.ARM_fp = (long) dwc_otg_fiq_fsm;
  81193. + } else {
  81194. + regs.ARM_fp = (long) dwc_otg_fiq_nop;
  81195. + }
  81196. +
  81197. + regs.ARM_sp = (long) dwc_otg_hcd->fiq_stack + (sizeof(struct fiq_stack) - 4);
  81198. +
  81199. +// __show_regs(&regs);
  81200. + set_fiq_regs(&regs);
  81201. +
  81202. + //Set the mphi periph to the required registers
  81203. + dwc_otg_hcd->fiq_state->mphi_regs.base = otg_dev->os_dep.mphi_base;
  81204. + dwc_otg_hcd->fiq_state->mphi_regs.ctrl = otg_dev->os_dep.mphi_base + 0x4c;
  81205. + dwc_otg_hcd->fiq_state->mphi_regs.outdda = otg_dev->os_dep.mphi_base + 0x28;
  81206. + dwc_otg_hcd->fiq_state->mphi_regs.outddb = otg_dev->os_dep.mphi_base + 0x2c;
  81207. + dwc_otg_hcd->fiq_state->mphi_regs.intstat = otg_dev->os_dep.mphi_base + 0x50;
  81208. + dwc_otg_hcd->fiq_state->dwc_regs_base = otg_dev->os_dep.base;
  81209. + DWC_WARN("MPHI regs_base at 0x%08x", (int)dwc_otg_hcd->fiq_state->mphi_regs.base);
  81210. + //Enable mphi peripheral
  81211. + writel((1<<31),dwc_otg_hcd->fiq_state->mphi_regs.ctrl);
  81212. +#ifdef DEBUG
  81213. + if (readl(dwc_otg_hcd->fiq_state->mphi_regs.ctrl) & 0x80000000)
  81214. + DWC_WARN("MPHI periph has been enabled");
  81215. + else
  81216. + DWC_WARN("MPHI periph has NOT been enabled");
  81217. +#endif
  81218. + // Enable FIQ interrupt from USB peripheral
  81219. + enable_fiq(INTERRUPT_VC_USB);
  81220. + local_fiq_enable();
  81221. + }
  81222. +
  81223. +
  81224. + otg_dev->hcd->otg_dev = otg_dev;
  81225. + hcd->self.otg_port = dwc_otg_hcd_otg_port(dwc_otg_hcd);
  81226. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33) //don't support for LM(with 2.6.20.1 kernel)
  81227. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) //version field absent later
  81228. + hcd->self.otg_version = dwc_otg_get_otg_version(otg_dev->core_if);
  81229. +#endif
  81230. + /* Don't support SG list at this point */
  81231. + hcd->self.sg_tablesize = 0;
  81232. +#endif
  81233. + /*
  81234. + * Finish generic HCD initialization and start the HCD. This function
  81235. + * allocates the DMA buffer pool, registers the USB bus, requests the
  81236. + * IRQ line, and calls hcd_start method.
  81237. + */
  81238. +#ifdef PLATFORM_INTERFACE
  81239. + retval = usb_add_hcd(hcd, platform_get_irq(_dev, fiq_enable ? 0 : 1), IRQF_SHARED | IRQF_DISABLED);
  81240. +#else
  81241. + retval = usb_add_hcd(hcd, _dev->irq, IRQF_SHARED | IRQF_DISABLED);
  81242. +#endif
  81243. + if (retval < 0) {
  81244. + goto error2;
  81245. + }
  81246. +
  81247. + dwc_otg_hcd_set_priv_data(dwc_otg_hcd, hcd);
  81248. + return 0;
  81249. +
  81250. +error2:
  81251. + usb_put_hcd(hcd);
  81252. +error1:
  81253. + return retval;
  81254. +}
  81255. +
  81256. +/**
  81257. + * Removes the HCD.
  81258. + * Frees memory and resources associated with the HCD and deregisters the bus.
  81259. + */
  81260. +void hcd_remove(dwc_bus_dev_t *_dev)
  81261. +{
  81262. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  81263. + dwc_otg_hcd_t *dwc_otg_hcd;
  81264. + struct usb_hcd *hcd;
  81265. +
  81266. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD REMOVE otg_dev=%p\n", otg_dev);
  81267. +
  81268. + if (!otg_dev) {
  81269. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev NULL!\n", __func__);
  81270. + return;
  81271. + }
  81272. +
  81273. + dwc_otg_hcd = otg_dev->hcd;
  81274. +
  81275. + if (!dwc_otg_hcd) {
  81276. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->hcd NULL!\n", __func__);
  81277. + return;
  81278. + }
  81279. +
  81280. + hcd = dwc_otg_hcd_to_hcd(dwc_otg_hcd);
  81281. +
  81282. + if (!hcd) {
  81283. + DWC_DEBUGPL(DBG_ANY,
  81284. + "%s: dwc_otg_hcd_to_hcd(dwc_otg_hcd) NULL!\n",
  81285. + __func__);
  81286. + return;
  81287. + }
  81288. + usb_remove_hcd(hcd);
  81289. + dwc_otg_hcd_set_priv_data(dwc_otg_hcd, NULL);
  81290. + dwc_otg_hcd_remove(dwc_otg_hcd);
  81291. + usb_put_hcd(hcd);
  81292. +}
  81293. +
  81294. +/* =========================================================================
  81295. + * Linux HC Driver Functions
  81296. + * ========================================================================= */
  81297. +
  81298. +/** Initializes the DWC_otg controller and its root hub and prepares it for host
  81299. + * mode operation. Activates the root port. Returns 0 on success and a negative
  81300. + * error code on failure. */
  81301. +int hcd_start(struct usb_hcd *hcd)
  81302. +{
  81303. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  81304. + struct usb_bus *bus;
  81305. +
  81306. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD START\n");
  81307. + bus = hcd_to_bus(hcd);
  81308. +
  81309. + hcd->state = HC_STATE_RUNNING;
  81310. + if (dwc_otg_hcd_start(dwc_otg_hcd, &hcd_fops)) {
  81311. + return 0;
  81312. + }
  81313. +
  81314. + /* Initialize and connect root hub if one is not already attached */
  81315. + if (bus->root_hub) {
  81316. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Has Root Hub\n");
  81317. + /* Inform the HUB driver to resume. */
  81318. + usb_hcd_resume_root_hub(hcd);
  81319. + }
  81320. +
  81321. + return 0;
  81322. +}
  81323. +
  81324. +/**
  81325. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  81326. + * stopped.
  81327. + */
  81328. +void hcd_stop(struct usb_hcd *hcd)
  81329. +{
  81330. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  81331. +
  81332. + dwc_otg_hcd_stop(dwc_otg_hcd);
  81333. +}
  81334. +
  81335. +/** Returns the current frame number. */
  81336. +static int get_frame_number(struct usb_hcd *hcd)
  81337. +{
  81338. + hprt0_data_t hprt0;
  81339. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  81340. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  81341. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED)
  81342. + return dwc_otg_hcd_get_frame_number(dwc_otg_hcd) >> 3;
  81343. + else
  81344. + return dwc_otg_hcd_get_frame_number(dwc_otg_hcd);
  81345. +}
  81346. +
  81347. +#ifdef DEBUG
  81348. +static void dump_urb_info(struct urb *urb, char *fn_name)
  81349. +{
  81350. + DWC_PRINTF("%s, urb %p\n", fn_name, urb);
  81351. + DWC_PRINTF(" Device address: %d\n", usb_pipedevice(urb->pipe));
  81352. + DWC_PRINTF(" Endpoint: %d, %s\n", usb_pipeendpoint(urb->pipe),
  81353. + (usb_pipein(urb->pipe) ? "IN" : "OUT"));
  81354. + DWC_PRINTF(" Endpoint type: %s\n", ( {
  81355. + char *pipetype;
  81356. + switch (usb_pipetype(urb->pipe)) {
  81357. +case PIPE_CONTROL:
  81358. +pipetype = "CONTROL"; break; case PIPE_BULK:
  81359. +pipetype = "BULK"; break; case PIPE_INTERRUPT:
  81360. +pipetype = "INTERRUPT"; break; case PIPE_ISOCHRONOUS:
  81361. +pipetype = "ISOCHRONOUS"; break; default:
  81362. + pipetype = "UNKNOWN"; break;};
  81363. + pipetype;}
  81364. + )) ;
  81365. + DWC_PRINTF(" Speed: %s\n", ( {
  81366. + char *speed; switch (urb->dev->speed) {
  81367. +case USB_SPEED_HIGH:
  81368. +speed = "HIGH"; break; case USB_SPEED_FULL:
  81369. +speed = "FULL"; break; case USB_SPEED_LOW:
  81370. +speed = "LOW"; break; default:
  81371. + speed = "UNKNOWN"; break;};
  81372. + speed;}
  81373. + )) ;
  81374. + DWC_PRINTF(" Max packet size: %d\n",
  81375. + usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)));
  81376. + DWC_PRINTF(" Data buffer length: %d\n", urb->transfer_buffer_length);
  81377. + DWC_PRINTF(" Transfer buffer: %p, Transfer DMA: %p\n",
  81378. + urb->transfer_buffer, (void *)urb->transfer_dma);
  81379. + DWC_PRINTF(" Setup buffer: %p, Setup DMA: %p\n",
  81380. + urb->setup_packet, (void *)urb->setup_dma);
  81381. + DWC_PRINTF(" Interval: %d\n", urb->interval);
  81382. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  81383. + int i;
  81384. + for (i = 0; i < urb->number_of_packets; i++) {
  81385. + DWC_PRINTF(" ISO Desc %d:\n", i);
  81386. + DWC_PRINTF(" offset: %d, length %d\n",
  81387. + urb->iso_frame_desc[i].offset,
  81388. + urb->iso_frame_desc[i].length);
  81389. + }
  81390. + }
  81391. +}
  81392. +#endif
  81393. +
  81394. +/** Starts processing a USB transfer request specified by a USB Request Block
  81395. + * (URB). mem_flags indicates the type of memory allocation to use while
  81396. + * processing this URB. */
  81397. +static int dwc_otg_urb_enqueue(struct usb_hcd *hcd,
  81398. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  81399. + struct usb_host_endpoint *ep,
  81400. +#endif
  81401. + struct urb *urb, gfp_t mem_flags)
  81402. +{
  81403. + int retval = 0;
  81404. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
  81405. + struct usb_host_endpoint *ep = urb->ep;
  81406. +#endif
  81407. + dwc_irqflags_t irqflags;
  81408. + void **ref_ep_hcpriv = &ep->hcpriv;
  81409. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  81410. + dwc_otg_hcd_urb_t *dwc_otg_urb;
  81411. + int i;
  81412. + int alloc_bandwidth = 0;
  81413. + uint8_t ep_type = 0;
  81414. + uint32_t flags = 0;
  81415. + void *buf;
  81416. +
  81417. +#ifdef DEBUG
  81418. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  81419. + dump_urb_info(urb, "dwc_otg_urb_enqueue");
  81420. + }
  81421. +#endif
  81422. +
  81423. + if (!urb->transfer_buffer && urb->transfer_buffer_length)
  81424. + return -EINVAL;
  81425. +
  81426. + if ((usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS)
  81427. + || (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)) {
  81428. + if (!dwc_otg_hcd_is_bandwidth_allocated
  81429. + (dwc_otg_hcd, ref_ep_hcpriv)) {
  81430. + alloc_bandwidth = 1;
  81431. + }
  81432. + }
  81433. +
  81434. + switch (usb_pipetype(urb->pipe)) {
  81435. + case PIPE_CONTROL:
  81436. + ep_type = USB_ENDPOINT_XFER_CONTROL;
  81437. + break;
  81438. + case PIPE_ISOCHRONOUS:
  81439. + ep_type = USB_ENDPOINT_XFER_ISOC;
  81440. + break;
  81441. + case PIPE_BULK:
  81442. + ep_type = USB_ENDPOINT_XFER_BULK;
  81443. + break;
  81444. + case PIPE_INTERRUPT:
  81445. + ep_type = USB_ENDPOINT_XFER_INT;
  81446. + break;
  81447. + default:
  81448. + DWC_WARN("Wrong EP type - %d\n", usb_pipetype(urb->pipe));
  81449. + }
  81450. +
  81451. + /* # of packets is often 0 - do we really need to call this then? */
  81452. + dwc_otg_urb = dwc_otg_hcd_urb_alloc(dwc_otg_hcd,
  81453. + urb->number_of_packets,
  81454. + mem_flags == GFP_ATOMIC ? 1 : 0);
  81455. +
  81456. + if(dwc_otg_urb == NULL)
  81457. + return -ENOMEM;
  81458. +
  81459. + if (!dwc_otg_urb && urb->number_of_packets)
  81460. + return -ENOMEM;
  81461. +
  81462. + dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_urb, usb_pipedevice(urb->pipe),
  81463. + usb_pipeendpoint(urb->pipe), ep_type,
  81464. + usb_pipein(urb->pipe),
  81465. + usb_maxpacket(urb->dev, urb->pipe,
  81466. + !(usb_pipein(urb->pipe))));
  81467. +
  81468. + buf = urb->transfer_buffer;
  81469. + if (hcd->self.uses_dma) {
  81470. + /*
  81471. + * Calculate virtual address from physical address,
  81472. + * because some class driver may not fill transfer_buffer.
  81473. + * In Buffer DMA mode virual address is used,
  81474. + * when handling non DWORD aligned buffers.
  81475. + */
  81476. + //buf = phys_to_virt(urb->transfer_dma);
  81477. + // DMA addresses are bus addresses not physical addresses!
  81478. + buf = dma_to_virt(&urb->dev->dev, urb->transfer_dma);
  81479. + }
  81480. +
  81481. + if (!(urb->transfer_flags & URB_NO_INTERRUPT))
  81482. + flags |= URB_GIVEBACK_ASAP;
  81483. + if (urb->transfer_flags & URB_ZERO_PACKET)
  81484. + flags |= URB_SEND_ZERO_PACKET;
  81485. +
  81486. + dwc_otg_hcd_urb_set_params(dwc_otg_urb, urb, buf,
  81487. + urb->transfer_dma,
  81488. + urb->transfer_buffer_length,
  81489. + urb->setup_packet,
  81490. + urb->setup_dma, flags, urb->interval);
  81491. +
  81492. + for (i = 0; i < urb->number_of_packets; ++i) {
  81493. + dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_urb, i,
  81494. + urb->
  81495. + iso_frame_desc[i].offset,
  81496. + urb->
  81497. + iso_frame_desc[i].length);
  81498. + }
  81499. +
  81500. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &irqflags);
  81501. + urb->hcpriv = dwc_otg_urb;
  81502. +#if USB_URB_EP_LINKING
  81503. + retval = usb_hcd_link_urb_to_ep(hcd, urb);
  81504. + if (0 == retval)
  81505. +#endif
  81506. + {
  81507. + retval = dwc_otg_hcd_urb_enqueue(dwc_otg_hcd, dwc_otg_urb,
  81508. + /*(dwc_otg_qh_t **)*/
  81509. + ref_ep_hcpriv, 1);
  81510. + if (0 == retval) {
  81511. + if (alloc_bandwidth) {
  81512. + allocate_bus_bandwidth(hcd,
  81513. + dwc_otg_hcd_get_ep_bandwidth(
  81514. + dwc_otg_hcd, *ref_ep_hcpriv),
  81515. + urb);
  81516. + }
  81517. + } else {
  81518. + DWC_DEBUGPL(DBG_HCD, "DWC OTG dwc_otg_hcd_urb_enqueue failed rc %d\n", retval);
  81519. +#if USB_URB_EP_LINKING
  81520. + usb_hcd_unlink_urb_from_ep(hcd, urb);
  81521. +#endif
  81522. + DWC_FREE(dwc_otg_urb);
  81523. + urb->hcpriv = NULL;
  81524. + if (retval == -DWC_E_NO_DEVICE)
  81525. + retval = -ENODEV;
  81526. + }
  81527. + }
  81528. +#if USB_URB_EP_LINKING
  81529. + else
  81530. + {
  81531. + DWC_FREE(dwc_otg_urb);
  81532. + urb->hcpriv = NULL;
  81533. + }
  81534. +#endif
  81535. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, irqflags);
  81536. + return retval;
  81537. +}
  81538. +
  81539. +/** Aborts/cancels a USB transfer request. Always returns 0 to indicate
  81540. + * success. */
  81541. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  81542. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
  81543. +#else
  81544. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  81545. +#endif
  81546. +{
  81547. + dwc_irqflags_t flags;
  81548. + dwc_otg_hcd_t *dwc_otg_hcd;
  81549. + int rc;
  81550. +
  81551. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue\n");
  81552. +
  81553. + dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  81554. +
  81555. +#ifdef DEBUG
  81556. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  81557. + dump_urb_info(urb, "dwc_otg_urb_dequeue");
  81558. + }
  81559. +#endif
  81560. +
  81561. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  81562. + rc = usb_hcd_check_unlink_urb(hcd, urb, status);
  81563. + if (0 == rc) {
  81564. + if(urb->hcpriv != NULL) {
  81565. + dwc_otg_hcd_urb_dequeue(dwc_otg_hcd,
  81566. + (dwc_otg_hcd_urb_t *)urb->hcpriv);
  81567. +
  81568. + DWC_FREE(urb->hcpriv);
  81569. + urb->hcpriv = NULL;
  81570. + }
  81571. + }
  81572. +
  81573. + if (0 == rc) {
  81574. + /* Higher layer software sets URB status. */
  81575. +#if USB_URB_EP_LINKING
  81576. + usb_hcd_unlink_urb_from_ep(hcd, urb);
  81577. +#endif
  81578. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  81579. +
  81580. +
  81581. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  81582. + usb_hcd_giveback_urb(hcd, urb);
  81583. +#else
  81584. + usb_hcd_giveback_urb(hcd, urb, status);
  81585. +#endif
  81586. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  81587. + DWC_PRINTF("Called usb_hcd_giveback_urb() \n");
  81588. + DWC_PRINTF(" 1urb->status = %d\n", urb->status);
  81589. + }
  81590. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue OK\n");
  81591. + } else {
  81592. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  81593. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue failed - rc %d\n",
  81594. + rc);
  81595. + }
  81596. +
  81597. + return rc;
  81598. +}
  81599. +
  81600. +/* Frees resources in the DWC_otg controller related to a given endpoint. Also
  81601. + * clears state in the HCD related to the endpoint. Any URBs for the endpoint
  81602. + * must already be dequeued. */
  81603. +static void endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  81604. +{
  81605. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  81606. +
  81607. + DWC_DEBUGPL(DBG_HCD,
  81608. + "DWC OTG HCD EP DISABLE: _bEndpointAddress=0x%02x, "
  81609. + "endpoint=%d\n", ep->desc.bEndpointAddress,
  81610. + dwc_ep_addr_to_endpoint(ep->desc.bEndpointAddress));
  81611. + dwc_otg_hcd_endpoint_disable(dwc_otg_hcd, ep->hcpriv, 250);
  81612. + ep->hcpriv = NULL;
  81613. +}
  81614. +
  81615. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  81616. +/* Resets endpoint specific parameter values, in current version used to reset
  81617. + * the data toggle(as a WA). This function can be called from usb_clear_halt routine */
  81618. +static void endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  81619. +{
  81620. + dwc_irqflags_t flags;
  81621. + struct usb_device *udev = NULL;
  81622. + int epnum = usb_endpoint_num(&ep->desc);
  81623. + int is_out = usb_endpoint_dir_out(&ep->desc);
  81624. + int is_control = usb_endpoint_xfer_control(&ep->desc);
  81625. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  81626. + struct device *dev = DWC_OTG_OS_GETDEV(dwc_otg_hcd->otg_dev->os_dep);
  81627. +
  81628. + if (dev)
  81629. + udev = to_usb_device(dev);
  81630. + else
  81631. + return;
  81632. +
  81633. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD EP RESET: Endpoint Num=0x%02d\n", epnum);
  81634. +
  81635. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  81636. + usb_settoggle(udev, epnum, is_out, 0);
  81637. + if (is_control)
  81638. + usb_settoggle(udev, epnum, !is_out, 0);
  81639. +
  81640. + if (ep->hcpriv) {
  81641. + dwc_otg_hcd_endpoint_reset(dwc_otg_hcd, ep->hcpriv);
  81642. + }
  81643. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  81644. +}
  81645. +#endif
  81646. +
  81647. +/** Handles host mode interrupts for the DWC_otg controller. Returns IRQ_NONE if
  81648. + * there was no interrupt to handle. Returns IRQ_HANDLED if there was a valid
  81649. + * interrupt.
  81650. + *
  81651. + * This function is called by the USB core when an interrupt occurs */
  81652. +static irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd)
  81653. +{
  81654. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  81655. + int32_t retval = dwc_otg_hcd_handle_intr(dwc_otg_hcd);
  81656. + if (retval != 0) {
  81657. + S3C2410X_CLEAR_EINTPEND();
  81658. + }
  81659. + return IRQ_RETVAL(retval);
  81660. +}
  81661. +
  81662. +/** Creates Status Change bitmap for the root hub and root port. The bitmap is
  81663. + * returned in buf. Bit 0 is the status change indicator for the root hub. Bit 1
  81664. + * is the status change indicator for the single root port. Returns 1 if either
  81665. + * change indicator is 1, otherwise returns 0. */
  81666. +int hub_status_data(struct usb_hcd *hcd, char *buf)
  81667. +{
  81668. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  81669. +
  81670. + buf[0] = 0;
  81671. + buf[0] |= (dwc_otg_hcd_is_status_changed(dwc_otg_hcd, 1)) << 1;
  81672. +
  81673. + return (buf[0] != 0);
  81674. +}
  81675. +
  81676. +/** Handles hub class-specific requests. */
  81677. +int hub_control(struct usb_hcd *hcd,
  81678. + u16 typeReq, u16 wValue, u16 wIndex, char *buf, u16 wLength)
  81679. +{
  81680. + int retval;
  81681. +
  81682. + retval = dwc_otg_hcd_hub_control(hcd_to_dwc_otg_hcd(hcd),
  81683. + typeReq, wValue, wIndex, buf, wLength);
  81684. +
  81685. + switch (retval) {
  81686. + case -DWC_E_INVALID:
  81687. + retval = -EINVAL;
  81688. + break;
  81689. + }
  81690. +
  81691. + return retval;
  81692. +}
  81693. +
  81694. +#endif /* DWC_DEVICE_ONLY */
  81695. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c
  81696. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c 1970-01-01 01:00:00.000000000 +0100
  81697. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c 2014-07-07 10:45:43.000000000 +0200
  81698. @@ -0,0 +1,942 @@
  81699. +/* ==========================================================================
  81700. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_queue.c $
  81701. + * $Revision: #44 $
  81702. + * $Date: 2011/10/26 $
  81703. + * $Change: 1873028 $
  81704. + *
  81705. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  81706. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  81707. + * otherwise expressly agreed to in writing between Synopsys and you.
  81708. + *
  81709. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  81710. + * any End User Software License Agreement or Agreement for Licensed Product
  81711. + * with Synopsys or any supplement thereto. You are permitted to use and
  81712. + * redistribute this Software in source and binary forms, with or without
  81713. + * modification, provided that redistributions of source code must retain this
  81714. + * notice. You may not view, use, disclose, copy or distribute this file or
  81715. + * any information contained herein except pursuant to this license grant from
  81716. + * Synopsys. If you do not agree with this notice, including the disclaimer
  81717. + * below, then you are not authorized to use the Software.
  81718. + *
  81719. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  81720. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  81721. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  81722. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  81723. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  81724. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  81725. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  81726. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  81727. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  81728. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  81729. + * DAMAGE.
  81730. + * ========================================================================== */
  81731. +#ifndef DWC_DEVICE_ONLY
  81732. +
  81733. +/**
  81734. + * @file
  81735. + *
  81736. + * This file contains the functions to manage Queue Heads and Queue
  81737. + * Transfer Descriptors.
  81738. + */
  81739. +
  81740. +#include "dwc_otg_hcd.h"
  81741. +#include "dwc_otg_regs.h"
  81742. +
  81743. +extern bool microframe_schedule;
  81744. +
  81745. +/**
  81746. + * Free each QTD in the QH's QTD-list then free the QH. QH should already be
  81747. + * removed from a list. QTD list should already be empty if called from URB
  81748. + * Dequeue.
  81749. + *
  81750. + * @param hcd HCD instance.
  81751. + * @param qh The QH to free.
  81752. + */
  81753. +void dwc_otg_hcd_qh_free(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  81754. +{
  81755. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  81756. +
  81757. + /* Free each QTD in the QTD list */
  81758. + DWC_SPINLOCK(hcd->lock);
  81759. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) {
  81760. + DWC_CIRCLEQ_REMOVE(&qh->qtd_list, qtd, qtd_list_entry);
  81761. + dwc_otg_hcd_qtd_free(qtd);
  81762. + }
  81763. +
  81764. + if (hcd->core_if->dma_desc_enable) {
  81765. + dwc_otg_hcd_qh_free_ddma(hcd, qh);
  81766. + } else if (qh->dw_align_buf) {
  81767. + uint32_t buf_size;
  81768. + if (qh->ep_type == UE_ISOCHRONOUS) {
  81769. + buf_size = 4096;
  81770. + } else {
  81771. + buf_size = hcd->core_if->core_params->max_transfer_size;
  81772. + }
  81773. + DWC_DMA_FREE(buf_size, qh->dw_align_buf, qh->dw_align_buf_dma);
  81774. + }
  81775. +
  81776. + DWC_FREE(qh);
  81777. + DWC_SPINUNLOCK(hcd->lock);
  81778. + return;
  81779. +}
  81780. +
  81781. +#define BitStuffTime(bytecount) ((8 * 7* bytecount) / 6)
  81782. +#define HS_HOST_DELAY 5 /* nanoseconds */
  81783. +#define FS_LS_HOST_DELAY 1000 /* nanoseconds */
  81784. +#define HUB_LS_SETUP 333 /* nanoseconds */
  81785. +#define NS_TO_US(ns) ((ns + 500) / 1000)
  81786. + /* convert & round nanoseconds to microseconds */
  81787. +
  81788. +static uint32_t calc_bus_time(int speed, int is_in, int is_isoc, int bytecount)
  81789. +{
  81790. + unsigned long retval;
  81791. +
  81792. + switch (speed) {
  81793. + case USB_SPEED_HIGH:
  81794. + if (is_isoc) {
  81795. + retval =
  81796. + ((38 * 8 * 2083) +
  81797. + (2083 * (3 + BitStuffTime(bytecount)))) / 1000 +
  81798. + HS_HOST_DELAY;
  81799. + } else {
  81800. + retval =
  81801. + ((55 * 8 * 2083) +
  81802. + (2083 * (3 + BitStuffTime(bytecount)))) / 1000 +
  81803. + HS_HOST_DELAY;
  81804. + }
  81805. + break;
  81806. + case USB_SPEED_FULL:
  81807. + if (is_isoc) {
  81808. + retval =
  81809. + (8354 * (31 + 10 * BitStuffTime(bytecount))) / 1000;
  81810. + if (is_in) {
  81811. + retval = 7268 + FS_LS_HOST_DELAY + retval;
  81812. + } else {
  81813. + retval = 6265 + FS_LS_HOST_DELAY + retval;
  81814. + }
  81815. + } else {
  81816. + retval =
  81817. + (8354 * (31 + 10 * BitStuffTime(bytecount))) / 1000;
  81818. + retval = 9107 + FS_LS_HOST_DELAY + retval;
  81819. + }
  81820. + break;
  81821. + case USB_SPEED_LOW:
  81822. + if (is_in) {
  81823. + retval =
  81824. + (67667 * (31 + 10 * BitStuffTime(bytecount))) /
  81825. + 1000;
  81826. + retval =
  81827. + 64060 + (2 * HUB_LS_SETUP) + FS_LS_HOST_DELAY +
  81828. + retval;
  81829. + } else {
  81830. + retval =
  81831. + (66700 * (31 + 10 * BitStuffTime(bytecount))) /
  81832. + 1000;
  81833. + retval =
  81834. + 64107 + (2 * HUB_LS_SETUP) + FS_LS_HOST_DELAY +
  81835. + retval;
  81836. + }
  81837. + break;
  81838. + default:
  81839. + DWC_WARN("Unknown device speed\n");
  81840. + retval = -1;
  81841. + }
  81842. +
  81843. + return NS_TO_US(retval);
  81844. +}
  81845. +
  81846. +/**
  81847. + * Initializes a QH structure.
  81848. + *
  81849. + * @param hcd The HCD state structure for the DWC OTG controller.
  81850. + * @param qh The QH to init.
  81851. + * @param urb Holds the information about the device/endpoint that we need
  81852. + * to initialize the QH.
  81853. + */
  81854. +#define SCHEDULE_SLOP 10
  81855. +void qh_init(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, dwc_otg_hcd_urb_t * urb)
  81856. +{
  81857. + char *speed, *type;
  81858. + int dev_speed;
  81859. + uint32_t hub_addr, hub_port;
  81860. +
  81861. + dwc_memset(qh, 0, sizeof(dwc_otg_qh_t));
  81862. +
  81863. + /* Initialize QH */
  81864. + qh->ep_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  81865. + qh->ep_is_in = dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? 1 : 0;
  81866. +
  81867. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  81868. + qh->maxp = dwc_otg_hcd_get_mps(&urb->pipe_info);
  81869. + DWC_CIRCLEQ_INIT(&qh->qtd_list);
  81870. + DWC_LIST_INIT(&qh->qh_list_entry);
  81871. + qh->channel = NULL;
  81872. +
  81873. + /* FS/LS Enpoint on HS Hub
  81874. + * NOT virtual root hub */
  81875. + dev_speed = hcd->fops->speed(hcd, urb->priv);
  81876. +
  81877. + hcd->fops->hub_info(hcd, urb->priv, &hub_addr, &hub_port);
  81878. + qh->do_split = 0;
  81879. + if (microframe_schedule)
  81880. + qh->speed = dev_speed;
  81881. +
  81882. + qh->nak_frame = 0xffff;
  81883. +
  81884. + if (((dev_speed == USB_SPEED_LOW) ||
  81885. + (dev_speed == USB_SPEED_FULL)) &&
  81886. + (hub_addr != 0 && hub_addr != 1)) {
  81887. + DWC_DEBUGPL(DBG_HCD,
  81888. + "QH init: EP %d: TT found at hub addr %d, for port %d\n",
  81889. + dwc_otg_hcd_get_ep_num(&urb->pipe_info), hub_addr,
  81890. + hub_port);
  81891. + qh->do_split = 1;
  81892. + qh->skip_count = 0;
  81893. + }
  81894. +
  81895. + if (qh->ep_type == UE_INTERRUPT || qh->ep_type == UE_ISOCHRONOUS) {
  81896. + /* Compute scheduling parameters once and save them. */
  81897. + hprt0_data_t hprt;
  81898. +
  81899. + /** @todo Account for split transfers in the bus time. */
  81900. + int bytecount =
  81901. + dwc_hb_mult(qh->maxp) * dwc_max_packet(qh->maxp);
  81902. +
  81903. + qh->usecs =
  81904. + calc_bus_time((qh->do_split ? USB_SPEED_HIGH : dev_speed),
  81905. + qh->ep_is_in, (qh->ep_type == UE_ISOCHRONOUS),
  81906. + bytecount);
  81907. + /* Start in a slightly future (micro)frame. */
  81908. + qh->sched_frame = dwc_frame_num_inc(hcd->frame_number,
  81909. + SCHEDULE_SLOP);
  81910. + qh->interval = urb->interval;
  81911. +
  81912. +#if 0
  81913. + /* Increase interrupt polling rate for debugging. */
  81914. + if (qh->ep_type == UE_INTERRUPT) {
  81915. + qh->interval = 8;
  81916. + }
  81917. +#endif
  81918. + hprt.d32 = DWC_READ_REG32(hcd->core_if->host_if->hprt0);
  81919. + if ((hprt.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED) &&
  81920. + ((dev_speed == USB_SPEED_LOW) ||
  81921. + (dev_speed == USB_SPEED_FULL))) {
  81922. + qh->interval *= 8;
  81923. + qh->sched_frame |= 0x7;
  81924. + qh->start_split_frame = qh->sched_frame;
  81925. + }
  81926. +
  81927. + }
  81928. +
  81929. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD QH Initialized\n");
  81930. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - qh = %p\n", qh);
  81931. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Device Address = %d\n",
  81932. + dwc_otg_hcd_get_dev_addr(&urb->pipe_info));
  81933. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Endpoint %d, %s\n",
  81934. + dwc_otg_hcd_get_ep_num(&urb->pipe_info),
  81935. + dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT");
  81936. + switch (dev_speed) {
  81937. + case USB_SPEED_LOW:
  81938. + qh->dev_speed = DWC_OTG_EP_SPEED_LOW;
  81939. + speed = "low";
  81940. + break;
  81941. + case USB_SPEED_FULL:
  81942. + qh->dev_speed = DWC_OTG_EP_SPEED_FULL;
  81943. + speed = "full";
  81944. + break;
  81945. + case USB_SPEED_HIGH:
  81946. + qh->dev_speed = DWC_OTG_EP_SPEED_HIGH;
  81947. + speed = "high";
  81948. + break;
  81949. + default:
  81950. + speed = "?";
  81951. + break;
  81952. + }
  81953. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Speed = %s\n", speed);
  81954. +
  81955. + switch (qh->ep_type) {
  81956. + case UE_ISOCHRONOUS:
  81957. + type = "isochronous";
  81958. + break;
  81959. + case UE_INTERRUPT:
  81960. + type = "interrupt";
  81961. + break;
  81962. + case UE_CONTROL:
  81963. + type = "control";
  81964. + break;
  81965. + case UE_BULK:
  81966. + type = "bulk";
  81967. + break;
  81968. + default:
  81969. + type = "?";
  81970. + break;
  81971. + }
  81972. +
  81973. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Type = %s\n", type);
  81974. +
  81975. +#ifdef DEBUG
  81976. + if (qh->ep_type == UE_INTERRUPT) {
  81977. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - usecs = %d\n",
  81978. + qh->usecs);
  81979. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - interval = %d\n",
  81980. + qh->interval);
  81981. + }
  81982. +#endif
  81983. +
  81984. +}
  81985. +
  81986. +/**
  81987. + * This function allocates and initializes a QH.
  81988. + *
  81989. + * @param hcd The HCD state structure for the DWC OTG controller.
  81990. + * @param urb Holds the information about the device/endpoint that we need
  81991. + * to initialize the QH.
  81992. + * @param atomic_alloc Flag to do atomic allocation if needed
  81993. + *
  81994. + * @return Returns pointer to the newly allocated QH, or NULL on error. */
  81995. +dwc_otg_qh_t *dwc_otg_hcd_qh_create(dwc_otg_hcd_t * hcd,
  81996. + dwc_otg_hcd_urb_t * urb, int atomic_alloc)
  81997. +{
  81998. + dwc_otg_qh_t *qh;
  81999. +
  82000. + /* Allocate memory */
  82001. + /** @todo add memflags argument */
  82002. + qh = dwc_otg_hcd_qh_alloc(atomic_alloc);
  82003. + if (qh == NULL) {
  82004. + DWC_ERROR("qh allocation failed");
  82005. + return NULL;
  82006. + }
  82007. +
  82008. + qh_init(hcd, qh, urb);
  82009. +
  82010. + if (hcd->core_if->dma_desc_enable
  82011. + && (dwc_otg_hcd_qh_init_ddma(hcd, qh) < 0)) {
  82012. + dwc_otg_hcd_qh_free(hcd, qh);
  82013. + return NULL;
  82014. + }
  82015. +
  82016. + return qh;
  82017. +}
  82018. +
  82019. +/* microframe_schedule=0 start */
  82020. +
  82021. +/**
  82022. + * Checks that a channel is available for a periodic transfer.
  82023. + *
  82024. + * @return 0 if successful, negative error code otherise.
  82025. + */
  82026. +static int periodic_channel_available(dwc_otg_hcd_t * hcd)
  82027. +{
  82028. + /*
  82029. + * Currently assuming that there is a dedicated host channnel for each
  82030. + * periodic transaction plus at least one host channel for
  82031. + * non-periodic transactions.
  82032. + */
  82033. + int status;
  82034. + int num_channels;
  82035. +
  82036. + num_channels = hcd->core_if->core_params->host_channels;
  82037. + if ((hcd->periodic_channels + hcd->non_periodic_channels < num_channels)
  82038. + && (hcd->periodic_channels < num_channels - 1)) {
  82039. + status = 0;
  82040. + } else {
  82041. + DWC_INFO("%s: Total channels: %d, Periodic: %d, Non-periodic: %d\n",
  82042. + __func__, num_channels, hcd->periodic_channels, hcd->non_periodic_channels); //NOTICE
  82043. + status = -DWC_E_NO_SPACE;
  82044. + }
  82045. +
  82046. + return status;
  82047. +}
  82048. +
  82049. +/**
  82050. + * Checks that there is sufficient bandwidth for the specified QH in the
  82051. + * periodic schedule. For simplicity, this calculation assumes that all the
  82052. + * transfers in the periodic schedule may occur in the same (micro)frame.
  82053. + *
  82054. + * @param hcd The HCD state structure for the DWC OTG controller.
  82055. + * @param qh QH containing periodic bandwidth required.
  82056. + *
  82057. + * @return 0 if successful, negative error code otherwise.
  82058. + */
  82059. +static int check_periodic_bandwidth(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  82060. +{
  82061. + int status;
  82062. + int16_t max_claimed_usecs;
  82063. +
  82064. + status = 0;
  82065. +
  82066. + if ((qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) || qh->do_split) {
  82067. + /*
  82068. + * High speed mode.
  82069. + * Max periodic usecs is 80% x 125 usec = 100 usec.
  82070. + */
  82071. +
  82072. + max_claimed_usecs = 100 - qh->usecs;
  82073. + } else {
  82074. + /*
  82075. + * Full speed mode.
  82076. + * Max periodic usecs is 90% x 1000 usec = 900 usec.
  82077. + */
  82078. + max_claimed_usecs = 900 - qh->usecs;
  82079. + }
  82080. +
  82081. + if (hcd->periodic_usecs > max_claimed_usecs) {
  82082. + DWC_INFO("%s: already claimed usecs %d, required usecs %d\n", __func__, hcd->periodic_usecs, qh->usecs); //NOTICE
  82083. + status = -DWC_E_NO_SPACE;
  82084. + }
  82085. +
  82086. + return status;
  82087. +}
  82088. +
  82089. +/* microframe_schedule=0 end */
  82090. +
  82091. +/**
  82092. + * Microframe scheduler
  82093. + * track the total use in hcd->frame_usecs
  82094. + * keep each qh use in qh->frame_usecs
  82095. + * when surrendering the qh then donate the time back
  82096. + */
  82097. +const unsigned short max_uframe_usecs[]={ 100, 100, 100, 100, 100, 100, 30, 0 };
  82098. +
  82099. +/*
  82100. + * called from dwc_otg_hcd.c:dwc_otg_hcd_init
  82101. + */
  82102. +int init_hcd_usecs(dwc_otg_hcd_t *_hcd)
  82103. +{
  82104. + int i;
  82105. + for (i=0; i<8; i++) {
  82106. + _hcd->frame_usecs[i] = max_uframe_usecs[i];
  82107. + }
  82108. + return 0;
  82109. +}
  82110. +
  82111. +static int find_single_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  82112. +{
  82113. + int i;
  82114. + unsigned short utime;
  82115. + int t_left;
  82116. + int ret;
  82117. + int done;
  82118. +
  82119. + ret = -1;
  82120. + utime = _qh->usecs;
  82121. + t_left = utime;
  82122. + i = 0;
  82123. + done = 0;
  82124. + while (done == 0) {
  82125. + /* At the start _hcd->frame_usecs[i] = max_uframe_usecs[i]; */
  82126. + if (utime <= _hcd->frame_usecs[i]) {
  82127. + _hcd->frame_usecs[i] -= utime;
  82128. + _qh->frame_usecs[i] += utime;
  82129. + t_left -= utime;
  82130. + ret = i;
  82131. + done = 1;
  82132. + return ret;
  82133. + } else {
  82134. + i++;
  82135. + if (i == 8) {
  82136. + done = 1;
  82137. + ret = -1;
  82138. + }
  82139. + }
  82140. + }
  82141. + return ret;
  82142. + }
  82143. +
  82144. +/*
  82145. + * use this for FS apps that can span multiple uframes
  82146. + */
  82147. +static int find_multi_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  82148. +{
  82149. + int i;
  82150. + int j;
  82151. + unsigned short utime;
  82152. + int t_left;
  82153. + int ret;
  82154. + int done;
  82155. + unsigned short xtime;
  82156. +
  82157. + ret = -1;
  82158. + utime = _qh->usecs;
  82159. + t_left = utime;
  82160. + i = 0;
  82161. + done = 0;
  82162. +loop:
  82163. + while (done == 0) {
  82164. + if(_hcd->frame_usecs[i] <= 0) {
  82165. + i++;
  82166. + if (i == 8) {
  82167. + done = 1;
  82168. + ret = -1;
  82169. + }
  82170. + goto loop;
  82171. + }
  82172. +
  82173. + /*
  82174. + * we need n consecutive slots
  82175. + * so use j as a start slot j plus j+1 must be enough time (for now)
  82176. + */
  82177. + xtime= _hcd->frame_usecs[i];
  82178. + for (j = i+1 ; j < 8 ; j++ ) {
  82179. + /*
  82180. + * if we add this frame remaining time to xtime we may
  82181. + * be OK, if not we need to test j for a complete frame
  82182. + */
  82183. + if ((xtime+_hcd->frame_usecs[j]) < utime) {
  82184. + if (_hcd->frame_usecs[j] < max_uframe_usecs[j]) {
  82185. + j = 8;
  82186. + ret = -1;
  82187. + continue;
  82188. + }
  82189. + }
  82190. + if (xtime >= utime) {
  82191. + ret = i;
  82192. + j = 8; /* stop loop with a good value ret */
  82193. + continue;
  82194. + }
  82195. + /* add the frame time to x time */
  82196. + xtime += _hcd->frame_usecs[j];
  82197. + /* we must have a fully available next frame or break */
  82198. + if ((xtime < utime)
  82199. + && (_hcd->frame_usecs[j] == max_uframe_usecs[j])) {
  82200. + ret = -1;
  82201. + j = 8; /* stop loop with a bad value ret */
  82202. + continue;
  82203. + }
  82204. + }
  82205. + if (ret >= 0) {
  82206. + t_left = utime;
  82207. + for (j = i; (t_left>0) && (j < 8); j++ ) {
  82208. + t_left -= _hcd->frame_usecs[j];
  82209. + if ( t_left <= 0 ) {
  82210. + _qh->frame_usecs[j] += _hcd->frame_usecs[j] + t_left;
  82211. + _hcd->frame_usecs[j]= -t_left;
  82212. + ret = i;
  82213. + done = 1;
  82214. + } else {
  82215. + _qh->frame_usecs[j] += _hcd->frame_usecs[j];
  82216. + _hcd->frame_usecs[j] = 0;
  82217. + }
  82218. + }
  82219. + } else {
  82220. + i++;
  82221. + if (i == 8) {
  82222. + done = 1;
  82223. + ret = -1;
  82224. + }
  82225. + }
  82226. + }
  82227. + return ret;
  82228. +}
  82229. +
  82230. +static int find_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  82231. +{
  82232. + int ret;
  82233. + ret = -1;
  82234. +
  82235. + if (_qh->speed == USB_SPEED_HIGH) {
  82236. + /* if this is a hs transaction we need a full frame */
  82237. + ret = find_single_uframe(_hcd, _qh);
  82238. + } else {
  82239. + /* if this is a fs transaction we may need a sequence of frames */
  82240. + ret = find_multi_uframe(_hcd, _qh);
  82241. + }
  82242. + return ret;
  82243. +}
  82244. +
  82245. +/**
  82246. + * Checks that the max transfer size allowed in a host channel is large enough
  82247. + * to handle the maximum data transfer in a single (micro)frame for a periodic
  82248. + * transfer.
  82249. + *
  82250. + * @param hcd The HCD state structure for the DWC OTG controller.
  82251. + * @param qh QH for a periodic endpoint.
  82252. + *
  82253. + * @return 0 if successful, negative error code otherwise.
  82254. + */
  82255. +static int check_max_xfer_size(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  82256. +{
  82257. + int status;
  82258. + uint32_t max_xfer_size;
  82259. + uint32_t max_channel_xfer_size;
  82260. +
  82261. + status = 0;
  82262. +
  82263. + max_xfer_size = dwc_max_packet(qh->maxp) * dwc_hb_mult(qh->maxp);
  82264. + max_channel_xfer_size = hcd->core_if->core_params->max_transfer_size;
  82265. +
  82266. + if (max_xfer_size > max_channel_xfer_size) {
  82267. + DWC_INFO("%s: Periodic xfer length %d > " "max xfer length for channel %d\n",
  82268. + __func__, max_xfer_size, max_channel_xfer_size); //NOTICE
  82269. + status = -DWC_E_NO_SPACE;
  82270. + }
  82271. +
  82272. + return status;
  82273. +}
  82274. +
  82275. +
  82276. +
  82277. +/**
  82278. + * Schedules an interrupt or isochronous transfer in the periodic schedule.
  82279. + *
  82280. + * @param hcd The HCD state structure for the DWC OTG controller.
  82281. + * @param qh QH for the periodic transfer. The QH should already contain the
  82282. + * scheduling information.
  82283. + *
  82284. + * @return 0 if successful, negative error code otherwise.
  82285. + */
  82286. +static int schedule_periodic(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  82287. +{
  82288. + int status = 0;
  82289. +
  82290. + if (microframe_schedule) {
  82291. + int frame;
  82292. + status = find_uframe(hcd, qh);
  82293. + frame = -1;
  82294. + if (status == 0) {
  82295. + frame = 7;
  82296. + } else {
  82297. + if (status > 0 )
  82298. + frame = status-1;
  82299. + }
  82300. +
  82301. + /* Set the new frame up */
  82302. + if (frame > -1) {
  82303. + qh->sched_frame &= ~0x7;
  82304. + qh->sched_frame |= (frame & 7);
  82305. + }
  82306. +
  82307. + if (status != -1)
  82308. + status = 0;
  82309. + } else {
  82310. + status = periodic_channel_available(hcd);
  82311. + if (status) {
  82312. + DWC_INFO("%s: No host channel available for periodic " "transfer.\n", __func__); //NOTICE
  82313. + return status;
  82314. + }
  82315. +
  82316. + status = check_periodic_bandwidth(hcd, qh);
  82317. + }
  82318. + if (status) {
  82319. + DWC_INFO("%s: Insufficient periodic bandwidth for "
  82320. + "periodic transfer.\n", __func__);
  82321. + return status;
  82322. + }
  82323. + status = check_max_xfer_size(hcd, qh);
  82324. + if (status) {
  82325. + DWC_INFO("%s: Channel max transfer size too small "
  82326. + "for periodic transfer.\n", __func__);
  82327. + return status;
  82328. + }
  82329. +
  82330. + if (hcd->core_if->dma_desc_enable) {
  82331. + /* Don't rely on SOF and start in ready schedule */
  82332. + DWC_LIST_INSERT_TAIL(&hcd->periodic_sched_ready, &qh->qh_list_entry);
  82333. + }
  82334. + else {
  82335. + if(fiq_enable && (DWC_LIST_EMPTY(&hcd->periodic_sched_inactive) || dwc_frame_num_le(qh->sched_frame, hcd->fiq_state->next_sched_frame)))
  82336. + {
  82337. + hcd->fiq_state->next_sched_frame = qh->sched_frame;
  82338. +
  82339. + }
  82340. + /* Always start in the inactive schedule. */
  82341. + DWC_LIST_INSERT_TAIL(&hcd->periodic_sched_inactive, &qh->qh_list_entry);
  82342. + }
  82343. +
  82344. + if (!microframe_schedule) {
  82345. + /* Reserve the periodic channel. */
  82346. + hcd->periodic_channels++;
  82347. + }
  82348. +
  82349. + /* Update claimed usecs per (micro)frame. */
  82350. + hcd->periodic_usecs += qh->usecs;
  82351. +
  82352. + return status;
  82353. +}
  82354. +
  82355. +
  82356. +/**
  82357. + * This function adds a QH to either the non periodic or periodic schedule if
  82358. + * it is not already in the schedule. If the QH is already in the schedule, no
  82359. + * action is taken.
  82360. + *
  82361. + * @return 0 if successful, negative error code otherwise.
  82362. + */
  82363. +int dwc_otg_hcd_qh_add(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  82364. +{
  82365. + int status = 0;
  82366. + gintmsk_data_t intr_mask = {.d32 = 0 };
  82367. +
  82368. + if (!DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  82369. + /* QH already in a schedule. */
  82370. + return status;
  82371. + }
  82372. +
  82373. + /* Add the new QH to the appropriate schedule */
  82374. + if (dwc_qh_is_non_per(qh)) {
  82375. + /* Always start in the inactive schedule. */
  82376. + DWC_LIST_INSERT_TAIL(&hcd->non_periodic_sched_inactive,
  82377. + &qh->qh_list_entry);
  82378. + //hcd->fiq_state->kick_np_queues = 1;
  82379. + } else {
  82380. + status = schedule_periodic(hcd, qh);
  82381. + if ( !hcd->periodic_qh_count ) {
  82382. + intr_mask.b.sofintr = 1;
  82383. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk,
  82384. + intr_mask.d32, intr_mask.d32);
  82385. + }
  82386. + hcd->periodic_qh_count++;
  82387. + }
  82388. +
  82389. + return status;
  82390. +}
  82391. +
  82392. +/**
  82393. + * Removes an interrupt or isochronous transfer from the periodic schedule.
  82394. + *
  82395. + * @param hcd The HCD state structure for the DWC OTG controller.
  82396. + * @param qh QH for the periodic transfer.
  82397. + */
  82398. +static void deschedule_periodic(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  82399. +{
  82400. + int i;
  82401. + DWC_LIST_REMOVE_INIT(&qh->qh_list_entry);
  82402. +
  82403. + /* Update claimed usecs per (micro)frame. */
  82404. + hcd->periodic_usecs -= qh->usecs;
  82405. +
  82406. + if (!microframe_schedule) {
  82407. + /* Release the periodic channel reservation. */
  82408. + hcd->periodic_channels--;
  82409. + } else {
  82410. + for (i = 0; i < 8; i++) {
  82411. + hcd->frame_usecs[i] += qh->frame_usecs[i];
  82412. + qh->frame_usecs[i] = 0;
  82413. + }
  82414. + }
  82415. +}
  82416. +
  82417. +/**
  82418. + * Removes a QH from either the non-periodic or periodic schedule. Memory is
  82419. + * not freed.
  82420. + *
  82421. + * @param hcd The HCD state structure.
  82422. + * @param qh QH to remove from schedule. */
  82423. +void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  82424. +{
  82425. + gintmsk_data_t intr_mask = {.d32 = 0 };
  82426. +
  82427. + if (DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  82428. + /* QH is not in a schedule. */
  82429. + return;
  82430. + }
  82431. +
  82432. + if (dwc_qh_is_non_per(qh)) {
  82433. + if (hcd->non_periodic_qh_ptr == &qh->qh_list_entry) {
  82434. + hcd->non_periodic_qh_ptr =
  82435. + hcd->non_periodic_qh_ptr->next;
  82436. + }
  82437. + DWC_LIST_REMOVE_INIT(&qh->qh_list_entry);
  82438. + //if (!DWC_LIST_EMPTY(&hcd->non_periodic_sched_inactive))
  82439. + // hcd->fiq_state->kick_np_queues = 1;
  82440. + } else {
  82441. + deschedule_periodic(hcd, qh);
  82442. + hcd->periodic_qh_count--;
  82443. + if( !hcd->periodic_qh_count && !fiq_fsm_enable ) {
  82444. + intr_mask.b.sofintr = 1;
  82445. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk,
  82446. + intr_mask.d32, 0);
  82447. + }
  82448. + }
  82449. +}
  82450. +
  82451. +/**
  82452. + * Deactivates a QH. For non-periodic QHs, removes the QH from the active
  82453. + * non-periodic schedule. The QH is added to the inactive non-periodic
  82454. + * schedule if any QTDs are still attached to the QH.
  82455. + *
  82456. + * For periodic QHs, the QH is removed from the periodic queued schedule. If
  82457. + * there are any QTDs still attached to the QH, the QH is added to either the
  82458. + * periodic inactive schedule or the periodic ready schedule and its next
  82459. + * scheduled frame is calculated. The QH is placed in the ready schedule if
  82460. + * the scheduled frame has been reached already. Otherwise it's placed in the
  82461. + * inactive schedule. If there are no QTDs attached to the QH, the QH is
  82462. + * completely removed from the periodic schedule.
  82463. + */
  82464. +void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  82465. + int sched_next_periodic_split)
  82466. +{
  82467. + if (dwc_qh_is_non_per(qh)) {
  82468. + dwc_otg_hcd_qh_remove(hcd, qh);
  82469. + if (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  82470. + /* Add back to inactive non-periodic schedule. */
  82471. + dwc_otg_hcd_qh_add(hcd, qh);
  82472. + //hcd->fiq_state->kick_np_queues = 1;
  82473. + }
  82474. + } else {
  82475. + uint16_t frame_number = dwc_otg_hcd_get_frame_number(hcd);
  82476. +
  82477. + if (qh->do_split) {
  82478. + /* Schedule the next continuing periodic split transfer */
  82479. + if (sched_next_periodic_split) {
  82480. +
  82481. + qh->sched_frame = frame_number;
  82482. +
  82483. + if (dwc_frame_num_le(frame_number,
  82484. + dwc_frame_num_inc
  82485. + (qh->start_split_frame,
  82486. + 1))) {
  82487. + /*
  82488. + * Allow one frame to elapse after start
  82489. + * split microframe before scheduling
  82490. + * complete split, but DONT if we are
  82491. + * doing the next start split in the
  82492. + * same frame for an ISOC out.
  82493. + */
  82494. + if ((qh->ep_type != UE_ISOCHRONOUS) ||
  82495. + (qh->ep_is_in != 0)) {
  82496. + qh->sched_frame =
  82497. + dwc_frame_num_inc(qh->sched_frame, 1);
  82498. + }
  82499. + }
  82500. + } else {
  82501. + qh->sched_frame =
  82502. + dwc_frame_num_inc(qh->start_split_frame,
  82503. + qh->interval);
  82504. + if (dwc_frame_num_le
  82505. + (qh->sched_frame, frame_number)) {
  82506. + qh->sched_frame = frame_number;
  82507. + }
  82508. + qh->sched_frame |= 0x7;
  82509. + qh->start_split_frame = qh->sched_frame;
  82510. + }
  82511. + } else {
  82512. + qh->sched_frame =
  82513. + dwc_frame_num_inc(qh->sched_frame, qh->interval);
  82514. + if (dwc_frame_num_le(qh->sched_frame, frame_number)) {
  82515. + qh->sched_frame = frame_number;
  82516. + }
  82517. + }
  82518. +
  82519. + if (DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  82520. + dwc_otg_hcd_qh_remove(hcd, qh);
  82521. + } else {
  82522. + /*
  82523. + * Remove from periodic_sched_queued and move to
  82524. + * appropriate queue.
  82525. + */
  82526. + if ((microframe_schedule && dwc_frame_num_le(qh->sched_frame, frame_number)) ||
  82527. + (!microframe_schedule && qh->sched_frame == frame_number)) {
  82528. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_ready,
  82529. + &qh->qh_list_entry);
  82530. + } else {
  82531. + if(fiq_enable && !dwc_frame_num_le(hcd->fiq_state->next_sched_frame, qh->sched_frame))
  82532. + {
  82533. + hcd->fiq_state->next_sched_frame = qh->sched_frame;
  82534. + }
  82535. +
  82536. + DWC_LIST_MOVE_HEAD
  82537. + (&hcd->periodic_sched_inactive,
  82538. + &qh->qh_list_entry);
  82539. + }
  82540. + }
  82541. + }
  82542. +}
  82543. +
  82544. +/**
  82545. + * This function allocates and initializes a QTD.
  82546. + *
  82547. + * @param urb The URB to create a QTD from. Each URB-QTD pair will end up
  82548. + * pointing to each other so each pair should have a unique correlation.
  82549. + * @param atomic_alloc Flag to do atomic alloc if needed
  82550. + *
  82551. + * @return Returns pointer to the newly allocated QTD, or NULL on error. */
  82552. +dwc_otg_qtd_t *dwc_otg_hcd_qtd_create(dwc_otg_hcd_urb_t * urb, int atomic_alloc)
  82553. +{
  82554. + dwc_otg_qtd_t *qtd;
  82555. +
  82556. + qtd = dwc_otg_hcd_qtd_alloc(atomic_alloc);
  82557. + if (qtd == NULL) {
  82558. + return NULL;
  82559. + }
  82560. +
  82561. + dwc_otg_hcd_qtd_init(qtd, urb);
  82562. + return qtd;
  82563. +}
  82564. +
  82565. +/**
  82566. + * Initializes a QTD structure.
  82567. + *
  82568. + * @param qtd The QTD to initialize.
  82569. + * @param urb The URB to use for initialization. */
  82570. +void dwc_otg_hcd_qtd_init(dwc_otg_qtd_t * qtd, dwc_otg_hcd_urb_t * urb)
  82571. +{
  82572. + dwc_memset(qtd, 0, sizeof(dwc_otg_qtd_t));
  82573. + qtd->urb = urb;
  82574. + if (dwc_otg_hcd_get_pipe_type(&urb->pipe_info) == UE_CONTROL) {
  82575. + /*
  82576. + * The only time the QTD data toggle is used is on the data
  82577. + * phase of control transfers. This phase always starts with
  82578. + * DATA1.
  82579. + */
  82580. + qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
  82581. + qtd->control_phase = DWC_OTG_CONTROL_SETUP;
  82582. + }
  82583. +
  82584. + /* start split */
  82585. + qtd->complete_split = 0;
  82586. + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
  82587. + qtd->isoc_split_offset = 0;
  82588. + qtd->in_process = 0;
  82589. +
  82590. + /* Store the qtd ptr in the urb to reference what QTD. */
  82591. + urb->qtd = qtd;
  82592. + return;
  82593. +}
  82594. +
  82595. +/**
  82596. + * This function adds a QTD to the QTD-list of a QH. It will find the correct
  82597. + * QH to place the QTD into. If it does not find a QH, then it will create a
  82598. + * new QH. If the QH to which the QTD is added is not currently scheduled, it
  82599. + * is placed into the proper schedule based on its EP type.
  82600. + * HCD lock must be held and interrupts must be disabled on entry
  82601. + *
  82602. + * @param[in] qtd The QTD to add
  82603. + * @param[in] hcd The DWC HCD structure
  82604. + * @param[out] qh out parameter to return queue head
  82605. + * @param atomic_alloc Flag to do atomic alloc if needed
  82606. + *
  82607. + * @return 0 if successful, negative error code otherwise.
  82608. + */
  82609. +int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t * qtd,
  82610. + dwc_otg_hcd_t * hcd, dwc_otg_qh_t ** qh, int atomic_alloc)
  82611. +{
  82612. + int retval = 0;
  82613. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  82614. +
  82615. + /*
  82616. + * Get the QH which holds the QTD-list to insert to. Create QH if it
  82617. + * doesn't exist.
  82618. + */
  82619. + if (*qh == NULL) {
  82620. + *qh = dwc_otg_hcd_qh_create(hcd, urb, atomic_alloc);
  82621. + if (*qh == NULL) {
  82622. + retval = -DWC_E_NO_MEMORY;
  82623. + goto done;
  82624. + } else {
  82625. + if (fiq_enable)
  82626. + hcd->fiq_state->kick_np_queues = 1;
  82627. + }
  82628. + }
  82629. + retval = dwc_otg_hcd_qh_add(hcd, *qh);
  82630. + if (retval == 0) {
  82631. + DWC_CIRCLEQ_INSERT_TAIL(&((*qh)->qtd_list), qtd,
  82632. + qtd_list_entry);
  82633. + qtd->qh = *qh;
  82634. + }
  82635. +done:
  82636. +
  82637. + return retval;
  82638. +}
  82639. +
  82640. +#endif /* DWC_DEVICE_ONLY */
  82641. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h
  82642. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h 1970-01-01 01:00:00.000000000 +0100
  82643. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h 2014-07-07 10:45:43.000000000 +0200
  82644. @@ -0,0 +1,188 @@
  82645. +#ifndef _DWC_OS_DEP_H_
  82646. +#define _DWC_OS_DEP_H_
  82647. +
  82648. +/**
  82649. + * @file
  82650. + *
  82651. + * This file contains OS dependent structures.
  82652. + *
  82653. + */
  82654. +
  82655. +#include <linux/kernel.h>
  82656. +#include <linux/module.h>
  82657. +#include <linux/moduleparam.h>
  82658. +#include <linux/init.h>
  82659. +#include <linux/device.h>
  82660. +#include <linux/errno.h>
  82661. +#include <linux/types.h>
  82662. +#include <linux/slab.h>
  82663. +#include <linux/list.h>
  82664. +#include <linux/interrupt.h>
  82665. +#include <linux/ctype.h>
  82666. +#include <linux/string.h>
  82667. +#include <linux/dma-mapping.h>
  82668. +#include <linux/jiffies.h>
  82669. +#include <linux/delay.h>
  82670. +#include <linux/timer.h>
  82671. +#include <linux/workqueue.h>
  82672. +#include <linux/stat.h>
  82673. +#include <linux/pci.h>
  82674. +
  82675. +#include <linux/version.h>
  82676. +
  82677. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
  82678. +# include <linux/irq.h>
  82679. +#endif
  82680. +
  82681. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
  82682. +# include <linux/usb/ch9.h>
  82683. +#else
  82684. +# include <linux/usb_ch9.h>
  82685. +#endif
  82686. +
  82687. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
  82688. +# include <linux/usb/gadget.h>
  82689. +#else
  82690. +# include <linux/usb_gadget.h>
  82691. +#endif
  82692. +
  82693. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
  82694. +# include <asm/irq.h>
  82695. +#endif
  82696. +
  82697. +#ifdef PCI_INTERFACE
  82698. +# include <asm/io.h>
  82699. +#endif
  82700. +
  82701. +#ifdef LM_INTERFACE
  82702. +# include <asm/unaligned.h>
  82703. +# include <asm/sizes.h>
  82704. +# include <asm/param.h>
  82705. +# include <asm/io.h>
  82706. +# if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30))
  82707. +# include <asm/arch/hardware.h>
  82708. +# include <asm/arch/lm.h>
  82709. +# include <asm/arch/irqs.h>
  82710. +# include <asm/arch/regs-irq.h>
  82711. +# else
  82712. +/* in 2.6.31, at least, we seem to have lost the generic LM infrastructure -
  82713. + here we assume that the machine architecture provides definitions
  82714. + in its own header
  82715. +*/
  82716. +# include <mach/lm.h>
  82717. +# include <mach/hardware.h>
  82718. +# endif
  82719. +#endif
  82720. +
  82721. +#ifdef PLATFORM_INTERFACE
  82722. +#include <linux/platform_device.h>
  82723. +#include <asm/mach/map.h>
  82724. +#endif
  82725. +
  82726. +/** The OS page size */
  82727. +#define DWC_OS_PAGE_SIZE PAGE_SIZE
  82728. +
  82729. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
  82730. +typedef int gfp_t;
  82731. +#endif
  82732. +
  82733. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
  82734. +# define IRQF_SHARED SA_SHIRQ
  82735. +#endif
  82736. +
  82737. +typedef struct os_dependent {
  82738. + /** Base address returned from ioremap() */
  82739. + void *base;
  82740. +
  82741. + /** Register offset for Diagnostic API */
  82742. + uint32_t reg_offset;
  82743. +
  82744. + /** Base address for MPHI peripheral */
  82745. + void *mphi_base;
  82746. +
  82747. +#ifdef LM_INTERFACE
  82748. + struct lm_device *lmdev;
  82749. +#elif defined(PCI_INTERFACE)
  82750. + struct pci_dev *pcidev;
  82751. +
  82752. + /** Start address of a PCI region */
  82753. + resource_size_t rsrc_start;
  82754. +
  82755. + /** Length address of a PCI region */
  82756. + resource_size_t rsrc_len;
  82757. +#elif defined(PLATFORM_INTERFACE)
  82758. + struct platform_device *platformdev;
  82759. +#endif
  82760. +
  82761. +} os_dependent_t;
  82762. +
  82763. +#ifdef __cplusplus
  82764. +}
  82765. +#endif
  82766. +
  82767. +
  82768. +
  82769. +/* Type for the our device on the chosen bus */
  82770. +#if defined(LM_INTERFACE)
  82771. +typedef struct lm_device dwc_bus_dev_t;
  82772. +#elif defined(PCI_INTERFACE)
  82773. +typedef struct pci_dev dwc_bus_dev_t;
  82774. +#elif defined(PLATFORM_INTERFACE)
  82775. +typedef struct platform_device dwc_bus_dev_t;
  82776. +#endif
  82777. +
  82778. +/* Helper macro to retrieve drvdata from the device on the chosen bus */
  82779. +#if defined(LM_INTERFACE)
  82780. +#define DWC_OTG_BUSDRVDATA(_dev) lm_get_drvdata(_dev)
  82781. +#elif defined(PCI_INTERFACE)
  82782. +#define DWC_OTG_BUSDRVDATA(_dev) pci_get_drvdata(_dev)
  82783. +#elif defined(PLATFORM_INTERFACE)
  82784. +#define DWC_OTG_BUSDRVDATA(_dev) platform_get_drvdata(_dev)
  82785. +#endif
  82786. +
  82787. +/**
  82788. + * Helper macro returning the otg_device structure of a given struct device
  82789. + *
  82790. + * c.f. static dwc_otg_device_t *dwc_otg_drvdev(struct device *_dev)
  82791. + */
  82792. +#ifdef LM_INTERFACE
  82793. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  82794. + struct lm_device *lm_dev = \
  82795. + container_of(_dev, struct lm_device, dev); \
  82796. + _var = lm_get_drvdata(lm_dev); \
  82797. + } while (0)
  82798. +
  82799. +#elif defined(PCI_INTERFACE)
  82800. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  82801. + _var = dev_get_drvdata(_dev); \
  82802. + } while (0)
  82803. +
  82804. +#elif defined(PLATFORM_INTERFACE)
  82805. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  82806. + struct platform_device *platform_dev = \
  82807. + container_of(_dev, struct platform_device, dev); \
  82808. + _var = platform_get_drvdata(platform_dev); \
  82809. + } while (0)
  82810. +#endif
  82811. +
  82812. +
  82813. +/**
  82814. + * Helper macro returning the struct dev of the given struct os_dependent
  82815. + *
  82816. + * c.f. static struct device *dwc_otg_getdev(struct os_dependent *osdep)
  82817. + */
  82818. +#ifdef LM_INTERFACE
  82819. +#define DWC_OTG_OS_GETDEV(_osdep) \
  82820. + ((_osdep).lmdev == NULL? NULL: &(_osdep).lmdev->dev)
  82821. +#elif defined(PCI_INTERFACE)
  82822. +#define DWC_OTG_OS_GETDEV(_osdep) \
  82823. + ((_osdep).pci_dev == NULL? NULL: &(_osdep).pci_dev->dev)
  82824. +#elif defined(PLATFORM_INTERFACE)
  82825. +#define DWC_OTG_OS_GETDEV(_osdep) \
  82826. + ((_osdep).platformdev == NULL? NULL: &(_osdep).platformdev->dev)
  82827. +#endif
  82828. +
  82829. +
  82830. +
  82831. +
  82832. +#endif /* _DWC_OS_DEP_H_ */
  82833. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_pcd.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd.c
  82834. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_pcd.c 1970-01-01 01:00:00.000000000 +0100
  82835. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd.c 2014-07-07 10:45:43.000000000 +0200
  82836. @@ -0,0 +1,2708 @@
  82837. +/* ==========================================================================
  82838. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.c $
  82839. + * $Revision: #101 $
  82840. + * $Date: 2012/08/10 $
  82841. + * $Change: 2047372 $
  82842. + *
  82843. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  82844. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  82845. + * otherwise expressly agreed to in writing between Synopsys and you.
  82846. + *
  82847. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  82848. + * any End User Software License Agreement or Agreement for Licensed Product
  82849. + * with Synopsys or any supplement thereto. You are permitted to use and
  82850. + * redistribute this Software in source and binary forms, with or without
  82851. + * modification, provided that redistributions of source code must retain this
  82852. + * notice. You may not view, use, disclose, copy or distribute this file or
  82853. + * any information contained herein except pursuant to this license grant from
  82854. + * Synopsys. If you do not agree with this notice, including the disclaimer
  82855. + * below, then you are not authorized to use the Software.
  82856. + *
  82857. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  82858. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  82859. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  82860. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  82861. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  82862. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  82863. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  82864. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  82865. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  82866. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  82867. + * DAMAGE.
  82868. + * ========================================================================== */
  82869. +#ifndef DWC_HOST_ONLY
  82870. +
  82871. +/** @file
  82872. + * This file implements PCD Core. All code in this file is portable and doesn't
  82873. + * use any OS specific functions.
  82874. + * PCD Core provides Interface, defined in <code><dwc_otg_pcd_if.h></code>
  82875. + * header file, which can be used to implement OS specific PCD interface.
  82876. + *
  82877. + * An important function of the PCD is managing interrupts generated
  82878. + * by the DWC_otg controller. The implementation of the DWC_otg device
  82879. + * mode interrupt service routines is in dwc_otg_pcd_intr.c.
  82880. + *
  82881. + * @todo Add Device Mode test modes (Test J mode, Test K mode, etc).
  82882. + * @todo Does it work when the request size is greater than DEPTSIZ
  82883. + * transfer size
  82884. + *
  82885. + */
  82886. +
  82887. +#include "dwc_otg_pcd.h"
  82888. +
  82889. +#ifdef DWC_UTE_CFI
  82890. +#include "dwc_otg_cfi.h"
  82891. +
  82892. +extern int init_cfi(cfiobject_t * cfiobj);
  82893. +#endif
  82894. +
  82895. +/**
  82896. + * Choose endpoint from ep arrays using usb_ep structure.
  82897. + */
  82898. +static dwc_otg_pcd_ep_t *get_ep_from_handle(dwc_otg_pcd_t * pcd, void *handle)
  82899. +{
  82900. + int i;
  82901. + if (pcd->ep0.priv == handle) {
  82902. + return &pcd->ep0;
  82903. + }
  82904. + for (i = 0; i < MAX_EPS_CHANNELS - 1; i++) {
  82905. + if (pcd->in_ep[i].priv == handle)
  82906. + return &pcd->in_ep[i];
  82907. + if (pcd->out_ep[i].priv == handle)
  82908. + return &pcd->out_ep[i];
  82909. + }
  82910. +
  82911. + return NULL;
  82912. +}
  82913. +
  82914. +/**
  82915. + * This function completes a request. It call's the request call back.
  82916. + */
  82917. +void dwc_otg_request_done(dwc_otg_pcd_ep_t * ep, dwc_otg_pcd_request_t * req,
  82918. + int32_t status)
  82919. +{
  82920. + unsigned stopped = ep->stopped;
  82921. +
  82922. + DWC_DEBUGPL(DBG_PCDV, "%s(ep %p req %p)\n", __func__, ep, req);
  82923. + DWC_CIRCLEQ_REMOVE_INIT(&ep->queue, req, queue_entry);
  82924. +
  82925. + /* don't modify queue heads during completion callback */
  82926. + ep->stopped = 1;
  82927. + /* spin_unlock/spin_lock now done in fops->complete() */
  82928. + ep->pcd->fops->complete(ep->pcd, ep->priv, req->priv, status,
  82929. + req->actual);
  82930. +
  82931. + if (ep->pcd->request_pending > 0) {
  82932. + --ep->pcd->request_pending;
  82933. + }
  82934. +
  82935. + ep->stopped = stopped;
  82936. + DWC_FREE(req);
  82937. +}
  82938. +
  82939. +/**
  82940. + * This function terminates all the requsts in the EP request queue.
  82941. + */
  82942. +void dwc_otg_request_nuke(dwc_otg_pcd_ep_t * ep)
  82943. +{
  82944. + dwc_otg_pcd_request_t *req;
  82945. +
  82946. + ep->stopped = 1;
  82947. +
  82948. + /* called with irqs blocked?? */
  82949. + while (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  82950. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  82951. + dwc_otg_request_done(ep, req, -DWC_E_SHUTDOWN);
  82952. + }
  82953. +}
  82954. +
  82955. +void dwc_otg_pcd_start(dwc_otg_pcd_t * pcd,
  82956. + const struct dwc_otg_pcd_function_ops *fops)
  82957. +{
  82958. + pcd->fops = fops;
  82959. +}
  82960. +
  82961. +/**
  82962. + * PCD Callback function for initializing the PCD when switching to
  82963. + * device mode.
  82964. + *
  82965. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  82966. + */
  82967. +static int32_t dwc_otg_pcd_start_cb(void *p)
  82968. +{
  82969. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  82970. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  82971. +
  82972. + /*
  82973. + * Initialized the Core for Device mode.
  82974. + */
  82975. + if (dwc_otg_is_device_mode(core_if)) {
  82976. + dwc_otg_core_dev_init(core_if);
  82977. + /* Set core_if's lock pointer to the pcd->lock */
  82978. + core_if->lock = pcd->lock;
  82979. + }
  82980. + return 1;
  82981. +}
  82982. +
  82983. +/** CFI-specific buffer allocation function for EP */
  82984. +#ifdef DWC_UTE_CFI
  82985. +uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep, dwc_dma_t * addr,
  82986. + size_t buflen, int flags)
  82987. +{
  82988. + dwc_otg_pcd_ep_t *ep;
  82989. + ep = get_ep_from_handle(pcd, pep);
  82990. + if (!ep) {
  82991. + DWC_WARN("bad ep\n");
  82992. + return -DWC_E_INVALID;
  82993. + }
  82994. +
  82995. + return pcd->cfi->ops.ep_alloc_buf(pcd->cfi, pcd, ep, addr, buflen,
  82996. + flags);
  82997. +}
  82998. +#else
  82999. +uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep, dwc_dma_t * addr,
  83000. + size_t buflen, int flags);
  83001. +#endif
  83002. +
  83003. +/**
  83004. + * PCD Callback function for notifying the PCD when resuming from
  83005. + * suspend.
  83006. + *
  83007. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  83008. + */
  83009. +static int32_t dwc_otg_pcd_resume_cb(void *p)
  83010. +{
  83011. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  83012. +
  83013. + if (pcd->fops->resume) {
  83014. + pcd->fops->resume(pcd);
  83015. + }
  83016. +
  83017. + /* Stop the SRP timeout timer. */
  83018. + if ((GET_CORE_IF(pcd)->core_params->phy_type != DWC_PHY_TYPE_PARAM_FS)
  83019. + || (!GET_CORE_IF(pcd)->core_params->i2c_enable)) {
  83020. + if (GET_CORE_IF(pcd)->srp_timer_started) {
  83021. + GET_CORE_IF(pcd)->srp_timer_started = 0;
  83022. + DWC_TIMER_CANCEL(GET_CORE_IF(pcd)->srp_timer);
  83023. + }
  83024. + }
  83025. + return 1;
  83026. +}
  83027. +
  83028. +/**
  83029. + * PCD Callback function for notifying the PCD device is suspended.
  83030. + *
  83031. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  83032. + */
  83033. +static int32_t dwc_otg_pcd_suspend_cb(void *p)
  83034. +{
  83035. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  83036. +
  83037. + if (pcd->fops->suspend) {
  83038. + DWC_SPINUNLOCK(pcd->lock);
  83039. + pcd->fops->suspend(pcd);
  83040. + DWC_SPINLOCK(pcd->lock);
  83041. + }
  83042. +
  83043. + return 1;
  83044. +}
  83045. +
  83046. +/**
  83047. + * PCD Callback function for stopping the PCD when switching to Host
  83048. + * mode.
  83049. + *
  83050. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  83051. + */
  83052. +static int32_t dwc_otg_pcd_stop_cb(void *p)
  83053. +{
  83054. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  83055. + extern void dwc_otg_pcd_stop(dwc_otg_pcd_t * _pcd);
  83056. +
  83057. + dwc_otg_pcd_stop(pcd);
  83058. + return 1;
  83059. +}
  83060. +
  83061. +/**
  83062. + * PCD Callback structure for handling mode switching.
  83063. + */
  83064. +static dwc_otg_cil_callbacks_t pcd_callbacks = {
  83065. + .start = dwc_otg_pcd_start_cb,
  83066. + .stop = dwc_otg_pcd_stop_cb,
  83067. + .suspend = dwc_otg_pcd_suspend_cb,
  83068. + .resume_wakeup = dwc_otg_pcd_resume_cb,
  83069. + .p = 0, /* Set at registration */
  83070. +};
  83071. +
  83072. +/**
  83073. + * This function allocates a DMA Descriptor chain for the Endpoint
  83074. + * buffer to be used for a transfer to/from the specified endpoint.
  83075. + */
  83076. +dwc_otg_dev_dma_desc_t *dwc_otg_ep_alloc_desc_chain(dwc_dma_t * dma_desc_addr,
  83077. + uint32_t count)
  83078. +{
  83079. + return DWC_DMA_ALLOC_ATOMIC(count * sizeof(dwc_otg_dev_dma_desc_t),
  83080. + dma_desc_addr);
  83081. +}
  83082. +
  83083. +/**
  83084. + * This function frees a DMA Descriptor chain that was allocated by ep_alloc_desc.
  83085. + */
  83086. +void dwc_otg_ep_free_desc_chain(dwc_otg_dev_dma_desc_t * desc_addr,
  83087. + uint32_t dma_desc_addr, uint32_t count)
  83088. +{
  83089. + DWC_DMA_FREE(count * sizeof(dwc_otg_dev_dma_desc_t), desc_addr,
  83090. + dma_desc_addr);
  83091. +}
  83092. +
  83093. +#ifdef DWC_EN_ISOC
  83094. +
  83095. +/**
  83096. + * This function initializes a descriptor chain for Isochronous transfer
  83097. + *
  83098. + * @param core_if Programming view of DWC_otg controller.
  83099. + * @param dwc_ep The EP to start the transfer on.
  83100. + *
  83101. + */
  83102. +void dwc_otg_iso_ep_start_ddma_transfer(dwc_otg_core_if_t * core_if,
  83103. + dwc_ep_t * dwc_ep)
  83104. +{
  83105. +
  83106. + dsts_data_t dsts = {.d32 = 0 };
  83107. + depctl_data_t depctl = {.d32 = 0 };
  83108. + volatile uint32_t *addr;
  83109. + int i, j;
  83110. + uint32_t len;
  83111. +
  83112. + if (dwc_ep->is_in)
  83113. + dwc_ep->desc_cnt = dwc_ep->buf_proc_intrvl / dwc_ep->bInterval;
  83114. + else
  83115. + dwc_ep->desc_cnt =
  83116. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  83117. + dwc_ep->bInterval;
  83118. +
  83119. + /** Allocate descriptors for double buffering */
  83120. + dwc_ep->iso_desc_addr =
  83121. + dwc_otg_ep_alloc_desc_chain(&dwc_ep->iso_dma_desc_addr,
  83122. + dwc_ep->desc_cnt * 2);
  83123. + if (dwc_ep->desc_addr) {
  83124. + DWC_WARN("%s, can't allocate DMA descriptor chain\n", __func__);
  83125. + return;
  83126. + }
  83127. +
  83128. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  83129. +
  83130. + /** ISO OUT EP */
  83131. + if (dwc_ep->is_in == 0) {
  83132. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  83133. + dwc_otg_dev_dma_desc_t *dma_desc = dwc_ep->iso_desc_addr;
  83134. + dma_addr_t dma_ad;
  83135. + uint32_t data_per_desc;
  83136. + dwc_otg_dev_out_ep_regs_t *out_regs =
  83137. + core_if->dev_if->out_ep_regs[dwc_ep->num];
  83138. + int offset;
  83139. +
  83140. + addr = &core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl;
  83141. + dma_ad = (dma_addr_t) DWC_READ_REG32(&(out_regs->doepdma));
  83142. +
  83143. + /** Buffer 0 descriptors setup */
  83144. + dma_ad = dwc_ep->dma_addr0;
  83145. +
  83146. + sts.b_iso_out.bs = BS_HOST_READY;
  83147. + sts.b_iso_out.rxsts = 0;
  83148. + sts.b_iso_out.l = 0;
  83149. + sts.b_iso_out.sp = 0;
  83150. + sts.b_iso_out.ioc = 0;
  83151. + sts.b_iso_out.pid = 0;
  83152. + sts.b_iso_out.framenum = 0;
  83153. +
  83154. + offset = 0;
  83155. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  83156. + i += dwc_ep->pkt_per_frm) {
  83157. +
  83158. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  83159. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  83160. + if (len > dwc_ep->data_per_frame)
  83161. + data_per_desc =
  83162. + dwc_ep->data_per_frame -
  83163. + j * dwc_ep->maxpacket;
  83164. + else
  83165. + data_per_desc = dwc_ep->maxpacket;
  83166. + len = data_per_desc % 4;
  83167. + if (len)
  83168. + data_per_desc += 4 - len;
  83169. +
  83170. + sts.b_iso_out.rxbytes = data_per_desc;
  83171. + dma_desc->buf = dma_ad;
  83172. + dma_desc->status.d32 = sts.d32;
  83173. +
  83174. + offset += data_per_desc;
  83175. + dma_desc++;
  83176. + dma_ad += data_per_desc;
  83177. + }
  83178. + }
  83179. +
  83180. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  83181. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  83182. + if (len > dwc_ep->data_per_frame)
  83183. + data_per_desc =
  83184. + dwc_ep->data_per_frame -
  83185. + j * dwc_ep->maxpacket;
  83186. + else
  83187. + data_per_desc = dwc_ep->maxpacket;
  83188. + len = data_per_desc % 4;
  83189. + if (len)
  83190. + data_per_desc += 4 - len;
  83191. + sts.b_iso_out.rxbytes = data_per_desc;
  83192. + dma_desc->buf = dma_ad;
  83193. + dma_desc->status.d32 = sts.d32;
  83194. +
  83195. + offset += data_per_desc;
  83196. + dma_desc++;
  83197. + dma_ad += data_per_desc;
  83198. + }
  83199. +
  83200. + sts.b_iso_out.ioc = 1;
  83201. + len = (j + 1) * dwc_ep->maxpacket;
  83202. + if (len > dwc_ep->data_per_frame)
  83203. + data_per_desc =
  83204. + dwc_ep->data_per_frame - j * dwc_ep->maxpacket;
  83205. + else
  83206. + data_per_desc = dwc_ep->maxpacket;
  83207. + len = data_per_desc % 4;
  83208. + if (len)
  83209. + data_per_desc += 4 - len;
  83210. + sts.b_iso_out.rxbytes = data_per_desc;
  83211. +
  83212. + dma_desc->buf = dma_ad;
  83213. + dma_desc->status.d32 = sts.d32;
  83214. + dma_desc++;
  83215. +
  83216. + /** Buffer 1 descriptors setup */
  83217. + sts.b_iso_out.ioc = 0;
  83218. + dma_ad = dwc_ep->dma_addr1;
  83219. +
  83220. + offset = 0;
  83221. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  83222. + i += dwc_ep->pkt_per_frm) {
  83223. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  83224. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  83225. + if (len > dwc_ep->data_per_frame)
  83226. + data_per_desc =
  83227. + dwc_ep->data_per_frame -
  83228. + j * dwc_ep->maxpacket;
  83229. + else
  83230. + data_per_desc = dwc_ep->maxpacket;
  83231. + len = data_per_desc % 4;
  83232. + if (len)
  83233. + data_per_desc += 4 - len;
  83234. +
  83235. + data_per_desc =
  83236. + sts.b_iso_out.rxbytes = data_per_desc;
  83237. + dma_desc->buf = dma_ad;
  83238. + dma_desc->status.d32 = sts.d32;
  83239. +
  83240. + offset += data_per_desc;
  83241. + dma_desc++;
  83242. + dma_ad += data_per_desc;
  83243. + }
  83244. + }
  83245. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  83246. + data_per_desc =
  83247. + ((j + 1) * dwc_ep->maxpacket >
  83248. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  83249. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  83250. + data_per_desc +=
  83251. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  83252. + sts.b_iso_out.rxbytes = data_per_desc;
  83253. + dma_desc->buf = dma_ad;
  83254. + dma_desc->status.d32 = sts.d32;
  83255. +
  83256. + offset += data_per_desc;
  83257. + dma_desc++;
  83258. + dma_ad += data_per_desc;
  83259. + }
  83260. +
  83261. + sts.b_iso_out.ioc = 1;
  83262. + sts.b_iso_out.l = 1;
  83263. + data_per_desc =
  83264. + ((j + 1) * dwc_ep->maxpacket >
  83265. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  83266. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  83267. + data_per_desc +=
  83268. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  83269. + sts.b_iso_out.rxbytes = data_per_desc;
  83270. +
  83271. + dma_desc->buf = dma_ad;
  83272. + dma_desc->status.d32 = sts.d32;
  83273. +
  83274. + dwc_ep->next_frame = 0;
  83275. +
  83276. + /** Write dma_ad into DOEPDMA register */
  83277. + DWC_WRITE_REG32(&(out_regs->doepdma),
  83278. + (uint32_t) dwc_ep->iso_dma_desc_addr);
  83279. +
  83280. + }
  83281. + /** ISO IN EP */
  83282. + else {
  83283. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  83284. + dwc_otg_dev_dma_desc_t *dma_desc = dwc_ep->iso_desc_addr;
  83285. + dma_addr_t dma_ad;
  83286. + dwc_otg_dev_in_ep_regs_t *in_regs =
  83287. + core_if->dev_if->in_ep_regs[dwc_ep->num];
  83288. + unsigned int frmnumber;
  83289. + fifosize_data_t txfifosize, rxfifosize;
  83290. +
  83291. + txfifosize.d32 =
  83292. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[dwc_ep->num]->
  83293. + dtxfsts);
  83294. + rxfifosize.d32 =
  83295. + DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  83296. +
  83297. + addr = &core_if->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  83298. +
  83299. + dma_ad = dwc_ep->dma_addr0;
  83300. +
  83301. + dsts.d32 =
  83302. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  83303. +
  83304. + sts.b_iso_in.bs = BS_HOST_READY;
  83305. + sts.b_iso_in.txsts = 0;
  83306. + sts.b_iso_in.sp =
  83307. + (dwc_ep->data_per_frame % dwc_ep->maxpacket) ? 1 : 0;
  83308. + sts.b_iso_in.ioc = 0;
  83309. + sts.b_iso_in.pid = dwc_ep->pkt_per_frm;
  83310. +
  83311. + frmnumber = dwc_ep->next_frame;
  83312. +
  83313. + sts.b_iso_in.framenum = frmnumber;
  83314. + sts.b_iso_in.txbytes = dwc_ep->data_per_frame;
  83315. + sts.b_iso_in.l = 0;
  83316. +
  83317. + /** Buffer 0 descriptors setup */
  83318. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  83319. + dma_desc->buf = dma_ad;
  83320. + dma_desc->status.d32 = sts.d32;
  83321. + dma_desc++;
  83322. +
  83323. + dma_ad += dwc_ep->data_per_frame;
  83324. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  83325. + }
  83326. +
  83327. + sts.b_iso_in.ioc = 1;
  83328. + dma_desc->buf = dma_ad;
  83329. + dma_desc->status.d32 = sts.d32;
  83330. + ++dma_desc;
  83331. +
  83332. + /** Buffer 1 descriptors setup */
  83333. + sts.b_iso_in.ioc = 0;
  83334. + dma_ad = dwc_ep->dma_addr1;
  83335. +
  83336. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  83337. + i += dwc_ep->pkt_per_frm) {
  83338. + dma_desc->buf = dma_ad;
  83339. + dma_desc->status.d32 = sts.d32;
  83340. + dma_desc++;
  83341. +
  83342. + dma_ad += dwc_ep->data_per_frame;
  83343. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  83344. +
  83345. + sts.b_iso_in.ioc = 0;
  83346. + }
  83347. + sts.b_iso_in.ioc = 1;
  83348. + sts.b_iso_in.l = 1;
  83349. +
  83350. + dma_desc->buf = dma_ad;
  83351. + dma_desc->status.d32 = sts.d32;
  83352. +
  83353. + dwc_ep->next_frame = sts.b_iso_in.framenum + dwc_ep->bInterval;
  83354. +
  83355. + /** Write dma_ad into diepdma register */
  83356. + DWC_WRITE_REG32(&(in_regs->diepdma),
  83357. + (uint32_t) dwc_ep->iso_dma_desc_addr);
  83358. + }
  83359. + /** Enable endpoint, clear nak */
  83360. + depctl.d32 = 0;
  83361. + depctl.b.epena = 1;
  83362. + depctl.b.usbactep = 1;
  83363. + depctl.b.cnak = 1;
  83364. +
  83365. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  83366. + depctl.d32 = DWC_READ_REG32(addr);
  83367. +}
  83368. +
  83369. +/**
  83370. + * This function initializes a descriptor chain for Isochronous transfer
  83371. + *
  83372. + * @param core_if Programming view of DWC_otg controller.
  83373. + * @param ep The EP to start the transfer on.
  83374. + *
  83375. + */
  83376. +void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t * core_if,
  83377. + dwc_ep_t * ep)
  83378. +{
  83379. + depctl_data_t depctl = {.d32 = 0 };
  83380. + volatile uint32_t *addr;
  83381. +
  83382. + if (ep->is_in) {
  83383. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  83384. + } else {
  83385. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  83386. + }
  83387. +
  83388. + if (core_if->dma_enable == 0 || core_if->dma_desc_enable != 0) {
  83389. + return;
  83390. + } else {
  83391. + deptsiz_data_t deptsiz = {.d32 = 0 };
  83392. +
  83393. + ep->xfer_len =
  83394. + ep->data_per_frame * ep->buf_proc_intrvl / ep->bInterval;
  83395. + ep->pkt_cnt =
  83396. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  83397. + ep->xfer_count = 0;
  83398. + ep->xfer_buff =
  83399. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->xfer_buff0;
  83400. + ep->dma_addr =
  83401. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->dma_addr0;
  83402. +
  83403. + if (ep->is_in) {
  83404. + /* Program the transfer size and packet count
  83405. + * as follows: xfersize = N * maxpacket +
  83406. + * short_packet pktcnt = N + (short_packet
  83407. + * exist ? 1 : 0)
  83408. + */
  83409. + deptsiz.b.mc = ep->pkt_per_frm;
  83410. + deptsiz.b.xfersize = ep->xfer_len;
  83411. + deptsiz.b.pktcnt =
  83412. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  83413. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  83414. + dieptsiz, deptsiz.d32);
  83415. +
  83416. + /* Write the DMA register */
  83417. + DWC_WRITE_REG32(&
  83418. + (core_if->dev_if->in_ep_regs[ep->num]->
  83419. + diepdma), (uint32_t) ep->dma_addr);
  83420. +
  83421. + } else {
  83422. + deptsiz.b.pktcnt =
  83423. + (ep->xfer_len + (ep->maxpacket - 1)) /
  83424. + ep->maxpacket;
  83425. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  83426. +
  83427. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->
  83428. + doeptsiz, deptsiz.d32);
  83429. +
  83430. + /* Write the DMA register */
  83431. + DWC_WRITE_REG32(&
  83432. + (core_if->dev_if->out_ep_regs[ep->num]->
  83433. + doepdma), (uint32_t) ep->dma_addr);
  83434. +
  83435. + }
  83436. + /** Enable endpoint, clear nak */
  83437. + depctl.d32 = 0;
  83438. + depctl.b.epena = 1;
  83439. + depctl.b.cnak = 1;
  83440. +
  83441. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  83442. + }
  83443. +}
  83444. +
  83445. +/**
  83446. + * This function does the setup for a data transfer for an EP and
  83447. + * starts the transfer. For an IN transfer, the packets will be
  83448. + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
  83449. + * the packets are unloaded from the Rx FIFO in the ISR.
  83450. + *
  83451. + * @param core_if Programming view of DWC_otg controller.
  83452. + * @param ep The EP to start the transfer on.
  83453. + */
  83454. +
  83455. +static void dwc_otg_iso_ep_start_transfer(dwc_otg_core_if_t * core_if,
  83456. + dwc_ep_t * ep)
  83457. +{
  83458. + if (core_if->dma_enable) {
  83459. + if (core_if->dma_desc_enable) {
  83460. + if (ep->is_in) {
  83461. + ep->desc_cnt = ep->pkt_cnt / ep->pkt_per_frm;
  83462. + } else {
  83463. + ep->desc_cnt = ep->pkt_cnt;
  83464. + }
  83465. + dwc_otg_iso_ep_start_ddma_transfer(core_if, ep);
  83466. + } else {
  83467. + if (core_if->pti_enh_enable) {
  83468. + dwc_otg_iso_ep_start_buf_transfer(core_if, ep);
  83469. + } else {
  83470. + ep->cur_pkt_addr =
  83471. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->
  83472. + xfer_buff0;
  83473. + ep->cur_pkt_dma_addr =
  83474. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->
  83475. + dma_addr0;
  83476. + dwc_otg_iso_ep_start_frm_transfer(core_if, ep);
  83477. + }
  83478. + }
  83479. + } else {
  83480. + ep->cur_pkt_addr =
  83481. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->xfer_buff0;
  83482. + ep->cur_pkt_dma_addr =
  83483. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->dma_addr0;
  83484. + dwc_otg_iso_ep_start_frm_transfer(core_if, ep);
  83485. + }
  83486. +}
  83487. +
  83488. +/**
  83489. + * This function stops transfer for an EP and
  83490. + * resets the ep's variables.
  83491. + *
  83492. + * @param core_if Programming view of DWC_otg controller.
  83493. + * @param ep The EP to start the transfer on.
  83494. + */
  83495. +
  83496. +void dwc_otg_iso_ep_stop_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  83497. +{
  83498. + depctl_data_t depctl = {.d32 = 0 };
  83499. + volatile uint32_t *addr;
  83500. +
  83501. + if (ep->is_in == 1) {
  83502. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  83503. + } else {
  83504. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  83505. + }
  83506. +
  83507. + /* disable the ep */
  83508. + depctl.d32 = DWC_READ_REG32(addr);
  83509. +
  83510. + depctl.b.epdis = 1;
  83511. + depctl.b.snak = 1;
  83512. +
  83513. + DWC_WRITE_REG32(addr, depctl.d32);
  83514. +
  83515. + if (core_if->dma_desc_enable &&
  83516. + ep->iso_desc_addr && ep->iso_dma_desc_addr) {
  83517. + dwc_otg_ep_free_desc_chain(ep->iso_desc_addr,
  83518. + ep->iso_dma_desc_addr,
  83519. + ep->desc_cnt * 2);
  83520. + }
  83521. +
  83522. + /* reset varibales */
  83523. + ep->dma_addr0 = 0;
  83524. + ep->dma_addr1 = 0;
  83525. + ep->xfer_buff0 = 0;
  83526. + ep->xfer_buff1 = 0;
  83527. + ep->data_per_frame = 0;
  83528. + ep->data_pattern_frame = 0;
  83529. + ep->sync_frame = 0;
  83530. + ep->buf_proc_intrvl = 0;
  83531. + ep->bInterval = 0;
  83532. + ep->proc_buf_num = 0;
  83533. + ep->pkt_per_frm = 0;
  83534. + ep->pkt_per_frm = 0;
  83535. + ep->desc_cnt = 0;
  83536. + ep->iso_desc_addr = 0;
  83537. + ep->iso_dma_desc_addr = 0;
  83538. +}
  83539. +
  83540. +int dwc_otg_pcd_iso_ep_start(dwc_otg_pcd_t * pcd, void *ep_handle,
  83541. + uint8_t * buf0, uint8_t * buf1, dwc_dma_t dma0,
  83542. + dwc_dma_t dma1, int sync_frame, int dp_frame,
  83543. + int data_per_frame, int start_frame,
  83544. + int buf_proc_intrvl, void *req_handle,
  83545. + int atomic_alloc)
  83546. +{
  83547. + dwc_otg_pcd_ep_t *ep;
  83548. + dwc_irqflags_t flags = 0;
  83549. + dwc_ep_t *dwc_ep;
  83550. + int32_t frm_data;
  83551. + dsts_data_t dsts;
  83552. + dwc_otg_core_if_t *core_if;
  83553. +
  83554. + ep = get_ep_from_handle(pcd, ep_handle);
  83555. +
  83556. + if (!ep || !ep->desc || ep->dwc_ep.num == 0) {
  83557. + DWC_WARN("bad ep\n");
  83558. + return -DWC_E_INVALID;
  83559. + }
  83560. +
  83561. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  83562. + core_if = GET_CORE_IF(pcd);
  83563. + dwc_ep = &ep->dwc_ep;
  83564. +
  83565. + if (ep->iso_req_handle) {
  83566. + DWC_WARN("ISO request in progress\n");
  83567. + }
  83568. +
  83569. + dwc_ep->dma_addr0 = dma0;
  83570. + dwc_ep->dma_addr1 = dma1;
  83571. +
  83572. + dwc_ep->xfer_buff0 = buf0;
  83573. + dwc_ep->xfer_buff1 = buf1;
  83574. +
  83575. + dwc_ep->data_per_frame = data_per_frame;
  83576. +
  83577. + /** @todo - pattern data support is to be implemented in the future */
  83578. + dwc_ep->data_pattern_frame = dp_frame;
  83579. + dwc_ep->sync_frame = sync_frame;
  83580. +
  83581. + dwc_ep->buf_proc_intrvl = buf_proc_intrvl;
  83582. +
  83583. + dwc_ep->bInterval = 1 << (ep->desc->bInterval - 1);
  83584. +
  83585. + dwc_ep->proc_buf_num = 0;
  83586. +
  83587. + dwc_ep->pkt_per_frm = 0;
  83588. + frm_data = ep->dwc_ep.data_per_frame;
  83589. + while (frm_data > 0) {
  83590. + dwc_ep->pkt_per_frm++;
  83591. + frm_data -= ep->dwc_ep.maxpacket;
  83592. + }
  83593. +
  83594. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  83595. +
  83596. + if (start_frame == -1) {
  83597. + dwc_ep->next_frame = dsts.b.soffn + 1;
  83598. + if (dwc_ep->bInterval != 1) {
  83599. + dwc_ep->next_frame =
  83600. + dwc_ep->next_frame + (dwc_ep->bInterval - 1 -
  83601. + dwc_ep->next_frame %
  83602. + dwc_ep->bInterval);
  83603. + }
  83604. + } else {
  83605. + dwc_ep->next_frame = start_frame;
  83606. + }
  83607. +
  83608. + if (!core_if->pti_enh_enable) {
  83609. + dwc_ep->pkt_cnt =
  83610. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  83611. + dwc_ep->bInterval;
  83612. + } else {
  83613. + dwc_ep->pkt_cnt =
  83614. + (dwc_ep->data_per_frame *
  83615. + (dwc_ep->buf_proc_intrvl / dwc_ep->bInterval)
  83616. + - 1 + dwc_ep->maxpacket) / dwc_ep->maxpacket;
  83617. + }
  83618. +
  83619. + if (core_if->dma_desc_enable) {
  83620. + dwc_ep->desc_cnt =
  83621. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  83622. + dwc_ep->bInterval;
  83623. + }
  83624. +
  83625. + if (atomic_alloc) {
  83626. + dwc_ep->pkt_info =
  83627. + DWC_ALLOC_ATOMIC(sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  83628. + } else {
  83629. + dwc_ep->pkt_info =
  83630. + DWC_ALLOC(sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  83631. + }
  83632. + if (!dwc_ep->pkt_info) {
  83633. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83634. + return -DWC_E_NO_MEMORY;
  83635. + }
  83636. + if (core_if->pti_enh_enable) {
  83637. + dwc_memset(dwc_ep->pkt_info, 0,
  83638. + sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  83639. + }
  83640. +
  83641. + dwc_ep->cur_pkt = 0;
  83642. + ep->iso_req_handle = req_handle;
  83643. +
  83644. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83645. + dwc_otg_iso_ep_start_transfer(core_if, dwc_ep);
  83646. + return 0;
  83647. +}
  83648. +
  83649. +int dwc_otg_pcd_iso_ep_stop(dwc_otg_pcd_t * pcd, void *ep_handle,
  83650. + void *req_handle)
  83651. +{
  83652. + dwc_irqflags_t flags = 0;
  83653. + dwc_otg_pcd_ep_t *ep;
  83654. + dwc_ep_t *dwc_ep;
  83655. +
  83656. + ep = get_ep_from_handle(pcd, ep_handle);
  83657. + if (!ep || !ep->desc || ep->dwc_ep.num == 0) {
  83658. + DWC_WARN("bad ep\n");
  83659. + return -DWC_E_INVALID;
  83660. + }
  83661. + dwc_ep = &ep->dwc_ep;
  83662. +
  83663. + dwc_otg_iso_ep_stop_transfer(GET_CORE_IF(pcd), dwc_ep);
  83664. +
  83665. + DWC_FREE(dwc_ep->pkt_info);
  83666. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  83667. + if (ep->iso_req_handle != req_handle) {
  83668. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83669. + return -DWC_E_INVALID;
  83670. + }
  83671. +
  83672. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83673. +
  83674. + ep->iso_req_handle = 0;
  83675. + return 0;
  83676. +}
  83677. +
  83678. +/**
  83679. + * This function is used for perodical data exchnage between PCD and gadget drivers.
  83680. + * for Isochronous EPs
  83681. + *
  83682. + * - Every time a sync period completes this function is called to
  83683. + * perform data exchange between PCD and gadget
  83684. + */
  83685. +void dwc_otg_iso_buffer_done(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep,
  83686. + void *req_handle)
  83687. +{
  83688. + int i;
  83689. + dwc_ep_t *dwc_ep;
  83690. +
  83691. + dwc_ep = &ep->dwc_ep;
  83692. +
  83693. + DWC_SPINUNLOCK(ep->pcd->lock);
  83694. + pcd->fops->isoc_complete(pcd, ep->priv, ep->iso_req_handle,
  83695. + dwc_ep->proc_buf_num ^ 0x1);
  83696. + DWC_SPINLOCK(ep->pcd->lock);
  83697. +
  83698. + for (i = 0; i < dwc_ep->pkt_cnt; ++i) {
  83699. + dwc_ep->pkt_info[i].status = 0;
  83700. + dwc_ep->pkt_info[i].offset = 0;
  83701. + dwc_ep->pkt_info[i].length = 0;
  83702. + }
  83703. +}
  83704. +
  83705. +int dwc_otg_pcd_get_iso_packet_count(dwc_otg_pcd_t * pcd, void *ep_handle,
  83706. + void *iso_req_handle)
  83707. +{
  83708. + dwc_otg_pcd_ep_t *ep;
  83709. + dwc_ep_t *dwc_ep;
  83710. +
  83711. + ep = get_ep_from_handle(pcd, ep_handle);
  83712. + if (!ep->desc || ep->dwc_ep.num == 0) {
  83713. + DWC_WARN("bad ep\n");
  83714. + return -DWC_E_INVALID;
  83715. + }
  83716. + dwc_ep = &ep->dwc_ep;
  83717. +
  83718. + return dwc_ep->pkt_cnt;
  83719. +}
  83720. +
  83721. +void dwc_otg_pcd_get_iso_packet_params(dwc_otg_pcd_t * pcd, void *ep_handle,
  83722. + void *iso_req_handle, int packet,
  83723. + int *status, int *actual, int *offset)
  83724. +{
  83725. + dwc_otg_pcd_ep_t *ep;
  83726. + dwc_ep_t *dwc_ep;
  83727. +
  83728. + ep = get_ep_from_handle(pcd, ep_handle);
  83729. + if (!ep)
  83730. + DWC_WARN("bad ep\n");
  83731. +
  83732. + dwc_ep = &ep->dwc_ep;
  83733. +
  83734. + *status = dwc_ep->pkt_info[packet].status;
  83735. + *actual = dwc_ep->pkt_info[packet].length;
  83736. + *offset = dwc_ep->pkt_info[packet].offset;
  83737. +}
  83738. +
  83739. +#endif /* DWC_EN_ISOC */
  83740. +
  83741. +static void dwc_otg_pcd_init_ep(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * pcd_ep,
  83742. + uint32_t is_in, uint32_t ep_num)
  83743. +{
  83744. + /* Init EP structure */
  83745. + pcd_ep->desc = 0;
  83746. + pcd_ep->pcd = pcd;
  83747. + pcd_ep->stopped = 1;
  83748. + pcd_ep->queue_sof = 0;
  83749. +
  83750. + /* Init DWC ep structure */
  83751. + pcd_ep->dwc_ep.is_in = is_in;
  83752. + pcd_ep->dwc_ep.num = ep_num;
  83753. + pcd_ep->dwc_ep.active = 0;
  83754. + pcd_ep->dwc_ep.tx_fifo_num = 0;
  83755. + /* Control until ep is actvated */
  83756. + pcd_ep->dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
  83757. + pcd_ep->dwc_ep.maxpacket = MAX_PACKET_SIZE;
  83758. + pcd_ep->dwc_ep.dma_addr = 0;
  83759. + pcd_ep->dwc_ep.start_xfer_buff = 0;
  83760. + pcd_ep->dwc_ep.xfer_buff = 0;
  83761. + pcd_ep->dwc_ep.xfer_len = 0;
  83762. + pcd_ep->dwc_ep.xfer_count = 0;
  83763. + pcd_ep->dwc_ep.sent_zlp = 0;
  83764. + pcd_ep->dwc_ep.total_len = 0;
  83765. + pcd_ep->dwc_ep.desc_addr = 0;
  83766. + pcd_ep->dwc_ep.dma_desc_addr = 0;
  83767. + DWC_CIRCLEQ_INIT(&pcd_ep->queue);
  83768. +}
  83769. +
  83770. +/**
  83771. + * Initialize ep's
  83772. + */
  83773. +static void dwc_otg_pcd_reinit(dwc_otg_pcd_t * pcd)
  83774. +{
  83775. + int i;
  83776. + uint32_t hwcfg1;
  83777. + dwc_otg_pcd_ep_t *ep;
  83778. + int in_ep_cntr, out_ep_cntr;
  83779. + uint32_t num_in_eps = (GET_CORE_IF(pcd))->dev_if->num_in_eps;
  83780. + uint32_t num_out_eps = (GET_CORE_IF(pcd))->dev_if->num_out_eps;
  83781. +
  83782. + /**
  83783. + * Initialize the EP0 structure.
  83784. + */
  83785. + ep = &pcd->ep0;
  83786. + dwc_otg_pcd_init_ep(pcd, ep, 0, 0);
  83787. +
  83788. + in_ep_cntr = 0;
  83789. + hwcfg1 = (GET_CORE_IF(pcd))->hwcfg1.d32 >> 3;
  83790. + for (i = 1; in_ep_cntr < num_in_eps; i++) {
  83791. + if ((hwcfg1 & 0x1) == 0) {
  83792. + dwc_otg_pcd_ep_t *ep = &pcd->in_ep[in_ep_cntr];
  83793. + in_ep_cntr++;
  83794. + /**
  83795. + * @todo NGS: Add direction to EP, based on contents
  83796. + * of HWCFG1. Need a copy of HWCFG1 in pcd structure?
  83797. + * sprintf(";r
  83798. + */
  83799. + dwc_otg_pcd_init_ep(pcd, ep, 1 /* IN */ , i);
  83800. +
  83801. + DWC_CIRCLEQ_INIT(&ep->queue);
  83802. + }
  83803. + hwcfg1 >>= 2;
  83804. + }
  83805. +
  83806. + out_ep_cntr = 0;
  83807. + hwcfg1 = (GET_CORE_IF(pcd))->hwcfg1.d32 >> 2;
  83808. + for (i = 1; out_ep_cntr < num_out_eps; i++) {
  83809. + if ((hwcfg1 & 0x1) == 0) {
  83810. + dwc_otg_pcd_ep_t *ep = &pcd->out_ep[out_ep_cntr];
  83811. + out_ep_cntr++;
  83812. + /**
  83813. + * @todo NGS: Add direction to EP, based on contents
  83814. + * of HWCFG1. Need a copy of HWCFG1 in pcd structure?
  83815. + * sprintf(";r
  83816. + */
  83817. + dwc_otg_pcd_init_ep(pcd, ep, 0 /* OUT */ , i);
  83818. + DWC_CIRCLEQ_INIT(&ep->queue);
  83819. + }
  83820. + hwcfg1 >>= 2;
  83821. + }
  83822. +
  83823. + pcd->ep0state = EP0_DISCONNECT;
  83824. + pcd->ep0.dwc_ep.maxpacket = MAX_EP0_SIZE;
  83825. + pcd->ep0.dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
  83826. +}
  83827. +
  83828. +/**
  83829. + * This function is called when the SRP timer expires. The SRP should
  83830. + * complete within 6 seconds.
  83831. + */
  83832. +static void srp_timeout(void *ptr)
  83833. +{
  83834. + gotgctl_data_t gotgctl;
  83835. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  83836. + volatile uint32_t *addr = &core_if->core_global_regs->gotgctl;
  83837. +
  83838. + gotgctl.d32 = DWC_READ_REG32(addr);
  83839. +
  83840. + core_if->srp_timer_started = 0;
  83841. +
  83842. + if (core_if->adp_enable) {
  83843. + if (gotgctl.b.bsesvld == 0) {
  83844. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  83845. + DWC_PRINTF("SRP Timeout BSESSVLD = 0\n");
  83846. + /* Power off the core */
  83847. + if (core_if->power_down == 2) {
  83848. + gpwrdn.b.pwrdnswtch = 1;
  83849. + DWC_MODIFY_REG32(&core_if->
  83850. + core_global_regs->gpwrdn,
  83851. + gpwrdn.d32, 0);
  83852. + }
  83853. +
  83854. + gpwrdn.d32 = 0;
  83855. + gpwrdn.b.pmuintsel = 1;
  83856. + gpwrdn.b.pmuactv = 1;
  83857. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  83858. + gpwrdn.d32);
  83859. + dwc_otg_adp_probe_start(core_if);
  83860. + } else {
  83861. + DWC_PRINTF("SRP Timeout BSESSVLD = 1\n");
  83862. + core_if->op_state = B_PERIPHERAL;
  83863. + dwc_otg_core_init(core_if);
  83864. + dwc_otg_enable_global_interrupts(core_if);
  83865. + cil_pcd_start(core_if);
  83866. + }
  83867. + }
  83868. +
  83869. + if ((core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS) &&
  83870. + (core_if->core_params->i2c_enable)) {
  83871. + DWC_PRINTF("SRP Timeout\n");
  83872. +
  83873. + if ((core_if->srp_success) && (gotgctl.b.bsesvld)) {
  83874. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  83875. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  83876. + }
  83877. +
  83878. + /* Clear Session Request */
  83879. + gotgctl.d32 = 0;
  83880. + gotgctl.b.sesreq = 1;
  83881. + DWC_MODIFY_REG32(&core_if->core_global_regs->gotgctl,
  83882. + gotgctl.d32, 0);
  83883. +
  83884. + core_if->srp_success = 0;
  83885. + } else {
  83886. + __DWC_ERROR("Device not connected/responding\n");
  83887. + gotgctl.b.sesreq = 0;
  83888. + DWC_WRITE_REG32(addr, gotgctl.d32);
  83889. + }
  83890. + } else if (gotgctl.b.sesreq) {
  83891. + DWC_PRINTF("SRP Timeout\n");
  83892. +
  83893. + __DWC_ERROR("Device not connected/responding\n");
  83894. + gotgctl.b.sesreq = 0;
  83895. + DWC_WRITE_REG32(addr, gotgctl.d32);
  83896. + } else {
  83897. + DWC_PRINTF(" SRP GOTGCTL=%0x\n", gotgctl.d32);
  83898. + }
  83899. +}
  83900. +
  83901. +/**
  83902. + * Tasklet
  83903. + *
  83904. + */
  83905. +extern void start_next_request(dwc_otg_pcd_ep_t * ep);
  83906. +
  83907. +static void start_xfer_tasklet_func(void *data)
  83908. +{
  83909. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) data;
  83910. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83911. +
  83912. + int i;
  83913. + depctl_data_t diepctl;
  83914. +
  83915. + DWC_DEBUGPL(DBG_PCDV, "Start xfer tasklet\n");
  83916. +
  83917. + diepctl.d32 = DWC_READ_REG32(&core_if->dev_if->in_ep_regs[0]->diepctl);
  83918. +
  83919. + if (pcd->ep0.queue_sof) {
  83920. + pcd->ep0.queue_sof = 0;
  83921. + start_next_request(&pcd->ep0);
  83922. + // break;
  83923. + }
  83924. +
  83925. + for (i = 0; i < core_if->dev_if->num_in_eps; i++) {
  83926. + depctl_data_t diepctl;
  83927. + diepctl.d32 =
  83928. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl);
  83929. +
  83930. + if (pcd->in_ep[i].queue_sof) {
  83931. + pcd->in_ep[i].queue_sof = 0;
  83932. + start_next_request(&pcd->in_ep[i]);
  83933. + // break;
  83934. + }
  83935. + }
  83936. +
  83937. + return;
  83938. +}
  83939. +
  83940. +/**
  83941. + * This function initialized the PCD portion of the driver.
  83942. + *
  83943. + */
  83944. +dwc_otg_pcd_t *dwc_otg_pcd_init(dwc_otg_core_if_t * core_if)
  83945. +{
  83946. + dwc_otg_pcd_t *pcd = NULL;
  83947. + dwc_otg_dev_if_t *dev_if;
  83948. + int i;
  83949. +
  83950. + /*
  83951. + * Allocate PCD structure
  83952. + */
  83953. + pcd = DWC_ALLOC(sizeof(dwc_otg_pcd_t));
  83954. +
  83955. + if (pcd == NULL) {
  83956. + return NULL;
  83957. + }
  83958. +
  83959. + pcd->lock = DWC_SPINLOCK_ALLOC();
  83960. + DWC_DEBUGPL(DBG_HCDV, "Init of PCD %p given core_if %p\n",
  83961. + pcd, core_if);//GRAYG
  83962. + if (!pcd->lock) {
  83963. + DWC_ERROR("Could not allocate lock for pcd");
  83964. + DWC_FREE(pcd);
  83965. + return NULL;
  83966. + }
  83967. + /* Set core_if's lock pointer to hcd->lock */
  83968. + core_if->lock = pcd->lock;
  83969. + pcd->core_if = core_if;
  83970. +
  83971. + dev_if = core_if->dev_if;
  83972. + dev_if->isoc_ep = NULL;
  83973. +
  83974. + if (core_if->hwcfg4.b.ded_fifo_en) {
  83975. + DWC_PRINTF("Dedicated Tx FIFOs mode\n");
  83976. + } else {
  83977. + DWC_PRINTF("Shared Tx FIFO mode\n");
  83978. + }
  83979. +
  83980. + /*
  83981. + * Initialized the Core for Device mode here if there is nod ADP support.
  83982. + * Otherwise it will be done later in dwc_otg_adp_start routine.
  83983. + */
  83984. + if (dwc_otg_is_device_mode(core_if) /*&& !core_if->adp_enable*/) {
  83985. + dwc_otg_core_dev_init(core_if);
  83986. + }
  83987. +
  83988. + /*
  83989. + * Register the PCD Callbacks.
  83990. + */
  83991. + dwc_otg_cil_register_pcd_callbacks(core_if, &pcd_callbacks, pcd);
  83992. +
  83993. + /*
  83994. + * Initialize the DMA buffer for SETUP packets
  83995. + */
  83996. + if (GET_CORE_IF(pcd)->dma_enable) {
  83997. + pcd->setup_pkt =
  83998. + DWC_DMA_ALLOC(sizeof(*pcd->setup_pkt) * 5,
  83999. + &pcd->setup_pkt_dma_handle);
  84000. + if (pcd->setup_pkt == NULL) {
  84001. + DWC_FREE(pcd);
  84002. + return NULL;
  84003. + }
  84004. +
  84005. + pcd->status_buf =
  84006. + DWC_DMA_ALLOC(sizeof(uint16_t),
  84007. + &pcd->status_buf_dma_handle);
  84008. + if (pcd->status_buf == NULL) {
  84009. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5,
  84010. + pcd->setup_pkt, pcd->setup_pkt_dma_handle);
  84011. + DWC_FREE(pcd);
  84012. + return NULL;
  84013. + }
  84014. +
  84015. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  84016. + dev_if->setup_desc_addr[0] =
  84017. + dwc_otg_ep_alloc_desc_chain
  84018. + (&dev_if->dma_setup_desc_addr[0], 1);
  84019. + dev_if->setup_desc_addr[1] =
  84020. + dwc_otg_ep_alloc_desc_chain
  84021. + (&dev_if->dma_setup_desc_addr[1], 1);
  84022. + dev_if->in_desc_addr =
  84023. + dwc_otg_ep_alloc_desc_chain
  84024. + (&dev_if->dma_in_desc_addr, 1);
  84025. + dev_if->out_desc_addr =
  84026. + dwc_otg_ep_alloc_desc_chain
  84027. + (&dev_if->dma_out_desc_addr, 1);
  84028. + pcd->data_terminated = 0;
  84029. +
  84030. + if (dev_if->setup_desc_addr[0] == 0
  84031. + || dev_if->setup_desc_addr[1] == 0
  84032. + || dev_if->in_desc_addr == 0
  84033. + || dev_if->out_desc_addr == 0) {
  84034. +
  84035. + if (dev_if->out_desc_addr)
  84036. + dwc_otg_ep_free_desc_chain
  84037. + (dev_if->out_desc_addr,
  84038. + dev_if->dma_out_desc_addr, 1);
  84039. + if (dev_if->in_desc_addr)
  84040. + dwc_otg_ep_free_desc_chain
  84041. + (dev_if->in_desc_addr,
  84042. + dev_if->dma_in_desc_addr, 1);
  84043. + if (dev_if->setup_desc_addr[1])
  84044. + dwc_otg_ep_free_desc_chain
  84045. + (dev_if->setup_desc_addr[1],
  84046. + dev_if->dma_setup_desc_addr[1], 1);
  84047. + if (dev_if->setup_desc_addr[0])
  84048. + dwc_otg_ep_free_desc_chain
  84049. + (dev_if->setup_desc_addr[0],
  84050. + dev_if->dma_setup_desc_addr[0], 1);
  84051. +
  84052. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5,
  84053. + pcd->setup_pkt,
  84054. + pcd->setup_pkt_dma_handle);
  84055. + DWC_DMA_FREE(sizeof(*pcd->status_buf),
  84056. + pcd->status_buf,
  84057. + pcd->status_buf_dma_handle);
  84058. +
  84059. + DWC_FREE(pcd);
  84060. +
  84061. + return NULL;
  84062. + }
  84063. + }
  84064. + } else {
  84065. + pcd->setup_pkt = DWC_ALLOC(sizeof(*pcd->setup_pkt) * 5);
  84066. + if (pcd->setup_pkt == NULL) {
  84067. + DWC_FREE(pcd);
  84068. + return NULL;
  84069. + }
  84070. +
  84071. + pcd->status_buf = DWC_ALLOC(sizeof(uint16_t));
  84072. + if (pcd->status_buf == NULL) {
  84073. + DWC_FREE(pcd->setup_pkt);
  84074. + DWC_FREE(pcd);
  84075. + return NULL;
  84076. + }
  84077. + }
  84078. +
  84079. + dwc_otg_pcd_reinit(pcd);
  84080. +
  84081. + /* Allocate the cfi object for the PCD */
  84082. +#ifdef DWC_UTE_CFI
  84083. + pcd->cfi = DWC_ALLOC(sizeof(cfiobject_t));
  84084. + if (NULL == pcd->cfi)
  84085. + goto fail;
  84086. + if (init_cfi(pcd->cfi)) {
  84087. + CFI_INFO("%s: Failed to init the CFI object\n", __func__);
  84088. + goto fail;
  84089. + }
  84090. +#endif
  84091. +
  84092. + /* Initialize tasklets */
  84093. + pcd->start_xfer_tasklet = DWC_TASK_ALLOC("xfer_tasklet",
  84094. + start_xfer_tasklet_func, pcd);
  84095. + pcd->test_mode_tasklet = DWC_TASK_ALLOC("test_mode_tasklet",
  84096. + do_test_mode, pcd);
  84097. +
  84098. + /* Initialize SRP timer */
  84099. + core_if->srp_timer = DWC_TIMER_ALLOC("SRP TIMER", srp_timeout, core_if);
  84100. +
  84101. + if (core_if->core_params->dev_out_nak) {
  84102. + /**
  84103. + * Initialize xfer timeout timer. Implemented for
  84104. + * 2.93a feature "Device DDMA OUT NAK Enhancement"
  84105. + */
  84106. + for(i = 0; i < MAX_EPS_CHANNELS; i++) {
  84107. + pcd->core_if->ep_xfer_timer[i] =
  84108. + DWC_TIMER_ALLOC("ep timer", ep_xfer_timeout,
  84109. + &pcd->core_if->ep_xfer_info[i]);
  84110. + }
  84111. + }
  84112. +
  84113. + return pcd;
  84114. +#ifdef DWC_UTE_CFI
  84115. +fail:
  84116. +#endif
  84117. + if (pcd->setup_pkt)
  84118. + DWC_FREE(pcd->setup_pkt);
  84119. + if (pcd->status_buf)
  84120. + DWC_FREE(pcd->status_buf);
  84121. +#ifdef DWC_UTE_CFI
  84122. + if (pcd->cfi)
  84123. + DWC_FREE(pcd->cfi);
  84124. +#endif
  84125. + if (pcd)
  84126. + DWC_FREE(pcd);
  84127. + return NULL;
  84128. +
  84129. +}
  84130. +
  84131. +/**
  84132. + * Remove PCD specific data
  84133. + */
  84134. +void dwc_otg_pcd_remove(dwc_otg_pcd_t * pcd)
  84135. +{
  84136. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  84137. + int i;
  84138. + if (pcd->core_if->core_params->dev_out_nak) {
  84139. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  84140. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[i]);
  84141. + pcd->core_if->ep_xfer_info[i].state = 0;
  84142. + }
  84143. + }
  84144. +
  84145. + if (GET_CORE_IF(pcd)->dma_enable) {
  84146. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5, pcd->setup_pkt,
  84147. + pcd->setup_pkt_dma_handle);
  84148. + DWC_DMA_FREE(sizeof(uint16_t), pcd->status_buf,
  84149. + pcd->status_buf_dma_handle);
  84150. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  84151. + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[0],
  84152. + dev_if->dma_setup_desc_addr
  84153. + [0], 1);
  84154. + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[1],
  84155. + dev_if->dma_setup_desc_addr
  84156. + [1], 1);
  84157. + dwc_otg_ep_free_desc_chain(dev_if->in_desc_addr,
  84158. + dev_if->dma_in_desc_addr, 1);
  84159. + dwc_otg_ep_free_desc_chain(dev_if->out_desc_addr,
  84160. + dev_if->dma_out_desc_addr,
  84161. + 1);
  84162. + }
  84163. + } else {
  84164. + DWC_FREE(pcd->setup_pkt);
  84165. + DWC_FREE(pcd->status_buf);
  84166. + }
  84167. + DWC_SPINLOCK_FREE(pcd->lock);
  84168. + /* Set core_if's lock pointer to NULL */
  84169. + pcd->core_if->lock = NULL;
  84170. +
  84171. + DWC_TASK_FREE(pcd->start_xfer_tasklet);
  84172. + DWC_TASK_FREE(pcd->test_mode_tasklet);
  84173. + if (pcd->core_if->core_params->dev_out_nak) {
  84174. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  84175. + if (pcd->core_if->ep_xfer_timer[i]) {
  84176. + DWC_TIMER_FREE(pcd->core_if->ep_xfer_timer[i]);
  84177. + }
  84178. + }
  84179. + }
  84180. +
  84181. +/* Release the CFI object's dynamic memory */
  84182. +#ifdef DWC_UTE_CFI
  84183. + if (pcd->cfi->ops.release) {
  84184. + pcd->cfi->ops.release(pcd->cfi);
  84185. + }
  84186. +#endif
  84187. +
  84188. + DWC_FREE(pcd);
  84189. +}
  84190. +
  84191. +/**
  84192. + * Returns whether registered pcd is dual speed or not
  84193. + */
  84194. +uint32_t dwc_otg_pcd_is_dualspeed(dwc_otg_pcd_t * pcd)
  84195. +{
  84196. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84197. +
  84198. + if ((core_if->core_params->speed == DWC_SPEED_PARAM_FULL) ||
  84199. + ((core_if->hwcfg2.b.hs_phy_type == 2) &&
  84200. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  84201. + (core_if->core_params->ulpi_fs_ls))) {
  84202. + return 0;
  84203. + }
  84204. +
  84205. + return 1;
  84206. +}
  84207. +
  84208. +/**
  84209. + * Returns whether registered pcd is OTG capable or not
  84210. + */
  84211. +uint32_t dwc_otg_pcd_is_otg(dwc_otg_pcd_t * pcd)
  84212. +{
  84213. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84214. + gusbcfg_data_t usbcfg = {.d32 = 0 };
  84215. +
  84216. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  84217. + if (!usbcfg.b.srpcap || !usbcfg.b.hnpcap) {
  84218. + return 0;
  84219. + }
  84220. +
  84221. + return 1;
  84222. +}
  84223. +
  84224. +/**
  84225. + * This function assigns periodic Tx FIFO to an periodic EP
  84226. + * in shared Tx FIFO mode
  84227. + */
  84228. +static uint32_t assign_tx_fifo(dwc_otg_core_if_t * core_if)
  84229. +{
  84230. + uint32_t TxMsk = 1;
  84231. + int i;
  84232. +
  84233. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; ++i) {
  84234. + if ((TxMsk & core_if->tx_msk) == 0) {
  84235. + core_if->tx_msk |= TxMsk;
  84236. + return i + 1;
  84237. + }
  84238. + TxMsk <<= 1;
  84239. + }
  84240. + return 0;
  84241. +}
  84242. +
  84243. +/**
  84244. + * This function assigns periodic Tx FIFO to an periodic EP
  84245. + * in shared Tx FIFO mode
  84246. + */
  84247. +static uint32_t assign_perio_tx_fifo(dwc_otg_core_if_t * core_if)
  84248. +{
  84249. + uint32_t PerTxMsk = 1;
  84250. + int i;
  84251. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; ++i) {
  84252. + if ((PerTxMsk & core_if->p_tx_msk) == 0) {
  84253. + core_if->p_tx_msk |= PerTxMsk;
  84254. + return i + 1;
  84255. + }
  84256. + PerTxMsk <<= 1;
  84257. + }
  84258. + return 0;
  84259. +}
  84260. +
  84261. +/**
  84262. + * This function releases periodic Tx FIFO
  84263. + * in shared Tx FIFO mode
  84264. + */
  84265. +static void release_perio_tx_fifo(dwc_otg_core_if_t * core_if,
  84266. + uint32_t fifo_num)
  84267. +{
  84268. + core_if->p_tx_msk =
  84269. + (core_if->p_tx_msk & (1 << (fifo_num - 1))) ^ core_if->p_tx_msk;
  84270. +}
  84271. +
  84272. +/**
  84273. + * This function releases periodic Tx FIFO
  84274. + * in shared Tx FIFO mode
  84275. + */
  84276. +static void release_tx_fifo(dwc_otg_core_if_t * core_if, uint32_t fifo_num)
  84277. +{
  84278. + core_if->tx_msk =
  84279. + (core_if->tx_msk & (1 << (fifo_num - 1))) ^ core_if->tx_msk;
  84280. +}
  84281. +
  84282. +/**
  84283. + * This function is being called from gadget
  84284. + * to enable PCD endpoint.
  84285. + */
  84286. +int dwc_otg_pcd_ep_enable(dwc_otg_pcd_t * pcd,
  84287. + const uint8_t * ep_desc, void *usb_ep)
  84288. +{
  84289. + int num, dir;
  84290. + dwc_otg_pcd_ep_t *ep = NULL;
  84291. + const usb_endpoint_descriptor_t *desc;
  84292. + dwc_irqflags_t flags;
  84293. + fifosize_data_t dptxfsiz = {.d32 = 0 };
  84294. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  84295. + gdfifocfg_data_t gdfifocfgbase = {.d32 = 0 };
  84296. + int retval = 0;
  84297. + int i, epcount;
  84298. +
  84299. + desc = (const usb_endpoint_descriptor_t *)ep_desc;
  84300. +
  84301. + if (!desc) {
  84302. + pcd->ep0.priv = usb_ep;
  84303. + ep = &pcd->ep0;
  84304. + retval = -DWC_E_INVALID;
  84305. + goto out;
  84306. + }
  84307. +
  84308. + num = UE_GET_ADDR(desc->bEndpointAddress);
  84309. + dir = UE_GET_DIR(desc->bEndpointAddress);
  84310. +
  84311. + if (!desc->wMaxPacketSize) {
  84312. + DWC_WARN("bad maxpacketsize\n");
  84313. + retval = -DWC_E_INVALID;
  84314. + goto out;
  84315. + }
  84316. +
  84317. + if (dir == UE_DIR_IN) {
  84318. + epcount = pcd->core_if->dev_if->num_in_eps;
  84319. + for (i = 0; i < epcount; i++) {
  84320. + if (num == pcd->in_ep[i].dwc_ep.num) {
  84321. + ep = &pcd->in_ep[i];
  84322. + break;
  84323. + }
  84324. + }
  84325. + } else {
  84326. + epcount = pcd->core_if->dev_if->num_out_eps;
  84327. + for (i = 0; i < epcount; i++) {
  84328. + if (num == pcd->out_ep[i].dwc_ep.num) {
  84329. + ep = &pcd->out_ep[i];
  84330. + break;
  84331. + }
  84332. + }
  84333. + }
  84334. +
  84335. + if (!ep) {
  84336. + DWC_WARN("bad address\n");
  84337. + retval = -DWC_E_INVALID;
  84338. + goto out;
  84339. + }
  84340. +
  84341. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  84342. +
  84343. + ep->desc = desc;
  84344. + ep->priv = usb_ep;
  84345. +
  84346. + /*
  84347. + * Activate the EP
  84348. + */
  84349. + ep->stopped = 0;
  84350. +
  84351. + ep->dwc_ep.is_in = (dir == UE_DIR_IN);
  84352. + ep->dwc_ep.maxpacket = UGETW(desc->wMaxPacketSize);
  84353. +
  84354. + ep->dwc_ep.type = desc->bmAttributes & UE_XFERTYPE;
  84355. +
  84356. + if (ep->dwc_ep.is_in) {
  84357. + if (!GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  84358. + ep->dwc_ep.tx_fifo_num = 0;
  84359. +
  84360. + if (ep->dwc_ep.type == UE_ISOCHRONOUS) {
  84361. + /*
  84362. + * if ISOC EP then assign a Periodic Tx FIFO.
  84363. + */
  84364. + ep->dwc_ep.tx_fifo_num =
  84365. + assign_perio_tx_fifo(GET_CORE_IF(pcd));
  84366. + }
  84367. + } else {
  84368. + /*
  84369. + * if Dedicated FIFOs mode is on then assign a Tx FIFO.
  84370. + */
  84371. + ep->dwc_ep.tx_fifo_num =
  84372. + assign_tx_fifo(GET_CORE_IF(pcd));
  84373. + }
  84374. +
  84375. + /* Calculating EP info controller base address */
  84376. + if (ep->dwc_ep.tx_fifo_num
  84377. + && GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  84378. + gdfifocfg.d32 =
  84379. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  84380. + core_global_regs->gdfifocfg);
  84381. + gdfifocfgbase.d32 = gdfifocfg.d32 >> 16;
  84382. + dptxfsiz.d32 =
  84383. + (DWC_READ_REG32
  84384. + (&GET_CORE_IF(pcd)->core_global_regs->
  84385. + dtxfsiz[ep->dwc_ep.tx_fifo_num - 1]) >> 16);
  84386. + gdfifocfg.b.epinfobase =
  84387. + gdfifocfgbase.d32 + dptxfsiz.d32;
  84388. + if (GET_CORE_IF(pcd)->snpsid <= OTG_CORE_REV_2_94a) {
  84389. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->
  84390. + core_global_regs->gdfifocfg,
  84391. + gdfifocfg.d32);
  84392. + }
  84393. + }
  84394. + }
  84395. + /* Set initial data PID. */
  84396. + if (ep->dwc_ep.type == UE_BULK) {
  84397. + ep->dwc_ep.data_pid_start = 0;
  84398. + }
  84399. +
  84400. + /* Alloc DMA Descriptors */
  84401. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  84402. +#ifndef DWC_UTE_PER_IO
  84403. + if (ep->dwc_ep.type != UE_ISOCHRONOUS) {
  84404. +#endif
  84405. + ep->dwc_ep.desc_addr =
  84406. + dwc_otg_ep_alloc_desc_chain(&ep->
  84407. + dwc_ep.dma_desc_addr,
  84408. + MAX_DMA_DESC_CNT);
  84409. + if (!ep->dwc_ep.desc_addr) {
  84410. + DWC_WARN("%s, can't allocate DMA descriptor\n",
  84411. + __func__);
  84412. + retval = -DWC_E_SHUTDOWN;
  84413. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84414. + goto out;
  84415. + }
  84416. +#ifndef DWC_UTE_PER_IO
  84417. + }
  84418. +#endif
  84419. + }
  84420. +
  84421. + DWC_DEBUGPL(DBG_PCD, "Activate %s: type=%d, mps=%d desc=%p\n",
  84422. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  84423. + ep->dwc_ep.type, ep->dwc_ep.maxpacket, ep->desc);
  84424. +#ifdef DWC_UTE_PER_IO
  84425. + ep->dwc_ep.xiso_bInterval = 1 << (ep->desc->bInterval - 1);
  84426. +#endif
  84427. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  84428. + ep->dwc_ep.bInterval = 1 << (ep->desc->bInterval - 1);
  84429. + ep->dwc_ep.frame_num = 0xFFFFFFFF;
  84430. + }
  84431. +
  84432. + dwc_otg_ep_activate(GET_CORE_IF(pcd), &ep->dwc_ep);
  84433. +
  84434. +#ifdef DWC_UTE_CFI
  84435. + if (pcd->cfi->ops.ep_enable) {
  84436. + pcd->cfi->ops.ep_enable(pcd->cfi, pcd, ep);
  84437. + }
  84438. +#endif
  84439. +
  84440. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84441. +
  84442. +out:
  84443. + return retval;
  84444. +}
  84445. +
  84446. +/**
  84447. + * This function is being called from gadget
  84448. + * to disable PCD endpoint.
  84449. + */
  84450. +int dwc_otg_pcd_ep_disable(dwc_otg_pcd_t * pcd, void *ep_handle)
  84451. +{
  84452. + dwc_otg_pcd_ep_t *ep;
  84453. + dwc_irqflags_t flags;
  84454. + dwc_otg_dev_dma_desc_t *desc_addr;
  84455. + dwc_dma_t dma_desc_addr;
  84456. + gdfifocfg_data_t gdfifocfgbase = {.d32 = 0 };
  84457. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  84458. + fifosize_data_t dptxfsiz = {.d32 = 0 };
  84459. +
  84460. + ep = get_ep_from_handle(pcd, ep_handle);
  84461. +
  84462. + if (!ep || !ep->desc) {
  84463. + DWC_DEBUGPL(DBG_PCD, "bad ep address\n");
  84464. + return -DWC_E_INVALID;
  84465. + }
  84466. +
  84467. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  84468. +
  84469. + dwc_otg_request_nuke(ep);
  84470. +
  84471. + dwc_otg_ep_deactivate(GET_CORE_IF(pcd), &ep->dwc_ep);
  84472. + if (pcd->core_if->core_params->dev_out_nak) {
  84473. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[ep->dwc_ep.num]);
  84474. + pcd->core_if->ep_xfer_info[ep->dwc_ep.num].state = 0;
  84475. + }
  84476. + ep->desc = NULL;
  84477. + ep->stopped = 1;
  84478. +
  84479. + gdfifocfg.d32 =
  84480. + DWC_READ_REG32(&GET_CORE_IF(pcd)->core_global_regs->gdfifocfg);
  84481. + gdfifocfgbase.d32 = gdfifocfg.d32 >> 16;
  84482. +
  84483. + if (ep->dwc_ep.is_in) {
  84484. + if (GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  84485. + /* Flush the Tx FIFO */
  84486. + dwc_otg_flush_tx_fifo(GET_CORE_IF(pcd),
  84487. + ep->dwc_ep.tx_fifo_num);
  84488. + }
  84489. + release_perio_tx_fifo(GET_CORE_IF(pcd), ep->dwc_ep.tx_fifo_num);
  84490. + release_tx_fifo(GET_CORE_IF(pcd), ep->dwc_ep.tx_fifo_num);
  84491. + if (GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  84492. + /* Decreasing EPinfo Base Addr */
  84493. + dptxfsiz.d32 =
  84494. + (DWC_READ_REG32
  84495. + (&GET_CORE_IF(pcd)->
  84496. + core_global_regs->dtxfsiz[ep->dwc_ep.tx_fifo_num-1]) >> 16);
  84497. + gdfifocfg.b.epinfobase = gdfifocfgbase.d32 - dptxfsiz.d32;
  84498. + if (GET_CORE_IF(pcd)->snpsid <= OTG_CORE_REV_2_94a) {
  84499. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gdfifocfg,
  84500. + gdfifocfg.d32);
  84501. + }
  84502. + }
  84503. + }
  84504. +
  84505. + /* Free DMA Descriptors */
  84506. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  84507. + if (ep->dwc_ep.type != UE_ISOCHRONOUS) {
  84508. + desc_addr = ep->dwc_ep.desc_addr;
  84509. + dma_desc_addr = ep->dwc_ep.dma_desc_addr;
  84510. +
  84511. + /* Cannot call dma_free_coherent() with IRQs disabled */
  84512. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84513. + dwc_otg_ep_free_desc_chain(desc_addr, dma_desc_addr,
  84514. + MAX_DMA_DESC_CNT);
  84515. +
  84516. + goto out_unlocked;
  84517. + }
  84518. + }
  84519. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84520. +
  84521. +out_unlocked:
  84522. + DWC_DEBUGPL(DBG_PCD, "%d %s disabled\n", ep->dwc_ep.num,
  84523. + ep->dwc_ep.is_in ? "IN" : "OUT");
  84524. + return 0;
  84525. +
  84526. +}
  84527. +
  84528. +/******************************************************************************/
  84529. +#ifdef DWC_UTE_PER_IO
  84530. +
  84531. +/**
  84532. + * Free the request and its extended parts
  84533. + *
  84534. + */
  84535. +void dwc_pcd_xiso_ereq_free(dwc_otg_pcd_ep_t * ep, dwc_otg_pcd_request_t * req)
  84536. +{
  84537. + DWC_FREE(req->ext_req.per_io_frame_descs);
  84538. + DWC_FREE(req);
  84539. +}
  84540. +
  84541. +/**
  84542. + * Start the next request in the endpoint's queue.
  84543. + *
  84544. + */
  84545. +int dwc_otg_pcd_xiso_start_next_request(dwc_otg_pcd_t * pcd,
  84546. + dwc_otg_pcd_ep_t * ep)
  84547. +{
  84548. + int i;
  84549. + dwc_otg_pcd_request_t *req = NULL;
  84550. + dwc_ep_t *dwcep = NULL;
  84551. + struct dwc_iso_xreq_port *ereq = NULL;
  84552. + struct dwc_iso_pkt_desc_port *ddesc_iso;
  84553. + uint16_t nat;
  84554. + depctl_data_t diepctl;
  84555. +
  84556. + dwcep = &ep->dwc_ep;
  84557. +
  84558. + if (dwcep->xiso_active_xfers > 0) {
  84559. +#if 0 //Disable this to decrease s/w overhead that is crucial for Isoc transfers
  84560. + DWC_WARN("There are currently active transfers for EP%d \
  84561. + (active=%d; queued=%d)", dwcep->num, dwcep->xiso_active_xfers,
  84562. + dwcep->xiso_queued_xfers);
  84563. +#endif
  84564. + return 0;
  84565. + }
  84566. +
  84567. + nat = UGETW(ep->desc->wMaxPacketSize);
  84568. + nat = (nat >> 11) & 0x03;
  84569. +
  84570. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  84571. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  84572. + ereq = &req->ext_req;
  84573. + ep->stopped = 0;
  84574. +
  84575. + /* Get the frame number */
  84576. + dwcep->xiso_frame_num =
  84577. + dwc_otg_get_frame_number(GET_CORE_IF(pcd));
  84578. + DWC_DEBUG("FRM_NUM=%d", dwcep->xiso_frame_num);
  84579. +
  84580. + ddesc_iso = ereq->per_io_frame_descs;
  84581. +
  84582. + if (dwcep->is_in) {
  84583. + /* Setup DMA Descriptor chain for IN Isoc request */
  84584. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  84585. + //if ((i % (nat + 1)) == 0)
  84586. + if ( i > 0 )
  84587. + dwcep->xiso_frame_num =
  84588. + (dwcep->xiso_bInterval +
  84589. + dwcep->xiso_frame_num) & 0x3FFF;
  84590. + dwcep->desc_addr[i].buf =
  84591. + req->dma + ddesc_iso[i].offset;
  84592. + dwcep->desc_addr[i].status.b_iso_in.txbytes =
  84593. + ddesc_iso[i].length;
  84594. + dwcep->desc_addr[i].status.b_iso_in.framenum =
  84595. + dwcep->xiso_frame_num;
  84596. + dwcep->desc_addr[i].status.b_iso_in.bs =
  84597. + BS_HOST_READY;
  84598. + dwcep->desc_addr[i].status.b_iso_in.txsts = 0;
  84599. + dwcep->desc_addr[i].status.b_iso_in.sp =
  84600. + (ddesc_iso[i].length %
  84601. + dwcep->maxpacket) ? 1 : 0;
  84602. + dwcep->desc_addr[i].status.b_iso_in.ioc = 0;
  84603. + dwcep->desc_addr[i].status.b_iso_in.pid = nat + 1;
  84604. + dwcep->desc_addr[i].status.b_iso_in.l = 0;
  84605. +
  84606. + /* Process the last descriptor */
  84607. + if (i == ereq->pio_pkt_count - 1) {
  84608. + dwcep->desc_addr[i].status.b_iso_in.ioc = 1;
  84609. + dwcep->desc_addr[i].status.b_iso_in.l = 1;
  84610. + }
  84611. + }
  84612. +
  84613. + /* Setup and start the transfer for this endpoint */
  84614. + dwcep->xiso_active_xfers++;
  84615. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->dev_if->
  84616. + in_ep_regs[dwcep->num]->diepdma,
  84617. + dwcep->dma_desc_addr);
  84618. + diepctl.d32 = 0;
  84619. + diepctl.b.epena = 1;
  84620. + diepctl.b.cnak = 1;
  84621. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->dev_if->
  84622. + in_ep_regs[dwcep->num]->diepctl, 0,
  84623. + diepctl.d32);
  84624. + } else {
  84625. + /* Setup DMA Descriptor chain for OUT Isoc request */
  84626. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  84627. + //if ((i % (nat + 1)) == 0)
  84628. + dwcep->xiso_frame_num = (dwcep->xiso_bInterval +
  84629. + dwcep->xiso_frame_num) & 0x3FFF;
  84630. + dwcep->desc_addr[i].buf =
  84631. + req->dma + ddesc_iso[i].offset;
  84632. + dwcep->desc_addr[i].status.b_iso_out.rxbytes =
  84633. + ddesc_iso[i].length;
  84634. + dwcep->desc_addr[i].status.b_iso_out.framenum =
  84635. + dwcep->xiso_frame_num;
  84636. + dwcep->desc_addr[i].status.b_iso_out.bs =
  84637. + BS_HOST_READY;
  84638. + dwcep->desc_addr[i].status.b_iso_out.rxsts = 0;
  84639. + dwcep->desc_addr[i].status.b_iso_out.sp =
  84640. + (ddesc_iso[i].length %
  84641. + dwcep->maxpacket) ? 1 : 0;
  84642. + dwcep->desc_addr[i].status.b_iso_out.ioc = 0;
  84643. + dwcep->desc_addr[i].status.b_iso_out.pid = nat + 1;
  84644. + dwcep->desc_addr[i].status.b_iso_out.l = 0;
  84645. +
  84646. + /* Process the last descriptor */
  84647. + if (i == ereq->pio_pkt_count - 1) {
  84648. + dwcep->desc_addr[i].status.b_iso_out.ioc = 1;
  84649. + dwcep->desc_addr[i].status.b_iso_out.l = 1;
  84650. + }
  84651. + }
  84652. +
  84653. + /* Setup and start the transfer for this endpoint */
  84654. + dwcep->xiso_active_xfers++;
  84655. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->
  84656. + dev_if->out_ep_regs[dwcep->num]->
  84657. + doepdma, dwcep->dma_desc_addr);
  84658. + diepctl.d32 = 0;
  84659. + diepctl.b.epena = 1;
  84660. + diepctl.b.cnak = 1;
  84661. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  84662. + dev_if->out_ep_regs[dwcep->num]->
  84663. + doepctl, 0, diepctl.d32);
  84664. + }
  84665. +
  84666. + } else {
  84667. + ep->stopped = 1;
  84668. + }
  84669. +
  84670. + return 0;
  84671. +}
  84672. +
  84673. +/**
  84674. + * - Remove the request from the queue
  84675. + */
  84676. +void complete_xiso_ep(dwc_otg_pcd_ep_t * ep)
  84677. +{
  84678. + dwc_otg_pcd_request_t *req = NULL;
  84679. + struct dwc_iso_xreq_port *ereq = NULL;
  84680. + struct dwc_iso_pkt_desc_port *ddesc_iso = NULL;
  84681. + dwc_ep_t *dwcep = NULL;
  84682. + int i;
  84683. +
  84684. + //DWC_DEBUG();
  84685. + dwcep = &ep->dwc_ep;
  84686. +
  84687. + /* Get the first pending request from the queue */
  84688. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  84689. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  84690. + if (!req) {
  84691. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  84692. + return;
  84693. + }
  84694. + dwcep->xiso_active_xfers--;
  84695. + dwcep->xiso_queued_xfers--;
  84696. + /* Remove this request from the queue */
  84697. + DWC_CIRCLEQ_REMOVE_INIT(&ep->queue, req, queue_entry);
  84698. + } else {
  84699. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  84700. + return;
  84701. + }
  84702. +
  84703. + ep->stopped = 1;
  84704. + ereq = &req->ext_req;
  84705. + ddesc_iso = ereq->per_io_frame_descs;
  84706. +
  84707. + if (dwcep->xiso_active_xfers < 0) {
  84708. + DWC_WARN("EP#%d (xiso_active_xfers=%d)", dwcep->num,
  84709. + dwcep->xiso_active_xfers);
  84710. + }
  84711. +
  84712. + /* Fill the Isoc descs of portable extended req from dma descriptors */
  84713. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  84714. + if (dwcep->is_in) { /* IN endpoints */
  84715. + ddesc_iso[i].actual_length = ddesc_iso[i].length -
  84716. + dwcep->desc_addr[i].status.b_iso_in.txbytes;
  84717. + ddesc_iso[i].status =
  84718. + dwcep->desc_addr[i].status.b_iso_in.txsts;
  84719. + } else { /* OUT endpoints */
  84720. + ddesc_iso[i].actual_length = ddesc_iso[i].length -
  84721. + dwcep->desc_addr[i].status.b_iso_out.rxbytes;
  84722. + ddesc_iso[i].status =
  84723. + dwcep->desc_addr[i].status.b_iso_out.rxsts;
  84724. + }
  84725. + }
  84726. +
  84727. + DWC_SPINUNLOCK(ep->pcd->lock);
  84728. +
  84729. + /* Call the completion function in the non-portable logic */
  84730. + ep->pcd->fops->xisoc_complete(ep->pcd, ep->priv, req->priv, 0,
  84731. + &req->ext_req);
  84732. +
  84733. + DWC_SPINLOCK(ep->pcd->lock);
  84734. +
  84735. + /* Free the request - specific freeing needed for extended request object */
  84736. + dwc_pcd_xiso_ereq_free(ep, req);
  84737. +
  84738. + /* Start the next request */
  84739. + dwc_otg_pcd_xiso_start_next_request(ep->pcd, ep);
  84740. +
  84741. + return;
  84742. +}
  84743. +
  84744. +/**
  84745. + * Create and initialize the Isoc pkt descriptors of the extended request.
  84746. + *
  84747. + */
  84748. +static int dwc_otg_pcd_xiso_create_pkt_descs(dwc_otg_pcd_request_t * req,
  84749. + void *ereq_nonport,
  84750. + int atomic_alloc)
  84751. +{
  84752. + struct dwc_iso_xreq_port *ereq = NULL;
  84753. + struct dwc_iso_xreq_port *req_mapped = NULL;
  84754. + struct dwc_iso_pkt_desc_port *ipds = NULL; /* To be created in this function */
  84755. + uint32_t pkt_count;
  84756. + int i;
  84757. +
  84758. + ereq = &req->ext_req;
  84759. + req_mapped = (struct dwc_iso_xreq_port *)ereq_nonport;
  84760. + pkt_count = req_mapped->pio_pkt_count;
  84761. +
  84762. + /* Create the isoc descs */
  84763. + if (atomic_alloc) {
  84764. + ipds = DWC_ALLOC_ATOMIC(sizeof(*ipds) * pkt_count);
  84765. + } else {
  84766. + ipds = DWC_ALLOC(sizeof(*ipds) * pkt_count);
  84767. + }
  84768. +
  84769. + if (!ipds) {
  84770. + DWC_ERROR("Failed to allocate isoc descriptors");
  84771. + return -DWC_E_NO_MEMORY;
  84772. + }
  84773. +
  84774. + /* Initialize the extended request fields */
  84775. + ereq->per_io_frame_descs = ipds;
  84776. + ereq->error_count = 0;
  84777. + ereq->pio_alloc_pkt_count = pkt_count;
  84778. + ereq->pio_pkt_count = pkt_count;
  84779. + ereq->tr_sub_flags = req_mapped->tr_sub_flags;
  84780. +
  84781. + /* Init the Isoc descriptors */
  84782. + for (i = 0; i < pkt_count; i++) {
  84783. + ipds[i].length = req_mapped->per_io_frame_descs[i].length;
  84784. + ipds[i].offset = req_mapped->per_io_frame_descs[i].offset;
  84785. + ipds[i].status = req_mapped->per_io_frame_descs[i].status; /* 0 */
  84786. + ipds[i].actual_length =
  84787. + req_mapped->per_io_frame_descs[i].actual_length;
  84788. + }
  84789. +
  84790. + return 0;
  84791. +}
  84792. +
  84793. +static void prn_ext_request(struct dwc_iso_xreq_port *ereq)
  84794. +{
  84795. + struct dwc_iso_pkt_desc_port *xfd = NULL;
  84796. + int i;
  84797. +
  84798. + DWC_DEBUG("per_io_frame_descs=%p", ereq->per_io_frame_descs);
  84799. + DWC_DEBUG("tr_sub_flags=%d", ereq->tr_sub_flags);
  84800. + DWC_DEBUG("error_count=%d", ereq->error_count);
  84801. + DWC_DEBUG("pio_alloc_pkt_count=%d", ereq->pio_alloc_pkt_count);
  84802. + DWC_DEBUG("pio_pkt_count=%d", ereq->pio_pkt_count);
  84803. + DWC_DEBUG("res=%d", ereq->res);
  84804. +
  84805. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  84806. + xfd = &ereq->per_io_frame_descs[0];
  84807. + DWC_DEBUG("FD #%d", i);
  84808. +
  84809. + DWC_DEBUG("xfd->actual_length=%d", xfd->actual_length);
  84810. + DWC_DEBUG("xfd->length=%d", xfd->length);
  84811. + DWC_DEBUG("xfd->offset=%d", xfd->offset);
  84812. + DWC_DEBUG("xfd->status=%d", xfd->status);
  84813. + }
  84814. +}
  84815. +
  84816. +/**
  84817. + *
  84818. + */
  84819. +int dwc_otg_pcd_xiso_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  84820. + uint8_t * buf, dwc_dma_t dma_buf, uint32_t buflen,
  84821. + int zero, void *req_handle, int atomic_alloc,
  84822. + void *ereq_nonport)
  84823. +{
  84824. + dwc_otg_pcd_request_t *req = NULL;
  84825. + dwc_otg_pcd_ep_t *ep;
  84826. + dwc_irqflags_t flags;
  84827. + int res;
  84828. +
  84829. + ep = get_ep_from_handle(pcd, ep_handle);
  84830. + if (!ep) {
  84831. + DWC_WARN("bad ep\n");
  84832. + return -DWC_E_INVALID;
  84833. + }
  84834. +
  84835. + /* We support this extension only for DDMA mode */
  84836. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC)
  84837. + if (!GET_CORE_IF(pcd)->dma_desc_enable)
  84838. + return -DWC_E_INVALID;
  84839. +
  84840. + /* Create a dwc_otg_pcd_request_t object */
  84841. + if (atomic_alloc) {
  84842. + req = DWC_ALLOC_ATOMIC(sizeof(*req));
  84843. + } else {
  84844. + req = DWC_ALLOC(sizeof(*req));
  84845. + }
  84846. +
  84847. + if (!req) {
  84848. + return -DWC_E_NO_MEMORY;
  84849. + }
  84850. +
  84851. + /* Create the Isoc descs for this request which shall be the exact match
  84852. + * of the structure sent to us from the non-portable logic */
  84853. + res =
  84854. + dwc_otg_pcd_xiso_create_pkt_descs(req, ereq_nonport, atomic_alloc);
  84855. + if (res) {
  84856. + DWC_WARN("Failed to init the Isoc descriptors");
  84857. + DWC_FREE(req);
  84858. + return res;
  84859. + }
  84860. +
  84861. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  84862. +
  84863. + DWC_CIRCLEQ_INIT_ENTRY(req, queue_entry);
  84864. + req->buf = buf;
  84865. + req->dma = dma_buf;
  84866. + req->length = buflen;
  84867. + req->sent_zlp = zero;
  84868. + req->priv = req_handle;
  84869. +
  84870. + //DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  84871. + ep->dwc_ep.dma_addr = dma_buf;
  84872. + ep->dwc_ep.start_xfer_buff = buf;
  84873. + ep->dwc_ep.xfer_buff = buf;
  84874. + ep->dwc_ep.xfer_len = 0;
  84875. + ep->dwc_ep.xfer_count = 0;
  84876. + ep->dwc_ep.sent_zlp = 0;
  84877. + ep->dwc_ep.total_len = buflen;
  84878. +
  84879. + /* Add this request to the tail */
  84880. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  84881. + ep->dwc_ep.xiso_queued_xfers++;
  84882. +
  84883. +//DWC_DEBUG("CP_0");
  84884. +//DWC_DEBUG("req->ext_req.tr_sub_flags=%d", req->ext_req.tr_sub_flags);
  84885. +//prn_ext_request((struct dwc_iso_xreq_port *) ereq_nonport);
  84886. +//prn_ext_request(&req->ext_req);
  84887. +
  84888. + //DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84889. +
  84890. + /* If the req->status == ASAP then check if there is any active transfer
  84891. + * for this endpoint. If no active transfers, then get the first entry
  84892. + * from the queue and start that transfer
  84893. + */
  84894. + if (req->ext_req.tr_sub_flags == DWC_EREQ_TF_ASAP) {
  84895. + res = dwc_otg_pcd_xiso_start_next_request(pcd, ep);
  84896. + if (res) {
  84897. + DWC_WARN("Failed to start the next Isoc transfer");
  84898. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84899. + DWC_FREE(req);
  84900. + return res;
  84901. + }
  84902. + }
  84903. +
  84904. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84905. + return 0;
  84906. +}
  84907. +
  84908. +#endif
  84909. +/* END ifdef DWC_UTE_PER_IO ***************************************************/
  84910. +int dwc_otg_pcd_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  84911. + uint8_t * buf, dwc_dma_t dma_buf, uint32_t buflen,
  84912. + int zero, void *req_handle, int atomic_alloc)
  84913. +{
  84914. + dwc_irqflags_t flags;
  84915. + dwc_otg_pcd_request_t *req;
  84916. + dwc_otg_pcd_ep_t *ep;
  84917. + uint32_t max_transfer;
  84918. +
  84919. + ep = get_ep_from_handle(pcd, ep_handle);
  84920. + if (!ep || (!ep->desc && ep->dwc_ep.num != 0)) {
  84921. + DWC_WARN("bad ep\n");
  84922. + return -DWC_E_INVALID;
  84923. + }
  84924. +
  84925. + if (atomic_alloc) {
  84926. + req = DWC_ALLOC_ATOMIC(sizeof(*req));
  84927. + } else {
  84928. + req = DWC_ALLOC(sizeof(*req));
  84929. + }
  84930. +
  84931. + if (!req) {
  84932. + return -DWC_E_NO_MEMORY;
  84933. + }
  84934. + DWC_CIRCLEQ_INIT_ENTRY(req, queue_entry);
  84935. + if (!GET_CORE_IF(pcd)->core_params->opt) {
  84936. + if (ep->dwc_ep.num != 0) {
  84937. + DWC_ERROR("queue req %p, len %d buf %p\n",
  84938. + req_handle, buflen, buf);
  84939. + }
  84940. + }
  84941. +
  84942. + req->buf = buf;
  84943. + req->dma = dma_buf;
  84944. + req->length = buflen;
  84945. + req->sent_zlp = zero;
  84946. + req->priv = req_handle;
  84947. + req->dw_align_buf = NULL;
  84948. + if ((dma_buf & 0x3) && GET_CORE_IF(pcd)->dma_enable
  84949. + && !GET_CORE_IF(pcd)->dma_desc_enable)
  84950. + req->dw_align_buf = DWC_DMA_ALLOC(buflen,
  84951. + &req->dw_align_buf_dma);
  84952. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  84953. +
  84954. + /*
  84955. + * After adding request to the queue for IN ISOC wait for In Token Received
  84956. + * when TX FIFO is empty interrupt and for OUT ISOC wait for OUT Token
  84957. + * Received when EP is disabled interrupt to obtain starting microframe
  84958. + * (odd/even) start transfer
  84959. + */
  84960. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  84961. + if (req != 0) {
  84962. + depctl_data_t depctl = {.d32 =
  84963. + DWC_READ_REG32(&pcd->core_if->dev_if->
  84964. + in_ep_regs[ep->dwc_ep.num]->
  84965. + diepctl) };
  84966. + ++pcd->request_pending;
  84967. +
  84968. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  84969. + if (ep->dwc_ep.is_in) {
  84970. + depctl.b.cnak = 1;
  84971. + DWC_WRITE_REG32(&pcd->core_if->dev_if->
  84972. + in_ep_regs[ep->dwc_ep.num]->
  84973. + diepctl, depctl.d32);
  84974. + }
  84975. +
  84976. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84977. + }
  84978. + return 0;
  84979. + }
  84980. +
  84981. + /*
  84982. + * For EP0 IN without premature status, zlp is required?
  84983. + */
  84984. + if (ep->dwc_ep.num == 0 && ep->dwc_ep.is_in) {
  84985. + DWC_DEBUGPL(DBG_PCDV, "%d-OUT ZLP\n", ep->dwc_ep.num);
  84986. + //_req->zero = 1;
  84987. + }
  84988. +
  84989. + /* Start the transfer */
  84990. + if (DWC_CIRCLEQ_EMPTY(&ep->queue) && !ep->stopped) {
  84991. + /* EP0 Transfer? */
  84992. + if (ep->dwc_ep.num == 0) {
  84993. + switch (pcd->ep0state) {
  84994. + case EP0_IN_DATA_PHASE:
  84995. + DWC_DEBUGPL(DBG_PCD,
  84996. + "%s ep0: EP0_IN_DATA_PHASE\n",
  84997. + __func__);
  84998. + break;
  84999. +
  85000. + case EP0_OUT_DATA_PHASE:
  85001. + DWC_DEBUGPL(DBG_PCD,
  85002. + "%s ep0: EP0_OUT_DATA_PHASE\n",
  85003. + __func__);
  85004. + if (pcd->request_config) {
  85005. + /* Complete STATUS PHASE */
  85006. + ep->dwc_ep.is_in = 1;
  85007. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  85008. + }
  85009. + break;
  85010. +
  85011. + case EP0_IN_STATUS_PHASE:
  85012. + DWC_DEBUGPL(DBG_PCD,
  85013. + "%s ep0: EP0_IN_STATUS_PHASE\n",
  85014. + __func__);
  85015. + break;
  85016. +
  85017. + default:
  85018. + DWC_DEBUGPL(DBG_ANY, "ep0: odd state %d\n",
  85019. + pcd->ep0state);
  85020. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  85021. + return -DWC_E_SHUTDOWN;
  85022. + }
  85023. +
  85024. + ep->dwc_ep.dma_addr = dma_buf;
  85025. + ep->dwc_ep.start_xfer_buff = buf;
  85026. + ep->dwc_ep.xfer_buff = buf;
  85027. + ep->dwc_ep.xfer_len = buflen;
  85028. + ep->dwc_ep.xfer_count = 0;
  85029. + ep->dwc_ep.sent_zlp = 0;
  85030. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  85031. +
  85032. + if (zero) {
  85033. + if ((ep->dwc_ep.xfer_len %
  85034. + ep->dwc_ep.maxpacket == 0)
  85035. + && (ep->dwc_ep.xfer_len != 0)) {
  85036. + ep->dwc_ep.sent_zlp = 1;
  85037. + }
  85038. +
  85039. + }
  85040. +
  85041. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd),
  85042. + &ep->dwc_ep);
  85043. + } // non-ep0 endpoints
  85044. + else {
  85045. +#ifdef DWC_UTE_CFI
  85046. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  85047. + /* store the request length */
  85048. + ep->dwc_ep.cfi_req_len = buflen;
  85049. + pcd->cfi->ops.build_descriptors(pcd->cfi, pcd,
  85050. + ep, req);
  85051. + } else {
  85052. +#endif
  85053. + max_transfer =
  85054. + GET_CORE_IF(ep->pcd)->core_params->
  85055. + max_transfer_size;
  85056. +
  85057. + /* Setup and start the Transfer */
  85058. + if (req->dw_align_buf){
  85059. + if (ep->dwc_ep.is_in)
  85060. + dwc_memcpy(req->dw_align_buf,
  85061. + buf, buflen);
  85062. + ep->dwc_ep.dma_addr =
  85063. + req->dw_align_buf_dma;
  85064. + ep->dwc_ep.start_xfer_buff =
  85065. + req->dw_align_buf;
  85066. + ep->dwc_ep.xfer_buff =
  85067. + req->dw_align_buf;
  85068. + } else {
  85069. + ep->dwc_ep.dma_addr = dma_buf;
  85070. + ep->dwc_ep.start_xfer_buff = buf;
  85071. + ep->dwc_ep.xfer_buff = buf;
  85072. + }
  85073. + ep->dwc_ep.xfer_len = 0;
  85074. + ep->dwc_ep.xfer_count = 0;
  85075. + ep->dwc_ep.sent_zlp = 0;
  85076. + ep->dwc_ep.total_len = buflen;
  85077. +
  85078. + ep->dwc_ep.maxxfer = max_transfer;
  85079. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  85080. + uint32_t out_max_xfer =
  85081. + DDMA_MAX_TRANSFER_SIZE -
  85082. + (DDMA_MAX_TRANSFER_SIZE % 4);
  85083. + if (ep->dwc_ep.is_in) {
  85084. + if (ep->dwc_ep.maxxfer >
  85085. + DDMA_MAX_TRANSFER_SIZE) {
  85086. + ep->dwc_ep.maxxfer =
  85087. + DDMA_MAX_TRANSFER_SIZE;
  85088. + }
  85089. + } else {
  85090. + if (ep->dwc_ep.maxxfer >
  85091. + out_max_xfer) {
  85092. + ep->dwc_ep.maxxfer =
  85093. + out_max_xfer;
  85094. + }
  85095. + }
  85096. + }
  85097. + if (ep->dwc_ep.maxxfer < ep->dwc_ep.total_len) {
  85098. + ep->dwc_ep.maxxfer -=
  85099. + (ep->dwc_ep.maxxfer %
  85100. + ep->dwc_ep.maxpacket);
  85101. + }
  85102. +
  85103. + if (zero) {
  85104. + if ((ep->dwc_ep.total_len %
  85105. + ep->dwc_ep.maxpacket == 0)
  85106. + && (ep->dwc_ep.total_len != 0)) {
  85107. + ep->dwc_ep.sent_zlp = 1;
  85108. + }
  85109. + }
  85110. +#ifdef DWC_UTE_CFI
  85111. + }
  85112. +#endif
  85113. + dwc_otg_ep_start_transfer(GET_CORE_IF(pcd),
  85114. + &ep->dwc_ep);
  85115. + }
  85116. + }
  85117. +
  85118. + if (req != 0) {
  85119. + ++pcd->request_pending;
  85120. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  85121. + if (ep->dwc_ep.is_in && ep->stopped
  85122. + && !(GET_CORE_IF(pcd)->dma_enable)) {
  85123. + /** @todo NGS Create a function for this. */
  85124. + diepmsk_data_t diepmsk = {.d32 = 0 };
  85125. + diepmsk.b.intktxfemp = 1;
  85126. + if (GET_CORE_IF(pcd)->multiproc_int_enable) {
  85127. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  85128. + dev_if->dev_global_regs->diepeachintmsk
  85129. + [ep->dwc_ep.num], 0,
  85130. + diepmsk.d32);
  85131. + } else {
  85132. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  85133. + dev_if->dev_global_regs->
  85134. + diepmsk, 0, diepmsk.d32);
  85135. + }
  85136. +
  85137. + }
  85138. + }
  85139. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  85140. +
  85141. + return 0;
  85142. +}
  85143. +
  85144. +int dwc_otg_pcd_ep_dequeue(dwc_otg_pcd_t * pcd, void *ep_handle,
  85145. + void *req_handle)
  85146. +{
  85147. + dwc_irqflags_t flags;
  85148. + dwc_otg_pcd_request_t *req;
  85149. + dwc_otg_pcd_ep_t *ep;
  85150. +
  85151. + ep = get_ep_from_handle(pcd, ep_handle);
  85152. + if (!ep || (!ep->desc && ep->dwc_ep.num != 0)) {
  85153. + DWC_WARN("bad argument\n");
  85154. + return -DWC_E_INVALID;
  85155. + }
  85156. +
  85157. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  85158. +
  85159. + /* make sure it's actually queued on this endpoint */
  85160. + DWC_CIRCLEQ_FOREACH(req, &ep->queue, queue_entry) {
  85161. + if (req->priv == (void *)req_handle) {
  85162. + break;
  85163. + }
  85164. + }
  85165. +
  85166. + if (req->priv != (void *)req_handle) {
  85167. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  85168. + return -DWC_E_INVALID;
  85169. + }
  85170. +
  85171. + if (!DWC_CIRCLEQ_EMPTY_ENTRY(req, queue_entry)) {
  85172. + dwc_otg_request_done(ep, req, -DWC_E_RESTART);
  85173. + } else {
  85174. + req = NULL;
  85175. + }
  85176. +
  85177. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  85178. +
  85179. + return req ? 0 : -DWC_E_SHUTDOWN;
  85180. +
  85181. +}
  85182. +
  85183. +/**
  85184. + * dwc_otg_pcd_ep_wedge - sets the halt feature and ignores clear requests
  85185. + *
  85186. + * Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT)
  85187. + * requests. If the gadget driver clears the halt status, it will
  85188. + * automatically unwedge the endpoint.
  85189. + *
  85190. + * Returns zero on success, else negative DWC error code.
  85191. + */
  85192. +int dwc_otg_pcd_ep_wedge(dwc_otg_pcd_t * pcd, void *ep_handle)
  85193. +{
  85194. + dwc_otg_pcd_ep_t *ep;
  85195. + dwc_irqflags_t flags;
  85196. + int retval = 0;
  85197. +
  85198. + ep = get_ep_from_handle(pcd, ep_handle);
  85199. +
  85200. + if ((!ep->desc && ep != &pcd->ep0) ||
  85201. + (ep->desc && (ep->desc->bmAttributes == UE_ISOCHRONOUS))) {
  85202. + DWC_WARN("%s, bad ep\n", __func__);
  85203. + return -DWC_E_INVALID;
  85204. + }
  85205. +
  85206. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  85207. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  85208. + DWC_WARN("%d %s XFer In process\n", ep->dwc_ep.num,
  85209. + ep->dwc_ep.is_in ? "IN" : "OUT");
  85210. + retval = -DWC_E_AGAIN;
  85211. + } else {
  85212. + /* This code needs to be reviewed */
  85213. + if (ep->dwc_ep.is_in == 1 && GET_CORE_IF(pcd)->dma_desc_enable) {
  85214. + dtxfsts_data_t txstatus;
  85215. + fifosize_data_t txfifosize;
  85216. +
  85217. + txfifosize.d32 =
  85218. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  85219. + core_global_regs->dtxfsiz[ep->dwc_ep.
  85220. + tx_fifo_num]);
  85221. + txstatus.d32 =
  85222. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  85223. + dev_if->in_ep_regs[ep->dwc_ep.num]->
  85224. + dtxfsts);
  85225. +
  85226. + if (txstatus.b.txfspcavail < txfifosize.b.depth) {
  85227. + DWC_WARN("%s() Data In Tx Fifo\n", __func__);
  85228. + retval = -DWC_E_AGAIN;
  85229. + } else {
  85230. + if (ep->dwc_ep.num == 0) {
  85231. + pcd->ep0state = EP0_STALL;
  85232. + }
  85233. +
  85234. + ep->stopped = 1;
  85235. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd),
  85236. + &ep->dwc_ep);
  85237. + }
  85238. + } else {
  85239. + if (ep->dwc_ep.num == 0) {
  85240. + pcd->ep0state = EP0_STALL;
  85241. + }
  85242. +
  85243. + ep->stopped = 1;
  85244. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  85245. + }
  85246. + }
  85247. +
  85248. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  85249. +
  85250. + return retval;
  85251. +}
  85252. +
  85253. +int dwc_otg_pcd_ep_halt(dwc_otg_pcd_t * pcd, void *ep_handle, int value)
  85254. +{
  85255. + dwc_otg_pcd_ep_t *ep;
  85256. + dwc_irqflags_t flags;
  85257. + int retval = 0;
  85258. +
  85259. + ep = get_ep_from_handle(pcd, ep_handle);
  85260. +
  85261. + if (!ep || (!ep->desc && ep != &pcd->ep0) ||
  85262. + (ep->desc && (ep->desc->bmAttributes == UE_ISOCHRONOUS))) {
  85263. + DWC_WARN("%s, bad ep\n", __func__);
  85264. + return -DWC_E_INVALID;
  85265. + }
  85266. +
  85267. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  85268. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  85269. + DWC_WARN("%d %s XFer In process\n", ep->dwc_ep.num,
  85270. + ep->dwc_ep.is_in ? "IN" : "OUT");
  85271. + retval = -DWC_E_AGAIN;
  85272. + } else if (value == 0) {
  85273. + dwc_otg_ep_clear_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  85274. + } else if (value == 1) {
  85275. + if (ep->dwc_ep.is_in == 1 && GET_CORE_IF(pcd)->dma_desc_enable) {
  85276. + dtxfsts_data_t txstatus;
  85277. + fifosize_data_t txfifosize;
  85278. +
  85279. + txfifosize.d32 =
  85280. + DWC_READ_REG32(&GET_CORE_IF(pcd)->core_global_regs->
  85281. + dtxfsiz[ep->dwc_ep.tx_fifo_num]);
  85282. + txstatus.d32 =
  85283. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  85284. + in_ep_regs[ep->dwc_ep.num]->dtxfsts);
  85285. +
  85286. + if (txstatus.b.txfspcavail < txfifosize.b.depth) {
  85287. + DWC_WARN("%s() Data In Tx Fifo\n", __func__);
  85288. + retval = -DWC_E_AGAIN;
  85289. + } else {
  85290. + if (ep->dwc_ep.num == 0) {
  85291. + pcd->ep0state = EP0_STALL;
  85292. + }
  85293. +
  85294. + ep->stopped = 1;
  85295. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd),
  85296. + &ep->dwc_ep);
  85297. + }
  85298. + } else {
  85299. + if (ep->dwc_ep.num == 0) {
  85300. + pcd->ep0state = EP0_STALL;
  85301. + }
  85302. +
  85303. + ep->stopped = 1;
  85304. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  85305. + }
  85306. + } else if (value == 2) {
  85307. + ep->dwc_ep.stall_clear_flag = 0;
  85308. + } else if (value == 3) {
  85309. + ep->dwc_ep.stall_clear_flag = 1;
  85310. + }
  85311. +
  85312. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  85313. +
  85314. + return retval;
  85315. +}
  85316. +
  85317. +/**
  85318. + * This function initiates remote wakeup of the host from suspend state.
  85319. + */
  85320. +void dwc_otg_pcd_rem_wkup_from_suspend(dwc_otg_pcd_t * pcd, int set)
  85321. +{
  85322. + dctl_data_t dctl = { 0 };
  85323. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85324. + dsts_data_t dsts;
  85325. +
  85326. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  85327. + if (!dsts.b.suspsts) {
  85328. + DWC_WARN("Remote wakeup while is not in suspend state\n");
  85329. + }
  85330. + /* Check if DEVICE_REMOTE_WAKEUP feature enabled */
  85331. + if (pcd->remote_wakeup_enable) {
  85332. + if (set) {
  85333. +
  85334. + if (core_if->adp_enable) {
  85335. + gpwrdn_data_t gpwrdn;
  85336. +
  85337. + dwc_otg_adp_probe_stop(core_if);
  85338. +
  85339. + /* Mask SRP detected interrupt from Power Down Logic */
  85340. + gpwrdn.d32 = 0;
  85341. + gpwrdn.b.srp_det_msk = 1;
  85342. + DWC_MODIFY_REG32(&core_if->
  85343. + core_global_regs->gpwrdn,
  85344. + gpwrdn.d32, 0);
  85345. +
  85346. + /* Disable Power Down Logic */
  85347. + gpwrdn.d32 = 0;
  85348. + gpwrdn.b.pmuactv = 1;
  85349. + DWC_MODIFY_REG32(&core_if->
  85350. + core_global_regs->gpwrdn,
  85351. + gpwrdn.d32, 0);
  85352. +
  85353. + /*
  85354. + * Initialize the Core for Device mode.
  85355. + */
  85356. + core_if->op_state = B_PERIPHERAL;
  85357. + dwc_otg_core_init(core_if);
  85358. + dwc_otg_enable_global_interrupts(core_if);
  85359. + cil_pcd_start(core_if);
  85360. +
  85361. + dwc_otg_initiate_srp(core_if);
  85362. + }
  85363. +
  85364. + dctl.b.rmtwkupsig = 1;
  85365. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  85366. + dctl, 0, dctl.d32);
  85367. + DWC_DEBUGPL(DBG_PCD, "Set Remote Wakeup\n");
  85368. +
  85369. + dwc_mdelay(2);
  85370. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  85371. + dctl, dctl.d32, 0);
  85372. + DWC_DEBUGPL(DBG_PCD, "Clear Remote Wakeup\n");
  85373. + }
  85374. + } else {
  85375. + DWC_DEBUGPL(DBG_PCD, "Remote Wakeup is disabled\n");
  85376. + }
  85377. +}
  85378. +
  85379. +#ifdef CONFIG_USB_DWC_OTG_LPM
  85380. +/**
  85381. + * This function initiates remote wakeup of the host from L1 sleep state.
  85382. + */
  85383. +void dwc_otg_pcd_rem_wkup_from_sleep(dwc_otg_pcd_t * pcd, int set)
  85384. +{
  85385. + glpmcfg_data_t lpmcfg;
  85386. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85387. +
  85388. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  85389. +
  85390. + /* Check if we are in L1 state */
  85391. + if (!lpmcfg.b.prt_sleep_sts) {
  85392. + DWC_DEBUGPL(DBG_PCD, "Device is not in sleep state\n");
  85393. + return;
  85394. + }
  85395. +
  85396. + /* Check if host allows remote wakeup */
  85397. + if (!lpmcfg.b.rem_wkup_en) {
  85398. + DWC_DEBUGPL(DBG_PCD, "Host does not allow remote wakeup\n");
  85399. + return;
  85400. + }
  85401. +
  85402. + /* Check if Resume OK */
  85403. + if (!lpmcfg.b.sleep_state_resumeok) {
  85404. + DWC_DEBUGPL(DBG_PCD, "Sleep state resume is not OK\n");
  85405. + return;
  85406. + }
  85407. +
  85408. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  85409. + lpmcfg.b.en_utmi_sleep = 0;
  85410. + lpmcfg.b.hird_thres &= (~(1 << 4));
  85411. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  85412. +
  85413. + if (set) {
  85414. + dctl_data_t dctl = {.d32 = 0 };
  85415. + dctl.b.rmtwkupsig = 1;
  85416. + /* Set RmtWkUpSig bit to start remote wakup signaling.
  85417. + * Hardware will automatically clear this bit.
  85418. + */
  85419. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl,
  85420. + 0, dctl.d32);
  85421. + DWC_DEBUGPL(DBG_PCD, "Set Remote Wakeup\n");
  85422. + }
  85423. +
  85424. +}
  85425. +#endif
  85426. +
  85427. +/**
  85428. + * Performs remote wakeup.
  85429. + */
  85430. +void dwc_otg_pcd_remote_wakeup(dwc_otg_pcd_t * pcd, int set)
  85431. +{
  85432. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85433. + dwc_irqflags_t flags;
  85434. + if (dwc_otg_is_device_mode(core_if)) {
  85435. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  85436. +#ifdef CONFIG_USB_DWC_OTG_LPM
  85437. + if (core_if->lx_state == DWC_OTG_L1) {
  85438. + dwc_otg_pcd_rem_wkup_from_sleep(pcd, set);
  85439. + } else {
  85440. +#endif
  85441. + dwc_otg_pcd_rem_wkup_from_suspend(pcd, set);
  85442. +#ifdef CONFIG_USB_DWC_OTG_LPM
  85443. + }
  85444. +#endif
  85445. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  85446. + }
  85447. + return;
  85448. +}
  85449. +
  85450. +void dwc_otg_pcd_disconnect_us(dwc_otg_pcd_t * pcd, int no_of_usecs)
  85451. +{
  85452. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85453. + dctl_data_t dctl = { 0 };
  85454. +
  85455. + if (dwc_otg_is_device_mode(core_if)) {
  85456. + dctl.b.sftdiscon = 1;
  85457. + DWC_PRINTF("Soft disconnect for %d useconds\n",no_of_usecs);
  85458. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  85459. + dwc_udelay(no_of_usecs);
  85460. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32,0);
  85461. +
  85462. + } else{
  85463. + DWC_PRINTF("NOT SUPPORTED IN HOST MODE\n");
  85464. + }
  85465. + return;
  85466. +
  85467. +}
  85468. +
  85469. +int dwc_otg_pcd_wakeup(dwc_otg_pcd_t * pcd)
  85470. +{
  85471. + dsts_data_t dsts;
  85472. + gotgctl_data_t gotgctl;
  85473. +
  85474. + /*
  85475. + * This function starts the Protocol if no session is in progress. If
  85476. + * a session is already in progress, but the device is suspended,
  85477. + * remote wakeup signaling is started.
  85478. + */
  85479. +
  85480. + /* Check if valid session */
  85481. + gotgctl.d32 =
  85482. + DWC_READ_REG32(&(GET_CORE_IF(pcd)->core_global_regs->gotgctl));
  85483. + if (gotgctl.b.bsesvld) {
  85484. + /* Check if suspend state */
  85485. + dsts.d32 =
  85486. + DWC_READ_REG32(&
  85487. + (GET_CORE_IF(pcd)->dev_if->
  85488. + dev_global_regs->dsts));
  85489. + if (dsts.b.suspsts) {
  85490. + dwc_otg_pcd_remote_wakeup(pcd, 1);
  85491. + }
  85492. + } else {
  85493. + dwc_otg_pcd_initiate_srp(pcd);
  85494. + }
  85495. +
  85496. + return 0;
  85497. +
  85498. +}
  85499. +
  85500. +/**
  85501. + * Start the SRP timer to detect when the SRP does not complete within
  85502. + * 6 seconds.
  85503. + *
  85504. + * @param pcd the pcd structure.
  85505. + */
  85506. +void dwc_otg_pcd_initiate_srp(dwc_otg_pcd_t * pcd)
  85507. +{
  85508. + dwc_irqflags_t flags;
  85509. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  85510. + dwc_otg_initiate_srp(GET_CORE_IF(pcd));
  85511. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  85512. +}
  85513. +
  85514. +int dwc_otg_pcd_get_frame_number(dwc_otg_pcd_t * pcd)
  85515. +{
  85516. + return dwc_otg_get_frame_number(GET_CORE_IF(pcd));
  85517. +}
  85518. +
  85519. +int dwc_otg_pcd_is_lpm_enabled(dwc_otg_pcd_t * pcd)
  85520. +{
  85521. + return GET_CORE_IF(pcd)->core_params->lpm_enable;
  85522. +}
  85523. +
  85524. +uint32_t get_b_hnp_enable(dwc_otg_pcd_t * pcd)
  85525. +{
  85526. + return pcd->b_hnp_enable;
  85527. +}
  85528. +
  85529. +uint32_t get_a_hnp_support(dwc_otg_pcd_t * pcd)
  85530. +{
  85531. + return pcd->a_hnp_support;
  85532. +}
  85533. +
  85534. +uint32_t get_a_alt_hnp_support(dwc_otg_pcd_t * pcd)
  85535. +{
  85536. + return pcd->a_alt_hnp_support;
  85537. +}
  85538. +
  85539. +int dwc_otg_pcd_get_rmwkup_enable(dwc_otg_pcd_t * pcd)
  85540. +{
  85541. + return pcd->remote_wakeup_enable;
  85542. +}
  85543. +
  85544. +#endif /* DWC_HOST_ONLY */
  85545. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_pcd.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd.h
  85546. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_pcd.h 1970-01-01 01:00:00.000000000 +0100
  85547. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd.h 2014-04-13 17:33:11.000000000 +0200
  85548. @@ -0,0 +1,266 @@
  85549. +/* ==========================================================================
  85550. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.h $
  85551. + * $Revision: #48 $
  85552. + * $Date: 2012/08/10 $
  85553. + * $Change: 2047372 $
  85554. + *
  85555. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  85556. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  85557. + * otherwise expressly agreed to in writing between Synopsys and you.
  85558. + *
  85559. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  85560. + * any End User Software License Agreement or Agreement for Licensed Product
  85561. + * with Synopsys or any supplement thereto. You are permitted to use and
  85562. + * redistribute this Software in source and binary forms, with or without
  85563. + * modification, provided that redistributions of source code must retain this
  85564. + * notice. You may not view, use, disclose, copy or distribute this file or
  85565. + * any information contained herein except pursuant to this license grant from
  85566. + * Synopsys. If you do not agree with this notice, including the disclaimer
  85567. + * below, then you are not authorized to use the Software.
  85568. + *
  85569. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  85570. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  85571. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  85572. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  85573. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  85574. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  85575. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  85576. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  85577. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  85578. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  85579. + * DAMAGE.
  85580. + * ========================================================================== */
  85581. +#ifndef DWC_HOST_ONLY
  85582. +#if !defined(__DWC_PCD_H__)
  85583. +#define __DWC_PCD_H__
  85584. +
  85585. +#include "dwc_otg_os_dep.h"
  85586. +#include "usb.h"
  85587. +#include "dwc_otg_cil.h"
  85588. +#include "dwc_otg_pcd_if.h"
  85589. +struct cfiobject;
  85590. +
  85591. +/**
  85592. + * @file
  85593. + *
  85594. + * This file contains the structures, constants, and interfaces for
  85595. + * the Perpherial Contoller Driver (PCD).
  85596. + *
  85597. + * The Peripheral Controller Driver (PCD) for Linux will implement the
  85598. + * Gadget API, so that the existing Gadget drivers can be used. For
  85599. + * the Mass Storage Function driver the File-backed USB Storage Gadget
  85600. + * (FBS) driver will be used. The FBS driver supports the
  85601. + * Control-Bulk (CB), Control-Bulk-Interrupt (CBI), and Bulk-Only
  85602. + * transports.
  85603. + *
  85604. + */
  85605. +
  85606. +/** Invalid DMA Address */
  85607. +#define DWC_DMA_ADDR_INVALID (~(dwc_dma_t)0)
  85608. +
  85609. +/** Max Transfer size for any EP */
  85610. +#define DDMA_MAX_TRANSFER_SIZE 65535
  85611. +
  85612. +/**
  85613. + * Get the pointer to the core_if from the pcd pointer.
  85614. + */
  85615. +#define GET_CORE_IF( _pcd ) (_pcd->core_if)
  85616. +
  85617. +/**
  85618. + * States of EP0.
  85619. + */
  85620. +typedef enum ep0_state {
  85621. + EP0_DISCONNECT, /* no host */
  85622. + EP0_IDLE,
  85623. + EP0_IN_DATA_PHASE,
  85624. + EP0_OUT_DATA_PHASE,
  85625. + EP0_IN_STATUS_PHASE,
  85626. + EP0_OUT_STATUS_PHASE,
  85627. + EP0_STALL,
  85628. +} ep0state_e;
  85629. +
  85630. +/** Fordward declaration.*/
  85631. +struct dwc_otg_pcd;
  85632. +
  85633. +/** DWC_otg iso request structure.
  85634. + *
  85635. + */
  85636. +typedef struct usb_iso_request dwc_otg_pcd_iso_request_t;
  85637. +
  85638. +#ifdef DWC_UTE_PER_IO
  85639. +
  85640. +/**
  85641. + * This shall be the exact analogy of the same type structure defined in the
  85642. + * usb_gadget.h. Each descriptor contains
  85643. + */
  85644. +struct dwc_iso_pkt_desc_port {
  85645. + uint32_t offset;
  85646. + uint32_t length; /* expected length */
  85647. + uint32_t actual_length;
  85648. + uint32_t status;
  85649. +};
  85650. +
  85651. +struct dwc_iso_xreq_port {
  85652. + /** transfer/submission flag */
  85653. + uint32_t tr_sub_flags;
  85654. + /** Start the request ASAP */
  85655. +#define DWC_EREQ_TF_ASAP 0x00000002
  85656. + /** Just enqueue the request w/o initiating a transfer */
  85657. +#define DWC_EREQ_TF_ENQUEUE 0x00000004
  85658. +
  85659. + /**
  85660. + * count of ISO packets attached to this request - shall
  85661. + * not exceed the pio_alloc_pkt_count
  85662. + */
  85663. + uint32_t pio_pkt_count;
  85664. + /** count of ISO packets allocated for this request */
  85665. + uint32_t pio_alloc_pkt_count;
  85666. + /** number of ISO packet errors */
  85667. + uint32_t error_count;
  85668. + /** reserved for future extension */
  85669. + uint32_t res;
  85670. + /** Will be allocated and freed in the UTE gadget and based on the CFC value */
  85671. + struct dwc_iso_pkt_desc_port *per_io_frame_descs;
  85672. +};
  85673. +#endif
  85674. +/** DWC_otg request structure.
  85675. + * This structure is a list of requests.
  85676. + */
  85677. +typedef struct dwc_otg_pcd_request {
  85678. + void *priv;
  85679. + void *buf;
  85680. + dwc_dma_t dma;
  85681. + uint32_t length;
  85682. + uint32_t actual;
  85683. + unsigned sent_zlp:1;
  85684. + /**
  85685. + * Used instead of original buffer if
  85686. + * it(physical address) is not dword-aligned.
  85687. + **/
  85688. + uint8_t *dw_align_buf;
  85689. + dwc_dma_t dw_align_buf_dma;
  85690. +
  85691. + DWC_CIRCLEQ_ENTRY(dwc_otg_pcd_request) queue_entry;
  85692. +#ifdef DWC_UTE_PER_IO
  85693. + struct dwc_iso_xreq_port ext_req;
  85694. + //void *priv_ereq_nport; /* */
  85695. +#endif
  85696. +} dwc_otg_pcd_request_t;
  85697. +
  85698. +DWC_CIRCLEQ_HEAD(req_list, dwc_otg_pcd_request);
  85699. +
  85700. +/** PCD EP structure.
  85701. + * This structure describes an EP, there is an array of EPs in the PCD
  85702. + * structure.
  85703. + */
  85704. +typedef struct dwc_otg_pcd_ep {
  85705. + /** USB EP Descriptor */
  85706. + const usb_endpoint_descriptor_t *desc;
  85707. +
  85708. + /** queue of dwc_otg_pcd_requests. */
  85709. + struct req_list queue;
  85710. + unsigned stopped:1;
  85711. + unsigned disabling:1;
  85712. + unsigned dma:1;
  85713. + unsigned queue_sof:1;
  85714. +
  85715. +#ifdef DWC_EN_ISOC
  85716. + /** ISOC req handle passed */
  85717. + void *iso_req_handle;
  85718. +#endif //_EN_ISOC_
  85719. +
  85720. + /** DWC_otg ep data. */
  85721. + dwc_ep_t dwc_ep;
  85722. +
  85723. + /** Pointer to PCD */
  85724. + struct dwc_otg_pcd *pcd;
  85725. +
  85726. + void *priv;
  85727. +} dwc_otg_pcd_ep_t;
  85728. +
  85729. +/** DWC_otg PCD Structure.
  85730. + * This structure encapsulates the data for the dwc_otg PCD.
  85731. + */
  85732. +struct dwc_otg_pcd {
  85733. + const struct dwc_otg_pcd_function_ops *fops;
  85734. + /** The DWC otg device pointer */
  85735. + struct dwc_otg_device *otg_dev;
  85736. + /** Core Interface */
  85737. + dwc_otg_core_if_t *core_if;
  85738. + /** State of EP0 */
  85739. + ep0state_e ep0state;
  85740. + /** EP0 Request is pending */
  85741. + unsigned ep0_pending:1;
  85742. + /** Indicates when SET CONFIGURATION Request is in process */
  85743. + unsigned request_config:1;
  85744. + /** The state of the Remote Wakeup Enable. */
  85745. + unsigned remote_wakeup_enable:1;
  85746. + /** The state of the B-Device HNP Enable. */
  85747. + unsigned b_hnp_enable:1;
  85748. + /** The state of A-Device HNP Support. */
  85749. + unsigned a_hnp_support:1;
  85750. + /** The state of the A-Device Alt HNP support. */
  85751. + unsigned a_alt_hnp_support:1;
  85752. + /** Count of pending Requests */
  85753. + unsigned request_pending;
  85754. +
  85755. + /** SETUP packet for EP0
  85756. + * This structure is allocated as a DMA buffer on PCD initialization
  85757. + * with enough space for up to 3 setup packets.
  85758. + */
  85759. + union {
  85760. + usb_device_request_t req;
  85761. + uint32_t d32[2];
  85762. + } *setup_pkt;
  85763. +
  85764. + dwc_dma_t setup_pkt_dma_handle;
  85765. +
  85766. + /* Additional buffer and flag for CTRL_WR premature case */
  85767. + uint8_t *backup_buf;
  85768. + unsigned data_terminated;
  85769. +
  85770. + /** 2-byte dma buffer used to return status from GET_STATUS */
  85771. + uint16_t *status_buf;
  85772. + dwc_dma_t status_buf_dma_handle;
  85773. +
  85774. + /** EP0 */
  85775. + dwc_otg_pcd_ep_t ep0;
  85776. +
  85777. + /** Array of IN EPs. */
  85778. + dwc_otg_pcd_ep_t in_ep[MAX_EPS_CHANNELS - 1];
  85779. + /** Array of OUT EPs. */
  85780. + dwc_otg_pcd_ep_t out_ep[MAX_EPS_CHANNELS - 1];
  85781. + /** number of valid EPs in the above array. */
  85782. +// unsigned num_eps : 4;
  85783. + dwc_spinlock_t *lock;
  85784. +
  85785. + /** Tasklet to defer starting of TEST mode transmissions until
  85786. + * Status Phase has been completed.
  85787. + */
  85788. + dwc_tasklet_t *test_mode_tasklet;
  85789. +
  85790. + /** Tasklet to delay starting of xfer in DMA mode */
  85791. + dwc_tasklet_t *start_xfer_tasklet;
  85792. +
  85793. + /** The test mode to enter when the tasklet is executed. */
  85794. + unsigned test_mode;
  85795. + /** The cfi_api structure that implements most of the CFI API
  85796. + * and OTG specific core configuration functionality
  85797. + */
  85798. +#ifdef DWC_UTE_CFI
  85799. + struct cfiobject *cfi;
  85800. +#endif
  85801. +
  85802. +};
  85803. +
  85804. +//FIXME this functions should be static, and this prototypes should be removed
  85805. +extern void dwc_otg_request_nuke(dwc_otg_pcd_ep_t * ep);
  85806. +extern void dwc_otg_request_done(dwc_otg_pcd_ep_t * ep,
  85807. + dwc_otg_pcd_request_t * req, int32_t status);
  85808. +
  85809. +void dwc_otg_iso_buffer_done(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep,
  85810. + void *req_handle);
  85811. +
  85812. +extern void do_test_mode(void *data);
  85813. +#endif
  85814. +#endif /* DWC_HOST_ONLY */
  85815. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h
  85816. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h 1970-01-01 01:00:00.000000000 +0100
  85817. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h 2014-04-13 17:33:11.000000000 +0200
  85818. @@ -0,0 +1,360 @@
  85819. +/* ==========================================================================
  85820. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_if.h $
  85821. + * $Revision: #11 $
  85822. + * $Date: 2011/10/26 $
  85823. + * $Change: 1873028 $
  85824. + *
  85825. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  85826. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  85827. + * otherwise expressly agreed to in writing between Synopsys and you.
  85828. + *
  85829. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  85830. + * any End User Software License Agreement or Agreement for Licensed Product
  85831. + * with Synopsys or any supplement thereto. You are permitted to use and
  85832. + * redistribute this Software in source and binary forms, with or without
  85833. + * modification, provided that redistributions of source code must retain this
  85834. + * notice. You may not view, use, disclose, copy or distribute this file or
  85835. + * any information contained herein except pursuant to this license grant from
  85836. + * Synopsys. If you do not agree with this notice, including the disclaimer
  85837. + * below, then you are not authorized to use the Software.
  85838. + *
  85839. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  85840. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  85841. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  85842. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  85843. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  85844. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  85845. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  85846. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  85847. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  85848. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  85849. + * DAMAGE.
  85850. + * ========================================================================== */
  85851. +#ifndef DWC_HOST_ONLY
  85852. +
  85853. +#if !defined(__DWC_PCD_IF_H__)
  85854. +#define __DWC_PCD_IF_H__
  85855. +
  85856. +//#include "dwc_os.h"
  85857. +#include "dwc_otg_core_if.h"
  85858. +
  85859. +/** @file
  85860. + * This file defines DWC_OTG PCD Core API.
  85861. + */
  85862. +
  85863. +struct dwc_otg_pcd;
  85864. +typedef struct dwc_otg_pcd dwc_otg_pcd_t;
  85865. +
  85866. +/** Maxpacket size for EP0 */
  85867. +#define MAX_EP0_SIZE 64
  85868. +/** Maxpacket size for any EP */
  85869. +#define MAX_PACKET_SIZE 1024
  85870. +
  85871. +/** @name Function Driver Callbacks */
  85872. +/** @{ */
  85873. +
  85874. +/** This function will be called whenever a previously queued request has
  85875. + * completed. The status value will be set to -DWC_E_SHUTDOWN to indicated a
  85876. + * failed or aborted transfer, or -DWC_E_RESTART to indicate the device was reset,
  85877. + * or -DWC_E_TIMEOUT to indicate it timed out, or -DWC_E_INVALID to indicate invalid
  85878. + * parameters. */
  85879. +typedef int (*dwc_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  85880. + void *req_handle, int32_t status,
  85881. + uint32_t actual);
  85882. +/**
  85883. + * This function will be called whenever a previousle queued ISOC request has
  85884. + * completed. Count of ISOC packets could be read using dwc_otg_pcd_get_iso_packet_count
  85885. + * function.
  85886. + * The status of each ISOC packet could be read using dwc_otg_pcd_get_iso_packet_*
  85887. + * functions.
  85888. + */
  85889. +typedef int (*dwc_isoc_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  85890. + void *req_handle, int proc_buf_num);
  85891. +/** This function should handle any SETUP request that cannot be handled by the
  85892. + * PCD Core. This includes most GET_DESCRIPTORs, SET_CONFIGS, Any
  85893. + * class-specific requests, etc. The function must non-blocking.
  85894. + *
  85895. + * Returns 0 on success.
  85896. + * Returns -DWC_E_NOT_SUPPORTED if the request is not supported.
  85897. + * Returns -DWC_E_INVALID if the setup request had invalid parameters or bytes.
  85898. + * Returns -DWC_E_SHUTDOWN on any other error. */
  85899. +typedef int (*dwc_setup_cb_t) (dwc_otg_pcd_t * pcd, uint8_t * bytes);
  85900. +/** This is called whenever the device has been disconnected. The function
  85901. + * driver should take appropriate action to clean up all pending requests in the
  85902. + * PCD Core, remove all endpoints (except ep0), and initialize back to reset
  85903. + * state. */
  85904. +typedef int (*dwc_disconnect_cb_t) (dwc_otg_pcd_t * pcd);
  85905. +/** This function is called when device has been connected. */
  85906. +typedef int (*dwc_connect_cb_t) (dwc_otg_pcd_t * pcd, int speed);
  85907. +/** This function is called when device has been suspended */
  85908. +typedef int (*dwc_suspend_cb_t) (dwc_otg_pcd_t * pcd);
  85909. +/** This function is called when device has received LPM tokens, i.e.
  85910. + * device has been sent to sleep state. */
  85911. +typedef int (*dwc_sleep_cb_t) (dwc_otg_pcd_t * pcd);
  85912. +/** This function is called when device has been resumed
  85913. + * from suspend(L2) or L1 sleep state. */
  85914. +typedef int (*dwc_resume_cb_t) (dwc_otg_pcd_t * pcd);
  85915. +/** This function is called whenever hnp params has been changed.
  85916. + * User can call get_b_hnp_enable, get_a_hnp_support, get_a_alt_hnp_support functions
  85917. + * to get hnp parameters. */
  85918. +typedef int (*dwc_hnp_params_changed_cb_t) (dwc_otg_pcd_t * pcd);
  85919. +/** This function is called whenever USB RESET is detected. */
  85920. +typedef int (*dwc_reset_cb_t) (dwc_otg_pcd_t * pcd);
  85921. +
  85922. +typedef int (*cfi_setup_cb_t) (dwc_otg_pcd_t * pcd, void *ctrl_req_bytes);
  85923. +
  85924. +/**
  85925. + *
  85926. + * @param ep_handle Void pointer to the usb_ep structure
  85927. + * @param ereq_port Pointer to the extended request structure created in the
  85928. + * portable part.
  85929. + */
  85930. +typedef int (*xiso_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  85931. + void *req_handle, int32_t status,
  85932. + void *ereq_port);
  85933. +/** Function Driver Ops Data Structure */
  85934. +struct dwc_otg_pcd_function_ops {
  85935. + dwc_connect_cb_t connect;
  85936. + dwc_disconnect_cb_t disconnect;
  85937. + dwc_setup_cb_t setup;
  85938. + dwc_completion_cb_t complete;
  85939. + dwc_isoc_completion_cb_t isoc_complete;
  85940. + dwc_suspend_cb_t suspend;
  85941. + dwc_sleep_cb_t sleep;
  85942. + dwc_resume_cb_t resume;
  85943. + dwc_reset_cb_t reset;
  85944. + dwc_hnp_params_changed_cb_t hnp_changed;
  85945. + cfi_setup_cb_t cfi_setup;
  85946. +#ifdef DWC_UTE_PER_IO
  85947. + xiso_completion_cb_t xisoc_complete;
  85948. +#endif
  85949. +};
  85950. +/** @} */
  85951. +
  85952. +/** @name Function Driver Functions */
  85953. +/** @{ */
  85954. +
  85955. +/** Call this function to get pointer on dwc_otg_pcd_t,
  85956. + * this pointer will be used for all PCD API functions.
  85957. + *
  85958. + * @param core_if The DWC_OTG Core
  85959. + */
  85960. +extern dwc_otg_pcd_t *dwc_otg_pcd_init(dwc_otg_core_if_t * core_if);
  85961. +
  85962. +/** Frees PCD allocated by dwc_otg_pcd_init
  85963. + *
  85964. + * @param pcd The PCD
  85965. + */
  85966. +extern void dwc_otg_pcd_remove(dwc_otg_pcd_t * pcd);
  85967. +
  85968. +/** Call this to bind the function driver to the PCD Core.
  85969. + *
  85970. + * @param pcd Pointer on dwc_otg_pcd_t returned by dwc_otg_pcd_init function.
  85971. + * @param fops The Function Driver Ops data structure containing pointers to all callbacks.
  85972. + */
  85973. +extern void dwc_otg_pcd_start(dwc_otg_pcd_t * pcd,
  85974. + const struct dwc_otg_pcd_function_ops *fops);
  85975. +
  85976. +/** Enables an endpoint for use. This function enables an endpoint in
  85977. + * the PCD. The endpoint is described by the ep_desc which has the
  85978. + * same format as a USB ep descriptor. The ep_handle parameter is used to refer
  85979. + * to the endpoint from other API functions and in callbacks. Normally this
  85980. + * should be called after a SET_CONFIGURATION/SET_INTERFACE to configure the
  85981. + * core for that interface.
  85982. + *
  85983. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  85984. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  85985. + * Returns 0 on success.
  85986. + *
  85987. + * @param pcd The PCD
  85988. + * @param ep_desc Endpoint descriptor
  85989. + * @param usb_ep Handle on endpoint, that will be used to identify endpoint.
  85990. + */
  85991. +extern int dwc_otg_pcd_ep_enable(dwc_otg_pcd_t * pcd,
  85992. + const uint8_t * ep_desc, void *usb_ep);
  85993. +
  85994. +/** Disable the endpoint referenced by ep_handle.
  85995. + *
  85996. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  85997. + * Returns -DWC_E_SHUTDOWN if any other error occurred.
  85998. + * Returns 0 on success. */
  85999. +extern int dwc_otg_pcd_ep_disable(dwc_otg_pcd_t * pcd, void *ep_handle);
  86000. +
  86001. +/** Queue a data transfer request on the endpoint referenced by ep_handle.
  86002. + * After the transfer is completes, the complete callback will be called with
  86003. + * the request status.
  86004. + *
  86005. + * @param pcd The PCD
  86006. + * @param ep_handle The handle of the endpoint
  86007. + * @param buf The buffer for the data
  86008. + * @param dma_buf The DMA buffer for the data
  86009. + * @param buflen The length of the data transfer
  86010. + * @param zero Specifies whether to send zero length last packet.
  86011. + * @param req_handle Set this handle to any value to use to reference this
  86012. + * request in the ep_dequeue function or from the complete callback
  86013. + * @param atomic_alloc If driver need to perform atomic allocations
  86014. + * for internal data structures.
  86015. + *
  86016. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  86017. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  86018. + * Returns 0 on success. */
  86019. +extern int dwc_otg_pcd_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  86020. + uint8_t * buf, dwc_dma_t dma_buf,
  86021. + uint32_t buflen, int zero, void *req_handle,
  86022. + int atomic_alloc);
  86023. +#ifdef DWC_UTE_PER_IO
  86024. +/**
  86025. + *
  86026. + * @param ereq_nonport Pointer to the extended request part of the
  86027. + * usb_request structure defined in usb_gadget.h file.
  86028. + */
  86029. +extern int dwc_otg_pcd_xiso_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  86030. + uint8_t * buf, dwc_dma_t dma_buf,
  86031. + uint32_t buflen, int zero,
  86032. + void *req_handle, int atomic_alloc,
  86033. + void *ereq_nonport);
  86034. +
  86035. +#endif
  86036. +
  86037. +/** De-queue the specified data transfer that has not yet completed.
  86038. + *
  86039. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  86040. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  86041. + * Returns 0 on success. */
  86042. +extern int dwc_otg_pcd_ep_dequeue(dwc_otg_pcd_t * pcd, void *ep_handle,
  86043. + void *req_handle);
  86044. +
  86045. +/** Halt (STALL) an endpoint or clear it.
  86046. + *
  86047. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  86048. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  86049. + * Returns -DWC_E_AGAIN if the STALL cannot be sent and must be tried again later
  86050. + * Returns 0 on success. */
  86051. +extern int dwc_otg_pcd_ep_halt(dwc_otg_pcd_t * pcd, void *ep_handle, int value);
  86052. +
  86053. +/** This function */
  86054. +extern int dwc_otg_pcd_ep_wedge(dwc_otg_pcd_t * pcd, void *ep_handle);
  86055. +
  86056. +/** This function should be called on every hardware interrupt */
  86057. +extern int32_t dwc_otg_pcd_handle_intr(dwc_otg_pcd_t * pcd);
  86058. +
  86059. +/** This function returns current frame number */
  86060. +extern int dwc_otg_pcd_get_frame_number(dwc_otg_pcd_t * pcd);
  86061. +
  86062. +/**
  86063. + * Start isochronous transfers on the endpoint referenced by ep_handle.
  86064. + * For isochronous transfers duble buffering is used.
  86065. + * After processing each of buffers comlete callback will be called with
  86066. + * status for each transaction.
  86067. + *
  86068. + * @param pcd The PCD
  86069. + * @param ep_handle The handle of the endpoint
  86070. + * @param buf0 The virtual address of first data buffer
  86071. + * @param buf1 The virtual address of second data buffer
  86072. + * @param dma0 The DMA address of first data buffer
  86073. + * @param dma1 The DMA address of second data buffer
  86074. + * @param sync_frame Data pattern frame number
  86075. + * @param dp_frame Data size for pattern frame
  86076. + * @param data_per_frame Data size for regular frame
  86077. + * @param start_frame Frame number to start transfers, if -1 then start transfers ASAP.
  86078. + * @param buf_proc_intrvl Interval of ISOC Buffer processing
  86079. + * @param req_handle Handle of ISOC request
  86080. + * @param atomic_alloc Specefies whether to perform atomic allocation for
  86081. + * internal data structures.
  86082. + *
  86083. + * Returns -DWC_E_NO_MEMORY if there is no enough memory.
  86084. + * Returns -DWC_E_INVALID if incorrect arguments are passed to the function.
  86085. + * Returns -DW_E_SHUTDOWN for any other error.
  86086. + * Returns 0 on success
  86087. + */
  86088. +extern int dwc_otg_pcd_iso_ep_start(dwc_otg_pcd_t * pcd, void *ep_handle,
  86089. + uint8_t * buf0, uint8_t * buf1,
  86090. + dwc_dma_t dma0, dwc_dma_t dma1,
  86091. + int sync_frame, int dp_frame,
  86092. + int data_per_frame, int start_frame,
  86093. + int buf_proc_intrvl, void *req_handle,
  86094. + int atomic_alloc);
  86095. +
  86096. +/** Stop ISOC transfers on endpoint referenced by ep_handle.
  86097. + *
  86098. + * @param pcd The PCD
  86099. + * @param ep_handle The handle of the endpoint
  86100. + * @param req_handle Handle of ISOC request
  86101. + *
  86102. + * Returns -DWC_E_INVALID if incorrect arguments are passed to the function
  86103. + * Returns 0 on success
  86104. + */
  86105. +int dwc_otg_pcd_iso_ep_stop(dwc_otg_pcd_t * pcd, void *ep_handle,
  86106. + void *req_handle);
  86107. +
  86108. +/** Get ISOC packet status.
  86109. + *
  86110. + * @param pcd The PCD
  86111. + * @param ep_handle The handle of the endpoint
  86112. + * @param iso_req_handle Isochronoush request handle
  86113. + * @param packet Number of packet
  86114. + * @param status Out parameter for returning status
  86115. + * @param actual Out parameter for returning actual length
  86116. + * @param offset Out parameter for returning offset
  86117. + *
  86118. + */
  86119. +extern void dwc_otg_pcd_get_iso_packet_params(dwc_otg_pcd_t * pcd,
  86120. + void *ep_handle,
  86121. + void *iso_req_handle, int packet,
  86122. + int *status, int *actual,
  86123. + int *offset);
  86124. +
  86125. +/** Get ISOC packet count.
  86126. + *
  86127. + * @param pcd The PCD
  86128. + * @param ep_handle The handle of the endpoint
  86129. + * @param iso_req_handle
  86130. + */
  86131. +extern int dwc_otg_pcd_get_iso_packet_count(dwc_otg_pcd_t * pcd,
  86132. + void *ep_handle,
  86133. + void *iso_req_handle);
  86134. +
  86135. +/** This function starts the SRP Protocol if no session is in progress. If
  86136. + * a session is already in progress, but the device is suspended,
  86137. + * remote wakeup signaling is started.
  86138. + */
  86139. +extern int dwc_otg_pcd_wakeup(dwc_otg_pcd_t * pcd);
  86140. +
  86141. +/** This function returns 1 if LPM support is enabled, and 0 otherwise. */
  86142. +extern int dwc_otg_pcd_is_lpm_enabled(dwc_otg_pcd_t * pcd);
  86143. +
  86144. +/** This function returns 1 if remote wakeup is allowed and 0, otherwise. */
  86145. +extern int dwc_otg_pcd_get_rmwkup_enable(dwc_otg_pcd_t * pcd);
  86146. +
  86147. +/** Initiate SRP */
  86148. +extern void dwc_otg_pcd_initiate_srp(dwc_otg_pcd_t * pcd);
  86149. +
  86150. +/** Starts remote wakeup signaling. */
  86151. +extern void dwc_otg_pcd_remote_wakeup(dwc_otg_pcd_t * pcd, int set);
  86152. +
  86153. +/** Starts micorsecond soft disconnect. */
  86154. +extern void dwc_otg_pcd_disconnect_us(dwc_otg_pcd_t * pcd, int no_of_usecs);
  86155. +/** This function returns whether device is dualspeed.*/
  86156. +extern uint32_t dwc_otg_pcd_is_dualspeed(dwc_otg_pcd_t * pcd);
  86157. +
  86158. +/** This function returns whether device is otg. */
  86159. +extern uint32_t dwc_otg_pcd_is_otg(dwc_otg_pcd_t * pcd);
  86160. +
  86161. +/** These functions allow to get hnp parameters */
  86162. +extern uint32_t get_b_hnp_enable(dwc_otg_pcd_t * pcd);
  86163. +extern uint32_t get_a_hnp_support(dwc_otg_pcd_t * pcd);
  86164. +extern uint32_t get_a_alt_hnp_support(dwc_otg_pcd_t * pcd);
  86165. +
  86166. +/** CFI specific Interface functions */
  86167. +/** Allocate a cfi buffer */
  86168. +extern uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep,
  86169. + dwc_dma_t * addr, size_t buflen,
  86170. + int flags);
  86171. +
  86172. +/******************************************************************************/
  86173. +
  86174. +/** @} */
  86175. +
  86176. +#endif /* __DWC_PCD_IF_H__ */
  86177. +
  86178. +#endif /* DWC_HOST_ONLY */
  86179. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c
  86180. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c 1970-01-01 01:00:00.000000000 +0100
  86181. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c 2014-07-07 10:45:43.000000000 +0200
  86182. @@ -0,0 +1,5147 @@
  86183. +/* ==========================================================================
  86184. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_intr.c $
  86185. + * $Revision: #116 $
  86186. + * $Date: 2012/08/10 $
  86187. + * $Change: 2047372 $
  86188. + *
  86189. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  86190. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  86191. + * otherwise expressly agreed to in writing between Synopsys and you.
  86192. + *
  86193. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  86194. + * any End User Software License Agreement or Agreement for Licensed Product
  86195. + * with Synopsys or any supplement thereto. You are permitted to use and
  86196. + * redistribute this Software in source and binary forms, with or without
  86197. + * modification, provided that redistributions of source code must retain this
  86198. + * notice. You may not view, use, disclose, copy or distribute this file or
  86199. + * any information contained herein except pursuant to this license grant from
  86200. + * Synopsys. If you do not agree with this notice, including the disclaimer
  86201. + * below, then you are not authorized to use the Software.
  86202. + *
  86203. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  86204. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  86205. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  86206. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  86207. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  86208. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  86209. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  86210. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  86211. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  86212. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  86213. + * DAMAGE.
  86214. + * ========================================================================== */
  86215. +#ifndef DWC_HOST_ONLY
  86216. +
  86217. +#include "dwc_otg_pcd.h"
  86218. +
  86219. +#ifdef DWC_UTE_CFI
  86220. +#include "dwc_otg_cfi.h"
  86221. +#endif
  86222. +
  86223. +#ifdef DWC_UTE_PER_IO
  86224. +extern void complete_xiso_ep(dwc_otg_pcd_ep_t * ep);
  86225. +#endif
  86226. +//#define PRINT_CFI_DMA_DESCS
  86227. +
  86228. +#define DEBUG_EP0
  86229. +
  86230. +/**
  86231. + * This function updates OTG.
  86232. + */
  86233. +static void dwc_otg_pcd_update_otg(dwc_otg_pcd_t * pcd, const unsigned reset)
  86234. +{
  86235. +
  86236. + if (reset) {
  86237. + pcd->b_hnp_enable = 0;
  86238. + pcd->a_hnp_support = 0;
  86239. + pcd->a_alt_hnp_support = 0;
  86240. + }
  86241. +
  86242. + if (pcd->fops->hnp_changed) {
  86243. + pcd->fops->hnp_changed(pcd);
  86244. + }
  86245. +}
  86246. +
  86247. +/** @file
  86248. + * This file contains the implementation of the PCD Interrupt handlers.
  86249. + *
  86250. + * The PCD handles the device interrupts. Many conditions can cause a
  86251. + * device interrupt. When an interrupt occurs, the device interrupt
  86252. + * service routine determines the cause of the interrupt and
  86253. + * dispatches handling to the appropriate function. These interrupt
  86254. + * handling functions are described below.
  86255. + * All interrupt registers are processed from LSB to MSB.
  86256. + */
  86257. +
  86258. +/**
  86259. + * This function prints the ep0 state for debug purposes.
  86260. + */
  86261. +static inline void print_ep0_state(dwc_otg_pcd_t * pcd)
  86262. +{
  86263. +#ifdef DEBUG
  86264. + char str[40];
  86265. +
  86266. + switch (pcd->ep0state) {
  86267. + case EP0_DISCONNECT:
  86268. + dwc_strcpy(str, "EP0_DISCONNECT");
  86269. + break;
  86270. + case EP0_IDLE:
  86271. + dwc_strcpy(str, "EP0_IDLE");
  86272. + break;
  86273. + case EP0_IN_DATA_PHASE:
  86274. + dwc_strcpy(str, "EP0_IN_DATA_PHASE");
  86275. + break;
  86276. + case EP0_OUT_DATA_PHASE:
  86277. + dwc_strcpy(str, "EP0_OUT_DATA_PHASE");
  86278. + break;
  86279. + case EP0_IN_STATUS_PHASE:
  86280. + dwc_strcpy(str, "EP0_IN_STATUS_PHASE");
  86281. + break;
  86282. + case EP0_OUT_STATUS_PHASE:
  86283. + dwc_strcpy(str, "EP0_OUT_STATUS_PHASE");
  86284. + break;
  86285. + case EP0_STALL:
  86286. + dwc_strcpy(str, "EP0_STALL");
  86287. + break;
  86288. + default:
  86289. + dwc_strcpy(str, "EP0_INVALID");
  86290. + }
  86291. +
  86292. + DWC_DEBUGPL(DBG_ANY, "%s(%d)\n", str, pcd->ep0state);
  86293. +#endif
  86294. +}
  86295. +
  86296. +/**
  86297. + * This function calculate the size of the payload in the memory
  86298. + * for out endpoints and prints size for debug purposes(used in
  86299. + * 2.93a DevOutNak feature).
  86300. + */
  86301. +static inline void print_memory_payload(dwc_otg_pcd_t * pcd, dwc_ep_t * ep)
  86302. +{
  86303. +#ifdef DEBUG
  86304. + deptsiz_data_t deptsiz_init = {.d32 = 0 };
  86305. + deptsiz_data_t deptsiz_updt = {.d32 = 0 };
  86306. + int pack_num;
  86307. + unsigned payload;
  86308. +
  86309. + deptsiz_init.d32 = pcd->core_if->start_doeptsiz_val[ep->num];
  86310. + deptsiz_updt.d32 =
  86311. + DWC_READ_REG32(&pcd->core_if->dev_if->
  86312. + out_ep_regs[ep->num]->doeptsiz);
  86313. + /* Payload will be */
  86314. + payload = deptsiz_init.b.xfersize - deptsiz_updt.b.xfersize;
  86315. + /* Packet count is decremented every time a packet
  86316. + * is written to the RxFIFO not in to the external memory
  86317. + * So, if payload == 0, then it means no packet was sent to ext memory*/
  86318. + pack_num = (!payload) ? 0 : (deptsiz_init.b.pktcnt - deptsiz_updt.b.pktcnt);
  86319. + DWC_DEBUGPL(DBG_PCDV,
  86320. + "Payload for EP%d-%s\n",
  86321. + ep->num, (ep->is_in ? "IN" : "OUT"));
  86322. + DWC_DEBUGPL(DBG_PCDV,
  86323. + "Number of transfered bytes = 0x%08x\n", payload);
  86324. + DWC_DEBUGPL(DBG_PCDV,
  86325. + "Number of transfered packets = %d\n", pack_num);
  86326. +#endif
  86327. +}
  86328. +
  86329. +
  86330. +#ifdef DWC_UTE_CFI
  86331. +static inline void print_desc(struct dwc_otg_dma_desc *ddesc,
  86332. + const uint8_t * epname, int descnum)
  86333. +{
  86334. + CFI_INFO
  86335. + ("%s DMA_DESC(%d) buf=0x%08x bytes=0x%04x; sp=0x%x; l=0x%x; sts=0x%02x; bs=0x%02x\n",
  86336. + epname, descnum, ddesc->buf, ddesc->status.b.bytes,
  86337. + ddesc->status.b.sp, ddesc->status.b.l, ddesc->status.b.sts,
  86338. + ddesc->status.b.bs);
  86339. +}
  86340. +#endif
  86341. +
  86342. +/**
  86343. + * This function returns pointer to in ep struct with number ep_num
  86344. + */
  86345. +static inline dwc_otg_pcd_ep_t *get_in_ep(dwc_otg_pcd_t * pcd, uint32_t ep_num)
  86346. +{
  86347. + int i;
  86348. + int num_in_eps = GET_CORE_IF(pcd)->dev_if->num_in_eps;
  86349. + if (ep_num == 0) {
  86350. + return &pcd->ep0;
  86351. + } else {
  86352. + for (i = 0; i < num_in_eps; ++i) {
  86353. + if (pcd->in_ep[i].dwc_ep.num == ep_num)
  86354. + return &pcd->in_ep[i];
  86355. + }
  86356. + return 0;
  86357. + }
  86358. +}
  86359. +
  86360. +/**
  86361. + * This function returns pointer to out ep struct with number ep_num
  86362. + */
  86363. +static inline dwc_otg_pcd_ep_t *get_out_ep(dwc_otg_pcd_t * pcd, uint32_t ep_num)
  86364. +{
  86365. + int i;
  86366. + int num_out_eps = GET_CORE_IF(pcd)->dev_if->num_out_eps;
  86367. + if (ep_num == 0) {
  86368. + return &pcd->ep0;
  86369. + } else {
  86370. + for (i = 0; i < num_out_eps; ++i) {
  86371. + if (pcd->out_ep[i].dwc_ep.num == ep_num)
  86372. + return &pcd->out_ep[i];
  86373. + }
  86374. + return 0;
  86375. + }
  86376. +}
  86377. +
  86378. +/**
  86379. + * This functions gets a pointer to an EP from the wIndex address
  86380. + * value of the control request.
  86381. + */
  86382. +dwc_otg_pcd_ep_t *get_ep_by_addr(dwc_otg_pcd_t * pcd, u16 wIndex)
  86383. +{
  86384. + dwc_otg_pcd_ep_t *ep;
  86385. + uint32_t ep_num = UE_GET_ADDR(wIndex);
  86386. +
  86387. + if (ep_num == 0) {
  86388. + ep = &pcd->ep0;
  86389. + } else if (UE_GET_DIR(wIndex) == UE_DIR_IN) { /* in ep */
  86390. + ep = &pcd->in_ep[ep_num - 1];
  86391. + } else {
  86392. + ep = &pcd->out_ep[ep_num - 1];
  86393. + }
  86394. +
  86395. + return ep;
  86396. +}
  86397. +
  86398. +/**
  86399. + * This function checks the EP request queue, if the queue is not
  86400. + * empty the next request is started.
  86401. + */
  86402. +void start_next_request(dwc_otg_pcd_ep_t * ep)
  86403. +{
  86404. + dwc_otg_pcd_request_t *req = 0;
  86405. + uint32_t max_transfer =
  86406. + GET_CORE_IF(ep->pcd)->core_params->max_transfer_size;
  86407. +
  86408. +#ifdef DWC_UTE_CFI
  86409. + struct dwc_otg_pcd *pcd;
  86410. + pcd = ep->pcd;
  86411. +#endif
  86412. +
  86413. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  86414. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  86415. +
  86416. +#ifdef DWC_UTE_CFI
  86417. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  86418. + ep->dwc_ep.cfi_req_len = req->length;
  86419. + pcd->cfi->ops.build_descriptors(pcd->cfi, pcd, ep, req);
  86420. + } else {
  86421. +#endif
  86422. + /* Setup and start the Transfer */
  86423. + if (req->dw_align_buf) {
  86424. + ep->dwc_ep.dma_addr = req->dw_align_buf_dma;
  86425. + ep->dwc_ep.start_xfer_buff = req->dw_align_buf;
  86426. + ep->dwc_ep.xfer_buff = req->dw_align_buf;
  86427. + } else {
  86428. + ep->dwc_ep.dma_addr = req->dma;
  86429. + ep->dwc_ep.start_xfer_buff = req->buf;
  86430. + ep->dwc_ep.xfer_buff = req->buf;
  86431. + }
  86432. + ep->dwc_ep.sent_zlp = 0;
  86433. + ep->dwc_ep.total_len = req->length;
  86434. + ep->dwc_ep.xfer_len = 0;
  86435. + ep->dwc_ep.xfer_count = 0;
  86436. +
  86437. + ep->dwc_ep.maxxfer = max_transfer;
  86438. + if (GET_CORE_IF(ep->pcd)->dma_desc_enable) {
  86439. + uint32_t out_max_xfer = DDMA_MAX_TRANSFER_SIZE
  86440. + - (DDMA_MAX_TRANSFER_SIZE % 4);
  86441. + if (ep->dwc_ep.is_in) {
  86442. + if (ep->dwc_ep.maxxfer >
  86443. + DDMA_MAX_TRANSFER_SIZE) {
  86444. + ep->dwc_ep.maxxfer =
  86445. + DDMA_MAX_TRANSFER_SIZE;
  86446. + }
  86447. + } else {
  86448. + if (ep->dwc_ep.maxxfer > out_max_xfer) {
  86449. + ep->dwc_ep.maxxfer =
  86450. + out_max_xfer;
  86451. + }
  86452. + }
  86453. + }
  86454. + if (ep->dwc_ep.maxxfer < ep->dwc_ep.total_len) {
  86455. + ep->dwc_ep.maxxfer -=
  86456. + (ep->dwc_ep.maxxfer % ep->dwc_ep.maxpacket);
  86457. + }
  86458. + if (req->sent_zlp) {
  86459. + if ((ep->dwc_ep.total_len %
  86460. + ep->dwc_ep.maxpacket == 0)
  86461. + && (ep->dwc_ep.total_len != 0)) {
  86462. + ep->dwc_ep.sent_zlp = 1;
  86463. + }
  86464. +
  86465. + }
  86466. +#ifdef DWC_UTE_CFI
  86467. + }
  86468. +#endif
  86469. + dwc_otg_ep_start_transfer(GET_CORE_IF(ep->pcd), &ep->dwc_ep);
  86470. + } else if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  86471. + DWC_PRINTF("There are no more ISOC requests \n");
  86472. + ep->dwc_ep.frame_num = 0xFFFFFFFF;
  86473. + }
  86474. +}
  86475. +
  86476. +/**
  86477. + * This function handles the SOF Interrupts. At this time the SOF
  86478. + * Interrupt is disabled.
  86479. + */
  86480. +int32_t dwc_otg_pcd_handle_sof_intr(dwc_otg_pcd_t * pcd)
  86481. +{
  86482. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  86483. +
  86484. + gintsts_data_t gintsts;
  86485. +
  86486. + DWC_DEBUGPL(DBG_PCD, "SOF\n");
  86487. +
  86488. + /* Clear interrupt */
  86489. + gintsts.d32 = 0;
  86490. + gintsts.b.sofintr = 1;
  86491. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  86492. +
  86493. + return 1;
  86494. +}
  86495. +
  86496. +/**
  86497. + * This function handles the Rx Status Queue Level Interrupt, which
  86498. + * indicates that there is a least one packet in the Rx FIFO. The
  86499. + * packets are moved from the FIFO to memory, where they will be
  86500. + * processed when the Endpoint Interrupt Register indicates Transfer
  86501. + * Complete or SETUP Phase Done.
  86502. + *
  86503. + * Repeat the following until the Rx Status Queue is empty:
  86504. + * -# Read the Receive Status Pop Register (GRXSTSP) to get Packet
  86505. + * info
  86506. + * -# If Receive FIFO is empty then skip to step Clear the interrupt
  86507. + * and exit
  86508. + * -# If SETUP Packet call dwc_otg_read_setup_packet to copy the
  86509. + * SETUP data to the buffer
  86510. + * -# If OUT Data Packet call dwc_otg_read_packet to copy the data
  86511. + * to the destination buffer
  86512. + */
  86513. +int32_t dwc_otg_pcd_handle_rx_status_q_level_intr(dwc_otg_pcd_t * pcd)
  86514. +{
  86515. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  86516. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  86517. + gintmsk_data_t gintmask = {.d32 = 0 };
  86518. + device_grxsts_data_t status;
  86519. + dwc_otg_pcd_ep_t *ep;
  86520. + gintsts_data_t gintsts;
  86521. +#ifdef DEBUG
  86522. + static char *dpid_str[] = { "D0", "D2", "D1", "MDATA" };
  86523. +#endif
  86524. +
  86525. + //DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, _pcd);
  86526. + /* Disable the Rx Status Queue Level interrupt */
  86527. + gintmask.b.rxstsqlvl = 1;
  86528. + DWC_MODIFY_REG32(&global_regs->gintmsk, gintmask.d32, 0);
  86529. +
  86530. + /* Get the Status from the top of the FIFO */
  86531. + status.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  86532. +
  86533. + DWC_DEBUGPL(DBG_PCD, "EP:%d BCnt:%d DPID:%s "
  86534. + "pktsts:%x Frame:%d(0x%0x)\n",
  86535. + status.b.epnum, status.b.bcnt,
  86536. + dpid_str[status.b.dpid],
  86537. + status.b.pktsts, status.b.fn, status.b.fn);
  86538. + /* Get pointer to EP structure */
  86539. + ep = get_out_ep(pcd, status.b.epnum);
  86540. +
  86541. + switch (status.b.pktsts) {
  86542. + case DWC_DSTS_GOUT_NAK:
  86543. + DWC_DEBUGPL(DBG_PCDV, "Global OUT NAK\n");
  86544. + break;
  86545. + case DWC_STS_DATA_UPDT:
  86546. + DWC_DEBUGPL(DBG_PCDV, "OUT Data Packet\n");
  86547. + if (status.b.bcnt && ep->dwc_ep.xfer_buff) {
  86548. + /** @todo NGS Check for buffer overflow? */
  86549. + dwc_otg_read_packet(core_if,
  86550. + ep->dwc_ep.xfer_buff,
  86551. + status.b.bcnt);
  86552. + ep->dwc_ep.xfer_count += status.b.bcnt;
  86553. + ep->dwc_ep.xfer_buff += status.b.bcnt;
  86554. + }
  86555. + break;
  86556. + case DWC_STS_XFER_COMP:
  86557. + DWC_DEBUGPL(DBG_PCDV, "OUT Complete\n");
  86558. + break;
  86559. + case DWC_DSTS_SETUP_COMP:
  86560. +#ifdef DEBUG_EP0
  86561. + DWC_DEBUGPL(DBG_PCDV, "Setup Complete\n");
  86562. +#endif
  86563. + break;
  86564. + case DWC_DSTS_SETUP_UPDT:
  86565. + dwc_otg_read_setup_packet(core_if, pcd->setup_pkt->d32);
  86566. +#ifdef DEBUG_EP0
  86567. + DWC_DEBUGPL(DBG_PCD,
  86568. + "SETUP PKT: %02x.%02x v%04x i%04x l%04x\n",
  86569. + pcd->setup_pkt->req.bmRequestType,
  86570. + pcd->setup_pkt->req.bRequest,
  86571. + UGETW(pcd->setup_pkt->req.wValue),
  86572. + UGETW(pcd->setup_pkt->req.wIndex),
  86573. + UGETW(pcd->setup_pkt->req.wLength));
  86574. +#endif
  86575. + ep->dwc_ep.xfer_count += status.b.bcnt;
  86576. + break;
  86577. + default:
  86578. + DWC_DEBUGPL(DBG_PCDV, "Invalid Packet Status (0x%0x)\n",
  86579. + status.b.pktsts);
  86580. + break;
  86581. + }
  86582. +
  86583. + /* Enable the Rx Status Queue Level interrupt */
  86584. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmask.d32);
  86585. + /* Clear interrupt */
  86586. + gintsts.d32 = 0;
  86587. + gintsts.b.rxstsqlvl = 1;
  86588. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  86589. +
  86590. + //DWC_DEBUGPL(DBG_PCDV, "EXIT: %s\n", __func__);
  86591. + return 1;
  86592. +}
  86593. +
  86594. +/**
  86595. + * This function examines the Device IN Token Learning Queue to
  86596. + * determine the EP number of the last IN token received. This
  86597. + * implementation is for the Mass Storage device where there are only
  86598. + * 2 IN EPs (Control-IN and BULK-IN).
  86599. + *
  86600. + * The EP numbers for the first six IN Tokens are in DTKNQR1 and there
  86601. + * are 8 EP Numbers in each of the other possible DTKNQ Registers.
  86602. + *
  86603. + * @param core_if Programming view of DWC_otg controller.
  86604. + *
  86605. + */
  86606. +static inline int get_ep_of_last_in_token(dwc_otg_core_if_t * core_if)
  86607. +{
  86608. + dwc_otg_device_global_regs_t *dev_global_regs =
  86609. + core_if->dev_if->dev_global_regs;
  86610. + const uint32_t TOKEN_Q_DEPTH = core_if->hwcfg2.b.dev_token_q_depth;
  86611. + /* Number of Token Queue Registers */
  86612. + const int DTKNQ_REG_CNT = (TOKEN_Q_DEPTH + 7) / 8;
  86613. + dtknq1_data_t dtknqr1;
  86614. + uint32_t in_tkn_epnums[4];
  86615. + int ndx = 0;
  86616. + int i = 0;
  86617. + volatile uint32_t *addr = &dev_global_regs->dtknqr1;
  86618. + int epnum = 0;
  86619. +
  86620. + //DWC_DEBUGPL(DBG_PCD,"dev_token_q_depth=%d\n",TOKEN_Q_DEPTH);
  86621. +
  86622. + /* Read the DTKNQ Registers */
  86623. + for (i = 0; i < DTKNQ_REG_CNT; i++) {
  86624. + in_tkn_epnums[i] = DWC_READ_REG32(addr);
  86625. + DWC_DEBUGPL(DBG_PCDV, "DTKNQR%d=0x%08x\n", i + 1,
  86626. + in_tkn_epnums[i]);
  86627. + if (addr == &dev_global_regs->dvbusdis) {
  86628. + addr = &dev_global_regs->dtknqr3_dthrctl;
  86629. + } else {
  86630. + ++addr;
  86631. + }
  86632. +
  86633. + }
  86634. +
  86635. + /* Copy the DTKNQR1 data to the bit field. */
  86636. + dtknqr1.d32 = in_tkn_epnums[0];
  86637. + /* Get the EP numbers */
  86638. + in_tkn_epnums[0] = dtknqr1.b.epnums0_5;
  86639. + ndx = dtknqr1.b.intknwptr - 1;
  86640. +
  86641. + //DWC_DEBUGPL(DBG_PCDV,"ndx=%d\n",ndx);
  86642. + if (ndx == -1) {
  86643. + /** @todo Find a simpler way to calculate the max
  86644. + * queue position.*/
  86645. + int cnt = TOKEN_Q_DEPTH;
  86646. + if (TOKEN_Q_DEPTH <= 6) {
  86647. + cnt = TOKEN_Q_DEPTH - 1;
  86648. + } else if (TOKEN_Q_DEPTH <= 14) {
  86649. + cnt = TOKEN_Q_DEPTH - 7;
  86650. + } else if (TOKEN_Q_DEPTH <= 22) {
  86651. + cnt = TOKEN_Q_DEPTH - 15;
  86652. + } else {
  86653. + cnt = TOKEN_Q_DEPTH - 23;
  86654. + }
  86655. + epnum = (in_tkn_epnums[DTKNQ_REG_CNT - 1] >> (cnt * 4)) & 0xF;
  86656. + } else {
  86657. + if (ndx <= 5) {
  86658. + epnum = (in_tkn_epnums[0] >> (ndx * 4)) & 0xF;
  86659. + } else if (ndx <= 13) {
  86660. + ndx -= 6;
  86661. + epnum = (in_tkn_epnums[1] >> (ndx * 4)) & 0xF;
  86662. + } else if (ndx <= 21) {
  86663. + ndx -= 14;
  86664. + epnum = (in_tkn_epnums[2] >> (ndx * 4)) & 0xF;
  86665. + } else if (ndx <= 29) {
  86666. + ndx -= 22;
  86667. + epnum = (in_tkn_epnums[3] >> (ndx * 4)) & 0xF;
  86668. + }
  86669. + }
  86670. + //DWC_DEBUGPL(DBG_PCD,"epnum=%d\n",epnum);
  86671. + return epnum;
  86672. +}
  86673. +
  86674. +/**
  86675. + * This interrupt occurs when the non-periodic Tx FIFO is half-empty.
  86676. + * The active request is checked for the next packet to be loaded into
  86677. + * the non-periodic Tx FIFO.
  86678. + */
  86679. +int32_t dwc_otg_pcd_handle_np_tx_fifo_empty_intr(dwc_otg_pcd_t * pcd)
  86680. +{
  86681. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  86682. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  86683. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  86684. + gnptxsts_data_t txstatus = {.d32 = 0 };
  86685. + gintsts_data_t gintsts;
  86686. +
  86687. + int epnum = 0;
  86688. + dwc_otg_pcd_ep_t *ep = 0;
  86689. + uint32_t len = 0;
  86690. + int dwords;
  86691. +
  86692. + /* Get the epnum from the IN Token Learning Queue. */
  86693. + epnum = get_ep_of_last_in_token(core_if);
  86694. + ep = get_in_ep(pcd, epnum);
  86695. +
  86696. + DWC_DEBUGPL(DBG_PCD, "NP TxFifo Empty: %d \n", epnum);
  86697. +
  86698. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  86699. +
  86700. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  86701. + if (len > ep->dwc_ep.maxpacket) {
  86702. + len = ep->dwc_ep.maxpacket;
  86703. + }
  86704. + dwords = (len + 3) / 4;
  86705. +
  86706. + /* While there is space in the queue and space in the FIFO and
  86707. + * More data to tranfer, Write packets to the Tx FIFO */
  86708. + txstatus.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  86709. + DWC_DEBUGPL(DBG_PCDV, "b4 GNPTXSTS=0x%08x\n", txstatus.d32);
  86710. +
  86711. + while (txstatus.b.nptxqspcavail > 0 &&
  86712. + txstatus.b.nptxfspcavail > dwords &&
  86713. + ep->dwc_ep.xfer_count < ep->dwc_ep.xfer_len) {
  86714. + /* Write the FIFO */
  86715. + dwc_otg_ep_write_packet(core_if, &ep->dwc_ep, 0);
  86716. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  86717. +
  86718. + if (len > ep->dwc_ep.maxpacket) {
  86719. + len = ep->dwc_ep.maxpacket;
  86720. + }
  86721. +
  86722. + dwords = (len + 3) / 4;
  86723. + txstatus.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  86724. + DWC_DEBUGPL(DBG_PCDV, "GNPTXSTS=0x%08x\n", txstatus.d32);
  86725. + }
  86726. +
  86727. + DWC_DEBUGPL(DBG_PCDV, "GNPTXSTS=0x%08x\n",
  86728. + DWC_READ_REG32(&global_regs->gnptxsts));
  86729. +
  86730. + /* Clear interrupt */
  86731. + gintsts.d32 = 0;
  86732. + gintsts.b.nptxfempty = 1;
  86733. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  86734. +
  86735. + return 1;
  86736. +}
  86737. +
  86738. +/**
  86739. + * This function is called when dedicated Tx FIFO Empty interrupt occurs.
  86740. + * The active request is checked for the next packet to be loaded into
  86741. + * apropriate Tx FIFO.
  86742. + */
  86743. +static int32_t write_empty_tx_fifo(dwc_otg_pcd_t * pcd, uint32_t epnum)
  86744. +{
  86745. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  86746. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  86747. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  86748. + dtxfsts_data_t txstatus = {.d32 = 0 };
  86749. + dwc_otg_pcd_ep_t *ep = 0;
  86750. + uint32_t len = 0;
  86751. + int dwords;
  86752. +
  86753. + ep = get_in_ep(pcd, epnum);
  86754. +
  86755. + DWC_DEBUGPL(DBG_PCD, "Dedicated TxFifo Empty: %d \n", epnum);
  86756. +
  86757. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  86758. +
  86759. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  86760. +
  86761. + if (len > ep->dwc_ep.maxpacket) {
  86762. + len = ep->dwc_ep.maxpacket;
  86763. + }
  86764. +
  86765. + dwords = (len + 3) / 4;
  86766. +
  86767. + /* While there is space in the queue and space in the FIFO and
  86768. + * More data to tranfer, Write packets to the Tx FIFO */
  86769. + txstatus.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  86770. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum, txstatus.d32);
  86771. +
  86772. + while (txstatus.b.txfspcavail > dwords &&
  86773. + ep->dwc_ep.xfer_count < ep->dwc_ep.xfer_len &&
  86774. + ep->dwc_ep.xfer_len != 0) {
  86775. + /* Write the FIFO */
  86776. + dwc_otg_ep_write_packet(core_if, &ep->dwc_ep, 0);
  86777. +
  86778. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  86779. + if (len > ep->dwc_ep.maxpacket) {
  86780. + len = ep->dwc_ep.maxpacket;
  86781. + }
  86782. +
  86783. + dwords = (len + 3) / 4;
  86784. + txstatus.d32 =
  86785. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  86786. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", epnum,
  86787. + txstatus.d32);
  86788. + }
  86789. +
  86790. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum,
  86791. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts));
  86792. +
  86793. + return 1;
  86794. +}
  86795. +
  86796. +/**
  86797. + * This function is called when the Device is disconnected. It stops
  86798. + * any active requests and informs the Gadget driver of the
  86799. + * disconnect.
  86800. + */
  86801. +void dwc_otg_pcd_stop(dwc_otg_pcd_t * pcd)
  86802. +{
  86803. + int i, num_in_eps, num_out_eps;
  86804. + dwc_otg_pcd_ep_t *ep;
  86805. +
  86806. + gintmsk_data_t intr_mask = {.d32 = 0 };
  86807. +
  86808. + DWC_SPINLOCK(pcd->lock);
  86809. +
  86810. + num_in_eps = GET_CORE_IF(pcd)->dev_if->num_in_eps;
  86811. + num_out_eps = GET_CORE_IF(pcd)->dev_if->num_out_eps;
  86812. +
  86813. + DWC_DEBUGPL(DBG_PCDV, "%s() \n", __func__);
  86814. + /* don't disconnect drivers more than once */
  86815. + if (pcd->ep0state == EP0_DISCONNECT) {
  86816. + DWC_DEBUGPL(DBG_ANY, "%s() Already Disconnected\n", __func__);
  86817. + DWC_SPINUNLOCK(pcd->lock);
  86818. + return;
  86819. + }
  86820. + pcd->ep0state = EP0_DISCONNECT;
  86821. +
  86822. + /* Reset the OTG state. */
  86823. + dwc_otg_pcd_update_otg(pcd, 1);
  86824. +
  86825. + /* Disable the NP Tx Fifo Empty Interrupt. */
  86826. + intr_mask.b.nptxfempty = 1;
  86827. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  86828. + intr_mask.d32, 0);
  86829. +
  86830. + /* Flush the FIFOs */
  86831. + /**@todo NGS Flush Periodic FIFOs */
  86832. + dwc_otg_flush_tx_fifo(GET_CORE_IF(pcd), 0x10);
  86833. + dwc_otg_flush_rx_fifo(GET_CORE_IF(pcd));
  86834. +
  86835. + /* prevent new request submissions, kill any outstanding requests */
  86836. + ep = &pcd->ep0;
  86837. + dwc_otg_request_nuke(ep);
  86838. + /* prevent new request submissions, kill any outstanding requests */
  86839. + for (i = 0; i < num_in_eps; i++) {
  86840. + dwc_otg_pcd_ep_t *ep = &pcd->in_ep[i];
  86841. + dwc_otg_request_nuke(ep);
  86842. + }
  86843. + /* prevent new request submissions, kill any outstanding requests */
  86844. + for (i = 0; i < num_out_eps; i++) {
  86845. + dwc_otg_pcd_ep_t *ep = &pcd->out_ep[i];
  86846. + dwc_otg_request_nuke(ep);
  86847. + }
  86848. +
  86849. + /* report disconnect; the driver is already quiesced */
  86850. + if (pcd->fops->disconnect) {
  86851. + DWC_SPINUNLOCK(pcd->lock);
  86852. + pcd->fops->disconnect(pcd);
  86853. + DWC_SPINLOCK(pcd->lock);
  86854. + }
  86855. + DWC_SPINUNLOCK(pcd->lock);
  86856. +}
  86857. +
  86858. +/**
  86859. + * This interrupt indicates that ...
  86860. + */
  86861. +int32_t dwc_otg_pcd_handle_i2c_intr(dwc_otg_pcd_t * pcd)
  86862. +{
  86863. + gintmsk_data_t intr_mask = {.d32 = 0 };
  86864. + gintsts_data_t gintsts;
  86865. +
  86866. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "i2cintr");
  86867. + intr_mask.b.i2cintr = 1;
  86868. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  86869. + intr_mask.d32, 0);
  86870. +
  86871. + /* Clear interrupt */
  86872. + gintsts.d32 = 0;
  86873. + gintsts.b.i2cintr = 1;
  86874. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  86875. + gintsts.d32);
  86876. + return 1;
  86877. +}
  86878. +
  86879. +/**
  86880. + * This interrupt indicates that ...
  86881. + */
  86882. +int32_t dwc_otg_pcd_handle_early_suspend_intr(dwc_otg_pcd_t * pcd)
  86883. +{
  86884. + gintsts_data_t gintsts;
  86885. +#if defined(VERBOSE)
  86886. + DWC_PRINTF("Early Suspend Detected\n");
  86887. +#endif
  86888. +
  86889. + /* Clear interrupt */
  86890. + gintsts.d32 = 0;
  86891. + gintsts.b.erlysuspend = 1;
  86892. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  86893. + gintsts.d32);
  86894. + return 1;
  86895. +}
  86896. +
  86897. +/**
  86898. + * This function configures EPO to receive SETUP packets.
  86899. + *
  86900. + * @todo NGS: Update the comments from the HW FS.
  86901. + *
  86902. + * -# Program the following fields in the endpoint specific registers
  86903. + * for Control OUT EP 0, in order to receive a setup packet
  86904. + * - DOEPTSIZ0.Packet Count = 3 (To receive up to 3 back to back
  86905. + * setup packets)
  86906. + * - DOEPTSIZE0.Transfer Size = 24 Bytes (To receive up to 3 back
  86907. + * to back setup packets)
  86908. + * - In DMA mode, DOEPDMA0 Register with a memory address to
  86909. + * store any setup packets received
  86910. + *
  86911. + * @param core_if Programming view of DWC_otg controller.
  86912. + * @param pcd Programming view of the PCD.
  86913. + */
  86914. +static inline void ep0_out_start(dwc_otg_core_if_t * core_if,
  86915. + dwc_otg_pcd_t * pcd)
  86916. +{
  86917. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  86918. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  86919. + dwc_otg_dev_dma_desc_t *dma_desc;
  86920. + depctl_data_t doepctl = {.d32 = 0 };
  86921. +
  86922. +#ifdef VERBOSE
  86923. + DWC_DEBUGPL(DBG_PCDV, "%s() doepctl0=%0x\n", __func__,
  86924. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  86925. +#endif
  86926. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  86927. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl);
  86928. + if (doepctl.b.epena) {
  86929. + return;
  86930. + }
  86931. + }
  86932. +
  86933. + doeptsize0.b.supcnt = 3;
  86934. + doeptsize0.b.pktcnt = 1;
  86935. + doeptsize0.b.xfersize = 8 * 3;
  86936. +
  86937. + if (core_if->dma_enable) {
  86938. + if (!core_if->dma_desc_enable) {
  86939. + /** put here as for Hermes mode deptisz register should not be written */
  86940. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doeptsiz,
  86941. + doeptsize0.d32);
  86942. +
  86943. + /** @todo dma needs to handle multiple setup packets (up to 3) */
  86944. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepdma,
  86945. + pcd->setup_pkt_dma_handle);
  86946. + } else {
  86947. + dev_if->setup_desc_index =
  86948. + (dev_if->setup_desc_index + 1) & 1;
  86949. + dma_desc =
  86950. + dev_if->setup_desc_addr[dev_if->setup_desc_index];
  86951. +
  86952. + /** DMA Descriptor Setup */
  86953. + dma_desc->status.b.bs = BS_HOST_BUSY;
  86954. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  86955. + dma_desc->status.b.sr = 0;
  86956. + dma_desc->status.b.mtrf = 0;
  86957. + }
  86958. + dma_desc->status.b.l = 1;
  86959. + dma_desc->status.b.ioc = 1;
  86960. + dma_desc->status.b.bytes = pcd->ep0.dwc_ep.maxpacket;
  86961. + dma_desc->buf = pcd->setup_pkt_dma_handle;
  86962. + dma_desc->status.b.sts = 0;
  86963. + dma_desc->status.b.bs = BS_HOST_READY;
  86964. +
  86965. + /** DOEPDMA0 Register write */
  86966. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepdma,
  86967. + dev_if->dma_setup_desc_addr
  86968. + [dev_if->setup_desc_index]);
  86969. + }
  86970. +
  86971. + } else {
  86972. + /** put here as for Hermes mode deptisz register should not be written */
  86973. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doeptsiz,
  86974. + doeptsize0.d32);
  86975. + }
  86976. +
  86977. + /** DOEPCTL0 Register write cnak will be set after setup interrupt */
  86978. + doepctl.d32 = 0;
  86979. + doepctl.b.epena = 1;
  86980. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  86981. + doepctl.b.cnak = 1;
  86982. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
  86983. + } else {
  86984. + DWC_MODIFY_REG32(&dev_if->out_ep_regs[0]->doepctl, 0, doepctl.d32);
  86985. + }
  86986. +
  86987. +#ifdef VERBOSE
  86988. + DWC_DEBUGPL(DBG_PCDV, "doepctl0=%0x\n",
  86989. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  86990. + DWC_DEBUGPL(DBG_PCDV, "diepctl0=%0x\n",
  86991. + DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl));
  86992. +#endif
  86993. +}
  86994. +
  86995. +/**
  86996. + * This interrupt occurs when a USB Reset is detected. When the USB
  86997. + * Reset Interrupt occurs the device state is set to DEFAULT and the
  86998. + * EP0 state is set to IDLE.
  86999. + * -# Set the NAK bit for all OUT endpoints (DOEPCTLn.SNAK = 1)
  87000. + * -# Unmask the following interrupt bits
  87001. + * - DAINTMSK.INEP0 = 1 (Control 0 IN endpoint)
  87002. + * - DAINTMSK.OUTEP0 = 1 (Control 0 OUT endpoint)
  87003. + * - DOEPMSK.SETUP = 1
  87004. + * - DOEPMSK.XferCompl = 1
  87005. + * - DIEPMSK.XferCompl = 1
  87006. + * - DIEPMSK.TimeOut = 1
  87007. + * -# Program the following fields in the endpoint specific registers
  87008. + * for Control OUT EP 0, in order to receive a setup packet
  87009. + * - DOEPTSIZ0.Packet Count = 3 (To receive up to 3 back to back
  87010. + * setup packets)
  87011. + * - DOEPTSIZE0.Transfer Size = 24 Bytes (To receive up to 3 back
  87012. + * to back setup packets)
  87013. + * - In DMA mode, DOEPDMA0 Register with a memory address to
  87014. + * store any setup packets received
  87015. + * At this point, all the required initialization, except for enabling
  87016. + * the control 0 OUT endpoint is done, for receiving SETUP packets.
  87017. + */
  87018. +int32_t dwc_otg_pcd_handle_usb_reset_intr(dwc_otg_pcd_t * pcd)
  87019. +{
  87020. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  87021. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  87022. + depctl_data_t doepctl = {.d32 = 0 };
  87023. + depctl_data_t diepctl = {.d32 = 0 };
  87024. + daint_data_t daintmsk = {.d32 = 0 };
  87025. + doepmsk_data_t doepmsk = {.d32 = 0 };
  87026. + diepmsk_data_t diepmsk = {.d32 = 0 };
  87027. + dcfg_data_t dcfg = {.d32 = 0 };
  87028. + grstctl_t resetctl = {.d32 = 0 };
  87029. + dctl_data_t dctl = {.d32 = 0 };
  87030. + int i = 0;
  87031. + gintsts_data_t gintsts;
  87032. + pcgcctl_data_t power = {.d32 = 0 };
  87033. +
  87034. + power.d32 = DWC_READ_REG32(core_if->pcgcctl);
  87035. + if (power.b.stoppclk) {
  87036. + power.d32 = 0;
  87037. + power.b.stoppclk = 1;
  87038. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  87039. +
  87040. + power.b.pwrclmp = 1;
  87041. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  87042. +
  87043. + power.b.rstpdwnmodule = 1;
  87044. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  87045. + }
  87046. +
  87047. + core_if->lx_state = DWC_OTG_L0;
  87048. +
  87049. + DWC_PRINTF("USB RESET\n");
  87050. +#ifdef DWC_EN_ISOC
  87051. + for (i = 1; i < 16; ++i) {
  87052. + dwc_otg_pcd_ep_t *ep;
  87053. + dwc_ep_t *dwc_ep;
  87054. + ep = get_in_ep(pcd, i);
  87055. + if (ep != 0) {
  87056. + dwc_ep = &ep->dwc_ep;
  87057. + dwc_ep->next_frame = 0xffffffff;
  87058. + }
  87059. + }
  87060. +#endif /* DWC_EN_ISOC */
  87061. +
  87062. + /* reset the HNP settings */
  87063. + dwc_otg_pcd_update_otg(pcd, 1);
  87064. +
  87065. + /* Clear the Remote Wakeup Signalling */
  87066. + dctl.b.rmtwkupsig = 1;
  87067. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  87068. +
  87069. + /* Set NAK for all OUT EPs */
  87070. + doepctl.b.snak = 1;
  87071. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  87072. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, doepctl.d32);
  87073. + }
  87074. +
  87075. + /* Flush the NP Tx FIFO */
  87076. + dwc_otg_flush_tx_fifo(core_if, 0x10);
  87077. + /* Flush the Learning Queue */
  87078. + resetctl.b.intknqflsh = 1;
  87079. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  87080. +
  87081. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable) {
  87082. + core_if->start_predict = 0;
  87083. + for (i = 0; i<= core_if->dev_if->num_in_eps; ++i) {
  87084. + core_if->nextep_seq[i] = 0xff; // 0xff - EP not active
  87085. + }
  87086. + core_if->nextep_seq[0] = 0;
  87087. + core_if->first_in_nextep_seq = 0;
  87088. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  87089. + diepctl.b.nextep = 0;
  87090. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  87091. +
  87092. + /* Update IN Endpoint Mismatch Count by active IN NP EP count + 1 */
  87093. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  87094. + dcfg.b.epmscnt = 2;
  87095. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  87096. +
  87097. + DWC_DEBUGPL(DBG_PCDV,
  87098. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  87099. + __func__, core_if->first_in_nextep_seq);
  87100. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  87101. + DWC_DEBUGPL(DBG_PCDV, "%2d\n", core_if->nextep_seq[i]);
  87102. + }
  87103. + }
  87104. +
  87105. + if (core_if->multiproc_int_enable) {
  87106. + daintmsk.b.inep0 = 1;
  87107. + daintmsk.b.outep0 = 1;
  87108. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachintmsk,
  87109. + daintmsk.d32);
  87110. +
  87111. + doepmsk.b.setup = 1;
  87112. + doepmsk.b.xfercompl = 1;
  87113. + doepmsk.b.ahberr = 1;
  87114. + doepmsk.b.epdisabled = 1;
  87115. +
  87116. + if ((core_if->dma_desc_enable) ||
  87117. + (core_if->dma_enable
  87118. + && core_if->snpsid >= OTG_CORE_REV_3_00a)) {
  87119. + doepmsk.b.stsphsercvd = 1;
  87120. + }
  87121. + if (core_if->dma_desc_enable)
  87122. + doepmsk.b.bna = 1;
  87123. +/*
  87124. + doepmsk.b.babble = 1;
  87125. + doepmsk.b.nyet = 1;
  87126. +
  87127. + if (core_if->dma_enable) {
  87128. + doepmsk.b.nak = 1;
  87129. + }
  87130. +*/
  87131. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepeachintmsk[0],
  87132. + doepmsk.d32);
  87133. +
  87134. + diepmsk.b.xfercompl = 1;
  87135. + diepmsk.b.timeout = 1;
  87136. + diepmsk.b.epdisabled = 1;
  87137. + diepmsk.b.ahberr = 1;
  87138. + diepmsk.b.intknepmis = 1;
  87139. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  87140. + diepmsk.b.intknepmis = 0;
  87141. +
  87142. +/* if (core_if->dma_desc_enable) {
  87143. + diepmsk.b.bna = 1;
  87144. + }
  87145. +*/
  87146. +/*
  87147. + if (core_if->dma_enable) {
  87148. + diepmsk.b.nak = 1;
  87149. + }
  87150. +*/
  87151. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepeachintmsk[0],
  87152. + diepmsk.d32);
  87153. + } else {
  87154. + daintmsk.b.inep0 = 1;
  87155. + daintmsk.b.outep0 = 1;
  87156. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daintmsk,
  87157. + daintmsk.d32);
  87158. +
  87159. + doepmsk.b.setup = 1;
  87160. + doepmsk.b.xfercompl = 1;
  87161. + doepmsk.b.ahberr = 1;
  87162. + doepmsk.b.epdisabled = 1;
  87163. +
  87164. + if ((core_if->dma_desc_enable) ||
  87165. + (core_if->dma_enable
  87166. + && core_if->snpsid >= OTG_CORE_REV_3_00a)) {
  87167. + doepmsk.b.stsphsercvd = 1;
  87168. + }
  87169. + if (core_if->dma_desc_enable)
  87170. + doepmsk.b.bna = 1;
  87171. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepmsk, doepmsk.d32);
  87172. +
  87173. + diepmsk.b.xfercompl = 1;
  87174. + diepmsk.b.timeout = 1;
  87175. + diepmsk.b.epdisabled = 1;
  87176. + diepmsk.b.ahberr = 1;
  87177. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  87178. + diepmsk.b.intknepmis = 0;
  87179. +/*
  87180. + if (core_if->dma_desc_enable) {
  87181. + diepmsk.b.bna = 1;
  87182. + }
  87183. +*/
  87184. +
  87185. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepmsk, diepmsk.d32);
  87186. + }
  87187. +
  87188. + /* Reset Device Address */
  87189. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  87190. + dcfg.b.devaddr = 0;
  87191. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  87192. +
  87193. + /* setup EP0 to receive SETUP packets */
  87194. + if (core_if->snpsid <= OTG_CORE_REV_2_94a)
  87195. + ep0_out_start(core_if, pcd);
  87196. +
  87197. + /* Clear interrupt */
  87198. + gintsts.d32 = 0;
  87199. + gintsts.b.usbreset = 1;
  87200. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  87201. +
  87202. + return 1;
  87203. +}
  87204. +
  87205. +/**
  87206. + * Get the device speed from the device status register and convert it
  87207. + * to USB speed constant.
  87208. + *
  87209. + * @param core_if Programming view of DWC_otg controller.
  87210. + */
  87211. +static int get_device_speed(dwc_otg_core_if_t * core_if)
  87212. +{
  87213. + dsts_data_t dsts;
  87214. + int speed = 0;
  87215. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  87216. +
  87217. + switch (dsts.b.enumspd) {
  87218. + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
  87219. + speed = USB_SPEED_HIGH;
  87220. + break;
  87221. + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
  87222. + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
  87223. + speed = USB_SPEED_FULL;
  87224. + break;
  87225. +
  87226. + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
  87227. + speed = USB_SPEED_LOW;
  87228. + break;
  87229. + }
  87230. +
  87231. + return speed;
  87232. +}
  87233. +
  87234. +/**
  87235. + * Read the device status register and set the device speed in the
  87236. + * data structure.
  87237. + * Set up EP0 to receive SETUP packets by calling dwc_ep0_activate.
  87238. + */
  87239. +int32_t dwc_otg_pcd_handle_enum_done_intr(dwc_otg_pcd_t * pcd)
  87240. +{
  87241. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  87242. + gintsts_data_t gintsts;
  87243. + gusbcfg_data_t gusbcfg;
  87244. + dwc_otg_core_global_regs_t *global_regs =
  87245. + GET_CORE_IF(pcd)->core_global_regs;
  87246. + uint8_t utmi16b, utmi8b;
  87247. + int speed;
  87248. + DWC_DEBUGPL(DBG_PCD, "SPEED ENUM\n");
  87249. +
  87250. + if (GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_2_60a) {
  87251. + utmi16b = 6; //vahrama old value was 6;
  87252. + utmi8b = 9;
  87253. + } else {
  87254. + utmi16b = 4;
  87255. + utmi8b = 8;
  87256. + }
  87257. + dwc_otg_ep0_activate(GET_CORE_IF(pcd), &ep0->dwc_ep);
  87258. + if (GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_3_00a) {
  87259. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  87260. + }
  87261. +
  87262. +#ifdef DEBUG_EP0
  87263. + print_ep0_state(pcd);
  87264. +#endif
  87265. +
  87266. + if (pcd->ep0state == EP0_DISCONNECT) {
  87267. + pcd->ep0state = EP0_IDLE;
  87268. + } else if (pcd->ep0state == EP0_STALL) {
  87269. + pcd->ep0state = EP0_IDLE;
  87270. + }
  87271. +
  87272. + pcd->ep0state = EP0_IDLE;
  87273. +
  87274. + ep0->stopped = 0;
  87275. +
  87276. + speed = get_device_speed(GET_CORE_IF(pcd));
  87277. + pcd->fops->connect(pcd, speed);
  87278. +
  87279. + /* Set USB turnaround time based on device speed and PHY interface. */
  87280. + gusbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  87281. + if (speed == USB_SPEED_HIGH) {
  87282. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  87283. + DWC_HWCFG2_HS_PHY_TYPE_ULPI) {
  87284. + /* ULPI interface */
  87285. + gusbcfg.b.usbtrdtim = 9;
  87286. + }
  87287. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  87288. + DWC_HWCFG2_HS_PHY_TYPE_UTMI) {
  87289. + /* UTMI+ interface */
  87290. + if (GET_CORE_IF(pcd)->hwcfg4.b.utmi_phy_data_width == 0) {
  87291. + gusbcfg.b.usbtrdtim = utmi8b;
  87292. + } else if (GET_CORE_IF(pcd)->hwcfg4.
  87293. + b.utmi_phy_data_width == 1) {
  87294. + gusbcfg.b.usbtrdtim = utmi16b;
  87295. + } else if (GET_CORE_IF(pcd)->
  87296. + core_params->phy_utmi_width == 8) {
  87297. + gusbcfg.b.usbtrdtim = utmi8b;
  87298. + } else {
  87299. + gusbcfg.b.usbtrdtim = utmi16b;
  87300. + }
  87301. + }
  87302. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  87303. + DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI) {
  87304. + /* UTMI+ OR ULPI interface */
  87305. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  87306. + /* ULPI interface */
  87307. + gusbcfg.b.usbtrdtim = 9;
  87308. + } else {
  87309. + /* UTMI+ interface */
  87310. + if (GET_CORE_IF(pcd)->
  87311. + core_params->phy_utmi_width == 16) {
  87312. + gusbcfg.b.usbtrdtim = utmi16b;
  87313. + } else {
  87314. + gusbcfg.b.usbtrdtim = utmi8b;
  87315. + }
  87316. + }
  87317. + }
  87318. + } else {
  87319. + /* Full or low speed */
  87320. + gusbcfg.b.usbtrdtim = 9;
  87321. + }
  87322. + DWC_WRITE_REG32(&global_regs->gusbcfg, gusbcfg.d32);
  87323. +
  87324. + /* Clear interrupt */
  87325. + gintsts.d32 = 0;
  87326. + gintsts.b.enumdone = 1;
  87327. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  87328. + gintsts.d32);
  87329. + return 1;
  87330. +}
  87331. +
  87332. +/**
  87333. + * This interrupt indicates that the ISO OUT Packet was dropped due to
  87334. + * Rx FIFO full or Rx Status Queue Full. If this interrupt occurs
  87335. + * read all the data from the Rx FIFO.
  87336. + */
  87337. +int32_t dwc_otg_pcd_handle_isoc_out_packet_dropped_intr(dwc_otg_pcd_t * pcd)
  87338. +{
  87339. + gintmsk_data_t intr_mask = {.d32 = 0 };
  87340. + gintsts_data_t gintsts;
  87341. +
  87342. + DWC_WARN("INTERRUPT Handler not implemented for %s\n",
  87343. + "ISOC Out Dropped");
  87344. +
  87345. + intr_mask.b.isooutdrop = 1;
  87346. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  87347. + intr_mask.d32, 0);
  87348. +
  87349. + /* Clear interrupt */
  87350. + gintsts.d32 = 0;
  87351. + gintsts.b.isooutdrop = 1;
  87352. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  87353. + gintsts.d32);
  87354. +
  87355. + return 1;
  87356. +}
  87357. +
  87358. +/**
  87359. + * This interrupt indicates the end of the portion of the micro-frame
  87360. + * for periodic transactions. If there is a periodic transaction for
  87361. + * the next frame, load the packets into the EP periodic Tx FIFO.
  87362. + */
  87363. +int32_t dwc_otg_pcd_handle_end_periodic_frame_intr(dwc_otg_pcd_t * pcd)
  87364. +{
  87365. + gintmsk_data_t intr_mask = {.d32 = 0 };
  87366. + gintsts_data_t gintsts;
  87367. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "EOP");
  87368. +
  87369. + intr_mask.b.eopframe = 1;
  87370. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  87371. + intr_mask.d32, 0);
  87372. +
  87373. + /* Clear interrupt */
  87374. + gintsts.d32 = 0;
  87375. + gintsts.b.eopframe = 1;
  87376. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  87377. + gintsts.d32);
  87378. +
  87379. + return 1;
  87380. +}
  87381. +
  87382. +/**
  87383. + * This interrupt indicates that EP of the packet on the top of the
  87384. + * non-periodic Tx FIFO does not match EP of the IN Token received.
  87385. + *
  87386. + * The "Device IN Token Queue" Registers are read to determine the
  87387. + * order the IN Tokens have been received. The non-periodic Tx FIFO
  87388. + * is flushed, so it can be reloaded in the order seen in the IN Token
  87389. + * Queue.
  87390. + */
  87391. +int32_t dwc_otg_pcd_handle_ep_mismatch_intr(dwc_otg_pcd_t * pcd)
  87392. +{
  87393. + gintsts_data_t gintsts;
  87394. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  87395. + dctl_data_t dctl;
  87396. + gintmsk_data_t intr_mask = {.d32 = 0 };
  87397. +
  87398. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable) {
  87399. + core_if->start_predict = 1;
  87400. +
  87401. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, core_if);
  87402. +
  87403. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  87404. + if (!gintsts.b.ginnakeff) {
  87405. + /* Disable EP Mismatch interrupt */
  87406. + intr_mask.d32 = 0;
  87407. + intr_mask.b.epmismatch = 1;
  87408. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, intr_mask.d32, 0);
  87409. + /* Enable the Global IN NAK Effective Interrupt */
  87410. + intr_mask.d32 = 0;
  87411. + intr_mask.b.ginnakeff = 1;
  87412. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, intr_mask.d32);
  87413. + /* Set the global non-periodic IN NAK handshake */
  87414. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  87415. + dctl.b.sgnpinnak = 1;
  87416. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  87417. + } else {
  87418. + DWC_PRINTF("gintsts.b.ginnakeff = 1! dctl.b.sgnpinnak not set\n");
  87419. + }
  87420. + /* Disabling of all EP's will be done in dwc_otg_pcd_handle_in_nak_effective()
  87421. + * handler after Global IN NAK Effective interrupt will be asserted */
  87422. + }
  87423. + /* Clear interrupt */
  87424. + gintsts.d32 = 0;
  87425. + gintsts.b.epmismatch = 1;
  87426. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  87427. +
  87428. + return 1;
  87429. +}
  87430. +
  87431. +/**
  87432. + * This interrupt is valid only in DMA mode. This interrupt indicates that the
  87433. + * core has stopped fetching data for IN endpoints due to the unavailability of
  87434. + * TxFIFO space or Request Queue space. This interrupt is used by the
  87435. + * application for an endpoint mismatch algorithm.
  87436. + *
  87437. + * @param pcd The PCD
  87438. + */
  87439. +int32_t dwc_otg_pcd_handle_ep_fetsusp_intr(dwc_otg_pcd_t * pcd)
  87440. +{
  87441. + gintsts_data_t gintsts;
  87442. + gintmsk_data_t gintmsk_data;
  87443. + dctl_data_t dctl;
  87444. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  87445. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, core_if);
  87446. +
  87447. + /* Clear the global non-periodic IN NAK handshake */
  87448. + dctl.d32 = 0;
  87449. + dctl.b.cgnpinnak = 1;
  87450. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  87451. +
  87452. + /* Mask GINTSTS.FETSUSP interrupt */
  87453. + gintmsk_data.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  87454. + gintmsk_data.b.fetsusp = 0;
  87455. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk_data.d32);
  87456. +
  87457. + /* Clear interrupt */
  87458. + gintsts.d32 = 0;
  87459. + gintsts.b.fetsusp = 1;
  87460. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  87461. +
  87462. + return 1;
  87463. +}
  87464. +/**
  87465. + * This funcion stalls EP0.
  87466. + */
  87467. +static inline void ep0_do_stall(dwc_otg_pcd_t * pcd, const int err_val)
  87468. +{
  87469. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  87470. + usb_device_request_t *ctrl = &pcd->setup_pkt->req;
  87471. + DWC_WARN("req %02x.%02x protocol STALL; err %d\n",
  87472. + ctrl->bmRequestType, ctrl->bRequest, err_val);
  87473. +
  87474. + ep0->dwc_ep.is_in = 1;
  87475. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep0->dwc_ep);
  87476. + pcd->ep0.stopped = 1;
  87477. + pcd->ep0state = EP0_IDLE;
  87478. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  87479. +}
  87480. +
  87481. +/**
  87482. + * This functions delegates the setup command to the gadget driver.
  87483. + */
  87484. +static inline void do_gadget_setup(dwc_otg_pcd_t * pcd,
  87485. + usb_device_request_t * ctrl)
  87486. +{
  87487. + int ret = 0;
  87488. + DWC_SPINUNLOCK(pcd->lock);
  87489. + ret = pcd->fops->setup(pcd, (uint8_t *) ctrl);
  87490. + DWC_SPINLOCK(pcd->lock);
  87491. + if (ret < 0) {
  87492. + ep0_do_stall(pcd, ret);
  87493. + }
  87494. +
  87495. + /** @todo This is a g_file_storage gadget driver specific
  87496. + * workaround: a DELAYED_STATUS result from the fsg_setup
  87497. + * routine will result in the gadget queueing a EP0 IN status
  87498. + * phase for a two-stage control transfer. Exactly the same as
  87499. + * a SET_CONFIGURATION/SET_INTERFACE except that this is a class
  87500. + * specific request. Need a generic way to know when the gadget
  87501. + * driver will queue the status phase. Can we assume when we
  87502. + * call the gadget driver setup() function that it will always
  87503. + * queue and require the following flag? Need to look into
  87504. + * this.
  87505. + */
  87506. +
  87507. + if (ret == 256 + 999) {
  87508. + pcd->request_config = 1;
  87509. + }
  87510. +}
  87511. +
  87512. +#ifdef DWC_UTE_CFI
  87513. +/**
  87514. + * This functions delegates the CFI setup commands to the gadget driver.
  87515. + * This function will return a negative value to indicate a failure.
  87516. + */
  87517. +static inline int cfi_gadget_setup(dwc_otg_pcd_t * pcd,
  87518. + struct cfi_usb_ctrlrequest *ctrl_req)
  87519. +{
  87520. + int ret = 0;
  87521. +
  87522. + if (pcd->fops && pcd->fops->cfi_setup) {
  87523. + DWC_SPINUNLOCK(pcd->lock);
  87524. + ret = pcd->fops->cfi_setup(pcd, ctrl_req);
  87525. + DWC_SPINLOCK(pcd->lock);
  87526. + if (ret < 0) {
  87527. + ep0_do_stall(pcd, ret);
  87528. + return ret;
  87529. + }
  87530. + }
  87531. +
  87532. + return ret;
  87533. +}
  87534. +#endif
  87535. +
  87536. +/**
  87537. + * This function starts the Zero-Length Packet for the IN status phase
  87538. + * of a 2 stage control transfer.
  87539. + */
  87540. +static inline void do_setup_in_status_phase(dwc_otg_pcd_t * pcd)
  87541. +{
  87542. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  87543. + if (pcd->ep0state == EP0_STALL) {
  87544. + return;
  87545. + }
  87546. +
  87547. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  87548. +
  87549. + /* Prepare for more SETUP Packets */
  87550. + DWC_DEBUGPL(DBG_PCD, "EP0 IN ZLP\n");
  87551. + if ((GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_3_00a)
  87552. + && (pcd->core_if->dma_desc_enable)
  87553. + && (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len)) {
  87554. + DWC_DEBUGPL(DBG_PCDV,
  87555. + "Data terminated wait next packet in out_desc_addr\n");
  87556. + pcd->backup_buf = phys_to_virt(ep0->dwc_ep.dma_addr);
  87557. + pcd->data_terminated = 1;
  87558. + }
  87559. + ep0->dwc_ep.xfer_len = 0;
  87560. + ep0->dwc_ep.xfer_count = 0;
  87561. + ep0->dwc_ep.is_in = 1;
  87562. + ep0->dwc_ep.dma_addr = pcd->setup_pkt_dma_handle;
  87563. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  87564. +
  87565. + /* Prepare for more SETUP Packets */
  87566. + //ep0_out_start(GET_CORE_IF(pcd), pcd);
  87567. +}
  87568. +
  87569. +/**
  87570. + * This function starts the Zero-Length Packet for the OUT status phase
  87571. + * of a 2 stage control transfer.
  87572. + */
  87573. +static inline void do_setup_out_status_phase(dwc_otg_pcd_t * pcd)
  87574. +{
  87575. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  87576. + if (pcd->ep0state == EP0_STALL) {
  87577. + DWC_DEBUGPL(DBG_PCD, "EP0 STALLED\n");
  87578. + return;
  87579. + }
  87580. + pcd->ep0state = EP0_OUT_STATUS_PHASE;
  87581. +
  87582. + DWC_DEBUGPL(DBG_PCD, "EP0 OUT ZLP\n");
  87583. + ep0->dwc_ep.xfer_len = 0;
  87584. + ep0->dwc_ep.xfer_count = 0;
  87585. + ep0->dwc_ep.is_in = 0;
  87586. + ep0->dwc_ep.dma_addr = pcd->setup_pkt_dma_handle;
  87587. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  87588. +
  87589. + /* Prepare for more SETUP Packets */
  87590. + if (GET_CORE_IF(pcd)->dma_enable == 0) {
  87591. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  87592. + }
  87593. +}
  87594. +
  87595. +/**
  87596. + * Clear the EP halt (STALL) and if pending requests start the
  87597. + * transfer.
  87598. + */
  87599. +static inline void pcd_clear_halt(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep)
  87600. +{
  87601. + if (ep->dwc_ep.stall_clear_flag == 0)
  87602. + dwc_otg_ep_clear_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  87603. +
  87604. + /* Reactive the EP */
  87605. + dwc_otg_ep_activate(GET_CORE_IF(pcd), &ep->dwc_ep);
  87606. + if (ep->stopped) {
  87607. + ep->stopped = 0;
  87608. + /* If there is a request in the EP queue start it */
  87609. +
  87610. + /** @todo FIXME: this causes an EP mismatch in DMA mode.
  87611. + * epmismatch not yet implemented. */
  87612. +
  87613. + /*
  87614. + * Above fixme is solved by implmenting a tasklet to call the
  87615. + * start_next_request(), outside of interrupt context at some
  87616. + * time after the current time, after a clear-halt setup packet.
  87617. + * Still need to implement ep mismatch in the future if a gadget
  87618. + * ever uses more than one endpoint at once
  87619. + */
  87620. + ep->queue_sof = 1;
  87621. + DWC_TASK_SCHEDULE(pcd->start_xfer_tasklet);
  87622. + }
  87623. + /* Start Control Status Phase */
  87624. + do_setup_in_status_phase(pcd);
  87625. +}
  87626. +
  87627. +/**
  87628. + * This function is called when the SET_FEATURE TEST_MODE Setup packet
  87629. + * is sent from the host. The Device Control register is written with
  87630. + * the Test Mode bits set to the specified Test Mode. This is done as
  87631. + * a tasklet so that the "Status" phase of the control transfer
  87632. + * completes before transmitting the TEST packets.
  87633. + *
  87634. + * @todo This has not been tested since the tasklet struct was put
  87635. + * into the PCD struct!
  87636. + *
  87637. + */
  87638. +void do_test_mode(void *data)
  87639. +{
  87640. + dctl_data_t dctl;
  87641. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) data;
  87642. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  87643. + int test_mode = pcd->test_mode;
  87644. +
  87645. +// DWC_WARN("%s() has not been tested since being rewritten!\n", __func__);
  87646. +
  87647. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  87648. + switch (test_mode) {
  87649. + case 1: // TEST_J
  87650. + dctl.b.tstctl = 1;
  87651. + break;
  87652. +
  87653. + case 2: // TEST_K
  87654. + dctl.b.tstctl = 2;
  87655. + break;
  87656. +
  87657. + case 3: // TEST_SE0_NAK
  87658. + dctl.b.tstctl = 3;
  87659. + break;
  87660. +
  87661. + case 4: // TEST_PACKET
  87662. + dctl.b.tstctl = 4;
  87663. + break;
  87664. +
  87665. + case 5: // TEST_FORCE_ENABLE
  87666. + dctl.b.tstctl = 5;
  87667. + break;
  87668. + }
  87669. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  87670. +}
  87671. +
  87672. +/**
  87673. + * This function process the GET_STATUS Setup Commands.
  87674. + */
  87675. +static inline void do_get_status(dwc_otg_pcd_t * pcd)
  87676. +{
  87677. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  87678. + dwc_otg_pcd_ep_t *ep;
  87679. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  87680. + uint16_t *status = pcd->status_buf;
  87681. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  87682. +
  87683. +#ifdef DEBUG_EP0
  87684. + DWC_DEBUGPL(DBG_PCD,
  87685. + "GET_STATUS %02x.%02x v%04x i%04x l%04x\n",
  87686. + ctrl.bmRequestType, ctrl.bRequest,
  87687. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  87688. + UGETW(ctrl.wLength));
  87689. +#endif
  87690. +
  87691. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  87692. + case UT_DEVICE:
  87693. + if(UGETW(ctrl.wIndex) == 0xF000) { /* OTG Status selector */
  87694. + DWC_PRINTF("wIndex - %d\n", UGETW(ctrl.wIndex));
  87695. + DWC_PRINTF("OTG VERSION - %d\n", core_if->otg_ver);
  87696. + DWC_PRINTF("OTG CAP - %d, %d\n",
  87697. + core_if->core_params->otg_cap,
  87698. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE);
  87699. + if (core_if->otg_ver == 1
  87700. + && core_if->core_params->otg_cap ==
  87701. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  87702. + uint8_t *otgsts = (uint8_t*)pcd->status_buf;
  87703. + *otgsts = (core_if->otg_sts & 0x1);
  87704. + pcd->ep0_pending = 1;
  87705. + ep0->dwc_ep.start_xfer_buff =
  87706. + (uint8_t *) otgsts;
  87707. + ep0->dwc_ep.xfer_buff = (uint8_t *) otgsts;
  87708. + ep0->dwc_ep.dma_addr =
  87709. + pcd->status_buf_dma_handle;
  87710. + ep0->dwc_ep.xfer_len = 1;
  87711. + ep0->dwc_ep.xfer_count = 0;
  87712. + ep0->dwc_ep.total_len = ep0->dwc_ep.xfer_len;
  87713. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd),
  87714. + &ep0->dwc_ep);
  87715. + return;
  87716. + } else {
  87717. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  87718. + return;
  87719. + }
  87720. + break;
  87721. + } else {
  87722. + *status = 0x1; /* Self powered */
  87723. + *status |= pcd->remote_wakeup_enable << 1;
  87724. + break;
  87725. + }
  87726. + case UT_INTERFACE:
  87727. + *status = 0;
  87728. + break;
  87729. +
  87730. + case UT_ENDPOINT:
  87731. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  87732. + if (ep == 0 || UGETW(ctrl.wLength) > 2) {
  87733. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  87734. + return;
  87735. + }
  87736. + /** @todo check for EP stall */
  87737. + *status = ep->stopped;
  87738. + break;
  87739. + }
  87740. + pcd->ep0_pending = 1;
  87741. + ep0->dwc_ep.start_xfer_buff = (uint8_t *) status;
  87742. + ep0->dwc_ep.xfer_buff = (uint8_t *) status;
  87743. + ep0->dwc_ep.dma_addr = pcd->status_buf_dma_handle;
  87744. + ep0->dwc_ep.xfer_len = 2;
  87745. + ep0->dwc_ep.xfer_count = 0;
  87746. + ep0->dwc_ep.total_len = ep0->dwc_ep.xfer_len;
  87747. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  87748. +}
  87749. +
  87750. +/**
  87751. + * This function process the SET_FEATURE Setup Commands.
  87752. + */
  87753. +static inline void do_set_feature(dwc_otg_pcd_t * pcd)
  87754. +{
  87755. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  87756. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  87757. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  87758. + dwc_otg_pcd_ep_t *ep = 0;
  87759. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  87760. + gotgctl_data_t gotgctl = {.d32 = 0 };
  87761. +
  87762. + DWC_DEBUGPL(DBG_PCD, "SET_FEATURE:%02x.%02x v%04x i%04x l%04x\n",
  87763. + ctrl.bmRequestType, ctrl.bRequest,
  87764. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  87765. + UGETW(ctrl.wLength));
  87766. + DWC_DEBUGPL(DBG_PCD, "otg_cap=%d\n", otg_cap_param);
  87767. +
  87768. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  87769. + case UT_DEVICE:
  87770. + switch (UGETW(ctrl.wValue)) {
  87771. + case UF_DEVICE_REMOTE_WAKEUP:
  87772. + pcd->remote_wakeup_enable = 1;
  87773. + break;
  87774. +
  87775. + case UF_TEST_MODE:
  87776. + /* Setup the Test Mode tasklet to do the Test
  87777. + * Packet generation after the SETUP Status
  87778. + * phase has completed. */
  87779. +
  87780. + /** @todo This has not been tested since the
  87781. + * tasklet struct was put into the PCD
  87782. + * struct! */
  87783. + pcd->test_mode = UGETW(ctrl.wIndex) >> 8;
  87784. + DWC_TASK_SCHEDULE(pcd->test_mode_tasklet);
  87785. + break;
  87786. +
  87787. + case UF_DEVICE_B_HNP_ENABLE:
  87788. + DWC_DEBUGPL(DBG_PCDV,
  87789. + "SET_FEATURE: USB_DEVICE_B_HNP_ENABLE\n");
  87790. +
  87791. + /* dev may initiate HNP */
  87792. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  87793. + pcd->b_hnp_enable = 1;
  87794. + dwc_otg_pcd_update_otg(pcd, 0);
  87795. + DWC_DEBUGPL(DBG_PCD, "Request B HNP\n");
  87796. + /**@todo Is the gotgctl.devhnpen cleared
  87797. + * by a USB Reset? */
  87798. + gotgctl.b.devhnpen = 1;
  87799. + gotgctl.b.hnpreq = 1;
  87800. + DWC_WRITE_REG32(&global_regs->gotgctl,
  87801. + gotgctl.d32);
  87802. + } else {
  87803. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  87804. + return;
  87805. + }
  87806. + break;
  87807. +
  87808. + case UF_DEVICE_A_HNP_SUPPORT:
  87809. + /* RH port supports HNP */
  87810. + DWC_DEBUGPL(DBG_PCDV,
  87811. + "SET_FEATURE: USB_DEVICE_A_HNP_SUPPORT\n");
  87812. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  87813. + pcd->a_hnp_support = 1;
  87814. + dwc_otg_pcd_update_otg(pcd, 0);
  87815. + } else {
  87816. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  87817. + return;
  87818. + }
  87819. + break;
  87820. +
  87821. + case UF_DEVICE_A_ALT_HNP_SUPPORT:
  87822. + /* other RH port does */
  87823. + DWC_DEBUGPL(DBG_PCDV,
  87824. + "SET_FEATURE: USB_DEVICE_A_ALT_HNP_SUPPORT\n");
  87825. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  87826. + pcd->a_alt_hnp_support = 1;
  87827. + dwc_otg_pcd_update_otg(pcd, 0);
  87828. + } else {
  87829. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  87830. + return;
  87831. + }
  87832. + break;
  87833. +
  87834. + default:
  87835. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  87836. + return;
  87837. +
  87838. + }
  87839. + do_setup_in_status_phase(pcd);
  87840. + break;
  87841. +
  87842. + case UT_INTERFACE:
  87843. + do_gadget_setup(pcd, &ctrl);
  87844. + break;
  87845. +
  87846. + case UT_ENDPOINT:
  87847. + if (UGETW(ctrl.wValue) == UF_ENDPOINT_HALT) {
  87848. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  87849. + if (ep == 0) {
  87850. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  87851. + return;
  87852. + }
  87853. + ep->stopped = 1;
  87854. + dwc_otg_ep_set_stall(core_if, &ep->dwc_ep);
  87855. + }
  87856. + do_setup_in_status_phase(pcd);
  87857. + break;
  87858. + }
  87859. +}
  87860. +
  87861. +/**
  87862. + * This function process the CLEAR_FEATURE Setup Commands.
  87863. + */
  87864. +static inline void do_clear_feature(dwc_otg_pcd_t * pcd)
  87865. +{
  87866. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  87867. + dwc_otg_pcd_ep_t *ep = 0;
  87868. +
  87869. + DWC_DEBUGPL(DBG_PCD,
  87870. + "CLEAR_FEATURE:%02x.%02x v%04x i%04x l%04x\n",
  87871. + ctrl.bmRequestType, ctrl.bRequest,
  87872. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  87873. + UGETW(ctrl.wLength));
  87874. +
  87875. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  87876. + case UT_DEVICE:
  87877. + switch (UGETW(ctrl.wValue)) {
  87878. + case UF_DEVICE_REMOTE_WAKEUP:
  87879. + pcd->remote_wakeup_enable = 0;
  87880. + break;
  87881. +
  87882. + case UF_TEST_MODE:
  87883. + /** @todo Add CLEAR_FEATURE for TEST modes. */
  87884. + break;
  87885. +
  87886. + default:
  87887. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  87888. + return;
  87889. + }
  87890. + do_setup_in_status_phase(pcd);
  87891. + break;
  87892. +
  87893. + case UT_ENDPOINT:
  87894. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  87895. + if (ep == 0) {
  87896. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  87897. + return;
  87898. + }
  87899. +
  87900. + pcd_clear_halt(pcd, ep);
  87901. +
  87902. + break;
  87903. + }
  87904. +}
  87905. +
  87906. +/**
  87907. + * This function process the SET_ADDRESS Setup Commands.
  87908. + */
  87909. +static inline void do_set_address(dwc_otg_pcd_t * pcd)
  87910. +{
  87911. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  87912. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  87913. +
  87914. + if (ctrl.bmRequestType == UT_DEVICE) {
  87915. + dcfg_data_t dcfg = {.d32 = 0 };
  87916. +
  87917. +#ifdef DEBUG_EP0
  87918. +// DWC_DEBUGPL(DBG_PCDV, "SET_ADDRESS:%d\n", ctrl.wValue);
  87919. +#endif
  87920. + dcfg.b.devaddr = UGETW(ctrl.wValue);
  87921. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dcfg, 0, dcfg.d32);
  87922. + do_setup_in_status_phase(pcd);
  87923. + }
  87924. +}
  87925. +
  87926. +/**
  87927. + * This function processes SETUP commands. In Linux, the USB Command
  87928. + * processing is done in two places - the first being the PCD and the
  87929. + * second in the Gadget Driver (for example, the File-Backed Storage
  87930. + * Gadget Driver).
  87931. + *
  87932. + * <table>
  87933. + * <tr><td>Command </td><td>Driver </td><td>Description</td></tr>
  87934. + *
  87935. + * <tr><td>GET_STATUS </td><td>PCD </td><td>Command is processed as
  87936. + * defined in chapter 9 of the USB 2.0 Specification chapter 9
  87937. + * </td></tr>
  87938. + *
  87939. + * <tr><td>CLEAR_FEATURE </td><td>PCD </td><td>The Device and Endpoint
  87940. + * requests are the ENDPOINT_HALT feature is procesed, all others the
  87941. + * interface requests are ignored.</td></tr>
  87942. + *
  87943. + * <tr><td>SET_FEATURE </td><td>PCD </td><td>The Device and Endpoint
  87944. + * requests are processed by the PCD. Interface requests are passed
  87945. + * to the Gadget Driver.</td></tr>
  87946. + *
  87947. + * <tr><td>SET_ADDRESS </td><td>PCD </td><td>Program the DCFG reg,
  87948. + * with device address received </td></tr>
  87949. + *
  87950. + * <tr><td>GET_DESCRIPTOR </td><td>Gadget Driver </td><td>Return the
  87951. + * requested descriptor</td></tr>
  87952. + *
  87953. + * <tr><td>SET_DESCRIPTOR </td><td>Gadget Driver </td><td>Optional -
  87954. + * not implemented by any of the existing Gadget Drivers.</td></tr>
  87955. + *
  87956. + * <tr><td>SET_CONFIGURATION </td><td>Gadget Driver </td><td>Disable
  87957. + * all EPs and enable EPs for new configuration.</td></tr>
  87958. + *
  87959. + * <tr><td>GET_CONFIGURATION </td><td>Gadget Driver </td><td>Return
  87960. + * the current configuration</td></tr>
  87961. + *
  87962. + * <tr><td>SET_INTERFACE </td><td>Gadget Driver </td><td>Disable all
  87963. + * EPs and enable EPs for new configuration.</td></tr>
  87964. + *
  87965. + * <tr><td>GET_INTERFACE </td><td>Gadget Driver </td><td>Return the
  87966. + * current interface.</td></tr>
  87967. + *
  87968. + * <tr><td>SYNC_FRAME </td><td>PCD </td><td>Display debug
  87969. + * message.</td></tr>
  87970. + * </table>
  87971. + *
  87972. + * When the SETUP Phase Done interrupt occurs, the PCD SETUP commands are
  87973. + * processed by pcd_setup. Calling the Function Driver's setup function from
  87974. + * pcd_setup processes the gadget SETUP commands.
  87975. + */
  87976. +static inline void pcd_setup(dwc_otg_pcd_t * pcd)
  87977. +{
  87978. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  87979. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  87980. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  87981. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  87982. +
  87983. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  87984. +
  87985. +#ifdef DWC_UTE_CFI
  87986. + int retval = 0;
  87987. + struct cfi_usb_ctrlrequest cfi_req;
  87988. +#endif
  87989. +
  87990. + doeptsize0.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doeptsiz);
  87991. +
  87992. + /** In BDMA more then 1 setup packet is not supported till 3.00a */
  87993. + if (core_if->dma_enable && core_if->dma_desc_enable == 0
  87994. + && (doeptsize0.b.supcnt < 2)
  87995. + && (core_if->snpsid < OTG_CORE_REV_2_94a)) {
  87996. + DWC_ERROR
  87997. + ("\n\n----------- CANNOT handle > 1 setup packet in DMA mode\n\n");
  87998. + }
  87999. + if ((core_if->snpsid >= OTG_CORE_REV_3_00a)
  88000. + && (core_if->dma_enable == 1) && (core_if->dma_desc_enable == 0)) {
  88001. + ctrl =
  88002. + (pcd->setup_pkt +
  88003. + (3 - doeptsize0.b.supcnt - 1 +
  88004. + ep0->dwc_ep.stp_rollover))->req;
  88005. + }
  88006. +#ifdef DEBUG_EP0
  88007. + DWC_DEBUGPL(DBG_PCD, "SETUP %02x.%02x v%04x i%04x l%04x\n",
  88008. + ctrl.bmRequestType, ctrl.bRequest,
  88009. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  88010. + UGETW(ctrl.wLength));
  88011. +#endif
  88012. +
  88013. + /* Clean up the request queue */
  88014. + dwc_otg_request_nuke(ep0);
  88015. + ep0->stopped = 0;
  88016. +
  88017. + if (ctrl.bmRequestType & UE_DIR_IN) {
  88018. + ep0->dwc_ep.is_in = 1;
  88019. + pcd->ep0state = EP0_IN_DATA_PHASE;
  88020. + } else {
  88021. + ep0->dwc_ep.is_in = 0;
  88022. + pcd->ep0state = EP0_OUT_DATA_PHASE;
  88023. + }
  88024. +
  88025. + if (UGETW(ctrl.wLength) == 0) {
  88026. + ep0->dwc_ep.is_in = 1;
  88027. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  88028. + }
  88029. +
  88030. + if (UT_GET_TYPE(ctrl.bmRequestType) != UT_STANDARD) {
  88031. +
  88032. +#ifdef DWC_UTE_CFI
  88033. + DWC_MEMCPY(&cfi_req, &ctrl, sizeof(usb_device_request_t));
  88034. +
  88035. + //printk(KERN_ALERT "CFI: req_type=0x%02x; req=0x%02x\n",
  88036. + ctrl.bRequestType, ctrl.bRequest);
  88037. + if (UT_GET_TYPE(cfi_req.bRequestType) == UT_VENDOR) {
  88038. + if (cfi_req.bRequest > 0xB0 && cfi_req.bRequest < 0xBF) {
  88039. + retval = cfi_setup(pcd, &cfi_req);
  88040. + if (retval < 0) {
  88041. + ep0_do_stall(pcd, retval);
  88042. + pcd->ep0_pending = 0;
  88043. + return;
  88044. + }
  88045. +
  88046. + /* if need gadget setup then call it and check the retval */
  88047. + if (pcd->cfi->need_gadget_att) {
  88048. + retval =
  88049. + cfi_gadget_setup(pcd,
  88050. + &pcd->
  88051. + cfi->ctrl_req);
  88052. + if (retval < 0) {
  88053. + pcd->ep0_pending = 0;
  88054. + return;
  88055. + }
  88056. + }
  88057. +
  88058. + if (pcd->cfi->need_status_in_complete) {
  88059. + do_setup_in_status_phase(pcd);
  88060. + }
  88061. + return;
  88062. + }
  88063. + }
  88064. +#endif
  88065. +
  88066. + /* handle non-standard (class/vendor) requests in the gadget driver */
  88067. + do_gadget_setup(pcd, &ctrl);
  88068. + return;
  88069. + }
  88070. +
  88071. + /** @todo NGS: Handle bad setup packet? */
  88072. +
  88073. +///////////////////////////////////////////
  88074. +//// --- Standard Request handling --- ////
  88075. +
  88076. + switch (ctrl.bRequest) {
  88077. + case UR_GET_STATUS:
  88078. + do_get_status(pcd);
  88079. + break;
  88080. +
  88081. + case UR_CLEAR_FEATURE:
  88082. + do_clear_feature(pcd);
  88083. + break;
  88084. +
  88085. + case UR_SET_FEATURE:
  88086. + do_set_feature(pcd);
  88087. + break;
  88088. +
  88089. + case UR_SET_ADDRESS:
  88090. + do_set_address(pcd);
  88091. + break;
  88092. +
  88093. + case UR_SET_INTERFACE:
  88094. + case UR_SET_CONFIG:
  88095. +// _pcd->request_config = 1; /* Configuration changed */
  88096. + do_gadget_setup(pcd, &ctrl);
  88097. + break;
  88098. +
  88099. + case UR_SYNCH_FRAME:
  88100. + do_gadget_setup(pcd, &ctrl);
  88101. + break;
  88102. +
  88103. + default:
  88104. + /* Call the Gadget Driver's setup functions */
  88105. + do_gadget_setup(pcd, &ctrl);
  88106. + break;
  88107. + }
  88108. +}
  88109. +
  88110. +/**
  88111. + * This function completes the ep0 control transfer.
  88112. + */
  88113. +static int32_t ep0_complete_request(dwc_otg_pcd_ep_t * ep)
  88114. +{
  88115. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  88116. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  88117. + dwc_otg_dev_in_ep_regs_t *in_ep_regs =
  88118. + dev_if->in_ep_regs[ep->dwc_ep.num];
  88119. +#ifdef DEBUG_EP0
  88120. + dwc_otg_dev_out_ep_regs_t *out_ep_regs =
  88121. + dev_if->out_ep_regs[ep->dwc_ep.num];
  88122. +#endif
  88123. + deptsiz0_data_t deptsiz;
  88124. + dev_dma_desc_sts_t desc_sts;
  88125. + dwc_otg_pcd_request_t *req;
  88126. + int is_last = 0;
  88127. + dwc_otg_pcd_t *pcd = ep->pcd;
  88128. +
  88129. +#ifdef DWC_UTE_CFI
  88130. + struct cfi_usb_ctrlrequest *ctrlreq;
  88131. + int retval = -DWC_E_NOT_SUPPORTED;
  88132. +#endif
  88133. +
  88134. + desc_sts.b.bytes = 0;
  88135. +
  88136. + if (pcd->ep0_pending && DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  88137. + if (ep->dwc_ep.is_in) {
  88138. +#ifdef DEBUG_EP0
  88139. + DWC_DEBUGPL(DBG_PCDV, "Do setup OUT status phase\n");
  88140. +#endif
  88141. + do_setup_out_status_phase(pcd);
  88142. + } else {
  88143. +#ifdef DEBUG_EP0
  88144. + DWC_DEBUGPL(DBG_PCDV, "Do setup IN status phase\n");
  88145. +#endif
  88146. +
  88147. +#ifdef DWC_UTE_CFI
  88148. + ctrlreq = &pcd->cfi->ctrl_req;
  88149. +
  88150. + if (UT_GET_TYPE(ctrlreq->bRequestType) == UT_VENDOR) {
  88151. + if (ctrlreq->bRequest > 0xB0
  88152. + && ctrlreq->bRequest < 0xBF) {
  88153. +
  88154. + /* Return if the PCD failed to handle the request */
  88155. + if ((retval =
  88156. + pcd->cfi->ops.
  88157. + ctrl_write_complete(pcd->cfi,
  88158. + pcd)) < 0) {
  88159. + CFI_INFO
  88160. + ("ERROR setting a new value in the PCD(%d)\n",
  88161. + retval);
  88162. + ep0_do_stall(pcd, retval);
  88163. + pcd->ep0_pending = 0;
  88164. + return 0;
  88165. + }
  88166. +
  88167. + /* If the gadget needs to be notified on the request */
  88168. + if (pcd->cfi->need_gadget_att == 1) {
  88169. + //retval = do_gadget_setup(pcd, &pcd->cfi->ctrl_req);
  88170. + retval =
  88171. + cfi_gadget_setup(pcd,
  88172. + &pcd->cfi->
  88173. + ctrl_req);
  88174. +
  88175. + /* Return from the function if the gadget failed to process
  88176. + * the request properly - this should never happen !!!
  88177. + */
  88178. + if (retval < 0) {
  88179. + CFI_INFO
  88180. + ("ERROR setting a new value in the gadget(%d)\n",
  88181. + retval);
  88182. + pcd->ep0_pending = 0;
  88183. + return 0;
  88184. + }
  88185. + }
  88186. +
  88187. + CFI_INFO("%s: RETVAL=%d\n", __func__,
  88188. + retval);
  88189. + /* If we hit here then the PCD and the gadget has properly
  88190. + * handled the request - so send the ZLP IN to the host.
  88191. + */
  88192. + /* @todo: MAS - decide whether we need to start the setup
  88193. + * stage based on the need_setup value of the cfi object
  88194. + */
  88195. + do_setup_in_status_phase(pcd);
  88196. + pcd->ep0_pending = 0;
  88197. + return 1;
  88198. + }
  88199. + }
  88200. +#endif
  88201. +
  88202. + do_setup_in_status_phase(pcd);
  88203. + }
  88204. + pcd->ep0_pending = 0;
  88205. + return 1;
  88206. + }
  88207. +
  88208. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  88209. + return 0;
  88210. + }
  88211. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  88212. +
  88213. + if (pcd->ep0state == EP0_OUT_STATUS_PHASE
  88214. + || pcd->ep0state == EP0_IN_STATUS_PHASE) {
  88215. + is_last = 1;
  88216. + } else if (ep->dwc_ep.is_in) {
  88217. + deptsiz.d32 = DWC_READ_REG32(&in_ep_regs->dieptsiz);
  88218. + if (core_if->dma_desc_enable != 0)
  88219. + desc_sts = dev_if->in_desc_addr->status;
  88220. +#ifdef DEBUG_EP0
  88221. + DWC_DEBUGPL(DBG_PCDV, "%d len=%d xfersize=%d pktcnt=%d\n",
  88222. + ep->dwc_ep.num, ep->dwc_ep.xfer_len,
  88223. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  88224. +#endif
  88225. +
  88226. + if (((core_if->dma_desc_enable == 0)
  88227. + && (deptsiz.b.xfersize == 0))
  88228. + || ((core_if->dma_desc_enable != 0)
  88229. + && (desc_sts.b.bytes == 0))) {
  88230. + req->actual = ep->dwc_ep.xfer_count;
  88231. + /* Is a Zero Len Packet needed? */
  88232. + if (req->sent_zlp) {
  88233. +#ifdef DEBUG_EP0
  88234. + DWC_DEBUGPL(DBG_PCD, "Setup Rx ZLP\n");
  88235. +#endif
  88236. + req->sent_zlp = 0;
  88237. + }
  88238. + do_setup_out_status_phase(pcd);
  88239. + }
  88240. + } else {
  88241. + /* ep0-OUT */
  88242. +#ifdef DEBUG_EP0
  88243. + deptsiz.d32 = DWC_READ_REG32(&out_ep_regs->doeptsiz);
  88244. + DWC_DEBUGPL(DBG_PCDV, "%d len=%d xsize=%d pktcnt=%d\n",
  88245. + ep->dwc_ep.num, ep->dwc_ep.xfer_len,
  88246. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  88247. +#endif
  88248. + req->actual = ep->dwc_ep.xfer_count;
  88249. +
  88250. + /* Is a Zero Len Packet needed? */
  88251. + if (req->sent_zlp) {
  88252. +#ifdef DEBUG_EP0
  88253. + DWC_DEBUGPL(DBG_PCDV, "Setup Tx ZLP\n");
  88254. +#endif
  88255. + req->sent_zlp = 0;
  88256. + }
  88257. + /* For older cores do setup in status phase in Slave/BDMA modes,
  88258. + * starting from 3.00 do that only in slave, and for DMA modes
  88259. + * just re-enable ep 0 OUT here*/
  88260. + if (core_if->dma_enable == 0
  88261. + || (core_if->dma_desc_enable == 0
  88262. + && core_if->snpsid <= OTG_CORE_REV_2_94a)) {
  88263. + do_setup_in_status_phase(pcd);
  88264. + } else if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  88265. + DWC_DEBUGPL(DBG_PCDV,
  88266. + "Enable out ep before in status phase\n");
  88267. + ep0_out_start(core_if, pcd);
  88268. + }
  88269. + }
  88270. +
  88271. + /* Complete the request */
  88272. + if (is_last) {
  88273. + dwc_otg_request_done(ep, req, 0);
  88274. + ep->dwc_ep.start_xfer_buff = 0;
  88275. + ep->dwc_ep.xfer_buff = 0;
  88276. + ep->dwc_ep.xfer_len = 0;
  88277. + return 1;
  88278. + }
  88279. + return 0;
  88280. +}
  88281. +
  88282. +#ifdef DWC_UTE_CFI
  88283. +/**
  88284. + * This function calculates traverses all the CFI DMA descriptors and
  88285. + * and accumulates the bytes that are left to be transfered.
  88286. + *
  88287. + * @return The total bytes left to transfered, or a negative value as failure
  88288. + */
  88289. +static inline int cfi_calc_desc_residue(dwc_otg_pcd_ep_t * ep)
  88290. +{
  88291. + int32_t ret = 0;
  88292. + int i;
  88293. + struct dwc_otg_dma_desc *ddesc = NULL;
  88294. + struct cfi_ep *cfiep;
  88295. +
  88296. + /* See if the pcd_ep has its respective cfi_ep mapped */
  88297. + cfiep = get_cfi_ep_by_pcd_ep(ep->pcd->cfi, ep);
  88298. + if (!cfiep) {
  88299. + CFI_INFO("%s: Failed to find ep\n", __func__);
  88300. + return -1;
  88301. + }
  88302. +
  88303. + ddesc = ep->dwc_ep.descs;
  88304. +
  88305. + for (i = 0; (i < cfiep->desc_count) && (i < MAX_DMA_DESCS_PER_EP); i++) {
  88306. +
  88307. +#if defined(PRINT_CFI_DMA_DESCS)
  88308. + print_desc(ddesc, ep->ep.name, i);
  88309. +#endif
  88310. + ret += ddesc->status.b.bytes;
  88311. + ddesc++;
  88312. + }
  88313. +
  88314. + if (ret)
  88315. + CFI_INFO("!!!!!!!!!! WARNING (%s) - residue=%d\n", __func__,
  88316. + ret);
  88317. +
  88318. + return ret;
  88319. +}
  88320. +#endif
  88321. +
  88322. +/**
  88323. + * This function completes the request for the EP. If there are
  88324. + * additional requests for the EP in the queue they will be started.
  88325. + */
  88326. +static void complete_ep(dwc_otg_pcd_ep_t * ep)
  88327. +{
  88328. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  88329. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  88330. + dwc_otg_dev_in_ep_regs_t *in_ep_regs =
  88331. + dev_if->in_ep_regs[ep->dwc_ep.num];
  88332. + deptsiz_data_t deptsiz;
  88333. + dev_dma_desc_sts_t desc_sts;
  88334. + dwc_otg_pcd_request_t *req = 0;
  88335. + dwc_otg_dev_dma_desc_t *dma_desc;
  88336. + uint32_t byte_count = 0;
  88337. + int is_last = 0;
  88338. + int i;
  88339. +
  88340. + DWC_DEBUGPL(DBG_PCDV, "%s() %d-%s\n", __func__, ep->dwc_ep.num,
  88341. + (ep->dwc_ep.is_in ? "IN" : "OUT"));
  88342. +
  88343. + /* Get any pending requests */
  88344. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  88345. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  88346. + if (!req) {
  88347. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  88348. + return;
  88349. + }
  88350. + } else {
  88351. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  88352. + return;
  88353. + }
  88354. +
  88355. + DWC_DEBUGPL(DBG_PCD, "Requests %d\n", ep->pcd->request_pending);
  88356. +
  88357. + if (ep->dwc_ep.is_in) {
  88358. + deptsiz.d32 = DWC_READ_REG32(&in_ep_regs->dieptsiz);
  88359. +
  88360. + if (core_if->dma_enable) {
  88361. + if (core_if->dma_desc_enable == 0) {
  88362. + if (deptsiz.b.xfersize == 0
  88363. + && deptsiz.b.pktcnt == 0) {
  88364. + byte_count =
  88365. + ep->dwc_ep.xfer_len -
  88366. + ep->dwc_ep.xfer_count;
  88367. +
  88368. + ep->dwc_ep.xfer_buff += byte_count;
  88369. + ep->dwc_ep.dma_addr += byte_count;
  88370. + ep->dwc_ep.xfer_count += byte_count;
  88371. +
  88372. + DWC_DEBUGPL(DBG_PCDV,
  88373. + "%d-%s len=%d xfersize=%d pktcnt=%d\n",
  88374. + ep->dwc_ep.num,
  88375. + (ep->dwc_ep.
  88376. + is_in ? "IN" : "OUT"),
  88377. + ep->dwc_ep.xfer_len,
  88378. + deptsiz.b.xfersize,
  88379. + deptsiz.b.pktcnt);
  88380. +
  88381. + if (ep->dwc_ep.xfer_len <
  88382. + ep->dwc_ep.total_len) {
  88383. + dwc_otg_ep_start_transfer
  88384. + (core_if, &ep->dwc_ep);
  88385. + } else if (ep->dwc_ep.sent_zlp) {
  88386. + /*
  88387. + * This fragment of code should initiate 0
  88388. + * length transfer in case if it is queued
  88389. + * a transfer with size divisible to EPs max
  88390. + * packet size and with usb_request zero field
  88391. + * is set, which means that after data is transfered,
  88392. + * it is also should be transfered
  88393. + * a 0 length packet at the end. For Slave and
  88394. + * Buffer DMA modes in this case SW has
  88395. + * to initiate 2 transfers one with transfer size,
  88396. + * and the second with 0 size. For Descriptor
  88397. + * DMA mode SW is able to initiate a transfer,
  88398. + * which will handle all the packets including
  88399. + * the last 0 length.
  88400. + */
  88401. + ep->dwc_ep.sent_zlp = 0;
  88402. + dwc_otg_ep_start_zl_transfer
  88403. + (core_if, &ep->dwc_ep);
  88404. + } else {
  88405. + is_last = 1;
  88406. + }
  88407. + } else {
  88408. + if (ep->dwc_ep.type ==
  88409. + DWC_OTG_EP_TYPE_ISOC) {
  88410. + req->actual = 0;
  88411. + dwc_otg_request_done(ep, req, 0);
  88412. +
  88413. + ep->dwc_ep.start_xfer_buff = 0;
  88414. + ep->dwc_ep.xfer_buff = 0;
  88415. + ep->dwc_ep.xfer_len = 0;
  88416. +
  88417. + /* If there is a request in the queue start it. */
  88418. + start_next_request(ep);
  88419. + } else
  88420. + DWC_WARN
  88421. + ("Incomplete transfer (%d - %s [siz=%d pkt=%d])\n",
  88422. + ep->dwc_ep.num,
  88423. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  88424. + deptsiz.b.xfersize,
  88425. + deptsiz.b.pktcnt);
  88426. + }
  88427. + } else {
  88428. + dma_desc = ep->dwc_ep.desc_addr;
  88429. + byte_count = 0;
  88430. + ep->dwc_ep.sent_zlp = 0;
  88431. +
  88432. +#ifdef DWC_UTE_CFI
  88433. + CFI_INFO("%s: BUFFER_MODE=%d\n", __func__,
  88434. + ep->dwc_ep.buff_mode);
  88435. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  88436. + int residue;
  88437. +
  88438. + residue = cfi_calc_desc_residue(ep);
  88439. + if (residue < 0)
  88440. + return;
  88441. +
  88442. + byte_count = residue;
  88443. + } else {
  88444. +#endif
  88445. + for (i = 0; i < ep->dwc_ep.desc_cnt;
  88446. + ++i) {
  88447. + desc_sts = dma_desc->status;
  88448. + byte_count += desc_sts.b.bytes;
  88449. + dma_desc++;
  88450. + }
  88451. +#ifdef DWC_UTE_CFI
  88452. + }
  88453. +#endif
  88454. + if (byte_count == 0) {
  88455. + ep->dwc_ep.xfer_count =
  88456. + ep->dwc_ep.total_len;
  88457. + is_last = 1;
  88458. + } else {
  88459. + DWC_WARN("Incomplete transfer\n");
  88460. + }
  88461. + }
  88462. + } else {
  88463. + if (deptsiz.b.xfersize == 0 && deptsiz.b.pktcnt == 0) {
  88464. + DWC_DEBUGPL(DBG_PCDV,
  88465. + "%d-%s len=%d xfersize=%d pktcnt=%d\n",
  88466. + ep->dwc_ep.num,
  88467. + ep->dwc_ep.is_in ? "IN" : "OUT",
  88468. + ep->dwc_ep.xfer_len,
  88469. + deptsiz.b.xfersize,
  88470. + deptsiz.b.pktcnt);
  88471. +
  88472. + /* Check if the whole transfer was completed,
  88473. + * if no, setup transfer for next portion of data
  88474. + */
  88475. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  88476. + dwc_otg_ep_start_transfer(core_if,
  88477. + &ep->dwc_ep);
  88478. + } else if (ep->dwc_ep.sent_zlp) {
  88479. + /*
  88480. + * This fragment of code should initiate 0
  88481. + * length trasfer in case if it is queued
  88482. + * a trasfer with size divisible to EPs max
  88483. + * packet size and with usb_request zero field
  88484. + * is set, which means that after data is transfered,
  88485. + * it is also should be transfered
  88486. + * a 0 length packet at the end. For Slave and
  88487. + * Buffer DMA modes in this case SW has
  88488. + * to initiate 2 transfers one with transfer size,
  88489. + * and the second with 0 size. For Desriptor
  88490. + * DMA mode SW is able to initiate a transfer,
  88491. + * which will handle all the packets including
  88492. + * the last 0 legth.
  88493. + */
  88494. + ep->dwc_ep.sent_zlp = 0;
  88495. + dwc_otg_ep_start_zl_transfer(core_if,
  88496. + &ep->dwc_ep);
  88497. + } else {
  88498. + is_last = 1;
  88499. + }
  88500. + } else {
  88501. + DWC_WARN
  88502. + ("Incomplete transfer (%d-%s [siz=%d pkt=%d])\n",
  88503. + ep->dwc_ep.num,
  88504. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  88505. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  88506. + }
  88507. + }
  88508. + } else {
  88509. + dwc_otg_dev_out_ep_regs_t *out_ep_regs =
  88510. + dev_if->out_ep_regs[ep->dwc_ep.num];
  88511. + desc_sts.d32 = 0;
  88512. + if (core_if->dma_enable) {
  88513. + if (core_if->dma_desc_enable) {
  88514. + dma_desc = ep->dwc_ep.desc_addr;
  88515. + byte_count = 0;
  88516. + ep->dwc_ep.sent_zlp = 0;
  88517. +
  88518. +#ifdef DWC_UTE_CFI
  88519. + CFI_INFO("%s: BUFFER_MODE=%d\n", __func__,
  88520. + ep->dwc_ep.buff_mode);
  88521. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  88522. + int residue;
  88523. + residue = cfi_calc_desc_residue(ep);
  88524. + if (residue < 0)
  88525. + return;
  88526. + byte_count = residue;
  88527. + } else {
  88528. +#endif
  88529. +
  88530. + for (i = 0; i < ep->dwc_ep.desc_cnt;
  88531. + ++i) {
  88532. + desc_sts = dma_desc->status;
  88533. + byte_count += desc_sts.b.bytes;
  88534. + dma_desc++;
  88535. + }
  88536. +
  88537. +#ifdef DWC_UTE_CFI
  88538. + }
  88539. +#endif
  88540. + /* Checking for interrupt Out transfers with not
  88541. + * dword aligned mps sizes
  88542. + */
  88543. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_INTR &&
  88544. + (ep->dwc_ep.maxpacket%4)) {
  88545. + ep->dwc_ep.xfer_count =
  88546. + ep->dwc_ep.total_len - byte_count;
  88547. + if ((ep->dwc_ep.xfer_len %
  88548. + ep->dwc_ep.maxpacket)
  88549. + && (ep->dwc_ep.xfer_len /
  88550. + ep->dwc_ep.maxpacket <
  88551. + MAX_DMA_DESC_CNT))
  88552. + ep->dwc_ep.xfer_len -=
  88553. + (ep->dwc_ep.desc_cnt -
  88554. + 1) * ep->dwc_ep.maxpacket +
  88555. + ep->dwc_ep.xfer_len %
  88556. + ep->dwc_ep.maxpacket;
  88557. + else
  88558. + ep->dwc_ep.xfer_len -=
  88559. + ep->dwc_ep.desc_cnt *
  88560. + ep->dwc_ep.maxpacket;
  88561. + if (ep->dwc_ep.xfer_len > 0) {
  88562. + dwc_otg_ep_start_transfer
  88563. + (core_if, &ep->dwc_ep);
  88564. + } else {
  88565. + is_last = 1;
  88566. + }
  88567. + } else {
  88568. + ep->dwc_ep.xfer_count =
  88569. + ep->dwc_ep.total_len - byte_count +
  88570. + ((4 -
  88571. + (ep->dwc_ep.
  88572. + total_len & 0x3)) & 0x3);
  88573. + is_last = 1;
  88574. + }
  88575. + } else {
  88576. + deptsiz.d32 = 0;
  88577. + deptsiz.d32 =
  88578. + DWC_READ_REG32(&out_ep_regs->doeptsiz);
  88579. +
  88580. + byte_count = (ep->dwc_ep.xfer_len -
  88581. + ep->dwc_ep.xfer_count -
  88582. + deptsiz.b.xfersize);
  88583. + ep->dwc_ep.xfer_buff += byte_count;
  88584. + ep->dwc_ep.dma_addr += byte_count;
  88585. + ep->dwc_ep.xfer_count += byte_count;
  88586. +
  88587. + /* Check if the whole transfer was completed,
  88588. + * if no, setup transfer for next portion of data
  88589. + */
  88590. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  88591. + dwc_otg_ep_start_transfer(core_if,
  88592. + &ep->dwc_ep);
  88593. + } else if (ep->dwc_ep.sent_zlp) {
  88594. + /*
  88595. + * This fragment of code should initiate 0
  88596. + * length trasfer in case if it is queued
  88597. + * a trasfer with size divisible to EPs max
  88598. + * packet size and with usb_request zero field
  88599. + * is set, which means that after data is transfered,
  88600. + * it is also should be transfered
  88601. + * a 0 length packet at the end. For Slave and
  88602. + * Buffer DMA modes in this case SW has
  88603. + * to initiate 2 transfers one with transfer size,
  88604. + * and the second with 0 size. For Desriptor
  88605. + * DMA mode SW is able to initiate a transfer,
  88606. + * which will handle all the packets including
  88607. + * the last 0 legth.
  88608. + */
  88609. + ep->dwc_ep.sent_zlp = 0;
  88610. + dwc_otg_ep_start_zl_transfer(core_if,
  88611. + &ep->dwc_ep);
  88612. + } else {
  88613. + is_last = 1;
  88614. + }
  88615. + }
  88616. + } else {
  88617. + /* Check if the whole transfer was completed,
  88618. + * if no, setup transfer for next portion of data
  88619. + */
  88620. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  88621. + dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
  88622. + } else if (ep->dwc_ep.sent_zlp) {
  88623. + /*
  88624. + * This fragment of code should initiate 0
  88625. + * length transfer in case if it is queued
  88626. + * a transfer with size divisible to EPs max
  88627. + * packet size and with usb_request zero field
  88628. + * is set, which means that after data is transfered,
  88629. + * it is also should be transfered
  88630. + * a 0 length packet at the end. For Slave and
  88631. + * Buffer DMA modes in this case SW has
  88632. + * to initiate 2 transfers one with transfer size,
  88633. + * and the second with 0 size. For Descriptor
  88634. + * DMA mode SW is able to initiate a transfer,
  88635. + * which will handle all the packets including
  88636. + * the last 0 length.
  88637. + */
  88638. + ep->dwc_ep.sent_zlp = 0;
  88639. + dwc_otg_ep_start_zl_transfer(core_if,
  88640. + &ep->dwc_ep);
  88641. + } else {
  88642. + is_last = 1;
  88643. + }
  88644. + }
  88645. +
  88646. + DWC_DEBUGPL(DBG_PCDV,
  88647. + "addr %p, %d-%s len=%d cnt=%d xsize=%d pktcnt=%d\n",
  88648. + &out_ep_regs->doeptsiz, ep->dwc_ep.num,
  88649. + ep->dwc_ep.is_in ? "IN" : "OUT",
  88650. + ep->dwc_ep.xfer_len, ep->dwc_ep.xfer_count,
  88651. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  88652. + }
  88653. +
  88654. + /* Complete the request */
  88655. + if (is_last) {
  88656. +#ifdef DWC_UTE_CFI
  88657. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  88658. + req->actual = ep->dwc_ep.cfi_req_len - byte_count;
  88659. + } else {
  88660. +#endif
  88661. + req->actual = ep->dwc_ep.xfer_count;
  88662. +#ifdef DWC_UTE_CFI
  88663. + }
  88664. +#endif
  88665. + if (req->dw_align_buf) {
  88666. + if (!ep->dwc_ep.is_in) {
  88667. + dwc_memcpy(req->buf, req->dw_align_buf, req->length);
  88668. + }
  88669. + DWC_DMA_FREE(req->length, req->dw_align_buf,
  88670. + req->dw_align_buf_dma);
  88671. + }
  88672. +
  88673. + dwc_otg_request_done(ep, req, 0);
  88674. +
  88675. + ep->dwc_ep.start_xfer_buff = 0;
  88676. + ep->dwc_ep.xfer_buff = 0;
  88677. + ep->dwc_ep.xfer_len = 0;
  88678. +
  88679. + /* If there is a request in the queue start it. */
  88680. + start_next_request(ep);
  88681. + }
  88682. +}
  88683. +
  88684. +#ifdef DWC_EN_ISOC
  88685. +
  88686. +/**
  88687. + * This function BNA interrupt for Isochronous EPs
  88688. + *
  88689. + */
  88690. +static void dwc_otg_pcd_handle_iso_bna(dwc_otg_pcd_ep_t * ep)
  88691. +{
  88692. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  88693. + volatile uint32_t *addr;
  88694. + depctl_data_t depctl = {.d32 = 0 };
  88695. + dwc_otg_pcd_t *pcd = ep->pcd;
  88696. + dwc_otg_dev_dma_desc_t *dma_desc;
  88697. + int i;
  88698. +
  88699. + dma_desc =
  88700. + dwc_ep->iso_desc_addr + dwc_ep->desc_cnt * (dwc_ep->proc_buf_num);
  88701. +
  88702. + if (dwc_ep->is_in) {
  88703. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  88704. + for (i = 0; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  88705. + sts.d32 = dma_desc->status.d32;
  88706. + sts.b_iso_in.bs = BS_HOST_READY;
  88707. + dma_desc->status.d32 = sts.d32;
  88708. + }
  88709. + } else {
  88710. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  88711. + for (i = 0; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  88712. + sts.d32 = dma_desc->status.d32;
  88713. + sts.b_iso_out.bs = BS_HOST_READY;
  88714. + dma_desc->status.d32 = sts.d32;
  88715. + }
  88716. + }
  88717. +
  88718. + if (dwc_ep->is_in == 0) {
  88719. + addr =
  88720. + &GET_CORE_IF(pcd)->dev_if->out_ep_regs[dwc_ep->
  88721. + num]->doepctl;
  88722. + } else {
  88723. + addr =
  88724. + &GET_CORE_IF(pcd)->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  88725. + }
  88726. + depctl.b.epena = 1;
  88727. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  88728. +}
  88729. +
  88730. +/**
  88731. + * This function sets latest iso packet information(non-PTI mode)
  88732. + *
  88733. + * @param core_if Programming view of DWC_otg controller.
  88734. + * @param ep The EP to start the transfer on.
  88735. + *
  88736. + */
  88737. +void set_current_pkt_info(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  88738. +{
  88739. + deptsiz_data_t deptsiz = {.d32 = 0 };
  88740. + dma_addr_t dma_addr;
  88741. + uint32_t offset;
  88742. +
  88743. + if (ep->proc_buf_num)
  88744. + dma_addr = ep->dma_addr1;
  88745. + else
  88746. + dma_addr = ep->dma_addr0;
  88747. +
  88748. + if (ep->is_in) {
  88749. + deptsiz.d32 =
  88750. + DWC_READ_REG32(&core_if->dev_if->
  88751. + in_ep_regs[ep->num]->dieptsiz);
  88752. + offset = ep->data_per_frame;
  88753. + } else {
  88754. + deptsiz.d32 =
  88755. + DWC_READ_REG32(&core_if->dev_if->
  88756. + out_ep_regs[ep->num]->doeptsiz);
  88757. + offset =
  88758. + ep->data_per_frame +
  88759. + (0x4 & (0x4 - (ep->data_per_frame & 0x3)));
  88760. + }
  88761. +
  88762. + if (!deptsiz.b.xfersize) {
  88763. + ep->pkt_info[ep->cur_pkt].length = ep->data_per_frame;
  88764. + ep->pkt_info[ep->cur_pkt].offset =
  88765. + ep->cur_pkt_dma_addr - dma_addr;
  88766. + ep->pkt_info[ep->cur_pkt].status = 0;
  88767. + } else {
  88768. + ep->pkt_info[ep->cur_pkt].length = ep->data_per_frame;
  88769. + ep->pkt_info[ep->cur_pkt].offset =
  88770. + ep->cur_pkt_dma_addr - dma_addr;
  88771. + ep->pkt_info[ep->cur_pkt].status = -DWC_E_NO_DATA;
  88772. + }
  88773. + ep->cur_pkt_addr += offset;
  88774. + ep->cur_pkt_dma_addr += offset;
  88775. + ep->cur_pkt++;
  88776. +}
  88777. +
  88778. +/**
  88779. + * This function sets latest iso packet information(DDMA mode)
  88780. + *
  88781. + * @param core_if Programming view of DWC_otg controller.
  88782. + * @param dwc_ep The EP to start the transfer on.
  88783. + *
  88784. + */
  88785. +static void set_ddma_iso_pkts_info(dwc_otg_core_if_t * core_if,
  88786. + dwc_ep_t * dwc_ep)
  88787. +{
  88788. + dwc_otg_dev_dma_desc_t *dma_desc;
  88789. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  88790. + iso_pkt_info_t *iso_packet;
  88791. + uint32_t data_per_desc;
  88792. + uint32_t offset;
  88793. + int i, j;
  88794. +
  88795. + iso_packet = dwc_ep->pkt_info;
  88796. +
  88797. + /** Reinit closed DMA Descriptors*/
  88798. + /** ISO OUT EP */
  88799. + if (dwc_ep->is_in == 0) {
  88800. + dma_desc =
  88801. + dwc_ep->iso_desc_addr +
  88802. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  88803. + offset = 0;
  88804. +
  88805. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  88806. + i += dwc_ep->pkt_per_frm) {
  88807. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  88808. + data_per_desc =
  88809. + ((j + 1) * dwc_ep->maxpacket >
  88810. + dwc_ep->
  88811. + data_per_frame) ? dwc_ep->data_per_frame -
  88812. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  88813. + data_per_desc +=
  88814. + (data_per_desc % 4) ? (4 -
  88815. + data_per_desc %
  88816. + 4) : 0;
  88817. +
  88818. + sts.d32 = dma_desc->status.d32;
  88819. +
  88820. + /* Write status in iso_packet_decsriptor */
  88821. + iso_packet->status =
  88822. + sts.b_iso_out.rxsts +
  88823. + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  88824. + if (iso_packet->status) {
  88825. + iso_packet->status = -DWC_E_NO_DATA;
  88826. + }
  88827. +
  88828. + /* Received data length */
  88829. + if (!sts.b_iso_out.rxbytes) {
  88830. + iso_packet->length =
  88831. + data_per_desc -
  88832. + sts.b_iso_out.rxbytes;
  88833. + } else {
  88834. + iso_packet->length =
  88835. + data_per_desc -
  88836. + sts.b_iso_out.rxbytes + (4 -
  88837. + dwc_ep->data_per_frame
  88838. + % 4);
  88839. + }
  88840. +
  88841. + iso_packet->offset = offset;
  88842. +
  88843. + offset += data_per_desc;
  88844. + dma_desc++;
  88845. + iso_packet++;
  88846. + }
  88847. + }
  88848. +
  88849. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  88850. + data_per_desc =
  88851. + ((j + 1) * dwc_ep->maxpacket >
  88852. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  88853. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  88854. + data_per_desc +=
  88855. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  88856. +
  88857. + sts.d32 = dma_desc->status.d32;
  88858. +
  88859. + /* Write status in iso_packet_decsriptor */
  88860. + iso_packet->status =
  88861. + sts.b_iso_out.rxsts +
  88862. + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  88863. + if (iso_packet->status) {
  88864. + iso_packet->status = -DWC_E_NO_DATA;
  88865. + }
  88866. +
  88867. + /* Received data length */
  88868. + iso_packet->length =
  88869. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes;
  88870. +
  88871. + iso_packet->offset = offset;
  88872. +
  88873. + offset += data_per_desc;
  88874. + iso_packet++;
  88875. + dma_desc++;
  88876. + }
  88877. +
  88878. + sts.d32 = dma_desc->status.d32;
  88879. +
  88880. + /* Write status in iso_packet_decsriptor */
  88881. + iso_packet->status =
  88882. + sts.b_iso_out.rxsts + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  88883. + if (iso_packet->status) {
  88884. + iso_packet->status = -DWC_E_NO_DATA;
  88885. + }
  88886. + /* Received data length */
  88887. + if (!sts.b_iso_out.rxbytes) {
  88888. + iso_packet->length =
  88889. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes;
  88890. + } else {
  88891. + iso_packet->length =
  88892. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes +
  88893. + (4 - dwc_ep->data_per_frame % 4);
  88894. + }
  88895. +
  88896. + iso_packet->offset = offset;
  88897. + } else {
  88898. +/** ISO IN EP */
  88899. +
  88900. + dma_desc =
  88901. + dwc_ep->iso_desc_addr +
  88902. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  88903. +
  88904. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  88905. + sts.d32 = dma_desc->status.d32;
  88906. +
  88907. + /* Write status in iso packet descriptor */
  88908. + iso_packet->status =
  88909. + sts.b_iso_in.txsts +
  88910. + (sts.b_iso_in.bs ^ BS_DMA_DONE);
  88911. + if (iso_packet->status != 0) {
  88912. + iso_packet->status = -DWC_E_NO_DATA;
  88913. +
  88914. + }
  88915. + /* Bytes has been transfered */
  88916. + iso_packet->length =
  88917. + dwc_ep->data_per_frame - sts.b_iso_in.txbytes;
  88918. +
  88919. + dma_desc++;
  88920. + iso_packet++;
  88921. + }
  88922. +
  88923. + sts.d32 = dma_desc->status.d32;
  88924. + while (sts.b_iso_in.bs == BS_DMA_BUSY) {
  88925. + sts.d32 = dma_desc->status.d32;
  88926. + }
  88927. +
  88928. + /* Write status in iso packet descriptor ??? do be done with ERROR codes */
  88929. + iso_packet->status =
  88930. + sts.b_iso_in.txsts + (sts.b_iso_in.bs ^ BS_DMA_DONE);
  88931. + if (iso_packet->status != 0) {
  88932. + iso_packet->status = -DWC_E_NO_DATA;
  88933. + }
  88934. +
  88935. + /* Bytes has been transfered */
  88936. + iso_packet->length =
  88937. + dwc_ep->data_per_frame - sts.b_iso_in.txbytes;
  88938. + }
  88939. +}
  88940. +
  88941. +/**
  88942. + * This function reinitialize DMA Descriptors for Isochronous transfer
  88943. + *
  88944. + * @param core_if Programming view of DWC_otg controller.
  88945. + * @param dwc_ep The EP to start the transfer on.
  88946. + *
  88947. + */
  88948. +static void reinit_ddma_iso_xfer(dwc_otg_core_if_t * core_if, dwc_ep_t * dwc_ep)
  88949. +{
  88950. + int i, j;
  88951. + dwc_otg_dev_dma_desc_t *dma_desc;
  88952. + dma_addr_t dma_ad;
  88953. + volatile uint32_t *addr;
  88954. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  88955. + uint32_t data_per_desc;
  88956. +
  88957. + if (dwc_ep->is_in == 0) {
  88958. + addr = &core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl;
  88959. + } else {
  88960. + addr = &core_if->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  88961. + }
  88962. +
  88963. + if (dwc_ep->proc_buf_num == 0) {
  88964. + /** Buffer 0 descriptors setup */
  88965. + dma_ad = dwc_ep->dma_addr0;
  88966. + } else {
  88967. + /** Buffer 1 descriptors setup */
  88968. + dma_ad = dwc_ep->dma_addr1;
  88969. + }
  88970. +
  88971. + /** Reinit closed DMA Descriptors*/
  88972. + /** ISO OUT EP */
  88973. + if (dwc_ep->is_in == 0) {
  88974. + dma_desc =
  88975. + dwc_ep->iso_desc_addr +
  88976. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  88977. +
  88978. + sts.b_iso_out.bs = BS_HOST_READY;
  88979. + sts.b_iso_out.rxsts = 0;
  88980. + sts.b_iso_out.l = 0;
  88981. + sts.b_iso_out.sp = 0;
  88982. + sts.b_iso_out.ioc = 0;
  88983. + sts.b_iso_out.pid = 0;
  88984. + sts.b_iso_out.framenum = 0;
  88985. +
  88986. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  88987. + i += dwc_ep->pkt_per_frm) {
  88988. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  88989. + data_per_desc =
  88990. + ((j + 1) * dwc_ep->maxpacket >
  88991. + dwc_ep->
  88992. + data_per_frame) ? dwc_ep->data_per_frame -
  88993. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  88994. + data_per_desc +=
  88995. + (data_per_desc % 4) ? (4 -
  88996. + data_per_desc %
  88997. + 4) : 0;
  88998. + sts.b_iso_out.rxbytes = data_per_desc;
  88999. + dma_desc->buf = dma_ad;
  89000. + dma_desc->status.d32 = sts.d32;
  89001. +
  89002. + dma_ad += data_per_desc;
  89003. + dma_desc++;
  89004. + }
  89005. + }
  89006. +
  89007. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  89008. +
  89009. + data_per_desc =
  89010. + ((j + 1) * dwc_ep->maxpacket >
  89011. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  89012. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  89013. + data_per_desc +=
  89014. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  89015. + sts.b_iso_out.rxbytes = data_per_desc;
  89016. +
  89017. + dma_desc->buf = dma_ad;
  89018. + dma_desc->status.d32 = sts.d32;
  89019. +
  89020. + dma_desc++;
  89021. + dma_ad += data_per_desc;
  89022. + }
  89023. +
  89024. + sts.b_iso_out.ioc = 1;
  89025. + sts.b_iso_out.l = dwc_ep->proc_buf_num;
  89026. +
  89027. + data_per_desc =
  89028. + ((j + 1) * dwc_ep->maxpacket >
  89029. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  89030. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  89031. + data_per_desc +=
  89032. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  89033. + sts.b_iso_out.rxbytes = data_per_desc;
  89034. +
  89035. + dma_desc->buf = dma_ad;
  89036. + dma_desc->status.d32 = sts.d32;
  89037. + } else {
  89038. +/** ISO IN EP */
  89039. +
  89040. + dma_desc =
  89041. + dwc_ep->iso_desc_addr +
  89042. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  89043. +
  89044. + sts.b_iso_in.bs = BS_HOST_READY;
  89045. + sts.b_iso_in.txsts = 0;
  89046. + sts.b_iso_in.sp = 0;
  89047. + sts.b_iso_in.ioc = 0;
  89048. + sts.b_iso_in.pid = dwc_ep->pkt_per_frm;
  89049. + sts.b_iso_in.framenum = dwc_ep->next_frame;
  89050. + sts.b_iso_in.txbytes = dwc_ep->data_per_frame;
  89051. + sts.b_iso_in.l = 0;
  89052. +
  89053. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  89054. + dma_desc->buf = dma_ad;
  89055. + dma_desc->status.d32 = sts.d32;
  89056. +
  89057. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  89058. + dma_ad += dwc_ep->data_per_frame;
  89059. + dma_desc++;
  89060. + }
  89061. +
  89062. + sts.b_iso_in.ioc = 1;
  89063. + sts.b_iso_in.l = dwc_ep->proc_buf_num;
  89064. +
  89065. + dma_desc->buf = dma_ad;
  89066. + dma_desc->status.d32 = sts.d32;
  89067. +
  89068. + dwc_ep->next_frame =
  89069. + sts.b_iso_in.framenum + dwc_ep->bInterval * 1;
  89070. + }
  89071. + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
  89072. +}
  89073. +
  89074. +/**
  89075. + * This function is to handle Iso EP transfer complete interrupt
  89076. + * in case Iso out packet was dropped
  89077. + *
  89078. + * @param core_if Programming view of DWC_otg controller.
  89079. + * @param dwc_ep The EP for wihich transfer complete was asserted
  89080. + *
  89081. + */
  89082. +static uint32_t handle_iso_out_pkt_dropped(dwc_otg_core_if_t * core_if,
  89083. + dwc_ep_t * dwc_ep)
  89084. +{
  89085. + uint32_t dma_addr;
  89086. + uint32_t drp_pkt;
  89087. + uint32_t drp_pkt_cnt;
  89088. + deptsiz_data_t deptsiz = {.d32 = 0 };
  89089. + depctl_data_t depctl = {.d32 = 0 };
  89090. + int i;
  89091. +
  89092. + deptsiz.d32 =
  89093. + DWC_READ_REG32(&core_if->dev_if->
  89094. + out_ep_regs[dwc_ep->num]->doeptsiz);
  89095. +
  89096. + drp_pkt = dwc_ep->pkt_cnt - deptsiz.b.pktcnt;
  89097. + drp_pkt_cnt = dwc_ep->pkt_per_frm - (drp_pkt % dwc_ep->pkt_per_frm);
  89098. +
  89099. + /* Setting dropped packets status */
  89100. + for (i = 0; i < drp_pkt_cnt; ++i) {
  89101. + dwc_ep->pkt_info[drp_pkt].status = -DWC_E_NO_DATA;
  89102. + drp_pkt++;
  89103. + deptsiz.b.pktcnt--;
  89104. + }
  89105. +
  89106. + if (deptsiz.b.pktcnt > 0) {
  89107. + deptsiz.b.xfersize =
  89108. + dwc_ep->xfer_len - (dwc_ep->pkt_cnt -
  89109. + deptsiz.b.pktcnt) * dwc_ep->maxpacket;
  89110. + } else {
  89111. + deptsiz.b.xfersize = 0;
  89112. + deptsiz.b.pktcnt = 0;
  89113. + }
  89114. +
  89115. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doeptsiz,
  89116. + deptsiz.d32);
  89117. +
  89118. + if (deptsiz.b.pktcnt > 0) {
  89119. + if (dwc_ep->proc_buf_num) {
  89120. + dma_addr =
  89121. + dwc_ep->dma_addr1 + dwc_ep->xfer_len -
  89122. + deptsiz.b.xfersize;
  89123. + } else {
  89124. + dma_addr =
  89125. + dwc_ep->dma_addr0 + dwc_ep->xfer_len -
  89126. + deptsiz.b.xfersize;;
  89127. + }
  89128. +
  89129. + DWC_WRITE_REG32(&core_if->dev_if->
  89130. + out_ep_regs[dwc_ep->num]->doepdma, dma_addr);
  89131. +
  89132. + /** Re-enable endpoint, clear nak */
  89133. + depctl.d32 = 0;
  89134. + depctl.b.epena = 1;
  89135. + depctl.b.cnak = 1;
  89136. +
  89137. + DWC_MODIFY_REG32(&core_if->dev_if->
  89138. + out_ep_regs[dwc_ep->num]->doepctl, depctl.d32,
  89139. + depctl.d32);
  89140. + return 0;
  89141. + } else {
  89142. + return 1;
  89143. + }
  89144. +}
  89145. +
  89146. +/**
  89147. + * This function sets iso packets information(PTI mode)
  89148. + *
  89149. + * @param core_if Programming view of DWC_otg controller.
  89150. + * @param ep The EP to start the transfer on.
  89151. + *
  89152. + */
  89153. +static uint32_t set_iso_pkts_info(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  89154. +{
  89155. + int i, j;
  89156. + dma_addr_t dma_ad;
  89157. + iso_pkt_info_t *packet_info = ep->pkt_info;
  89158. + uint32_t offset;
  89159. + uint32_t frame_data;
  89160. + deptsiz_data_t deptsiz;
  89161. +
  89162. + if (ep->proc_buf_num == 0) {
  89163. + /** Buffer 0 descriptors setup */
  89164. + dma_ad = ep->dma_addr0;
  89165. + } else {
  89166. + /** Buffer 1 descriptors setup */
  89167. + dma_ad = ep->dma_addr1;
  89168. + }
  89169. +
  89170. + if (ep->is_in) {
  89171. + deptsiz.d32 =
  89172. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  89173. + dieptsiz);
  89174. + } else {
  89175. + deptsiz.d32 =
  89176. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[ep->num]->
  89177. + doeptsiz);
  89178. + }
  89179. +
  89180. + if (!deptsiz.b.xfersize) {
  89181. + offset = 0;
  89182. + for (i = 0; i < ep->pkt_cnt; i += ep->pkt_per_frm) {
  89183. + frame_data = ep->data_per_frame;
  89184. + for (j = 0; j < ep->pkt_per_frm; ++j) {
  89185. +
  89186. + /* Packet status - is not set as initially
  89187. + * it is set to 0 and if packet was sent
  89188. + successfully, status field will remain 0*/
  89189. +
  89190. + /* Bytes has been transfered */
  89191. + packet_info->length =
  89192. + (ep->maxpacket <
  89193. + frame_data) ? ep->maxpacket : frame_data;
  89194. +
  89195. + /* Received packet offset */
  89196. + packet_info->offset = offset;
  89197. + offset += packet_info->length;
  89198. + frame_data -= packet_info->length;
  89199. +
  89200. + packet_info++;
  89201. + }
  89202. + }
  89203. + return 1;
  89204. + } else {
  89205. + /* This is a workaround for in case of Transfer Complete with
  89206. + * PktDrpSts interrupts merging - in this case Transfer complete
  89207. + * interrupt for Isoc Out Endpoint is asserted without PktDrpSts
  89208. + * set and with DOEPTSIZ register non zero. Investigations showed,
  89209. + * that this happens when Out packet is dropped, but because of
  89210. + * interrupts merging during first interrupt handling PktDrpSts
  89211. + * bit is cleared and for next merged interrupts it is not reset.
  89212. + * In this case SW hadles the interrupt as if PktDrpSts bit is set.
  89213. + */
  89214. + if (ep->is_in) {
  89215. + return 1;
  89216. + } else {
  89217. + return handle_iso_out_pkt_dropped(core_if, ep);
  89218. + }
  89219. + }
  89220. +}
  89221. +
  89222. +/**
  89223. + * This function is to handle Iso EP transfer complete interrupt
  89224. + *
  89225. + * @param pcd The PCD
  89226. + * @param ep The EP for which transfer complete was asserted
  89227. + *
  89228. + */
  89229. +static void complete_iso_ep(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep)
  89230. +{
  89231. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  89232. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  89233. + uint8_t is_last = 0;
  89234. +
  89235. + if (ep->dwc_ep.next_frame == 0xffffffff) {
  89236. + DWC_WARN("Next frame is not set!\n");
  89237. + return;
  89238. + }
  89239. +
  89240. + if (core_if->dma_enable) {
  89241. + if (core_if->dma_desc_enable) {
  89242. + set_ddma_iso_pkts_info(core_if, dwc_ep);
  89243. + reinit_ddma_iso_xfer(core_if, dwc_ep);
  89244. + is_last = 1;
  89245. + } else {
  89246. + if (core_if->pti_enh_enable) {
  89247. + if (set_iso_pkts_info(core_if, dwc_ep)) {
  89248. + dwc_ep->proc_buf_num =
  89249. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  89250. + dwc_otg_iso_ep_start_buf_transfer
  89251. + (core_if, dwc_ep);
  89252. + is_last = 1;
  89253. + }
  89254. + } else {
  89255. + set_current_pkt_info(core_if, dwc_ep);
  89256. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  89257. + is_last = 1;
  89258. + dwc_ep->cur_pkt = 0;
  89259. + dwc_ep->proc_buf_num =
  89260. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  89261. + if (dwc_ep->proc_buf_num) {
  89262. + dwc_ep->cur_pkt_addr =
  89263. + dwc_ep->xfer_buff1;
  89264. + dwc_ep->cur_pkt_dma_addr =
  89265. + dwc_ep->dma_addr1;
  89266. + } else {
  89267. + dwc_ep->cur_pkt_addr =
  89268. + dwc_ep->xfer_buff0;
  89269. + dwc_ep->cur_pkt_dma_addr =
  89270. + dwc_ep->dma_addr0;
  89271. + }
  89272. +
  89273. + }
  89274. + dwc_otg_iso_ep_start_frm_transfer(core_if,
  89275. + dwc_ep);
  89276. + }
  89277. + }
  89278. + } else {
  89279. + set_current_pkt_info(core_if, dwc_ep);
  89280. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  89281. + is_last = 1;
  89282. + dwc_ep->cur_pkt = 0;
  89283. + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
  89284. + if (dwc_ep->proc_buf_num) {
  89285. + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff1;
  89286. + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr1;
  89287. + } else {
  89288. + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff0;
  89289. + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr0;
  89290. + }
  89291. +
  89292. + }
  89293. + dwc_otg_iso_ep_start_frm_transfer(core_if, dwc_ep);
  89294. + }
  89295. + if (is_last)
  89296. + dwc_otg_iso_buffer_done(pcd, ep, ep->iso_req_handle);
  89297. +}
  89298. +#endif /* DWC_EN_ISOC */
  89299. +
  89300. +/**
  89301. + * This function handle BNA interrupt for Non Isochronous EPs
  89302. + *
  89303. + */
  89304. +static void dwc_otg_pcd_handle_noniso_bna(dwc_otg_pcd_ep_t * ep)
  89305. +{
  89306. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  89307. + volatile uint32_t *addr;
  89308. + depctl_data_t depctl = {.d32 = 0 };
  89309. + dwc_otg_pcd_t *pcd = ep->pcd;
  89310. + dwc_otg_dev_dma_desc_t *dma_desc;
  89311. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  89312. + dwc_otg_core_if_t *core_if = ep->pcd->core_if;
  89313. + int i, start;
  89314. +
  89315. + if (!dwc_ep->desc_cnt)
  89316. + DWC_WARN("Ep%d %s Descriptor count = %d \n", dwc_ep->num,
  89317. + (dwc_ep->is_in ? "IN" : "OUT"), dwc_ep->desc_cnt);
  89318. +
  89319. + if (core_if->core_params->cont_on_bna && !dwc_ep->is_in
  89320. + && dwc_ep->type != DWC_OTG_EP_TYPE_CONTROL) {
  89321. + uint32_t doepdma;
  89322. + dwc_otg_dev_out_ep_regs_t *out_regs =
  89323. + core_if->dev_if->out_ep_regs[dwc_ep->num];
  89324. + doepdma = DWC_READ_REG32(&(out_regs->doepdma));
  89325. + start = (doepdma - dwc_ep->dma_desc_addr)/sizeof(dwc_otg_dev_dma_desc_t);
  89326. + dma_desc = &(dwc_ep->desc_addr[start]);
  89327. + } else {
  89328. + start = 0;
  89329. + dma_desc = dwc_ep->desc_addr;
  89330. + }
  89331. +
  89332. +
  89333. + for (i = start; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  89334. + sts.d32 = dma_desc->status.d32;
  89335. + sts.b.bs = BS_HOST_READY;
  89336. + dma_desc->status.d32 = sts.d32;
  89337. + }
  89338. +
  89339. + if (dwc_ep->is_in == 0) {
  89340. + addr =
  89341. + &GET_CORE_IF(pcd)->dev_if->out_ep_regs[dwc_ep->num]->
  89342. + doepctl;
  89343. + } else {
  89344. + addr =
  89345. + &GET_CORE_IF(pcd)->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  89346. + }
  89347. + depctl.b.epena = 1;
  89348. + depctl.b.cnak = 1;
  89349. + DWC_MODIFY_REG32(addr, 0, depctl.d32);
  89350. +}
  89351. +
  89352. +/**
  89353. + * This function handles EP0 Control transfers.
  89354. + *
  89355. + * The state of the control transfers are tracked in
  89356. + * <code>ep0state</code>.
  89357. + */
  89358. +static void handle_ep0(dwc_otg_pcd_t * pcd)
  89359. +{
  89360. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  89361. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  89362. + dev_dma_desc_sts_t desc_sts;
  89363. + deptsiz0_data_t deptsiz;
  89364. + uint32_t byte_count;
  89365. +
  89366. +#ifdef DEBUG_EP0
  89367. + DWC_DEBUGPL(DBG_PCDV, "%s()\n", __func__);
  89368. + print_ep0_state(pcd);
  89369. +#endif
  89370. +
  89371. +// DWC_PRINTF("HANDLE EP0\n");
  89372. +
  89373. + switch (pcd->ep0state) {
  89374. + case EP0_DISCONNECT:
  89375. + break;
  89376. +
  89377. + case EP0_IDLE:
  89378. + pcd->request_config = 0;
  89379. +
  89380. + pcd_setup(pcd);
  89381. + break;
  89382. +
  89383. + case EP0_IN_DATA_PHASE:
  89384. +#ifdef DEBUG_EP0
  89385. + DWC_DEBUGPL(DBG_PCD, "DATA_IN EP%d-%s: type=%d, mps=%d\n",
  89386. + ep0->dwc_ep.num, (ep0->dwc_ep.is_in ? "IN" : "OUT"),
  89387. + ep0->dwc_ep.type, ep0->dwc_ep.maxpacket);
  89388. +#endif
  89389. +
  89390. + if (core_if->dma_enable != 0) {
  89391. + /*
  89392. + * For EP0 we can only program 1 packet at a time so we
  89393. + * need to do the make calculations after each complete.
  89394. + * Call write_packet to make the calculations, as in
  89395. + * slave mode, and use those values to determine if we
  89396. + * can complete.
  89397. + */
  89398. + if (core_if->dma_desc_enable == 0) {
  89399. + deptsiz.d32 =
  89400. + DWC_READ_REG32(&core_if->
  89401. + dev_if->in_ep_regs[0]->
  89402. + dieptsiz);
  89403. + byte_count =
  89404. + ep0->dwc_ep.xfer_len - deptsiz.b.xfersize;
  89405. + } else {
  89406. + desc_sts =
  89407. + core_if->dev_if->in_desc_addr->status;
  89408. + byte_count =
  89409. + ep0->dwc_ep.xfer_len - desc_sts.b.bytes;
  89410. + }
  89411. + ep0->dwc_ep.xfer_count += byte_count;
  89412. + ep0->dwc_ep.xfer_buff += byte_count;
  89413. + ep0->dwc_ep.dma_addr += byte_count;
  89414. + }
  89415. + if (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len) {
  89416. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  89417. + &ep0->dwc_ep);
  89418. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
  89419. + } else if (ep0->dwc_ep.sent_zlp) {
  89420. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  89421. + &ep0->dwc_ep);
  89422. + ep0->dwc_ep.sent_zlp = 0;
  89423. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER sent zlp\n");
  89424. + } else {
  89425. + ep0_complete_request(ep0);
  89426. + DWC_DEBUGPL(DBG_PCD, "COMPLETE TRANSFER\n");
  89427. + }
  89428. + break;
  89429. + case EP0_OUT_DATA_PHASE:
  89430. +#ifdef DEBUG_EP0
  89431. + DWC_DEBUGPL(DBG_PCD, "DATA_OUT EP%d-%s: type=%d, mps=%d\n",
  89432. + ep0->dwc_ep.num, (ep0->dwc_ep.is_in ? "IN" : "OUT"),
  89433. + ep0->dwc_ep.type, ep0->dwc_ep.maxpacket);
  89434. +#endif
  89435. + if (core_if->dma_enable != 0) {
  89436. + if (core_if->dma_desc_enable == 0) {
  89437. + deptsiz.d32 =
  89438. + DWC_READ_REG32(&core_if->
  89439. + dev_if->out_ep_regs[0]->
  89440. + doeptsiz);
  89441. + byte_count =
  89442. + ep0->dwc_ep.maxpacket - deptsiz.b.xfersize;
  89443. + } else {
  89444. + desc_sts =
  89445. + core_if->dev_if->out_desc_addr->status;
  89446. + byte_count =
  89447. + ep0->dwc_ep.maxpacket - desc_sts.b.bytes;
  89448. + }
  89449. + ep0->dwc_ep.xfer_count += byte_count;
  89450. + ep0->dwc_ep.xfer_buff += byte_count;
  89451. + ep0->dwc_ep.dma_addr += byte_count;
  89452. + }
  89453. + if (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len) {
  89454. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  89455. + &ep0->dwc_ep);
  89456. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
  89457. + } else if (ep0->dwc_ep.sent_zlp) {
  89458. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  89459. + &ep0->dwc_ep);
  89460. + ep0->dwc_ep.sent_zlp = 0;
  89461. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER sent zlp\n");
  89462. + } else {
  89463. + ep0_complete_request(ep0);
  89464. + DWC_DEBUGPL(DBG_PCD, "COMPLETE TRANSFER\n");
  89465. + }
  89466. + break;
  89467. +
  89468. + case EP0_IN_STATUS_PHASE:
  89469. + case EP0_OUT_STATUS_PHASE:
  89470. + DWC_DEBUGPL(DBG_PCD, "CASE: EP0_STATUS\n");
  89471. + ep0_complete_request(ep0);
  89472. + pcd->ep0state = EP0_IDLE;
  89473. + ep0->stopped = 1;
  89474. + ep0->dwc_ep.is_in = 0; /* OUT for next SETUP */
  89475. +
  89476. + /* Prepare for more SETUP Packets */
  89477. + if (core_if->dma_enable) {
  89478. + ep0_out_start(core_if, pcd);
  89479. + }
  89480. + break;
  89481. +
  89482. + case EP0_STALL:
  89483. + DWC_ERROR("EP0 STALLed, should not get here pcd_setup()\n");
  89484. + break;
  89485. + }
  89486. +#ifdef DEBUG_EP0
  89487. + print_ep0_state(pcd);
  89488. +#endif
  89489. +}
  89490. +
  89491. +/**
  89492. + * Restart transfer
  89493. + */
  89494. +static void restart_transfer(dwc_otg_pcd_t * pcd, const uint32_t epnum)
  89495. +{
  89496. + dwc_otg_core_if_t *core_if;
  89497. + dwc_otg_dev_if_t *dev_if;
  89498. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  89499. + dwc_otg_pcd_ep_t *ep;
  89500. +
  89501. + ep = get_in_ep(pcd, epnum);
  89502. +
  89503. +#ifdef DWC_EN_ISOC
  89504. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  89505. + return;
  89506. + }
  89507. +#endif /* DWC_EN_ISOC */
  89508. +
  89509. + core_if = GET_CORE_IF(pcd);
  89510. + dev_if = core_if->dev_if;
  89511. +
  89512. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dieptsiz);
  89513. +
  89514. + DWC_DEBUGPL(DBG_PCD, "xfer_buff=%p xfer_count=%0x xfer_len=%0x"
  89515. + " stopped=%d\n", ep->dwc_ep.xfer_buff,
  89516. + ep->dwc_ep.xfer_count, ep->dwc_ep.xfer_len, ep->stopped);
  89517. + /*
  89518. + * If xfersize is 0 and pktcnt in not 0, resend the last packet.
  89519. + */
  89520. + if (dieptsiz.b.pktcnt && dieptsiz.b.xfersize == 0 &&
  89521. + ep->dwc_ep.start_xfer_buff != 0) {
  89522. + if (ep->dwc_ep.total_len <= ep->dwc_ep.maxpacket) {
  89523. + ep->dwc_ep.xfer_count = 0;
  89524. + ep->dwc_ep.xfer_buff = ep->dwc_ep.start_xfer_buff;
  89525. + ep->dwc_ep.xfer_len = ep->dwc_ep.xfer_count;
  89526. + } else {
  89527. + ep->dwc_ep.xfer_count -= ep->dwc_ep.maxpacket;
  89528. + /* convert packet size to dwords. */
  89529. + ep->dwc_ep.xfer_buff -= ep->dwc_ep.maxpacket;
  89530. + ep->dwc_ep.xfer_len = ep->dwc_ep.xfer_count;
  89531. + }
  89532. + ep->stopped = 0;
  89533. + DWC_DEBUGPL(DBG_PCD, "xfer_buff=%p xfer_count=%0x "
  89534. + "xfer_len=%0x stopped=%d\n",
  89535. + ep->dwc_ep.xfer_buff,
  89536. + ep->dwc_ep.xfer_count, ep->dwc_ep.xfer_len,
  89537. + ep->stopped);
  89538. + if (epnum == 0) {
  89539. + dwc_otg_ep0_start_transfer(core_if, &ep->dwc_ep);
  89540. + } else {
  89541. + dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
  89542. + }
  89543. + }
  89544. +}
  89545. +
  89546. +/*
  89547. + * This function create new nextep sequnce based on Learn Queue.
  89548. + *
  89549. + * @param core_if Programming view of DWC_otg controller
  89550. + */
  89551. +void predict_nextep_seq( dwc_otg_core_if_t * core_if)
  89552. +{
  89553. + dwc_otg_device_global_regs_t *dev_global_regs =
  89554. + core_if->dev_if->dev_global_regs;
  89555. + const uint32_t TOKEN_Q_DEPTH = core_if->hwcfg2.b.dev_token_q_depth;
  89556. + /* Number of Token Queue Registers */
  89557. + const int DTKNQ_REG_CNT = (TOKEN_Q_DEPTH + 7) / 8;
  89558. + dtknq1_data_t dtknqr1;
  89559. + uint32_t in_tkn_epnums[4];
  89560. + uint8_t seqnum[MAX_EPS_CHANNELS];
  89561. + uint8_t intkn_seq[TOKEN_Q_DEPTH];
  89562. + grstctl_t resetctl = {.d32 = 0 };
  89563. + uint8_t temp;
  89564. + int ndx = 0;
  89565. + int start = 0;
  89566. + int end = 0;
  89567. + int sort_done = 0;
  89568. + int i = 0;
  89569. + volatile uint32_t *addr = &dev_global_regs->dtknqr1;
  89570. +
  89571. +
  89572. + DWC_DEBUGPL(DBG_PCD,"dev_token_q_depth=%d\n",TOKEN_Q_DEPTH);
  89573. +
  89574. + /* Read the DTKNQ Registers */
  89575. + for (i = 0; i < DTKNQ_REG_CNT; i++) {
  89576. + in_tkn_epnums[i] = DWC_READ_REG32(addr);
  89577. + DWC_DEBUGPL(DBG_PCDV, "DTKNQR%d=0x%08x\n", i + 1,
  89578. + in_tkn_epnums[i]);
  89579. + if (addr == &dev_global_regs->dvbusdis) {
  89580. + addr = &dev_global_regs->dtknqr3_dthrctl;
  89581. + } else {
  89582. + ++addr;
  89583. + }
  89584. +
  89585. + }
  89586. +
  89587. + /* Copy the DTKNQR1 data to the bit field. */
  89588. + dtknqr1.d32 = in_tkn_epnums[0];
  89589. + if (dtknqr1.b.wrap_bit) {
  89590. + ndx = dtknqr1.b.intknwptr;
  89591. + end = ndx -1;
  89592. + if (end < 0)
  89593. + end = TOKEN_Q_DEPTH -1;
  89594. + } else {
  89595. + ndx = 0;
  89596. + end = dtknqr1.b.intknwptr -1;
  89597. + if (end < 0)
  89598. + end = 0;
  89599. + }
  89600. + start = ndx;
  89601. +
  89602. + /* Fill seqnum[] by initial values: EP number + 31 */
  89603. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  89604. + seqnum[i] = i +31;
  89605. + }
  89606. +
  89607. + /* Fill intkn_seq[] from in_tkn_epnums[0] */
  89608. + for (i=0; i < 6; i++)
  89609. + intkn_seq[i] = (in_tkn_epnums[0] >> ((7-i) * 4)) & 0xf;
  89610. +
  89611. + if (TOKEN_Q_DEPTH > 6) {
  89612. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  89613. + for (i=6; i < 14; i++)
  89614. + intkn_seq[i] =
  89615. + (in_tkn_epnums[1] >> ((7 - (i - 6)) * 4)) & 0xf;
  89616. + }
  89617. +
  89618. + if (TOKEN_Q_DEPTH > 14) {
  89619. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  89620. + for (i=14; i < 22; i++)
  89621. + intkn_seq[i] =
  89622. + (in_tkn_epnums[2] >> ((7 - (i - 14)) * 4)) & 0xf;
  89623. + }
  89624. +
  89625. + if (TOKEN_Q_DEPTH > 22) {
  89626. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  89627. + for (i=22; i < 30; i++)
  89628. + intkn_seq[i] =
  89629. + (in_tkn_epnums[3] >> ((7 - (i - 22)) * 4)) & 0xf;
  89630. + }
  89631. +
  89632. + DWC_DEBUGPL(DBG_PCDV, "%s start=%d end=%d intkn_seq[]:\n", __func__,
  89633. + start, end);
  89634. + for (i=0; i<TOKEN_Q_DEPTH; i++)
  89635. + DWC_DEBUGPL(DBG_PCDV,"%d\n", intkn_seq[i]);
  89636. +
  89637. + /* Update seqnum based on intkn_seq[] */
  89638. + i = 0;
  89639. + do {
  89640. + seqnum[intkn_seq[ndx]] = i;
  89641. + ndx++;
  89642. + i++;
  89643. + if (ndx == TOKEN_Q_DEPTH)
  89644. + ndx = 0;
  89645. + } while ( i < TOKEN_Q_DEPTH );
  89646. +
  89647. + /* Mark non active EP's in seqnum[] by 0xff */
  89648. + for (i=0; i<=core_if->dev_if->num_in_eps; i++) {
  89649. + if (core_if->nextep_seq[i] == 0xff )
  89650. + seqnum[i] = 0xff;
  89651. + }
  89652. +
  89653. + /* Sort seqnum[] */
  89654. + sort_done = 0;
  89655. + while (!sort_done) {
  89656. + sort_done = 1;
  89657. + for (i=0; i<core_if->dev_if->num_in_eps; i++) {
  89658. + if (seqnum[i] > seqnum[i+1]) {
  89659. + temp = seqnum[i];
  89660. + seqnum[i] = seqnum[i+1];
  89661. + seqnum[i+1] = temp;
  89662. + sort_done = 0;
  89663. + }
  89664. + }
  89665. + }
  89666. +
  89667. + ndx = start + seqnum[0];
  89668. + if (ndx >= TOKEN_Q_DEPTH)
  89669. + ndx = ndx % TOKEN_Q_DEPTH;
  89670. + core_if->first_in_nextep_seq = intkn_seq[ndx];
  89671. +
  89672. + /* Update seqnum[] by EP numbers */
  89673. + for (i=0; i<=core_if->dev_if->num_in_eps; i++) {
  89674. + ndx = start + i;
  89675. + if (seqnum[i] < 31) {
  89676. + ndx = start + seqnum[i];
  89677. + if (ndx >= TOKEN_Q_DEPTH)
  89678. + ndx = ndx % TOKEN_Q_DEPTH;
  89679. + seqnum[i] = intkn_seq[ndx];
  89680. + } else {
  89681. + if (seqnum[i] < 0xff) {
  89682. + seqnum[i] = seqnum[i] - 31;
  89683. + } else {
  89684. + break;
  89685. + }
  89686. + }
  89687. + }
  89688. +
  89689. + /* Update nextep_seq[] based on seqnum[] */
  89690. + for (i=0; i<core_if->dev_if->num_in_eps; i++) {
  89691. + if (seqnum[i] != 0xff) {
  89692. + if (seqnum[i+1] != 0xff) {
  89693. + core_if->nextep_seq[seqnum[i]] = seqnum[i+1];
  89694. + } else {
  89695. + core_if->nextep_seq[seqnum[i]] = core_if->first_in_nextep_seq;
  89696. + break;
  89697. + }
  89698. + } else {
  89699. + break;
  89700. + }
  89701. + }
  89702. +
  89703. + DWC_DEBUGPL(DBG_PCDV, "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  89704. + __func__, core_if->first_in_nextep_seq);
  89705. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  89706. + DWC_DEBUGPL(DBG_PCDV,"%2d\n", core_if->nextep_seq[i]);
  89707. + }
  89708. +
  89709. + /* Flush the Learning Queue */
  89710. + resetctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->grstctl);
  89711. + resetctl.b.intknqflsh = 1;
  89712. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  89713. +
  89714. +
  89715. +}
  89716. +
  89717. +/**
  89718. + * handle the IN EP disable interrupt.
  89719. + */
  89720. +static inline void handle_in_ep_disable_intr(dwc_otg_pcd_t * pcd,
  89721. + const uint32_t epnum)
  89722. +{
  89723. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  89724. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  89725. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  89726. + dctl_data_t dctl = {.d32 = 0 };
  89727. + dwc_otg_pcd_ep_t *ep;
  89728. + dwc_ep_t *dwc_ep;
  89729. + gintmsk_data_t gintmsk_data;
  89730. + depctl_data_t depctl;
  89731. + uint32_t diepdma;
  89732. + uint32_t remain_to_transfer = 0;
  89733. + uint8_t i;
  89734. + uint32_t xfer_size;
  89735. +
  89736. + ep = get_in_ep(pcd, epnum);
  89737. + dwc_ep = &ep->dwc_ep;
  89738. +
  89739. + if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  89740. + dwc_otg_flush_tx_fifo(core_if, dwc_ep->tx_fifo_num);
  89741. + complete_ep(ep);
  89742. + return;
  89743. + }
  89744. +
  89745. + DWC_DEBUGPL(DBG_PCD, "diepctl%d=%0x\n", epnum,
  89746. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl));
  89747. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dieptsiz);
  89748. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  89749. +
  89750. + DWC_DEBUGPL(DBG_ANY, "pktcnt=%d size=%d\n",
  89751. + dieptsiz.b.pktcnt, dieptsiz.b.xfersize);
  89752. +
  89753. + if ((core_if->start_predict == 0) || (depctl.b.eptype & 1)) {
  89754. + if (ep->stopped) {
  89755. + if (core_if->en_multiple_tx_fifo)
  89756. + /* Flush the Tx FIFO */
  89757. + dwc_otg_flush_tx_fifo(core_if, dwc_ep->tx_fifo_num);
  89758. + /* Clear the Global IN NP NAK */
  89759. + dctl.d32 = 0;
  89760. + dctl.b.cgnpinnak = 1;
  89761. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  89762. + /* Restart the transaction */
  89763. + if (dieptsiz.b.pktcnt != 0 || dieptsiz.b.xfersize != 0) {
  89764. + restart_transfer(pcd, epnum);
  89765. + }
  89766. + } else {
  89767. + /* Restart the transaction */
  89768. + if (dieptsiz.b.pktcnt != 0 || dieptsiz.b.xfersize != 0) {
  89769. + restart_transfer(pcd, epnum);
  89770. + }
  89771. + DWC_DEBUGPL(DBG_ANY, "STOPPED!!!\n");
  89772. + }
  89773. + return;
  89774. + }
  89775. +
  89776. + if (core_if->start_predict > 2) { // NP IN EP
  89777. + core_if->start_predict--;
  89778. + return;
  89779. + }
  89780. +
  89781. + core_if->start_predict--;
  89782. +
  89783. + if (core_if->start_predict == 1) { // All NP IN Ep's disabled now
  89784. +
  89785. + predict_nextep_seq(core_if);
  89786. +
  89787. + /* Update all active IN EP's NextEP field based of nextep_seq[] */
  89788. + for ( i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  89789. + depctl.d32 =
  89790. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  89791. + if (core_if->nextep_seq[i] != 0xff) { // Active NP IN EP
  89792. + depctl.b.nextep = core_if->nextep_seq[i];
  89793. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  89794. + }
  89795. + }
  89796. + /* Flush Shared NP TxFIFO */
  89797. + dwc_otg_flush_tx_fifo(core_if, 0);
  89798. + /* Rewind buffers */
  89799. + if (!core_if->dma_desc_enable) {
  89800. + i = core_if->first_in_nextep_seq;
  89801. + do {
  89802. + ep = get_in_ep(pcd, i);
  89803. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  89804. + xfer_size = ep->dwc_ep.total_len - ep->dwc_ep.xfer_count;
  89805. + if (xfer_size > ep->dwc_ep.maxxfer)
  89806. + xfer_size = ep->dwc_ep.maxxfer;
  89807. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  89808. + if (dieptsiz.b.pktcnt != 0) {
  89809. + if (xfer_size == 0) {
  89810. + remain_to_transfer = 0;
  89811. + } else {
  89812. + if ((xfer_size % ep->dwc_ep.maxpacket) == 0) {
  89813. + remain_to_transfer =
  89814. + dieptsiz.b.pktcnt * ep->dwc_ep.maxpacket;
  89815. + } else {
  89816. + remain_to_transfer = ((dieptsiz.b.pktcnt -1) * ep->dwc_ep.maxpacket)
  89817. + + (xfer_size % ep->dwc_ep.maxpacket);
  89818. + }
  89819. + }
  89820. + diepdma = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepdma);
  89821. + dieptsiz.b.xfersize = remain_to_transfer;
  89822. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->dieptsiz, dieptsiz.d32);
  89823. + diepdma = ep->dwc_ep.dma_addr + (xfer_size - remain_to_transfer);
  89824. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepdma, diepdma);
  89825. + }
  89826. + i = core_if->nextep_seq[i];
  89827. + } while (i != core_if->first_in_nextep_seq);
  89828. + } else { // dma_desc_enable
  89829. + DWC_PRINTF("%s Learning Queue not supported in DDMA\n", __func__);
  89830. + }
  89831. +
  89832. + /* Restart transfers in predicted sequences */
  89833. + i = core_if->first_in_nextep_seq;
  89834. + do {
  89835. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  89836. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  89837. + if (dieptsiz.b.pktcnt != 0) {
  89838. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  89839. + depctl.b.epena = 1;
  89840. + depctl.b.cnak = 1;
  89841. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  89842. + }
  89843. + i = core_if->nextep_seq[i];
  89844. + } while (i != core_if->first_in_nextep_seq);
  89845. +
  89846. + /* Clear the global non-periodic IN NAK handshake */
  89847. + dctl.d32 = 0;
  89848. + dctl.b.cgnpinnak = 1;
  89849. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  89850. +
  89851. + /* Unmask EP Mismatch interrupt */
  89852. + gintmsk_data.d32 = 0;
  89853. + gintmsk_data.b.epmismatch = 1;
  89854. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk_data.d32);
  89855. +
  89856. + core_if->start_predict = 0;
  89857. +
  89858. + }
  89859. +}
  89860. +
  89861. +/**
  89862. + * Handler for the IN EP timeout handshake interrupt.
  89863. + */
  89864. +static inline void handle_in_ep_timeout_intr(dwc_otg_pcd_t * pcd,
  89865. + const uint32_t epnum)
  89866. +{
  89867. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  89868. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  89869. +
  89870. +#ifdef DEBUG
  89871. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  89872. + uint32_t num = 0;
  89873. +#endif
  89874. + dctl_data_t dctl = {.d32 = 0 };
  89875. + dwc_otg_pcd_ep_t *ep;
  89876. +
  89877. + gintmsk_data_t intr_mask = {.d32 = 0 };
  89878. +
  89879. + ep = get_in_ep(pcd, epnum);
  89880. +
  89881. + /* Disable the NP Tx Fifo Empty Interrrupt */
  89882. + if (!core_if->dma_enable) {
  89883. + intr_mask.b.nptxfempty = 1;
  89884. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  89885. + intr_mask.d32, 0);
  89886. + }
  89887. + /** @todo NGS Check EP type.
  89888. + * Implement for Periodic EPs */
  89889. + /*
  89890. + * Non-periodic EP
  89891. + */
  89892. + /* Enable the Global IN NAK Effective Interrupt */
  89893. + intr_mask.b.ginnakeff = 1;
  89894. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, intr_mask.d32);
  89895. +
  89896. + /* Set Global IN NAK */
  89897. + dctl.b.sgnpinnak = 1;
  89898. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  89899. +
  89900. + ep->stopped = 1;
  89901. +
  89902. +#ifdef DEBUG
  89903. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[num]->dieptsiz);
  89904. + DWC_DEBUGPL(DBG_ANY, "pktcnt=%d size=%d\n",
  89905. + dieptsiz.b.pktcnt, dieptsiz.b.xfersize);
  89906. +#endif
  89907. +
  89908. +#ifdef DISABLE_PERIODIC_EP
  89909. + /*
  89910. + * Set the NAK bit for this EP to
  89911. + * start the disable process.
  89912. + */
  89913. + diepctl.d32 = 0;
  89914. + diepctl.b.snak = 1;
  89915. + DWC_MODIFY_REG32(&dev_if->in_ep_regs[num]->diepctl, diepctl.d32,
  89916. + diepctl.d32);
  89917. + ep->disabling = 1;
  89918. + ep->stopped = 1;
  89919. +#endif
  89920. +}
  89921. +
  89922. +/**
  89923. + * Handler for the IN EP NAK interrupt.
  89924. + */
  89925. +static inline int32_t handle_in_ep_nak_intr(dwc_otg_pcd_t * pcd,
  89926. + const uint32_t epnum)
  89927. +{
  89928. + /** @todo implement ISR */
  89929. + dwc_otg_core_if_t *core_if;
  89930. + diepmsk_data_t intr_mask = {.d32 = 0 };
  89931. +
  89932. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "IN EP NAK");
  89933. + core_if = GET_CORE_IF(pcd);
  89934. + intr_mask.b.nak = 1;
  89935. +
  89936. + if (core_if->multiproc_int_enable) {
  89937. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  89938. + diepeachintmsk[epnum], intr_mask.d32, 0);
  89939. + } else {
  89940. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->diepmsk,
  89941. + intr_mask.d32, 0);
  89942. + }
  89943. +
  89944. + return 1;
  89945. +}
  89946. +
  89947. +/**
  89948. + * Handler for the OUT EP Babble interrupt.
  89949. + */
  89950. +static inline int32_t handle_out_ep_babble_intr(dwc_otg_pcd_t * pcd,
  89951. + const uint32_t epnum)
  89952. +{
  89953. + /** @todo implement ISR */
  89954. + dwc_otg_core_if_t *core_if;
  89955. + doepmsk_data_t intr_mask = {.d32 = 0 };
  89956. +
  89957. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n",
  89958. + "OUT EP Babble");
  89959. + core_if = GET_CORE_IF(pcd);
  89960. + intr_mask.b.babble = 1;
  89961. +
  89962. + if (core_if->multiproc_int_enable) {
  89963. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  89964. + doepeachintmsk[epnum], intr_mask.d32, 0);
  89965. + } else {
  89966. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  89967. + intr_mask.d32, 0);
  89968. + }
  89969. +
  89970. + return 1;
  89971. +}
  89972. +
  89973. +/**
  89974. + * Handler for the OUT EP NAK interrupt.
  89975. + */
  89976. +static inline int32_t handle_out_ep_nak_intr(dwc_otg_pcd_t * pcd,
  89977. + const uint32_t epnum)
  89978. +{
  89979. + /** @todo implement ISR */
  89980. + dwc_otg_core_if_t *core_if;
  89981. + doepmsk_data_t intr_mask = {.d32 = 0 };
  89982. +
  89983. + DWC_DEBUGPL(DBG_ANY, "INTERRUPT Handler not implemented for %s\n", "OUT EP NAK");
  89984. + core_if = GET_CORE_IF(pcd);
  89985. + intr_mask.b.nak = 1;
  89986. +
  89987. + if (core_if->multiproc_int_enable) {
  89988. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  89989. + doepeachintmsk[epnum], intr_mask.d32, 0);
  89990. + } else {
  89991. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  89992. + intr_mask.d32, 0);
  89993. + }
  89994. +
  89995. + return 1;
  89996. +}
  89997. +
  89998. +/**
  89999. + * Handler for the OUT EP NYET interrupt.
  90000. + */
  90001. +static inline int32_t handle_out_ep_nyet_intr(dwc_otg_pcd_t * pcd,
  90002. + const uint32_t epnum)
  90003. +{
  90004. + /** @todo implement ISR */
  90005. + dwc_otg_core_if_t *core_if;
  90006. + doepmsk_data_t intr_mask = {.d32 = 0 };
  90007. +
  90008. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "OUT EP NYET");
  90009. + core_if = GET_CORE_IF(pcd);
  90010. + intr_mask.b.nyet = 1;
  90011. +
  90012. + if (core_if->multiproc_int_enable) {
  90013. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  90014. + doepeachintmsk[epnum], intr_mask.d32, 0);
  90015. + } else {
  90016. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  90017. + intr_mask.d32, 0);
  90018. + }
  90019. +
  90020. + return 1;
  90021. +}
  90022. +
  90023. +/**
  90024. + * This interrupt indicates that an IN EP has a pending Interrupt.
  90025. + * The sequence for handling the IN EP interrupt is shown below:
  90026. + * -# Read the Device All Endpoint Interrupt register
  90027. + * -# Repeat the following for each IN EP interrupt bit set (from
  90028. + * LSB to MSB).
  90029. + * -# Read the Device Endpoint Interrupt (DIEPINTn) register
  90030. + * -# If "Transfer Complete" call the request complete function
  90031. + * -# If "Endpoint Disabled" complete the EP disable procedure.
  90032. + * -# If "AHB Error Interrupt" log error
  90033. + * -# If "Time-out Handshake" log error
  90034. + * -# If "IN Token Received when TxFIFO Empty" write packet to Tx
  90035. + * FIFO.
  90036. + * -# If "IN Token EP Mismatch" (disable, this is handled by EP
  90037. + * Mismatch Interrupt)
  90038. + */
  90039. +static int32_t dwc_otg_pcd_handle_in_ep_intr(dwc_otg_pcd_t * pcd)
  90040. +{
  90041. +#define CLEAR_IN_EP_INTR(__core_if,__epnum,__intr) \
  90042. +do { \
  90043. + diepint_data_t diepint = {.d32=0}; \
  90044. + diepint.b.__intr = 1; \
  90045. + DWC_WRITE_REG32(&__core_if->dev_if->in_ep_regs[__epnum]->diepint, \
  90046. + diepint.d32); \
  90047. +} while (0)
  90048. +
  90049. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  90050. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  90051. + diepint_data_t diepint = {.d32 = 0 };
  90052. + depctl_data_t depctl = {.d32 = 0 };
  90053. + uint32_t ep_intr;
  90054. + uint32_t epnum = 0;
  90055. + dwc_otg_pcd_ep_t *ep;
  90056. + dwc_ep_t *dwc_ep;
  90057. + gintmsk_data_t intr_mask = {.d32 = 0 };
  90058. +
  90059. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, pcd);
  90060. +
  90061. + /* Read in the device interrupt bits */
  90062. + ep_intr = dwc_otg_read_dev_all_in_ep_intr(core_if);
  90063. +
  90064. + /* Service the Device IN interrupts for each endpoint */
  90065. + while (ep_intr) {
  90066. + if (ep_intr & 0x1) {
  90067. + uint32_t empty_msk;
  90068. + /* Get EP pointer */
  90069. + ep = get_in_ep(pcd, epnum);
  90070. + dwc_ep = &ep->dwc_ep;
  90071. +
  90072. + depctl.d32 =
  90073. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  90074. + empty_msk =
  90075. + DWC_READ_REG32(&dev_if->
  90076. + dev_global_regs->dtknqr4_fifoemptymsk);
  90077. +
  90078. + DWC_DEBUGPL(DBG_PCDV,
  90079. + "IN EP INTERRUPT - %d\nepmty_msk - %8x diepctl - %8x\n",
  90080. + epnum, empty_msk, depctl.d32);
  90081. +
  90082. + DWC_DEBUGPL(DBG_PCD,
  90083. + "EP%d-%s: type=%d, mps=%d\n",
  90084. + dwc_ep->num, (dwc_ep->is_in ? "IN" : "OUT"),
  90085. + dwc_ep->type, dwc_ep->maxpacket);
  90086. +
  90087. + diepint.d32 =
  90088. + dwc_otg_read_dev_in_ep_intr(core_if, dwc_ep);
  90089. +
  90090. + DWC_DEBUGPL(DBG_PCDV,
  90091. + "EP %d Interrupt Register - 0x%x\n", epnum,
  90092. + diepint.d32);
  90093. + /* Transfer complete */
  90094. + if (diepint.b.xfercompl) {
  90095. + /* Disable the NP Tx FIFO Empty
  90096. + * Interrupt */
  90097. + if (core_if->en_multiple_tx_fifo == 0) {
  90098. + intr_mask.b.nptxfempty = 1;
  90099. + DWC_MODIFY_REG32
  90100. + (&core_if->core_global_regs->gintmsk,
  90101. + intr_mask.d32, 0);
  90102. + } else {
  90103. + /* Disable the Tx FIFO Empty Interrupt for this EP */
  90104. + uint32_t fifoemptymsk =
  90105. + 0x1 << dwc_ep->num;
  90106. + DWC_MODIFY_REG32(&core_if->
  90107. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  90108. + fifoemptymsk, 0);
  90109. + }
  90110. + /* Clear the bit in DIEPINTn for this interrupt */
  90111. + CLEAR_IN_EP_INTR(core_if, epnum, xfercompl);
  90112. +
  90113. + /* Complete the transfer */
  90114. + if (epnum == 0) {
  90115. + handle_ep0(pcd);
  90116. + }
  90117. +#ifdef DWC_EN_ISOC
  90118. + else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  90119. + if (!ep->stopped)
  90120. + complete_iso_ep(pcd, ep);
  90121. + }
  90122. +#endif /* DWC_EN_ISOC */
  90123. +#ifdef DWC_UTE_PER_IO
  90124. + else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  90125. + if (!ep->stopped)
  90126. + complete_xiso_ep(ep);
  90127. + }
  90128. +#endif /* DWC_UTE_PER_IO */
  90129. + else {
  90130. + if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC &&
  90131. + dwc_ep->bInterval > 1) {
  90132. + dwc_ep->frame_num += dwc_ep->bInterval;
  90133. + if (dwc_ep->frame_num > 0x3FFF)
  90134. + {
  90135. + dwc_ep->frm_overrun = 1;
  90136. + dwc_ep->frame_num &= 0x3FFF;
  90137. + } else
  90138. + dwc_ep->frm_overrun = 0;
  90139. + }
  90140. + complete_ep(ep);
  90141. + if(diepint.b.nak)
  90142. + CLEAR_IN_EP_INTR(core_if, epnum, nak);
  90143. + }
  90144. + }
  90145. + /* Endpoint disable */
  90146. + if (diepint.b.epdisabled) {
  90147. + DWC_DEBUGPL(DBG_ANY, "EP%d IN disabled\n",
  90148. + epnum);
  90149. + handle_in_ep_disable_intr(pcd, epnum);
  90150. +
  90151. + /* Clear the bit in DIEPINTn for this interrupt */
  90152. + CLEAR_IN_EP_INTR(core_if, epnum, epdisabled);
  90153. + }
  90154. + /* AHB Error */
  90155. + if (diepint.b.ahberr) {
  90156. + DWC_ERROR("EP%d IN AHB Error\n", epnum);
  90157. + /* Clear the bit in DIEPINTn for this interrupt */
  90158. + CLEAR_IN_EP_INTR(core_if, epnum, ahberr);
  90159. + }
  90160. + /* TimeOUT Handshake (non-ISOC IN EPs) */
  90161. + if (diepint.b.timeout) {
  90162. + DWC_ERROR("EP%d IN Time-out\n", epnum);
  90163. + handle_in_ep_timeout_intr(pcd, epnum);
  90164. +
  90165. + CLEAR_IN_EP_INTR(core_if, epnum, timeout);
  90166. + }
  90167. + /** IN Token received with TxF Empty */
  90168. + if (diepint.b.intktxfemp) {
  90169. + DWC_DEBUGPL(DBG_ANY,
  90170. + "EP%d IN TKN TxFifo Empty\n",
  90171. + epnum);
  90172. + if (!ep->stopped && epnum != 0) {
  90173. +
  90174. + diepmsk_data_t diepmsk = {.d32 = 0 };
  90175. + diepmsk.b.intktxfemp = 1;
  90176. +
  90177. + if (core_if->multiproc_int_enable) {
  90178. + DWC_MODIFY_REG32
  90179. + (&dev_if->dev_global_regs->diepeachintmsk
  90180. + [epnum], diepmsk.d32, 0);
  90181. + } else {
  90182. + DWC_MODIFY_REG32
  90183. + (&dev_if->dev_global_regs->diepmsk,
  90184. + diepmsk.d32, 0);
  90185. + }
  90186. + } else if (core_if->dma_desc_enable
  90187. + && epnum == 0
  90188. + && pcd->ep0state ==
  90189. + EP0_OUT_STATUS_PHASE) {
  90190. + // EP0 IN set STALL
  90191. + depctl.d32 =
  90192. + DWC_READ_REG32(&dev_if->in_ep_regs
  90193. + [epnum]->diepctl);
  90194. +
  90195. + /* set the disable and stall bits */
  90196. + if (depctl.b.epena) {
  90197. + depctl.b.epdis = 1;
  90198. + }
  90199. + depctl.b.stall = 1;
  90200. + DWC_WRITE_REG32(&dev_if->in_ep_regs
  90201. + [epnum]->diepctl,
  90202. + depctl.d32);
  90203. + }
  90204. + CLEAR_IN_EP_INTR(core_if, epnum, intktxfemp);
  90205. + }
  90206. + /** IN Token Received with EP mismatch */
  90207. + if (diepint.b.intknepmis) {
  90208. + DWC_DEBUGPL(DBG_ANY,
  90209. + "EP%d IN TKN EP Mismatch\n", epnum);
  90210. + CLEAR_IN_EP_INTR(core_if, epnum, intknepmis);
  90211. + }
  90212. + /** IN Endpoint NAK Effective */
  90213. + if (diepint.b.inepnakeff) {
  90214. + DWC_DEBUGPL(DBG_ANY,
  90215. + "EP%d IN EP NAK Effective\n",
  90216. + epnum);
  90217. + /* Periodic EP */
  90218. + if (ep->disabling) {
  90219. + depctl.d32 = 0;
  90220. + depctl.b.snak = 1;
  90221. + depctl.b.epdis = 1;
  90222. + DWC_MODIFY_REG32(&dev_if->in_ep_regs
  90223. + [epnum]->diepctl,
  90224. + depctl.d32,
  90225. + depctl.d32);
  90226. + }
  90227. + CLEAR_IN_EP_INTR(core_if, epnum, inepnakeff);
  90228. +
  90229. + }
  90230. +
  90231. + /** IN EP Tx FIFO Empty Intr */
  90232. + if (diepint.b.emptyintr) {
  90233. + DWC_DEBUGPL(DBG_ANY,
  90234. + "EP%d Tx FIFO Empty Intr \n",
  90235. + epnum);
  90236. + write_empty_tx_fifo(pcd, epnum);
  90237. +
  90238. + CLEAR_IN_EP_INTR(core_if, epnum, emptyintr);
  90239. +
  90240. + }
  90241. +
  90242. + /** IN EP BNA Intr */
  90243. + if (diepint.b.bna) {
  90244. + CLEAR_IN_EP_INTR(core_if, epnum, bna);
  90245. + if (core_if->dma_desc_enable) {
  90246. +#ifdef DWC_EN_ISOC
  90247. + if (dwc_ep->type ==
  90248. + DWC_OTG_EP_TYPE_ISOC) {
  90249. + /*
  90250. + * This checking is performed to prevent first "false" BNA
  90251. + * handling occuring right after reconnect
  90252. + */
  90253. + if (dwc_ep->next_frame !=
  90254. + 0xffffffff)
  90255. + dwc_otg_pcd_handle_iso_bna(ep);
  90256. + } else
  90257. +#endif /* DWC_EN_ISOC */
  90258. + {
  90259. + dwc_otg_pcd_handle_noniso_bna(ep);
  90260. + }
  90261. + }
  90262. + }
  90263. + /* NAK Interrutp */
  90264. + if (diepint.b.nak) {
  90265. + DWC_DEBUGPL(DBG_ANY, "EP%d IN NAK Interrupt\n",
  90266. + epnum);
  90267. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  90268. + depctl_data_t depctl;
  90269. + if (ep->dwc_ep.frame_num == 0xFFFFFFFF) {
  90270. + ep->dwc_ep.frame_num = core_if->frame_num;
  90271. + if (ep->dwc_ep.bInterval > 1) {
  90272. + depctl.d32 = 0;
  90273. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  90274. + if (ep->dwc_ep.frame_num & 0x1) {
  90275. + depctl.b.setd1pid = 1;
  90276. + depctl.b.setd0pid = 0;
  90277. + } else {
  90278. + depctl.b.setd0pid = 1;
  90279. + depctl.b.setd1pid = 0;
  90280. + }
  90281. + DWC_WRITE_REG32(&dev_if->in_ep_regs[epnum]->diepctl, depctl.d32);
  90282. + }
  90283. + start_next_request(ep);
  90284. + }
  90285. + ep->dwc_ep.frame_num += ep->dwc_ep.bInterval;
  90286. + if (dwc_ep->frame_num > 0x3FFF) {
  90287. + dwc_ep->frm_overrun = 1;
  90288. + dwc_ep->frame_num &= 0x3FFF;
  90289. + } else
  90290. + dwc_ep->frm_overrun = 0;
  90291. + }
  90292. +
  90293. + CLEAR_IN_EP_INTR(core_if, epnum, nak);
  90294. + }
  90295. + }
  90296. + epnum++;
  90297. + ep_intr >>= 1;
  90298. + }
  90299. +
  90300. + return 1;
  90301. +#undef CLEAR_IN_EP_INTR
  90302. +}
  90303. +
  90304. +/**
  90305. + * This interrupt indicates that an OUT EP has a pending Interrupt.
  90306. + * The sequence for handling the OUT EP interrupt is shown below:
  90307. + * -# Read the Device All Endpoint Interrupt register
  90308. + * -# Repeat the following for each OUT EP interrupt bit set (from
  90309. + * LSB to MSB).
  90310. + * -# Read the Device Endpoint Interrupt (DOEPINTn) register
  90311. + * -# If "Transfer Complete" call the request complete function
  90312. + * -# If "Endpoint Disabled" complete the EP disable procedure.
  90313. + * -# If "AHB Error Interrupt" log error
  90314. + * -# If "Setup Phase Done" process Setup Packet (See Standard USB
  90315. + * Command Processing)
  90316. + */
  90317. +static int32_t dwc_otg_pcd_handle_out_ep_intr(dwc_otg_pcd_t * pcd)
  90318. +{
  90319. +#define CLEAR_OUT_EP_INTR(__core_if,__epnum,__intr) \
  90320. +do { \
  90321. + doepint_data_t doepint = {.d32=0}; \
  90322. + doepint.b.__intr = 1; \
  90323. + DWC_WRITE_REG32(&__core_if->dev_if->out_ep_regs[__epnum]->doepint, \
  90324. + doepint.d32); \
  90325. +} while (0)
  90326. +
  90327. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  90328. + uint32_t ep_intr;
  90329. + doepint_data_t doepint = {.d32 = 0 };
  90330. + uint32_t epnum = 0;
  90331. + dwc_otg_pcd_ep_t *ep;
  90332. + dwc_ep_t *dwc_ep;
  90333. + dctl_data_t dctl = {.d32 = 0 };
  90334. + gintmsk_data_t gintmsk = {.d32 = 0 };
  90335. +
  90336. +
  90337. + DWC_DEBUGPL(DBG_PCDV, "%s()\n", __func__);
  90338. +
  90339. + /* Read in the device interrupt bits */
  90340. + ep_intr = dwc_otg_read_dev_all_out_ep_intr(core_if);
  90341. +
  90342. + while (ep_intr) {
  90343. + if (ep_intr & 0x1) {
  90344. + /* Get EP pointer */
  90345. + ep = get_out_ep(pcd, epnum);
  90346. + dwc_ep = &ep->dwc_ep;
  90347. +
  90348. +#ifdef VERBOSE
  90349. + DWC_DEBUGPL(DBG_PCDV,
  90350. + "EP%d-%s: type=%d, mps=%d\n",
  90351. + dwc_ep->num, (dwc_ep->is_in ? "IN" : "OUT"),
  90352. + dwc_ep->type, dwc_ep->maxpacket);
  90353. +#endif
  90354. + doepint.d32 =
  90355. + dwc_otg_read_dev_out_ep_intr(core_if, dwc_ep);
  90356. + /* Moved this interrupt upper due to core deffect of asserting
  90357. + * OUT EP 0 xfercompl along with stsphsrcvd in BDMA */
  90358. + if (doepint.b.stsphsercvd) {
  90359. + deptsiz0_data_t deptsiz;
  90360. + CLEAR_OUT_EP_INTR(core_if, epnum, stsphsercvd);
  90361. + deptsiz.d32 =
  90362. + DWC_READ_REG32(&core_if->dev_if->
  90363. + out_ep_regs[0]->doeptsiz);
  90364. + if (core_if->snpsid >= OTG_CORE_REV_3_00a
  90365. + && core_if->dma_enable
  90366. + && core_if->dma_desc_enable == 0
  90367. + && doepint.b.xfercompl
  90368. + && deptsiz.b.xfersize == 24) {
  90369. + CLEAR_OUT_EP_INTR(core_if, epnum,
  90370. + xfercompl);
  90371. + doepint.b.xfercompl = 0;
  90372. + ep0_out_start(core_if, pcd);
  90373. + }
  90374. + if ((core_if->dma_desc_enable) ||
  90375. + (core_if->dma_enable
  90376. + && core_if->snpsid >=
  90377. + OTG_CORE_REV_3_00a)) {
  90378. + do_setup_in_status_phase(pcd);
  90379. + }
  90380. + }
  90381. + /* Transfer complete */
  90382. + if (doepint.b.xfercompl) {
  90383. +
  90384. + if (epnum == 0) {
  90385. + /* Clear the bit in DOEPINTn for this interrupt */
  90386. + CLEAR_OUT_EP_INTR(core_if, epnum, xfercompl);
  90387. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  90388. + DWC_DEBUGPL(DBG_PCDV, "DOEPINT=%x doepint=%x\n",
  90389. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[0]->doepint),
  90390. + doepint.d32);
  90391. + DWC_DEBUGPL(DBG_PCDV, "DOEPCTL=%x \n",
  90392. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[0]->doepctl));
  90393. +
  90394. + if (core_if->snpsid >= OTG_CORE_REV_3_00a
  90395. + && core_if->dma_enable == 0) {
  90396. + doepint_data_t doepint;
  90397. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  90398. + out_ep_regs[0]->doepint);
  90399. + if (pcd->ep0state == EP0_IDLE && doepint.b.sr) {
  90400. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  90401. + goto exit_xfercompl;
  90402. + }
  90403. + }
  90404. + /* In case of DDMA look at SR bit to go to the Data Stage */
  90405. + if (core_if->dma_desc_enable) {
  90406. + dev_dma_desc_sts_t status = {.d32 = 0};
  90407. + if (pcd->ep0state == EP0_IDLE) {
  90408. + status.d32 = core_if->dev_if->setup_desc_addr[core_if->
  90409. + dev_if->setup_desc_index]->status.d32;
  90410. + if(pcd->data_terminated) {
  90411. + pcd->data_terminated = 0;
  90412. + status.d32 = core_if->dev_if->out_desc_addr->status.d32;
  90413. + dwc_memcpy(&pcd->setup_pkt->req, pcd->backup_buf, 8);
  90414. + }
  90415. + if (status.b.sr) {
  90416. + if (doepint.b.setup) {
  90417. + DWC_DEBUGPL(DBG_PCDV, "DMA DESC EP0_IDLE SR=1 setup=1\n");
  90418. + /* Already started data stage, clear setup */
  90419. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  90420. + doepint.b.setup = 0;
  90421. + handle_ep0(pcd);
  90422. + /* Prepare for more setup packets */
  90423. + if (pcd->ep0state == EP0_IN_STATUS_PHASE ||
  90424. + pcd->ep0state == EP0_IN_DATA_PHASE) {
  90425. + ep0_out_start(core_if, pcd);
  90426. + }
  90427. +
  90428. + goto exit_xfercompl;
  90429. + } else {
  90430. + /* Prepare for more setup packets */
  90431. + DWC_DEBUGPL(DBG_PCDV,
  90432. + "EP0_IDLE SR=1 setup=0 new setup comes\n");
  90433. + ep0_out_start(core_if, pcd);
  90434. + }
  90435. + }
  90436. + } else {
  90437. + dwc_otg_pcd_request_t *req;
  90438. + dev_dma_desc_sts_t status = {.d32 = 0};
  90439. + diepint_data_t diepint0;
  90440. + diepint0.d32 = DWC_READ_REG32(&core_if->dev_if->
  90441. + in_ep_regs[0]->diepint);
  90442. +
  90443. + if (pcd->ep0state == EP0_STALL || pcd->ep0state == EP0_DISCONNECT) {
  90444. + DWC_ERROR("EP0 is stalled/disconnected\n");
  90445. + }
  90446. +
  90447. + /* Clear IN xfercompl if set */
  90448. + if (diepint0.b.xfercompl && (pcd->ep0state == EP0_IN_STATUS_PHASE
  90449. + || pcd->ep0state == EP0_IN_DATA_PHASE)) {
  90450. + DWC_WRITE_REG32(&core_if->dev_if->
  90451. + in_ep_regs[0]->diepint, diepint0.d32);
  90452. + }
  90453. +
  90454. + status.d32 = core_if->dev_if->setup_desc_addr[core_if->
  90455. + dev_if->setup_desc_index]->status.d32;
  90456. +
  90457. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len
  90458. + && (pcd->ep0state == EP0_OUT_DATA_PHASE))
  90459. + status.d32 = core_if->dev_if->out_desc_addr->status.d32;
  90460. + if (pcd->ep0state == EP0_OUT_STATUS_PHASE)
  90461. + status.d32 = core_if->dev_if->
  90462. + out_desc_addr->status.d32;
  90463. +
  90464. + if (status.b.sr) {
  90465. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  90466. + DWC_DEBUGPL(DBG_PCDV, "Request queue empty!!\n");
  90467. + } else {
  90468. + DWC_DEBUGPL(DBG_PCDV, "complete req!!\n");
  90469. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  90470. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len &&
  90471. + pcd->ep0state == EP0_OUT_DATA_PHASE) {
  90472. + /* Read arrived setup packet from req->buf */
  90473. + dwc_memcpy(&pcd->setup_pkt->req,
  90474. + req->buf + ep->dwc_ep.xfer_count, 8);
  90475. + }
  90476. + req->actual = ep->dwc_ep.xfer_count;
  90477. + dwc_otg_request_done(ep, req, -ECONNRESET);
  90478. + ep->dwc_ep.start_xfer_buff = 0;
  90479. + ep->dwc_ep.xfer_buff = 0;
  90480. + ep->dwc_ep.xfer_len = 0;
  90481. + }
  90482. + pcd->ep0state = EP0_IDLE;
  90483. + if (doepint.b.setup) {
  90484. + DWC_DEBUGPL(DBG_PCDV, "EP0_IDLE SR=1 setup=1\n");
  90485. + /* Data stage started, clear setup */
  90486. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  90487. + doepint.b.setup = 0;
  90488. + handle_ep0(pcd);
  90489. + /* Prepare for setup packets if ep0in was enabled*/
  90490. + if (pcd->ep0state == EP0_IN_STATUS_PHASE) {
  90491. + ep0_out_start(core_if, pcd);
  90492. + }
  90493. +
  90494. + goto exit_xfercompl;
  90495. + } else {
  90496. + /* Prepare for more setup packets */
  90497. + DWC_DEBUGPL(DBG_PCDV,
  90498. + "EP0_IDLE SR=1 setup=0 new setup comes 2\n");
  90499. + ep0_out_start(core_if, pcd);
  90500. + }
  90501. + }
  90502. + }
  90503. + }
  90504. + if (core_if->snpsid >= OTG_CORE_REV_2_94a && core_if->dma_enable
  90505. + && core_if->dma_desc_enable == 0) {
  90506. + doepint_data_t doepint_temp = {.d32 = 0};
  90507. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  90508. + doepint_temp.d32 = DWC_READ_REG32(&core_if->dev_if->
  90509. + out_ep_regs[ep->dwc_ep.num]->doepint);
  90510. + doeptsize0.d32 = DWC_READ_REG32(&core_if->dev_if->
  90511. + out_ep_regs[ep->dwc_ep.num]->doeptsiz);
  90512. + if (pcd->ep0state == EP0_IDLE) {
  90513. + if (doepint_temp.b.sr) {
  90514. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  90515. + }
  90516. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  90517. + out_ep_regs[0]->doepint);
  90518. + if (doeptsize0.b.supcnt == 3) {
  90519. + DWC_DEBUGPL(DBG_ANY, "Rolling over!!!!!!!\n");
  90520. + ep->dwc_ep.stp_rollover = 1;
  90521. + }
  90522. + if (doepint.b.setup) {
  90523. +retry:
  90524. + /* Already started data stage, clear setup */
  90525. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  90526. + doepint.b.setup = 0;
  90527. + handle_ep0(pcd);
  90528. + ep->dwc_ep.stp_rollover = 0;
  90529. + /* Prepare for more setup packets */
  90530. + if (pcd->ep0state == EP0_IN_STATUS_PHASE ||
  90531. + pcd->ep0state == EP0_IN_DATA_PHASE) {
  90532. + ep0_out_start(core_if, pcd);
  90533. + }
  90534. + goto exit_xfercompl;
  90535. + } else {
  90536. + /* Prepare for more setup packets */
  90537. + DWC_DEBUGPL(DBG_ANY,
  90538. + "EP0_IDLE SR=1 setup=0 new setup comes\n");
  90539. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  90540. + out_ep_regs[0]->doepint);
  90541. + if(doepint.b.setup)
  90542. + goto retry;
  90543. + ep0_out_start(core_if, pcd);
  90544. + }
  90545. + } else {
  90546. + dwc_otg_pcd_request_t *req;
  90547. + diepint_data_t diepint0 = {.d32 = 0};
  90548. + doepint_data_t doepint_temp = {.d32 = 0};
  90549. + depctl_data_t diepctl0;
  90550. + diepint0.d32 = DWC_READ_REG32(&core_if->dev_if->
  90551. + in_ep_regs[0]->diepint);
  90552. + diepctl0.d32 = DWC_READ_REG32(&core_if->dev_if->
  90553. + in_ep_regs[0]->diepctl);
  90554. +
  90555. + if (pcd->ep0state == EP0_IN_DATA_PHASE
  90556. + || pcd->ep0state == EP0_IN_STATUS_PHASE) {
  90557. + if (diepint0.b.xfercompl) {
  90558. + DWC_WRITE_REG32(&core_if->dev_if->
  90559. + in_ep_regs[0]->diepint, diepint0.d32);
  90560. + }
  90561. + if (diepctl0.b.epena) {
  90562. + diepint_data_t diepint = {.d32 = 0};
  90563. + diepctl0.b.snak = 1;
  90564. + DWC_WRITE_REG32(&core_if->dev_if->
  90565. + in_ep_regs[0]->diepctl, diepctl0.d32);
  90566. + do {
  90567. + dwc_udelay(10);
  90568. + diepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  90569. + in_ep_regs[0]->diepint);
  90570. + } while (!diepint.b.inepnakeff);
  90571. + diepint.b.inepnakeff = 1;
  90572. + DWC_WRITE_REG32(&core_if->dev_if->
  90573. + in_ep_regs[0]->diepint, diepint.d32);
  90574. + diepctl0.d32 = 0;
  90575. + diepctl0.b.epdis = 1;
  90576. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[0]->diepctl,
  90577. + diepctl0.d32);
  90578. + do {
  90579. + dwc_udelay(10);
  90580. + diepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  90581. + in_ep_regs[0]->diepint);
  90582. + } while (!diepint.b.epdisabled);
  90583. + diepint.b.epdisabled = 1;
  90584. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[0]->diepint,
  90585. + diepint.d32);
  90586. + }
  90587. + }
  90588. + doepint_temp.d32 = DWC_READ_REG32(&core_if->dev_if->
  90589. + out_ep_regs[ep->dwc_ep.num]->doepint);
  90590. + if (doepint_temp.b.sr) {
  90591. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  90592. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  90593. + DWC_DEBUGPL(DBG_PCDV, "Request queue empty!!\n");
  90594. + } else {
  90595. + DWC_DEBUGPL(DBG_PCDV, "complete req!!\n");
  90596. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  90597. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len &&
  90598. + pcd->ep0state == EP0_OUT_DATA_PHASE) {
  90599. + /* Read arrived setup packet from req->buf */
  90600. + dwc_memcpy(&pcd->setup_pkt->req,
  90601. + req->buf + ep->dwc_ep.xfer_count, 8);
  90602. + }
  90603. + req->actual = ep->dwc_ep.xfer_count;
  90604. + dwc_otg_request_done(ep, req, -ECONNRESET);
  90605. + ep->dwc_ep.start_xfer_buff = 0;
  90606. + ep->dwc_ep.xfer_buff = 0;
  90607. + ep->dwc_ep.xfer_len = 0;
  90608. + }
  90609. + pcd->ep0state = EP0_IDLE;
  90610. + if (doepint.b.setup) {
  90611. + DWC_DEBUGPL(DBG_PCDV, "EP0_IDLE SR=1 setup=1\n");
  90612. + /* Data stage started, clear setup */
  90613. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  90614. + doepint.b.setup = 0;
  90615. + handle_ep0(pcd);
  90616. + /* Prepare for setup packets if ep0in was enabled*/
  90617. + if (pcd->ep0state == EP0_IN_STATUS_PHASE) {
  90618. + ep0_out_start(core_if, pcd);
  90619. + }
  90620. + goto exit_xfercompl;
  90621. + } else {
  90622. + /* Prepare for more setup packets */
  90623. + DWC_DEBUGPL(DBG_PCDV,
  90624. + "EP0_IDLE SR=1 setup=0 new setup comes 2\n");
  90625. + ep0_out_start(core_if, pcd);
  90626. + }
  90627. + }
  90628. + }
  90629. + }
  90630. + if (core_if->dma_enable == 0 || pcd->ep0state != EP0_IDLE)
  90631. + handle_ep0(pcd);
  90632. +exit_xfercompl:
  90633. + DWC_DEBUGPL(DBG_PCDV, "DOEPINT=%x doepint=%x\n",
  90634. + dwc_otg_read_dev_out_ep_intr(core_if, dwc_ep), doepint.d32);
  90635. + } else {
  90636. + if (core_if->dma_desc_enable == 0
  90637. + || pcd->ep0state != EP0_IDLE)
  90638. + handle_ep0(pcd);
  90639. + }
  90640. +#ifdef DWC_EN_ISOC
  90641. + } else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  90642. + if (doepint.b.pktdrpsts == 0) {
  90643. + /* Clear the bit in DOEPINTn for this interrupt */
  90644. + CLEAR_OUT_EP_INTR(core_if,
  90645. + epnum,
  90646. + xfercompl);
  90647. + complete_iso_ep(pcd, ep);
  90648. + } else {
  90649. +
  90650. + doepint_data_t doepint = {.d32 = 0 };
  90651. + doepint.b.xfercompl = 1;
  90652. + doepint.b.pktdrpsts = 1;
  90653. + DWC_WRITE_REG32
  90654. + (&core_if->dev_if->out_ep_regs
  90655. + [epnum]->doepint,
  90656. + doepint.d32);
  90657. + if (handle_iso_out_pkt_dropped
  90658. + (core_if, dwc_ep)) {
  90659. + complete_iso_ep(pcd,
  90660. + ep);
  90661. + }
  90662. + }
  90663. +#endif /* DWC_EN_ISOC */
  90664. +#ifdef DWC_UTE_PER_IO
  90665. + } else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  90666. + CLEAR_OUT_EP_INTR(core_if, epnum, xfercompl);
  90667. + if (!ep->stopped)
  90668. + complete_xiso_ep(ep);
  90669. +#endif /* DWC_UTE_PER_IO */
  90670. + } else {
  90671. + /* Clear the bit in DOEPINTn for this interrupt */
  90672. + CLEAR_OUT_EP_INTR(core_if, epnum,
  90673. + xfercompl);
  90674. +
  90675. + if (core_if->core_params->dev_out_nak) {
  90676. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[epnum]);
  90677. + pcd->core_if->ep_xfer_info[epnum].state = 0;
  90678. +#ifdef DEBUG
  90679. + print_memory_payload(pcd, dwc_ep);
  90680. +#endif
  90681. + }
  90682. + complete_ep(ep);
  90683. + }
  90684. +
  90685. + }
  90686. +
  90687. + /* Endpoint disable */
  90688. + if (doepint.b.epdisabled) {
  90689. +
  90690. + /* Clear the bit in DOEPINTn for this interrupt */
  90691. + CLEAR_OUT_EP_INTR(core_if, epnum, epdisabled);
  90692. + if (core_if->core_params->dev_out_nak) {
  90693. +#ifdef DEBUG
  90694. + print_memory_payload(pcd, dwc_ep);
  90695. +#endif
  90696. + /* In case of timeout condition */
  90697. + if (core_if->ep_xfer_info[epnum].state == 2) {
  90698. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  90699. + dev_global_regs->dctl);
  90700. + dctl.b.cgoutnak = 1;
  90701. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  90702. + dctl.d32);
  90703. + /* Unmask goutnakeff interrupt which was masked
  90704. + * during handle nak out interrupt */
  90705. + gintmsk.b.goutnakeff = 1;
  90706. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  90707. + 0, gintmsk.d32);
  90708. +
  90709. + complete_ep(ep);
  90710. + }
  90711. + }
  90712. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC)
  90713. + {
  90714. + dctl_data_t dctl;
  90715. + gintmsk_data_t intr_mask = {.d32 = 0};
  90716. + dwc_otg_pcd_request_t *req = 0;
  90717. +
  90718. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  90719. + dev_global_regs->dctl);
  90720. + dctl.b.cgoutnak = 1;
  90721. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  90722. + dctl.d32);
  90723. +
  90724. + intr_mask.d32 = 0;
  90725. + intr_mask.b.incomplisoout = 1;
  90726. +
  90727. + /* Get any pending requests */
  90728. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  90729. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  90730. + if (!req) {
  90731. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  90732. + } else {
  90733. + dwc_otg_request_done(ep, req, 0);
  90734. + start_next_request(ep);
  90735. + }
  90736. + } else {
  90737. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  90738. + }
  90739. + }
  90740. + }
  90741. + /* AHB Error */
  90742. + if (doepint.b.ahberr) {
  90743. + DWC_ERROR("EP%d OUT AHB Error\n", epnum);
  90744. + DWC_ERROR("EP%d DEPDMA=0x%08x \n",
  90745. + epnum, core_if->dev_if->out_ep_regs[epnum]->doepdma);
  90746. + CLEAR_OUT_EP_INTR(core_if, epnum, ahberr);
  90747. + }
  90748. + /* Setup Phase Done (contorl EPs) */
  90749. + if (doepint.b.setup) {
  90750. +#ifdef DEBUG_EP0
  90751. + DWC_DEBUGPL(DBG_PCD, "EP%d SETUP Done\n", epnum);
  90752. +#endif
  90753. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  90754. +
  90755. + handle_ep0(pcd);
  90756. + }
  90757. +
  90758. + /** OUT EP BNA Intr */
  90759. + if (doepint.b.bna) {
  90760. + CLEAR_OUT_EP_INTR(core_if, epnum, bna);
  90761. + if (core_if->dma_desc_enable) {
  90762. +#ifdef DWC_EN_ISOC
  90763. + if (dwc_ep->type ==
  90764. + DWC_OTG_EP_TYPE_ISOC) {
  90765. + /*
  90766. + * This checking is performed to prevent first "false" BNA
  90767. + * handling occuring right after reconnect
  90768. + */
  90769. + if (dwc_ep->next_frame !=
  90770. + 0xffffffff)
  90771. + dwc_otg_pcd_handle_iso_bna(ep);
  90772. + } else
  90773. +#endif /* DWC_EN_ISOC */
  90774. + {
  90775. + dwc_otg_pcd_handle_noniso_bna(ep);
  90776. + }
  90777. + }
  90778. + }
  90779. + /* Babble Interrupt */
  90780. + if (doepint.b.babble) {
  90781. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT Babble\n",
  90782. + epnum);
  90783. + handle_out_ep_babble_intr(pcd, epnum);
  90784. +
  90785. + CLEAR_OUT_EP_INTR(core_if, epnum, babble);
  90786. + }
  90787. + if (doepint.b.outtknepdis) {
  90788. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT Token received when EP is \
  90789. + disabled\n",epnum);
  90790. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  90791. + doepmsk_data_t doepmsk = {.d32 = 0};
  90792. + ep->dwc_ep.frame_num = core_if->frame_num;
  90793. + if (ep->dwc_ep.bInterval > 1) {
  90794. + depctl_data_t depctl;
  90795. + depctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  90796. + out_ep_regs[epnum]->doepctl);
  90797. + if (ep->dwc_ep.frame_num & 0x1) {
  90798. + depctl.b.setd1pid = 1;
  90799. + depctl.b.setd0pid = 0;
  90800. + } else {
  90801. + depctl.b.setd0pid = 1;
  90802. + depctl.b.setd1pid = 0;
  90803. + }
  90804. + DWC_WRITE_REG32(&core_if->dev_if->
  90805. + out_ep_regs[epnum]->doepctl, depctl.d32);
  90806. + }
  90807. + start_next_request(ep);
  90808. + doepmsk.b.outtknepdis = 1;
  90809. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  90810. + doepmsk.d32, 0);
  90811. + }
  90812. + CLEAR_OUT_EP_INTR(core_if, epnum, outtknepdis);
  90813. + }
  90814. +
  90815. + /* NAK Interrutp */
  90816. + if (doepint.b.nak) {
  90817. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT NAK\n", epnum);
  90818. + handle_out_ep_nak_intr(pcd, epnum);
  90819. +
  90820. + CLEAR_OUT_EP_INTR(core_if, epnum, nak);
  90821. + }
  90822. + /* NYET Interrutp */
  90823. + if (doepint.b.nyet) {
  90824. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT NYET\n", epnum);
  90825. + handle_out_ep_nyet_intr(pcd, epnum);
  90826. +
  90827. + CLEAR_OUT_EP_INTR(core_if, epnum, nyet);
  90828. + }
  90829. + }
  90830. +
  90831. + epnum++;
  90832. + ep_intr >>= 1;
  90833. + }
  90834. +
  90835. + return 1;
  90836. +
  90837. +#undef CLEAR_OUT_EP_INTR
  90838. +}
  90839. +static int drop_transfer(uint32_t trgt_fr, uint32_t curr_fr, uint8_t frm_overrun)
  90840. +{
  90841. + int retval = 0;
  90842. + if(!frm_overrun && curr_fr >= trgt_fr)
  90843. + retval = 1;
  90844. + else if (frm_overrun
  90845. + && (curr_fr >= trgt_fr && ((curr_fr - trgt_fr) < 0x3FFF / 2)))
  90846. + retval = 1;
  90847. + return retval;
  90848. +}
  90849. +/**
  90850. + * Incomplete ISO IN Transfer Interrupt.
  90851. + * This interrupt indicates one of the following conditions occurred
  90852. + * while transmitting an ISOC transaction.
  90853. + * - Corrupted IN Token for ISOC EP.
  90854. + * - Packet not complete in FIFO.
  90855. + * The follow actions will be taken:
  90856. + * -# Determine the EP
  90857. + * -# Set incomplete flag in dwc_ep structure
  90858. + * -# Disable EP; when "Endpoint Disabled" interrupt is received
  90859. + * Flush FIFO
  90860. + */
  90861. +int32_t dwc_otg_pcd_handle_incomplete_isoc_in_intr(dwc_otg_pcd_t * pcd)
  90862. +{
  90863. + gintsts_data_t gintsts;
  90864. +
  90865. +#ifdef DWC_EN_ISOC
  90866. + dwc_otg_dev_if_t *dev_if;
  90867. + deptsiz_data_t deptsiz = {.d32 = 0 };
  90868. + depctl_data_t depctl = {.d32 = 0 };
  90869. + dsts_data_t dsts = {.d32 = 0 };
  90870. + dwc_ep_t *dwc_ep;
  90871. + int i;
  90872. +
  90873. + dev_if = GET_CORE_IF(pcd)->dev_if;
  90874. +
  90875. + for (i = 1; i <= dev_if->num_in_eps; ++i) {
  90876. + dwc_ep = &pcd->in_ep[i].dwc_ep;
  90877. + if (dwc_ep->active && dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  90878. + deptsiz.d32 =
  90879. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  90880. + depctl.d32 =
  90881. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  90882. +
  90883. + if (depctl.b.epdis && deptsiz.d32) {
  90884. + set_current_pkt_info(GET_CORE_IF(pcd), dwc_ep);
  90885. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  90886. + dwc_ep->cur_pkt = 0;
  90887. + dwc_ep->proc_buf_num =
  90888. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  90889. +
  90890. + if (dwc_ep->proc_buf_num) {
  90891. + dwc_ep->cur_pkt_addr =
  90892. + dwc_ep->xfer_buff1;
  90893. + dwc_ep->cur_pkt_dma_addr =
  90894. + dwc_ep->dma_addr1;
  90895. + } else {
  90896. + dwc_ep->cur_pkt_addr =
  90897. + dwc_ep->xfer_buff0;
  90898. + dwc_ep->cur_pkt_dma_addr =
  90899. + dwc_ep->dma_addr0;
  90900. + }
  90901. +
  90902. + }
  90903. +
  90904. + dsts.d32 =
  90905. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  90906. + dev_global_regs->dsts);
  90907. + dwc_ep->next_frame = dsts.b.soffn;
  90908. +
  90909. + dwc_otg_iso_ep_start_frm_transfer(GET_CORE_IF
  90910. + (pcd),
  90911. + dwc_ep);
  90912. + }
  90913. + }
  90914. + }
  90915. +
  90916. +#else
  90917. + depctl_data_t depctl = {.d32 = 0 };
  90918. + dwc_ep_t *dwc_ep;
  90919. + dwc_otg_dev_if_t *dev_if;
  90920. + int i;
  90921. + dev_if = GET_CORE_IF(pcd)->dev_if;
  90922. +
  90923. + DWC_DEBUGPL(DBG_PCD,"Incomplete ISO IN \n");
  90924. +
  90925. + for (i = 1; i <= dev_if->num_in_eps; ++i) {
  90926. + dwc_ep = &pcd->in_ep[i-1].dwc_ep;
  90927. + depctl.d32 =
  90928. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  90929. + if (depctl.b.epena && dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  90930. + if (drop_transfer(dwc_ep->frame_num, GET_CORE_IF(pcd)->frame_num,
  90931. + dwc_ep->frm_overrun))
  90932. + {
  90933. + depctl.d32 =
  90934. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  90935. + depctl.b.snak = 1;
  90936. + depctl.b.epdis = 1;
  90937. + DWC_MODIFY_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32, depctl.d32);
  90938. + }
  90939. + }
  90940. + }
  90941. +
  90942. + /*intr_mask.b.incomplisoin = 1;
  90943. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  90944. + intr_mask.d32, 0); */
  90945. +#endif //DWC_EN_ISOC
  90946. +
  90947. + /* Clear interrupt */
  90948. + gintsts.d32 = 0;
  90949. + gintsts.b.incomplisoin = 1;
  90950. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  90951. + gintsts.d32);
  90952. +
  90953. + return 1;
  90954. +}
  90955. +
  90956. +/**
  90957. + * Incomplete ISO OUT Transfer Interrupt.
  90958. + *
  90959. + * This interrupt indicates that the core has dropped an ISO OUT
  90960. + * packet. The following conditions can be the cause:
  90961. + * - FIFO Full, the entire packet would not fit in the FIFO.
  90962. + * - CRC Error
  90963. + * - Corrupted Token
  90964. + * The follow actions will be taken:
  90965. + * -# Determine the EP
  90966. + * -# Set incomplete flag in dwc_ep structure
  90967. + * -# Read any data from the FIFO
  90968. + * -# Disable EP. When "Endpoint Disabled" interrupt is received
  90969. + * re-enable EP.
  90970. + */
  90971. +int32_t dwc_otg_pcd_handle_incomplete_isoc_out_intr(dwc_otg_pcd_t * pcd)
  90972. +{
  90973. +
  90974. + gintsts_data_t gintsts;
  90975. +
  90976. +#ifdef DWC_EN_ISOC
  90977. + dwc_otg_dev_if_t *dev_if;
  90978. + deptsiz_data_t deptsiz = {.d32 = 0 };
  90979. + depctl_data_t depctl = {.d32 = 0 };
  90980. + dsts_data_t dsts = {.d32 = 0 };
  90981. + dwc_ep_t *dwc_ep;
  90982. + int i;
  90983. +
  90984. + dev_if = GET_CORE_IF(pcd)->dev_if;
  90985. +
  90986. + for (i = 1; i <= dev_if->num_out_eps; ++i) {
  90987. + dwc_ep = &pcd->in_ep[i].dwc_ep;
  90988. + if (pcd->out_ep[i].dwc_ep.active &&
  90989. + pcd->out_ep[i].dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  90990. + deptsiz.d32 =
  90991. + DWC_READ_REG32(&dev_if->out_ep_regs[i]->doeptsiz);
  90992. + depctl.d32 =
  90993. + DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  90994. +
  90995. + if (depctl.b.epdis && deptsiz.d32) {
  90996. + set_current_pkt_info(GET_CORE_IF(pcd),
  90997. + &pcd->out_ep[i].dwc_ep);
  90998. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  90999. + dwc_ep->cur_pkt = 0;
  91000. + dwc_ep->proc_buf_num =
  91001. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  91002. +
  91003. + if (dwc_ep->proc_buf_num) {
  91004. + dwc_ep->cur_pkt_addr =
  91005. + dwc_ep->xfer_buff1;
  91006. + dwc_ep->cur_pkt_dma_addr =
  91007. + dwc_ep->dma_addr1;
  91008. + } else {
  91009. + dwc_ep->cur_pkt_addr =
  91010. + dwc_ep->xfer_buff0;
  91011. + dwc_ep->cur_pkt_dma_addr =
  91012. + dwc_ep->dma_addr0;
  91013. + }
  91014. +
  91015. + }
  91016. +
  91017. + dsts.d32 =
  91018. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  91019. + dev_global_regs->dsts);
  91020. + dwc_ep->next_frame = dsts.b.soffn;
  91021. +
  91022. + dwc_otg_iso_ep_start_frm_transfer(GET_CORE_IF
  91023. + (pcd),
  91024. + dwc_ep);
  91025. + }
  91026. + }
  91027. + }
  91028. +#else
  91029. + /** @todo implement ISR */
  91030. + gintmsk_data_t intr_mask = {.d32 = 0 };
  91031. + dwc_otg_core_if_t *core_if;
  91032. + deptsiz_data_t deptsiz = {.d32 = 0 };
  91033. + depctl_data_t depctl = {.d32 = 0 };
  91034. + dctl_data_t dctl = {.d32 = 0 };
  91035. + dwc_ep_t *dwc_ep = NULL;
  91036. + int i;
  91037. + core_if = GET_CORE_IF(pcd);
  91038. +
  91039. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  91040. + dwc_ep = &pcd->out_ep[i].dwc_ep;
  91041. + depctl.d32 =
  91042. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl);
  91043. + if (depctl.b.epena && depctl.b.dpid == (core_if->frame_num & 0x1)) {
  91044. + core_if->dev_if->isoc_ep = dwc_ep;
  91045. + deptsiz.d32 =
  91046. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doeptsiz);
  91047. + break;
  91048. + }
  91049. + }
  91050. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  91051. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  91052. + intr_mask.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  91053. +
  91054. + if (!intr_mask.b.goutnakeff) {
  91055. + /* Unmask it */
  91056. + intr_mask.b.goutnakeff = 1;
  91057. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, intr_mask.d32);
  91058. + }
  91059. + if (!gintsts.b.goutnakeff) {
  91060. + dctl.b.sgoutnak = 1;
  91061. + }
  91062. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  91063. +
  91064. + depctl.d32 = DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl);
  91065. + if (depctl.b.epena) {
  91066. + depctl.b.epdis = 1;
  91067. + depctl.b.snak = 1;
  91068. + }
  91069. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl, depctl.d32);
  91070. +
  91071. + intr_mask.d32 = 0;
  91072. + intr_mask.b.incomplisoout = 1;
  91073. +
  91074. +#endif /* DWC_EN_ISOC */
  91075. +
  91076. + /* Clear interrupt */
  91077. + gintsts.d32 = 0;
  91078. + gintsts.b.incomplisoout = 1;
  91079. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  91080. + gintsts.d32);
  91081. +
  91082. + return 1;
  91083. +}
  91084. +
  91085. +/**
  91086. + * This function handles the Global IN NAK Effective interrupt.
  91087. + *
  91088. + */
  91089. +int32_t dwc_otg_pcd_handle_in_nak_effective(dwc_otg_pcd_t * pcd)
  91090. +{
  91091. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  91092. + depctl_data_t diepctl = {.d32 = 0 };
  91093. + gintmsk_data_t intr_mask = {.d32 = 0 };
  91094. + gintsts_data_t gintsts;
  91095. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  91096. + int i;
  91097. +
  91098. + DWC_DEBUGPL(DBG_PCD, "Global IN NAK Effective\n");
  91099. +
  91100. + /* Disable all active IN EPs */
  91101. + for (i = 0; i <= dev_if->num_in_eps; i++) {
  91102. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  91103. + if (!(diepctl.b.eptype & 1) && diepctl.b.epena) {
  91104. + if (core_if->start_predict > 0)
  91105. + core_if->start_predict++;
  91106. + diepctl.b.epdis = 1;
  91107. + diepctl.b.snak = 1;
  91108. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, diepctl.d32);
  91109. + }
  91110. + }
  91111. +
  91112. +
  91113. + /* Disable the Global IN NAK Effective Interrupt */
  91114. + intr_mask.b.ginnakeff = 1;
  91115. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  91116. + intr_mask.d32, 0);
  91117. +
  91118. + /* Clear interrupt */
  91119. + gintsts.d32 = 0;
  91120. + gintsts.b.ginnakeff = 1;
  91121. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  91122. + gintsts.d32);
  91123. +
  91124. + return 1;
  91125. +}
  91126. +
  91127. +/**
  91128. + * OUT NAK Effective.
  91129. + *
  91130. + */
  91131. +int32_t dwc_otg_pcd_handle_out_nak_effective(dwc_otg_pcd_t * pcd)
  91132. +{
  91133. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  91134. + gintmsk_data_t intr_mask = {.d32 = 0 };
  91135. + gintsts_data_t gintsts;
  91136. + depctl_data_t doepctl;
  91137. + int i;
  91138. +
  91139. + /* Disable the Global OUT NAK Effective Interrupt */
  91140. + intr_mask.b.goutnakeff = 1;
  91141. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  91142. + intr_mask.d32, 0);
  91143. +
  91144. + /* If DEV OUT NAK enabled*/
  91145. + if (pcd->core_if->core_params->dev_out_nak) {
  91146. + /* Run over all out endpoints to determine the ep number on
  91147. + * which the timeout has happened
  91148. + */
  91149. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  91150. + if ( pcd->core_if->ep_xfer_info[i].state == 2 )
  91151. + break;
  91152. + }
  91153. + if (i > dev_if->num_out_eps) {
  91154. + dctl_data_t dctl;
  91155. + dctl.d32 =
  91156. + DWC_READ_REG32(&dev_if->dev_global_regs->dctl);
  91157. + dctl.b.cgoutnak = 1;
  91158. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dctl,
  91159. + dctl.d32);
  91160. + goto out;
  91161. + }
  91162. +
  91163. + /* Disable the endpoint */
  91164. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  91165. + if (doepctl.b.epena) {
  91166. + doepctl.b.epdis = 1;
  91167. + doepctl.b.snak = 1;
  91168. + }
  91169. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, doepctl.d32);
  91170. + return 1;
  91171. + }
  91172. + /* We come here from Incomplete ISO OUT handler */
  91173. + if (dev_if->isoc_ep) {
  91174. + dwc_ep_t *dwc_ep = (dwc_ep_t *)dev_if->isoc_ep;
  91175. + uint32_t epnum = dwc_ep->num;
  91176. + doepint_data_t doepint;
  91177. + doepint.d32 =
  91178. + DWC_READ_REG32(&dev_if->out_ep_regs[dwc_ep->num]->doepint);
  91179. + dev_if->isoc_ep = NULL;
  91180. + doepctl.d32 =
  91181. + DWC_READ_REG32(&dev_if->out_ep_regs[epnum]->doepctl);
  91182. + DWC_PRINTF("Before disable DOEPCTL = %08x\n", doepctl.d32);
  91183. + if (doepctl.b.epena) {
  91184. + doepctl.b.epdis = 1;
  91185. + doepctl.b.snak = 1;
  91186. + }
  91187. + DWC_WRITE_REG32(&dev_if->out_ep_regs[epnum]->doepctl,
  91188. + doepctl.d32);
  91189. + return 1;
  91190. + } else
  91191. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n",
  91192. + "Global OUT NAK Effective\n");
  91193. +
  91194. +out:
  91195. + /* Clear interrupt */
  91196. + gintsts.d32 = 0;
  91197. + gintsts.b.goutnakeff = 1;
  91198. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  91199. + gintsts.d32);
  91200. +
  91201. + return 1;
  91202. +}
  91203. +
  91204. +/**
  91205. + * PCD interrupt handler.
  91206. + *
  91207. + * The PCD handles the device interrupts. Many conditions can cause a
  91208. + * device interrupt. When an interrupt occurs, the device interrupt
  91209. + * service routine determines the cause of the interrupt and
  91210. + * dispatches handling to the appropriate function. These interrupt
  91211. + * handling functions are described below.
  91212. + *
  91213. + * All interrupt registers are processed from LSB to MSB.
  91214. + *
  91215. + */
  91216. +int32_t dwc_otg_pcd_handle_intr(dwc_otg_pcd_t * pcd)
  91217. +{
  91218. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  91219. +#ifdef VERBOSE
  91220. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  91221. +#endif
  91222. + gintsts_data_t gintr_status;
  91223. + int32_t retval = 0;
  91224. +
  91225. + /* Exit from ISR if core is hibernated */
  91226. + if (core_if->hibernation_suspend == 1) {
  91227. + return retval;
  91228. + }
  91229. +#ifdef VERBOSE
  91230. + DWC_DEBUGPL(DBG_ANY, "%s() gintsts=%08x gintmsk=%08x\n",
  91231. + __func__,
  91232. + DWC_READ_REG32(&global_regs->gintsts),
  91233. + DWC_READ_REG32(&global_regs->gintmsk));
  91234. +#endif
  91235. +
  91236. + if (dwc_otg_is_device_mode(core_if)) {
  91237. + DWC_SPINLOCK(pcd->lock);
  91238. +#ifdef VERBOSE
  91239. + DWC_DEBUGPL(DBG_PCDV, "%s() gintsts=%08x gintmsk=%08x\n",
  91240. + __func__,
  91241. + DWC_READ_REG32(&global_regs->gintsts),
  91242. + DWC_READ_REG32(&global_regs->gintmsk));
  91243. +#endif
  91244. +
  91245. + gintr_status.d32 = dwc_otg_read_core_intr(core_if);
  91246. +
  91247. + DWC_DEBUGPL(DBG_PCDV, "%s: gintsts&gintmsk=%08x\n",
  91248. + __func__, gintr_status.d32);
  91249. +
  91250. + if (gintr_status.b.sofintr) {
  91251. + retval |= dwc_otg_pcd_handle_sof_intr(pcd);
  91252. + }
  91253. + if (gintr_status.b.rxstsqlvl) {
  91254. + retval |=
  91255. + dwc_otg_pcd_handle_rx_status_q_level_intr(pcd);
  91256. + }
  91257. + if (gintr_status.b.nptxfempty) {
  91258. + retval |= dwc_otg_pcd_handle_np_tx_fifo_empty_intr(pcd);
  91259. + }
  91260. + if (gintr_status.b.goutnakeff) {
  91261. + retval |= dwc_otg_pcd_handle_out_nak_effective(pcd);
  91262. + }
  91263. + if (gintr_status.b.i2cintr) {
  91264. + retval |= dwc_otg_pcd_handle_i2c_intr(pcd);
  91265. + }
  91266. + if (gintr_status.b.erlysuspend) {
  91267. + retval |= dwc_otg_pcd_handle_early_suspend_intr(pcd);
  91268. + }
  91269. + if (gintr_status.b.usbreset) {
  91270. + retval |= dwc_otg_pcd_handle_usb_reset_intr(pcd);
  91271. + }
  91272. + if (gintr_status.b.enumdone) {
  91273. + retval |= dwc_otg_pcd_handle_enum_done_intr(pcd);
  91274. + }
  91275. + if (gintr_status.b.isooutdrop) {
  91276. + retval |=
  91277. + dwc_otg_pcd_handle_isoc_out_packet_dropped_intr
  91278. + (pcd);
  91279. + }
  91280. + if (gintr_status.b.eopframe) {
  91281. + retval |=
  91282. + dwc_otg_pcd_handle_end_periodic_frame_intr(pcd);
  91283. + }
  91284. + if (gintr_status.b.inepint) {
  91285. + if (!core_if->multiproc_int_enable) {
  91286. + retval |= dwc_otg_pcd_handle_in_ep_intr(pcd);
  91287. + }
  91288. + }
  91289. + if (gintr_status.b.outepintr) {
  91290. + if (!core_if->multiproc_int_enable) {
  91291. + retval |= dwc_otg_pcd_handle_out_ep_intr(pcd);
  91292. + }
  91293. + }
  91294. + if (gintr_status.b.epmismatch) {
  91295. + retval |= dwc_otg_pcd_handle_ep_mismatch_intr(pcd);
  91296. + }
  91297. + if (gintr_status.b.fetsusp) {
  91298. + retval |= dwc_otg_pcd_handle_ep_fetsusp_intr(pcd);
  91299. + }
  91300. + if (gintr_status.b.ginnakeff) {
  91301. + retval |= dwc_otg_pcd_handle_in_nak_effective(pcd);
  91302. + }
  91303. + if (gintr_status.b.incomplisoin) {
  91304. + retval |=
  91305. + dwc_otg_pcd_handle_incomplete_isoc_in_intr(pcd);
  91306. + }
  91307. + if (gintr_status.b.incomplisoout) {
  91308. + retval |=
  91309. + dwc_otg_pcd_handle_incomplete_isoc_out_intr(pcd);
  91310. + }
  91311. +
  91312. + /* In MPI mode Device Endpoints interrupts are asserted
  91313. + * without setting outepintr and inepint bits set, so these
  91314. + * Interrupt handlers are called without checking these bit-fields
  91315. + */
  91316. + if (core_if->multiproc_int_enable) {
  91317. + retval |= dwc_otg_pcd_handle_in_ep_intr(pcd);
  91318. + retval |= dwc_otg_pcd_handle_out_ep_intr(pcd);
  91319. + }
  91320. +#ifdef VERBOSE
  91321. + DWC_DEBUGPL(DBG_PCDV, "%s() gintsts=%0x\n", __func__,
  91322. + DWC_READ_REG32(&global_regs->gintsts));
  91323. +#endif
  91324. + DWC_SPINUNLOCK(pcd->lock);
  91325. + }
  91326. + return retval;
  91327. +}
  91328. +
  91329. +#endif /* DWC_HOST_ONLY */
  91330. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c
  91331. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c 1970-01-01 01:00:00.000000000 +0100
  91332. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c 2014-07-07 10:45:43.000000000 +0200
  91333. @@ -0,0 +1,1360 @@
  91334. + /* ==========================================================================
  91335. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_linux.c $
  91336. + * $Revision: #21 $
  91337. + * $Date: 2012/08/10 $
  91338. + * $Change: 2047372 $
  91339. + *
  91340. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  91341. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  91342. + * otherwise expressly agreed to in writing between Synopsys and you.
  91343. + *
  91344. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  91345. + * any End User Software License Agreement or Agreement for Licensed Product
  91346. + * with Synopsys or any supplement thereto. You are permitted to use and
  91347. + * redistribute this Software in source and binary forms, with or without
  91348. + * modification, provided that redistributions of source code must retain this
  91349. + * notice. You may not view, use, disclose, copy or distribute this file or
  91350. + * any information contained herein except pursuant to this license grant from
  91351. + * Synopsys. If you do not agree with this notice, including the disclaimer
  91352. + * below, then you are not authorized to use the Software.
  91353. + *
  91354. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  91355. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  91356. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  91357. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  91358. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  91359. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  91360. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  91361. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  91362. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  91363. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  91364. + * DAMAGE.
  91365. + * ========================================================================== */
  91366. +#ifndef DWC_HOST_ONLY
  91367. +
  91368. +/** @file
  91369. + * This file implements the Peripheral Controller Driver.
  91370. + *
  91371. + * The Peripheral Controller Driver (PCD) is responsible for
  91372. + * translating requests from the Function Driver into the appropriate
  91373. + * actions on the DWC_otg controller. It isolates the Function Driver
  91374. + * from the specifics of the controller by providing an API to the
  91375. + * Function Driver.
  91376. + *
  91377. + * The Peripheral Controller Driver for Linux will implement the
  91378. + * Gadget API, so that the existing Gadget drivers can be used.
  91379. + * (Gadget Driver is the Linux terminology for a Function Driver.)
  91380. + *
  91381. + * The Linux Gadget API is defined in the header file
  91382. + * <code><linux/usb_gadget.h></code>. The USB EP operations API is
  91383. + * defined in the structure <code>usb_ep_ops</code> and the USB
  91384. + * Controller API is defined in the structure
  91385. + * <code>usb_gadget_ops</code>.
  91386. + *
  91387. + */
  91388. +
  91389. +#include "dwc_otg_os_dep.h"
  91390. +#include "dwc_otg_pcd_if.h"
  91391. +#include "dwc_otg_pcd.h"
  91392. +#include "dwc_otg_driver.h"
  91393. +#include "dwc_otg_dbg.h"
  91394. +
  91395. +extern bool fiq_enable;
  91396. +
  91397. +static struct gadget_wrapper {
  91398. + dwc_otg_pcd_t *pcd;
  91399. +
  91400. + struct usb_gadget gadget;
  91401. + struct usb_gadget_driver *driver;
  91402. +
  91403. + struct usb_ep ep0;
  91404. + struct usb_ep in_ep[16];
  91405. + struct usb_ep out_ep[16];
  91406. +
  91407. +} *gadget_wrapper;
  91408. +
  91409. +/* Display the contents of the buffer */
  91410. +extern void dump_msg(const u8 * buf, unsigned int length);
  91411. +/**
  91412. + * Get the dwc_otg_pcd_ep_t* from usb_ep* pointer - NULL in case
  91413. + * if the endpoint is not found
  91414. + */
  91415. +static struct dwc_otg_pcd_ep *ep_from_handle(dwc_otg_pcd_t * pcd, void *handle)
  91416. +{
  91417. + int i;
  91418. + if (pcd->ep0.priv == handle) {
  91419. + return &pcd->ep0;
  91420. + }
  91421. +
  91422. + for (i = 0; i < MAX_EPS_CHANNELS - 1; i++) {
  91423. + if (pcd->in_ep[i].priv == handle)
  91424. + return &pcd->in_ep[i];
  91425. + if (pcd->out_ep[i].priv == handle)
  91426. + return &pcd->out_ep[i];
  91427. + }
  91428. +
  91429. + return NULL;
  91430. +}
  91431. +
  91432. +/* USB Endpoint Operations */
  91433. +/*
  91434. + * The following sections briefly describe the behavior of the Gadget
  91435. + * API endpoint operations implemented in the DWC_otg driver
  91436. + * software. Detailed descriptions of the generic behavior of each of
  91437. + * these functions can be found in the Linux header file
  91438. + * include/linux/usb_gadget.h.
  91439. + *
  91440. + * The Gadget API provides wrapper functions for each of the function
  91441. + * pointers defined in usb_ep_ops. The Gadget Driver calls the wrapper
  91442. + * function, which then calls the underlying PCD function. The
  91443. + * following sections are named according to the wrapper
  91444. + * functions. Within each section, the corresponding DWC_otg PCD
  91445. + * function name is specified.
  91446. + *
  91447. + */
  91448. +
  91449. +/**
  91450. + * This function is called by the Gadget Driver for each EP to be
  91451. + * configured for the current configuration (SET_CONFIGURATION).
  91452. + *
  91453. + * This function initializes the dwc_otg_ep_t data structure, and then
  91454. + * calls dwc_otg_ep_activate.
  91455. + */
  91456. +static int ep_enable(struct usb_ep *usb_ep,
  91457. + const struct usb_endpoint_descriptor *ep_desc)
  91458. +{
  91459. + int retval;
  91460. +
  91461. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, usb_ep, ep_desc);
  91462. +
  91463. + if (!usb_ep || !ep_desc || ep_desc->bDescriptorType != USB_DT_ENDPOINT) {
  91464. + DWC_WARN("%s, bad ep or descriptor\n", __func__);
  91465. + return -EINVAL;
  91466. + }
  91467. + if (usb_ep == &gadget_wrapper->ep0) {
  91468. + DWC_WARN("%s, bad ep(0)\n", __func__);
  91469. + return -EINVAL;
  91470. + }
  91471. +
  91472. + /* Check FIFO size? */
  91473. + if (!ep_desc->wMaxPacketSize) {
  91474. + DWC_WARN("%s, bad %s maxpacket\n", __func__, usb_ep->name);
  91475. + return -ERANGE;
  91476. + }
  91477. +
  91478. + if (!gadget_wrapper->driver ||
  91479. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  91480. + DWC_WARN("%s, bogus device state\n", __func__);
  91481. + return -ESHUTDOWN;
  91482. + }
  91483. +
  91484. + /* Delete after check - MAS */
  91485. +#if 0
  91486. + nat = (uint32_t) ep_desc->wMaxPacketSize;
  91487. + printk(KERN_ALERT "%s: nat (before) =%d\n", __func__, nat);
  91488. + nat = (nat >> 11) & 0x03;
  91489. + printk(KERN_ALERT "%s: nat (after) =%d\n", __func__, nat);
  91490. +#endif
  91491. + retval = dwc_otg_pcd_ep_enable(gadget_wrapper->pcd,
  91492. + (const uint8_t *)ep_desc,
  91493. + (void *)usb_ep);
  91494. + if (retval) {
  91495. + DWC_WARN("dwc_otg_pcd_ep_enable failed\n");
  91496. + return -EINVAL;
  91497. + }
  91498. +
  91499. + usb_ep->maxpacket = le16_to_cpu(ep_desc->wMaxPacketSize);
  91500. +
  91501. + return 0;
  91502. +}
  91503. +
  91504. +/**
  91505. + * This function is called when an EP is disabled due to disconnect or
  91506. + * change in configuration. Any pending requests will terminate with a
  91507. + * status of -ESHUTDOWN.
  91508. + *
  91509. + * This function modifies the dwc_otg_ep_t data structure for this EP,
  91510. + * and then calls dwc_otg_ep_deactivate.
  91511. + */
  91512. +static int ep_disable(struct usb_ep *usb_ep)
  91513. +{
  91514. + int retval;
  91515. +
  91516. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, usb_ep);
  91517. + if (!usb_ep) {
  91518. + DWC_DEBUGPL(DBG_PCD, "%s, %s not enabled\n", __func__,
  91519. + usb_ep ? usb_ep->name : NULL);
  91520. + return -EINVAL;
  91521. + }
  91522. +
  91523. + retval = dwc_otg_pcd_ep_disable(gadget_wrapper->pcd, usb_ep);
  91524. + if (retval) {
  91525. + retval = -EINVAL;
  91526. + }
  91527. +
  91528. + return retval;
  91529. +}
  91530. +
  91531. +/**
  91532. + * This function allocates a request object to use with the specified
  91533. + * endpoint.
  91534. + *
  91535. + * @param ep The endpoint to be used with with the request
  91536. + * @param gfp_flags the GFP_* flags to use.
  91537. + */
  91538. +static struct usb_request *dwc_otg_pcd_alloc_request(struct usb_ep *ep,
  91539. + gfp_t gfp_flags)
  91540. +{
  91541. + struct usb_request *usb_req;
  91542. +
  91543. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%d)\n", __func__, ep, gfp_flags);
  91544. + if (0 == ep) {
  91545. + DWC_WARN("%s() %s\n", __func__, "Invalid EP!\n");
  91546. + return 0;
  91547. + }
  91548. + usb_req = kmalloc(sizeof(*usb_req), gfp_flags);
  91549. + if (0 == usb_req) {
  91550. + DWC_WARN("%s() %s\n", __func__, "request allocation failed!\n");
  91551. + return 0;
  91552. + }
  91553. + memset(usb_req, 0, sizeof(*usb_req));
  91554. + usb_req->dma = DWC_DMA_ADDR_INVALID;
  91555. +
  91556. + return usb_req;
  91557. +}
  91558. +
  91559. +/**
  91560. + * This function frees a request object.
  91561. + *
  91562. + * @param ep The endpoint associated with the request
  91563. + * @param req The request being freed
  91564. + */
  91565. +static void dwc_otg_pcd_free_request(struct usb_ep *ep, struct usb_request *req)
  91566. +{
  91567. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, ep, req);
  91568. +
  91569. + if (0 == ep || 0 == req) {
  91570. + DWC_WARN("%s() %s\n", __func__,
  91571. + "Invalid ep or req argument!\n");
  91572. + return;
  91573. + }
  91574. +
  91575. + kfree(req);
  91576. +}
  91577. +
  91578. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  91579. +/**
  91580. + * This function allocates an I/O buffer to be used for a transfer
  91581. + * to/from the specified endpoint.
  91582. + *
  91583. + * @param usb_ep The endpoint to be used with with the request
  91584. + * @param bytes The desired number of bytes for the buffer
  91585. + * @param dma Pointer to the buffer's DMA address; must be valid
  91586. + * @param gfp_flags the GFP_* flags to use.
  91587. + * @return address of a new buffer or null is buffer could not be allocated.
  91588. + */
  91589. +static void *dwc_otg_pcd_alloc_buffer(struct usb_ep *usb_ep, unsigned bytes,
  91590. + dma_addr_t * dma, gfp_t gfp_flags)
  91591. +{
  91592. + void *buf;
  91593. + dwc_otg_pcd_t *pcd = 0;
  91594. +
  91595. + pcd = gadget_wrapper->pcd;
  91596. +
  91597. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%d,%p,%0x)\n", __func__, usb_ep, bytes,
  91598. + dma, gfp_flags);
  91599. +
  91600. + /* Check dword alignment */
  91601. + if ((bytes & 0x3UL) != 0) {
  91602. + DWC_WARN("%s() Buffer size is not a multiple of"
  91603. + "DWORD size (%d)", __func__, bytes);
  91604. + }
  91605. +
  91606. + buf = dma_alloc_coherent(NULL, bytes, dma, gfp_flags);
  91607. +
  91608. + /* Check dword alignment */
  91609. + if (((int)buf & 0x3UL) != 0) {
  91610. + DWC_WARN("%s() Buffer is not DWORD aligned (%p)",
  91611. + __func__, buf);
  91612. + }
  91613. +
  91614. + return buf;
  91615. +}
  91616. +
  91617. +/**
  91618. + * This function frees an I/O buffer that was allocated by alloc_buffer.
  91619. + *
  91620. + * @param usb_ep the endpoint associated with the buffer
  91621. + * @param buf address of the buffer
  91622. + * @param dma The buffer's DMA address
  91623. + * @param bytes The number of bytes of the buffer
  91624. + */
  91625. +static void dwc_otg_pcd_free_buffer(struct usb_ep *usb_ep, void *buf,
  91626. + dma_addr_t dma, unsigned bytes)
  91627. +{
  91628. + dwc_otg_pcd_t *pcd = 0;
  91629. +
  91630. + pcd = gadget_wrapper->pcd;
  91631. +
  91632. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%0x,%d)\n", __func__, buf, dma, bytes);
  91633. +
  91634. + dma_free_coherent(NULL, bytes, buf, dma);
  91635. +}
  91636. +#endif
  91637. +
  91638. +/**
  91639. + * This function is used to submit an I/O Request to an EP.
  91640. + *
  91641. + * - When the request completes the request's completion callback
  91642. + * is called to return the request to the driver.
  91643. + * - An EP, except control EPs, may have multiple requests
  91644. + * pending.
  91645. + * - Once submitted the request cannot be examined or modified.
  91646. + * - Each request is turned into one or more packets.
  91647. + * - A BULK EP can queue any amount of data; the transfer is
  91648. + * packetized.
  91649. + * - Zero length Packets are specified with the request 'zero'
  91650. + * flag.
  91651. + */
  91652. +static int ep_queue(struct usb_ep *usb_ep, struct usb_request *usb_req,
  91653. + gfp_t gfp_flags)
  91654. +{
  91655. + dwc_otg_pcd_t *pcd;
  91656. + struct dwc_otg_pcd_ep *ep = NULL;
  91657. + int retval = 0, is_isoc_ep = 0;
  91658. + dma_addr_t dma_addr = DWC_DMA_ADDR_INVALID;
  91659. +
  91660. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p,%d)\n",
  91661. + __func__, usb_ep, usb_req, gfp_flags);
  91662. +
  91663. + if (!usb_req || !usb_req->complete || !usb_req->buf) {
  91664. + DWC_WARN("bad params\n");
  91665. + return -EINVAL;
  91666. + }
  91667. +
  91668. + if (!usb_ep) {
  91669. + DWC_WARN("bad ep\n");
  91670. + return -EINVAL;
  91671. + }
  91672. +
  91673. + pcd = gadget_wrapper->pcd;
  91674. + if (!gadget_wrapper->driver ||
  91675. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  91676. + DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n",
  91677. + gadget_wrapper->gadget.speed);
  91678. + DWC_WARN("bogus device state\n");
  91679. + return -ESHUTDOWN;
  91680. + }
  91681. +
  91682. + DWC_DEBUGPL(DBG_PCD, "%s queue req %p, len %d buf %p\n",
  91683. + usb_ep->name, usb_req, usb_req->length, usb_req->buf);
  91684. +
  91685. + usb_req->status = -EINPROGRESS;
  91686. + usb_req->actual = 0;
  91687. +
  91688. + ep = ep_from_handle(pcd, usb_ep);
  91689. + if (ep == NULL)
  91690. + is_isoc_ep = 0;
  91691. + else
  91692. + is_isoc_ep = (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) ? 1 : 0;
  91693. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  91694. + dma_addr = usb_req->dma;
  91695. +#else
  91696. + if (GET_CORE_IF(pcd)->dma_enable) {
  91697. + dwc_otg_device_t *otg_dev = gadget_wrapper->pcd->otg_dev;
  91698. + struct device *dev = NULL;
  91699. +
  91700. + if (otg_dev != NULL)
  91701. + dev = DWC_OTG_OS_GETDEV(otg_dev->os_dep);
  91702. +
  91703. + if (usb_req->length != 0 &&
  91704. + usb_req->dma == DWC_DMA_ADDR_INVALID) {
  91705. + dma_addr = dma_map_single(dev, usb_req->buf,
  91706. + usb_req->length,
  91707. + ep->dwc_ep.is_in ?
  91708. + DMA_TO_DEVICE:
  91709. + DMA_FROM_DEVICE);
  91710. + }
  91711. + }
  91712. +#endif
  91713. +
  91714. +#ifdef DWC_UTE_PER_IO
  91715. + if (is_isoc_ep == 1) {
  91716. + retval = dwc_otg_pcd_xiso_ep_queue(pcd, usb_ep, usb_req->buf, dma_addr,
  91717. + usb_req->length, usb_req->zero, usb_req,
  91718. + gfp_flags == GFP_ATOMIC ? 1 : 0, &usb_req->ext_req);
  91719. + if (retval)
  91720. + return -EINVAL;
  91721. +
  91722. + return 0;
  91723. + }
  91724. +#endif
  91725. + retval = dwc_otg_pcd_ep_queue(pcd, usb_ep, usb_req->buf, dma_addr,
  91726. + usb_req->length, usb_req->zero, usb_req,
  91727. + gfp_flags == GFP_ATOMIC ? 1 : 0);
  91728. + if (retval) {
  91729. + return -EINVAL;
  91730. + }
  91731. +
  91732. + return 0;
  91733. +}
  91734. +
  91735. +/**
  91736. + * This function cancels an I/O request from an EP.
  91737. + */
  91738. +static int ep_dequeue(struct usb_ep *usb_ep, struct usb_request *usb_req)
  91739. +{
  91740. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, usb_ep, usb_req);
  91741. +
  91742. + if (!usb_ep || !usb_req) {
  91743. + DWC_WARN("bad argument\n");
  91744. + return -EINVAL;
  91745. + }
  91746. + if (!gadget_wrapper->driver ||
  91747. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  91748. + DWC_WARN("bogus device state\n");
  91749. + return -ESHUTDOWN;
  91750. + }
  91751. + if (dwc_otg_pcd_ep_dequeue(gadget_wrapper->pcd, usb_ep, usb_req)) {
  91752. + return -EINVAL;
  91753. + }
  91754. +
  91755. + return 0;
  91756. +}
  91757. +
  91758. +/**
  91759. + * usb_ep_set_halt stalls an endpoint.
  91760. + *
  91761. + * usb_ep_clear_halt clears an endpoint halt and resets its data
  91762. + * toggle.
  91763. + *
  91764. + * Both of these functions are implemented with the same underlying
  91765. + * function. The behavior depends on the value argument.
  91766. + *
  91767. + * @param[in] usb_ep the Endpoint to halt or clear halt.
  91768. + * @param[in] value
  91769. + * - 0 means clear_halt.
  91770. + * - 1 means set_halt,
  91771. + * - 2 means clear stall lock flag.
  91772. + * - 3 means set stall lock flag.
  91773. + */
  91774. +static int ep_halt(struct usb_ep *usb_ep, int value)
  91775. +{
  91776. + int retval = 0;
  91777. +
  91778. + DWC_DEBUGPL(DBG_PCD, "HALT %s %d\n", usb_ep->name, value);
  91779. +
  91780. + if (!usb_ep) {
  91781. + DWC_WARN("bad ep\n");
  91782. + return -EINVAL;
  91783. + }
  91784. +
  91785. + retval = dwc_otg_pcd_ep_halt(gadget_wrapper->pcd, usb_ep, value);
  91786. + if (retval == -DWC_E_AGAIN) {
  91787. + return -EAGAIN;
  91788. + } else if (retval) {
  91789. + retval = -EINVAL;
  91790. + }
  91791. +
  91792. + return retval;
  91793. +}
  91794. +
  91795. +//#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30))
  91796. +#if 0
  91797. +/**
  91798. + * ep_wedge: sets the halt feature and ignores clear requests
  91799. + *
  91800. + * @usb_ep: the endpoint being wedged
  91801. + *
  91802. + * Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT)
  91803. + * requests. If the gadget driver clears the halt status, it will
  91804. + * automatically unwedge the endpoint.
  91805. + *
  91806. + * Returns zero on success, else negative errno. *
  91807. + * Check usb_ep_set_wedge() at "usb_gadget.h" for details
  91808. + */
  91809. +static int ep_wedge(struct usb_ep *usb_ep)
  91810. +{
  91811. + int retval = 0;
  91812. +
  91813. + DWC_DEBUGPL(DBG_PCD, "WEDGE %s\n", usb_ep->name);
  91814. +
  91815. + if (!usb_ep) {
  91816. + DWC_WARN("bad ep\n");
  91817. + return -EINVAL;
  91818. + }
  91819. +
  91820. + retval = dwc_otg_pcd_ep_wedge(gadget_wrapper->pcd, usb_ep);
  91821. + if (retval == -DWC_E_AGAIN) {
  91822. + retval = -EAGAIN;
  91823. + } else if (retval) {
  91824. + retval = -EINVAL;
  91825. + }
  91826. +
  91827. + return retval;
  91828. +}
  91829. +#endif
  91830. +
  91831. +#ifdef DWC_EN_ISOC
  91832. +/**
  91833. + * This function is used to submit an ISOC Transfer Request to an EP.
  91834. + *
  91835. + * - Every time a sync period completes the request's completion callback
  91836. + * is called to provide data to the gadget driver.
  91837. + * - Once submitted the request cannot be modified.
  91838. + * - Each request is turned into periodic data packets untill ISO
  91839. + * Transfer is stopped..
  91840. + */
  91841. +static int iso_ep_start(struct usb_ep *usb_ep, struct usb_iso_request *req,
  91842. + gfp_t gfp_flags)
  91843. +{
  91844. + int retval = 0;
  91845. +
  91846. + if (!req || !req->process_buffer || !req->buf0 || !req->buf1) {
  91847. + DWC_WARN("bad params\n");
  91848. + return -EINVAL;
  91849. + }
  91850. +
  91851. + if (!usb_ep) {
  91852. + DWC_PRINTF("bad params\n");
  91853. + return -EINVAL;
  91854. + }
  91855. +
  91856. + req->status = -EINPROGRESS;
  91857. +
  91858. + retval =
  91859. + dwc_otg_pcd_iso_ep_start(gadget_wrapper->pcd, usb_ep, req->buf0,
  91860. + req->buf1, req->dma0, req->dma1,
  91861. + req->sync_frame, req->data_pattern_frame,
  91862. + req->data_per_frame,
  91863. + req->
  91864. + flags & USB_REQ_ISO_ASAP ? -1 :
  91865. + req->start_frame, req->buf_proc_intrvl,
  91866. + req, gfp_flags == GFP_ATOMIC ? 1 : 0);
  91867. +
  91868. + if (retval) {
  91869. + return -EINVAL;
  91870. + }
  91871. +
  91872. + return retval;
  91873. +}
  91874. +
  91875. +/**
  91876. + * This function stops ISO EP Periodic Data Transfer.
  91877. + */
  91878. +static int iso_ep_stop(struct usb_ep *usb_ep, struct usb_iso_request *req)
  91879. +{
  91880. + int retval = 0;
  91881. + if (!usb_ep) {
  91882. + DWC_WARN("bad ep\n");
  91883. + }
  91884. +
  91885. + if (!gadget_wrapper->driver ||
  91886. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  91887. + DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n",
  91888. + gadget_wrapper->gadget.speed);
  91889. + DWC_WARN("bogus device state\n");
  91890. + }
  91891. +
  91892. + dwc_otg_pcd_iso_ep_stop(gadget_wrapper->pcd, usb_ep, req);
  91893. + if (retval) {
  91894. + retval = -EINVAL;
  91895. + }
  91896. +
  91897. + return retval;
  91898. +}
  91899. +
  91900. +static struct usb_iso_request *alloc_iso_request(struct usb_ep *ep,
  91901. + int packets, gfp_t gfp_flags)
  91902. +{
  91903. + struct usb_iso_request *pReq = NULL;
  91904. + uint32_t req_size;
  91905. +
  91906. + req_size = sizeof(struct usb_iso_request);
  91907. + req_size +=
  91908. + (2 * packets * (sizeof(struct usb_gadget_iso_packet_descriptor)));
  91909. +
  91910. + pReq = kmalloc(req_size, gfp_flags);
  91911. + if (!pReq) {
  91912. + DWC_WARN("Can't allocate Iso Request\n");
  91913. + return 0;
  91914. + }
  91915. + pReq->iso_packet_desc0 = (void *)(pReq + 1);
  91916. +
  91917. + pReq->iso_packet_desc1 = pReq->iso_packet_desc0 + packets;
  91918. +
  91919. + return pReq;
  91920. +}
  91921. +
  91922. +static void free_iso_request(struct usb_ep *ep, struct usb_iso_request *req)
  91923. +{
  91924. + kfree(req);
  91925. +}
  91926. +
  91927. +static struct usb_isoc_ep_ops dwc_otg_pcd_ep_ops = {
  91928. + .ep_ops = {
  91929. + .enable = ep_enable,
  91930. + .disable = ep_disable,
  91931. +
  91932. + .alloc_request = dwc_otg_pcd_alloc_request,
  91933. + .free_request = dwc_otg_pcd_free_request,
  91934. +
  91935. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  91936. + .alloc_buffer = dwc_otg_pcd_alloc_buffer,
  91937. + .free_buffer = dwc_otg_pcd_free_buffer,
  91938. +#endif
  91939. +
  91940. + .queue = ep_queue,
  91941. + .dequeue = ep_dequeue,
  91942. +
  91943. + .set_halt = ep_halt,
  91944. + .fifo_status = 0,
  91945. + .fifo_flush = 0,
  91946. + },
  91947. + .iso_ep_start = iso_ep_start,
  91948. + .iso_ep_stop = iso_ep_stop,
  91949. + .alloc_iso_request = alloc_iso_request,
  91950. + .free_iso_request = free_iso_request,
  91951. +};
  91952. +
  91953. +#else
  91954. +
  91955. + int (*enable) (struct usb_ep *ep,
  91956. + const struct usb_endpoint_descriptor *desc);
  91957. + int (*disable) (struct usb_ep *ep);
  91958. +
  91959. + struct usb_request *(*alloc_request) (struct usb_ep *ep,
  91960. + gfp_t gfp_flags);
  91961. + void (*free_request) (struct usb_ep *ep, struct usb_request *req);
  91962. +
  91963. + int (*queue) (struct usb_ep *ep, struct usb_request *req,
  91964. + gfp_t gfp_flags);
  91965. + int (*dequeue) (struct usb_ep *ep, struct usb_request *req);
  91966. +
  91967. + int (*set_halt) (struct usb_ep *ep, int value);
  91968. + int (*set_wedge) (struct usb_ep *ep);
  91969. +
  91970. + int (*fifo_status) (struct usb_ep *ep);
  91971. + void (*fifo_flush) (struct usb_ep *ep);
  91972. +static struct usb_ep_ops dwc_otg_pcd_ep_ops = {
  91973. + .enable = ep_enable,
  91974. + .disable = ep_disable,
  91975. +
  91976. + .alloc_request = dwc_otg_pcd_alloc_request,
  91977. + .free_request = dwc_otg_pcd_free_request,
  91978. +
  91979. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  91980. + .alloc_buffer = dwc_otg_pcd_alloc_buffer,
  91981. + .free_buffer = dwc_otg_pcd_free_buffer,
  91982. +#else
  91983. + /* .set_wedge = ep_wedge, */
  91984. + .set_wedge = NULL, /* uses set_halt instead */
  91985. +#endif
  91986. +
  91987. + .queue = ep_queue,
  91988. + .dequeue = ep_dequeue,
  91989. +
  91990. + .set_halt = ep_halt,
  91991. + .fifo_status = 0,
  91992. + .fifo_flush = 0,
  91993. +
  91994. +};
  91995. +
  91996. +#endif /* _EN_ISOC_ */
  91997. +/* Gadget Operations */
  91998. +/**
  91999. + * The following gadget operations will be implemented in the DWC_otg
  92000. + * PCD. Functions in the API that are not described below are not
  92001. + * implemented.
  92002. + *
  92003. + * The Gadget API provides wrapper functions for each of the function
  92004. + * pointers defined in usb_gadget_ops. The Gadget Driver calls the
  92005. + * wrapper function, which then calls the underlying PCD function. The
  92006. + * following sections are named according to the wrapper functions
  92007. + * (except for ioctl, which doesn't have a wrapper function). Within
  92008. + * each section, the corresponding DWC_otg PCD function name is
  92009. + * specified.
  92010. + *
  92011. + */
  92012. +
  92013. +/**
  92014. + *Gets the USB Frame number of the last SOF.
  92015. + */
  92016. +static int get_frame_number(struct usb_gadget *gadget)
  92017. +{
  92018. + struct gadget_wrapper *d;
  92019. +
  92020. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, gadget);
  92021. +
  92022. + if (gadget == 0) {
  92023. + return -ENODEV;
  92024. + }
  92025. +
  92026. + d = container_of(gadget, struct gadget_wrapper, gadget);
  92027. + return dwc_otg_pcd_get_frame_number(d->pcd);
  92028. +}
  92029. +
  92030. +#ifdef CONFIG_USB_DWC_OTG_LPM
  92031. +static int test_lpm_enabled(struct usb_gadget *gadget)
  92032. +{
  92033. + struct gadget_wrapper *d;
  92034. +
  92035. + d = container_of(gadget, struct gadget_wrapper, gadget);
  92036. +
  92037. + return dwc_otg_pcd_is_lpm_enabled(d->pcd);
  92038. +}
  92039. +#endif
  92040. +
  92041. +/**
  92042. + * Initiates Session Request Protocol (SRP) to wakeup the host if no
  92043. + * session is in progress. If a session is already in progress, but
  92044. + * the device is suspended, remote wakeup signaling is started.
  92045. + *
  92046. + */
  92047. +static int wakeup(struct usb_gadget *gadget)
  92048. +{
  92049. + struct gadget_wrapper *d;
  92050. +
  92051. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, gadget);
  92052. +
  92053. + if (gadget == 0) {
  92054. + return -ENODEV;
  92055. + } else {
  92056. + d = container_of(gadget, struct gadget_wrapper, gadget);
  92057. + }
  92058. + dwc_otg_pcd_wakeup(d->pcd);
  92059. + return 0;
  92060. +}
  92061. +
  92062. +static const struct usb_gadget_ops dwc_otg_pcd_ops = {
  92063. + .get_frame = get_frame_number,
  92064. + .wakeup = wakeup,
  92065. +#ifdef CONFIG_USB_DWC_OTG_LPM
  92066. + .lpm_support = test_lpm_enabled,
  92067. +#endif
  92068. + // current versions must always be self-powered
  92069. +};
  92070. +
  92071. +static int _setup(dwc_otg_pcd_t * pcd, uint8_t * bytes)
  92072. +{
  92073. + int retval = -DWC_E_NOT_SUPPORTED;
  92074. + if (gadget_wrapper->driver && gadget_wrapper->driver->setup) {
  92075. + retval = gadget_wrapper->driver->setup(&gadget_wrapper->gadget,
  92076. + (struct usb_ctrlrequest
  92077. + *)bytes);
  92078. + }
  92079. +
  92080. + if (retval == -ENOTSUPP) {
  92081. + retval = -DWC_E_NOT_SUPPORTED;
  92082. + } else if (retval < 0) {
  92083. + retval = -DWC_E_INVALID;
  92084. + }
  92085. +
  92086. + return retval;
  92087. +}
  92088. +
  92089. +#ifdef DWC_EN_ISOC
  92090. +static int _isoc_complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  92091. + void *req_handle, int proc_buf_num)
  92092. +{
  92093. + int i, packet_count;
  92094. + struct usb_gadget_iso_packet_descriptor *iso_packet = 0;
  92095. + struct usb_iso_request *iso_req = req_handle;
  92096. +
  92097. + if (proc_buf_num) {
  92098. + iso_packet = iso_req->iso_packet_desc1;
  92099. + } else {
  92100. + iso_packet = iso_req->iso_packet_desc0;
  92101. + }
  92102. + packet_count =
  92103. + dwc_otg_pcd_get_iso_packet_count(pcd, ep_handle, req_handle);
  92104. + for (i = 0; i < packet_count; ++i) {
  92105. + int status;
  92106. + int actual;
  92107. + int offset;
  92108. + dwc_otg_pcd_get_iso_packet_params(pcd, ep_handle, req_handle,
  92109. + i, &status, &actual, &offset);
  92110. + switch (status) {
  92111. + case -DWC_E_NO_DATA:
  92112. + status = -ENODATA;
  92113. + break;
  92114. + default:
  92115. + if (status) {
  92116. + DWC_PRINTF("unknown status in isoc packet\n");
  92117. + }
  92118. +
  92119. + }
  92120. + iso_packet[i].status = status;
  92121. + iso_packet[i].offset = offset;
  92122. + iso_packet[i].actual_length = actual;
  92123. + }
  92124. +
  92125. + iso_req->status = 0;
  92126. + iso_req->process_buffer(ep_handle, iso_req);
  92127. +
  92128. + return 0;
  92129. +}
  92130. +#endif /* DWC_EN_ISOC */
  92131. +
  92132. +#ifdef DWC_UTE_PER_IO
  92133. +/**
  92134. + * Copy the contents of the extended request to the Linux usb_request's
  92135. + * extended part and call the gadget's completion.
  92136. + *
  92137. + * @param pcd Pointer to the pcd structure
  92138. + * @param ep_handle Void pointer to the usb_ep structure
  92139. + * @param req_handle Void pointer to the usb_request structure
  92140. + * @param status Request status returned from the portable logic
  92141. + * @param ereq_port Void pointer to the extended request structure
  92142. + * created in the the portable part that contains the
  92143. + * results of the processed iso packets.
  92144. + */
  92145. +static int _xisoc_complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  92146. + void *req_handle, int32_t status, void *ereq_port)
  92147. +{
  92148. + struct dwc_ute_iso_req_ext *ereqorg = NULL;
  92149. + struct dwc_iso_xreq_port *ereqport = NULL;
  92150. + struct dwc_ute_iso_packet_descriptor *desc_org = NULL;
  92151. + int i;
  92152. + struct usb_request *req;
  92153. + //struct dwc_ute_iso_packet_descriptor *
  92154. + //int status = 0;
  92155. +
  92156. + req = (struct usb_request *)req_handle;
  92157. + ereqorg = &req->ext_req;
  92158. + ereqport = (struct dwc_iso_xreq_port *)ereq_port;
  92159. + desc_org = ereqorg->per_io_frame_descs;
  92160. +
  92161. + if (req && req->complete) {
  92162. + /* Copy the request data from the portable logic to our request */
  92163. + for (i = 0; i < ereqport->pio_pkt_count; i++) {
  92164. + desc_org[i].actual_length =
  92165. + ereqport->per_io_frame_descs[i].actual_length;
  92166. + desc_org[i].status =
  92167. + ereqport->per_io_frame_descs[i].status;
  92168. + }
  92169. +
  92170. + switch (status) {
  92171. + case -DWC_E_SHUTDOWN:
  92172. + req->status = -ESHUTDOWN;
  92173. + break;
  92174. + case -DWC_E_RESTART:
  92175. + req->status = -ECONNRESET;
  92176. + break;
  92177. + case -DWC_E_INVALID:
  92178. + req->status = -EINVAL;
  92179. + break;
  92180. + case -DWC_E_TIMEOUT:
  92181. + req->status = -ETIMEDOUT;
  92182. + break;
  92183. + default:
  92184. + req->status = status;
  92185. + }
  92186. +
  92187. + /* And call the gadget's completion */
  92188. + req->complete(ep_handle, req);
  92189. + }
  92190. +
  92191. + return 0;
  92192. +}
  92193. +#endif /* DWC_UTE_PER_IO */
  92194. +
  92195. +static int _complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  92196. + void *req_handle, int32_t status, uint32_t actual)
  92197. +{
  92198. + struct usb_request *req = (struct usb_request *)req_handle;
  92199. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27)
  92200. + struct dwc_otg_pcd_ep *ep = NULL;
  92201. +#endif
  92202. +
  92203. + if (req && req->complete) {
  92204. + switch (status) {
  92205. + case -DWC_E_SHUTDOWN:
  92206. + req->status = -ESHUTDOWN;
  92207. + break;
  92208. + case -DWC_E_RESTART:
  92209. + req->status = -ECONNRESET;
  92210. + break;
  92211. + case -DWC_E_INVALID:
  92212. + req->status = -EINVAL;
  92213. + break;
  92214. + case -DWC_E_TIMEOUT:
  92215. + req->status = -ETIMEDOUT;
  92216. + break;
  92217. + default:
  92218. + req->status = status;
  92219. +
  92220. + }
  92221. +
  92222. + req->actual = actual;
  92223. + DWC_SPINUNLOCK(pcd->lock);
  92224. + req->complete(ep_handle, req);
  92225. + DWC_SPINLOCK(pcd->lock);
  92226. + }
  92227. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27)
  92228. + ep = ep_from_handle(pcd, ep_handle);
  92229. + if (GET_CORE_IF(pcd)->dma_enable) {
  92230. + if (req->length != 0) {
  92231. + dwc_otg_device_t *otg_dev = gadget_wrapper->pcd->otg_dev;
  92232. + struct device *dev = NULL;
  92233. +
  92234. + if (otg_dev != NULL)
  92235. + dev = DWC_OTG_OS_GETDEV(otg_dev->os_dep);
  92236. +
  92237. + dma_unmap_single(dev, req->dma, req->length,
  92238. + ep->dwc_ep.is_in ?
  92239. + DMA_TO_DEVICE: DMA_FROM_DEVICE);
  92240. + }
  92241. + }
  92242. +#endif
  92243. +
  92244. + return 0;
  92245. +}
  92246. +
  92247. +static int _connect(dwc_otg_pcd_t * pcd, int speed)
  92248. +{
  92249. + gadget_wrapper->gadget.speed = speed;
  92250. + return 0;
  92251. +}
  92252. +
  92253. +static int _disconnect(dwc_otg_pcd_t * pcd)
  92254. +{
  92255. + if (gadget_wrapper->driver && gadget_wrapper->driver->disconnect) {
  92256. + gadget_wrapper->driver->disconnect(&gadget_wrapper->gadget);
  92257. + }
  92258. + return 0;
  92259. +}
  92260. +
  92261. +static int _resume(dwc_otg_pcd_t * pcd)
  92262. +{
  92263. + if (gadget_wrapper->driver && gadget_wrapper->driver->resume) {
  92264. + gadget_wrapper->driver->resume(&gadget_wrapper->gadget);
  92265. + }
  92266. +
  92267. + return 0;
  92268. +}
  92269. +
  92270. +static int _suspend(dwc_otg_pcd_t * pcd)
  92271. +{
  92272. + if (gadget_wrapper->driver && gadget_wrapper->driver->suspend) {
  92273. + gadget_wrapper->driver->suspend(&gadget_wrapper->gadget);
  92274. + }
  92275. + return 0;
  92276. +}
  92277. +
  92278. +/**
  92279. + * This function updates the otg values in the gadget structure.
  92280. + */
  92281. +static int _hnp_changed(dwc_otg_pcd_t * pcd)
  92282. +{
  92283. +
  92284. + if (!gadget_wrapper->gadget.is_otg)
  92285. + return 0;
  92286. +
  92287. + gadget_wrapper->gadget.b_hnp_enable = get_b_hnp_enable(pcd);
  92288. + gadget_wrapper->gadget.a_hnp_support = get_a_hnp_support(pcd);
  92289. + gadget_wrapper->gadget.a_alt_hnp_support = get_a_alt_hnp_support(pcd);
  92290. + return 0;
  92291. +}
  92292. +
  92293. +static int _reset(dwc_otg_pcd_t * pcd)
  92294. +{
  92295. + return 0;
  92296. +}
  92297. +
  92298. +#ifdef DWC_UTE_CFI
  92299. +static int _cfi_setup(dwc_otg_pcd_t * pcd, void *cfi_req)
  92300. +{
  92301. + int retval = -DWC_E_INVALID;
  92302. + if (gadget_wrapper->driver->cfi_feature_setup) {
  92303. + retval =
  92304. + gadget_wrapper->driver->
  92305. + cfi_feature_setup(&gadget_wrapper->gadget,
  92306. + (struct cfi_usb_ctrlrequest *)cfi_req);
  92307. + }
  92308. +
  92309. + return retval;
  92310. +}
  92311. +#endif
  92312. +
  92313. +static const struct dwc_otg_pcd_function_ops fops = {
  92314. + .complete = _complete,
  92315. +#ifdef DWC_EN_ISOC
  92316. + .isoc_complete = _isoc_complete,
  92317. +#endif
  92318. + .setup = _setup,
  92319. + .disconnect = _disconnect,
  92320. + .connect = _connect,
  92321. + .resume = _resume,
  92322. + .suspend = _suspend,
  92323. + .hnp_changed = _hnp_changed,
  92324. + .reset = _reset,
  92325. +#ifdef DWC_UTE_CFI
  92326. + .cfi_setup = _cfi_setup,
  92327. +#endif
  92328. +#ifdef DWC_UTE_PER_IO
  92329. + .xisoc_complete = _xisoc_complete,
  92330. +#endif
  92331. +};
  92332. +
  92333. +/**
  92334. + * This function is the top level PCD interrupt handler.
  92335. + */
  92336. +static irqreturn_t dwc_otg_pcd_irq(int irq, void *dev)
  92337. +{
  92338. + dwc_otg_pcd_t *pcd = dev;
  92339. + int32_t retval = IRQ_NONE;
  92340. +
  92341. + retval = dwc_otg_pcd_handle_intr(pcd);
  92342. + if (retval != 0) {
  92343. + S3C2410X_CLEAR_EINTPEND();
  92344. + }
  92345. + return IRQ_RETVAL(retval);
  92346. +}
  92347. +
  92348. +/**
  92349. + * This function initialized the usb_ep structures to there default
  92350. + * state.
  92351. + *
  92352. + * @param d Pointer on gadget_wrapper.
  92353. + */
  92354. +void gadget_add_eps(struct gadget_wrapper *d)
  92355. +{
  92356. + static const char *names[] = {
  92357. +
  92358. + "ep0",
  92359. + "ep1in",
  92360. + "ep2in",
  92361. + "ep3in",
  92362. + "ep4in",
  92363. + "ep5in",
  92364. + "ep6in",
  92365. + "ep7in",
  92366. + "ep8in",
  92367. + "ep9in",
  92368. + "ep10in",
  92369. + "ep11in",
  92370. + "ep12in",
  92371. + "ep13in",
  92372. + "ep14in",
  92373. + "ep15in",
  92374. + "ep1out",
  92375. + "ep2out",
  92376. + "ep3out",
  92377. + "ep4out",
  92378. + "ep5out",
  92379. + "ep6out",
  92380. + "ep7out",
  92381. + "ep8out",
  92382. + "ep9out",
  92383. + "ep10out",
  92384. + "ep11out",
  92385. + "ep12out",
  92386. + "ep13out",
  92387. + "ep14out",
  92388. + "ep15out"
  92389. + };
  92390. +
  92391. + int i;
  92392. + struct usb_ep *ep;
  92393. + int8_t dev_endpoints;
  92394. +
  92395. + DWC_DEBUGPL(DBG_PCDV, "%s\n", __func__);
  92396. +
  92397. + INIT_LIST_HEAD(&d->gadget.ep_list);
  92398. + d->gadget.ep0 = &d->ep0;
  92399. + d->gadget.speed = USB_SPEED_UNKNOWN;
  92400. +
  92401. + INIT_LIST_HEAD(&d->gadget.ep0->ep_list);
  92402. +
  92403. + /**
  92404. + * Initialize the EP0 structure.
  92405. + */
  92406. + ep = &d->ep0;
  92407. +
  92408. + /* Init the usb_ep structure. */
  92409. + ep->name = names[0];
  92410. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  92411. +
  92412. + /**
  92413. + * @todo NGS: What should the max packet size be set to
  92414. + * here? Before EP type is set?
  92415. + */
  92416. + ep->maxpacket = MAX_PACKET_SIZE;
  92417. + dwc_otg_pcd_ep_enable(d->pcd, NULL, ep);
  92418. +
  92419. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  92420. +
  92421. + /**
  92422. + * Initialize the EP structures.
  92423. + */
  92424. + dev_endpoints = d->pcd->core_if->dev_if->num_in_eps;
  92425. +
  92426. + for (i = 0; i < dev_endpoints; i++) {
  92427. + ep = &d->in_ep[i];
  92428. +
  92429. + /* Init the usb_ep structure. */
  92430. + ep->name = names[d->pcd->in_ep[i].dwc_ep.num];
  92431. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  92432. +
  92433. + /**
  92434. + * @todo NGS: What should the max packet size be set to
  92435. + * here? Before EP type is set?
  92436. + */
  92437. + ep->maxpacket = MAX_PACKET_SIZE;
  92438. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  92439. + }
  92440. +
  92441. + dev_endpoints = d->pcd->core_if->dev_if->num_out_eps;
  92442. +
  92443. + for (i = 0; i < dev_endpoints; i++) {
  92444. + ep = &d->out_ep[i];
  92445. +
  92446. + /* Init the usb_ep structure. */
  92447. + ep->name = names[15 + d->pcd->out_ep[i].dwc_ep.num];
  92448. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  92449. +
  92450. + /**
  92451. + * @todo NGS: What should the max packet size be set to
  92452. + * here? Before EP type is set?
  92453. + */
  92454. + ep->maxpacket = MAX_PACKET_SIZE;
  92455. +
  92456. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  92457. + }
  92458. +
  92459. + /* remove ep0 from the list. There is a ep0 pointer. */
  92460. + list_del_init(&d->ep0.ep_list);
  92461. +
  92462. + d->ep0.maxpacket = MAX_EP0_SIZE;
  92463. +}
  92464. +
  92465. +/**
  92466. + * This function releases the Gadget device.
  92467. + * required by device_unregister().
  92468. + *
  92469. + * @todo Should this do something? Should it free the PCD?
  92470. + */
  92471. +static void dwc_otg_pcd_gadget_release(struct device *dev)
  92472. +{
  92473. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, dev);
  92474. +}
  92475. +
  92476. +static struct gadget_wrapper *alloc_wrapper(dwc_bus_dev_t *_dev)
  92477. +{
  92478. + static char pcd_name[] = "dwc_otg_pcd";
  92479. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  92480. + struct gadget_wrapper *d;
  92481. + int retval;
  92482. +
  92483. + d = DWC_ALLOC(sizeof(*d));
  92484. + if (d == NULL) {
  92485. + return NULL;
  92486. + }
  92487. +
  92488. + memset(d, 0, sizeof(*d));
  92489. +
  92490. + d->gadget.name = pcd_name;
  92491. + d->pcd = otg_dev->pcd;
  92492. +
  92493. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  92494. + strcpy(d->gadget.dev.bus_id, "gadget");
  92495. +#else
  92496. + dev_set_name(&d->gadget.dev, "%s", "gadget");
  92497. +#endif
  92498. +
  92499. + d->gadget.dev.parent = &_dev->dev;
  92500. + d->gadget.dev.release = dwc_otg_pcd_gadget_release;
  92501. + d->gadget.ops = &dwc_otg_pcd_ops;
  92502. + d->gadget.max_speed = dwc_otg_pcd_is_dualspeed(otg_dev->pcd) ? USB_SPEED_HIGH:USB_SPEED_FULL;
  92503. + d->gadget.is_otg = dwc_otg_pcd_is_otg(otg_dev->pcd);
  92504. +
  92505. + d->driver = 0;
  92506. + /* Register the gadget device */
  92507. + retval = device_register(&d->gadget.dev);
  92508. + if (retval != 0) {
  92509. + DWC_ERROR("device_register failed\n");
  92510. + DWC_FREE(d);
  92511. + return NULL;
  92512. + }
  92513. +
  92514. + return d;
  92515. +}
  92516. +
  92517. +static void free_wrapper(struct gadget_wrapper *d)
  92518. +{
  92519. + if (d->driver) {
  92520. + /* should have been done already by driver model core */
  92521. + DWC_WARN("driver '%s' is still registered\n",
  92522. + d->driver->driver.name);
  92523. + usb_gadget_unregister_driver(d->driver);
  92524. + }
  92525. +
  92526. + device_unregister(&d->gadget.dev);
  92527. + DWC_FREE(d);
  92528. +}
  92529. +
  92530. +/**
  92531. + * This function initialized the PCD portion of the driver.
  92532. + *
  92533. + */
  92534. +int pcd_init(dwc_bus_dev_t *_dev)
  92535. +{
  92536. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  92537. + int retval = 0;
  92538. +
  92539. + DWC_DEBUGPL(DBG_PCDV, "%s(%p) otg_dev=%p\n", __func__, _dev, otg_dev);
  92540. +
  92541. + otg_dev->pcd = dwc_otg_pcd_init(otg_dev->core_if);
  92542. +
  92543. + if (!otg_dev->pcd) {
  92544. + DWC_ERROR("dwc_otg_pcd_init failed\n");
  92545. + return -ENOMEM;
  92546. + }
  92547. +
  92548. + otg_dev->pcd->otg_dev = otg_dev;
  92549. + gadget_wrapper = alloc_wrapper(_dev);
  92550. +
  92551. + /*
  92552. + * Initialize EP structures
  92553. + */
  92554. + gadget_add_eps(gadget_wrapper);
  92555. + /*
  92556. + * Setup interupt handler
  92557. + */
  92558. +#ifdef PLATFORM_INTERFACE
  92559. + DWC_DEBUGPL(DBG_ANY, "registering handler for irq%d\n",
  92560. + platform_get_irq(_dev, fiq_enable ? 0 : 1));
  92561. + retval = request_irq(platform_get_irq(_dev, fiq_enable ? 0 : 1), dwc_otg_pcd_irq,
  92562. + IRQF_SHARED, gadget_wrapper->gadget.name,
  92563. + otg_dev->pcd);
  92564. + if (retval != 0) {
  92565. + DWC_ERROR("request of irq%d failed\n",
  92566. + platform_get_irq(_dev, fiq_enable ? 0 : 1));
  92567. + free_wrapper(gadget_wrapper);
  92568. + return -EBUSY;
  92569. + }
  92570. +#else
  92571. + DWC_DEBUGPL(DBG_ANY, "registering handler for irq%d\n",
  92572. + _dev->irq);
  92573. + retval = request_irq(_dev->irq, dwc_otg_pcd_irq,
  92574. + IRQF_SHARED | IRQF_DISABLED,
  92575. + gadget_wrapper->gadget.name, otg_dev->pcd);
  92576. + if (retval != 0) {
  92577. + DWC_ERROR("request of irq%d failed\n", _dev->irq);
  92578. + free_wrapper(gadget_wrapper);
  92579. + return -EBUSY;
  92580. + }
  92581. +#endif
  92582. +
  92583. + dwc_otg_pcd_start(gadget_wrapper->pcd, &fops);
  92584. +
  92585. + return retval;
  92586. +}
  92587. +
  92588. +/**
  92589. + * Cleanup the PCD.
  92590. + */
  92591. +void pcd_remove(dwc_bus_dev_t *_dev)
  92592. +{
  92593. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  92594. + dwc_otg_pcd_t *pcd = otg_dev->pcd;
  92595. +
  92596. + DWC_DEBUGPL(DBG_PCDV, "%s(%p) otg_dev %p\n", __func__, _dev, otg_dev);
  92597. +
  92598. + /*
  92599. + * Free the IRQ
  92600. + */
  92601. +#ifdef PLATFORM_INTERFACE
  92602. + free_irq(platform_get_irq(_dev, 0), pcd);
  92603. +#else
  92604. + free_irq(_dev->irq, pcd);
  92605. +#endif
  92606. + dwc_otg_pcd_remove(otg_dev->pcd);
  92607. + free_wrapper(gadget_wrapper);
  92608. + otg_dev->pcd = 0;
  92609. +}
  92610. +
  92611. +/**
  92612. + * This function registers a gadget driver with the PCD.
  92613. + *
  92614. + * When a driver is successfully registered, it will receive control
  92615. + * requests including set_configuration(), which enables non-control
  92616. + * requests. then usb traffic follows until a disconnect is reported.
  92617. + * then a host may connect again, or the driver might get unbound.
  92618. + *
  92619. + * @param driver The driver being registered
  92620. + * @param bind The bind function of gadget driver
  92621. + */
  92622. +
  92623. +int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
  92624. +{
  92625. + int retval;
  92626. +
  92627. + DWC_DEBUGPL(DBG_PCD, "registering gadget driver '%s'\n",
  92628. + driver->driver.name);
  92629. +
  92630. + if (!driver || driver->max_speed == USB_SPEED_UNKNOWN ||
  92631. + !driver->bind ||
  92632. + !driver->unbind || !driver->disconnect || !driver->setup) {
  92633. + DWC_DEBUGPL(DBG_PCDV, "EINVAL\n");
  92634. + return -EINVAL;
  92635. + }
  92636. + if (gadget_wrapper == 0) {
  92637. + DWC_DEBUGPL(DBG_PCDV, "ENODEV\n");
  92638. + return -ENODEV;
  92639. + }
  92640. + if (gadget_wrapper->driver != 0) {
  92641. + DWC_DEBUGPL(DBG_PCDV, "EBUSY (%p)\n", gadget_wrapper->driver);
  92642. + return -EBUSY;
  92643. + }
  92644. +
  92645. + /* hook up the driver */
  92646. + gadget_wrapper->driver = driver;
  92647. + gadget_wrapper->gadget.dev.driver = &driver->driver;
  92648. +
  92649. + DWC_DEBUGPL(DBG_PCD, "bind to driver %s\n", driver->driver.name);
  92650. + retval = driver->bind(&gadget_wrapper->gadget, gadget_wrapper->driver);
  92651. + if (retval) {
  92652. + DWC_ERROR("bind to driver %s --> error %d\n",
  92653. + driver->driver.name, retval);
  92654. + gadget_wrapper->driver = 0;
  92655. + gadget_wrapper->gadget.dev.driver = 0;
  92656. + return retval;
  92657. + }
  92658. + DWC_DEBUGPL(DBG_ANY, "registered gadget driver '%s'\n",
  92659. + driver->driver.name);
  92660. + return 0;
  92661. +}
  92662. +EXPORT_SYMBOL(usb_gadget_probe_driver);
  92663. +
  92664. +/**
  92665. + * This function unregisters a gadget driver
  92666. + *
  92667. + * @param driver The driver being unregistered
  92668. + */
  92669. +int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
  92670. +{
  92671. + //DWC_DEBUGPL(DBG_PCDV,"%s(%p)\n", __func__, _driver);
  92672. +
  92673. + if (gadget_wrapper == 0) {
  92674. + DWC_DEBUGPL(DBG_ANY, "%s Return(%d): s_pcd==0\n", __func__,
  92675. + -ENODEV);
  92676. + return -ENODEV;
  92677. + }
  92678. + if (driver == 0 || driver != gadget_wrapper->driver) {
  92679. + DWC_DEBUGPL(DBG_ANY, "%s Return(%d): driver?\n", __func__,
  92680. + -EINVAL);
  92681. + return -EINVAL;
  92682. + }
  92683. +
  92684. + driver->unbind(&gadget_wrapper->gadget);
  92685. + gadget_wrapper->driver = 0;
  92686. +
  92687. + DWC_DEBUGPL(DBG_ANY, "unregistered driver '%s'\n", driver->driver.name);
  92688. + return 0;
  92689. +}
  92690. +
  92691. +EXPORT_SYMBOL(usb_gadget_unregister_driver);
  92692. +
  92693. +#endif /* DWC_HOST_ONLY */
  92694. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_regs.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_regs.h
  92695. --- linux-3.15.4/drivers/usb/host/dwc_otg/dwc_otg_regs.h 1970-01-01 01:00:00.000000000 +0100
  92696. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_regs.h 2014-07-07 10:45:43.000000000 +0200
  92697. @@ -0,0 +1,2550 @@
  92698. +/* ==========================================================================
  92699. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_regs.h $
  92700. + * $Revision: #98 $
  92701. + * $Date: 2012/08/10 $
  92702. + * $Change: 2047372 $
  92703. + *
  92704. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  92705. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  92706. + * otherwise expressly agreed to in writing between Synopsys and you.
  92707. + *
  92708. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  92709. + * any End User Software License Agreement or Agreement for Licensed Product
  92710. + * with Synopsys or any supplement thereto. You are permitted to use and
  92711. + * redistribute this Software in source and binary forms, with or without
  92712. + * modification, provided that redistributions of source code must retain this
  92713. + * notice. You may not view, use, disclose, copy or distribute this file or
  92714. + * any information contained herein except pursuant to this license grant from
  92715. + * Synopsys. If you do not agree with this notice, including the disclaimer
  92716. + * below, then you are not authorized to use the Software.
  92717. + *
  92718. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  92719. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  92720. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  92721. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  92722. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  92723. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  92724. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  92725. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  92726. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  92727. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  92728. + * DAMAGE.
  92729. + * ========================================================================== */
  92730. +
  92731. +#ifndef __DWC_OTG_REGS_H__
  92732. +#define __DWC_OTG_REGS_H__
  92733. +
  92734. +#include "dwc_otg_core_if.h"
  92735. +
  92736. +/**
  92737. + * @file
  92738. + *
  92739. + * This file contains the data structures for accessing the DWC_otg core registers.
  92740. + *
  92741. + * The application interfaces with the HS OTG core by reading from and
  92742. + * writing to the Control and Status Register (CSR) space through the
  92743. + * AHB Slave interface. These registers are 32 bits wide, and the
  92744. + * addresses are 32-bit-block aligned.
  92745. + * CSRs are classified as follows:
  92746. + * - Core Global Registers
  92747. + * - Device Mode Registers
  92748. + * - Device Global Registers
  92749. + * - Device Endpoint Specific Registers
  92750. + * - Host Mode Registers
  92751. + * - Host Global Registers
  92752. + * - Host Port CSRs
  92753. + * - Host Channel Specific Registers
  92754. + *
  92755. + * Only the Core Global registers can be accessed in both Device and
  92756. + * Host modes. When the HS OTG core is operating in one mode, either
  92757. + * Device or Host, the application must not access registers from the
  92758. + * other mode. When the core switches from one mode to another, the
  92759. + * registers in the new mode of operation must be reprogrammed as they
  92760. + * would be after a power-on reset.
  92761. + */
  92762. +
  92763. +/****************************************************************************/
  92764. +/** DWC_otg Core registers .
  92765. + * The dwc_otg_core_global_regs structure defines the size
  92766. + * and relative field offsets for the Core Global registers.
  92767. + */
  92768. +typedef struct dwc_otg_core_global_regs {
  92769. + /** OTG Control and Status Register. <i>Offset: 000h</i> */
  92770. + volatile uint32_t gotgctl;
  92771. + /** OTG Interrupt Register. <i>Offset: 004h</i> */
  92772. + volatile uint32_t gotgint;
  92773. + /**Core AHB Configuration Register. <i>Offset: 008h</i> */
  92774. + volatile uint32_t gahbcfg;
  92775. +
  92776. +#define DWC_GLBINTRMASK 0x0001
  92777. +#define DWC_DMAENABLE 0x0020
  92778. +#define DWC_NPTXEMPTYLVL_EMPTY 0x0080
  92779. +#define DWC_NPTXEMPTYLVL_HALFEMPTY 0x0000
  92780. +#define DWC_PTXEMPTYLVL_EMPTY 0x0100
  92781. +#define DWC_PTXEMPTYLVL_HALFEMPTY 0x0000
  92782. +
  92783. + /**Core USB Configuration Register. <i>Offset: 00Ch</i> */
  92784. + volatile uint32_t gusbcfg;
  92785. + /**Core Reset Register. <i>Offset: 010h</i> */
  92786. + volatile uint32_t grstctl;
  92787. + /**Core Interrupt Register. <i>Offset: 014h</i> */
  92788. + volatile uint32_t gintsts;
  92789. + /**Core Interrupt Mask Register. <i>Offset: 018h</i> */
  92790. + volatile uint32_t gintmsk;
  92791. + /**Receive Status Queue Read Register (Read Only). <i>Offset: 01Ch</i> */
  92792. + volatile uint32_t grxstsr;
  92793. + /**Receive Status Queue Read & POP Register (Read Only). <i>Offset: 020h</i>*/
  92794. + volatile uint32_t grxstsp;
  92795. + /**Receive FIFO Size Register. <i>Offset: 024h</i> */
  92796. + volatile uint32_t grxfsiz;
  92797. + /**Non Periodic Transmit FIFO Size Register. <i>Offset: 028h</i> */
  92798. + volatile uint32_t gnptxfsiz;
  92799. + /**Non Periodic Transmit FIFO/Queue Status Register (Read
  92800. + * Only). <i>Offset: 02Ch</i> */
  92801. + volatile uint32_t gnptxsts;
  92802. + /**I2C Access Register. <i>Offset: 030h</i> */
  92803. + volatile uint32_t gi2cctl;
  92804. + /**PHY Vendor Control Register. <i>Offset: 034h</i> */
  92805. + volatile uint32_t gpvndctl;
  92806. + /**General Purpose Input/Output Register. <i>Offset: 038h</i> */
  92807. + volatile uint32_t ggpio;
  92808. + /**User ID Register. <i>Offset: 03Ch</i> */
  92809. + volatile uint32_t guid;
  92810. + /**Synopsys ID Register (Read Only). <i>Offset: 040h</i> */
  92811. + volatile uint32_t gsnpsid;
  92812. + /**User HW Config1 Register (Read Only). <i>Offset: 044h</i> */
  92813. + volatile uint32_t ghwcfg1;
  92814. + /**User HW Config2 Register (Read Only). <i>Offset: 048h</i> */
  92815. + volatile uint32_t ghwcfg2;
  92816. +#define DWC_SLAVE_ONLY_ARCH 0
  92817. +#define DWC_EXT_DMA_ARCH 1
  92818. +#define DWC_INT_DMA_ARCH 2
  92819. +
  92820. +#define DWC_MODE_HNP_SRP_CAPABLE 0
  92821. +#define DWC_MODE_SRP_ONLY_CAPABLE 1
  92822. +#define DWC_MODE_NO_HNP_SRP_CAPABLE 2
  92823. +#define DWC_MODE_SRP_CAPABLE_DEVICE 3
  92824. +#define DWC_MODE_NO_SRP_CAPABLE_DEVICE 4
  92825. +#define DWC_MODE_SRP_CAPABLE_HOST 5
  92826. +#define DWC_MODE_NO_SRP_CAPABLE_HOST 6
  92827. +
  92828. + /**User HW Config3 Register (Read Only). <i>Offset: 04Ch</i> */
  92829. + volatile uint32_t ghwcfg3;
  92830. + /**User HW Config4 Register (Read Only). <i>Offset: 050h</i>*/
  92831. + volatile uint32_t ghwcfg4;
  92832. + /** Core LPM Configuration register <i>Offset: 054h</i>*/
  92833. + volatile uint32_t glpmcfg;
  92834. + /** Global PowerDn Register <i>Offset: 058h</i> */
  92835. + volatile uint32_t gpwrdn;
  92836. + /** Global DFIFO SW Config Register <i>Offset: 05Ch</i> */
  92837. + volatile uint32_t gdfifocfg;
  92838. + /** ADP Control Register <i>Offset: 060h</i> */
  92839. + volatile uint32_t adpctl;
  92840. + /** Reserved <i>Offset: 064h-0FFh</i> */
  92841. + volatile uint32_t reserved39[39];
  92842. + /** Host Periodic Transmit FIFO Size Register. <i>Offset: 100h</i> */
  92843. + volatile uint32_t hptxfsiz;
  92844. + /** Device Periodic Transmit FIFO#n Register if dedicated fifos are disabled,
  92845. + otherwise Device Transmit FIFO#n Register.
  92846. + * <i>Offset: 104h + (FIFO_Number-1)*04h, 1 <= FIFO Number <= 15 (1<=n<=15).</i> */
  92847. + volatile uint32_t dtxfsiz[15];
  92848. +} dwc_otg_core_global_regs_t;
  92849. +
  92850. +/**
  92851. + * This union represents the bit fields of the Core OTG Control
  92852. + * and Status Register (GOTGCTL). Set the bits using the bit
  92853. + * fields then write the <i>d32</i> value to the register.
  92854. + */
  92855. +typedef union gotgctl_data {
  92856. + /** raw register data */
  92857. + uint32_t d32;
  92858. + /** register bits */
  92859. + struct {
  92860. + unsigned sesreqscs:1;
  92861. + unsigned sesreq:1;
  92862. + unsigned vbvalidoven:1;
  92863. + unsigned vbvalidovval:1;
  92864. + unsigned avalidoven:1;
  92865. + unsigned avalidovval:1;
  92866. + unsigned bvalidoven:1;
  92867. + unsigned bvalidovval:1;
  92868. + unsigned hstnegscs:1;
  92869. + unsigned hnpreq:1;
  92870. + unsigned hstsethnpen:1;
  92871. + unsigned devhnpen:1;
  92872. + unsigned reserved12_15:4;
  92873. + unsigned conidsts:1;
  92874. + unsigned dbnctime:1;
  92875. + unsigned asesvld:1;
  92876. + unsigned bsesvld:1;
  92877. + unsigned otgver:1;
  92878. + unsigned reserved1:1;
  92879. + unsigned multvalidbc:5;
  92880. + unsigned chirpen:1;
  92881. + unsigned reserved28_31:4;
  92882. + } b;
  92883. +} gotgctl_data_t;
  92884. +
  92885. +/**
  92886. + * This union represents the bit fields of the Core OTG Interrupt Register
  92887. + * (GOTGINT). Set/clear the bits using the bit fields then write the <i>d32</i>
  92888. + * value to the register.
  92889. + */
  92890. +typedef union gotgint_data {
  92891. + /** raw register data */
  92892. + uint32_t d32;
  92893. + /** register bits */
  92894. + struct {
  92895. + /** Current Mode */
  92896. + unsigned reserved0_1:2;
  92897. +
  92898. + /** Session End Detected */
  92899. + unsigned sesenddet:1;
  92900. +
  92901. + unsigned reserved3_7:5;
  92902. +
  92903. + /** Session Request Success Status Change */
  92904. + unsigned sesreqsucstschng:1;
  92905. + /** Host Negotiation Success Status Change */
  92906. + unsigned hstnegsucstschng:1;
  92907. +
  92908. + unsigned reserved10_16:7;
  92909. +
  92910. + /** Host Negotiation Detected */
  92911. + unsigned hstnegdet:1;
  92912. + /** A-Device Timeout Change */
  92913. + unsigned adevtoutchng:1;
  92914. + /** Debounce Done */
  92915. + unsigned debdone:1;
  92916. + /** Multi-Valued input changed */
  92917. + unsigned mvic:1;
  92918. +
  92919. + unsigned reserved31_21:11;
  92920. +
  92921. + } b;
  92922. +} gotgint_data_t;
  92923. +
  92924. +/**
  92925. + * This union represents the bit fields of the Core AHB Configuration
  92926. + * Register (GAHBCFG). Set/clear the bits using the bit fields then
  92927. + * write the <i>d32</i> value to the register.
  92928. + */
  92929. +typedef union gahbcfg_data {
  92930. + /** raw register data */
  92931. + uint32_t d32;
  92932. + /** register bits */
  92933. + struct {
  92934. + unsigned glblintrmsk:1;
  92935. +#define DWC_GAHBCFG_GLBINT_ENABLE 1
  92936. +
  92937. + unsigned hburstlen:4;
  92938. +#define DWC_GAHBCFG_INT_DMA_BURST_SINGLE 0
  92939. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR 1
  92940. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR4 3
  92941. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR8 5
  92942. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR16 7
  92943. +
  92944. + unsigned dmaenable:1;
  92945. +#define DWC_GAHBCFG_DMAENABLE 1
  92946. + unsigned reserved:1;
  92947. + unsigned nptxfemplvl_txfemplvl:1;
  92948. + unsigned ptxfemplvl:1;
  92949. +#define DWC_GAHBCFG_TXFEMPTYLVL_EMPTY 1
  92950. +#define DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY 0
  92951. + unsigned reserved9_20:12;
  92952. + unsigned remmemsupp:1;
  92953. + unsigned notialldmawrit:1;
  92954. + unsigned ahbsingle:1;
  92955. + unsigned reserved24_31:8;
  92956. + } b;
  92957. +} gahbcfg_data_t;
  92958. +
  92959. +/**
  92960. + * This union represents the bit fields of the Core USB Configuration
  92961. + * Register (GUSBCFG). Set the bits using the bit fields then write
  92962. + * the <i>d32</i> value to the register.
  92963. + */
  92964. +typedef union gusbcfg_data {
  92965. + /** raw register data */
  92966. + uint32_t d32;
  92967. + /** register bits */
  92968. + struct {
  92969. + unsigned toutcal:3;
  92970. + unsigned phyif:1;
  92971. + unsigned ulpi_utmi_sel:1;
  92972. + unsigned fsintf:1;
  92973. + unsigned physel:1;
  92974. + unsigned ddrsel:1;
  92975. + unsigned srpcap:1;
  92976. + unsigned hnpcap:1;
  92977. + unsigned usbtrdtim:4;
  92978. + unsigned reserved1:1;
  92979. + unsigned phylpwrclksel:1;
  92980. + unsigned otgutmifssel:1;
  92981. + unsigned ulpi_fsls:1;
  92982. + unsigned ulpi_auto_res:1;
  92983. + unsigned ulpi_clk_sus_m:1;
  92984. + unsigned ulpi_ext_vbus_drv:1;
  92985. + unsigned ulpi_int_vbus_indicator:1;
  92986. + unsigned term_sel_dl_pulse:1;
  92987. + unsigned indicator_complement:1;
  92988. + unsigned indicator_pass_through:1;
  92989. + unsigned ulpi_int_prot_dis:1;
  92990. + unsigned ic_usb_cap:1;
  92991. + unsigned ic_traffic_pull_remove:1;
  92992. + unsigned tx_end_delay:1;
  92993. + unsigned force_host_mode:1;
  92994. + unsigned force_dev_mode:1;
  92995. + unsigned reserved31:1;
  92996. + } b;
  92997. +} gusbcfg_data_t;
  92998. +
  92999. +/**
  93000. + * This union represents the bit fields of the Core Reset Register
  93001. + * (GRSTCTL). Set/clear the bits using the bit fields then write the
  93002. + * <i>d32</i> value to the register.
  93003. + */
  93004. +typedef union grstctl_data {
  93005. + /** raw register data */
  93006. + uint32_t d32;
  93007. + /** register bits */
  93008. + struct {
  93009. + /** Core Soft Reset (CSftRst) (Device and Host)
  93010. + *
  93011. + * The application can flush the control logic in the
  93012. + * entire core using this bit. This bit resets the
  93013. + * pipelines in the AHB Clock domain as well as the
  93014. + * PHY Clock domain.
  93015. + *
  93016. + * The state machines are reset to an IDLE state, the
  93017. + * control bits in the CSRs are cleared, all the
  93018. + * transmit FIFOs and the receive FIFO are flushed.
  93019. + *
  93020. + * The status mask bits that control the generation of
  93021. + * the interrupt, are cleared, to clear the
  93022. + * interrupt. The interrupt status bits are not
  93023. + * cleared, so the application can get the status of
  93024. + * any events that occurred in the core after it has
  93025. + * set this bit.
  93026. + *
  93027. + * Any transactions on the AHB are terminated as soon
  93028. + * as possible following the protocol. Any
  93029. + * transactions on the USB are terminated immediately.
  93030. + *
  93031. + * The configuration settings in the CSRs are
  93032. + * unchanged, so the software doesn't have to
  93033. + * reprogram these registers (Device
  93034. + * Configuration/Host Configuration/Core System
  93035. + * Configuration/Core PHY Configuration).
  93036. + *
  93037. + * The application can write to this bit, any time it
  93038. + * wants to reset the core. This is a self clearing
  93039. + * bit and the core clears this bit after all the
  93040. + * necessary logic is reset in the core, which may
  93041. + * take several clocks, depending on the current state
  93042. + * of the core.
  93043. + */
  93044. + unsigned csftrst:1;
  93045. + /** Hclk Soft Reset
  93046. + *
  93047. + * The application uses this bit to reset the control logic in
  93048. + * the AHB clock domain. Only AHB clock domain pipelines are
  93049. + * reset.
  93050. + */
  93051. + unsigned hsftrst:1;
  93052. + /** Host Frame Counter Reset (Host Only)<br>
  93053. + *
  93054. + * The application can reset the (micro)frame number
  93055. + * counter inside the core, using this bit. When the
  93056. + * (micro)frame counter is reset, the subsequent SOF
  93057. + * sent out by the core, will have a (micro)frame
  93058. + * number of 0.
  93059. + */
  93060. + unsigned hstfrm:1;
  93061. + /** In Token Sequence Learning Queue Flush
  93062. + * (INTknQFlsh) (Device Only)
  93063. + */
  93064. + unsigned intknqflsh:1;
  93065. + /** RxFIFO Flush (RxFFlsh) (Device and Host)
  93066. + *
  93067. + * The application can flush the entire Receive FIFO
  93068. + * using this bit. The application must first
  93069. + * ensure that the core is not in the middle of a
  93070. + * transaction. The application should write into
  93071. + * this bit, only after making sure that neither the
  93072. + * DMA engine is reading from the RxFIFO nor the MAC
  93073. + * is writing the data in to the FIFO. The
  93074. + * application should wait until the bit is cleared
  93075. + * before performing any other operations. This bit
  93076. + * will takes 8 clocks (slowest of PHY or AHB clock)
  93077. + * to clear.
  93078. + */
  93079. + unsigned rxfflsh:1;
  93080. + /** TxFIFO Flush (TxFFlsh) (Device and Host).
  93081. + *
  93082. + * This bit is used to selectively flush a single or
  93083. + * all transmit FIFOs. The application must first
  93084. + * ensure that the core is not in the middle of a
  93085. + * transaction. The application should write into
  93086. + * this bit, only after making sure that neither the
  93087. + * DMA engine is writing into the TxFIFO nor the MAC
  93088. + * is reading the data out of the FIFO. The
  93089. + * application should wait until the core clears this
  93090. + * bit, before performing any operations. This bit
  93091. + * will takes 8 clocks (slowest of PHY or AHB clock)
  93092. + * to clear.
  93093. + */
  93094. + unsigned txfflsh:1;
  93095. +
  93096. + /** TxFIFO Number (TxFNum) (Device and Host).
  93097. + *
  93098. + * This is the FIFO number which needs to be flushed,
  93099. + * using the TxFIFO Flush bit. This field should not
  93100. + * be changed until the TxFIFO Flush bit is cleared by
  93101. + * the core.
  93102. + * - 0x0 : Non Periodic TxFIFO Flush
  93103. + * - 0x1 : Periodic TxFIFO #1 Flush in device mode
  93104. + * or Periodic TxFIFO in host mode
  93105. + * - 0x2 : Periodic TxFIFO #2 Flush in device mode.
  93106. + * - ...
  93107. + * - 0xF : Periodic TxFIFO #15 Flush in device mode
  93108. + * - 0x10: Flush all the Transmit NonPeriodic and
  93109. + * Transmit Periodic FIFOs in the core
  93110. + */
  93111. + unsigned txfnum:5;
  93112. + /** Reserved */
  93113. + unsigned reserved11_29:19;
  93114. + /** DMA Request Signal. Indicated DMA request is in
  93115. + * probress. Used for debug purpose. */
  93116. + unsigned dmareq:1;
  93117. + /** AHB Master Idle. Indicates the AHB Master State
  93118. + * Machine is in IDLE condition. */
  93119. + unsigned ahbidle:1;
  93120. + } b;
  93121. +} grstctl_t;
  93122. +
  93123. +/**
  93124. + * This union represents the bit fields of the Core Interrupt Mask
  93125. + * Register (GINTMSK). Set/clear the bits using the bit fields then
  93126. + * write the <i>d32</i> value to the register.
  93127. + */
  93128. +typedef union gintmsk_data {
  93129. + /** raw register data */
  93130. + uint32_t d32;
  93131. + /** register bits */
  93132. + struct {
  93133. + unsigned reserved0:1;
  93134. + unsigned modemismatch:1;
  93135. + unsigned otgintr:1;
  93136. + unsigned sofintr:1;
  93137. + unsigned rxstsqlvl:1;
  93138. + unsigned nptxfempty:1;
  93139. + unsigned ginnakeff:1;
  93140. + unsigned goutnakeff:1;
  93141. + unsigned ulpickint:1;
  93142. + unsigned i2cintr:1;
  93143. + unsigned erlysuspend:1;
  93144. + unsigned usbsuspend:1;
  93145. + unsigned usbreset:1;
  93146. + unsigned enumdone:1;
  93147. + unsigned isooutdrop:1;
  93148. + unsigned eopframe:1;
  93149. + unsigned restoredone:1;
  93150. + unsigned epmismatch:1;
  93151. + unsigned inepintr:1;
  93152. + unsigned outepintr:1;
  93153. + unsigned incomplisoin:1;
  93154. + unsigned incomplisoout:1;
  93155. + unsigned fetsusp:1;
  93156. + unsigned resetdet:1;
  93157. + unsigned portintr:1;
  93158. + unsigned hcintr:1;
  93159. + unsigned ptxfempty:1;
  93160. + unsigned lpmtranrcvd:1;
  93161. + unsigned conidstschng:1;
  93162. + unsigned disconnect:1;
  93163. + unsigned sessreqintr:1;
  93164. + unsigned wkupintr:1;
  93165. + } b;
  93166. +} gintmsk_data_t;
  93167. +/**
  93168. + * This union represents the bit fields of the Core Interrupt Register
  93169. + * (GINTSTS). Set/clear the bits using the bit fields then write the
  93170. + * <i>d32</i> value to the register.
  93171. + */
  93172. +typedef union gintsts_data {
  93173. + /** raw register data */
  93174. + uint32_t d32;
  93175. +#define DWC_SOF_INTR_MASK 0x0008
  93176. + /** register bits */
  93177. + struct {
  93178. +#define DWC_HOST_MODE 1
  93179. + unsigned curmode:1;
  93180. + unsigned modemismatch:1;
  93181. + unsigned otgintr:1;
  93182. + unsigned sofintr:1;
  93183. + unsigned rxstsqlvl:1;
  93184. + unsigned nptxfempty:1;
  93185. + unsigned ginnakeff:1;
  93186. + unsigned goutnakeff:1;
  93187. + unsigned ulpickint:1;
  93188. + unsigned i2cintr:1;
  93189. + unsigned erlysuspend:1;
  93190. + unsigned usbsuspend:1;
  93191. + unsigned usbreset:1;
  93192. + unsigned enumdone:1;
  93193. + unsigned isooutdrop:1;
  93194. + unsigned eopframe:1;
  93195. + unsigned restoredone:1;
  93196. + unsigned epmismatch:1;
  93197. + unsigned inepint:1;
  93198. + unsigned outepintr:1;
  93199. + unsigned incomplisoin:1;
  93200. + unsigned incomplisoout:1;
  93201. + unsigned fetsusp:1;
  93202. + unsigned resetdet:1;
  93203. + unsigned portintr:1;
  93204. + unsigned hcintr:1;
  93205. + unsigned ptxfempty:1;
  93206. + unsigned lpmtranrcvd:1;
  93207. + unsigned conidstschng:1;
  93208. + unsigned disconnect:1;
  93209. + unsigned sessreqintr:1;
  93210. + unsigned wkupintr:1;
  93211. + } b;
  93212. +} gintsts_data_t;
  93213. +
  93214. +/**
  93215. + * This union represents the bit fields in the Device Receive Status Read and
  93216. + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
  93217. + * element then read out the bits using the <i>b</i>it elements.
  93218. + */
  93219. +typedef union device_grxsts_data {
  93220. + /** raw register data */
  93221. + uint32_t d32;
  93222. + /** register bits */
  93223. + struct {
  93224. + unsigned epnum:4;
  93225. + unsigned bcnt:11;
  93226. + unsigned dpid:2;
  93227. +
  93228. +#define DWC_STS_DATA_UPDT 0x2 // OUT Data Packet
  93229. +#define DWC_STS_XFER_COMP 0x3 // OUT Data Transfer Complete
  93230. +
  93231. +#define DWC_DSTS_GOUT_NAK 0x1 // Global OUT NAK
  93232. +#define DWC_DSTS_SETUP_COMP 0x4 // Setup Phase Complete
  93233. +#define DWC_DSTS_SETUP_UPDT 0x6 // SETUP Packet
  93234. + unsigned pktsts:4;
  93235. + unsigned fn:4;
  93236. + unsigned reserved25_31:7;
  93237. + } b;
  93238. +} device_grxsts_data_t;
  93239. +
  93240. +/**
  93241. + * This union represents the bit fields in the Host Receive Status Read and
  93242. + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
  93243. + * element then read out the bits using the <i>b</i>it elements.
  93244. + */
  93245. +typedef union host_grxsts_data {
  93246. + /** raw register data */
  93247. + uint32_t d32;
  93248. + /** register bits */
  93249. + struct {
  93250. + unsigned chnum:4;
  93251. + unsigned bcnt:11;
  93252. + unsigned dpid:2;
  93253. +
  93254. + unsigned pktsts:4;
  93255. +#define DWC_GRXSTS_PKTSTS_IN 0x2
  93256. +#define DWC_GRXSTS_PKTSTS_IN_XFER_COMP 0x3
  93257. +#define DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR 0x5
  93258. +#define DWC_GRXSTS_PKTSTS_CH_HALTED 0x7
  93259. +
  93260. + unsigned reserved21_31:11;
  93261. + } b;
  93262. +} host_grxsts_data_t;
  93263. +
  93264. +/**
  93265. + * This union represents the bit fields in the FIFO Size Registers (HPTXFSIZ,
  93266. + * GNPTXFSIZ, DPTXFSIZn, DIEPTXFn). Read the register into the <i>d32</i> element
  93267. + * then read out the bits using the <i>b</i>it elements.
  93268. + */
  93269. +typedef union fifosize_data {
  93270. + /** raw register data */
  93271. + uint32_t d32;
  93272. + /** register bits */
  93273. + struct {
  93274. + unsigned startaddr:16;
  93275. + unsigned depth:16;
  93276. + } b;
  93277. +} fifosize_data_t;
  93278. +
  93279. +/**
  93280. + * This union represents the bit fields in the Non-Periodic Transmit
  93281. + * FIFO/Queue Status Register (GNPTXSTS). Read the register into the
  93282. + * <i>d32</i> element then read out the bits using the <i>b</i>it
  93283. + * elements.
  93284. + */
  93285. +typedef union gnptxsts_data {
  93286. + /** raw register data */
  93287. + uint32_t d32;
  93288. + /** register bits */
  93289. + struct {
  93290. + unsigned nptxfspcavail:16;
  93291. + unsigned nptxqspcavail:8;
  93292. + /** Top of the Non-Periodic Transmit Request Queue
  93293. + * - bit 24 - Terminate (Last entry for the selected
  93294. + * channel/EP)
  93295. + * - bits 26:25 - Token Type
  93296. + * - 2'b00 - IN/OUT
  93297. + * - 2'b01 - Zero Length OUT
  93298. + * - 2'b10 - PING/Complete Split
  93299. + * - 2'b11 - Channel Halt
  93300. + * - bits 30:27 - Channel/EP Number
  93301. + */
  93302. + unsigned nptxqtop_terminate:1;
  93303. + unsigned nptxqtop_token:2;
  93304. + unsigned nptxqtop_chnep:4;
  93305. + unsigned reserved:1;
  93306. + } b;
  93307. +} gnptxsts_data_t;
  93308. +
  93309. +/**
  93310. + * This union represents the bit fields in the Transmit
  93311. + * FIFO Status Register (DTXFSTS). Read the register into the
  93312. + * <i>d32</i> element then read out the bits using the <i>b</i>it
  93313. + * elements.
  93314. + */
  93315. +typedef union dtxfsts_data {
  93316. + /** raw register data */
  93317. + uint32_t d32;
  93318. + /** register bits */
  93319. + struct {
  93320. + unsigned txfspcavail:16;
  93321. + unsigned reserved:16;
  93322. + } b;
  93323. +} dtxfsts_data_t;
  93324. +
  93325. +/**
  93326. + * This union represents the bit fields in the I2C Control Register
  93327. + * (I2CCTL). Read the register into the <i>d32</i> element then read out the
  93328. + * bits using the <i>b</i>it elements.
  93329. + */
  93330. +typedef union gi2cctl_data {
  93331. + /** raw register data */
  93332. + uint32_t d32;
  93333. + /** register bits */
  93334. + struct {
  93335. + unsigned rwdata:8;
  93336. + unsigned regaddr:8;
  93337. + unsigned addr:7;
  93338. + unsigned i2cen:1;
  93339. + unsigned ack:1;
  93340. + unsigned i2csuspctl:1;
  93341. + unsigned i2cdevaddr:2;
  93342. + unsigned i2cdatse0:1;
  93343. + unsigned reserved:1;
  93344. + unsigned rw:1;
  93345. + unsigned bsydne:1;
  93346. + } b;
  93347. +} gi2cctl_data_t;
  93348. +
  93349. +/**
  93350. + * This union represents the bit fields in the PHY Vendor Control Register
  93351. + * (GPVNDCTL). Read the register into the <i>d32</i> element then read out the
  93352. + * bits using the <i>b</i>it elements.
  93353. + */
  93354. +typedef union gpvndctl_data {
  93355. + /** raw register data */
  93356. + uint32_t d32;
  93357. + /** register bits */
  93358. + struct {
  93359. + unsigned regdata:8;
  93360. + unsigned vctrl:8;
  93361. + unsigned regaddr16_21:6;
  93362. + unsigned regwr:1;
  93363. + unsigned reserved23_24:2;
  93364. + unsigned newregreq:1;
  93365. + unsigned vstsbsy:1;
  93366. + unsigned vstsdone:1;
  93367. + unsigned reserved28_30:3;
  93368. + unsigned disulpidrvr:1;
  93369. + } b;
  93370. +} gpvndctl_data_t;
  93371. +
  93372. +/**
  93373. + * This union represents the bit fields in the General Purpose
  93374. + * Input/Output Register (GGPIO).
  93375. + * Read the register into the <i>d32</i> element then read out the
  93376. + * bits using the <i>b</i>it elements.
  93377. + */
  93378. +typedef union ggpio_data {
  93379. + /** raw register data */
  93380. + uint32_t d32;
  93381. + /** register bits */
  93382. + struct {
  93383. + unsigned gpi:16;
  93384. + unsigned gpo:16;
  93385. + } b;
  93386. +} ggpio_data_t;
  93387. +
  93388. +/**
  93389. + * This union represents the bit fields in the User ID Register
  93390. + * (GUID). Read the register into the <i>d32</i> element then read out the
  93391. + * bits using the <i>b</i>it elements.
  93392. + */
  93393. +typedef union guid_data {
  93394. + /** raw register data */
  93395. + uint32_t d32;
  93396. + /** register bits */
  93397. + struct {
  93398. + unsigned rwdata:32;
  93399. + } b;
  93400. +} guid_data_t;
  93401. +
  93402. +/**
  93403. + * This union represents the bit fields in the Synopsys ID Register
  93404. + * (GSNPSID). Read the register into the <i>d32</i> element then read out the
  93405. + * bits using the <i>b</i>it elements.
  93406. + */
  93407. +typedef union gsnpsid_data {
  93408. + /** raw register data */
  93409. + uint32_t d32;
  93410. + /** register bits */
  93411. + struct {
  93412. + unsigned rwdata:32;
  93413. + } b;
  93414. +} gsnpsid_data_t;
  93415. +
  93416. +/**
  93417. + * This union represents the bit fields in the User HW Config1
  93418. + * Register. Read the register into the <i>d32</i> element then read
  93419. + * out the bits using the <i>b</i>it elements.
  93420. + */
  93421. +typedef union hwcfg1_data {
  93422. + /** raw register data */
  93423. + uint32_t d32;
  93424. + /** register bits */
  93425. + struct {
  93426. + unsigned ep_dir0:2;
  93427. + unsigned ep_dir1:2;
  93428. + unsigned ep_dir2:2;
  93429. + unsigned ep_dir3:2;
  93430. + unsigned ep_dir4:2;
  93431. + unsigned ep_dir5:2;
  93432. + unsigned ep_dir6:2;
  93433. + unsigned ep_dir7:2;
  93434. + unsigned ep_dir8:2;
  93435. + unsigned ep_dir9:2;
  93436. + unsigned ep_dir10:2;
  93437. + unsigned ep_dir11:2;
  93438. + unsigned ep_dir12:2;
  93439. + unsigned ep_dir13:2;
  93440. + unsigned ep_dir14:2;
  93441. + unsigned ep_dir15:2;
  93442. + } b;
  93443. +} hwcfg1_data_t;
  93444. +
  93445. +/**
  93446. + * This union represents the bit fields in the User HW Config2
  93447. + * Register. Read the register into the <i>d32</i> element then read
  93448. + * out the bits using the <i>b</i>it elements.
  93449. + */
  93450. +typedef union hwcfg2_data {
  93451. + /** raw register data */
  93452. + uint32_t d32;
  93453. + /** register bits */
  93454. + struct {
  93455. + /* GHWCFG2 */
  93456. + unsigned op_mode:3;
  93457. +#define DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG 0
  93458. +#define DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG 1
  93459. +#define DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG 2
  93460. +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE 3
  93461. +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE 4
  93462. +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST 5
  93463. +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST 6
  93464. +
  93465. + unsigned architecture:2;
  93466. + unsigned point2point:1;
  93467. + unsigned hs_phy_type:2;
  93468. +#define DWC_HWCFG2_HS_PHY_TYPE_NOT_SUPPORTED 0
  93469. +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI 1
  93470. +#define DWC_HWCFG2_HS_PHY_TYPE_ULPI 2
  93471. +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI 3
  93472. +
  93473. + unsigned fs_phy_type:2;
  93474. + unsigned num_dev_ep:4;
  93475. + unsigned num_host_chan:4;
  93476. + unsigned perio_ep_supported:1;
  93477. + unsigned dynamic_fifo:1;
  93478. + unsigned multi_proc_int:1;
  93479. + unsigned reserved21:1;
  93480. + unsigned nonperio_tx_q_depth:2;
  93481. + unsigned host_perio_tx_q_depth:2;
  93482. + unsigned dev_token_q_depth:5;
  93483. + unsigned otg_enable_ic_usb:1;
  93484. + } b;
  93485. +} hwcfg2_data_t;
  93486. +
  93487. +/**
  93488. + * This union represents the bit fields in the User HW Config3
  93489. + * Register. Read the register into the <i>d32</i> element then read
  93490. + * out the bits using the <i>b</i>it elements.
  93491. + */
  93492. +typedef union hwcfg3_data {
  93493. + /** raw register data */
  93494. + uint32_t d32;
  93495. + /** register bits */
  93496. + struct {
  93497. + /* GHWCFG3 */
  93498. + unsigned xfer_size_cntr_width:4;
  93499. + unsigned packet_size_cntr_width:3;
  93500. + unsigned otg_func:1;
  93501. + unsigned i2c:1;
  93502. + unsigned vendor_ctrl_if:1;
  93503. + unsigned optional_features:1;
  93504. + unsigned synch_reset_type:1;
  93505. + unsigned adp_supp:1;
  93506. + unsigned otg_enable_hsic:1;
  93507. + unsigned bc_support:1;
  93508. + unsigned otg_lpm_en:1;
  93509. + unsigned dfifo_depth:16;
  93510. + } b;
  93511. +} hwcfg3_data_t;
  93512. +
  93513. +/**
  93514. + * This union represents the bit fields in the User HW Config4
  93515. + * Register. Read the register into the <i>d32</i> element then read
  93516. + * out the bits using the <i>b</i>it elements.
  93517. + */
  93518. +typedef union hwcfg4_data {
  93519. + /** raw register data */
  93520. + uint32_t d32;
  93521. + /** register bits */
  93522. + struct {
  93523. + unsigned num_dev_perio_in_ep:4;
  93524. + unsigned power_optimiz:1;
  93525. + unsigned min_ahb_freq:1;
  93526. + unsigned hiber:1;
  93527. + unsigned xhiber:1;
  93528. + unsigned reserved:6;
  93529. + unsigned utmi_phy_data_width:2;
  93530. + unsigned num_dev_mode_ctrl_ep:4;
  93531. + unsigned iddig_filt_en:1;
  93532. + unsigned vbus_valid_filt_en:1;
  93533. + unsigned a_valid_filt_en:1;
  93534. + unsigned b_valid_filt_en:1;
  93535. + unsigned session_end_filt_en:1;
  93536. + unsigned ded_fifo_en:1;
  93537. + unsigned num_in_eps:4;
  93538. + unsigned desc_dma:1;
  93539. + unsigned desc_dma_dyn:1;
  93540. + } b;
  93541. +} hwcfg4_data_t;
  93542. +
  93543. +/**
  93544. + * This union represents the bit fields of the Core LPM Configuration
  93545. + * Register (GLPMCFG). Set the bits using bit fields then write
  93546. + * the <i>d32</i> value to the register.
  93547. + */
  93548. +typedef union glpmctl_data {
  93549. + /** raw register data */
  93550. + uint32_t d32;
  93551. + /** register bits */
  93552. + struct {
  93553. + /** LPM-Capable (LPMCap) (Device and Host)
  93554. + * The application uses this bit to control
  93555. + * the DWC_otg core LPM capabilities.
  93556. + */
  93557. + unsigned lpm_cap_en:1;
  93558. + /** LPM response programmed by application (AppL1Res) (Device)
  93559. + * Handshake response to LPM token pre-programmed
  93560. + * by device application software.
  93561. + */
  93562. + unsigned appl_resp:1;
  93563. + /** Host Initiated Resume Duration (HIRD) (Device and Host)
  93564. + * In Host mode this field indicates the value of HIRD
  93565. + * to be sent in an LPM transaction.
  93566. + * In Device mode this field is updated with the
  93567. + * Received LPM Token HIRD bmAttribute
  93568. + * when an ACK/NYET/STALL response is sent
  93569. + * to an LPM transaction.
  93570. + */
  93571. + unsigned hird:4;
  93572. + /** RemoteWakeEnable (bRemoteWake) (Device and Host)
  93573. + * In Host mode this bit indicates the value of remote
  93574. + * wake up to be sent in wIndex field of LPM transaction.
  93575. + * In Device mode this field is updated with the
  93576. + * Received LPM Token bRemoteWake bmAttribute
  93577. + * when an ACK/NYET/STALL response is sent
  93578. + * to an LPM transaction.
  93579. + */
  93580. + unsigned rem_wkup_en:1;
  93581. + /** Enable utmi_sleep_n (EnblSlpM) (Device and Host)
  93582. + * The application uses this bit to control
  93583. + * the utmi_sleep_n assertion to the PHY when in L1 state.
  93584. + */
  93585. + unsigned en_utmi_sleep:1;
  93586. + /** HIRD Threshold (HIRD_Thres) (Device and Host)
  93587. + */
  93588. + unsigned hird_thres:5;
  93589. + /** LPM Response (CoreL1Res) (Device and Host)
  93590. + * In Host mode this bit contains handsake response to
  93591. + * LPM transaction.
  93592. + * In Device mode the response of the core to
  93593. + * LPM transaction received is reflected in these two bits.
  93594. + - 0x0 : ERROR (No handshake response)
  93595. + - 0x1 : STALL
  93596. + - 0x2 : NYET
  93597. + - 0x3 : ACK
  93598. + */
  93599. + unsigned lpm_resp:2;
  93600. + /** Port Sleep Status (SlpSts) (Device and Host)
  93601. + * This bit is set as long as a Sleep condition
  93602. + * is present on the USB bus.
  93603. + */
  93604. + unsigned prt_sleep_sts:1;
  93605. + /** Sleep State Resume OK (L1ResumeOK) (Device and Host)
  93606. + * Indicates that the application or host
  93607. + * can start resume from Sleep state.
  93608. + */
  93609. + unsigned sleep_state_resumeok:1;
  93610. + /** LPM channel Index (LPM_Chnl_Indx) (Host)
  93611. + * The channel number on which the LPM transaction
  93612. + * has to be applied while sending
  93613. + * an LPM transaction to the local device.
  93614. + */
  93615. + unsigned lpm_chan_index:4;
  93616. + /** LPM Retry Count (LPM_Retry_Cnt) (Host)
  93617. + * Number host retries that would be performed
  93618. + * if the device response was not valid response.
  93619. + */
  93620. + unsigned retry_count:3;
  93621. + /** Send LPM Transaction (SndLPM) (Host)
  93622. + * When set by application software,
  93623. + * an LPM transaction containing two tokens
  93624. + * is sent.
  93625. + */
  93626. + unsigned send_lpm:1;
  93627. + /** LPM Retry status (LPM_RetryCnt_Sts) (Host)
  93628. + * Number of LPM Host Retries still remaining
  93629. + * to be transmitted for the current LPM sequence
  93630. + */
  93631. + unsigned retry_count_sts:3;
  93632. + unsigned reserved28_29:2;
  93633. + /** In host mode once this bit is set, the host
  93634. + * configures to drive the HSIC Idle state on the bus.
  93635. + * It then waits for the device to initiate the Connect sequence.
  93636. + * In device mode once this bit is set, the device waits for
  93637. + * the HSIC Idle line state on the bus. Upon receving the Idle
  93638. + * line state, it initiates the HSIC Connect sequence.
  93639. + */
  93640. + unsigned hsic_connect:1;
  93641. + /** This bit overrides and functionally inverts
  93642. + * the if_select_hsic input port signal.
  93643. + */
  93644. + unsigned inv_sel_hsic:1;
  93645. + } b;
  93646. +} glpmcfg_data_t;
  93647. +
  93648. +/**
  93649. + * This union represents the bit fields of the Core ADP Timer, Control and
  93650. + * Status Register (ADPTIMCTLSTS). Set the bits using bit fields then write
  93651. + * the <i>d32</i> value to the register.
  93652. + */
  93653. +typedef union adpctl_data {
  93654. + /** raw register data */
  93655. + uint32_t d32;
  93656. + /** register bits */
  93657. + struct {
  93658. + /** Probe Discharge (PRB_DSCHG)
  93659. + * These bits set the times for TADP_DSCHG.
  93660. + * These bits are defined as follows:
  93661. + * 2'b00 - 4 msec
  93662. + * 2'b01 - 8 msec
  93663. + * 2'b10 - 16 msec
  93664. + * 2'b11 - 32 msec
  93665. + */
  93666. + unsigned prb_dschg:2;
  93667. + /** Probe Delta (PRB_DELTA)
  93668. + * These bits set the resolution for RTIM value.
  93669. + * The bits are defined in units of 32 kHz clock cycles as follows:
  93670. + * 2'b00 - 1 cycles
  93671. + * 2'b01 - 2 cycles
  93672. + * 2'b10 - 3 cycles
  93673. + * 2'b11 - 4 cycles
  93674. + * For example if this value is chosen to 2'b01, it means that RTIM
  93675. + * increments for every 3(three) 32Khz clock cycles.
  93676. + */
  93677. + unsigned prb_delta:2;
  93678. + /** Probe Period (PRB_PER)
  93679. + * These bits sets the TADP_PRD as shown in Figure 4 as follows:
  93680. + * 2'b00 - 0.625 to 0.925 sec (typical 0.775 sec)
  93681. + * 2'b01 - 1.25 to 1.85 sec (typical 1.55 sec)
  93682. + * 2'b10 - 1.9 to 2.6 sec (typical 2.275 sec)
  93683. + * 2'b11 - Reserved
  93684. + */
  93685. + unsigned prb_per:2;
  93686. + /** These bits capture the latest time it took for VBUS to ramp from
  93687. + * VADP_SINK to VADP_PRB.
  93688. + * 0x000 - 1 cycles
  93689. + * 0x001 - 2 cycles
  93690. + * 0x002 - 3 cycles
  93691. + * etc
  93692. + * 0x7FF - 2048 cycles
  93693. + * A time of 1024 cycles at 32 kHz corresponds to a time of 32 msec.
  93694. + */
  93695. + unsigned rtim:11;
  93696. + /** Enable Probe (EnaPrb)
  93697. + * When programmed to 1'b1, the core performs a probe operation.
  93698. + * This bit is valid only if OTG_Ver = 1'b1.
  93699. + */
  93700. + unsigned enaprb:1;
  93701. + /** Enable Sense (EnaSns)
  93702. + * When programmed to 1'b1, the core performs a Sense operation.
  93703. + * This bit is valid only if OTG_Ver = 1'b1.
  93704. + */
  93705. + unsigned enasns:1;
  93706. + /** ADP Reset (ADPRes)
  93707. + * When set, ADP controller is reset.
  93708. + * This bit is valid only if OTG_Ver = 1'b1.
  93709. + */
  93710. + unsigned adpres:1;
  93711. + /** ADP Enable (ADPEn)
  93712. + * When set, the core performs either ADP probing or sensing
  93713. + * based on EnaPrb or EnaSns.
  93714. + * This bit is valid only if OTG_Ver = 1'b1.
  93715. + */
  93716. + unsigned adpen:1;
  93717. + /** ADP Probe Interrupt (ADP_PRB_INT)
  93718. + * When this bit is set, it means that the VBUS
  93719. + * voltage is greater than VADP_PRB or VADP_PRB is reached.
  93720. + * This bit is valid only if OTG_Ver = 1'b1.
  93721. + */
  93722. + unsigned adp_prb_int:1;
  93723. + /**
  93724. + * ADP Sense Interrupt (ADP_SNS_INT)
  93725. + * When this bit is set, it means that the VBUS voltage is greater than
  93726. + * VADP_SNS value or VADP_SNS is reached.
  93727. + * This bit is valid only if OTG_Ver = 1'b1.
  93728. + */
  93729. + unsigned adp_sns_int:1;
  93730. + /** ADP Tomeout Interrupt (ADP_TMOUT_INT)
  93731. + * This bit is relevant only for an ADP probe.
  93732. + * When this bit is set, it means that the ramp time has
  93733. + * completed ie ADPCTL.RTIM has reached its terminal value
  93734. + * of 0x7FF. This is a debug feature that allows software
  93735. + * to read the ramp time after each cycle.
  93736. + * This bit is valid only if OTG_Ver = 1'b1.
  93737. + */
  93738. + unsigned adp_tmout_int:1;
  93739. + /** ADP Probe Interrupt Mask (ADP_PRB_INT_MSK)
  93740. + * When this bit is set, it unmasks the interrupt due to ADP_PRB_INT.
  93741. + * This bit is valid only if OTG_Ver = 1'b1.
  93742. + */
  93743. + unsigned adp_prb_int_msk:1;
  93744. + /** ADP Sense Interrupt Mask (ADP_SNS_INT_MSK)
  93745. + * When this bit is set, it unmasks the interrupt due to ADP_SNS_INT.
  93746. + * This bit is valid only if OTG_Ver = 1'b1.
  93747. + */
  93748. + unsigned adp_sns_int_msk:1;
  93749. + /** ADP Timoeout Interrupt Mask (ADP_TMOUT_MSK)
  93750. + * When this bit is set, it unmasks the interrupt due to ADP_TMOUT_INT.
  93751. + * This bit is valid only if OTG_Ver = 1'b1.
  93752. + */
  93753. + unsigned adp_tmout_int_msk:1;
  93754. + /** Access Request
  93755. + * 2'b00 - Read/Write Valid (updated by the core)
  93756. + * 2'b01 - Read
  93757. + * 2'b00 - Write
  93758. + * 2'b00 - Reserved
  93759. + */
  93760. + unsigned ar:2;
  93761. + /** Reserved */
  93762. + unsigned reserved29_31:3;
  93763. + } b;
  93764. +} adpctl_data_t;
  93765. +
  93766. +////////////////////////////////////////////
  93767. +// Device Registers
  93768. +/**
  93769. + * Device Global Registers. <i>Offsets 800h-BFFh</i>
  93770. + *
  93771. + * The following structures define the size and relative field offsets
  93772. + * for the Device Mode Registers.
  93773. + *
  93774. + * <i>These registers are visible only in Device mode and must not be
  93775. + * accessed in Host mode, as the results are unknown.</i>
  93776. + */
  93777. +typedef struct dwc_otg_dev_global_regs {
  93778. + /** Device Configuration Register. <i>Offset 800h</i> */
  93779. + volatile uint32_t dcfg;
  93780. + /** Device Control Register. <i>Offset: 804h</i> */
  93781. + volatile uint32_t dctl;
  93782. + /** Device Status Register (Read Only). <i>Offset: 808h</i> */
  93783. + volatile uint32_t dsts;
  93784. + /** Reserved. <i>Offset: 80Ch</i> */
  93785. + uint32_t unused;
  93786. + /** Device IN Endpoint Common Interrupt Mask
  93787. + * Register. <i>Offset: 810h</i> */
  93788. + volatile uint32_t diepmsk;
  93789. + /** Device OUT Endpoint Common Interrupt Mask
  93790. + * Register. <i>Offset: 814h</i> */
  93791. + volatile uint32_t doepmsk;
  93792. + /** Device All Endpoints Interrupt Register. <i>Offset: 818h</i> */
  93793. + volatile uint32_t daint;
  93794. + /** Device All Endpoints Interrupt Mask Register. <i>Offset:
  93795. + * 81Ch</i> */
  93796. + volatile uint32_t daintmsk;
  93797. + /** Device IN Token Queue Read Register-1 (Read Only).
  93798. + * <i>Offset: 820h</i> */
  93799. + volatile uint32_t dtknqr1;
  93800. + /** Device IN Token Queue Read Register-2 (Read Only).
  93801. + * <i>Offset: 824h</i> */
  93802. + volatile uint32_t dtknqr2;
  93803. + /** Device VBUS discharge Register. <i>Offset: 828h</i> */
  93804. + volatile uint32_t dvbusdis;
  93805. + /** Device VBUS Pulse Register. <i>Offset: 82Ch</i> */
  93806. + volatile uint32_t dvbuspulse;
  93807. + /** Device IN Token Queue Read Register-3 (Read Only). /
  93808. + * Device Thresholding control register (Read/Write)
  93809. + * <i>Offset: 830h</i> */
  93810. + volatile uint32_t dtknqr3_dthrctl;
  93811. + /** Device IN Token Queue Read Register-4 (Read Only). /
  93812. + * Device IN EPs empty Inr. Mask Register (Read/Write)
  93813. + * <i>Offset: 834h</i> */
  93814. + volatile uint32_t dtknqr4_fifoemptymsk;
  93815. + /** Device Each Endpoint Interrupt Register (Read Only). /
  93816. + * <i>Offset: 838h</i> */
  93817. + volatile uint32_t deachint;
  93818. + /** Device Each Endpoint Interrupt mask Register (Read/Write). /
  93819. + * <i>Offset: 83Ch</i> */
  93820. + volatile uint32_t deachintmsk;
  93821. + /** Device Each In Endpoint Interrupt mask Register (Read/Write). /
  93822. + * <i>Offset: 840h</i> */
  93823. + volatile uint32_t diepeachintmsk[MAX_EPS_CHANNELS];
  93824. + /** Device Each Out Endpoint Interrupt mask Register (Read/Write). /
  93825. + * <i>Offset: 880h</i> */
  93826. + volatile uint32_t doepeachintmsk[MAX_EPS_CHANNELS];
  93827. +} dwc_otg_device_global_regs_t;
  93828. +
  93829. +/**
  93830. + * This union represents the bit fields in the Device Configuration
  93831. + * Register. Read the register into the <i>d32</i> member then
  93832. + * set/clear the bits using the <i>b</i>it elements. Write the
  93833. + * <i>d32</i> member to the dcfg register.
  93834. + */
  93835. +typedef union dcfg_data {
  93836. + /** raw register data */
  93837. + uint32_t d32;
  93838. + /** register bits */
  93839. + struct {
  93840. + /** Device Speed */
  93841. + unsigned devspd:2;
  93842. + /** Non Zero Length Status OUT Handshake */
  93843. + unsigned nzstsouthshk:1;
  93844. +#define DWC_DCFG_SEND_STALL 1
  93845. +
  93846. + unsigned ena32khzs:1;
  93847. + /** Device Addresses */
  93848. + unsigned devaddr:7;
  93849. + /** Periodic Frame Interval */
  93850. + unsigned perfrint:2;
  93851. +#define DWC_DCFG_FRAME_INTERVAL_80 0
  93852. +#define DWC_DCFG_FRAME_INTERVAL_85 1
  93853. +#define DWC_DCFG_FRAME_INTERVAL_90 2
  93854. +#define DWC_DCFG_FRAME_INTERVAL_95 3
  93855. +
  93856. + /** Enable Device OUT NAK for bulk in DDMA mode */
  93857. + unsigned endevoutnak:1;
  93858. +
  93859. + unsigned reserved14_17:4;
  93860. + /** In Endpoint Mis-match count */
  93861. + unsigned epmscnt:5;
  93862. + /** Enable Descriptor DMA in Device mode */
  93863. + unsigned descdma:1;
  93864. + unsigned perschintvl:2;
  93865. + unsigned resvalid:6;
  93866. + } b;
  93867. +} dcfg_data_t;
  93868. +
  93869. +/**
  93870. + * This union represents the bit fields in the Device Control
  93871. + * Register. Read the register into the <i>d32</i> member then
  93872. + * set/clear the bits using the <i>b</i>it elements.
  93873. + */
  93874. +typedef union dctl_data {
  93875. + /** raw register data */
  93876. + uint32_t d32;
  93877. + /** register bits */
  93878. + struct {
  93879. + /** Remote Wakeup */
  93880. + unsigned rmtwkupsig:1;
  93881. + /** Soft Disconnect */
  93882. + unsigned sftdiscon:1;
  93883. + /** Global Non-Periodic IN NAK Status */
  93884. + unsigned gnpinnaksts:1;
  93885. + /** Global OUT NAK Status */
  93886. + unsigned goutnaksts:1;
  93887. + /** Test Control */
  93888. + unsigned tstctl:3;
  93889. + /** Set Global Non-Periodic IN NAK */
  93890. + unsigned sgnpinnak:1;
  93891. + /** Clear Global Non-Periodic IN NAK */
  93892. + unsigned cgnpinnak:1;
  93893. + /** Set Global OUT NAK */
  93894. + unsigned sgoutnak:1;
  93895. + /** Clear Global OUT NAK */
  93896. + unsigned cgoutnak:1;
  93897. + /** Power-On Programming Done */
  93898. + unsigned pwronprgdone:1;
  93899. + /** Reserved */
  93900. + unsigned reserved:1;
  93901. + /** Global Multi Count */
  93902. + unsigned gmc:2;
  93903. + /** Ignore Frame Number for ISOC EPs */
  93904. + unsigned ifrmnum:1;
  93905. + /** NAK on Babble */
  93906. + unsigned nakonbble:1;
  93907. + /** Enable Continue on BNA */
  93908. + unsigned encontonbna:1;
  93909. +
  93910. + unsigned reserved18_31:14;
  93911. + } b;
  93912. +} dctl_data_t;
  93913. +
  93914. +/**
  93915. + * This union represents the bit fields in the Device Status
  93916. + * Register. Read the register into the <i>d32</i> member then
  93917. + * set/clear the bits using the <i>b</i>it elements.
  93918. + */
  93919. +typedef union dsts_data {
  93920. + /** raw register data */
  93921. + uint32_t d32;
  93922. + /** register bits */
  93923. + struct {
  93924. + /** Suspend Status */
  93925. + unsigned suspsts:1;
  93926. + /** Enumerated Speed */
  93927. + unsigned enumspd:2;
  93928. +#define DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ 0
  93929. +#define DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ 1
  93930. +#define DWC_DSTS_ENUMSPD_LS_PHY_6MHZ 2
  93931. +#define DWC_DSTS_ENUMSPD_FS_PHY_48MHZ 3
  93932. + /** Erratic Error */
  93933. + unsigned errticerr:1;
  93934. + unsigned reserved4_7:4;
  93935. + /** Frame or Microframe Number of the received SOF */
  93936. + unsigned soffn:14;
  93937. + unsigned reserved22_31:10;
  93938. + } b;
  93939. +} dsts_data_t;
  93940. +
  93941. +/**
  93942. + * This union represents the bit fields in the Device IN EP Interrupt
  93943. + * Register and the Device IN EP Common Mask Register.
  93944. + *
  93945. + * - Read the register into the <i>d32</i> member then set/clear the
  93946. + * bits using the <i>b</i>it elements.
  93947. + */
  93948. +typedef union diepint_data {
  93949. + /** raw register data */
  93950. + uint32_t d32;
  93951. + /** register bits */
  93952. + struct {
  93953. + /** Transfer complete mask */
  93954. + unsigned xfercompl:1;
  93955. + /** Endpoint disable mask */
  93956. + unsigned epdisabled:1;
  93957. + /** AHB Error mask */
  93958. + unsigned ahberr:1;
  93959. + /** TimeOUT Handshake mask (non-ISOC EPs) */
  93960. + unsigned timeout:1;
  93961. + /** IN Token received with TxF Empty mask */
  93962. + unsigned intktxfemp:1;
  93963. + /** IN Token Received with EP mismatch mask */
  93964. + unsigned intknepmis:1;
  93965. + /** IN Endpoint NAK Effective mask */
  93966. + unsigned inepnakeff:1;
  93967. + /** Reserved */
  93968. + unsigned emptyintr:1;
  93969. +
  93970. + unsigned txfifoundrn:1;
  93971. +
  93972. + /** BNA Interrupt mask */
  93973. + unsigned bna:1;
  93974. +
  93975. + unsigned reserved10_12:3;
  93976. + /** BNA Interrupt mask */
  93977. + unsigned nak:1;
  93978. +
  93979. + unsigned reserved14_31:18;
  93980. + } b;
  93981. +} diepint_data_t;
  93982. +
  93983. +/**
  93984. + * This union represents the bit fields in the Device IN EP
  93985. + * Common/Dedicated Interrupt Mask Register.
  93986. + */
  93987. +typedef union diepint_data diepmsk_data_t;
  93988. +
  93989. +/**
  93990. + * This union represents the bit fields in the Device OUT EP Interrupt
  93991. + * Registerand Device OUT EP Common Interrupt Mask Register.
  93992. + *
  93993. + * - Read the register into the <i>d32</i> member then set/clear the
  93994. + * bits using the <i>b</i>it elements.
  93995. + */
  93996. +typedef union doepint_data {
  93997. + /** raw register data */
  93998. + uint32_t d32;
  93999. + /** register bits */
  94000. + struct {
  94001. + /** Transfer complete */
  94002. + unsigned xfercompl:1;
  94003. + /** Endpoint disable */
  94004. + unsigned epdisabled:1;
  94005. + /** AHB Error */
  94006. + unsigned ahberr:1;
  94007. + /** Setup Phase Done (contorl EPs) */
  94008. + unsigned setup:1;
  94009. + /** OUT Token Received when Endpoint Disabled */
  94010. + unsigned outtknepdis:1;
  94011. +
  94012. + unsigned stsphsercvd:1;
  94013. + /** Back-to-Back SETUP Packets Received */
  94014. + unsigned back2backsetup:1;
  94015. +
  94016. + unsigned reserved7:1;
  94017. + /** OUT packet Error */
  94018. + unsigned outpkterr:1;
  94019. + /** BNA Interrupt */
  94020. + unsigned bna:1;
  94021. +
  94022. + unsigned reserved10:1;
  94023. + /** Packet Drop Status */
  94024. + unsigned pktdrpsts:1;
  94025. + /** Babble Interrupt */
  94026. + unsigned babble:1;
  94027. + /** NAK Interrupt */
  94028. + unsigned nak:1;
  94029. + /** NYET Interrupt */
  94030. + unsigned nyet:1;
  94031. + /** Bit indicating setup packet received */
  94032. + unsigned sr:1;
  94033. +
  94034. + unsigned reserved16_31:16;
  94035. + } b;
  94036. +} doepint_data_t;
  94037. +
  94038. +/**
  94039. + * This union represents the bit fields in the Device OUT EP
  94040. + * Common/Dedicated Interrupt Mask Register.
  94041. + */
  94042. +typedef union doepint_data doepmsk_data_t;
  94043. +
  94044. +/**
  94045. + * This union represents the bit fields in the Device All EP Interrupt
  94046. + * and Mask Registers.
  94047. + * - Read the register into the <i>d32</i> member then set/clear the
  94048. + * bits using the <i>b</i>it elements.
  94049. + */
  94050. +typedef union daint_data {
  94051. + /** raw register data */
  94052. + uint32_t d32;
  94053. + /** register bits */
  94054. + struct {
  94055. + /** IN Endpoint bits */
  94056. + unsigned in:16;
  94057. + /** OUT Endpoint bits */
  94058. + unsigned out:16;
  94059. + } ep;
  94060. + struct {
  94061. + /** IN Endpoint bits */
  94062. + unsigned inep0:1;
  94063. + unsigned inep1:1;
  94064. + unsigned inep2:1;
  94065. + unsigned inep3:1;
  94066. + unsigned inep4:1;
  94067. + unsigned inep5:1;
  94068. + unsigned inep6:1;
  94069. + unsigned inep7:1;
  94070. + unsigned inep8:1;
  94071. + unsigned inep9:1;
  94072. + unsigned inep10:1;
  94073. + unsigned inep11:1;
  94074. + unsigned inep12:1;
  94075. + unsigned inep13:1;
  94076. + unsigned inep14:1;
  94077. + unsigned inep15:1;
  94078. + /** OUT Endpoint bits */
  94079. + unsigned outep0:1;
  94080. + unsigned outep1:1;
  94081. + unsigned outep2:1;
  94082. + unsigned outep3:1;
  94083. + unsigned outep4:1;
  94084. + unsigned outep5:1;
  94085. + unsigned outep6:1;
  94086. + unsigned outep7:1;
  94087. + unsigned outep8:1;
  94088. + unsigned outep9:1;
  94089. + unsigned outep10:1;
  94090. + unsigned outep11:1;
  94091. + unsigned outep12:1;
  94092. + unsigned outep13:1;
  94093. + unsigned outep14:1;
  94094. + unsigned outep15:1;
  94095. + } b;
  94096. +} daint_data_t;
  94097. +
  94098. +/**
  94099. + * This union represents the bit fields in the Device IN Token Queue
  94100. + * Read Registers.
  94101. + * - Read the register into the <i>d32</i> member.
  94102. + * - READ-ONLY Register
  94103. + */
  94104. +typedef union dtknq1_data {
  94105. + /** raw register data */
  94106. + uint32_t d32;
  94107. + /** register bits */
  94108. + struct {
  94109. + /** In Token Queue Write Pointer */
  94110. + unsigned intknwptr:5;
  94111. + /** Reserved */
  94112. + unsigned reserved05_06:2;
  94113. + /** write pointer has wrapped. */
  94114. + unsigned wrap_bit:1;
  94115. + /** EP Numbers of IN Tokens 0 ... 4 */
  94116. + unsigned epnums0_5:24;
  94117. + } b;
  94118. +} dtknq1_data_t;
  94119. +
  94120. +/**
  94121. + * This union represents Threshold control Register
  94122. + * - Read and write the register into the <i>d32</i> member.
  94123. + * - READ-WRITABLE Register
  94124. + */
  94125. +typedef union dthrctl_data {
  94126. + /** raw register data */
  94127. + uint32_t d32;
  94128. + /** register bits */
  94129. + struct {
  94130. + /** non ISO Tx Thr. Enable */
  94131. + unsigned non_iso_thr_en:1;
  94132. + /** ISO Tx Thr. Enable */
  94133. + unsigned iso_thr_en:1;
  94134. + /** Tx Thr. Length */
  94135. + unsigned tx_thr_len:9;
  94136. + /** AHB Threshold ratio */
  94137. + unsigned ahb_thr_ratio:2;
  94138. + /** Reserved */
  94139. + unsigned reserved13_15:3;
  94140. + /** Rx Thr. Enable */
  94141. + unsigned rx_thr_en:1;
  94142. + /** Rx Thr. Length */
  94143. + unsigned rx_thr_len:9;
  94144. + unsigned reserved26:1;
  94145. + /** Arbiter Parking Enable*/
  94146. + unsigned arbprken:1;
  94147. + /** Reserved */
  94148. + unsigned reserved28_31:4;
  94149. + } b;
  94150. +} dthrctl_data_t;
  94151. +
  94152. +/**
  94153. + * Device Logical IN Endpoint-Specific Registers. <i>Offsets
  94154. + * 900h-AFCh</i>
  94155. + *
  94156. + * There will be one set of endpoint registers per logical endpoint
  94157. + * implemented.
  94158. + *
  94159. + * <i>These registers are visible only in Device mode and must not be
  94160. + * accessed in Host mode, as the results are unknown.</i>
  94161. + */
  94162. +typedef struct dwc_otg_dev_in_ep_regs {
  94163. + /** Device IN Endpoint Control Register. <i>Offset:900h +
  94164. + * (ep_num * 20h) + 00h</i> */
  94165. + volatile uint32_t diepctl;
  94166. + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 04h</i> */
  94167. + uint32_t reserved04;
  94168. + /** Device IN Endpoint Interrupt Register. <i>Offset:900h +
  94169. + * (ep_num * 20h) + 08h</i> */
  94170. + volatile uint32_t diepint;
  94171. + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 0Ch</i> */
  94172. + uint32_t reserved0C;
  94173. + /** Device IN Endpoint Transfer Size
  94174. + * Register. <i>Offset:900h + (ep_num * 20h) + 10h</i> */
  94175. + volatile uint32_t dieptsiz;
  94176. + /** Device IN Endpoint DMA Address Register. <i>Offset:900h +
  94177. + * (ep_num * 20h) + 14h</i> */
  94178. + volatile uint32_t diepdma;
  94179. + /** Device IN Endpoint Transmit FIFO Status Register. <i>Offset:900h +
  94180. + * (ep_num * 20h) + 18h</i> */
  94181. + volatile uint32_t dtxfsts;
  94182. + /** Device IN Endpoint DMA Buffer Register. <i>Offset:900h +
  94183. + * (ep_num * 20h) + 1Ch</i> */
  94184. + volatile uint32_t diepdmab;
  94185. +} dwc_otg_dev_in_ep_regs_t;
  94186. +
  94187. +/**
  94188. + * Device Logical OUT Endpoint-Specific Registers. <i>Offsets:
  94189. + * B00h-CFCh</i>
  94190. + *
  94191. + * There will be one set of endpoint registers per logical endpoint
  94192. + * implemented.
  94193. + *
  94194. + * <i>These registers are visible only in Device mode and must not be
  94195. + * accessed in Host mode, as the results are unknown.</i>
  94196. + */
  94197. +typedef struct dwc_otg_dev_out_ep_regs {
  94198. + /** Device OUT Endpoint Control Register. <i>Offset:B00h +
  94199. + * (ep_num * 20h) + 00h</i> */
  94200. + volatile uint32_t doepctl;
  94201. + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 04h</i> */
  94202. + uint32_t reserved04;
  94203. + /** Device OUT Endpoint Interrupt Register. <i>Offset:B00h +
  94204. + * (ep_num * 20h) + 08h</i> */
  94205. + volatile uint32_t doepint;
  94206. + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 0Ch</i> */
  94207. + uint32_t reserved0C;
  94208. + /** Device OUT Endpoint Transfer Size Register. <i>Offset:
  94209. + * B00h + (ep_num * 20h) + 10h</i> */
  94210. + volatile uint32_t doeptsiz;
  94211. + /** Device OUT Endpoint DMA Address Register. <i>Offset:B00h
  94212. + * + (ep_num * 20h) + 14h</i> */
  94213. + volatile uint32_t doepdma;
  94214. + /** Reserved. <i>Offset:B00h + * (ep_num * 20h) + 18h</i> */
  94215. + uint32_t unused;
  94216. + /** Device OUT Endpoint DMA Buffer Register. <i>Offset:B00h
  94217. + * + (ep_num * 20h) + 1Ch</i> */
  94218. + uint32_t doepdmab;
  94219. +} dwc_otg_dev_out_ep_regs_t;
  94220. +
  94221. +/**
  94222. + * This union represents the bit fields in the Device EP Control
  94223. + * Register. Read the register into the <i>d32</i> member then
  94224. + * set/clear the bits using the <i>b</i>it elements.
  94225. + */
  94226. +typedef union depctl_data {
  94227. + /** raw register data */
  94228. + uint32_t d32;
  94229. + /** register bits */
  94230. + struct {
  94231. + /** Maximum Packet Size
  94232. + * IN/OUT EPn
  94233. + * IN/OUT EP0 - 2 bits
  94234. + * 2'b00: 64 Bytes
  94235. + * 2'b01: 32
  94236. + * 2'b10: 16
  94237. + * 2'b11: 8 */
  94238. + unsigned mps:11;
  94239. +#define DWC_DEP0CTL_MPS_64 0
  94240. +#define DWC_DEP0CTL_MPS_32 1
  94241. +#define DWC_DEP0CTL_MPS_16 2
  94242. +#define DWC_DEP0CTL_MPS_8 3
  94243. +
  94244. + /** Next Endpoint
  94245. + * IN EPn/IN EP0
  94246. + * OUT EPn/OUT EP0 - reserved */
  94247. + unsigned nextep:4;
  94248. +
  94249. + /** USB Active Endpoint */
  94250. + unsigned usbactep:1;
  94251. +
  94252. + /** Endpoint DPID (INTR/Bulk IN and OUT endpoints)
  94253. + * This field contains the PID of the packet going to
  94254. + * be received or transmitted on this endpoint. The
  94255. + * application should program the PID of the first
  94256. + * packet going to be received or transmitted on this
  94257. + * endpoint , after the endpoint is
  94258. + * activated. Application use the SetD1PID and
  94259. + * SetD0PID fields of this register to program either
  94260. + * D0 or D1 PID.
  94261. + *
  94262. + * The encoding for this field is
  94263. + * - 0: D0
  94264. + * - 1: D1
  94265. + */
  94266. + unsigned dpid:1;
  94267. +
  94268. + /** NAK Status */
  94269. + unsigned naksts:1;
  94270. +
  94271. + /** Endpoint Type
  94272. + * 2'b00: Control
  94273. + * 2'b01: Isochronous
  94274. + * 2'b10: Bulk
  94275. + * 2'b11: Interrupt */
  94276. + unsigned eptype:2;
  94277. +
  94278. + /** Snoop Mode
  94279. + * OUT EPn/OUT EP0
  94280. + * IN EPn/IN EP0 - reserved */
  94281. + unsigned snp:1;
  94282. +
  94283. + /** Stall Handshake */
  94284. + unsigned stall:1;
  94285. +
  94286. + /** Tx Fifo Number
  94287. + * IN EPn/IN EP0
  94288. + * OUT EPn/OUT EP0 - reserved */
  94289. + unsigned txfnum:4;
  94290. +
  94291. + /** Clear NAK */
  94292. + unsigned cnak:1;
  94293. + /** Set NAK */
  94294. + unsigned snak:1;
  94295. + /** Set DATA0 PID (INTR/Bulk IN and OUT endpoints)
  94296. + * Writing to this field sets the Endpoint DPID (DPID)
  94297. + * field in this register to DATA0. Set Even
  94298. + * (micro)frame (SetEvenFr) (ISO IN and OUT Endpoints)
  94299. + * Writing to this field sets the Even/Odd
  94300. + * (micro)frame (EO_FrNum) field to even (micro)
  94301. + * frame.
  94302. + */
  94303. + unsigned setd0pid:1;
  94304. + /** Set DATA1 PID (INTR/Bulk IN and OUT endpoints)
  94305. + * Writing to this field sets the Endpoint DPID (DPID)
  94306. + * field in this register to DATA1 Set Odd
  94307. + * (micro)frame (SetOddFr) (ISO IN and OUT Endpoints)
  94308. + * Writing to this field sets the Even/Odd
  94309. + * (micro)frame (EO_FrNum) field to odd (micro) frame.
  94310. + */
  94311. + unsigned setd1pid:1;
  94312. +
  94313. + /** Endpoint Disable */
  94314. + unsigned epdis:1;
  94315. + /** Endpoint Enable */
  94316. + unsigned epena:1;
  94317. + } b;
  94318. +} depctl_data_t;
  94319. +
  94320. +/**
  94321. + * This union represents the bit fields in the Device EP Transfer
  94322. + * Size Register. Read the register into the <i>d32</i> member then
  94323. + * set/clear the bits using the <i>b</i>it elements.
  94324. + */
  94325. +typedef union deptsiz_data {
  94326. + /** raw register data */
  94327. + uint32_t d32;
  94328. + /** register bits */
  94329. + struct {
  94330. + /** Transfer size */
  94331. + unsigned xfersize:19;
  94332. +/** Max packet count for EP (pow(2,10)-1) */
  94333. +#define MAX_PKT_CNT 1023
  94334. + /** Packet Count */
  94335. + unsigned pktcnt:10;
  94336. + /** Multi Count - Periodic IN endpoints */
  94337. + unsigned mc:2;
  94338. + unsigned reserved:1;
  94339. + } b;
  94340. +} deptsiz_data_t;
  94341. +
  94342. +/**
  94343. + * This union represents the bit fields in the Device EP 0 Transfer
  94344. + * Size Register. Read the register into the <i>d32</i> member then
  94345. + * set/clear the bits using the <i>b</i>it elements.
  94346. + */
  94347. +typedef union deptsiz0_data {
  94348. + /** raw register data */
  94349. + uint32_t d32;
  94350. + /** register bits */
  94351. + struct {
  94352. + /** Transfer size */
  94353. + unsigned xfersize:7;
  94354. + /** Reserved */
  94355. + unsigned reserved7_18:12;
  94356. + /** Packet Count */
  94357. + unsigned pktcnt:2;
  94358. + /** Reserved */
  94359. + unsigned reserved21_28:8;
  94360. + /**Setup Packet Count (DOEPTSIZ0 Only) */
  94361. + unsigned supcnt:2;
  94362. + unsigned reserved31;
  94363. + } b;
  94364. +} deptsiz0_data_t;
  94365. +
  94366. +/////////////////////////////////////////////////
  94367. +// DMA Descriptor Specific Structures
  94368. +//
  94369. +
  94370. +/** Buffer status definitions */
  94371. +
  94372. +#define BS_HOST_READY 0x0
  94373. +#define BS_DMA_BUSY 0x1
  94374. +#define BS_DMA_DONE 0x2
  94375. +#define BS_HOST_BUSY 0x3
  94376. +
  94377. +/** Receive/Transmit status definitions */
  94378. +
  94379. +#define RTS_SUCCESS 0x0
  94380. +#define RTS_BUFFLUSH 0x1
  94381. +#define RTS_RESERVED 0x2
  94382. +#define RTS_BUFERR 0x3
  94383. +
  94384. +/**
  94385. + * This union represents the bit fields in the DMA Descriptor
  94386. + * status quadlet. Read the quadlet into the <i>d32</i> member then
  94387. + * set/clear the bits using the <i>b</i>it, <i>b_iso_out</i> and
  94388. + * <i>b_iso_in</i> elements.
  94389. + */
  94390. +typedef union dev_dma_desc_sts {
  94391. + /** raw register data */
  94392. + uint32_t d32;
  94393. + /** quadlet bits */
  94394. + struct {
  94395. + /** Received number of bytes */
  94396. + unsigned bytes:16;
  94397. + /** NAK bit - only for OUT EPs */
  94398. + unsigned nak:1;
  94399. + unsigned reserved17_22:6;
  94400. + /** Multiple Transfer - only for OUT EPs */
  94401. + unsigned mtrf:1;
  94402. + /** Setup Packet received - only for OUT EPs */
  94403. + unsigned sr:1;
  94404. + /** Interrupt On Complete */
  94405. + unsigned ioc:1;
  94406. + /** Short Packet */
  94407. + unsigned sp:1;
  94408. + /** Last */
  94409. + unsigned l:1;
  94410. + /** Receive Status */
  94411. + unsigned sts:2;
  94412. + /** Buffer Status */
  94413. + unsigned bs:2;
  94414. + } b;
  94415. +
  94416. +//#ifdef DWC_EN_ISOC
  94417. + /** iso out quadlet bits */
  94418. + struct {
  94419. + /** Received number of bytes */
  94420. + unsigned rxbytes:11;
  94421. +
  94422. + unsigned reserved11:1;
  94423. + /** Frame Number */
  94424. + unsigned framenum:11;
  94425. + /** Received ISO Data PID */
  94426. + unsigned pid:2;
  94427. + /** Interrupt On Complete */
  94428. + unsigned ioc:1;
  94429. + /** Short Packet */
  94430. + unsigned sp:1;
  94431. + /** Last */
  94432. + unsigned l:1;
  94433. + /** Receive Status */
  94434. + unsigned rxsts:2;
  94435. + /** Buffer Status */
  94436. + unsigned bs:2;
  94437. + } b_iso_out;
  94438. +
  94439. + /** iso in quadlet bits */
  94440. + struct {
  94441. + /** Transmited number of bytes */
  94442. + unsigned txbytes:12;
  94443. + /** Frame Number */
  94444. + unsigned framenum:11;
  94445. + /** Transmited ISO Data PID */
  94446. + unsigned pid:2;
  94447. + /** Interrupt On Complete */
  94448. + unsigned ioc:1;
  94449. + /** Short Packet */
  94450. + unsigned sp:1;
  94451. + /** Last */
  94452. + unsigned l:1;
  94453. + /** Transmit Status */
  94454. + unsigned txsts:2;
  94455. + /** Buffer Status */
  94456. + unsigned bs:2;
  94457. + } b_iso_in;
  94458. +//#endif /* DWC_EN_ISOC */
  94459. +} dev_dma_desc_sts_t;
  94460. +
  94461. +/**
  94462. + * DMA Descriptor structure
  94463. + *
  94464. + * DMA Descriptor structure contains two quadlets:
  94465. + * Status quadlet and Data buffer pointer.
  94466. + */
  94467. +typedef struct dwc_otg_dev_dma_desc {
  94468. + /** DMA Descriptor status quadlet */
  94469. + dev_dma_desc_sts_t status;
  94470. + /** DMA Descriptor data buffer pointer */
  94471. + uint32_t buf;
  94472. +} dwc_otg_dev_dma_desc_t;
  94473. +
  94474. +/**
  94475. + * The dwc_otg_dev_if structure contains information needed to manage
  94476. + * the DWC_otg controller acting in device mode. It represents the
  94477. + * programming view of the device-specific aspects of the controller.
  94478. + */
  94479. +typedef struct dwc_otg_dev_if {
  94480. + /** Pointer to device Global registers.
  94481. + * Device Global Registers starting at offset 800h
  94482. + */
  94483. + dwc_otg_device_global_regs_t *dev_global_regs;
  94484. +#define DWC_DEV_GLOBAL_REG_OFFSET 0x800
  94485. +
  94486. + /**
  94487. + * Device Logical IN Endpoint-Specific Registers 900h-AFCh
  94488. + */
  94489. + dwc_otg_dev_in_ep_regs_t *in_ep_regs[MAX_EPS_CHANNELS];
  94490. +#define DWC_DEV_IN_EP_REG_OFFSET 0x900
  94491. +#define DWC_EP_REG_OFFSET 0x20
  94492. +
  94493. + /** Device Logical OUT Endpoint-Specific Registers B00h-CFCh */
  94494. + dwc_otg_dev_out_ep_regs_t *out_ep_regs[MAX_EPS_CHANNELS];
  94495. +#define DWC_DEV_OUT_EP_REG_OFFSET 0xB00
  94496. +
  94497. + /* Device configuration information */
  94498. + uint8_t speed; /**< Device Speed 0: Unknown, 1: LS, 2:FS, 3: HS */
  94499. + uint8_t num_in_eps; /**< Number # of Tx EP range: 0-15 exept ep0 */
  94500. + uint8_t num_out_eps; /**< Number # of Rx EP range: 0-15 exept ep 0*/
  94501. +
  94502. + /** Size of periodic FIFOs (Bytes) */
  94503. + uint16_t perio_tx_fifo_size[MAX_PERIO_FIFOS];
  94504. +
  94505. + /** Size of Tx FIFOs (Bytes) */
  94506. + uint16_t tx_fifo_size[MAX_TX_FIFOS];
  94507. +
  94508. + /** Thresholding enable flags and length varaiables **/
  94509. + uint16_t rx_thr_en;
  94510. + uint16_t iso_tx_thr_en;
  94511. + uint16_t non_iso_tx_thr_en;
  94512. +
  94513. + uint16_t rx_thr_length;
  94514. + uint16_t tx_thr_length;
  94515. +
  94516. + /**
  94517. + * Pointers to the DMA Descriptors for EP0 Control
  94518. + * transfers (virtual and physical)
  94519. + */
  94520. +
  94521. + /** 2 descriptors for SETUP packets */
  94522. + dwc_dma_t dma_setup_desc_addr[2];
  94523. + dwc_otg_dev_dma_desc_t *setup_desc_addr[2];
  94524. +
  94525. + /** Pointer to Descriptor with latest SETUP packet */
  94526. + dwc_otg_dev_dma_desc_t *psetup;
  94527. +
  94528. + /** Index of current SETUP handler descriptor */
  94529. + uint32_t setup_desc_index;
  94530. +
  94531. + /** Descriptor for Data In or Status In phases */
  94532. + dwc_dma_t dma_in_desc_addr;
  94533. + dwc_otg_dev_dma_desc_t *in_desc_addr;
  94534. +
  94535. + /** Descriptor for Data Out or Status Out phases */
  94536. + dwc_dma_t dma_out_desc_addr;
  94537. + dwc_otg_dev_dma_desc_t *out_desc_addr;
  94538. +
  94539. + /** Setup Packet Detected - if set clear NAK when queueing */
  94540. + uint32_t spd;
  94541. + /** Isoc ep pointer on which incomplete happens */
  94542. + void *isoc_ep;
  94543. +
  94544. +} dwc_otg_dev_if_t;
  94545. +
  94546. +/////////////////////////////////////////////////
  94547. +// Host Mode Register Structures
  94548. +//
  94549. +/**
  94550. + * The Host Global Registers structure defines the size and relative
  94551. + * field offsets for the Host Mode Global Registers. Host Global
  94552. + * Registers offsets 400h-7FFh.
  94553. +*/
  94554. +typedef struct dwc_otg_host_global_regs {
  94555. + /** Host Configuration Register. <i>Offset: 400h</i> */
  94556. + volatile uint32_t hcfg;
  94557. + /** Host Frame Interval Register. <i>Offset: 404h</i> */
  94558. + volatile uint32_t hfir;
  94559. + /** Host Frame Number / Frame Remaining Register. <i>Offset: 408h</i> */
  94560. + volatile uint32_t hfnum;
  94561. + /** Reserved. <i>Offset: 40Ch</i> */
  94562. + uint32_t reserved40C;
  94563. + /** Host Periodic Transmit FIFO/ Queue Status Register. <i>Offset: 410h</i> */
  94564. + volatile uint32_t hptxsts;
  94565. + /** Host All Channels Interrupt Register. <i>Offset: 414h</i> */
  94566. + volatile uint32_t haint;
  94567. + /** Host All Channels Interrupt Mask Register. <i>Offset: 418h</i> */
  94568. + volatile uint32_t haintmsk;
  94569. + /** Host Frame List Base Address Register . <i>Offset: 41Ch</i> */
  94570. + volatile uint32_t hflbaddr;
  94571. +} dwc_otg_host_global_regs_t;
  94572. +
  94573. +/**
  94574. + * This union represents the bit fields in the Host Configuration Register.
  94575. + * Read the register into the <i>d32</i> member then set/clear the bits using
  94576. + * the <i>b</i>it elements. Write the <i>d32</i> member to the hcfg register.
  94577. + */
  94578. +typedef union hcfg_data {
  94579. + /** raw register data */
  94580. + uint32_t d32;
  94581. +
  94582. + /** register bits */
  94583. + struct {
  94584. + /** FS/LS Phy Clock Select */
  94585. + unsigned fslspclksel:2;
  94586. +#define DWC_HCFG_30_60_MHZ 0
  94587. +#define DWC_HCFG_48_MHZ 1
  94588. +#define DWC_HCFG_6_MHZ 2
  94589. +
  94590. + /** FS/LS Only Support */
  94591. + unsigned fslssupp:1;
  94592. + unsigned reserved3_6:4;
  94593. + /** Enable 32-KHz Suspend Mode */
  94594. + unsigned ena32khzs:1;
  94595. + /** Resume Validation Periiod */
  94596. + unsigned resvalid:8;
  94597. + unsigned reserved16_22:7;
  94598. + /** Enable Scatter/gather DMA in Host mode */
  94599. + unsigned descdma:1;
  94600. + /** Frame List Entries */
  94601. + unsigned frlisten:2;
  94602. + /** Enable Periodic Scheduling */
  94603. + unsigned perschedena:1;
  94604. + unsigned reserved27_30:4;
  94605. + unsigned modechtimen:1;
  94606. + } b;
  94607. +} hcfg_data_t;
  94608. +
  94609. +/**
  94610. + * This union represents the bit fields in the Host Frame Remaing/Number
  94611. + * Register.
  94612. + */
  94613. +typedef union hfir_data {
  94614. + /** raw register data */
  94615. + uint32_t d32;
  94616. +
  94617. + /** register bits */
  94618. + struct {
  94619. + unsigned frint:16;
  94620. + unsigned hfirrldctrl:1;
  94621. + unsigned reserved:15;
  94622. + } b;
  94623. +} hfir_data_t;
  94624. +
  94625. +/**
  94626. + * This union represents the bit fields in the Host Frame Remaing/Number
  94627. + * Register.
  94628. + */
  94629. +typedef union hfnum_data {
  94630. + /** raw register data */
  94631. + uint32_t d32;
  94632. +
  94633. + /** register bits */
  94634. + struct {
  94635. + unsigned frnum:16;
  94636. +#define DWC_HFNUM_MAX_FRNUM 0x3FFF
  94637. + unsigned frrem:16;
  94638. + } b;
  94639. +} hfnum_data_t;
  94640. +
  94641. +typedef union hptxsts_data {
  94642. + /** raw register data */
  94643. + uint32_t d32;
  94644. +
  94645. + /** register bits */
  94646. + struct {
  94647. + unsigned ptxfspcavail:16;
  94648. + unsigned ptxqspcavail:8;
  94649. + /** Top of the Periodic Transmit Request Queue
  94650. + * - bit 24 - Terminate (last entry for the selected channel)
  94651. + * - bits 26:25 - Token Type
  94652. + * - 2'b00 - Zero length
  94653. + * - 2'b01 - Ping
  94654. + * - 2'b10 - Disable
  94655. + * - bits 30:27 - Channel Number
  94656. + * - bit 31 - Odd/even microframe
  94657. + */
  94658. + unsigned ptxqtop_terminate:1;
  94659. + unsigned ptxqtop_token:2;
  94660. + unsigned ptxqtop_chnum:4;
  94661. + unsigned ptxqtop_odd:1;
  94662. + } b;
  94663. +} hptxsts_data_t;
  94664. +
  94665. +/**
  94666. + * This union represents the bit fields in the Host Port Control and Status
  94667. + * Register. Read the register into the <i>d32</i> member then set/clear the
  94668. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  94669. + * hprt0 register.
  94670. + */
  94671. +typedef union hprt0_data {
  94672. + /** raw register data */
  94673. + uint32_t d32;
  94674. + /** register bits */
  94675. + struct {
  94676. + unsigned prtconnsts:1;
  94677. + unsigned prtconndet:1;
  94678. + unsigned prtena:1;
  94679. + unsigned prtenchng:1;
  94680. + unsigned prtovrcurract:1;
  94681. + unsigned prtovrcurrchng:1;
  94682. + unsigned prtres:1;
  94683. + unsigned prtsusp:1;
  94684. + unsigned prtrst:1;
  94685. + unsigned reserved9:1;
  94686. + unsigned prtlnsts:2;
  94687. + unsigned prtpwr:1;
  94688. + unsigned prttstctl:4;
  94689. + unsigned prtspd:2;
  94690. +#define DWC_HPRT0_PRTSPD_HIGH_SPEED 0
  94691. +#define DWC_HPRT0_PRTSPD_FULL_SPEED 1
  94692. +#define DWC_HPRT0_PRTSPD_LOW_SPEED 2
  94693. + unsigned reserved19_31:13;
  94694. + } b;
  94695. +} hprt0_data_t;
  94696. +
  94697. +/**
  94698. + * This union represents the bit fields in the Host All Interrupt
  94699. + * Register.
  94700. + */
  94701. +typedef union haint_data {
  94702. + /** raw register data */
  94703. + uint32_t d32;
  94704. + /** register bits */
  94705. + struct {
  94706. + unsigned ch0:1;
  94707. + unsigned ch1:1;
  94708. + unsigned ch2:1;
  94709. + unsigned ch3:1;
  94710. + unsigned ch4:1;
  94711. + unsigned ch5:1;
  94712. + unsigned ch6:1;
  94713. + unsigned ch7:1;
  94714. + unsigned ch8:1;
  94715. + unsigned ch9:1;
  94716. + unsigned ch10:1;
  94717. + unsigned ch11:1;
  94718. + unsigned ch12:1;
  94719. + unsigned ch13:1;
  94720. + unsigned ch14:1;
  94721. + unsigned ch15:1;
  94722. + unsigned reserved:16;
  94723. + } b;
  94724. +
  94725. + struct {
  94726. + unsigned chint:16;
  94727. + unsigned reserved:16;
  94728. + } b2;
  94729. +} haint_data_t;
  94730. +
  94731. +/**
  94732. + * This union represents the bit fields in the Host All Interrupt
  94733. + * Register.
  94734. + */
  94735. +typedef union haintmsk_data {
  94736. + /** raw register data */
  94737. + uint32_t d32;
  94738. + /** register bits */
  94739. + struct {
  94740. + unsigned ch0:1;
  94741. + unsigned ch1:1;
  94742. + unsigned ch2:1;
  94743. + unsigned ch3:1;
  94744. + unsigned ch4:1;
  94745. + unsigned ch5:1;
  94746. + unsigned ch6:1;
  94747. + unsigned ch7:1;
  94748. + unsigned ch8:1;
  94749. + unsigned ch9:1;
  94750. + unsigned ch10:1;
  94751. + unsigned ch11:1;
  94752. + unsigned ch12:1;
  94753. + unsigned ch13:1;
  94754. + unsigned ch14:1;
  94755. + unsigned ch15:1;
  94756. + unsigned reserved:16;
  94757. + } b;
  94758. +
  94759. + struct {
  94760. + unsigned chint:16;
  94761. + unsigned reserved:16;
  94762. + } b2;
  94763. +} haintmsk_data_t;
  94764. +
  94765. +/**
  94766. + * Host Channel Specific Registers. <i>500h-5FCh</i>
  94767. + */
  94768. +typedef struct dwc_otg_hc_regs {
  94769. + /** Host Channel 0 Characteristic Register. <i>Offset: 500h + (chan_num * 20h) + 00h</i> */
  94770. + volatile uint32_t hcchar;
  94771. + /** Host Channel 0 Split Control Register. <i>Offset: 500h + (chan_num * 20h) + 04h</i> */
  94772. + volatile uint32_t hcsplt;
  94773. + /** Host Channel 0 Interrupt Register. <i>Offset: 500h + (chan_num * 20h) + 08h</i> */
  94774. + volatile uint32_t hcint;
  94775. + /** Host Channel 0 Interrupt Mask Register. <i>Offset: 500h + (chan_num * 20h) + 0Ch</i> */
  94776. + volatile uint32_t hcintmsk;
  94777. + /** Host Channel 0 Transfer Size Register. <i>Offset: 500h + (chan_num * 20h) + 10h</i> */
  94778. + volatile uint32_t hctsiz;
  94779. + /** Host Channel 0 DMA Address Register. <i>Offset: 500h + (chan_num * 20h) + 14h</i> */
  94780. + volatile uint32_t hcdma;
  94781. + volatile uint32_t reserved;
  94782. + /** Host Channel 0 DMA Buffer Address Register. <i>Offset: 500h + (chan_num * 20h) + 1Ch</i> */
  94783. + volatile uint32_t hcdmab;
  94784. +} dwc_otg_hc_regs_t;
  94785. +
  94786. +/**
  94787. + * This union represents the bit fields in the Host Channel Characteristics
  94788. + * Register. Read the register into the <i>d32</i> member then set/clear the
  94789. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  94790. + * hcchar register.
  94791. + */
  94792. +typedef union hcchar_data {
  94793. + /** raw register data */
  94794. + uint32_t d32;
  94795. +
  94796. + /** register bits */
  94797. + struct {
  94798. + /** Maximum packet size in bytes */
  94799. + unsigned mps:11;
  94800. +
  94801. + /** Endpoint number */
  94802. + unsigned epnum:4;
  94803. +
  94804. + /** 0: OUT, 1: IN */
  94805. + unsigned epdir:1;
  94806. +
  94807. + unsigned reserved:1;
  94808. +
  94809. + /** 0: Full/high speed device, 1: Low speed device */
  94810. + unsigned lspddev:1;
  94811. +
  94812. + /** 0: Control, 1: Isoc, 2: Bulk, 3: Intr */
  94813. + unsigned eptype:2;
  94814. +
  94815. + /** Packets per frame for periodic transfers. 0 is reserved. */
  94816. + unsigned multicnt:2;
  94817. +
  94818. + /** Device address */
  94819. + unsigned devaddr:7;
  94820. +
  94821. + /**
  94822. + * Frame to transmit periodic transaction.
  94823. + * 0: even, 1: odd
  94824. + */
  94825. + unsigned oddfrm:1;
  94826. +
  94827. + /** Channel disable */
  94828. + unsigned chdis:1;
  94829. +
  94830. + /** Channel enable */
  94831. + unsigned chen:1;
  94832. + } b;
  94833. +} hcchar_data_t;
  94834. +
  94835. +typedef union hcsplt_data {
  94836. + /** raw register data */
  94837. + uint32_t d32;
  94838. +
  94839. + /** register bits */
  94840. + struct {
  94841. + /** Port Address */
  94842. + unsigned prtaddr:7;
  94843. +
  94844. + /** Hub Address */
  94845. + unsigned hubaddr:7;
  94846. +
  94847. + /** Transaction Position */
  94848. + unsigned xactpos:2;
  94849. +#define DWC_HCSPLIT_XACTPOS_MID 0
  94850. +#define DWC_HCSPLIT_XACTPOS_END 1
  94851. +#define DWC_HCSPLIT_XACTPOS_BEGIN 2
  94852. +#define DWC_HCSPLIT_XACTPOS_ALL 3
  94853. +
  94854. + /** Do Complete Split */
  94855. + unsigned compsplt:1;
  94856. +
  94857. + /** Reserved */
  94858. + unsigned reserved:14;
  94859. +
  94860. + /** Split Enble */
  94861. + unsigned spltena:1;
  94862. + } b;
  94863. +} hcsplt_data_t;
  94864. +
  94865. +/**
  94866. + * This union represents the bit fields in the Host All Interrupt
  94867. + * Register.
  94868. + */
  94869. +typedef union hcint_data {
  94870. + /** raw register data */
  94871. + uint32_t d32;
  94872. + /** register bits */
  94873. + struct {
  94874. + /** Transfer Complete */
  94875. + unsigned xfercomp:1;
  94876. + /** Channel Halted */
  94877. + unsigned chhltd:1;
  94878. + /** AHB Error */
  94879. + unsigned ahberr:1;
  94880. + /** STALL Response Received */
  94881. + unsigned stall:1;
  94882. + /** NAK Response Received */
  94883. + unsigned nak:1;
  94884. + /** ACK Response Received */
  94885. + unsigned ack:1;
  94886. + /** NYET Response Received */
  94887. + unsigned nyet:1;
  94888. + /** Transaction Err */
  94889. + unsigned xacterr:1;
  94890. + /** Babble Error */
  94891. + unsigned bblerr:1;
  94892. + /** Frame Overrun */
  94893. + unsigned frmovrun:1;
  94894. + /** Data Toggle Error */
  94895. + unsigned datatglerr:1;
  94896. + /** Buffer Not Available (only for DDMA mode) */
  94897. + unsigned bna:1;
  94898. + /** Exessive transaction error (only for DDMA mode) */
  94899. + unsigned xcs_xact:1;
  94900. + /** Frame List Rollover interrupt */
  94901. + unsigned frm_list_roll:1;
  94902. + /** Reserved */
  94903. + unsigned reserved14_31:18;
  94904. + } b;
  94905. +} hcint_data_t;
  94906. +
  94907. +/**
  94908. + * This union represents the bit fields in the Host Channel Interrupt Mask
  94909. + * Register. Read the register into the <i>d32</i> member then set/clear the
  94910. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  94911. + * hcintmsk register.
  94912. + */
  94913. +typedef union hcintmsk_data {
  94914. + /** raw register data */
  94915. + uint32_t d32;
  94916. +
  94917. + /** register bits */
  94918. + struct {
  94919. + unsigned xfercompl:1;
  94920. + unsigned chhltd:1;
  94921. + unsigned ahberr:1;
  94922. + unsigned stall:1;
  94923. + unsigned nak:1;
  94924. + unsigned ack:1;
  94925. + unsigned nyet:1;
  94926. + unsigned xacterr:1;
  94927. + unsigned bblerr:1;
  94928. + unsigned frmovrun:1;
  94929. + unsigned datatglerr:1;
  94930. + unsigned bna:1;
  94931. + unsigned xcs_xact:1;
  94932. + unsigned frm_list_roll:1;
  94933. + unsigned reserved14_31:18;
  94934. + } b;
  94935. +} hcintmsk_data_t;
  94936. +
  94937. +/**
  94938. + * This union represents the bit fields in the Host Channel Transfer Size
  94939. + * Register. Read the register into the <i>d32</i> member then set/clear the
  94940. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  94941. + * hcchar register.
  94942. + */
  94943. +
  94944. +typedef union hctsiz_data {
  94945. + /** raw register data */
  94946. + uint32_t d32;
  94947. +
  94948. + /** register bits */
  94949. + struct {
  94950. + /** Total transfer size in bytes */
  94951. + unsigned xfersize:19;
  94952. +
  94953. + /** Data packets to transfer */
  94954. + unsigned pktcnt:10;
  94955. +
  94956. + /**
  94957. + * Packet ID for next data packet
  94958. + * 0: DATA0
  94959. + * 1: DATA2
  94960. + * 2: DATA1
  94961. + * 3: MDATA (non-Control), SETUP (Control)
  94962. + */
  94963. + unsigned pid:2;
  94964. +#define DWC_HCTSIZ_DATA0 0
  94965. +#define DWC_HCTSIZ_DATA1 2
  94966. +#define DWC_HCTSIZ_DATA2 1
  94967. +#define DWC_HCTSIZ_MDATA 3
  94968. +#define DWC_HCTSIZ_SETUP 3
  94969. +
  94970. + /** Do PING protocol when 1 */
  94971. + unsigned dopng:1;
  94972. + } b;
  94973. +
  94974. + /** register bits */
  94975. + struct {
  94976. + /** Scheduling information */
  94977. + unsigned schinfo:8;
  94978. +
  94979. + /** Number of transfer descriptors.
  94980. + * Max value:
  94981. + * 64 in general,
  94982. + * 256 only for HS isochronous endpoint.
  94983. + */
  94984. + unsigned ntd:8;
  94985. +
  94986. + /** Data packets to transfer */
  94987. + unsigned reserved16_28:13;
  94988. +
  94989. + /**
  94990. + * Packet ID for next data packet
  94991. + * 0: DATA0
  94992. + * 1: DATA2
  94993. + * 2: DATA1
  94994. + * 3: MDATA (non-Control)
  94995. + */
  94996. + unsigned pid:2;
  94997. +
  94998. + /** Do PING protocol when 1 */
  94999. + unsigned dopng:1;
  95000. + } b_ddma;
  95001. +} hctsiz_data_t;
  95002. +
  95003. +/**
  95004. + * This union represents the bit fields in the Host DMA Address
  95005. + * Register used in Descriptor DMA mode.
  95006. + */
  95007. +typedef union hcdma_data {
  95008. + /** raw register data */
  95009. + uint32_t d32;
  95010. + /** register bits */
  95011. + struct {
  95012. + unsigned reserved0_2:3;
  95013. + /** Current Transfer Descriptor. Not used for ISOC */
  95014. + unsigned ctd:8;
  95015. + /** Start Address of Descriptor List */
  95016. + unsigned dma_addr:21;
  95017. + } b;
  95018. +} hcdma_data_t;
  95019. +
  95020. +/**
  95021. + * This union represents the bit fields in the DMA Descriptor
  95022. + * status quadlet for host mode. Read the quadlet into the <i>d32</i> member then
  95023. + * set/clear the bits using the <i>b</i>it elements.
  95024. + */
  95025. +typedef union host_dma_desc_sts {
  95026. + /** raw register data */
  95027. + uint32_t d32;
  95028. + /** quadlet bits */
  95029. +
  95030. + /* for non-isochronous */
  95031. + struct {
  95032. + /** Number of bytes */
  95033. + unsigned n_bytes:17;
  95034. + /** QTD offset to jump when Short Packet received - only for IN EPs */
  95035. + unsigned qtd_offset:6;
  95036. + /**
  95037. + * Set to request the core to jump to alternate QTD if
  95038. + * Short Packet received - only for IN EPs
  95039. + */
  95040. + unsigned a_qtd:1;
  95041. + /**
  95042. + * Setup Packet bit. When set indicates that buffer contains
  95043. + * setup packet.
  95044. + */
  95045. + unsigned sup:1;
  95046. + /** Interrupt On Complete */
  95047. + unsigned ioc:1;
  95048. + /** End of List */
  95049. + unsigned eol:1;
  95050. + unsigned reserved27:1;
  95051. + /** Rx/Tx Status */
  95052. + unsigned sts:2;
  95053. +#define DMA_DESC_STS_PKTERR 1
  95054. + unsigned reserved30:1;
  95055. + /** Active Bit */
  95056. + unsigned a:1;
  95057. + } b;
  95058. + /* for isochronous */
  95059. + struct {
  95060. + /** Number of bytes */
  95061. + unsigned n_bytes:12;
  95062. + unsigned reserved12_24:13;
  95063. + /** Interrupt On Complete */
  95064. + unsigned ioc:1;
  95065. + unsigned reserved26_27:2;
  95066. + /** Rx/Tx Status */
  95067. + unsigned sts:2;
  95068. + unsigned reserved30:1;
  95069. + /** Active Bit */
  95070. + unsigned a:1;
  95071. + } b_isoc;
  95072. +} host_dma_desc_sts_t;
  95073. +
  95074. +#define MAX_DMA_DESC_SIZE 131071
  95075. +#define MAX_DMA_DESC_NUM_GENERIC 64
  95076. +#define MAX_DMA_DESC_NUM_HS_ISOC 256
  95077. +#define MAX_FRLIST_EN_NUM 64
  95078. +/**
  95079. + * Host-mode DMA Descriptor structure
  95080. + *
  95081. + * DMA Descriptor structure contains two quadlets:
  95082. + * Status quadlet and Data buffer pointer.
  95083. + */
  95084. +typedef struct dwc_otg_host_dma_desc {
  95085. + /** DMA Descriptor status quadlet */
  95086. + host_dma_desc_sts_t status;
  95087. + /** DMA Descriptor data buffer pointer */
  95088. + uint32_t buf;
  95089. +} dwc_otg_host_dma_desc_t;
  95090. +
  95091. +/** OTG Host Interface Structure.
  95092. + *
  95093. + * The OTG Host Interface Structure structure contains information
  95094. + * needed to manage the DWC_otg controller acting in host mode. It
  95095. + * represents the programming view of the host-specific aspects of the
  95096. + * controller.
  95097. + */
  95098. +typedef struct dwc_otg_host_if {
  95099. + /** Host Global Registers starting at offset 400h.*/
  95100. + dwc_otg_host_global_regs_t *host_global_regs;
  95101. +#define DWC_OTG_HOST_GLOBAL_REG_OFFSET 0x400
  95102. +
  95103. + /** Host Port 0 Control and Status Register */
  95104. + volatile uint32_t *hprt0;
  95105. +#define DWC_OTG_HOST_PORT_REGS_OFFSET 0x440
  95106. +
  95107. + /** Host Channel Specific Registers at offsets 500h-5FCh. */
  95108. + dwc_otg_hc_regs_t *hc_regs[MAX_EPS_CHANNELS];
  95109. +#define DWC_OTG_HOST_CHAN_REGS_OFFSET 0x500
  95110. +#define DWC_OTG_CHAN_REGS_OFFSET 0x20
  95111. +
  95112. + /* Host configuration information */
  95113. + /** Number of Host Channels (range: 1-16) */
  95114. + uint8_t num_host_channels;
  95115. + /** Periodic EPs supported (0: no, 1: yes) */
  95116. + uint8_t perio_eps_supported;
  95117. + /** Periodic Tx FIFO Size (Only 1 host periodic Tx FIFO) */
  95118. + uint16_t perio_tx_fifo_size;
  95119. +
  95120. +} dwc_otg_host_if_t;
  95121. +
  95122. +/**
  95123. + * This union represents the bit fields in the Power and Clock Gating Control
  95124. + * Register. Read the register into the <i>d32</i> member then set/clear the
  95125. + * bits using the <i>b</i>it elements.
  95126. + */
  95127. +typedef union pcgcctl_data {
  95128. + /** raw register data */
  95129. + uint32_t d32;
  95130. +
  95131. + /** register bits */
  95132. + struct {
  95133. + /** Stop Pclk */
  95134. + unsigned stoppclk:1;
  95135. + /** Gate Hclk */
  95136. + unsigned gatehclk:1;
  95137. + /** Power Clamp */
  95138. + unsigned pwrclmp:1;
  95139. + /** Reset Power Down Modules */
  95140. + unsigned rstpdwnmodule:1;
  95141. + /** Reserved */
  95142. + unsigned reserved:1;
  95143. + /** Enable Sleep Clock Gating (Enbl_L1Gating) */
  95144. + unsigned enbl_sleep_gating:1;
  95145. + /** PHY In Sleep (PhySleep) */
  95146. + unsigned phy_in_sleep:1;
  95147. + /** Deep Sleep*/
  95148. + unsigned deep_sleep:1;
  95149. + unsigned resetaftsusp:1;
  95150. + unsigned restoremode:1;
  95151. + unsigned enbl_extnd_hiber:1;
  95152. + unsigned extnd_hiber_pwrclmp:1;
  95153. + unsigned extnd_hiber_switch:1;
  95154. + unsigned ess_reg_restored:1;
  95155. + unsigned prt_clk_sel:2;
  95156. + unsigned port_power:1;
  95157. + unsigned max_xcvrselect:2;
  95158. + unsigned max_termsel:1;
  95159. + unsigned mac_dev_addr:7;
  95160. + unsigned p2hd_dev_enum_spd:2;
  95161. + unsigned p2hd_prt_spd:2;
  95162. + unsigned if_dev_mode:1;
  95163. + } b;
  95164. +} pcgcctl_data_t;
  95165. +
  95166. +/**
  95167. + * This union represents the bit fields in the Global Data FIFO Software
  95168. + * Configuration Register. Read the register into the <i>d32</i> member then
  95169. + * set/clear the bits using the <i>b</i>it elements.
  95170. + */
  95171. +typedef union gdfifocfg_data {
  95172. + /* raw register data */
  95173. + uint32_t d32;
  95174. + /** register bits */
  95175. + struct {
  95176. + /** OTG Data FIFO depth */
  95177. + unsigned gdfifocfg:16;
  95178. + /** Start address of EP info controller */
  95179. + unsigned epinfobase:16;
  95180. + } b;
  95181. +} gdfifocfg_data_t;
  95182. +
  95183. +/**
  95184. + * This union represents the bit fields in the Global Power Down Register
  95185. + * Register. Read the register into the <i>d32</i> member then set/clear the
  95186. + * bits using the <i>b</i>it elements.
  95187. + */
  95188. +typedef union gpwrdn_data {
  95189. + /* raw register data */
  95190. + uint32_t d32;
  95191. +
  95192. + /** register bits */
  95193. + struct {
  95194. + /** PMU Interrupt Select */
  95195. + unsigned pmuintsel:1;
  95196. + /** PMU Active */
  95197. + unsigned pmuactv:1;
  95198. + /** Restore */
  95199. + unsigned restore:1;
  95200. + /** Power Down Clamp */
  95201. + unsigned pwrdnclmp:1;
  95202. + /** Power Down Reset */
  95203. + unsigned pwrdnrstn:1;
  95204. + /** Power Down Switch */
  95205. + unsigned pwrdnswtch:1;
  95206. + /** Disable VBUS */
  95207. + unsigned dis_vbus:1;
  95208. + /** Line State Change */
  95209. + unsigned lnstschng:1;
  95210. + /** Line state change mask */
  95211. + unsigned lnstchng_msk:1;
  95212. + /** Reset Detected */
  95213. + unsigned rst_det:1;
  95214. + /** Reset Detect mask */
  95215. + unsigned rst_det_msk:1;
  95216. + /** Disconnect Detected */
  95217. + unsigned disconn_det:1;
  95218. + /** Disconnect Detect mask */
  95219. + unsigned disconn_det_msk:1;
  95220. + /** Connect Detected*/
  95221. + unsigned connect_det:1;
  95222. + /** Connect Detected Mask*/
  95223. + unsigned connect_det_msk:1;
  95224. + /** SRP Detected */
  95225. + unsigned srp_det:1;
  95226. + /** SRP Detect mask */
  95227. + unsigned srp_det_msk:1;
  95228. + /** Status Change Interrupt */
  95229. + unsigned sts_chngint:1;
  95230. + /** Status Change Interrupt Mask */
  95231. + unsigned sts_chngint_msk:1;
  95232. + /** Line State */
  95233. + unsigned linestate:2;
  95234. + /** Indicates current mode(status of IDDIG signal) */
  95235. + unsigned idsts:1;
  95236. + /** B Session Valid signal status*/
  95237. + unsigned bsessvld:1;
  95238. + /** ADP Event Detected */
  95239. + unsigned adp_int:1;
  95240. + /** Multi Valued ID pin */
  95241. + unsigned mult_val_id_bc:5;
  95242. + /** Reserved 24_31 */
  95243. + unsigned reserved29_31:3;
  95244. + } b;
  95245. +} gpwrdn_data_t;
  95246. +
  95247. +#endif
  95248. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/Makefile linux-rpi/drivers/usb/host/dwc_otg/Makefile
  95249. --- linux-3.15.4/drivers/usb/host/dwc_otg/Makefile 1970-01-01 01:00:00.000000000 +0100
  95250. +++ linux-rpi/drivers/usb/host/dwc_otg/Makefile 2014-07-07 10:45:43.000000000 +0200
  95251. @@ -0,0 +1,82 @@
  95252. +#
  95253. +# Makefile for DWC_otg Highspeed USB controller driver
  95254. +#
  95255. +
  95256. +ifneq ($(KERNELRELEASE),)
  95257. +
  95258. +# Use the BUS_INTERFACE variable to compile the software for either
  95259. +# PCI(PCI_INTERFACE) or LM(LM_INTERFACE) bus.
  95260. +ifeq ($(BUS_INTERFACE),)
  95261. +# BUS_INTERFACE = -DPCI_INTERFACE
  95262. +# BUS_INTERFACE = -DLM_INTERFACE
  95263. + BUS_INTERFACE = -DPLATFORM_INTERFACE
  95264. +endif
  95265. +
  95266. +#ccflags-y += -DDEBUG
  95267. +#ccflags-y += -DDWC_OTG_DEBUGLEV=1 # reduce common debug msgs
  95268. +
  95269. +# Use one of the following flags to compile the software in host-only or
  95270. +# device-only mode.
  95271. +#ccflags-y += -DDWC_HOST_ONLY
  95272. +#ccflags-y += -DDWC_DEVICE_ONLY
  95273. +
  95274. +ccflags-y += -Dlinux -DDWC_HS_ELECT_TST
  95275. +#ccflags-y += -DDWC_EN_ISOC
  95276. +ccflags-y += -I$(obj)/../dwc_common_port
  95277. +#ccflags-y += -I$(PORTLIB)
  95278. +ccflags-y += -DDWC_LINUX
  95279. +ccflags-y += $(CFI)
  95280. +ccflags-y += $(BUS_INTERFACE)
  95281. +#ccflags-y += -DDWC_DEV_SRPCAP
  95282. +
  95283. +obj-$(CONFIG_USB_DWCOTG) += dwc_otg.o
  95284. +
  95285. +dwc_otg-objs := dwc_otg_driver.o dwc_otg_attr.o
  95286. +dwc_otg-objs += dwc_otg_cil.o dwc_otg_cil_intr.o
  95287. +dwc_otg-objs += dwc_otg_pcd_linux.o dwc_otg_pcd.o dwc_otg_pcd_intr.o
  95288. +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
  95289. +dwc_otg-objs += dwc_otg_adp.o
  95290. +dwc_otg-objs += dwc_otg_fiq_fsm.o
  95291. +dwc_otg-objs += dwc_otg_fiq_stub.o
  95292. +ifneq ($(CFI),)
  95293. +dwc_otg-objs += dwc_otg_cfi.o
  95294. +endif
  95295. +
  95296. +kernrelwd := $(subst ., ,$(KERNELRELEASE))
  95297. +kernrel3 := $(word 1,$(kernrelwd)).$(word 2,$(kernrelwd)).$(word 3,$(kernrelwd))
  95298. +
  95299. +ifneq ($(kernrel3),2.6.20)
  95300. +ccflags-y += $(CPPFLAGS)
  95301. +endif
  95302. +
  95303. +else
  95304. +
  95305. +PWD := $(shell pwd)
  95306. +PORTLIB := $(PWD)/../dwc_common_port
  95307. +
  95308. +# Command paths
  95309. +CTAGS := $(CTAGS)
  95310. +DOXYGEN := $(DOXYGEN)
  95311. +
  95312. +default: portlib
  95313. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  95314. +
  95315. +install: default
  95316. + $(MAKE) -C$(KDIR) M=$(PORTLIB) modules_install
  95317. + $(MAKE) -C$(KDIR) M=$(PWD) modules_install
  95318. +
  95319. +portlib:
  95320. + $(MAKE) -C$(KDIR) M=$(PORTLIB) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  95321. + cp $(PORTLIB)/Module.symvers $(PWD)/
  95322. +
  95323. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  95324. + $(DOXYGEN) doc/doxygen.cfg
  95325. +
  95326. +tags: $(wildcard *.[hc])
  95327. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  95328. +
  95329. +
  95330. +clean:
  95331. + rm -rf *.o *.ko .*cmd *.mod.c .tmp_versions Module.symvers
  95332. +
  95333. +endif
  95334. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm linux-rpi/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm
  95335. --- linux-3.15.4/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm 1970-01-01 01:00:00.000000000 +0100
  95336. +++ linux-rpi/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm 2014-07-07 10:45:43.000000000 +0200
  95337. @@ -0,0 +1,337 @@
  95338. +package dwc_otg_test;
  95339. +
  95340. +use strict;
  95341. +use Exporter ();
  95342. +
  95343. +use vars qw(@ISA @EXPORT
  95344. +$sysfsdir $paramdir $errors $params
  95345. +);
  95346. +
  95347. +@ISA = qw(Exporter);
  95348. +
  95349. +#
  95350. +# Globals
  95351. +#
  95352. +$sysfsdir = "/sys/devices/lm0";
  95353. +$paramdir = "/sys/module/dwc_otg";
  95354. +$errors = 0;
  95355. +
  95356. +$params = [
  95357. + {
  95358. + NAME => "otg_cap",
  95359. + DEFAULT => 0,
  95360. + ENUM => [],
  95361. + LOW => 0,
  95362. + HIGH => 2
  95363. + },
  95364. + {
  95365. + NAME => "dma_enable",
  95366. + DEFAULT => 0,
  95367. + ENUM => [],
  95368. + LOW => 0,
  95369. + HIGH => 1
  95370. + },
  95371. + {
  95372. + NAME => "dma_burst_size",
  95373. + DEFAULT => 32,
  95374. + ENUM => [1, 4, 8, 16, 32, 64, 128, 256],
  95375. + LOW => 1,
  95376. + HIGH => 256
  95377. + },
  95378. + {
  95379. + NAME => "host_speed",
  95380. + DEFAULT => 0,
  95381. + ENUM => [],
  95382. + LOW => 0,
  95383. + HIGH => 1
  95384. + },
  95385. + {
  95386. + NAME => "host_support_fs_ls_low_power",
  95387. + DEFAULT => 0,
  95388. + ENUM => [],
  95389. + LOW => 0,
  95390. + HIGH => 1
  95391. + },
  95392. + {
  95393. + NAME => "host_ls_low_power_phy_clk",
  95394. + DEFAULT => 0,
  95395. + ENUM => [],
  95396. + LOW => 0,
  95397. + HIGH => 1
  95398. + },
  95399. + {
  95400. + NAME => "dev_speed",
  95401. + DEFAULT => 0,
  95402. + ENUM => [],
  95403. + LOW => 0,
  95404. + HIGH => 1
  95405. + },
  95406. + {
  95407. + NAME => "enable_dynamic_fifo",
  95408. + DEFAULT => 1,
  95409. + ENUM => [],
  95410. + LOW => 0,
  95411. + HIGH => 1
  95412. + },
  95413. + {
  95414. + NAME => "data_fifo_size",
  95415. + DEFAULT => 8192,
  95416. + ENUM => [],
  95417. + LOW => 32,
  95418. + HIGH => 32768
  95419. + },
  95420. + {
  95421. + NAME => "dev_rx_fifo_size",
  95422. + DEFAULT => 1064,
  95423. + ENUM => [],
  95424. + LOW => 16,
  95425. + HIGH => 32768
  95426. + },
  95427. + {
  95428. + NAME => "dev_nperio_tx_fifo_size",
  95429. + DEFAULT => 1024,
  95430. + ENUM => [],
  95431. + LOW => 16,
  95432. + HIGH => 32768
  95433. + },
  95434. + {
  95435. + NAME => "dev_perio_tx_fifo_size_1",
  95436. + DEFAULT => 256,
  95437. + ENUM => [],
  95438. + LOW => 4,
  95439. + HIGH => 768
  95440. + },
  95441. + {
  95442. + NAME => "dev_perio_tx_fifo_size_2",
  95443. + DEFAULT => 256,
  95444. + ENUM => [],
  95445. + LOW => 4,
  95446. + HIGH => 768
  95447. + },
  95448. + {
  95449. + NAME => "dev_perio_tx_fifo_size_3",
  95450. + DEFAULT => 256,
  95451. + ENUM => [],
  95452. + LOW => 4,
  95453. + HIGH => 768
  95454. + },
  95455. + {
  95456. + NAME => "dev_perio_tx_fifo_size_4",
  95457. + DEFAULT => 256,
  95458. + ENUM => [],
  95459. + LOW => 4,
  95460. + HIGH => 768
  95461. + },
  95462. + {
  95463. + NAME => "dev_perio_tx_fifo_size_5",
  95464. + DEFAULT => 256,
  95465. + ENUM => [],
  95466. + LOW => 4,
  95467. + HIGH => 768
  95468. + },
  95469. + {
  95470. + NAME => "dev_perio_tx_fifo_size_6",
  95471. + DEFAULT => 256,
  95472. + ENUM => [],
  95473. + LOW => 4,
  95474. + HIGH => 768
  95475. + },
  95476. + {
  95477. + NAME => "dev_perio_tx_fifo_size_7",
  95478. + DEFAULT => 256,
  95479. + ENUM => [],
  95480. + LOW => 4,
  95481. + HIGH => 768
  95482. + },
  95483. + {
  95484. + NAME => "dev_perio_tx_fifo_size_8",
  95485. + DEFAULT => 256,
  95486. + ENUM => [],
  95487. + LOW => 4,
  95488. + HIGH => 768
  95489. + },
  95490. + {
  95491. + NAME => "dev_perio_tx_fifo_size_9",
  95492. + DEFAULT => 256,
  95493. + ENUM => [],
  95494. + LOW => 4,
  95495. + HIGH => 768
  95496. + },
  95497. + {
  95498. + NAME => "dev_perio_tx_fifo_size_10",
  95499. + DEFAULT => 256,
  95500. + ENUM => [],
  95501. + LOW => 4,
  95502. + HIGH => 768
  95503. + },
  95504. + {
  95505. + NAME => "dev_perio_tx_fifo_size_11",
  95506. + DEFAULT => 256,
  95507. + ENUM => [],
  95508. + LOW => 4,
  95509. + HIGH => 768
  95510. + },
  95511. + {
  95512. + NAME => "dev_perio_tx_fifo_size_12",
  95513. + DEFAULT => 256,
  95514. + ENUM => [],
  95515. + LOW => 4,
  95516. + HIGH => 768
  95517. + },
  95518. + {
  95519. + NAME => "dev_perio_tx_fifo_size_13",
  95520. + DEFAULT => 256,
  95521. + ENUM => [],
  95522. + LOW => 4,
  95523. + HIGH => 768
  95524. + },
  95525. + {
  95526. + NAME => "dev_perio_tx_fifo_size_14",
  95527. + DEFAULT => 256,
  95528. + ENUM => [],
  95529. + LOW => 4,
  95530. + HIGH => 768
  95531. + },
  95532. + {
  95533. + NAME => "dev_perio_tx_fifo_size_15",
  95534. + DEFAULT => 256,
  95535. + ENUM => [],
  95536. + LOW => 4,
  95537. + HIGH => 768
  95538. + },
  95539. + {
  95540. + NAME => "host_rx_fifo_size",
  95541. + DEFAULT => 1024,
  95542. + ENUM => [],
  95543. + LOW => 16,
  95544. + HIGH => 32768
  95545. + },
  95546. + {
  95547. + NAME => "host_nperio_tx_fifo_size",
  95548. + DEFAULT => 1024,
  95549. + ENUM => [],
  95550. + LOW => 16,
  95551. + HIGH => 32768
  95552. + },
  95553. + {
  95554. + NAME => "host_perio_tx_fifo_size",
  95555. + DEFAULT => 1024,
  95556. + ENUM => [],
  95557. + LOW => 16,
  95558. + HIGH => 32768
  95559. + },
  95560. + {
  95561. + NAME => "max_transfer_size",
  95562. + DEFAULT => 65535,
  95563. + ENUM => [],
  95564. + LOW => 2047,
  95565. + HIGH => 65535
  95566. + },
  95567. + {
  95568. + NAME => "max_packet_count",
  95569. + DEFAULT => 511,
  95570. + ENUM => [],
  95571. + LOW => 15,
  95572. + HIGH => 511
  95573. + },
  95574. + {
  95575. + NAME => "host_channels",
  95576. + DEFAULT => 12,
  95577. + ENUM => [],
  95578. + LOW => 1,
  95579. + HIGH => 16
  95580. + },
  95581. + {
  95582. + NAME => "dev_endpoints",
  95583. + DEFAULT => 6,
  95584. + ENUM => [],
  95585. + LOW => 1,
  95586. + HIGH => 15
  95587. + },
  95588. + {
  95589. + NAME => "phy_type",
  95590. + DEFAULT => 1,
  95591. + ENUM => [],
  95592. + LOW => 0,
  95593. + HIGH => 2
  95594. + },
  95595. + {
  95596. + NAME => "phy_utmi_width",
  95597. + DEFAULT => 16,
  95598. + ENUM => [8, 16],
  95599. + LOW => 8,
  95600. + HIGH => 16
  95601. + },
  95602. + {
  95603. + NAME => "phy_ulpi_ddr",
  95604. + DEFAULT => 0,
  95605. + ENUM => [],
  95606. + LOW => 0,
  95607. + HIGH => 1
  95608. + },
  95609. + ];
  95610. +
  95611. +
  95612. +#
  95613. +#
  95614. +sub check_arch {
  95615. + $_ = `uname -m`;
  95616. + chomp;
  95617. + unless (m/armv4tl/) {
  95618. + warn "# \n# Can't execute on $_. Run on integrator platform.\n# \n";
  95619. + return 0;
  95620. + }
  95621. + return 1;
  95622. +}
  95623. +
  95624. +#
  95625. +#
  95626. +sub load_module {
  95627. + my $params = shift;
  95628. + print "\nRemoving Module\n";
  95629. + system "rmmod dwc_otg";
  95630. + print "Loading Module\n";
  95631. + if ($params ne "") {
  95632. + print "Module Parameters: $params\n";
  95633. + }
  95634. + if (system("modprobe dwc_otg $params")) {
  95635. + warn "Unable to load module\n";
  95636. + return 0;
  95637. + }
  95638. + return 1;
  95639. +}
  95640. +
  95641. +#
  95642. +#
  95643. +sub test_status {
  95644. + my $arg = shift;
  95645. +
  95646. + print "\n";
  95647. +
  95648. + if (defined $arg) {
  95649. + warn "WARNING: $arg\n";
  95650. + }
  95651. +
  95652. + if ($errors > 0) {
  95653. + warn "TEST FAILED with $errors errors\n";
  95654. + return 0;
  95655. + } else {
  95656. + print "TEST PASSED\n";
  95657. + return 0 if (defined $arg);
  95658. + }
  95659. + return 1;
  95660. +}
  95661. +
  95662. +#
  95663. +#
  95664. +@EXPORT = qw(
  95665. +$sysfsdir
  95666. +$paramdir
  95667. +$params
  95668. +$errors
  95669. +check_arch
  95670. +load_module
  95671. +test_status
  95672. +);
  95673. +
  95674. +1;
  95675. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/test/Makefile linux-rpi/drivers/usb/host/dwc_otg/test/Makefile
  95676. --- linux-3.15.4/drivers/usb/host/dwc_otg/test/Makefile 1970-01-01 01:00:00.000000000 +0100
  95677. +++ linux-rpi/drivers/usb/host/dwc_otg/test/Makefile 2014-04-13 17:33:11.000000000 +0200
  95678. @@ -0,0 +1,16 @@
  95679. +
  95680. +PERL=/usr/bin/perl
  95681. +PL_TESTS=test_sysfs.pl test_mod_param.pl
  95682. +
  95683. +.PHONY : test
  95684. +test : perl_tests
  95685. +
  95686. +perl_tests :
  95687. + @echo
  95688. + @echo Running perl tests
  95689. + @for test in $(PL_TESTS); do \
  95690. + if $(PERL) ./$$test ; then \
  95691. + echo "=======> $$test, PASSED" ; \
  95692. + else echo "=======> $$test, FAILED" ; \
  95693. + fi \
  95694. + done
  95695. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/test/test_mod_param.pl linux-rpi/drivers/usb/host/dwc_otg/test/test_mod_param.pl
  95696. --- linux-3.15.4/drivers/usb/host/dwc_otg/test/test_mod_param.pl 1970-01-01 01:00:00.000000000 +0100
  95697. +++ linux-rpi/drivers/usb/host/dwc_otg/test/test_mod_param.pl 2014-07-07 10:45:43.000000000 +0200
  95698. @@ -0,0 +1,133 @@
  95699. +#!/usr/bin/perl -w
  95700. +#
  95701. +# Run this program on the integrator.
  95702. +#
  95703. +# - Tests module parameter default values.
  95704. +# - Tests setting of valid module parameter values via modprobe.
  95705. +# - Tests invalid module parameter values.
  95706. +# -----------------------------------------------------------------------------
  95707. +use strict;
  95708. +use dwc_otg_test;
  95709. +
  95710. +check_arch() or die;
  95711. +
  95712. +#
  95713. +#
  95714. +sub test {
  95715. + my ($param,$expected) = @_;
  95716. + my $value = get($param);
  95717. +
  95718. + if ($value == $expected) {
  95719. + print "$param = $value, okay\n";
  95720. + }
  95721. +
  95722. + else {
  95723. + warn "ERROR: value of $param != $expected, $value\n";
  95724. + $errors ++;
  95725. + }
  95726. +}
  95727. +
  95728. +#
  95729. +#
  95730. +sub get {
  95731. + my $param = shift;
  95732. + my $tmp = `cat $paramdir/$param`;
  95733. + chomp $tmp;
  95734. + return $tmp;
  95735. +}
  95736. +
  95737. +#
  95738. +#
  95739. +sub test_main {
  95740. +
  95741. + print "\nTesting Module Parameters\n";
  95742. +
  95743. + load_module("") or die;
  95744. +
  95745. + # Test initial values
  95746. + print "\nTesting Default Values\n";
  95747. + foreach (@{$params}) {
  95748. + test ($_->{NAME}, $_->{DEFAULT});
  95749. + }
  95750. +
  95751. + # Test low value
  95752. + print "\nTesting Low Value\n";
  95753. + my $cmd_params = "";
  95754. + foreach (@{$params}) {
  95755. + $cmd_params = $cmd_params . "$_->{NAME}=$_->{LOW} ";
  95756. + }
  95757. + load_module($cmd_params) or die;
  95758. +
  95759. + foreach (@{$params}) {
  95760. + test ($_->{NAME}, $_->{LOW});
  95761. + }
  95762. +
  95763. + # Test high value
  95764. + print "\nTesting High Value\n";
  95765. + $cmd_params = "";
  95766. + foreach (@{$params}) {
  95767. + $cmd_params = $cmd_params . "$_->{NAME}=$_->{HIGH} ";
  95768. + }
  95769. + load_module($cmd_params) or die;
  95770. +
  95771. + foreach (@{$params}) {
  95772. + test ($_->{NAME}, $_->{HIGH});
  95773. + }
  95774. +
  95775. + # Test Enum
  95776. + print "\nTesting Enumerated\n";
  95777. + foreach (@{$params}) {
  95778. + if (defined $_->{ENUM}) {
  95779. + my $value;
  95780. + foreach $value (@{$_->{ENUM}}) {
  95781. + $cmd_params = "$_->{NAME}=$value";
  95782. + load_module($cmd_params) or die;
  95783. + test ($_->{NAME}, $value);
  95784. + }
  95785. + }
  95786. + }
  95787. +
  95788. + # Test Invalid Values
  95789. + print "\nTesting Invalid Values\n";
  95790. + $cmd_params = "";
  95791. + foreach (@{$params}) {
  95792. + $cmd_params = $cmd_params . sprintf "$_->{NAME}=%d ", $_->{LOW}-1;
  95793. + }
  95794. + load_module($cmd_params) or die;
  95795. +
  95796. + foreach (@{$params}) {
  95797. + test ($_->{NAME}, $_->{DEFAULT});
  95798. + }
  95799. +
  95800. + $cmd_params = "";
  95801. + foreach (@{$params}) {
  95802. + $cmd_params = $cmd_params . sprintf "$_->{NAME}=%d ", $_->{HIGH}+1;
  95803. + }
  95804. + load_module($cmd_params) or die;
  95805. +
  95806. + foreach (@{$params}) {
  95807. + test ($_->{NAME}, $_->{DEFAULT});
  95808. + }
  95809. +
  95810. + print "\nTesting Enumerated\n";
  95811. + foreach (@{$params}) {
  95812. + if (defined $_->{ENUM}) {
  95813. + my $value;
  95814. + foreach $value (@{$_->{ENUM}}) {
  95815. + $value = $value + 1;
  95816. + $cmd_params = "$_->{NAME}=$value";
  95817. + load_module($cmd_params) or die;
  95818. + test ($_->{NAME}, $_->{DEFAULT});
  95819. + $value = $value - 2;
  95820. + $cmd_params = "$_->{NAME}=$value";
  95821. + load_module($cmd_params) or die;
  95822. + test ($_->{NAME}, $_->{DEFAULT});
  95823. + }
  95824. + }
  95825. + }
  95826. +
  95827. + test_status() or die;
  95828. +}
  95829. +
  95830. +test_main();
  95831. +0;
  95832. diff -Nur linux-3.15.4/drivers/usb/host/dwc_otg/test/test_sysfs.pl linux-rpi/drivers/usb/host/dwc_otg/test/test_sysfs.pl
  95833. --- linux-3.15.4/drivers/usb/host/dwc_otg/test/test_sysfs.pl 1970-01-01 01:00:00.000000000 +0100
  95834. +++ linux-rpi/drivers/usb/host/dwc_otg/test/test_sysfs.pl 2014-07-07 10:45:43.000000000 +0200
  95835. @@ -0,0 +1,193 @@
  95836. +#!/usr/bin/perl -w
  95837. +#
  95838. +# Run this program on the integrator
  95839. +# - Tests select sysfs attributes.
  95840. +# - Todo ... test more attributes, hnp/srp, buspower/bussuspend, etc.
  95841. +# -----------------------------------------------------------------------------
  95842. +use strict;
  95843. +use dwc_otg_test;
  95844. +
  95845. +check_arch() or die;
  95846. +
  95847. +#
  95848. +#
  95849. +sub test {
  95850. + my ($attr,$expected) = @_;
  95851. + my $string = get($attr);
  95852. +
  95853. + if ($string eq $expected) {
  95854. + printf("$attr = $string, okay\n");
  95855. + }
  95856. + else {
  95857. + warn "ERROR: value of $attr != $expected, $string\n";
  95858. + $errors ++;
  95859. + }
  95860. +}
  95861. +
  95862. +#
  95863. +#
  95864. +sub set {
  95865. + my ($reg, $value) = @_;
  95866. + system "echo $value > $sysfsdir/$reg";
  95867. +}
  95868. +
  95869. +#
  95870. +#
  95871. +sub get {
  95872. + my $attr = shift;
  95873. + my $string = `cat $sysfsdir/$attr`;
  95874. + chomp $string;
  95875. + if ($string =~ m/\s\=\s/) {
  95876. + my $tmp;
  95877. + ($tmp, $string) = split /\s=\s/, $string;
  95878. + }
  95879. + return $string;
  95880. +}
  95881. +
  95882. +#
  95883. +#
  95884. +sub test_main {
  95885. + print("\nTesting Sysfs Attributes\n");
  95886. +
  95887. + load_module("") or die;
  95888. +
  95889. + # Test initial values of regoffset/regvalue/guid/gsnpsid
  95890. + print("\nTesting Default Values\n");
  95891. +
  95892. + test("regoffset", "0xffffffff");
  95893. + test("regvalue", "invalid offset");
  95894. + test("guid", "0x12345678"); # this will fail if it has been changed
  95895. + test("gsnpsid", "0x4f54200a");
  95896. +
  95897. + # Test operation of regoffset/regvalue
  95898. + print("\nTesting regoffset\n");
  95899. + set('regoffset', '5a5a5a5a');
  95900. + test("regoffset", "0xffffffff");
  95901. +
  95902. + set('regoffset', '0');
  95903. + test("regoffset", "0x00000000");
  95904. +
  95905. + set('regoffset', '40000');
  95906. + test("regoffset", "0x00000000");
  95907. +
  95908. + set('regoffset', '3ffff');
  95909. + test("regoffset", "0x0003ffff");
  95910. +
  95911. + set('regoffset', '1');
  95912. + test("regoffset", "0x00000001");
  95913. +
  95914. + print("\nTesting regvalue\n");
  95915. + set('regoffset', '3c');
  95916. + test("regvalue", "0x12345678");
  95917. + set('regvalue', '5a5a5a5a');
  95918. + test("regvalue", "0x5a5a5a5a");
  95919. + set('regvalue','a5a5a5a5');
  95920. + test("regvalue", "0xa5a5a5a5");
  95921. + set('guid','12345678');
  95922. +
  95923. + # Test HNP Capable
  95924. + print("\nTesting HNP Capable bit\n");
  95925. + set('hnpcapable', '1');
  95926. + test("hnpcapable", "0x1");
  95927. + set('hnpcapable','0');
  95928. + test("hnpcapable", "0x0");
  95929. +
  95930. + set('regoffset','0c');
  95931. +
  95932. + my $old = get('gusbcfg');
  95933. + print("setting hnpcapable\n");
  95934. + set('hnpcapable', '1');
  95935. + test("hnpcapable", "0x1");
  95936. + test('gusbcfg', sprintf "0x%08x", (oct ($old) | (1<<9)));
  95937. + test('regvalue', sprintf "0x%08x", (oct ($old) | (1<<9)));
  95938. +
  95939. + $old = get('gusbcfg');
  95940. + print("clearing hnpcapable\n");
  95941. + set('hnpcapable', '0');
  95942. + test("hnpcapable", "0x0");
  95943. + test ('gusbcfg', sprintf "0x%08x", oct ($old) & (~(1<<9)));
  95944. + test ('regvalue', sprintf "0x%08x", oct ($old) & (~(1<<9)));
  95945. +
  95946. + # Test SRP Capable
  95947. + print("\nTesting SRP Capable bit\n");
  95948. + set('srpcapable', '1');
  95949. + test("srpcapable", "0x1");
  95950. + set('srpcapable','0');
  95951. + test("srpcapable", "0x0");
  95952. +
  95953. + set('regoffset','0c');
  95954. +
  95955. + $old = get('gusbcfg');
  95956. + print("setting srpcapable\n");
  95957. + set('srpcapable', '1');
  95958. + test("srpcapable", "0x1");
  95959. + test('gusbcfg', sprintf "0x%08x", (oct ($old) | (1<<8)));
  95960. + test('regvalue', sprintf "0x%08x", (oct ($old) | (1<<8)));
  95961. +
  95962. + $old = get('gusbcfg');
  95963. + print("clearing srpcapable\n");
  95964. + set('srpcapable', '0');
  95965. + test("srpcapable", "0x0");
  95966. + test('gusbcfg', sprintf "0x%08x", oct ($old) & (~(1<<8)));
  95967. + test('regvalue', sprintf "0x%08x", oct ($old) & (~(1<<8)));
  95968. +
  95969. + # Test GGPIO
  95970. + print("\nTesting GGPIO\n");
  95971. + set('ggpio','5a5a5a5a');
  95972. + test('ggpio','0x5a5a0000');
  95973. + set('ggpio','a5a5a5a5');
  95974. + test('ggpio','0xa5a50000');
  95975. + set('ggpio','11110000');
  95976. + test('ggpio','0x11110000');
  95977. + set('ggpio','00001111');
  95978. + test('ggpio','0x00000000');
  95979. +
  95980. + # Test DEVSPEED
  95981. + print("\nTesting DEVSPEED\n");
  95982. + set('regoffset','800');
  95983. + $old = get('regvalue');
  95984. + set('devspeed','0');
  95985. + test('devspeed','0x0');
  95986. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3)));
  95987. + set('devspeed','1');
  95988. + test('devspeed','0x1');
  95989. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 1));
  95990. + set('devspeed','2');
  95991. + test('devspeed','0x2');
  95992. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 2));
  95993. + set('devspeed','3');
  95994. + test('devspeed','0x3');
  95995. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 3));
  95996. + set('devspeed','4');
  95997. + test('devspeed','0x0');
  95998. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3)));
  95999. + set('devspeed','5');
  96000. + test('devspeed','0x1');
  96001. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 1));
  96002. +
  96003. +
  96004. + # mode Returns the current mode:0 for device mode1 for host mode Read
  96005. + # hnp Initiate the Host Negotiation Protocol. Read returns the status. Read/Write
  96006. + # srp Initiate the Session Request Protocol. Read returns the status. Read/Write
  96007. + # buspower Get or Set the Power State of the bus (0 - Off or 1 - On) Read/Write
  96008. + # bussuspend Suspend the USB bus. Read/Write
  96009. + # busconnected Get the connection status of the bus Read
  96010. +
  96011. + # gotgctl Get or set the Core Control Status Register. Read/Write
  96012. + ## gusbcfg Get or set the Core USB Configuration Register Read/Write
  96013. + # grxfsiz Get or set the Receive FIFO Size Register Read/Write
  96014. + # gnptxfsiz Get or set the non-periodic Transmit Size Register Read/Write
  96015. + # gpvndctl Get or set the PHY Vendor Control Register Read/Write
  96016. + ## ggpio Get the value in the lower 16-bits of the General Purpose IO Register or Set the upper 16 bits. Read/Write
  96017. + ## guid Get or set the value of the User ID Register Read/Write
  96018. + ## gsnpsid Get the value of the Synopsys ID Regester Read
  96019. + ## devspeed Get or set the device speed setting in the DCFG register Read/Write
  96020. + # enumspeed Gets the device enumeration Speed. Read
  96021. + # hptxfsiz Get the value of the Host Periodic Transmit FIFO Read
  96022. + # hprt0 Get or Set the value in the Host Port Control and Status Register Read/Write
  96023. +
  96024. + test_status("TEST NYI") or die;
  96025. +}
  96026. +
  96027. +test_main();
  96028. +0;
  96029. diff -Nur linux-3.15.4/drivers/usb/host/Kconfig linux-rpi/drivers/usb/host/Kconfig
  96030. --- linux-3.15.4/drivers/usb/host/Kconfig 2014-07-07 03:59:25.000000000 +0200
  96031. +++ linux-rpi/drivers/usb/host/Kconfig 2014-07-07 10:45:43.000000000 +0200
  96032. @@ -685,6 +685,19 @@
  96033. To compile this driver a module, choose M here: the module
  96034. will be called "hwa-hc".
  96035. +config USB_DWCOTG
  96036. + tristate "Synopsis DWC host support"
  96037. + depends on USB
  96038. + help
  96039. + The Synopsis DWC controller is a dual-role
  96040. + host/peripheral/OTG ("On The Go") USB controllers.
  96041. +
  96042. + Enable this option to support this IP in host controller mode.
  96043. + If unsure, say N.
  96044. +
  96045. + To compile this driver as a module, choose M here: the
  96046. + modules built will be called dwc_otg and dwc_common_port.
  96047. +
  96048. config USB_IMX21_HCD
  96049. tristate "i.MX21 HCD support"
  96050. depends on ARM && ARCH_MXC
  96051. diff -Nur linux-3.15.4/drivers/usb/host/Makefile linux-rpi/drivers/usb/host/Makefile
  96052. --- linux-3.15.4/drivers/usb/host/Makefile 2014-07-07 03:59:25.000000000 +0200
  96053. +++ linux-rpi/drivers/usb/host/Makefile 2014-07-07 10:45:43.000000000 +0200
  96054. @@ -63,6 +63,8 @@
  96055. obj-$(CONFIG_USB_R8A66597_HCD) += r8a66597-hcd.o
  96056. obj-$(CONFIG_USB_ISP1760_HCD) += isp1760.o
  96057. obj-$(CONFIG_USB_HWA_HCD) += hwa-hc.o
  96058. +
  96059. +obj-$(CONFIG_USB_DWCOTG) += dwc_otg/ dwc_common_port/
  96060. obj-$(CONFIG_USB_IMX21_HCD) += imx21-hcd.o
  96061. obj-$(CONFIG_USB_FSL_MPH_DR_OF) += fsl-mph-dr-of.o
  96062. obj-$(CONFIG_USB_OCTEON2_COMMON) += octeon2-common.o
  96063. diff -Nur linux-3.15.4/drivers/usb/Makefile linux-rpi/drivers/usb/Makefile
  96064. --- linux-3.15.4/drivers/usb/Makefile 2014-07-07 03:59:25.000000000 +0200
  96065. +++ linux-rpi/drivers/usb/Makefile 2014-07-07 10:45:42.000000000 +0200
  96066. @@ -24,6 +24,7 @@
  96067. obj-$(CONFIG_USB_R8A66597_HCD) += host/
  96068. obj-$(CONFIG_USB_HWA_HCD) += host/
  96069. obj-$(CONFIG_USB_ISP1760_HCD) += host/
  96070. +obj-$(CONFIG_USB_DWCOTG) += host/
  96071. obj-$(CONFIG_USB_IMX21_HCD) += host/
  96072. obj-$(CONFIG_USB_FSL_MPH_DR_OF) += host/
  96073. obj-$(CONFIG_USB_FUSBH200_HCD) += host/
  96074. diff -Nur linux-3.15.4/drivers/video/fbdev/bcm2708_fb.c linux-rpi/drivers/video/fbdev/bcm2708_fb.c
  96075. --- linux-3.15.4/drivers/video/fbdev/bcm2708_fb.c 1970-01-01 01:00:00.000000000 +0100
  96076. +++ linux-rpi/drivers/video/fbdev/bcm2708_fb.c 2014-07-07 10:45:46.000000000 +0200
  96077. @@ -0,0 +1,765 @@
  96078. +/*
  96079. + * linux/drivers/video/bcm2708_fb.c
  96080. + *
  96081. + * Copyright (C) 2010 Broadcom
  96082. + *
  96083. + * This file is subject to the terms and conditions of the GNU General Public
  96084. + * License. See the file COPYING in the main directory of this archive
  96085. + * for more details.
  96086. + *
  96087. + * Broadcom simple framebuffer driver
  96088. + *
  96089. + * This file is derived from cirrusfb.c
  96090. + * Copyright 1999-2001 Jeff Garzik <jgarzik@pobox.com>
  96091. + *
  96092. + */
  96093. +#include <linux/module.h>
  96094. +#include <linux/kernel.h>
  96095. +#include <linux/errno.h>
  96096. +#include <linux/string.h>
  96097. +#include <linux/slab.h>
  96098. +#include <linux/mm.h>
  96099. +#include <linux/fb.h>
  96100. +#include <linux/init.h>
  96101. +#include <linux/interrupt.h>
  96102. +#include <linux/ioport.h>
  96103. +#include <linux/list.h>
  96104. +#include <linux/platform_device.h>
  96105. +#include <linux/clk.h>
  96106. +#include <linux/printk.h>
  96107. +#include <linux/console.h>
  96108. +#include <linux/debugfs.h>
  96109. +
  96110. +#include <mach/dma.h>
  96111. +#include <mach/platform.h>
  96112. +#include <mach/vcio.h>
  96113. +
  96114. +#include <asm/sizes.h>
  96115. +#include <linux/io.h>
  96116. +#include <linux/dma-mapping.h>
  96117. +
  96118. +#ifdef BCM2708_FB_DEBUG
  96119. +#define print_debug(fmt,...) pr_debug("%s:%s:%d: "fmt, MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  96120. +#else
  96121. +#define print_debug(fmt,...)
  96122. +#endif
  96123. +
  96124. +/* This is limited to 16 characters when displayed by X startup */
  96125. +static const char *bcm2708_name = "BCM2708 FB";
  96126. +
  96127. +#define DRIVER_NAME "bcm2708_fb"
  96128. +
  96129. +static int fbwidth = 800; /* module parameter */
  96130. +static int fbheight = 480; /* module parameter */
  96131. +static int fbdepth = 16; /* module parameter */
  96132. +static int fbswap = 0; /* module parameter */
  96133. +
  96134. +static u32 dma_busy_wait_threshold = 1<<15;
  96135. +module_param(dma_busy_wait_threshold, int, 0644);
  96136. +MODULE_PARM_DESC(dma_busy_wait_threshold, "Busy-wait for DMA completion below this area");
  96137. +
  96138. +/* this data structure describes each frame buffer device we find */
  96139. +
  96140. +struct fbinfo_s {
  96141. + u32 xres, yres, xres_virtual, yres_virtual;
  96142. + u32 pitch, bpp;
  96143. + u32 xoffset, yoffset;
  96144. + u32 base;
  96145. + u32 screen_size;
  96146. + u16 cmap[256];
  96147. +};
  96148. +
  96149. +struct bcm2708_fb_stats {
  96150. + struct debugfs_regset32 regset;
  96151. + u32 dma_copies;
  96152. + u32 dma_irqs;
  96153. +};
  96154. +
  96155. +struct bcm2708_fb {
  96156. + struct fb_info fb;
  96157. + struct platform_device *dev;
  96158. + struct fbinfo_s *info;
  96159. + dma_addr_t dma;
  96160. + u32 cmap[16];
  96161. + int dma_chan;
  96162. + int dma_irq;
  96163. + void __iomem *dma_chan_base;
  96164. + void *cb_base; /* DMA control blocks */
  96165. + dma_addr_t cb_handle;
  96166. + struct dentry *debugfs_dir;
  96167. + wait_queue_head_t dma_waitq;
  96168. + struct bcm2708_fb_stats stats;
  96169. + unsigned long fb_bus_address;
  96170. +};
  96171. +
  96172. +#define to_bcm2708(info) container_of(info, struct bcm2708_fb, fb)
  96173. +
  96174. +static void bcm2708_fb_debugfs_deinit(struct bcm2708_fb *fb)
  96175. +{
  96176. + debugfs_remove_recursive(fb->debugfs_dir);
  96177. + fb->debugfs_dir = NULL;
  96178. +}
  96179. +
  96180. +static int bcm2708_fb_debugfs_init(struct bcm2708_fb *fb)
  96181. +{
  96182. + static struct debugfs_reg32 stats_registers[] = {
  96183. + {
  96184. + "dma_copies",
  96185. + offsetof(struct bcm2708_fb_stats, dma_copies)
  96186. + },
  96187. + {
  96188. + "dma_irqs",
  96189. + offsetof(struct bcm2708_fb_stats, dma_irqs)
  96190. + },
  96191. + };
  96192. +
  96193. + fb->debugfs_dir = debugfs_create_dir(DRIVER_NAME, NULL);
  96194. + if (!fb->debugfs_dir) {
  96195. + pr_warn("%s: could not create debugfs entry\n",
  96196. + __func__);
  96197. + return -EFAULT;
  96198. + }
  96199. +
  96200. + fb->stats.regset.regs = stats_registers;
  96201. + fb->stats.regset.nregs = ARRAY_SIZE(stats_registers);
  96202. + fb->stats.regset.base = &fb->stats;
  96203. +
  96204. + if (!debugfs_create_regset32(
  96205. + "stats", 0444, fb->debugfs_dir, &fb->stats.regset)) {
  96206. + pr_warn("%s: could not create statistics registers\n",
  96207. + __func__);
  96208. + goto fail;
  96209. + }
  96210. + return 0;
  96211. +
  96212. +fail:
  96213. + bcm2708_fb_debugfs_deinit(fb);
  96214. + return -EFAULT;
  96215. +}
  96216. +
  96217. +static int bcm2708_fb_set_bitfields(struct fb_var_screeninfo *var)
  96218. +{
  96219. + int ret = 0;
  96220. +
  96221. + memset(&var->transp, 0, sizeof(var->transp));
  96222. +
  96223. + var->red.msb_right = 0;
  96224. + var->green.msb_right = 0;
  96225. + var->blue.msb_right = 0;
  96226. +
  96227. + switch (var->bits_per_pixel) {
  96228. + case 1:
  96229. + case 2:
  96230. + case 4:
  96231. + case 8:
  96232. + var->red.length = var->bits_per_pixel;
  96233. + var->red.offset = 0;
  96234. + var->green.length = var->bits_per_pixel;
  96235. + var->green.offset = 0;
  96236. + var->blue.length = var->bits_per_pixel;
  96237. + var->blue.offset = 0;
  96238. + break;
  96239. + case 16:
  96240. + var->red.length = 5;
  96241. + var->blue.length = 5;
  96242. + /*
  96243. + * Green length can be 5 or 6 depending whether
  96244. + * we're operating in RGB555 or RGB565 mode.
  96245. + */
  96246. + if (var->green.length != 5 && var->green.length != 6)
  96247. + var->green.length = 6;
  96248. + break;
  96249. + case 24:
  96250. + var->red.length = 8;
  96251. + var->blue.length = 8;
  96252. + var->green.length = 8;
  96253. + break;
  96254. + case 32:
  96255. + var->red.length = 8;
  96256. + var->green.length = 8;
  96257. + var->blue.length = 8;
  96258. + var->transp.length = 8;
  96259. + break;
  96260. + default:
  96261. + ret = -EINVAL;
  96262. + break;
  96263. + }
  96264. +
  96265. + /*
  96266. + * >= 16bpp displays have separate colour component bitfields
  96267. + * encoded in the pixel data. Calculate their position from
  96268. + * the bitfield length defined above.
  96269. + */
  96270. + if (ret == 0 && var->bits_per_pixel >= 24 && fbswap) {
  96271. + var->blue.offset = 0;
  96272. + var->green.offset = var->blue.offset + var->blue.length;
  96273. + var->red.offset = var->green.offset + var->green.length;
  96274. + var->transp.offset = var->red.offset + var->red.length;
  96275. + } else if (ret == 0 && var->bits_per_pixel >= 24) {
  96276. + var->red.offset = 0;
  96277. + var->green.offset = var->red.offset + var->red.length;
  96278. + var->blue.offset = var->green.offset + var->green.length;
  96279. + var->transp.offset = var->blue.offset + var->blue.length;
  96280. + } else if (ret == 0 && var->bits_per_pixel >= 16) {
  96281. + var->blue.offset = 0;
  96282. + var->green.offset = var->blue.offset + var->blue.length;
  96283. + var->red.offset = var->green.offset + var->green.length;
  96284. + var->transp.offset = var->red.offset + var->red.length;
  96285. + }
  96286. +
  96287. + return ret;
  96288. +}
  96289. +
  96290. +static int bcm2708_fb_check_var(struct fb_var_screeninfo *var,
  96291. + struct fb_info *info)
  96292. +{
  96293. + /* info input, var output */
  96294. + int yres;
  96295. +
  96296. + /* info input, var output */
  96297. + print_debug("bcm2708_fb_check_var info(%p) %dx%d (%dx%d), %d, %d\n", info,
  96298. + info->var.xres, info->var.yres, info->var.xres_virtual,
  96299. + info->var.yres_virtual, (int)info->screen_size,
  96300. + info->var.bits_per_pixel);
  96301. + print_debug("bcm2708_fb_check_var var(%p) %dx%d (%dx%d), %d\n", var,
  96302. + var->xres, var->yres, var->xres_virtual, var->yres_virtual,
  96303. + var->bits_per_pixel);
  96304. +
  96305. + if (!var->bits_per_pixel)
  96306. + var->bits_per_pixel = 16;
  96307. +
  96308. + if (bcm2708_fb_set_bitfields(var) != 0) {
  96309. + pr_err("bcm2708_fb_check_var: invalid bits_per_pixel %d\n",
  96310. + var->bits_per_pixel);
  96311. + return -EINVAL;
  96312. + }
  96313. +
  96314. +
  96315. + if (var->xres_virtual < var->xres)
  96316. + var->xres_virtual = var->xres;
  96317. + /* use highest possible virtual resolution */
  96318. + if (var->yres_virtual == -1) {
  96319. + var->yres_virtual = 480;
  96320. +
  96321. + pr_err
  96322. + ("bcm2708_fb_check_var: virtual resolution set to maximum of %dx%d\n",
  96323. + var->xres_virtual, var->yres_virtual);
  96324. + }
  96325. + if (var->yres_virtual < var->yres)
  96326. + var->yres_virtual = var->yres;
  96327. +
  96328. + if (var->xoffset < 0)
  96329. + var->xoffset = 0;
  96330. + if (var->yoffset < 0)
  96331. + var->yoffset = 0;
  96332. +
  96333. + /* truncate xoffset and yoffset to maximum if too high */
  96334. + if (var->xoffset > var->xres_virtual - var->xres)
  96335. + var->xoffset = var->xres_virtual - var->xres - 1;
  96336. + if (var->yoffset > var->yres_virtual - var->yres)
  96337. + var->yoffset = var->yres_virtual - var->yres - 1;
  96338. +
  96339. + yres = var->yres;
  96340. + if (var->vmode & FB_VMODE_DOUBLE)
  96341. + yres *= 2;
  96342. + else if (var->vmode & FB_VMODE_INTERLACED)
  96343. + yres = (yres + 1) / 2;
  96344. +
  96345. + if (var->xres * yres > 1920 * 1200) {
  96346. + pr_err("bcm2708_fb_check_var: ERROR: Pixel size >= 1920x1200; "
  96347. + "special treatment required! (TODO)\n");
  96348. + return -EINVAL;
  96349. + }
  96350. +
  96351. + return 0;
  96352. +}
  96353. +
  96354. +static int bcm2708_fb_set_par(struct fb_info *info)
  96355. +{
  96356. + uint32_t val = 0;
  96357. + struct bcm2708_fb *fb = to_bcm2708(info);
  96358. + volatile struct fbinfo_s *fbinfo = fb->info;
  96359. + fbinfo->xres = info->var.xres;
  96360. + fbinfo->yres = info->var.yres;
  96361. + fbinfo->xres_virtual = info->var.xres_virtual;
  96362. + fbinfo->yres_virtual = info->var.yres_virtual;
  96363. + fbinfo->bpp = info->var.bits_per_pixel;
  96364. + fbinfo->xoffset = info->var.xoffset;
  96365. + fbinfo->yoffset = info->var.yoffset;
  96366. + fbinfo->base = 0; /* filled in by VC */
  96367. + fbinfo->pitch = 0; /* filled in by VC */
  96368. +
  96369. + print_debug("bcm2708_fb_set_par info(%p) %dx%d (%dx%d), %d, %d\n", info,
  96370. + info->var.xres, info->var.yres, info->var.xres_virtual,
  96371. + info->var.yres_virtual, (int)info->screen_size,
  96372. + info->var.bits_per_pixel);
  96373. +
  96374. + /* ensure last write to fbinfo is visible to GPU */
  96375. + wmb();
  96376. +
  96377. + /* inform vc about new framebuffer */
  96378. + bcm_mailbox_write(MBOX_CHAN_FB, fb->dma);
  96379. +
  96380. + /* TODO: replace fb driver with vchiq version */
  96381. + /* wait for response */
  96382. + bcm_mailbox_read(MBOX_CHAN_FB, &val);
  96383. +
  96384. + /* ensure GPU writes are visible to us */
  96385. + rmb();
  96386. +
  96387. + if (val == 0) {
  96388. + fb->fb.fix.line_length = fbinfo->pitch;
  96389. +
  96390. + if (info->var.bits_per_pixel <= 8)
  96391. + fb->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
  96392. + else
  96393. + fb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
  96394. +
  96395. + fb->fb_bus_address = fbinfo->base;
  96396. + fbinfo->base &= ~0xc0000000;
  96397. + fb->fb.fix.smem_start = fbinfo->base;
  96398. + fb->fb.fix.smem_len = fbinfo->pitch * fbinfo->yres_virtual;
  96399. + fb->fb.screen_size = fbinfo->screen_size;
  96400. + if (fb->fb.screen_base)
  96401. + iounmap(fb->fb.screen_base);
  96402. + fb->fb.screen_base =
  96403. + (void *)ioremap_wc(fbinfo->base, fb->fb.screen_size);
  96404. + if (!fb->fb.screen_base) {
  96405. + /* the console may currently be locked */
  96406. + console_trylock();
  96407. + console_unlock();
  96408. +
  96409. + BUG(); /* what can we do here */
  96410. + }
  96411. + }
  96412. + print_debug
  96413. + ("BCM2708FB: start = %p,%p width=%d, height=%d, bpp=%d, pitch=%d size=%d success=%d\n",
  96414. + (void *)fb->fb.screen_base, (void *)fb->fb_bus_address,
  96415. + fbinfo->xres, fbinfo->yres, fbinfo->bpp,
  96416. + fbinfo->pitch, (int)fb->fb.screen_size, val);
  96417. +
  96418. + return val;
  96419. +}
  96420. +
  96421. +static inline u32 convert_bitfield(int val, struct fb_bitfield *bf)
  96422. +{
  96423. + unsigned int mask = (1 << bf->length) - 1;
  96424. +
  96425. + return (val >> (16 - bf->length) & mask) << bf->offset;
  96426. +}
  96427. +
  96428. +
  96429. +static int bcm2708_fb_setcolreg(unsigned int regno, unsigned int red,
  96430. + unsigned int green, unsigned int blue,
  96431. + unsigned int transp, struct fb_info *info)
  96432. +{
  96433. + struct bcm2708_fb *fb = to_bcm2708(info);
  96434. +
  96435. + /*print_debug("BCM2708FB: setcolreg %d:(%02x,%02x,%02x,%02x) %x\n", regno, red, green, blue, transp, fb->fb.fix.visual);*/
  96436. + if (fb->fb.var.bits_per_pixel <= 8) {
  96437. + if (regno < 256) {
  96438. + /* blue [0:4], green [5:10], red [11:15] */
  96439. + fb->info->cmap[regno] = ((red >> (16-5)) & 0x1f) << 11 |
  96440. + ((green >> (16-6)) & 0x3f) << 5 |
  96441. + ((blue >> (16-5)) & 0x1f) << 0;
  96442. + }
  96443. + /* 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 */
  96444. + /* So just call it for what looks like the last colour in a list for now. */
  96445. + if (regno == 15 || regno == 255)
  96446. + bcm2708_fb_set_par(info);
  96447. + } else if (regno < 16) {
  96448. + fb->cmap[regno] = convert_bitfield(transp, &fb->fb.var.transp) |
  96449. + convert_bitfield(blue, &fb->fb.var.blue) |
  96450. + convert_bitfield(green, &fb->fb.var.green) |
  96451. + convert_bitfield(red, &fb->fb.var.red);
  96452. + }
  96453. + return regno > 255;
  96454. +}
  96455. +
  96456. +static int bcm2708_fb_blank(int blank_mode, struct fb_info *info)
  96457. +{
  96458. + /*print_debug("bcm2708_fb_blank\n"); */
  96459. + return -1;
  96460. +}
  96461. +
  96462. +static void bcm2708_fb_fillrect(struct fb_info *info,
  96463. + const struct fb_fillrect *rect)
  96464. +{
  96465. + /* (is called) print_debug("bcm2708_fb_fillrect\n"); */
  96466. + cfb_fillrect(info, rect);
  96467. +}
  96468. +
  96469. +/* A helper function for configuring dma control block */
  96470. +static void set_dma_cb(struct bcm2708_dma_cb *cb,
  96471. + int burst_size,
  96472. + dma_addr_t dst,
  96473. + int dst_stride,
  96474. + dma_addr_t src,
  96475. + int src_stride,
  96476. + int w,
  96477. + int h)
  96478. +{
  96479. + cb->info = BCM2708_DMA_BURST(burst_size) | BCM2708_DMA_S_WIDTH |
  96480. + BCM2708_DMA_S_INC | BCM2708_DMA_D_WIDTH |
  96481. + BCM2708_DMA_D_INC | BCM2708_DMA_TDMODE;
  96482. + cb->dst = dst;
  96483. + cb->src = src;
  96484. + /*
  96485. + * This is not really obvious from the DMA documentation,
  96486. + * but the top 16 bits must be programmmed to "height -1"
  96487. + * and not "height" in 2D mode.
  96488. + */
  96489. + cb->length = ((h - 1) << 16) | w;
  96490. + cb->stride = ((dst_stride - w) << 16) | (u16)(src_stride - w);
  96491. + cb->pad[0] = 0;
  96492. + cb->pad[1] = 0;
  96493. +}
  96494. +
  96495. +static void bcm2708_fb_copyarea(struct fb_info *info,
  96496. + const struct fb_copyarea *region)
  96497. +{
  96498. + struct bcm2708_fb *fb = to_bcm2708(info);
  96499. + struct bcm2708_dma_cb *cb = fb->cb_base;
  96500. + int bytes_per_pixel = (info->var.bits_per_pixel + 7) >> 3;
  96501. + /* Channel 0 supports larger bursts and is a bit faster */
  96502. + int burst_size = (fb->dma_chan == 0) ? 8 : 2;
  96503. + int pixels = region->width * region->height;
  96504. +
  96505. + /* Fallback to cfb_copyarea() if we don't like something */
  96506. + if (bytes_per_pixel > 4 ||
  96507. + info->var.xres * info->var.yres > 1920 * 1200 ||
  96508. + region->width <= 0 || region->width > info->var.xres ||
  96509. + region->height <= 0 || region->height > info->var.yres ||
  96510. + region->sx < 0 || region->sx >= info->var.xres ||
  96511. + region->sy < 0 || region->sy >= info->var.yres ||
  96512. + region->dx < 0 || region->dx >= info->var.xres ||
  96513. + region->dy < 0 || region->dy >= info->var.yres ||
  96514. + region->sx + region->width > info->var.xres ||
  96515. + region->dx + region->width > info->var.xres ||
  96516. + region->sy + region->height > info->var.yres ||
  96517. + region->dy + region->height > info->var.yres) {
  96518. + cfb_copyarea(info, region);
  96519. + return;
  96520. + }
  96521. +
  96522. + if (region->dy == region->sy && region->dx > region->sx) {
  96523. + /*
  96524. + * A difficult case of overlapped copy. Because DMA can't
  96525. + * copy individual scanlines in backwards direction, we need
  96526. + * two-pass processing. We do it by programming a chain of dma
  96527. + * control blocks in the first 16K part of the buffer and use
  96528. + * the remaining 48K as the intermediate temporary scratch
  96529. + * buffer. The buffer size is sufficient to handle up to
  96530. + * 1920x1200 resolution at 32bpp pixel depth.
  96531. + */
  96532. + int y;
  96533. + dma_addr_t control_block_pa = fb->cb_handle;
  96534. + dma_addr_t scratchbuf = fb->cb_handle + 16 * 1024;
  96535. + int scanline_size = bytes_per_pixel * region->width;
  96536. + int scanlines_per_cb = (64 * 1024 - 16 * 1024) / scanline_size;
  96537. +
  96538. + for (y = 0; y < region->height; y += scanlines_per_cb) {
  96539. + dma_addr_t src =
  96540. + fb->fb_bus_address +
  96541. + bytes_per_pixel * region->sx +
  96542. + (region->sy + y) * fb->fb.fix.line_length;
  96543. + dma_addr_t dst =
  96544. + fb->fb_bus_address +
  96545. + bytes_per_pixel * region->dx +
  96546. + (region->dy + y) * fb->fb.fix.line_length;
  96547. +
  96548. + if (region->height - y < scanlines_per_cb)
  96549. + scanlines_per_cb = region->height - y;
  96550. +
  96551. + set_dma_cb(cb, burst_size, scratchbuf, scanline_size,
  96552. + src, fb->fb.fix.line_length,
  96553. + scanline_size, scanlines_per_cb);
  96554. + control_block_pa += sizeof(struct bcm2708_dma_cb);
  96555. + cb->next = control_block_pa;
  96556. + cb++;
  96557. +
  96558. + set_dma_cb(cb, burst_size, dst, fb->fb.fix.line_length,
  96559. + scratchbuf, scanline_size,
  96560. + scanline_size, scanlines_per_cb);
  96561. + control_block_pa += sizeof(struct bcm2708_dma_cb);
  96562. + cb->next = control_block_pa;
  96563. + cb++;
  96564. + }
  96565. + /* move the pointer back to the last dma control block */
  96566. + cb--;
  96567. + } else {
  96568. + /* A single dma control block is enough. */
  96569. + int sy, dy, stride;
  96570. + if (region->dy <= region->sy) {
  96571. + /* processing from top to bottom */
  96572. + dy = region->dy;
  96573. + sy = region->sy;
  96574. + stride = fb->fb.fix.line_length;
  96575. + } else {
  96576. + /* processing from bottom to top */
  96577. + dy = region->dy + region->height - 1;
  96578. + sy = region->sy + region->height - 1;
  96579. + stride = -fb->fb.fix.line_length;
  96580. + }
  96581. + set_dma_cb(cb, burst_size,
  96582. + fb->fb_bus_address + dy * fb->fb.fix.line_length +
  96583. + bytes_per_pixel * region->dx,
  96584. + stride,
  96585. + fb->fb_bus_address + sy * fb->fb.fix.line_length +
  96586. + bytes_per_pixel * region->sx,
  96587. + stride,
  96588. + region->width * bytes_per_pixel,
  96589. + region->height);
  96590. + }
  96591. +
  96592. + /* end of dma control blocks chain */
  96593. + cb->next = 0;
  96594. +
  96595. +
  96596. + if (pixels < dma_busy_wait_threshold) {
  96597. + bcm_dma_start(fb->dma_chan_base, fb->cb_handle);
  96598. + bcm_dma_wait_idle(fb->dma_chan_base);
  96599. + } else {
  96600. + void __iomem *dma_chan = fb->dma_chan_base;
  96601. + cb->info |= BCM2708_DMA_INT_EN;
  96602. + bcm_dma_start(fb->dma_chan_base, fb->cb_handle);
  96603. + while (bcm_dma_is_busy(dma_chan)) {
  96604. + wait_event_interruptible(
  96605. + fb->dma_waitq,
  96606. + !bcm_dma_is_busy(dma_chan));
  96607. + }
  96608. + fb->stats.dma_irqs++;
  96609. + }
  96610. + fb->stats.dma_copies++;
  96611. +}
  96612. +
  96613. +static void bcm2708_fb_imageblit(struct fb_info *info,
  96614. + const struct fb_image *image)
  96615. +{
  96616. + /* (is called) print_debug("bcm2708_fb_imageblit\n"); */
  96617. + cfb_imageblit(info, image);
  96618. +}
  96619. +
  96620. +static irqreturn_t bcm2708_fb_dma_irq(int irq, void *cxt)
  96621. +{
  96622. + struct bcm2708_fb *fb = cxt;
  96623. +
  96624. + /* FIXME: should read status register to check if this is
  96625. + * actually interrupting us or not, in case this interrupt
  96626. + * ever becomes shared amongst several DMA channels
  96627. + *
  96628. + * readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_IRQ;
  96629. + */
  96630. +
  96631. + /* acknowledge the interrupt */
  96632. + writel(BCM2708_DMA_INT, fb->dma_chan_base + BCM2708_DMA_CS);
  96633. +
  96634. + wake_up(&fb->dma_waitq);
  96635. + return IRQ_HANDLED;
  96636. +}
  96637. +
  96638. +static struct fb_ops bcm2708_fb_ops = {
  96639. + .owner = THIS_MODULE,
  96640. + .fb_check_var = bcm2708_fb_check_var,
  96641. + .fb_set_par = bcm2708_fb_set_par,
  96642. + .fb_setcolreg = bcm2708_fb_setcolreg,
  96643. + .fb_blank = bcm2708_fb_blank,
  96644. + .fb_fillrect = bcm2708_fb_fillrect,
  96645. + .fb_copyarea = bcm2708_fb_copyarea,
  96646. + .fb_imageblit = bcm2708_fb_imageblit,
  96647. +};
  96648. +
  96649. +static int bcm2708_fb_register(struct bcm2708_fb *fb)
  96650. +{
  96651. + int ret;
  96652. + dma_addr_t dma;
  96653. + void *mem;
  96654. +
  96655. + mem =
  96656. + dma_alloc_coherent(NULL, PAGE_ALIGN(sizeof(*fb->info)), &dma,
  96657. + GFP_KERNEL);
  96658. +
  96659. + if (NULL == mem) {
  96660. + pr_err(": unable to allocate fbinfo buffer\n");
  96661. + ret = -ENOMEM;
  96662. + } else {
  96663. + fb->info = (struct fbinfo_s *)mem;
  96664. + fb->dma = dma;
  96665. + }
  96666. + fb->fb.fbops = &bcm2708_fb_ops;
  96667. + fb->fb.flags = FBINFO_FLAG_DEFAULT | FBINFO_HWACCEL_COPYAREA;
  96668. + fb->fb.pseudo_palette = fb->cmap;
  96669. +
  96670. + strncpy(fb->fb.fix.id, bcm2708_name, sizeof(fb->fb.fix.id));
  96671. + fb->fb.fix.type = FB_TYPE_PACKED_PIXELS;
  96672. + fb->fb.fix.type_aux = 0;
  96673. + fb->fb.fix.xpanstep = 0;
  96674. + fb->fb.fix.ypanstep = 0;
  96675. + fb->fb.fix.ywrapstep = 0;
  96676. + fb->fb.fix.accel = FB_ACCEL_NONE;
  96677. +
  96678. + fb->fb.var.xres = fbwidth;
  96679. + fb->fb.var.yres = fbheight;
  96680. + fb->fb.var.xres_virtual = fbwidth;
  96681. + fb->fb.var.yres_virtual = fbheight;
  96682. + fb->fb.var.bits_per_pixel = fbdepth;
  96683. + fb->fb.var.vmode = FB_VMODE_NONINTERLACED;
  96684. + fb->fb.var.activate = FB_ACTIVATE_NOW;
  96685. + fb->fb.var.nonstd = 0;
  96686. + fb->fb.var.height = -1; /* height of picture in mm */
  96687. + fb->fb.var.width = -1; /* width of picture in mm */
  96688. + fb->fb.var.accel_flags = 0;
  96689. +
  96690. + fb->fb.monspecs.hfmin = 0;
  96691. + fb->fb.monspecs.hfmax = 100000;
  96692. + fb->fb.monspecs.vfmin = 0;
  96693. + fb->fb.monspecs.vfmax = 400;
  96694. + fb->fb.monspecs.dclkmin = 1000000;
  96695. + fb->fb.monspecs.dclkmax = 100000000;
  96696. +
  96697. + bcm2708_fb_set_bitfields(&fb->fb.var);
  96698. + init_waitqueue_head(&fb->dma_waitq);
  96699. +
  96700. + /*
  96701. + * Allocate colourmap.
  96702. + */
  96703. +
  96704. + fb_set_var(&fb->fb, &fb->fb.var);
  96705. +
  96706. + print_debug("BCM2708FB: registering framebuffer (%dx%d@%d) (%d)\n", fbwidth
  96707. + fbheight, fbdepth, fbswap);
  96708. +
  96709. + ret = register_framebuffer(&fb->fb);
  96710. + print_debug("BCM2708FB: register framebuffer (%d)\n", ret);
  96711. + if (ret == 0)
  96712. + goto out;
  96713. +
  96714. + print_debug("BCM2708FB: cannot register framebuffer (%d)\n", ret);
  96715. +out:
  96716. + return ret;
  96717. +}
  96718. +
  96719. +static int bcm2708_fb_probe(struct platform_device *dev)
  96720. +{
  96721. + struct bcm2708_fb *fb;
  96722. + int ret;
  96723. +
  96724. + fb = kzalloc(sizeof(struct bcm2708_fb), GFP_KERNEL);
  96725. + if (!fb) {
  96726. + dev_err(&dev->dev,
  96727. + "could not allocate new bcm2708_fb struct\n");
  96728. + ret = -ENOMEM;
  96729. + goto free_region;
  96730. + }
  96731. +
  96732. + bcm2708_fb_debugfs_init(fb);
  96733. +
  96734. + fb->cb_base = dma_alloc_writecombine(&dev->dev, SZ_64K,
  96735. + &fb->cb_handle, GFP_KERNEL);
  96736. + if (!fb->cb_base) {
  96737. + dev_err(&dev->dev, "cannot allocate DMA CBs\n");
  96738. + ret = -ENOMEM;
  96739. + goto free_fb;
  96740. + }
  96741. +
  96742. + pr_info("BCM2708FB: allocated DMA memory %08x\n",
  96743. + fb->cb_handle);
  96744. +
  96745. + ret = bcm_dma_chan_alloc(BCM_DMA_FEATURE_BULK,
  96746. + &fb->dma_chan_base, &fb->dma_irq);
  96747. + if (ret < 0) {
  96748. + dev_err(&dev->dev, "couldn't allocate a DMA channel\n");
  96749. + goto free_cb;
  96750. + }
  96751. + fb->dma_chan = ret;
  96752. +
  96753. + ret = request_irq(fb->dma_irq, bcm2708_fb_dma_irq,
  96754. + 0, "bcm2708_fb dma", fb);
  96755. + if (ret) {
  96756. + pr_err("%s: failed to request DMA irq\n", __func__);
  96757. + goto free_dma_chan;
  96758. + }
  96759. +
  96760. +
  96761. + pr_info("BCM2708FB: allocated DMA channel %d @ %p\n",
  96762. + fb->dma_chan, fb->dma_chan_base);
  96763. +
  96764. + fb->dev = dev;
  96765. +
  96766. + ret = bcm2708_fb_register(fb);
  96767. + if (ret == 0) {
  96768. + platform_set_drvdata(dev, fb);
  96769. + goto out;
  96770. + }
  96771. +
  96772. +free_dma_chan:
  96773. + bcm_dma_chan_free(fb->dma_chan);
  96774. +free_cb:
  96775. + dma_free_writecombine(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
  96776. +free_fb:
  96777. + kfree(fb);
  96778. +free_region:
  96779. + dev_err(&dev->dev, "probe failed, err %d\n", ret);
  96780. +out:
  96781. + return ret;
  96782. +}
  96783. +
  96784. +static int bcm2708_fb_remove(struct platform_device *dev)
  96785. +{
  96786. + struct bcm2708_fb *fb = platform_get_drvdata(dev);
  96787. +
  96788. + platform_set_drvdata(dev, NULL);
  96789. +
  96790. + if (fb->fb.screen_base)
  96791. + iounmap(fb->fb.screen_base);
  96792. + unregister_framebuffer(&fb->fb);
  96793. +
  96794. + dma_free_writecombine(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
  96795. + bcm_dma_chan_free(fb->dma_chan);
  96796. +
  96797. + dma_free_coherent(NULL, PAGE_ALIGN(sizeof(*fb->info)), (void *)fb->info,
  96798. + fb->dma);
  96799. + bcm2708_fb_debugfs_deinit(fb);
  96800. +
  96801. + free_irq(fb->dma_irq, fb);
  96802. +
  96803. + kfree(fb);
  96804. +
  96805. + return 0;
  96806. +}
  96807. +
  96808. +static struct platform_driver bcm2708_fb_driver = {
  96809. + .probe = bcm2708_fb_probe,
  96810. + .remove = bcm2708_fb_remove,
  96811. + .driver = {
  96812. + .name = DRIVER_NAME,
  96813. + .owner = THIS_MODULE,
  96814. + },
  96815. +};
  96816. +
  96817. +static int __init bcm2708_fb_init(void)
  96818. +{
  96819. + return platform_driver_register(&bcm2708_fb_driver);
  96820. +}
  96821. +
  96822. +module_init(bcm2708_fb_init);
  96823. +
  96824. +static void __exit bcm2708_fb_exit(void)
  96825. +{
  96826. + platform_driver_unregister(&bcm2708_fb_driver);
  96827. +}
  96828. +
  96829. +module_exit(bcm2708_fb_exit);
  96830. +
  96831. +module_param(fbwidth, int, 0644);
  96832. +module_param(fbheight, int, 0644);
  96833. +module_param(fbdepth, int, 0644);
  96834. +module_param(fbswap, int, 0644);
  96835. +
  96836. +MODULE_DESCRIPTION("BCM2708 framebuffer driver");
  96837. +MODULE_LICENSE("GPL");
  96838. +
  96839. +MODULE_PARM_DESC(fbwidth, "Width of ARM Framebuffer");
  96840. +MODULE_PARM_DESC(fbheight, "Height of ARM Framebuffer");
  96841. +MODULE_PARM_DESC(fbdepth, "Bit depth of ARM Framebuffer");
  96842. +MODULE_PARM_DESC(fbswap, "Swap order of red and blue in 24 and 32 bit modes");
  96843. diff -Nur linux-3.15.4/drivers/video/fbdev/core/cfbimgblt.c linux-rpi/drivers/video/fbdev/core/cfbimgblt.c
  96844. --- linux-3.15.4/drivers/video/fbdev/core/cfbimgblt.c 2014-07-07 03:59:25.000000000 +0200
  96845. +++ linux-rpi/drivers/video/fbdev/core/cfbimgblt.c 2014-07-07 10:45:46.000000000 +0200
  96846. @@ -28,6 +28,11 @@
  96847. *
  96848. * Also need to add code to deal with cards endians that are different than
  96849. * the native cpu endians. I also need to deal with MSB position in the word.
  96850. + * Modified by Harm Hanemaaijer (fgenfb@yahoo.com) 2013:
  96851. + * - Provide optimized versions of fast_imageblit for 16 and 32bpp that are
  96852. + * significantly faster than the previous implementation.
  96853. + * - Simplify the fast/slow_imageblit selection code, avoiding integer
  96854. + * divides.
  96855. */
  96856. #include <linux/module.h>
  96857. #include <linux/string.h>
  96858. @@ -262,6 +267,133 @@
  96859. }
  96860. }
  96861. +/*
  96862. + * Optimized fast_imageblit for bpp == 16. ppw = 2, bit_mask = 3 folded
  96863. + * into the code, main loop unrolled.
  96864. + */
  96865. +
  96866. +static inline void fast_imageblit16(const struct fb_image *image,
  96867. + struct fb_info *p, u8 __iomem * dst1,
  96868. + u32 fgcolor, u32 bgcolor)
  96869. +{
  96870. + u32 fgx = fgcolor, bgx = bgcolor;
  96871. + u32 spitch = (image->width + 7) / 8;
  96872. + u32 end_mask, eorx;
  96873. + const char *s = image->data, *src;
  96874. + u32 __iomem *dst;
  96875. + const u32 *tab = NULL;
  96876. + int i, j, k;
  96877. +
  96878. + tab = fb_be_math(p) ? cfb_tab16_be : cfb_tab16_le;
  96879. +
  96880. + fgx <<= 16;
  96881. + bgx <<= 16;
  96882. + fgx |= fgcolor;
  96883. + bgx |= bgcolor;
  96884. +
  96885. + eorx = fgx ^ bgx;
  96886. + k = image->width / 2;
  96887. +
  96888. + for (i = image->height; i--;) {
  96889. + dst = (u32 __iomem *) dst1;
  96890. + src = s;
  96891. +
  96892. + j = k;
  96893. + while (j >= 4) {
  96894. + u8 bits = *src;
  96895. + end_mask = tab[(bits >> 6) & 3];
  96896. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96897. + end_mask = tab[(bits >> 4) & 3];
  96898. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96899. + end_mask = tab[(bits >> 2) & 3];
  96900. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96901. + end_mask = tab[bits & 3];
  96902. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96903. + src++;
  96904. + j -= 4;
  96905. + }
  96906. + if (j != 0) {
  96907. + u8 bits = *src;
  96908. + end_mask = tab[(bits >> 6) & 3];
  96909. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96910. + if (j >= 2) {
  96911. + end_mask = tab[(bits >> 4) & 3];
  96912. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96913. + if (j == 3) {
  96914. + end_mask = tab[(bits >> 2) & 3];
  96915. + FB_WRITEL((end_mask & eorx) ^ bgx, dst);
  96916. + }
  96917. + }
  96918. + }
  96919. + dst1 += p->fix.line_length;
  96920. + s += spitch;
  96921. + }
  96922. +}
  96923. +
  96924. +/*
  96925. + * Optimized fast_imageblit for bpp == 32. ppw = 1, bit_mask = 1 folded
  96926. + * into the code, main loop unrolled.
  96927. + */
  96928. +
  96929. +static inline void fast_imageblit32(const struct fb_image *image,
  96930. + struct fb_info *p, u8 __iomem * dst1,
  96931. + u32 fgcolor, u32 bgcolor)
  96932. +{
  96933. + u32 fgx = fgcolor, bgx = bgcolor;
  96934. + u32 spitch = (image->width + 7) / 8;
  96935. + u32 end_mask, eorx;
  96936. + const char *s = image->data, *src;
  96937. + u32 __iomem *dst;
  96938. + const u32 *tab = NULL;
  96939. + int i, j, k;
  96940. +
  96941. + tab = cfb_tab32;
  96942. +
  96943. + eorx = fgx ^ bgx;
  96944. + k = image->width;
  96945. +
  96946. + for (i = image->height; i--;) {
  96947. + dst = (u32 __iomem *) dst1;
  96948. + src = s;
  96949. +
  96950. + j = k;
  96951. + while (j >= 8) {
  96952. + u8 bits = *src;
  96953. + end_mask = tab[(bits >> 7) & 1];
  96954. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96955. + end_mask = tab[(bits >> 6) & 1];
  96956. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96957. + end_mask = tab[(bits >> 5) & 1];
  96958. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96959. + end_mask = tab[(bits >> 4) & 1];
  96960. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96961. + end_mask = tab[(bits >> 3) & 1];
  96962. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96963. + end_mask = tab[(bits >> 2) & 1];
  96964. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96965. + end_mask = tab[(bits >> 1) & 1];
  96966. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96967. + end_mask = tab[bits & 1];
  96968. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96969. + src++;
  96970. + j -= 8;
  96971. + }
  96972. + if (j != 0) {
  96973. + u32 bits = (u32) * src;
  96974. + while (j > 1) {
  96975. + end_mask = tab[(bits >> 7) & 1];
  96976. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96977. + bits <<= 1;
  96978. + j--;
  96979. + }
  96980. + end_mask = tab[(bits >> 7) & 1];
  96981. + FB_WRITEL((end_mask & eorx) ^ bgx, dst);
  96982. + }
  96983. + dst1 += p->fix.line_length;
  96984. + s += spitch;
  96985. + }
  96986. +}
  96987. +
  96988. void cfb_imageblit(struct fb_info *p, const struct fb_image *image)
  96989. {
  96990. u32 fgcolor, bgcolor, start_index, bitstart, pitch_index = 0;
  96991. @@ -294,11 +426,21 @@
  96992. bgcolor = image->bg_color;
  96993. }
  96994. - if (32 % bpp == 0 && !start_index && !pitch_index &&
  96995. - ((width & (32/bpp-1)) == 0) &&
  96996. - bpp >= 8 && bpp <= 32)
  96997. - fast_imageblit(image, p, dst1, fgcolor, bgcolor);
  96998. - else
  96999. + if (!start_index && !pitch_index) {
  97000. + if (bpp == 32)
  97001. + fast_imageblit32(image, p, dst1, fgcolor,
  97002. + bgcolor);
  97003. + else if (bpp == 16 && (width & 1) == 0)
  97004. + fast_imageblit16(image, p, dst1, fgcolor,
  97005. + bgcolor);
  97006. + else if (bpp == 8 && (width & 3) == 0)
  97007. + fast_imageblit(image, p, dst1, fgcolor,
  97008. + bgcolor);
  97009. + else
  97010. + slow_imageblit(image, p, dst1, fgcolor,
  97011. + bgcolor,
  97012. + start_index, pitch_index);
  97013. + } else
  97014. slow_imageblit(image, p, dst1, fgcolor, bgcolor,
  97015. start_index, pitch_index);
  97016. } else
  97017. diff -Nur linux-3.15.4/drivers/video/fbdev/core/fbmem.c linux-rpi/drivers/video/fbdev/core/fbmem.c
  97018. --- linux-3.15.4/drivers/video/fbdev/core/fbmem.c 2014-07-07 03:59:25.000000000 +0200
  97019. +++ linux-rpi/drivers/video/fbdev/core/fbmem.c 2014-07-07 10:45:46.000000000 +0200
  97020. @@ -1083,6 +1083,25 @@
  97021. }
  97022. EXPORT_SYMBOL(fb_blank);
  97023. +static int fb_copyarea_user(struct fb_info *info,
  97024. + struct fb_copyarea *copy)
  97025. +{
  97026. + int ret = 0;
  97027. + if (!lock_fb_info(info))
  97028. + return -ENODEV;
  97029. + if (copy->dx + copy->width > info->var.xres ||
  97030. + copy->sx + copy->width > info->var.xres ||
  97031. + copy->dy + copy->height > info->var.yres ||
  97032. + copy->sy + copy->height > info->var.yres) {
  97033. + ret = -EINVAL;
  97034. + goto out;
  97035. + }
  97036. + info->fbops->fb_copyarea(info, copy);
  97037. +out:
  97038. + unlock_fb_info(info);
  97039. + return ret;
  97040. +}
  97041. +
  97042. static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
  97043. unsigned long arg)
  97044. {
  97045. @@ -1093,6 +1112,7 @@
  97046. struct fb_cmap cmap_from;
  97047. struct fb_cmap_user cmap;
  97048. struct fb_event event;
  97049. + struct fb_copyarea copy;
  97050. void __user *argp = (void __user *)arg;
  97051. long ret = 0;
  97052. @@ -1210,6 +1230,15 @@
  97053. unlock_fb_info(info);
  97054. console_unlock();
  97055. break;
  97056. + case FBIOCOPYAREA:
  97057. + if (info->flags & FBINFO_HWACCEL_COPYAREA) {
  97058. + /* only provide this ioctl if it is accelerated */
  97059. + if (copy_from_user(&copy, argp, sizeof(copy)))
  97060. + return -EFAULT;
  97061. + ret = fb_copyarea_user(info, &copy);
  97062. + break;
  97063. + }
  97064. + /* fall through */
  97065. default:
  97066. if (!lock_fb_info(info))
  97067. return -ENODEV;
  97068. @@ -1364,6 +1393,7 @@
  97069. case FBIOPAN_DISPLAY:
  97070. case FBIOGET_CON2FBMAP:
  97071. case FBIOPUT_CON2FBMAP:
  97072. + case FBIOCOPYAREA:
  97073. arg = (unsigned long) compat_ptr(arg);
  97074. case FBIOBLANK:
  97075. ret = do_fb_ioctl(info, cmd, arg);
  97076. diff -Nur linux-3.15.4/drivers/video/fbdev/Kconfig linux-rpi/drivers/video/fbdev/Kconfig
  97077. --- linux-3.15.4/drivers/video/fbdev/Kconfig 2014-07-07 03:59:25.000000000 +0200
  97078. +++ linux-rpi/drivers/video/fbdev/Kconfig 2014-07-07 10:45:46.000000000 +0200
  97079. @@ -220,6 +220,20 @@
  97080. comment "Frame buffer hardware drivers"
  97081. depends on FB
  97082. +config FB_BCM2708
  97083. + tristate "BCM2708 framebuffer support"
  97084. + depends on FB && ARM
  97085. + select FB_CFB_FILLRECT
  97086. + select FB_CFB_COPYAREA
  97087. + select FB_CFB_IMAGEBLIT
  97088. + help
  97089. + This framebuffer device driver is for the BCM2708 framebuffer.
  97090. +
  97091. + If you want to compile this as a module (=code which can be
  97092. + inserted into and removed from the running kernel), say M
  97093. + here and read <file:Documentation/kbuild/modules.txt>. The module
  97094. + will be called bcm2708_fb.
  97095. +
  97096. config FB_GRVGA
  97097. tristate "Aeroflex Gaisler framebuffer support"
  97098. depends on FB && SPARC
  97099. diff -Nur linux-3.15.4/drivers/video/fbdev/Makefile linux-rpi/drivers/video/fbdev/Makefile
  97100. --- linux-3.15.4/drivers/video/fbdev/Makefile 2014-07-07 03:59:25.000000000 +0200
  97101. +++ linux-rpi/drivers/video/fbdev/Makefile 2014-07-07 10:45:46.000000000 +0200
  97102. @@ -12,6 +12,7 @@
  97103. obj-$(CONFIG_FB_WMT_GE_ROPS) += wmt_ge_rops.o
  97104. # Hardware specific drivers go first
  97105. +obj-$(CONFIG_FB_BCM2708) += bcm2708_fb.o
  97106. obj-$(CONFIG_FB_AMIGA) += amifb.o c2p_planar.o
  97107. obj-$(CONFIG_FB_ARC) += arcfb.o
  97108. obj-$(CONFIG_FB_CLPS711X) += clps711xfb.o
  97109. diff -Nur linux-3.15.4/drivers/video/logo/logo_linux_clut224.ppm linux-rpi/drivers/video/logo/logo_linux_clut224.ppm
  97110. --- linux-3.15.4/drivers/video/logo/logo_linux_clut224.ppm 2014-07-07 03:59:25.000000000 +0200
  97111. +++ linux-rpi/drivers/video/logo/logo_linux_clut224.ppm 2014-04-13 17:33:14.000000000 +0200
  97112. @@ -1,1604 +1,883 @@
  97113. P3
  97114. -# Standard 224-color Linux logo
  97115. -80 80
  97116. +63 80
  97117. 255
  97118. - 0 0 0 0 0 0 0 0 0 0 0 0
  97119. - 0 0 0 0 0 0 0 0 0 0 0 0
  97120. - 0 0 0 0 0 0 0 0 0 0 0 0
  97121. - 0 0 0 0 0 0 0 0 0 0 0 0
  97122. - 0 0 0 0 0 0 0 0 0 0 0 0
  97123. - 0 0 0 0 0 0 0 0 0 0 0 0
  97124. - 0 0 0 0 0 0 0 0 0 0 0 0
  97125. - 0 0 0 0 0 0 0 0 0 0 0 0
  97126. - 0 0 0 0 0 0 0 0 0 0 0 0
  97127. - 6 6 6 6 6 6 10 10 10 10 10 10
  97128. - 10 10 10 6 6 6 6 6 6 6 6 6
  97129. - 0 0 0 0 0 0 0 0 0 0 0 0
  97130. - 0 0 0 0 0 0 0 0 0 0 0 0
  97131. - 0 0 0 0 0 0 0 0 0 0 0 0
  97132. - 0 0 0 0 0 0 0 0 0 0 0 0
  97133. - 0 0 0 0 0 0 0 0 0 0 0 0
  97134. - 0 0 0 0 0 0 0 0 0 0 0 0
  97135. - 0 0 0 0 0 0 0 0 0 0 0 0
  97136. - 0 0 0 0 0 0 0 0 0 0 0 0
  97137. - 0 0 0 0 0 0 0 0 0 0 0 0
  97138. - 0 0 0 0 0 0 0 0 0 0 0 0
  97139. - 0 0 0 0 0 0 0 0 0 0 0 0
  97140. - 0 0 0 0 0 0 0 0 0 0 0 0
  97141. - 0 0 0 0 0 0 0 0 0 0 0 0
  97142. - 0 0 0 0 0 0 0 0 0 0 0 0
  97143. - 0 0 0 0 0 0 0 0 0 0 0 0
  97144. - 0 0 0 0 0 0 0 0 0 0 0 0
  97145. - 0 0 0 0 0 0 0 0 0 0 0 0
  97146. - 0 0 0 6 6 6 10 10 10 14 14 14
  97147. - 22 22 22 26 26 26 30 30 30 34 34 34
  97148. - 30 30 30 30 30 30 26 26 26 18 18 18
  97149. - 14 14 14 10 10 10 6 6 6 0 0 0
  97150. - 0 0 0 0 0 0 0 0 0 0 0 0
  97151. - 0 0 0 0 0 0 0 0 0 0 0 0
  97152. - 0 0 0 0 0 0 0 0 0 0 0 0
  97153. - 0 0 0 0 0 0 0 0 0 0 0 0
  97154. - 0 0 0 0 0 0 0 0 0 0 0 0
  97155. - 0 0 0 0 0 0 0 0 0 0 0 0
  97156. - 0 0 0 0 0 0 0 0 0 0 0 0
  97157. - 0 0 0 0 0 0 0 0 0 0 0 0
  97158. - 0 0 0 0 0 0 0 0 0 0 0 0
  97159. - 0 0 0 0 0 1 0 0 1 0 0 0
  97160. - 0 0 0 0 0 0 0 0 0 0 0 0
  97161. - 0 0 0 0 0 0 0 0 0 0 0 0
  97162. - 0 0 0 0 0 0 0 0 0 0 0 0
  97163. - 0 0 0 0 0 0 0 0 0 0 0 0
  97164. - 0 0 0 0 0 0 0 0 0 0 0 0
  97165. - 0 0 0 0 0 0 0 0 0 0 0 0
  97166. - 6 6 6 14 14 14 26 26 26 42 42 42
  97167. - 54 54 54 66 66 66 78 78 78 78 78 78
  97168. - 78 78 78 74 74 74 66 66 66 54 54 54
  97169. - 42 42 42 26 26 26 18 18 18 10 10 10
  97170. - 6 6 6 0 0 0 0 0 0 0 0 0
  97171. - 0 0 0 0 0 0 0 0 0 0 0 0
  97172. - 0 0 0 0 0 0 0 0 0 0 0 0
  97173. - 0 0 0 0 0 0 0 0 0 0 0 0
  97174. - 0 0 0 0 0 0 0 0 0 0 0 0
  97175. - 0 0 0 0 0 0 0 0 0 0 0 0
  97176. - 0 0 0 0 0 0 0 0 0 0 0 0
  97177. - 0 0 0 0 0 0 0 0 0 0 0 0
  97178. - 0 0 0 0 0 0 0 0 0 0 0 0
  97179. - 0 0 1 0 0 0 0 0 0 0 0 0
  97180. - 0 0 0 0 0 0 0 0 0 0 0 0
  97181. - 0 0 0 0 0 0 0 0 0 0 0 0
  97182. - 0 0 0 0 0 0 0 0 0 0 0 0
  97183. - 0 0 0 0 0 0 0 0 0 0 0 0
  97184. - 0 0 0 0 0 0 0 0 0 0 0 0
  97185. - 0 0 0 0 0 0 0 0 0 10 10 10
  97186. - 22 22 22 42 42 42 66 66 66 86 86 86
  97187. - 66 66 66 38 38 38 38 38 38 22 22 22
  97188. - 26 26 26 34 34 34 54 54 54 66 66 66
  97189. - 86 86 86 70 70 70 46 46 46 26 26 26
  97190. - 14 14 14 6 6 6 0 0 0 0 0 0
  97191. - 0 0 0 0 0 0 0 0 0 0 0 0
  97192. - 0 0 0 0 0 0 0 0 0 0 0 0
  97193. - 0 0 0 0 0 0 0 0 0 0 0 0
  97194. - 0 0 0 0 0 0 0 0 0 0 0 0
  97195. - 0 0 0 0 0 0 0 0 0 0 0 0
  97196. - 0 0 0 0 0 0 0 0 0 0 0 0
  97197. - 0 0 0 0 0 0 0 0 0 0 0 0
  97198. - 0 0 0 0 0 0 0 0 0 0 0 0
  97199. - 0 0 1 0 0 1 0 0 1 0 0 0
  97200. - 0 0 0 0 0 0 0 0 0 0 0 0
  97201. - 0 0 0 0 0 0 0 0 0 0 0 0
  97202. - 0 0 0 0 0 0 0 0 0 0 0 0
  97203. - 0 0 0 0 0 0 0 0 0 0 0 0
  97204. - 0 0 0 0 0 0 0 0 0 0 0 0
  97205. - 0 0 0 0 0 0 10 10 10 26 26 26
  97206. - 50 50 50 82 82 82 58 58 58 6 6 6
  97207. - 2 2 6 2 2 6 2 2 6 2 2 6
  97208. - 2 2 6 2 2 6 2 2 6 2 2 6
  97209. - 6 6 6 54 54 54 86 86 86 66 66 66
  97210. - 38 38 38 18 18 18 6 6 6 0 0 0
  97211. - 0 0 0 0 0 0 0 0 0 0 0 0
  97212. - 0 0 0 0 0 0 0 0 0 0 0 0
  97213. - 0 0 0 0 0 0 0 0 0 0 0 0
  97214. - 0 0 0 0 0 0 0 0 0 0 0 0
  97215. - 0 0 0 0 0 0 0 0 0 0 0 0
  97216. - 0 0 0 0 0 0 0 0 0 0 0 0
  97217. - 0 0 0 0 0 0 0 0 0 0 0 0
  97218. - 0 0 0 0 0 0 0 0 0 0 0 0
  97219. - 0 0 0 0 0 0 0 0 0 0 0 0
  97220. - 0 0 0 0 0 0 0 0 0 0 0 0
  97221. - 0 0 0 0 0 0 0 0 0 0 0 0
  97222. - 0 0 0 0 0 0 0 0 0 0 0 0
  97223. - 0 0 0 0 0 0 0 0 0 0 0 0
  97224. - 0 0 0 0 0 0 0 0 0 0 0 0
  97225. - 0 0 0 6 6 6 22 22 22 50 50 50
  97226. - 78 78 78 34 34 34 2 2 6 2 2 6
  97227. - 2 2 6 2 2 6 2 2 6 2 2 6
  97228. - 2 2 6 2 2 6 2 2 6 2 2 6
  97229. - 2 2 6 2 2 6 6 6 6 70 70 70
  97230. - 78 78 78 46 46 46 22 22 22 6 6 6
  97231. - 0 0 0 0 0 0 0 0 0 0 0 0
  97232. - 0 0 0 0 0 0 0 0 0 0 0 0
  97233. - 0 0 0 0 0 0 0 0 0 0 0 0
  97234. - 0 0 0 0 0 0 0 0 0 0 0 0
  97235. - 0 0 0 0 0 0 0 0 0 0 0 0
  97236. - 0 0 0 0 0 0 0 0 0 0 0 0
  97237. - 0 0 0 0 0 0 0 0 0 0 0 0
  97238. - 0 0 0 0 0 0 0 0 0 0 0 0
  97239. - 0 0 1 0 0 1 0 0 1 0 0 0
  97240. - 0 0 0 0 0 0 0 0 0 0 0 0
  97241. - 0 0 0 0 0 0 0 0 0 0 0 0
  97242. - 0 0 0 0 0 0 0 0 0 0 0 0
  97243. - 0 0 0 0 0 0 0 0 0 0 0 0
  97244. - 0 0 0 0 0 0 0 0 0 0 0 0
  97245. - 6 6 6 18 18 18 42 42 42 82 82 82
  97246. - 26 26 26 2 2 6 2 2 6 2 2 6
  97247. - 2 2 6 2 2 6 2 2 6 2 2 6
  97248. - 2 2 6 2 2 6 2 2 6 14 14 14
  97249. - 46 46 46 34 34 34 6 6 6 2 2 6
  97250. - 42 42 42 78 78 78 42 42 42 18 18 18
  97251. - 6 6 6 0 0 0 0 0 0 0 0 0
  97252. - 0 0 0 0 0 0 0 0 0 0 0 0
  97253. - 0 0 0 0 0 0 0 0 0 0 0 0
  97254. - 0 0 0 0 0 0 0 0 0 0 0 0
  97255. - 0 0 0 0 0 0 0 0 0 0 0 0
  97256. - 0 0 0 0 0 0 0 0 0 0 0 0
  97257. - 0 0 0 0 0 0 0 0 0 0 0 0
  97258. - 0 0 0 0 0 0 0 0 0 0 0 0
  97259. - 0 0 1 0 0 0 0 0 1 0 0 0
  97260. - 0 0 0 0 0 0 0 0 0 0 0 0
  97261. - 0 0 0 0 0 0 0 0 0 0 0 0
  97262. - 0 0 0 0 0 0 0 0 0 0 0 0
  97263. - 0 0 0 0 0 0 0 0 0 0 0 0
  97264. - 0 0 0 0 0 0 0 0 0 0 0 0
  97265. - 10 10 10 30 30 30 66 66 66 58 58 58
  97266. - 2 2 6 2 2 6 2 2 6 2 2 6
  97267. - 2 2 6 2 2 6 2 2 6 2 2 6
  97268. - 2 2 6 2 2 6 2 2 6 26 26 26
  97269. - 86 86 86 101 101 101 46 46 46 10 10 10
  97270. - 2 2 6 58 58 58 70 70 70 34 34 34
  97271. - 10 10 10 0 0 0 0 0 0 0 0 0
  97272. - 0 0 0 0 0 0 0 0 0 0 0 0
  97273. - 0 0 0 0 0 0 0 0 0 0 0 0
  97274. - 0 0 0 0 0 0 0 0 0 0 0 0
  97275. - 0 0 0 0 0 0 0 0 0 0 0 0
  97276. - 0 0 0 0 0 0 0 0 0 0 0 0
  97277. - 0 0 0 0 0 0 0 0 0 0 0 0
  97278. - 0 0 0 0 0 0 0 0 0 0 0 0
  97279. - 0 0 1 0 0 1 0 0 1 0 0 0
  97280. - 0 0 0 0 0 0 0 0 0 0 0 0
  97281. - 0 0 0 0 0 0 0 0 0 0 0 0
  97282. - 0 0 0 0 0 0 0 0 0 0 0 0
  97283. - 0 0 0 0 0 0 0 0 0 0 0 0
  97284. - 0 0 0 0 0 0 0 0 0 0 0 0
  97285. - 14 14 14 42 42 42 86 86 86 10 10 10
  97286. - 2 2 6 2 2 6 2 2 6 2 2 6
  97287. - 2 2 6 2 2 6 2 2 6 2 2 6
  97288. - 2 2 6 2 2 6 2 2 6 30 30 30
  97289. - 94 94 94 94 94 94 58 58 58 26 26 26
  97290. - 2 2 6 6 6 6 78 78 78 54 54 54
  97291. - 22 22 22 6 6 6 0 0 0 0 0 0
  97292. - 0 0 0 0 0 0 0 0 0 0 0 0
  97293. - 0 0 0 0 0 0 0 0 0 0 0 0
  97294. - 0 0 0 0 0 0 0 0 0 0 0 0
  97295. - 0 0 0 0 0 0 0 0 0 0 0 0
  97296. - 0 0 0 0 0 0 0 0 0 0 0 0
  97297. - 0 0 0 0 0 0 0 0 0 0 0 0
  97298. - 0 0 0 0 0 0 0 0 0 0 0 0
  97299. - 0 0 0 0 0 0 0 0 0 0 0 0
  97300. - 0 0 0 0 0 0 0 0 0 0 0 0
  97301. - 0 0 0 0 0 0 0 0 0 0 0 0
  97302. - 0 0 0 0 0 0 0 0 0 0 0 0
  97303. - 0 0 0 0 0 0 0 0 0 0 0 0
  97304. - 0 0 0 0 0 0 0 0 0 6 6 6
  97305. - 22 22 22 62 62 62 62 62 62 2 2 6
  97306. - 2 2 6 2 2 6 2 2 6 2 2 6
  97307. - 2 2 6 2 2 6 2 2 6 2 2 6
  97308. - 2 2 6 2 2 6 2 2 6 26 26 26
  97309. - 54 54 54 38 38 38 18 18 18 10 10 10
  97310. - 2 2 6 2 2 6 34 34 34 82 82 82
  97311. - 38 38 38 14 14 14 0 0 0 0 0 0
  97312. - 0 0 0 0 0 0 0 0 0 0 0 0
  97313. - 0 0 0 0 0 0 0 0 0 0 0 0
  97314. - 0 0 0 0 0 0 0 0 0 0 0 0
  97315. - 0 0 0 0 0 0 0 0 0 0 0 0
  97316. - 0 0 0 0 0 0 0 0 0 0 0 0
  97317. - 0 0 0 0 0 0 0 0 0 0 0 0
  97318. - 0 0 0 0 0 0 0 0 0 0 0 0
  97319. - 0 0 0 0 0 1 0 0 1 0 0 0
  97320. - 0 0 0 0 0 0 0 0 0 0 0 0
  97321. - 0 0 0 0 0 0 0 0 0 0 0 0
  97322. - 0 0 0 0 0 0 0 0 0 0 0 0
  97323. - 0 0 0 0 0 0 0 0 0 0 0 0
  97324. - 0 0 0 0 0 0 0 0 0 6 6 6
  97325. - 30 30 30 78 78 78 30 30 30 2 2 6
  97326. - 2 2 6 2 2 6 2 2 6 2 2 6
  97327. - 2 2 6 2 2 6 2 2 6 2 2 6
  97328. - 2 2 6 2 2 6 2 2 6 10 10 10
  97329. - 10 10 10 2 2 6 2 2 6 2 2 6
  97330. - 2 2 6 2 2 6 2 2 6 78 78 78
  97331. - 50 50 50 18 18 18 6 6 6 0 0 0
  97332. - 0 0 0 0 0 0 0 0 0 0 0 0
  97333. - 0 0 0 0 0 0 0 0 0 0 0 0
  97334. - 0 0 0 0 0 0 0 0 0 0 0 0
  97335. - 0 0 0 0 0 0 0 0 0 0 0 0
  97336. - 0 0 0 0 0 0 0 0 0 0 0 0
  97337. - 0 0 0 0 0 0 0 0 0 0 0 0
  97338. - 0 0 0 0 0 0 0 0 0 0 0 0
  97339. - 0 0 1 0 0 0 0 0 0 0 0 0
  97340. - 0 0 0 0 0 0 0 0 0 0 0 0
  97341. - 0 0 0 0 0 0 0 0 0 0 0 0
  97342. - 0 0 0 0 0 0 0 0 0 0 0 0
  97343. - 0 0 0 0 0 0 0 0 0 0 0 0
  97344. - 0 0 0 0 0 0 0 0 0 10 10 10
  97345. - 38 38 38 86 86 86 14 14 14 2 2 6
  97346. - 2 2 6 2 2 6 2 2 6 2 2 6
  97347. - 2 2 6 2 2 6 2 2 6 2 2 6
  97348. - 2 2 6 2 2 6 2 2 6 2 2 6
  97349. - 2 2 6 2 2 6 2 2 6 2 2 6
  97350. - 2 2 6 2 2 6 2 2 6 54 54 54
  97351. - 66 66 66 26 26 26 6 6 6 0 0 0
  97352. - 0 0 0 0 0 0 0 0 0 0 0 0
  97353. - 0 0 0 0 0 0 0 0 0 0 0 0
  97354. - 0 0 0 0 0 0 0 0 0 0 0 0
  97355. - 0 0 0 0 0 0 0 0 0 0 0 0
  97356. - 0 0 0 0 0 0 0 0 0 0 0 0
  97357. - 0 0 0 0 0 0 0 0 0 0 0 0
  97358. - 0 0 0 0 0 0 0 0 0 0 0 0
  97359. - 0 0 0 0 0 1 0 0 1 0 0 0
  97360. - 0 0 0 0 0 0 0 0 0 0 0 0
  97361. - 0 0 0 0 0 0 0 0 0 0 0 0
  97362. - 0 0 0 0 0 0 0 0 0 0 0 0
  97363. - 0 0 0 0 0 0 0 0 0 0 0 0
  97364. - 0 0 0 0 0 0 0 0 0 14 14 14
  97365. - 42 42 42 82 82 82 2 2 6 2 2 6
  97366. - 2 2 6 6 6 6 10 10 10 2 2 6
  97367. - 2 2 6 2 2 6 2 2 6 2 2 6
  97368. - 2 2 6 2 2 6 2 2 6 6 6 6
  97369. - 14 14 14 10 10 10 2 2 6 2 2 6
  97370. - 2 2 6 2 2 6 2 2 6 18 18 18
  97371. - 82 82 82 34 34 34 10 10 10 0 0 0
  97372. - 0 0 0 0 0 0 0 0 0 0 0 0
  97373. - 0 0 0 0 0 0 0 0 0 0 0 0
  97374. - 0 0 0 0 0 0 0 0 0 0 0 0
  97375. - 0 0 0 0 0 0 0 0 0 0 0 0
  97376. - 0 0 0 0 0 0 0 0 0 0 0 0
  97377. - 0 0 0 0 0 0 0 0 0 0 0 0
  97378. - 0 0 0 0 0 0 0 0 0 0 0 0
  97379. - 0 0 1 0 0 0 0 0 0 0 0 0
  97380. - 0 0 0 0 0 0 0 0 0 0 0 0
  97381. - 0 0 0 0 0 0 0 0 0 0 0 0
  97382. - 0 0 0 0 0 0 0 0 0 0 0 0
  97383. - 0 0 0 0 0 0 0 0 0 0 0 0
  97384. - 0 0 0 0 0 0 0 0 0 14 14 14
  97385. - 46 46 46 86 86 86 2 2 6 2 2 6
  97386. - 6 6 6 6 6 6 22 22 22 34 34 34
  97387. - 6 6 6 2 2 6 2 2 6 2 2 6
  97388. - 2 2 6 2 2 6 18 18 18 34 34 34
  97389. - 10 10 10 50 50 50 22 22 22 2 2 6
  97390. - 2 2 6 2 2 6 2 2 6 10 10 10
  97391. - 86 86 86 42 42 42 14 14 14 0 0 0
  97392. - 0 0 0 0 0 0 0 0 0 0 0 0
  97393. - 0 0 0 0 0 0 0 0 0 0 0 0
  97394. - 0 0 0 0 0 0 0 0 0 0 0 0
  97395. - 0 0 0 0 0 0 0 0 0 0 0 0
  97396. - 0 0 0 0 0 0 0 0 0 0 0 0
  97397. - 0 0 0 0 0 0 0 0 0 0 0 0
  97398. - 0 0 0 0 0 0 0 0 0 0 0 0
  97399. - 0 0 1 0 0 1 0 0 1 0 0 0
  97400. - 0 0 0 0 0 0 0 0 0 0 0 0
  97401. - 0 0 0 0 0 0 0 0 0 0 0 0
  97402. - 0 0 0 0 0 0 0 0 0 0 0 0
  97403. - 0 0 0 0 0 0 0 0 0 0 0 0
  97404. - 0 0 0 0 0 0 0 0 0 14 14 14
  97405. - 46 46 46 86 86 86 2 2 6 2 2 6
  97406. - 38 38 38 116 116 116 94 94 94 22 22 22
  97407. - 22 22 22 2 2 6 2 2 6 2 2 6
  97408. - 14 14 14 86 86 86 138 138 138 162 162 162
  97409. -154 154 154 38 38 38 26 26 26 6 6 6
  97410. - 2 2 6 2 2 6 2 2 6 2 2 6
  97411. - 86 86 86 46 46 46 14 14 14 0 0 0
  97412. - 0 0 0 0 0 0 0 0 0 0 0 0
  97413. - 0 0 0 0 0 0 0 0 0 0 0 0
  97414. - 0 0 0 0 0 0 0 0 0 0 0 0
  97415. - 0 0 0 0 0 0 0 0 0 0 0 0
  97416. - 0 0 0 0 0 0 0 0 0 0 0 0
  97417. - 0 0 0 0 0 0 0 0 0 0 0 0
  97418. - 0 0 0 0 0 0 0 0 0 0 0 0
  97419. - 0 0 0 0 0 0 0 0 0 0 0 0
  97420. - 0 0 0 0 0 0 0 0 0 0 0 0
  97421. - 0 0 0 0 0 0 0 0 0 0 0 0
  97422. - 0 0 0 0 0 0 0 0 0 0 0 0
  97423. - 0 0 0 0 0 0 0 0 0 0 0 0
  97424. - 0 0 0 0 0 0 0 0 0 14 14 14
  97425. - 46 46 46 86 86 86 2 2 6 14 14 14
  97426. -134 134 134 198 198 198 195 195 195 116 116 116
  97427. - 10 10 10 2 2 6 2 2 6 6 6 6
  97428. -101 98 89 187 187 187 210 210 210 218 218 218
  97429. -214 214 214 134 134 134 14 14 14 6 6 6
  97430. - 2 2 6 2 2 6 2 2 6 2 2 6
  97431. - 86 86 86 50 50 50 18 18 18 6 6 6
  97432. - 0 0 0 0 0 0 0 0 0 0 0 0
  97433. - 0 0 0 0 0 0 0 0 0 0 0 0
  97434. - 0 0 0 0 0 0 0 0 0 0 0 0
  97435. - 0 0 0 0 0 0 0 0 0 0 0 0
  97436. - 0 0 0 0 0 0 0 0 0 0 0 0
  97437. - 0 0 0 0 0 0 0 0 0 0 0 0
  97438. - 0 0 0 0 0 0 0 0 1 0 0 0
  97439. - 0 0 1 0 0 1 0 0 1 0 0 0
  97440. - 0 0 0 0 0 0 0 0 0 0 0 0
  97441. - 0 0 0 0 0 0 0 0 0 0 0 0
  97442. - 0 0 0 0 0 0 0 0 0 0 0 0
  97443. - 0 0 0 0 0 0 0 0 0 0 0 0
  97444. - 0 0 0 0 0 0 0 0 0 14 14 14
  97445. - 46 46 46 86 86 86 2 2 6 54 54 54
  97446. -218 218 218 195 195 195 226 226 226 246 246 246
  97447. - 58 58 58 2 2 6 2 2 6 30 30 30
  97448. -210 210 210 253 253 253 174 174 174 123 123 123
  97449. -221 221 221 234 234 234 74 74 74 2 2 6
  97450. - 2 2 6 2 2 6 2 2 6 2 2 6
  97451. - 70 70 70 58 58 58 22 22 22 6 6 6
  97452. - 0 0 0 0 0 0 0 0 0 0 0 0
  97453. - 0 0 0 0 0 0 0 0 0 0 0 0
  97454. - 0 0 0 0 0 0 0 0 0 0 0 0
  97455. - 0 0 0 0 0 0 0 0 0 0 0 0
  97456. - 0 0 0 0 0 0 0 0 0 0 0 0
  97457. - 0 0 0 0 0 0 0 0 0 0 0 0
  97458. - 0 0 0 0 0 0 0 0 0 0 0 0
  97459. - 0 0 0 0 0 0 0 0 0 0 0 0
  97460. - 0 0 0 0 0 0 0 0 0 0 0 0
  97461. - 0 0 0 0 0 0 0 0 0 0 0 0
  97462. - 0 0 0 0 0 0 0 0 0 0 0 0
  97463. - 0 0 0 0 0 0 0 0 0 0 0 0
  97464. - 0 0 0 0 0 0 0 0 0 14 14 14
  97465. - 46 46 46 82 82 82 2 2 6 106 106 106
  97466. -170 170 170 26 26 26 86 86 86 226 226 226
  97467. -123 123 123 10 10 10 14 14 14 46 46 46
  97468. -231 231 231 190 190 190 6 6 6 70 70 70
  97469. - 90 90 90 238 238 238 158 158 158 2 2 6
  97470. - 2 2 6 2 2 6 2 2 6 2 2 6
  97471. - 70 70 70 58 58 58 22 22 22 6 6 6
  97472. - 0 0 0 0 0 0 0 0 0 0 0 0
  97473. - 0 0 0 0 0 0 0 0 0 0 0 0
  97474. - 0 0 0 0 0 0 0 0 0 0 0 0
  97475. - 0 0 0 0 0 0 0 0 0 0 0 0
  97476. - 0 0 0 0 0 0 0 0 0 0 0 0
  97477. - 0 0 0 0 0 0 0 0 0 0 0 0
  97478. - 0 0 0 0 0 0 0 0 1 0 0 0
  97479. - 0 0 1 0 0 1 0 0 1 0 0 0
  97480. - 0 0 0 0 0 0 0 0 0 0 0 0
  97481. - 0 0 0 0 0 0 0 0 0 0 0 0
  97482. - 0 0 0 0 0 0 0 0 0 0 0 0
  97483. - 0 0 0 0 0 0 0 0 0 0 0 0
  97484. - 0 0 0 0 0 0 0 0 0 14 14 14
  97485. - 42 42 42 86 86 86 6 6 6 116 116 116
  97486. -106 106 106 6 6 6 70 70 70 149 149 149
  97487. -128 128 128 18 18 18 38 38 38 54 54 54
  97488. -221 221 221 106 106 106 2 2 6 14 14 14
  97489. - 46 46 46 190 190 190 198 198 198 2 2 6
  97490. - 2 2 6 2 2 6 2 2 6 2 2 6
  97491. - 74 74 74 62 62 62 22 22 22 6 6 6
  97492. - 0 0 0 0 0 0 0 0 0 0 0 0
  97493. - 0 0 0 0 0 0 0 0 0 0 0 0
  97494. - 0 0 0 0 0 0 0 0 0 0 0 0
  97495. - 0 0 0 0 0 0 0 0 0 0 0 0
  97496. - 0 0 0 0 0 0 0 0 0 0 0 0
  97497. - 0 0 0 0 0 0 0 0 0 0 0 0
  97498. - 0 0 0 0 0 0 0 0 1 0 0 0
  97499. - 0 0 1 0 0 0 0 0 1 0 0 0
  97500. - 0 0 0 0 0 0 0 0 0 0 0 0
  97501. - 0 0 0 0 0 0 0 0 0 0 0 0
  97502. - 0 0 0 0 0 0 0 0 0 0 0 0
  97503. - 0 0 0 0 0 0 0 0 0 0 0 0
  97504. - 0 0 0 0 0 0 0 0 0 14 14 14
  97505. - 42 42 42 94 94 94 14 14 14 101 101 101
  97506. -128 128 128 2 2 6 18 18 18 116 116 116
  97507. -118 98 46 121 92 8 121 92 8 98 78 10
  97508. -162 162 162 106 106 106 2 2 6 2 2 6
  97509. - 2 2 6 195 195 195 195 195 195 6 6 6
  97510. - 2 2 6 2 2 6 2 2 6 2 2 6
  97511. - 74 74 74 62 62 62 22 22 22 6 6 6
  97512. - 0 0 0 0 0 0 0 0 0 0 0 0
  97513. - 0 0 0 0 0 0 0 0 0 0 0 0
  97514. - 0 0 0 0 0 0 0 0 0 0 0 0
  97515. - 0 0 0 0 0 0 0 0 0 0 0 0
  97516. - 0 0 0 0 0 0 0 0 0 0 0 0
  97517. - 0 0 0 0 0 0 0 0 0 0 0 0
  97518. - 0 0 0 0 0 0 0 0 1 0 0 1
  97519. - 0 0 1 0 0 0 0 0 1 0 0 0
  97520. - 0 0 0 0 0 0 0 0 0 0 0 0
  97521. - 0 0 0 0 0 0 0 0 0 0 0 0
  97522. - 0 0 0 0 0 0 0 0 0 0 0 0
  97523. - 0 0 0 0 0 0 0 0 0 0 0 0
  97524. - 0 0 0 0 0 0 0 0 0 10 10 10
  97525. - 38 38 38 90 90 90 14 14 14 58 58 58
  97526. -210 210 210 26 26 26 54 38 6 154 114 10
  97527. -226 170 11 236 186 11 225 175 15 184 144 12
  97528. -215 174 15 175 146 61 37 26 9 2 2 6
  97529. - 70 70 70 246 246 246 138 138 138 2 2 6
  97530. - 2 2 6 2 2 6 2 2 6 2 2 6
  97531. - 70 70 70 66 66 66 26 26 26 6 6 6
  97532. - 0 0 0 0 0 0 0 0 0 0 0 0
  97533. - 0 0 0 0 0 0 0 0 0 0 0 0
  97534. - 0 0 0 0 0 0 0 0 0 0 0 0
  97535. - 0 0 0 0 0 0 0 0 0 0 0 0
  97536. - 0 0 0 0 0 0 0 0 0 0 0 0
  97537. - 0 0 0 0 0 0 0 0 0 0 0 0
  97538. - 0 0 0 0 0 0 0 0 0 0 0 0
  97539. - 0 0 0 0 0 0 0 0 0 0 0 0
  97540. - 0 0 0 0 0 0 0 0 0 0 0 0
  97541. - 0 0 0 0 0 0 0 0 0 0 0 0
  97542. - 0 0 0 0 0 0 0 0 0 0 0 0
  97543. - 0 0 0 0 0 0 0 0 0 0 0 0
  97544. - 0 0 0 0 0 0 0 0 0 10 10 10
  97545. - 38 38 38 86 86 86 14 14 14 10 10 10
  97546. -195 195 195 188 164 115 192 133 9 225 175 15
  97547. -239 182 13 234 190 10 232 195 16 232 200 30
  97548. -245 207 45 241 208 19 232 195 16 184 144 12
  97549. -218 194 134 211 206 186 42 42 42 2 2 6
  97550. - 2 2 6 2 2 6 2 2 6 2 2 6
  97551. - 50 50 50 74 74 74 30 30 30 6 6 6
  97552. - 0 0 0 0 0 0 0 0 0 0 0 0
  97553. - 0 0 0 0 0 0 0 0 0 0 0 0
  97554. - 0 0 0 0 0 0 0 0 0 0 0 0
  97555. - 0 0 0 0 0 0 0 0 0 0 0 0
  97556. - 0 0 0 0 0 0 0 0 0 0 0 0
  97557. - 0 0 0 0 0 0 0 0 0 0 0 0
  97558. - 0 0 0 0 0 0 0 0 0 0 0 0
  97559. - 0 0 0 0 0 0 0 0 0 0 0 0
  97560. - 0 0 0 0 0 0 0 0 0 0 0 0
  97561. - 0 0 0 0 0 0 0 0 0 0 0 0
  97562. - 0 0 0 0 0 0 0 0 0 0 0 0
  97563. - 0 0 0 0 0 0 0 0 0 0 0 0
  97564. - 0 0 0 0 0 0 0 0 0 10 10 10
  97565. - 34 34 34 86 86 86 14 14 14 2 2 6
  97566. -121 87 25 192 133 9 219 162 10 239 182 13
  97567. -236 186 11 232 195 16 241 208 19 244 214 54
  97568. -246 218 60 246 218 38 246 215 20 241 208 19
  97569. -241 208 19 226 184 13 121 87 25 2 2 6
  97570. - 2 2 6 2 2 6 2 2 6 2 2 6
  97571. - 50 50 50 82 82 82 34 34 34 10 10 10
  97572. - 0 0 0 0 0 0 0 0 0 0 0 0
  97573. - 0 0 0 0 0 0 0 0 0 0 0 0
  97574. - 0 0 0 0 0 0 0 0 0 0 0 0
  97575. - 0 0 0 0 0 0 0 0 0 0 0 0
  97576. - 0 0 0 0 0 0 0 0 0 0 0 0
  97577. - 0 0 0 0 0 0 0 0 0 0 0 0
  97578. - 0 0 0 0 0 0 0 0 0 0 0 0
  97579. - 0 0 0 0 0 0 0 0 0 0 0 0
  97580. - 0 0 0 0 0 0 0 0 0 0 0 0
  97581. - 0 0 0 0 0 0 0 0 0 0 0 0
  97582. - 0 0 0 0 0 0 0 0 0 0 0 0
  97583. - 0 0 0 0 0 0 0 0 0 0 0 0
  97584. - 0 0 0 0 0 0 0 0 0 10 10 10
  97585. - 34 34 34 82 82 82 30 30 30 61 42 6
  97586. -180 123 7 206 145 10 230 174 11 239 182 13
  97587. -234 190 10 238 202 15 241 208 19 246 218 74
  97588. -246 218 38 246 215 20 246 215 20 246 215 20
  97589. -226 184 13 215 174 15 184 144 12 6 6 6
  97590. - 2 2 6 2 2 6 2 2 6 2 2 6
  97591. - 26 26 26 94 94 94 42 42 42 14 14 14
  97592. - 0 0 0 0 0 0 0 0 0 0 0 0
  97593. - 0 0 0 0 0 0 0 0 0 0 0 0
  97594. - 0 0 0 0 0 0 0 0 0 0 0 0
  97595. - 0 0 0 0 0 0 0 0 0 0 0 0
  97596. - 0 0 0 0 0 0 0 0 0 0 0 0
  97597. - 0 0 0 0 0 0 0 0 0 0 0 0
  97598. - 0 0 0 0 0 0 0 0 0 0 0 0
  97599. - 0 0 0 0 0 0 0 0 0 0 0 0
  97600. - 0 0 0 0 0 0 0 0 0 0 0 0
  97601. - 0 0 0 0 0 0 0 0 0 0 0 0
  97602. - 0 0 0 0 0 0 0 0 0 0 0 0
  97603. - 0 0 0 0 0 0 0 0 0 0 0 0
  97604. - 0 0 0 0 0 0 0 0 0 10 10 10
  97605. - 30 30 30 78 78 78 50 50 50 104 69 6
  97606. -192 133 9 216 158 10 236 178 12 236 186 11
  97607. -232 195 16 241 208 19 244 214 54 245 215 43
  97608. -246 215 20 246 215 20 241 208 19 198 155 10
  97609. -200 144 11 216 158 10 156 118 10 2 2 6
  97610. - 2 2 6 2 2 6 2 2 6 2 2 6
  97611. - 6 6 6 90 90 90 54 54 54 18 18 18
  97612. - 6 6 6 0 0 0 0 0 0 0 0 0
  97613. - 0 0 0 0 0 0 0 0 0 0 0 0
  97614. - 0 0 0 0 0 0 0 0 0 0 0 0
  97615. - 0 0 0 0 0 0 0 0 0 0 0 0
  97616. - 0 0 0 0 0 0 0 0 0 0 0 0
  97617. - 0 0 0 0 0 0 0 0 0 0 0 0
  97618. - 0 0 0 0 0 0 0 0 0 0 0 0
  97619. - 0 0 0 0 0 0 0 0 0 0 0 0
  97620. - 0 0 0 0 0 0 0 0 0 0 0 0
  97621. - 0 0 0 0 0 0 0 0 0 0 0 0
  97622. - 0 0 0 0 0 0 0 0 0 0 0 0
  97623. - 0 0 0 0 0 0 0 0 0 0 0 0
  97624. - 0 0 0 0 0 0 0 0 0 10 10 10
  97625. - 30 30 30 78 78 78 46 46 46 22 22 22
  97626. -137 92 6 210 162 10 239 182 13 238 190 10
  97627. -238 202 15 241 208 19 246 215 20 246 215 20
  97628. -241 208 19 203 166 17 185 133 11 210 150 10
  97629. -216 158 10 210 150 10 102 78 10 2 2 6
  97630. - 6 6 6 54 54 54 14 14 14 2 2 6
  97631. - 2 2 6 62 62 62 74 74 74 30 30 30
  97632. - 10 10 10 0 0 0 0 0 0 0 0 0
  97633. - 0 0 0 0 0 0 0 0 0 0 0 0
  97634. - 0 0 0 0 0 0 0 0 0 0 0 0
  97635. - 0 0 0 0 0 0 0 0 0 0 0 0
  97636. - 0 0 0 0 0 0 0 0 0 0 0 0
  97637. - 0 0 0 0 0 0 0 0 0 0 0 0
  97638. - 0 0 0 0 0 0 0 0 0 0 0 0
  97639. - 0 0 0 0 0 0 0 0 0 0 0 0
  97640. - 0 0 0 0 0 0 0 0 0 0 0 0
  97641. - 0 0 0 0 0 0 0 0 0 0 0 0
  97642. - 0 0 0 0 0 0 0 0 0 0 0 0
  97643. - 0 0 0 0 0 0 0 0 0 0 0 0
  97644. - 0 0 0 0 0 0 0 0 0 10 10 10
  97645. - 34 34 34 78 78 78 50 50 50 6 6 6
  97646. - 94 70 30 139 102 15 190 146 13 226 184 13
  97647. -232 200 30 232 195 16 215 174 15 190 146 13
  97648. -168 122 10 192 133 9 210 150 10 213 154 11
  97649. -202 150 34 182 157 106 101 98 89 2 2 6
  97650. - 2 2 6 78 78 78 116 116 116 58 58 58
  97651. - 2 2 6 22 22 22 90 90 90 46 46 46
  97652. - 18 18 18 6 6 6 0 0 0 0 0 0
  97653. - 0 0 0 0 0 0 0 0 0 0 0 0
  97654. - 0 0 0 0 0 0 0 0 0 0 0 0
  97655. - 0 0 0 0 0 0 0 0 0 0 0 0
  97656. - 0 0 0 0 0 0 0 0 0 0 0 0
  97657. - 0 0 0 0 0 0 0 0 0 0 0 0
  97658. - 0 0 0 0 0 0 0 0 0 0 0 0
  97659. - 0 0 0 0 0 0 0 0 0 0 0 0
  97660. - 0 0 0 0 0 0 0 0 0 0 0 0
  97661. - 0 0 0 0 0 0 0 0 0 0 0 0
  97662. - 0 0 0 0 0 0 0 0 0 0 0 0
  97663. - 0 0 0 0 0 0 0 0 0 0 0 0
  97664. - 0 0 0 0 0 0 0 0 0 10 10 10
  97665. - 38 38 38 86 86 86 50 50 50 6 6 6
  97666. -128 128 128 174 154 114 156 107 11 168 122 10
  97667. -198 155 10 184 144 12 197 138 11 200 144 11
  97668. -206 145 10 206 145 10 197 138 11 188 164 115
  97669. -195 195 195 198 198 198 174 174 174 14 14 14
  97670. - 2 2 6 22 22 22 116 116 116 116 116 116
  97671. - 22 22 22 2 2 6 74 74 74 70 70 70
  97672. - 30 30 30 10 10 10 0 0 0 0 0 0
  97673. - 0 0 0 0 0 0 0 0 0 0 0 0
  97674. - 0 0 0 0 0 0 0 0 0 0 0 0
  97675. - 0 0 0 0 0 0 0 0 0 0 0 0
  97676. - 0 0 0 0 0 0 0 0 0 0 0 0
  97677. - 0 0 0 0 0 0 0 0 0 0 0 0
  97678. - 0 0 0 0 0 0 0 0 0 0 0 0
  97679. - 0 0 0 0 0 0 0 0 0 0 0 0
  97680. - 0 0 0 0 0 0 0 0 0 0 0 0
  97681. - 0 0 0 0 0 0 0 0 0 0 0 0
  97682. - 0 0 0 0 0 0 0 0 0 0 0 0
  97683. - 0 0 0 0 0 0 0 0 0 0 0 0
  97684. - 0 0 0 0 0 0 6 6 6 18 18 18
  97685. - 50 50 50 101 101 101 26 26 26 10 10 10
  97686. -138 138 138 190 190 190 174 154 114 156 107 11
  97687. -197 138 11 200 144 11 197 138 11 192 133 9
  97688. -180 123 7 190 142 34 190 178 144 187 187 187
  97689. -202 202 202 221 221 221 214 214 214 66 66 66
  97690. - 2 2 6 2 2 6 50 50 50 62 62 62
  97691. - 6 6 6 2 2 6 10 10 10 90 90 90
  97692. - 50 50 50 18 18 18 6 6 6 0 0 0
  97693. - 0 0 0 0 0 0 0 0 0 0 0 0
  97694. - 0 0 0 0 0 0 0 0 0 0 0 0
  97695. - 0 0 0 0 0 0 0 0 0 0 0 0
  97696. - 0 0 0 0 0 0 0 0 0 0 0 0
  97697. - 0 0 0 0 0 0 0 0 0 0 0 0
  97698. - 0 0 0 0 0 0 0 0 0 0 0 0
  97699. - 0 0 0 0 0 0 0 0 0 0 0 0
  97700. - 0 0 0 0 0 0 0 0 0 0 0 0
  97701. - 0 0 0 0 0 0 0 0 0 0 0 0
  97702. - 0 0 0 0 0 0 0 0 0 0 0 0
  97703. - 0 0 0 0 0 0 0 0 0 0 0 0
  97704. - 0 0 0 0 0 0 10 10 10 34 34 34
  97705. - 74 74 74 74 74 74 2 2 6 6 6 6
  97706. -144 144 144 198 198 198 190 190 190 178 166 146
  97707. -154 121 60 156 107 11 156 107 11 168 124 44
  97708. -174 154 114 187 187 187 190 190 190 210 210 210
  97709. -246 246 246 253 253 253 253 253 253 182 182 182
  97710. - 6 6 6 2 2 6 2 2 6 2 2 6
  97711. - 2 2 6 2 2 6 2 2 6 62 62 62
  97712. - 74 74 74 34 34 34 14 14 14 0 0 0
  97713. - 0 0 0 0 0 0 0 0 0 0 0 0
  97714. - 0 0 0 0 0 0 0 0 0 0 0 0
  97715. - 0 0 0 0 0 0 0 0 0 0 0 0
  97716. - 0 0 0 0 0 0 0 0 0 0 0 0
  97717. - 0 0 0 0 0 0 0 0 0 0 0 0
  97718. - 0 0 0 0 0 0 0 0 0 0 0 0
  97719. - 0 0 0 0 0 0 0 0 0 0 0 0
  97720. - 0 0 0 0 0 0 0 0 0 0 0 0
  97721. - 0 0 0 0 0 0 0 0 0 0 0 0
  97722. - 0 0 0 0 0 0 0 0 0 0 0 0
  97723. - 0 0 0 0 0 0 0 0 0 0 0 0
  97724. - 0 0 0 10 10 10 22 22 22 54 54 54
  97725. - 94 94 94 18 18 18 2 2 6 46 46 46
  97726. -234 234 234 221 221 221 190 190 190 190 190 190
  97727. -190 190 190 187 187 187 187 187 187 190 190 190
  97728. -190 190 190 195 195 195 214 214 214 242 242 242
  97729. -253 253 253 253 253 253 253 253 253 253 253 253
  97730. - 82 82 82 2 2 6 2 2 6 2 2 6
  97731. - 2 2 6 2 2 6 2 2 6 14 14 14
  97732. - 86 86 86 54 54 54 22 22 22 6 6 6
  97733. - 0 0 0 0 0 0 0 0 0 0 0 0
  97734. - 0 0 0 0 0 0 0 0 0 0 0 0
  97735. - 0 0 0 0 0 0 0 0 0 0 0 0
  97736. - 0 0 0 0 0 0 0 0 0 0 0 0
  97737. - 0 0 0 0 0 0 0 0 0 0 0 0
  97738. - 0 0 0 0 0 0 0 0 0 0 0 0
  97739. - 0 0 0 0 0 0 0 0 0 0 0 0
  97740. - 0 0 0 0 0 0 0 0 0 0 0 0
  97741. - 0 0 0 0 0 0 0 0 0 0 0 0
  97742. - 0 0 0 0 0 0 0 0 0 0 0 0
  97743. - 0 0 0 0 0 0 0 0 0 0 0 0
  97744. - 6 6 6 18 18 18 46 46 46 90 90 90
  97745. - 46 46 46 18 18 18 6 6 6 182 182 182
  97746. -253 253 253 246 246 246 206 206 206 190 190 190
  97747. -190 190 190 190 190 190 190 190 190 190 190 190
  97748. -206 206 206 231 231 231 250 250 250 253 253 253
  97749. -253 253 253 253 253 253 253 253 253 253 253 253
  97750. -202 202 202 14 14 14 2 2 6 2 2 6
  97751. - 2 2 6 2 2 6 2 2 6 2 2 6
  97752. - 42 42 42 86 86 86 42 42 42 18 18 18
  97753. - 6 6 6 0 0 0 0 0 0 0 0 0
  97754. - 0 0 0 0 0 0 0 0 0 0 0 0
  97755. - 0 0 0 0 0 0 0 0 0 0 0 0
  97756. - 0 0 0 0 0 0 0 0 0 0 0 0
  97757. - 0 0 0 0 0 0 0 0 0 0 0 0
  97758. - 0 0 0 0 0 0 0 0 0 0 0 0
  97759. - 0 0 0 0 0 0 0 0 0 0 0 0
  97760. - 0 0 0 0 0 0 0 0 0 0 0 0
  97761. - 0 0 0 0 0 0 0 0 0 0 0 0
  97762. - 0 0 0 0 0 0 0 0 0 0 0 0
  97763. - 0 0 0 0 0 0 0 0 0 6 6 6
  97764. - 14 14 14 38 38 38 74 74 74 66 66 66
  97765. - 2 2 6 6 6 6 90 90 90 250 250 250
  97766. -253 253 253 253 253 253 238 238 238 198 198 198
  97767. -190 190 190 190 190 190 195 195 195 221 221 221
  97768. -246 246 246 253 253 253 253 253 253 253 253 253
  97769. -253 253 253 253 253 253 253 253 253 253 253 253
  97770. -253 253 253 82 82 82 2 2 6 2 2 6
  97771. - 2 2 6 2 2 6 2 2 6 2 2 6
  97772. - 2 2 6 78 78 78 70 70 70 34 34 34
  97773. - 14 14 14 6 6 6 0 0 0 0 0 0
  97774. - 0 0 0 0 0 0 0 0 0 0 0 0
  97775. - 0 0 0 0 0 0 0 0 0 0 0 0
  97776. - 0 0 0 0 0 0 0 0 0 0 0 0
  97777. - 0 0 0 0 0 0 0 0 0 0 0 0
  97778. - 0 0 0 0 0 0 0 0 0 0 0 0
  97779. - 0 0 0 0 0 0 0 0 0 0 0 0
  97780. - 0 0 0 0 0 0 0 0 0 0 0 0
  97781. - 0 0 0 0 0 0 0 0 0 0 0 0
  97782. - 0 0 0 0 0 0 0 0 0 0 0 0
  97783. - 0 0 0 0 0 0 0 0 0 14 14 14
  97784. - 34 34 34 66 66 66 78 78 78 6 6 6
  97785. - 2 2 6 18 18 18 218 218 218 253 253 253
  97786. -253 253 253 253 253 253 253 253 253 246 246 246
  97787. -226 226 226 231 231 231 246 246 246 253 253 253
  97788. -253 253 253 253 253 253 253 253 253 253 253 253
  97789. -253 253 253 253 253 253 253 253 253 253 253 253
  97790. -253 253 253 178 178 178 2 2 6 2 2 6
  97791. - 2 2 6 2 2 6 2 2 6 2 2 6
  97792. - 2 2 6 18 18 18 90 90 90 62 62 62
  97793. - 30 30 30 10 10 10 0 0 0 0 0 0
  97794. - 0 0 0 0 0 0 0 0 0 0 0 0
  97795. - 0 0 0 0 0 0 0 0 0 0 0 0
  97796. - 0 0 0 0 0 0 0 0 0 0 0 0
  97797. - 0 0 0 0 0 0 0 0 0 0 0 0
  97798. - 0 0 0 0 0 0 0 0 0 0 0 0
  97799. - 0 0 0 0 0 0 0 0 0 0 0 0
  97800. - 0 0 0 0 0 0 0 0 0 0 0 0
  97801. - 0 0 0 0 0 0 0 0 0 0 0 0
  97802. - 0 0 0 0 0 0 0 0 0 0 0 0
  97803. - 0 0 0 0 0 0 10 10 10 26 26 26
  97804. - 58 58 58 90 90 90 18 18 18 2 2 6
  97805. - 2 2 6 110 110 110 253 253 253 253 253 253
  97806. -253 253 253 253 253 253 253 253 253 253 253 253
  97807. -250 250 250 253 253 253 253 253 253 253 253 253
  97808. -253 253 253 253 253 253 253 253 253 253 253 253
  97809. -253 253 253 253 253 253 253 253 253 253 253 253
  97810. -253 253 253 231 231 231 18 18 18 2 2 6
  97811. - 2 2 6 2 2 6 2 2 6 2 2 6
  97812. - 2 2 6 2 2 6 18 18 18 94 94 94
  97813. - 54 54 54 26 26 26 10 10 10 0 0 0
  97814. - 0 0 0 0 0 0 0 0 0 0 0 0
  97815. - 0 0 0 0 0 0 0 0 0 0 0 0
  97816. - 0 0 0 0 0 0 0 0 0 0 0 0
  97817. - 0 0 0 0 0 0 0 0 0 0 0 0
  97818. - 0 0 0 0 0 0 0 0 0 0 0 0
  97819. - 0 0 0 0 0 0 0 0 0 0 0 0
  97820. - 0 0 0 0 0 0 0 0 0 0 0 0
  97821. - 0 0 0 0 0 0 0 0 0 0 0 0
  97822. - 0 0 0 0 0 0 0 0 0 0 0 0
  97823. - 0 0 0 6 6 6 22 22 22 50 50 50
  97824. - 90 90 90 26 26 26 2 2 6 2 2 6
  97825. - 14 14 14 195 195 195 250 250 250 253 253 253
  97826. -253 253 253 253 253 253 253 253 253 253 253 253
  97827. -253 253 253 253 253 253 253 253 253 253 253 253
  97828. -253 253 253 253 253 253 253 253 253 253 253 253
  97829. -253 253 253 253 253 253 253 253 253 253 253 253
  97830. -250 250 250 242 242 242 54 54 54 2 2 6
  97831. - 2 2 6 2 2 6 2 2 6 2 2 6
  97832. - 2 2 6 2 2 6 2 2 6 38 38 38
  97833. - 86 86 86 50 50 50 22 22 22 6 6 6
  97834. - 0 0 0 0 0 0 0 0 0 0 0 0
  97835. - 0 0 0 0 0 0 0 0 0 0 0 0
  97836. - 0 0 0 0 0 0 0 0 0 0 0 0
  97837. - 0 0 0 0 0 0 0 0 0 0 0 0
  97838. - 0 0 0 0 0 0 0 0 0 0 0 0
  97839. - 0 0 0 0 0 0 0 0 0 0 0 0
  97840. - 0 0 0 0 0 0 0 0 0 0 0 0
  97841. - 0 0 0 0 0 0 0 0 0 0 0 0
  97842. - 0 0 0 0 0 0 0 0 0 0 0 0
  97843. - 6 6 6 14 14 14 38 38 38 82 82 82
  97844. - 34 34 34 2 2 6 2 2 6 2 2 6
  97845. - 42 42 42 195 195 195 246 246 246 253 253 253
  97846. -253 253 253 253 253 253 253 253 253 250 250 250
  97847. -242 242 242 242 242 242 250 250 250 253 253 253
  97848. -253 253 253 253 253 253 253 253 253 253 253 253
  97849. -253 253 253 250 250 250 246 246 246 238 238 238
  97850. -226 226 226 231 231 231 101 101 101 6 6 6
  97851. - 2 2 6 2 2 6 2 2 6 2 2 6
  97852. - 2 2 6 2 2 6 2 2 6 2 2 6
  97853. - 38 38 38 82 82 82 42 42 42 14 14 14
  97854. - 6 6 6 0 0 0 0 0 0 0 0 0
  97855. - 0 0 0 0 0 0 0 0 0 0 0 0
  97856. - 0 0 0 0 0 0 0 0 0 0 0 0
  97857. - 0 0 0 0 0 0 0 0 0 0 0 0
  97858. - 0 0 0 0 0 0 0 0 0 0 0 0
  97859. - 0 0 0 0 0 0 0 0 0 0 0 0
  97860. - 0 0 0 0 0 0 0 0 0 0 0 0
  97861. - 0 0 0 0 0 0 0 0 0 0 0 0
  97862. - 0 0 0 0 0 0 0 0 0 0 0 0
  97863. - 10 10 10 26 26 26 62 62 62 66 66 66
  97864. - 2 2 6 2 2 6 2 2 6 6 6 6
  97865. - 70 70 70 170 170 170 206 206 206 234 234 234
  97866. -246 246 246 250 250 250 250 250 250 238 238 238
  97867. -226 226 226 231 231 231 238 238 238 250 250 250
  97868. -250 250 250 250 250 250 246 246 246 231 231 231
  97869. -214 214 214 206 206 206 202 202 202 202 202 202
  97870. -198 198 198 202 202 202 182 182 182 18 18 18
  97871. - 2 2 6 2 2 6 2 2 6 2 2 6
  97872. - 2 2 6 2 2 6 2 2 6 2 2 6
  97873. - 2 2 6 62 62 62 66 66 66 30 30 30
  97874. - 10 10 10 0 0 0 0 0 0 0 0 0
  97875. - 0 0 0 0 0 0 0 0 0 0 0 0
  97876. - 0 0 0 0 0 0 0 0 0 0 0 0
  97877. - 0 0 0 0 0 0 0 0 0 0 0 0
  97878. - 0 0 0 0 0 0 0 0 0 0 0 0
  97879. - 0 0 0 0 0 0 0 0 0 0 0 0
  97880. - 0 0 0 0 0 0 0 0 0 0 0 0
  97881. - 0 0 0 0 0 0 0 0 0 0 0 0
  97882. - 0 0 0 0 0 0 0 0 0 0 0 0
  97883. - 14 14 14 42 42 42 82 82 82 18 18 18
  97884. - 2 2 6 2 2 6 2 2 6 10 10 10
  97885. - 94 94 94 182 182 182 218 218 218 242 242 242
  97886. -250 250 250 253 253 253 253 253 253 250 250 250
  97887. -234 234 234 253 253 253 253 253 253 253 253 253
  97888. -253 253 253 253 253 253 253 253 253 246 246 246
  97889. -238 238 238 226 226 226 210 210 210 202 202 202
  97890. -195 195 195 195 195 195 210 210 210 158 158 158
  97891. - 6 6 6 14 14 14 50 50 50 14 14 14
  97892. - 2 2 6 2 2 6 2 2 6 2 2 6
  97893. - 2 2 6 6 6 6 86 86 86 46 46 46
  97894. - 18 18 18 6 6 6 0 0 0 0 0 0
  97895. - 0 0 0 0 0 0 0 0 0 0 0 0
  97896. - 0 0 0 0 0 0 0 0 0 0 0 0
  97897. - 0 0 0 0 0 0 0 0 0 0 0 0
  97898. - 0 0 0 0 0 0 0 0 0 0 0 0
  97899. - 0 0 0 0 0 0 0 0 0 0 0 0
  97900. - 0 0 0 0 0 0 0 0 0 0 0 0
  97901. - 0 0 0 0 0 0 0 0 0 0 0 0
  97902. - 0 0 0 0 0 0 0 0 0 6 6 6
  97903. - 22 22 22 54 54 54 70 70 70 2 2 6
  97904. - 2 2 6 10 10 10 2 2 6 22 22 22
  97905. -166 166 166 231 231 231 250 250 250 253 253 253
  97906. -253 253 253 253 253 253 253 253 253 250 250 250
  97907. -242 242 242 253 253 253 253 253 253 253 253 253
  97908. -253 253 253 253 253 253 253 253 253 253 253 253
  97909. -253 253 253 253 253 253 253 253 253 246 246 246
  97910. -231 231 231 206 206 206 198 198 198 226 226 226
  97911. - 94 94 94 2 2 6 6 6 6 38 38 38
  97912. - 30 30 30 2 2 6 2 2 6 2 2 6
  97913. - 2 2 6 2 2 6 62 62 62 66 66 66
  97914. - 26 26 26 10 10 10 0 0 0 0 0 0
  97915. - 0 0 0 0 0 0 0 0 0 0 0 0
  97916. - 0 0 0 0 0 0 0 0 0 0 0 0
  97917. - 0 0 0 0 0 0 0 0 0 0 0 0
  97918. - 0 0 0 0 0 0 0 0 0 0 0 0
  97919. - 0 0 0 0 0 0 0 0 0 0 0 0
  97920. - 0 0 0 0 0 0 0 0 0 0 0 0
  97921. - 0 0 0 0 0 0 0 0 0 0 0 0
  97922. - 0 0 0 0 0 0 0 0 0 10 10 10
  97923. - 30 30 30 74 74 74 50 50 50 2 2 6
  97924. - 26 26 26 26 26 26 2 2 6 106 106 106
  97925. -238 238 238 253 253 253 253 253 253 253 253 253
  97926. -253 253 253 253 253 253 253 253 253 253 253 253
  97927. -253 253 253 253 253 253 253 253 253 253 253 253
  97928. -253 253 253 253 253 253 253 253 253 253 253 253
  97929. -253 253 253 253 253 253 253 253 253 253 253 253
  97930. -253 253 253 246 246 246 218 218 218 202 202 202
  97931. -210 210 210 14 14 14 2 2 6 2 2 6
  97932. - 30 30 30 22 22 22 2 2 6 2 2 6
  97933. - 2 2 6 2 2 6 18 18 18 86 86 86
  97934. - 42 42 42 14 14 14 0 0 0 0 0 0
  97935. - 0 0 0 0 0 0 0 0 0 0 0 0
  97936. - 0 0 0 0 0 0 0 0 0 0 0 0
  97937. - 0 0 0 0 0 0 0 0 0 0 0 0
  97938. - 0 0 0 0 0 0 0 0 0 0 0 0
  97939. - 0 0 0 0 0 0 0 0 0 0 0 0
  97940. - 0 0 0 0 0 0 0 0 0 0 0 0
  97941. - 0 0 0 0 0 0 0 0 0 0 0 0
  97942. - 0 0 0 0 0 0 0 0 0 14 14 14
  97943. - 42 42 42 90 90 90 22 22 22 2 2 6
  97944. - 42 42 42 2 2 6 18 18 18 218 218 218
  97945. -253 253 253 253 253 253 253 253 253 253 253 253
  97946. -253 253 253 253 253 253 253 253 253 253 253 253
  97947. -253 253 253 253 253 253 253 253 253 253 253 253
  97948. -253 253 253 253 253 253 253 253 253 253 253 253
  97949. -253 253 253 253 253 253 253 253 253 253 253 253
  97950. -253 253 253 253 253 253 250 250 250 221 221 221
  97951. -218 218 218 101 101 101 2 2 6 14 14 14
  97952. - 18 18 18 38 38 38 10 10 10 2 2 6
  97953. - 2 2 6 2 2 6 2 2 6 78 78 78
  97954. - 58 58 58 22 22 22 6 6 6 0 0 0
  97955. - 0 0 0 0 0 0 0 0 0 0 0 0
  97956. - 0 0 0 0 0 0 0 0 0 0 0 0
  97957. - 0 0 0 0 0 0 0 0 0 0 0 0
  97958. - 0 0 0 0 0 0 0 0 0 0 0 0
  97959. - 0 0 0 0 0 0 0 0 0 0 0 0
  97960. - 0 0 0 0 0 0 0 0 0 0 0 0
  97961. - 0 0 0 0 0 0 0 0 0 0 0 0
  97962. - 0 0 0 0 0 0 6 6 6 18 18 18
  97963. - 54 54 54 82 82 82 2 2 6 26 26 26
  97964. - 22 22 22 2 2 6 123 123 123 253 253 253
  97965. -253 253 253 253 253 253 253 253 253 253 253 253
  97966. -253 253 253 253 253 253 253 253 253 253 253 253
  97967. -253 253 253 253 253 253 253 253 253 253 253 253
  97968. -253 253 253 253 253 253 253 253 253 253 253 253
  97969. -253 253 253 253 253 253 253 253 253 253 253 253
  97970. -253 253 253 253 253 253 253 253 253 250 250 250
  97971. -238 238 238 198 198 198 6 6 6 38 38 38
  97972. - 58 58 58 26 26 26 38 38 38 2 2 6
  97973. - 2 2 6 2 2 6 2 2 6 46 46 46
  97974. - 78 78 78 30 30 30 10 10 10 0 0 0
  97975. - 0 0 0 0 0 0 0 0 0 0 0 0
  97976. - 0 0 0 0 0 0 0 0 0 0 0 0
  97977. - 0 0 0 0 0 0 0 0 0 0 0 0
  97978. - 0 0 0 0 0 0 0 0 0 0 0 0
  97979. - 0 0 0 0 0 0 0 0 0 0 0 0
  97980. - 0 0 0 0 0 0 0 0 0 0 0 0
  97981. - 0 0 0 0 0 0 0 0 0 0 0 0
  97982. - 0 0 0 0 0 0 10 10 10 30 30 30
  97983. - 74 74 74 58 58 58 2 2 6 42 42 42
  97984. - 2 2 6 22 22 22 231 231 231 253 253 253
  97985. -253 253 253 253 253 253 253 253 253 253 253 253
  97986. -253 253 253 253 253 253 253 253 253 250 250 250
  97987. -253 253 253 253 253 253 253 253 253 253 253 253
  97988. -253 253 253 253 253 253 253 253 253 253 253 253
  97989. -253 253 253 253 253 253 253 253 253 253 253 253
  97990. -253 253 253 253 253 253 253 253 253 253 253 253
  97991. -253 253 253 246 246 246 46 46 46 38 38 38
  97992. - 42 42 42 14 14 14 38 38 38 14 14 14
  97993. - 2 2 6 2 2 6 2 2 6 6 6 6
  97994. - 86 86 86 46 46 46 14 14 14 0 0 0
  97995. - 0 0 0 0 0 0 0 0 0 0 0 0
  97996. - 0 0 0 0 0 0 0 0 0 0 0 0
  97997. - 0 0 0 0 0 0 0 0 0 0 0 0
  97998. - 0 0 0 0 0 0 0 0 0 0 0 0
  97999. - 0 0 0 0 0 0 0 0 0 0 0 0
  98000. - 0 0 0 0 0 0 0 0 0 0 0 0
  98001. - 0 0 0 0 0 0 0 0 0 0 0 0
  98002. - 0 0 0 6 6 6 14 14 14 42 42 42
  98003. - 90 90 90 18 18 18 18 18 18 26 26 26
  98004. - 2 2 6 116 116 116 253 253 253 253 253 253
  98005. -253 253 253 253 253 253 253 253 253 253 253 253
  98006. -253 253 253 253 253 253 250 250 250 238 238 238
  98007. -253 253 253 253 253 253 253 253 253 253 253 253
  98008. -253 253 253 253 253 253 253 253 253 253 253 253
  98009. -253 253 253 253 253 253 253 253 253 253 253 253
  98010. -253 253 253 253 253 253 253 253 253 253 253 253
  98011. -253 253 253 253 253 253 94 94 94 6 6 6
  98012. - 2 2 6 2 2 6 10 10 10 34 34 34
  98013. - 2 2 6 2 2 6 2 2 6 2 2 6
  98014. - 74 74 74 58 58 58 22 22 22 6 6 6
  98015. - 0 0 0 0 0 0 0 0 0 0 0 0
  98016. - 0 0 0 0 0 0 0 0 0 0 0 0
  98017. - 0 0 0 0 0 0 0 0 0 0 0 0
  98018. - 0 0 0 0 0 0 0 0 0 0 0 0
  98019. - 0 0 0 0 0 0 0 0 0 0 0 0
  98020. - 0 0 0 0 0 0 0 0 0 0 0 0
  98021. - 0 0 0 0 0 0 0 0 0 0 0 0
  98022. - 0 0 0 10 10 10 26 26 26 66 66 66
  98023. - 82 82 82 2 2 6 38 38 38 6 6 6
  98024. - 14 14 14 210 210 210 253 253 253 253 253 253
  98025. -253 253 253 253 253 253 253 253 253 253 253 253
  98026. -253 253 253 253 253 253 246 246 246 242 242 242
  98027. -253 253 253 253 253 253 253 253 253 253 253 253
  98028. -253 253 253 253 253 253 253 253 253 253 253 253
  98029. -253 253 253 253 253 253 253 253 253 253 253 253
  98030. -253 253 253 253 253 253 253 253 253 253 253 253
  98031. -253 253 253 253 253 253 144 144 144 2 2 6
  98032. - 2 2 6 2 2 6 2 2 6 46 46 46
  98033. - 2 2 6 2 2 6 2 2 6 2 2 6
  98034. - 42 42 42 74 74 74 30 30 30 10 10 10
  98035. - 0 0 0 0 0 0 0 0 0 0 0 0
  98036. - 0 0 0 0 0 0 0 0 0 0 0 0
  98037. - 0 0 0 0 0 0 0 0 0 0 0 0
  98038. - 0 0 0 0 0 0 0 0 0 0 0 0
  98039. - 0 0 0 0 0 0 0 0 0 0 0 0
  98040. - 0 0 0 0 0 0 0 0 0 0 0 0
  98041. - 0 0 0 0 0 0 0 0 0 0 0 0
  98042. - 6 6 6 14 14 14 42 42 42 90 90 90
  98043. - 26 26 26 6 6 6 42 42 42 2 2 6
  98044. - 74 74 74 250 250 250 253 253 253 253 253 253
  98045. -253 253 253 253 253 253 253 253 253 253 253 253
  98046. -253 253 253 253 253 253 242 242 242 242 242 242
  98047. -253 253 253 253 253 253 253 253 253 253 253 253
  98048. -253 253 253 253 253 253 253 253 253 253 253 253
  98049. -253 253 253 253 253 253 253 253 253 253 253 253
  98050. -253 253 253 253 253 253 253 253 253 253 253 253
  98051. -253 253 253 253 253 253 182 182 182 2 2 6
  98052. - 2 2 6 2 2 6 2 2 6 46 46 46
  98053. - 2 2 6 2 2 6 2 2 6 2 2 6
  98054. - 10 10 10 86 86 86 38 38 38 10 10 10
  98055. - 0 0 0 0 0 0 0 0 0 0 0 0
  98056. - 0 0 0 0 0 0 0 0 0 0 0 0
  98057. - 0 0 0 0 0 0 0 0 0 0 0 0
  98058. - 0 0 0 0 0 0 0 0 0 0 0 0
  98059. - 0 0 0 0 0 0 0 0 0 0 0 0
  98060. - 0 0 0 0 0 0 0 0 0 0 0 0
  98061. - 0 0 0 0 0 0 0 0 0 0 0 0
  98062. - 10 10 10 26 26 26 66 66 66 82 82 82
  98063. - 2 2 6 22 22 22 18 18 18 2 2 6
  98064. -149 149 149 253 253 253 253 253 253 253 253 253
  98065. -253 253 253 253 253 253 253 253 253 253 253 253
  98066. -253 253 253 253 253 253 234 234 234 242 242 242
  98067. -253 253 253 253 253 253 253 253 253 253 253 253
  98068. -253 253 253 253 253 253 253 253 253 253 253 253
  98069. -253 253 253 253 253 253 253 253 253 253 253 253
  98070. -253 253 253 253 253 253 253 253 253 253 253 253
  98071. -253 253 253 253 253 253 206 206 206 2 2 6
  98072. - 2 2 6 2 2 6 2 2 6 38 38 38
  98073. - 2 2 6 2 2 6 2 2 6 2 2 6
  98074. - 6 6 6 86 86 86 46 46 46 14 14 14
  98075. - 0 0 0 0 0 0 0 0 0 0 0 0
  98076. - 0 0 0 0 0 0 0 0 0 0 0 0
  98077. - 0 0 0 0 0 0 0 0 0 0 0 0
  98078. - 0 0 0 0 0 0 0 0 0 0 0 0
  98079. - 0 0 0 0 0 0 0 0 0 0 0 0
  98080. - 0 0 0 0 0 0 0 0 0 0 0 0
  98081. - 0 0 0 0 0 0 0 0 0 6 6 6
  98082. - 18 18 18 46 46 46 86 86 86 18 18 18
  98083. - 2 2 6 34 34 34 10 10 10 6 6 6
  98084. -210 210 210 253 253 253 253 253 253 253 253 253
  98085. -253 253 253 253 253 253 253 253 253 253 253 253
  98086. -253 253 253 253 253 253 234 234 234 242 242 242
  98087. -253 253 253 253 253 253 253 253 253 253 253 253
  98088. -253 253 253 253 253 253 253 253 253 253 253 253
  98089. -253 253 253 253 253 253 253 253 253 253 253 253
  98090. -253 253 253 253 253 253 253 253 253 253 253 253
  98091. -253 253 253 253 253 253 221 221 221 6 6 6
  98092. - 2 2 6 2 2 6 6 6 6 30 30 30
  98093. - 2 2 6 2 2 6 2 2 6 2 2 6
  98094. - 2 2 6 82 82 82 54 54 54 18 18 18
  98095. - 6 6 6 0 0 0 0 0 0 0 0 0
  98096. - 0 0 0 0 0 0 0 0 0 0 0 0
  98097. - 0 0 0 0 0 0 0 0 0 0 0 0
  98098. - 0 0 0 0 0 0 0 0 0 0 0 0
  98099. - 0 0 0 0 0 0 0 0 0 0 0 0
  98100. - 0 0 0 0 0 0 0 0 0 0 0 0
  98101. - 0 0 0 0 0 0 0 0 0 10 10 10
  98102. - 26 26 26 66 66 66 62 62 62 2 2 6
  98103. - 2 2 6 38 38 38 10 10 10 26 26 26
  98104. -238 238 238 253 253 253 253 253 253 253 253 253
  98105. -253 253 253 253 253 253 253 253 253 253 253 253
  98106. -253 253 253 253 253 253 231 231 231 238 238 238
  98107. -253 253 253 253 253 253 253 253 253 253 253 253
  98108. -253 253 253 253 253 253 253 253 253 253 253 253
  98109. -253 253 253 253 253 253 253 253 253 253 253 253
  98110. -253 253 253 253 253 253 253 253 253 253 253 253
  98111. -253 253 253 253 253 253 231 231 231 6 6 6
  98112. - 2 2 6 2 2 6 10 10 10 30 30 30
  98113. - 2 2 6 2 2 6 2 2 6 2 2 6
  98114. - 2 2 6 66 66 66 58 58 58 22 22 22
  98115. - 6 6 6 0 0 0 0 0 0 0 0 0
  98116. - 0 0 0 0 0 0 0 0 0 0 0 0
  98117. - 0 0 0 0 0 0 0 0 0 0 0 0
  98118. - 0 0 0 0 0 0 0 0 0 0 0 0
  98119. - 0 0 0 0 0 0 0 0 0 0 0 0
  98120. - 0 0 0 0 0 0 0 0 0 0 0 0
  98121. - 0 0 0 0 0 0 0 0 0 10 10 10
  98122. - 38 38 38 78 78 78 6 6 6 2 2 6
  98123. - 2 2 6 46 46 46 14 14 14 42 42 42
  98124. -246 246 246 253 253 253 253 253 253 253 253 253
  98125. -253 253 253 253 253 253 253 253 253 253 253 253
  98126. -253 253 253 253 253 253 231 231 231 242 242 242
  98127. -253 253 253 253 253 253 253 253 253 253 253 253
  98128. -253 253 253 253 253 253 253 253 253 253 253 253
  98129. -253 253 253 253 253 253 253 253 253 253 253 253
  98130. -253 253 253 253 253 253 253 253 253 253 253 253
  98131. -253 253 253 253 253 253 234 234 234 10 10 10
  98132. - 2 2 6 2 2 6 22 22 22 14 14 14
  98133. - 2 2 6 2 2 6 2 2 6 2 2 6
  98134. - 2 2 6 66 66 66 62 62 62 22 22 22
  98135. - 6 6 6 0 0 0 0 0 0 0 0 0
  98136. - 0 0 0 0 0 0 0 0 0 0 0 0
  98137. - 0 0 0 0 0 0 0 0 0 0 0 0
  98138. - 0 0 0 0 0 0 0 0 0 0 0 0
  98139. - 0 0 0 0 0 0 0 0 0 0 0 0
  98140. - 0 0 0 0 0 0 0 0 0 0 0 0
  98141. - 0 0 0 0 0 0 6 6 6 18 18 18
  98142. - 50 50 50 74 74 74 2 2 6 2 2 6
  98143. - 14 14 14 70 70 70 34 34 34 62 62 62
  98144. -250 250 250 253 253 253 253 253 253 253 253 253
  98145. -253 253 253 253 253 253 253 253 253 253 253 253
  98146. -253 253 253 253 253 253 231 231 231 246 246 246
  98147. -253 253 253 253 253 253 253 253 253 253 253 253
  98148. -253 253 253 253 253 253 253 253 253 253 253 253
  98149. -253 253 253 253 253 253 253 253 253 253 253 253
  98150. -253 253 253 253 253 253 253 253 253 253 253 253
  98151. -253 253 253 253 253 253 234 234 234 14 14 14
  98152. - 2 2 6 2 2 6 30 30 30 2 2 6
  98153. - 2 2 6 2 2 6 2 2 6 2 2 6
  98154. - 2 2 6 66 66 66 62 62 62 22 22 22
  98155. - 6 6 6 0 0 0 0 0 0 0 0 0
  98156. - 0 0 0 0 0 0 0 0 0 0 0 0
  98157. - 0 0 0 0 0 0 0 0 0 0 0 0
  98158. - 0 0 0 0 0 0 0 0 0 0 0 0
  98159. - 0 0 0 0 0 0 0 0 0 0 0 0
  98160. - 0 0 0 0 0 0 0 0 0 0 0 0
  98161. - 0 0 0 0 0 0 6 6 6 18 18 18
  98162. - 54 54 54 62 62 62 2 2 6 2 2 6
  98163. - 2 2 6 30 30 30 46 46 46 70 70 70
  98164. -250 250 250 253 253 253 253 253 253 253 253 253
  98165. -253 253 253 253 253 253 253 253 253 253 253 253
  98166. -253 253 253 253 253 253 231 231 231 246 246 246
  98167. -253 253 253 253 253 253 253 253 253 253 253 253
  98168. -253 253 253 253 253 253 253 253 253 253 253 253
  98169. -253 253 253 253 253 253 253 253 253 253 253 253
  98170. -253 253 253 253 253 253 253 253 253 253 253 253
  98171. -253 253 253 253 253 253 226 226 226 10 10 10
  98172. - 2 2 6 6 6 6 30 30 30 2 2 6
  98173. - 2 2 6 2 2 6 2 2 6 2 2 6
  98174. - 2 2 6 66 66 66 58 58 58 22 22 22
  98175. - 6 6 6 0 0 0 0 0 0 0 0 0
  98176. - 0 0 0 0 0 0 0 0 0 0 0 0
  98177. - 0 0 0 0 0 0 0 0 0 0 0 0
  98178. - 0 0 0 0 0 0 0 0 0 0 0 0
  98179. - 0 0 0 0 0 0 0 0 0 0 0 0
  98180. - 0 0 0 0 0 0 0 0 0 0 0 0
  98181. - 0 0 0 0 0 0 6 6 6 22 22 22
  98182. - 58 58 58 62 62 62 2 2 6 2 2 6
  98183. - 2 2 6 2 2 6 30 30 30 78 78 78
  98184. -250 250 250 253 253 253 253 253 253 253 253 253
  98185. -253 253 253 253 253 253 253 253 253 253 253 253
  98186. -253 253 253 253 253 253 231 231 231 246 246 246
  98187. -253 253 253 253 253 253 253 253 253 253 253 253
  98188. -253 253 253 253 253 253 253 253 253 253 253 253
  98189. -253 253 253 253 253 253 253 253 253 253 253 253
  98190. -253 253 253 253 253 253 253 253 253 253 253 253
  98191. -253 253 253 253 253 253 206 206 206 2 2 6
  98192. - 22 22 22 34 34 34 18 14 6 22 22 22
  98193. - 26 26 26 18 18 18 6 6 6 2 2 6
  98194. - 2 2 6 82 82 82 54 54 54 18 18 18
  98195. - 6 6 6 0 0 0 0 0 0 0 0 0
  98196. - 0 0 0 0 0 0 0 0 0 0 0 0
  98197. - 0 0 0 0 0 0 0 0 0 0 0 0
  98198. - 0 0 0 0 0 0 0 0 0 0 0 0
  98199. - 0 0 0 0 0 0 0 0 0 0 0 0
  98200. - 0 0 0 0 0 0 0 0 0 0 0 0
  98201. - 0 0 0 0 0 0 6 6 6 26 26 26
  98202. - 62 62 62 106 106 106 74 54 14 185 133 11
  98203. -210 162 10 121 92 8 6 6 6 62 62 62
  98204. -238 238 238 253 253 253 253 253 253 253 253 253
  98205. -253 253 253 253 253 253 253 253 253 253 253 253
  98206. -253 253 253 253 253 253 231 231 231 246 246 246
  98207. -253 253 253 253 253 253 253 253 253 253 253 253
  98208. -253 253 253 253 253 253 253 253 253 253 253 253
  98209. -253 253 253 253 253 253 253 253 253 253 253 253
  98210. -253 253 253 253 253 253 253 253 253 253 253 253
  98211. -253 253 253 253 253 253 158 158 158 18 18 18
  98212. - 14 14 14 2 2 6 2 2 6 2 2 6
  98213. - 6 6 6 18 18 18 66 66 66 38 38 38
  98214. - 6 6 6 94 94 94 50 50 50 18 18 18
  98215. - 6 6 6 0 0 0 0 0 0 0 0 0
  98216. - 0 0 0 0 0 0 0 0 0 0 0 0
  98217. - 0 0 0 0 0 0 0 0 0 0 0 0
  98218. - 0 0 0 0 0 0 0 0 0 0 0 0
  98219. - 0 0 0 0 0 0 0 0 0 0 0 0
  98220. - 0 0 0 0 0 0 0 0 0 6 6 6
  98221. - 10 10 10 10 10 10 18 18 18 38 38 38
  98222. - 78 78 78 142 134 106 216 158 10 242 186 14
  98223. -246 190 14 246 190 14 156 118 10 10 10 10
  98224. - 90 90 90 238 238 238 253 253 253 253 253 253
  98225. -253 253 253 253 253 253 253 253 253 253 253 253
  98226. -253 253 253 253 253 253 231 231 231 250 250 250
  98227. -253 253 253 253 253 253 253 253 253 253 253 253
  98228. -253 253 253 253 253 253 253 253 253 253 253 253
  98229. -253 253 253 253 253 253 253 253 253 253 253 253
  98230. -253 253 253 253 253 253 253 253 253 246 230 190
  98231. -238 204 91 238 204 91 181 142 44 37 26 9
  98232. - 2 2 6 2 2 6 2 2 6 2 2 6
  98233. - 2 2 6 2 2 6 38 38 38 46 46 46
  98234. - 26 26 26 106 106 106 54 54 54 18 18 18
  98235. - 6 6 6 0 0 0 0 0 0 0 0 0
  98236. - 0 0 0 0 0 0 0 0 0 0 0 0
  98237. - 0 0 0 0 0 0 0 0 0 0 0 0
  98238. - 0 0 0 0 0 0 0 0 0 0 0 0
  98239. - 0 0 0 0 0 0 0 0 0 0 0 0
  98240. - 0 0 0 6 6 6 14 14 14 22 22 22
  98241. - 30 30 30 38 38 38 50 50 50 70 70 70
  98242. -106 106 106 190 142 34 226 170 11 242 186 14
  98243. -246 190 14 246 190 14 246 190 14 154 114 10
  98244. - 6 6 6 74 74 74 226 226 226 253 253 253
  98245. -253 253 253 253 253 253 253 253 253 253 253 253
  98246. -253 253 253 253 253 253 231 231 231 250 250 250
  98247. -253 253 253 253 253 253 253 253 253 253 253 253
  98248. -253 253 253 253 253 253 253 253 253 253 253 253
  98249. -253 253 253 253 253 253 253 253 253 253 253 253
  98250. -253 253 253 253 253 253 253 253 253 228 184 62
  98251. -241 196 14 241 208 19 232 195 16 38 30 10
  98252. - 2 2 6 2 2 6 2 2 6 2 2 6
  98253. - 2 2 6 6 6 6 30 30 30 26 26 26
  98254. -203 166 17 154 142 90 66 66 66 26 26 26
  98255. - 6 6 6 0 0 0 0 0 0 0 0 0
  98256. - 0 0 0 0 0 0 0 0 0 0 0 0
  98257. - 0 0 0 0 0 0 0 0 0 0 0 0
  98258. - 0 0 0 0 0 0 0 0 0 0 0 0
  98259. - 0 0 0 0 0 0 0 0 0 0 0 0
  98260. - 6 6 6 18 18 18 38 38 38 58 58 58
  98261. - 78 78 78 86 86 86 101 101 101 123 123 123
  98262. -175 146 61 210 150 10 234 174 13 246 186 14
  98263. -246 190 14 246 190 14 246 190 14 238 190 10
  98264. -102 78 10 2 2 6 46 46 46 198 198 198
  98265. -253 253 253 253 253 253 253 253 253 253 253 253
  98266. -253 253 253 253 253 253 234 234 234 242 242 242
  98267. -253 253 253 253 253 253 253 253 253 253 253 253
  98268. -253 253 253 253 253 253 253 253 253 253 253 253
  98269. -253 253 253 253 253 253 253 253 253 253 253 253
  98270. -253 253 253 253 253 253 253 253 253 224 178 62
  98271. -242 186 14 241 196 14 210 166 10 22 18 6
  98272. - 2 2 6 2 2 6 2 2 6 2 2 6
  98273. - 2 2 6 2 2 6 6 6 6 121 92 8
  98274. -238 202 15 232 195 16 82 82 82 34 34 34
  98275. - 10 10 10 0 0 0 0 0 0 0 0 0
  98276. - 0 0 0 0 0 0 0 0 0 0 0 0
  98277. - 0 0 0 0 0 0 0 0 0 0 0 0
  98278. - 0 0 0 0 0 0 0 0 0 0 0 0
  98279. - 0 0 0 0 0 0 0 0 0 0 0 0
  98280. - 14 14 14 38 38 38 70 70 70 154 122 46
  98281. -190 142 34 200 144 11 197 138 11 197 138 11
  98282. -213 154 11 226 170 11 242 186 14 246 190 14
  98283. -246 190 14 246 190 14 246 190 14 246 190 14
  98284. -225 175 15 46 32 6 2 2 6 22 22 22
  98285. -158 158 158 250 250 250 253 253 253 253 253 253
  98286. -253 253 253 253 253 253 253 253 253 253 253 253
  98287. -253 253 253 253 253 253 253 253 253 253 253 253
  98288. -253 253 253 253 253 253 253 253 253 253 253 253
  98289. -253 253 253 253 253 253 253 253 253 253 253 253
  98290. -253 253 253 250 250 250 242 242 242 224 178 62
  98291. -239 182 13 236 186 11 213 154 11 46 32 6
  98292. - 2 2 6 2 2 6 2 2 6 2 2 6
  98293. - 2 2 6 2 2 6 61 42 6 225 175 15
  98294. -238 190 10 236 186 11 112 100 78 42 42 42
  98295. - 14 14 14 0 0 0 0 0 0 0 0 0
  98296. - 0 0 0 0 0 0 0 0 0 0 0 0
  98297. - 0 0 0 0 0 0 0 0 0 0 0 0
  98298. - 0 0 0 0 0 0 0 0 0 0 0 0
  98299. - 0 0 0 0 0 0 0 0 0 6 6 6
  98300. - 22 22 22 54 54 54 154 122 46 213 154 11
  98301. -226 170 11 230 174 11 226 170 11 226 170 11
  98302. -236 178 12 242 186 14 246 190 14 246 190 14
  98303. -246 190 14 246 190 14 246 190 14 246 190 14
  98304. -241 196 14 184 144 12 10 10 10 2 2 6
  98305. - 6 6 6 116 116 116 242 242 242 253 253 253
  98306. -253 253 253 253 253 253 253 253 253 253 253 253
  98307. -253 253 253 253 253 253 253 253 253 253 253 253
  98308. -253 253 253 253 253 253 253 253 253 253 253 253
  98309. -253 253 253 253 253 253 253 253 253 253 253 253
  98310. -253 253 253 231 231 231 198 198 198 214 170 54
  98311. -236 178 12 236 178 12 210 150 10 137 92 6
  98312. - 18 14 6 2 2 6 2 2 6 2 2 6
  98313. - 6 6 6 70 47 6 200 144 11 236 178 12
  98314. -239 182 13 239 182 13 124 112 88 58 58 58
  98315. - 22 22 22 6 6 6 0 0 0 0 0 0
  98316. - 0 0 0 0 0 0 0 0 0 0 0 0
  98317. - 0 0 0 0 0 0 0 0 0 0 0 0
  98318. - 0 0 0 0 0 0 0 0 0 0 0 0
  98319. - 0 0 0 0 0 0 0 0 0 10 10 10
  98320. - 30 30 30 70 70 70 180 133 36 226 170 11
  98321. -239 182 13 242 186 14 242 186 14 246 186 14
  98322. -246 190 14 246 190 14 246 190 14 246 190 14
  98323. -246 190 14 246 190 14 246 190 14 246 190 14
  98324. -246 190 14 232 195 16 98 70 6 2 2 6
  98325. - 2 2 6 2 2 6 66 66 66 221 221 221
  98326. -253 253 253 253 253 253 253 253 253 253 253 253
  98327. -253 253 253 253 253 253 253 253 253 253 253 253
  98328. -253 253 253 253 253 253 253 253 253 253 253 253
  98329. -253 253 253 253 253 253 253 253 253 253 253 253
  98330. -253 253 253 206 206 206 198 198 198 214 166 58
  98331. -230 174 11 230 174 11 216 158 10 192 133 9
  98332. -163 110 8 116 81 8 102 78 10 116 81 8
  98333. -167 114 7 197 138 11 226 170 11 239 182 13
  98334. -242 186 14 242 186 14 162 146 94 78 78 78
  98335. - 34 34 34 14 14 14 6 6 6 0 0 0
  98336. - 0 0 0 0 0 0 0 0 0 0 0 0
  98337. - 0 0 0 0 0 0 0 0 0 0 0 0
  98338. - 0 0 0 0 0 0 0 0 0 0 0 0
  98339. - 0 0 0 0 0 0 0 0 0 6 6 6
  98340. - 30 30 30 78 78 78 190 142 34 226 170 11
  98341. -239 182 13 246 190 14 246 190 14 246 190 14
  98342. -246 190 14 246 190 14 246 190 14 246 190 14
  98343. -246 190 14 246 190 14 246 190 14 246 190 14
  98344. -246 190 14 241 196 14 203 166 17 22 18 6
  98345. - 2 2 6 2 2 6 2 2 6 38 38 38
  98346. -218 218 218 253 253 253 253 253 253 253 253 253
  98347. -253 253 253 253 253 253 253 253 253 253 253 253
  98348. -253 253 253 253 253 253 253 253 253 253 253 253
  98349. -253 253 253 253 253 253 253 253 253 253 253 253
  98350. -250 250 250 206 206 206 198 198 198 202 162 69
  98351. -226 170 11 236 178 12 224 166 10 210 150 10
  98352. -200 144 11 197 138 11 192 133 9 197 138 11
  98353. -210 150 10 226 170 11 242 186 14 246 190 14
  98354. -246 190 14 246 186 14 225 175 15 124 112 88
  98355. - 62 62 62 30 30 30 14 14 14 6 6 6
  98356. - 0 0 0 0 0 0 0 0 0 0 0 0
  98357. - 0 0 0 0 0 0 0 0 0 0 0 0
  98358. - 0 0 0 0 0 0 0 0 0 0 0 0
  98359. - 0 0 0 0 0 0 0 0 0 10 10 10
  98360. - 30 30 30 78 78 78 174 135 50 224 166 10
  98361. -239 182 13 246 190 14 246 190 14 246 190 14
  98362. -246 190 14 246 190 14 246 190 14 246 190 14
  98363. -246 190 14 246 190 14 246 190 14 246 190 14
  98364. -246 190 14 246 190 14 241 196 14 139 102 15
  98365. - 2 2 6 2 2 6 2 2 6 2 2 6
  98366. - 78 78 78 250 250 250 253 253 253 253 253 253
  98367. -253 253 253 253 253 253 253 253 253 253 253 253
  98368. -253 253 253 253 253 253 253 253 253 253 253 253
  98369. -253 253 253 253 253 253 253 253 253 253 253 253
  98370. -250 250 250 214 214 214 198 198 198 190 150 46
  98371. -219 162 10 236 178 12 234 174 13 224 166 10
  98372. -216 158 10 213 154 11 213 154 11 216 158 10
  98373. -226 170 11 239 182 13 246 190 14 246 190 14
  98374. -246 190 14 246 190 14 242 186 14 206 162 42
  98375. -101 101 101 58 58 58 30 30 30 14 14 14
  98376. - 6 6 6 0 0 0 0 0 0 0 0 0
  98377. - 0 0 0 0 0 0 0 0 0 0 0 0
  98378. - 0 0 0 0 0 0 0 0 0 0 0 0
  98379. - 0 0 0 0 0 0 0 0 0 10 10 10
  98380. - 30 30 30 74 74 74 174 135 50 216 158 10
  98381. -236 178 12 246 190 14 246 190 14 246 190 14
  98382. -246 190 14 246 190 14 246 190 14 246 190 14
  98383. -246 190 14 246 190 14 246 190 14 246 190 14
  98384. -246 190 14 246 190 14 241 196 14 226 184 13
  98385. - 61 42 6 2 2 6 2 2 6 2 2 6
  98386. - 22 22 22 238 238 238 253 253 253 253 253 253
  98387. -253 253 253 253 253 253 253 253 253 253 253 253
  98388. -253 253 253 253 253 253 253 253 253 253 253 253
  98389. -253 253 253 253 253 253 253 253 253 253 253 253
  98390. -253 253 253 226 226 226 187 187 187 180 133 36
  98391. -216 158 10 236 178 12 239 182 13 236 178 12
  98392. -230 174 11 226 170 11 226 170 11 230 174 11
  98393. -236 178 12 242 186 14 246 190 14 246 190 14
  98394. -246 190 14 246 190 14 246 186 14 239 182 13
  98395. -206 162 42 106 106 106 66 66 66 34 34 34
  98396. - 14 14 14 6 6 6 0 0 0 0 0 0
  98397. - 0 0 0 0 0 0 0 0 0 0 0 0
  98398. - 0 0 0 0 0 0 0 0 0 0 0 0
  98399. - 0 0 0 0 0 0 0 0 0 6 6 6
  98400. - 26 26 26 70 70 70 163 133 67 213 154 11
  98401. -236 178 12 246 190 14 246 190 14 246 190 14
  98402. -246 190 14 246 190 14 246 190 14 246 190 14
  98403. -246 190 14 246 190 14 246 190 14 246 190 14
  98404. -246 190 14 246 190 14 246 190 14 241 196 14
  98405. -190 146 13 18 14 6 2 2 6 2 2 6
  98406. - 46 46 46 246 246 246 253 253 253 253 253 253
  98407. -253 253 253 253 253 253 253 253 253 253 253 253
  98408. -253 253 253 253 253 253 253 253 253 253 253 253
  98409. -253 253 253 253 253 253 253 253 253 253 253 253
  98410. -253 253 253 221 221 221 86 86 86 156 107 11
  98411. -216 158 10 236 178 12 242 186 14 246 186 14
  98412. -242 186 14 239 182 13 239 182 13 242 186 14
  98413. -242 186 14 246 186 14 246 190 14 246 190 14
  98414. -246 190 14 246 190 14 246 190 14 246 190 14
  98415. -242 186 14 225 175 15 142 122 72 66 66 66
  98416. - 30 30 30 10 10 10 0 0 0 0 0 0
  98417. - 0 0 0 0 0 0 0 0 0 0 0 0
  98418. - 0 0 0 0 0 0 0 0 0 0 0 0
  98419. - 0 0 0 0 0 0 0 0 0 6 6 6
  98420. - 26 26 26 70 70 70 163 133 67 210 150 10
  98421. -236 178 12 246 190 14 246 190 14 246 190 14
  98422. -246 190 14 246 190 14 246 190 14 246 190 14
  98423. -246 190 14 246 190 14 246 190 14 246 190 14
  98424. -246 190 14 246 190 14 246 190 14 246 190 14
  98425. -232 195 16 121 92 8 34 34 34 106 106 106
  98426. -221 221 221 253 253 253 253 253 253 253 253 253
  98427. -253 253 253 253 253 253 253 253 253 253 253 253
  98428. -253 253 253 253 253 253 253 253 253 253 253 253
  98429. -253 253 253 253 253 253 253 253 253 253 253 253
  98430. -242 242 242 82 82 82 18 14 6 163 110 8
  98431. -216 158 10 236 178 12 242 186 14 246 190 14
  98432. -246 190 14 246 190 14 246 190 14 246 190 14
  98433. -246 190 14 246 190 14 246 190 14 246 190 14
  98434. -246 190 14 246 190 14 246 190 14 246 190 14
  98435. -246 190 14 246 190 14 242 186 14 163 133 67
  98436. - 46 46 46 18 18 18 6 6 6 0 0 0
  98437. - 0 0 0 0 0 0 0 0 0 0 0 0
  98438. - 0 0 0 0 0 0 0 0 0 0 0 0
  98439. - 0 0 0 0 0 0 0 0 0 10 10 10
  98440. - 30 30 30 78 78 78 163 133 67 210 150 10
  98441. -236 178 12 246 186 14 246 190 14 246 190 14
  98442. -246 190 14 246 190 14 246 190 14 246 190 14
  98443. -246 190 14 246 190 14 246 190 14 246 190 14
  98444. -246 190 14 246 190 14 246 190 14 246 190 14
  98445. -241 196 14 215 174 15 190 178 144 253 253 253
  98446. -253 253 253 253 253 253 253 253 253 253 253 253
  98447. -253 253 253 253 253 253 253 253 253 253 253 253
  98448. -253 253 253 253 253 253 253 253 253 253 253 253
  98449. -253 253 253 253 253 253 253 253 253 218 218 218
  98450. - 58 58 58 2 2 6 22 18 6 167 114 7
  98451. -216 158 10 236 178 12 246 186 14 246 190 14
  98452. -246 190 14 246 190 14 246 190 14 246 190 14
  98453. -246 190 14 246 190 14 246 190 14 246 190 14
  98454. -246 190 14 246 190 14 246 190 14 246 190 14
  98455. -246 190 14 246 186 14 242 186 14 190 150 46
  98456. - 54 54 54 22 22 22 6 6 6 0 0 0
  98457. - 0 0 0 0 0 0 0 0 0 0 0 0
  98458. - 0 0 0 0 0 0 0 0 0 0 0 0
  98459. - 0 0 0 0 0 0 0 0 0 14 14 14
  98460. - 38 38 38 86 86 86 180 133 36 213 154 11
  98461. -236 178 12 246 186 14 246 190 14 246 190 14
  98462. -246 190 14 246 190 14 246 190 14 246 190 14
  98463. -246 190 14 246 190 14 246 190 14 246 190 14
  98464. -246 190 14 246 190 14 246 190 14 246 190 14
  98465. -246 190 14 232 195 16 190 146 13 214 214 214
  98466. -253 253 253 253 253 253 253 253 253 253 253 253
  98467. -253 253 253 253 253 253 253 253 253 253 253 253
  98468. -253 253 253 253 253 253 253 253 253 253 253 253
  98469. -253 253 253 250 250 250 170 170 170 26 26 26
  98470. - 2 2 6 2 2 6 37 26 9 163 110 8
  98471. -219 162 10 239 182 13 246 186 14 246 190 14
  98472. -246 190 14 246 190 14 246 190 14 246 190 14
  98473. -246 190 14 246 190 14 246 190 14 246 190 14
  98474. -246 190 14 246 190 14 246 190 14 246 190 14
  98475. -246 186 14 236 178 12 224 166 10 142 122 72
  98476. - 46 46 46 18 18 18 6 6 6 0 0 0
  98477. - 0 0 0 0 0 0 0 0 0 0 0 0
  98478. - 0 0 0 0 0 0 0 0 0 0 0 0
  98479. - 0 0 0 0 0 0 6 6 6 18 18 18
  98480. - 50 50 50 109 106 95 192 133 9 224 166 10
  98481. -242 186 14 246 190 14 246 190 14 246 190 14
  98482. -246 190 14 246 190 14 246 190 14 246 190 14
  98483. -246 190 14 246 190 14 246 190 14 246 190 14
  98484. -246 190 14 246 190 14 246 190 14 246 190 14
  98485. -242 186 14 226 184 13 210 162 10 142 110 46
  98486. -226 226 226 253 253 253 253 253 253 253 253 253
  98487. -253 253 253 253 253 253 253 253 253 253 253 253
  98488. -253 253 253 253 253 253 253 253 253 253 253 253
  98489. -198 198 198 66 66 66 2 2 6 2 2 6
  98490. - 2 2 6 2 2 6 50 34 6 156 107 11
  98491. -219 162 10 239 182 13 246 186 14 246 190 14
  98492. -246 190 14 246 190 14 246 190 14 246 190 14
  98493. -246 190 14 246 190 14 246 190 14 246 190 14
  98494. -246 190 14 246 190 14 246 190 14 242 186 14
  98495. -234 174 13 213 154 11 154 122 46 66 66 66
  98496. - 30 30 30 10 10 10 0 0 0 0 0 0
  98497. - 0 0 0 0 0 0 0 0 0 0 0 0
  98498. - 0 0 0 0 0 0 0 0 0 0 0 0
  98499. - 0 0 0 0 0 0 6 6 6 22 22 22
  98500. - 58 58 58 154 121 60 206 145 10 234 174 13
  98501. -242 186 14 246 186 14 246 190 14 246 190 14
  98502. -246 190 14 246 190 14 246 190 14 246 190 14
  98503. -246 190 14 246 190 14 246 190 14 246 190 14
  98504. -246 190 14 246 190 14 246 190 14 246 190 14
  98505. -246 186 14 236 178 12 210 162 10 163 110 8
  98506. - 61 42 6 138 138 138 218 218 218 250 250 250
  98507. -253 253 253 253 253 253 253 253 253 250 250 250
  98508. -242 242 242 210 210 210 144 144 144 66 66 66
  98509. - 6 6 6 2 2 6 2 2 6 2 2 6
  98510. - 2 2 6 2 2 6 61 42 6 163 110 8
  98511. -216 158 10 236 178 12 246 190 14 246 190 14
  98512. -246 190 14 246 190 14 246 190 14 246 190 14
  98513. -246 190 14 246 190 14 246 190 14 246 190 14
  98514. -246 190 14 239 182 13 230 174 11 216 158 10
  98515. -190 142 34 124 112 88 70 70 70 38 38 38
  98516. - 18 18 18 6 6 6 0 0 0 0 0 0
  98517. - 0 0 0 0 0 0 0 0 0 0 0 0
  98518. - 0 0 0 0 0 0 0 0 0 0 0 0
  98519. - 0 0 0 0 0 0 6 6 6 22 22 22
  98520. - 62 62 62 168 124 44 206 145 10 224 166 10
  98521. -236 178 12 239 182 13 242 186 14 242 186 14
  98522. -246 186 14 246 190 14 246 190 14 246 190 14
  98523. -246 190 14 246 190 14 246 190 14 246 190 14
  98524. -246 190 14 246 190 14 246 190 14 246 190 14
  98525. -246 190 14 236 178 12 216 158 10 175 118 6
  98526. - 80 54 7 2 2 6 6 6 6 30 30 30
  98527. - 54 54 54 62 62 62 50 50 50 38 38 38
  98528. - 14 14 14 2 2 6 2 2 6 2 2 6
  98529. - 2 2 6 2 2 6 2 2 6 2 2 6
  98530. - 2 2 6 6 6 6 80 54 7 167 114 7
  98531. -213 154 11 236 178 12 246 190 14 246 190 14
  98532. -246 190 14 246 190 14 246 190 14 246 190 14
  98533. -246 190 14 242 186 14 239 182 13 239 182 13
  98534. -230 174 11 210 150 10 174 135 50 124 112 88
  98535. - 82 82 82 54 54 54 34 34 34 18 18 18
  98536. - 6 6 6 0 0 0 0 0 0 0 0 0
  98537. - 0 0 0 0 0 0 0 0 0 0 0 0
  98538. - 0 0 0 0 0 0 0 0 0 0 0 0
  98539. - 0 0 0 0 0 0 6 6 6 18 18 18
  98540. - 50 50 50 158 118 36 192 133 9 200 144 11
  98541. -216 158 10 219 162 10 224 166 10 226 170 11
  98542. -230 174 11 236 178 12 239 182 13 239 182 13
  98543. -242 186 14 246 186 14 246 190 14 246 190 14
  98544. -246 190 14 246 190 14 246 190 14 246 190 14
  98545. -246 186 14 230 174 11 210 150 10 163 110 8
  98546. -104 69 6 10 10 10 2 2 6 2 2 6
  98547. - 2 2 6 2 2 6 2 2 6 2 2 6
  98548. - 2 2 6 2 2 6 2 2 6 2 2 6
  98549. - 2 2 6 2 2 6 2 2 6 2 2 6
  98550. - 2 2 6 6 6 6 91 60 6 167 114 7
  98551. -206 145 10 230 174 11 242 186 14 246 190 14
  98552. -246 190 14 246 190 14 246 186 14 242 186 14
  98553. -239 182 13 230 174 11 224 166 10 213 154 11
  98554. -180 133 36 124 112 88 86 86 86 58 58 58
  98555. - 38 38 38 22 22 22 10 10 10 6 6 6
  98556. - 0 0 0 0 0 0 0 0 0 0 0 0
  98557. - 0 0 0 0 0 0 0 0 0 0 0 0
  98558. - 0 0 0 0 0 0 0 0 0 0 0 0
  98559. - 0 0 0 0 0 0 0 0 0 14 14 14
  98560. - 34 34 34 70 70 70 138 110 50 158 118 36
  98561. -167 114 7 180 123 7 192 133 9 197 138 11
  98562. -200 144 11 206 145 10 213 154 11 219 162 10
  98563. -224 166 10 230 174 11 239 182 13 242 186 14
  98564. -246 186 14 246 186 14 246 186 14 246 186 14
  98565. -239 182 13 216 158 10 185 133 11 152 99 6
  98566. -104 69 6 18 14 6 2 2 6 2 2 6
  98567. - 2 2 6 2 2 6 2 2 6 2 2 6
  98568. - 2 2 6 2 2 6 2 2 6 2 2 6
  98569. - 2 2 6 2 2 6 2 2 6 2 2 6
  98570. - 2 2 6 6 6 6 80 54 7 152 99 6
  98571. -192 133 9 219 162 10 236 178 12 239 182 13
  98572. -246 186 14 242 186 14 239 182 13 236 178 12
  98573. -224 166 10 206 145 10 192 133 9 154 121 60
  98574. - 94 94 94 62 62 62 42 42 42 22 22 22
  98575. - 14 14 14 6 6 6 0 0 0 0 0 0
  98576. - 0 0 0 0 0 0 0 0 0 0 0 0
  98577. - 0 0 0 0 0 0 0 0 0 0 0 0
  98578. - 0 0 0 0 0 0 0 0 0 0 0 0
  98579. - 0 0 0 0 0 0 0 0 0 6 6 6
  98580. - 18 18 18 34 34 34 58 58 58 78 78 78
  98581. -101 98 89 124 112 88 142 110 46 156 107 11
  98582. -163 110 8 167 114 7 175 118 6 180 123 7
  98583. -185 133 11 197 138 11 210 150 10 219 162 10
  98584. -226 170 11 236 178 12 236 178 12 234 174 13
  98585. -219 162 10 197 138 11 163 110 8 130 83 6
  98586. - 91 60 6 10 10 10 2 2 6 2 2 6
  98587. - 18 18 18 38 38 38 38 38 38 38 38 38
  98588. - 38 38 38 38 38 38 38 38 38 38 38 38
  98589. - 38 38 38 38 38 38 26 26 26 2 2 6
  98590. - 2 2 6 6 6 6 70 47 6 137 92 6
  98591. -175 118 6 200 144 11 219 162 10 230 174 11
  98592. -234 174 13 230 174 11 219 162 10 210 150 10
  98593. -192 133 9 163 110 8 124 112 88 82 82 82
  98594. - 50 50 50 30 30 30 14 14 14 6 6 6
  98595. - 0 0 0 0 0 0 0 0 0 0 0 0
  98596. - 0 0 0 0 0 0 0 0 0 0 0 0
  98597. - 0 0 0 0 0 0 0 0 0 0 0 0
  98598. - 0 0 0 0 0 0 0 0 0 0 0 0
  98599. - 0 0 0 0 0 0 0 0 0 0 0 0
  98600. - 6 6 6 14 14 14 22 22 22 34 34 34
  98601. - 42 42 42 58 58 58 74 74 74 86 86 86
  98602. -101 98 89 122 102 70 130 98 46 121 87 25
  98603. -137 92 6 152 99 6 163 110 8 180 123 7
  98604. -185 133 11 197 138 11 206 145 10 200 144 11
  98605. -180 123 7 156 107 11 130 83 6 104 69 6
  98606. - 50 34 6 54 54 54 110 110 110 101 98 89
  98607. - 86 86 86 82 82 82 78 78 78 78 78 78
  98608. - 78 78 78 78 78 78 78 78 78 78 78 78
  98609. - 78 78 78 82 82 82 86 86 86 94 94 94
  98610. -106 106 106 101 101 101 86 66 34 124 80 6
  98611. -156 107 11 180 123 7 192 133 9 200 144 11
  98612. -206 145 10 200 144 11 192 133 9 175 118 6
  98613. -139 102 15 109 106 95 70 70 70 42 42 42
  98614. - 22 22 22 10 10 10 0 0 0 0 0 0
  98615. - 0 0 0 0 0 0 0 0 0 0 0 0
  98616. - 0 0 0 0 0 0 0 0 0 0 0 0
  98617. - 0 0 0 0 0 0 0 0 0 0 0 0
  98618. - 0 0 0 0 0 0 0 0 0 0 0 0
  98619. - 0 0 0 0 0 0 0 0 0 0 0 0
  98620. - 0 0 0 0 0 0 6 6 6 10 10 10
  98621. - 14 14 14 22 22 22 30 30 30 38 38 38
  98622. - 50 50 50 62 62 62 74 74 74 90 90 90
  98623. -101 98 89 112 100 78 121 87 25 124 80 6
  98624. -137 92 6 152 99 6 152 99 6 152 99 6
  98625. -138 86 6 124 80 6 98 70 6 86 66 30
  98626. -101 98 89 82 82 82 58 58 58 46 46 46
  98627. - 38 38 38 34 34 34 34 34 34 34 34 34
  98628. - 34 34 34 34 34 34 34 34 34 34 34 34
  98629. - 34 34 34 34 34 34 38 38 38 42 42 42
  98630. - 54 54 54 82 82 82 94 86 76 91 60 6
  98631. -134 86 6 156 107 11 167 114 7 175 118 6
  98632. -175 118 6 167 114 7 152 99 6 121 87 25
  98633. -101 98 89 62 62 62 34 34 34 18 18 18
  98634. - 6 6 6 0 0 0 0 0 0 0 0 0
  98635. - 0 0 0 0 0 0 0 0 0 0 0 0
  98636. - 0 0 0 0 0 0 0 0 0 0 0 0
  98637. - 0 0 0 0 0 0 0 0 0 0 0 0
  98638. - 0 0 0 0 0 0 0 0 0 0 0 0
  98639. - 0 0 0 0 0 0 0 0 0 0 0 0
  98640. - 0 0 0 0 0 0 0 0 0 0 0 0
  98641. - 0 0 0 6 6 6 6 6 6 10 10 10
  98642. - 18 18 18 22 22 22 30 30 30 42 42 42
  98643. - 50 50 50 66 66 66 86 86 86 101 98 89
  98644. -106 86 58 98 70 6 104 69 6 104 69 6
  98645. -104 69 6 91 60 6 82 62 34 90 90 90
  98646. - 62 62 62 38 38 38 22 22 22 14 14 14
  98647. - 10 10 10 10 10 10 10 10 10 10 10 10
  98648. - 10 10 10 10 10 10 6 6 6 10 10 10
  98649. - 10 10 10 10 10 10 10 10 10 14 14 14
  98650. - 22 22 22 42 42 42 70 70 70 89 81 66
  98651. - 80 54 7 104 69 6 124 80 6 137 92 6
  98652. -134 86 6 116 81 8 100 82 52 86 86 86
  98653. - 58 58 58 30 30 30 14 14 14 6 6 6
  98654. - 0 0 0 0 0 0 0 0 0 0 0 0
  98655. - 0 0 0 0 0 0 0 0 0 0 0 0
  98656. - 0 0 0 0 0 0 0 0 0 0 0 0
  98657. - 0 0 0 0 0 0 0 0 0 0 0 0
  98658. - 0 0 0 0 0 0 0 0 0 0 0 0
  98659. - 0 0 0 0 0 0 0 0 0 0 0 0
  98660. - 0 0 0 0 0 0 0 0 0 0 0 0
  98661. - 0 0 0 0 0 0 0 0 0 0 0 0
  98662. - 0 0 0 6 6 6 10 10 10 14 14 14
  98663. - 18 18 18 26 26 26 38 38 38 54 54 54
  98664. - 70 70 70 86 86 86 94 86 76 89 81 66
  98665. - 89 81 66 86 86 86 74 74 74 50 50 50
  98666. - 30 30 30 14 14 14 6 6 6 0 0 0
  98667. - 0 0 0 0 0 0 0 0 0 0 0 0
  98668. - 0 0 0 0 0 0 0 0 0 0 0 0
  98669. - 0 0 0 0 0 0 0 0 0 0 0 0
  98670. - 6 6 6 18 18 18 34 34 34 58 58 58
  98671. - 82 82 82 89 81 66 89 81 66 89 81 66
  98672. - 94 86 66 94 86 76 74 74 74 50 50 50
  98673. - 26 26 26 14 14 14 6 6 6 0 0 0
  98674. - 0 0 0 0 0 0 0 0 0 0 0 0
  98675. - 0 0 0 0 0 0 0 0 0 0 0 0
  98676. - 0 0 0 0 0 0 0 0 0 0 0 0
  98677. - 0 0 0 0 0 0 0 0 0 0 0 0
  98678. - 0 0 0 0 0 0 0 0 0 0 0 0
  98679. - 0 0 0 0 0 0 0 0 0 0 0 0
  98680. - 0 0 0 0 0 0 0 0 0 0 0 0
  98681. - 0 0 0 0 0 0 0 0 0 0 0 0
  98682. - 0 0 0 0 0 0 0 0 0 0 0 0
  98683. - 6 6 6 6 6 6 14 14 14 18 18 18
  98684. - 30 30 30 38 38 38 46 46 46 54 54 54
  98685. - 50 50 50 42 42 42 30 30 30 18 18 18
  98686. - 10 10 10 0 0 0 0 0 0 0 0 0
  98687. - 0 0 0 0 0 0 0 0 0 0 0 0
  98688. - 0 0 0 0 0 0 0 0 0 0 0 0
  98689. - 0 0 0 0 0 0 0 0 0 0 0 0
  98690. - 0 0 0 6 6 6 14 14 14 26 26 26
  98691. - 38 38 38 50 50 50 58 58 58 58 58 58
  98692. - 54 54 54 42 42 42 30 30 30 18 18 18
  98693. - 10 10 10 0 0 0 0 0 0 0 0 0
  98694. - 0 0 0 0 0 0 0 0 0 0 0 0
  98695. - 0 0 0 0 0 0 0 0 0 0 0 0
  98696. - 0 0 0 0 0 0 0 0 0 0 0 0
  98697. - 0 0 0 0 0 0 0 0 0 0 0 0
  98698. - 0 0 0 0 0 0 0 0 0 0 0 0
  98699. - 0 0 0 0 0 0 0 0 0 0 0 0
  98700. - 0 0 0 0 0 0 0 0 0 0 0 0
  98701. - 0 0 0 0 0 0 0 0 0 0 0 0
  98702. - 0 0 0 0 0 0 0 0 0 0 0 0
  98703. - 0 0 0 0 0 0 0 0 0 6 6 6
  98704. - 6 6 6 10 10 10 14 14 14 18 18 18
  98705. - 18 18 18 14 14 14 10 10 10 6 6 6
  98706. - 0 0 0 0 0 0 0 0 0 0 0 0
  98707. - 0 0 0 0 0 0 0 0 0 0 0 0
  98708. - 0 0 0 0 0 0 0 0 0 0 0 0
  98709. - 0 0 0 0 0 0 0 0 0 0 0 0
  98710. - 0 0 0 0 0 0 0 0 0 6 6 6
  98711. - 14 14 14 18 18 18 22 22 22 22 22 22
  98712. - 18 18 18 14 14 14 10 10 10 6 6 6
  98713. - 0 0 0 0 0 0 0 0 0 0 0 0
  98714. - 0 0 0 0 0 0 0 0 0 0 0 0
  98715. - 0 0 0 0 0 0 0 0 0 0 0 0
  98716. - 0 0 0 0 0 0 0 0 0 0 0 0
  98717. - 0 0 0 0 0 0 0 0 0 0 0 0
  98718. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98719. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98720. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98721. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98722. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98723. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98724. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98725. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98726. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98727. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98728. +0 0 0 0 0 0 0 0 0
  98729. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98730. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98731. +0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0
  98732. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98733. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98734. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98735. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98736. +0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0
  98737. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98738. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98739. +0 0 0 0 0 0 0 0 0
  98740. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98741. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  98742. +10 15 3 2 3 1 12 18 4 42 61 14 19 27 6 11 16 4
  98743. +38 55 13 10 15 3 3 4 1 10 15 3 0 0 0 0 0 0
  98744. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98745. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98746. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 3 1
  98747. +12 18 4 1 1 0 23 34 8 31 45 11 10 15 3 32 47 11
  98748. +34 49 12 3 4 1 3 4 1 3 4 1 0 0 0 0 0 0
  98749. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98750. +0 0 0 0 0 0 0 0 0
  98751. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98752. +0 0 0 0 0 0 10 15 3 29 42 10 26 37 9 12 18 4
  98753. +55 80 19 81 118 28 55 80 19 92 132 31 106 153 36 69 100 23
  98754. +100 144 34 80 116 27 42 61 14 81 118 28 23 34 8 27 40 9
  98755. +15 21 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98756. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98757. +0 0 0 0 0 0 1 1 0 29 42 10 15 21 5 50 72 17
  98758. +74 107 25 45 64 15 102 148 35 80 116 27 84 121 28 111 160 38
  98759. +69 100 23 65 94 22 81 118 28 29 42 10 17 25 6 29 42 10
  98760. +23 34 8 2 3 1 0 0 0 0 0 0 0 0 0 0 0 0
  98761. +0 0 0 0 0 0 0 0 0
  98762. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 1
  98763. +15 21 5 15 21 5 34 49 12 101 146 34 111 161 38 97 141 33
  98764. +97 141 33 119 172 41 117 170 40 116 167 40 118 170 40 118 171 40
  98765. +117 169 40 118 170 40 111 160 38 118 170 40 96 138 32 89 128 30
  98766. +81 118 28 11 16 4 10 15 3 1 1 0 0 0 0 0 0 0
  98767. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98768. +3 4 1 3 4 1 34 49 12 101 146 34 79 115 27 111 160 38
  98769. +114 165 39 113 163 39 118 170 40 117 169 40 118 171 40 117 169 40
  98770. +116 167 40 119 172 41 113 163 39 92 132 31 105 151 36 113 163 39
  98771. +75 109 26 19 27 6 16 23 5 11 16 4 0 1 0 0 0 0
  98772. +0 0 0 0 0 0 0 0 0
  98773. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 15 3
  98774. +80 116 27 106 153 36 105 151 36 114 165 39 118 170 40 118 171 40
  98775. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98776. +117 169 40 117 169 40 117 170 40 117 169 40 118 170 40 118 170 40
  98777. +117 170 40 75 109 26 75 109 26 34 49 12 0 0 0 0 0 0
  98778. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 1
  98779. +64 92 22 65 94 22 100 144 34 118 171 40 118 170 40 117 169 40
  98780. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98781. +117 169 40 117 169 40 117 169 40 118 171 41 118 170 40 117 169 40
  98782. +109 158 37 105 151 36 104 150 35 47 69 16 0 0 0 0 0 0
  98783. +0 0 0 0 0 0 0 0 0
  98784. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98785. +42 61 14 115 167 39 118 170 40 117 169 40 117 169 40 117 169 40
  98786. +117 170 40 117 170 40 117 169 40 117 169 40 117 169 40 117 169 40
  98787. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98788. +117 169 40 117 169 40 118 170 40 96 138 32 17 25 6 0 0 0
  98789. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 47 69 16
  98790. +114 165 39 117 168 40 117 170 40 117 169 40 117 169 40 117 169 40
  98791. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98792. +117 169 40 117 169 40 118 170 40 117 169 40 117 169 40 117 169 40
  98793. +117 170 40 119 172 41 96 138 32 12 18 4 0 0 0 0 0 0
  98794. +0 0 0 0 0 0 0 0 0
  98795. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 15 3
  98796. +32 47 11 105 151 36 118 170 40 117 169 40 117 169 40 116 168 40
  98797. +109 157 37 111 160 38 117 169 40 118 171 40 117 169 40 117 169 40
  98798. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98799. +117 169 40 117 169 40 117 169 40 118 171 40 69 100 23 2 3 1
  98800. +0 0 0 0 0 0 0 0 0 0 0 0 19 27 6 101 146 34
  98801. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98802. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 170 40
  98803. +118 171 40 115 166 39 107 154 36 111 161 38 117 169 40 117 169 40
  98804. +117 169 40 118 171 40 75 109 26 19 27 6 2 3 1 0 0 0
  98805. +0 0 0 0 0 0 0 0 0
  98806. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 23 5
  98807. +89 128 30 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98808. +111 160 38 92 132 31 79 115 27 96 138 32 115 166 39 119 171 41
  98809. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98810. +117 169 40 117 169 40 117 169 40 118 170 40 109 157 37 26 37 9
  98811. +0 0 0 0 0 0 0 0 0 0 0 0 64 92 22 118 171 40
  98812. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98813. +117 169 40 117 169 40 117 169 40 118 170 40 118 171 40 109 157 37
  98814. +89 128 30 81 118 28 100 144 34 115 166 39 117 169 40 117 169 40
  98815. +117 169 40 117 170 40 113 163 39 60 86 20 1 1 0 0 0 0
  98816. +0 0 0 0 0 0 0 0 0
  98817. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98818. +27 40 9 96 138 32 118 170 40 117 169 40 117 169 40 117 169 40
  98819. +117 170 40 117 169 40 101 146 34 67 96 23 55 80 19 84 121 28
  98820. +113 163 39 119 171 41 117 169 40 117 169 40 117 169 40 117 169 40
  98821. +117 169 40 117 169 40 117 169 40 117 169 40 119 171 41 65 94 22
  98822. +0 0 0 0 0 0 0 0 0 15 21 5 101 146 34 118 171 40
  98823. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98824. +117 169 40 118 170 40 118 171 40 104 150 35 69 100 23 53 76 18
  98825. +81 118 28 111 160 38 118 170 40 117 169 40 117 169 40 117 169 40
  98826. +117 169 40 114 165 39 69 100 23 10 15 3 0 0 0 0 0 0
  98827. +0 0 0 0 0 0 0 0 0
  98828. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  98829. +31 45 11 77 111 26 117 169 40 117 169 40 117 169 40 117 169 40
  98830. +117 169 40 117 169 40 118 170 40 116 168 40 92 132 31 47 69 16
  98831. +38 55 13 81 118 28 113 163 39 119 171 41 117 169 40 117 169 40
  98832. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 41 92 132 31
  98833. +10 15 3 0 0 0 0 0 0 36 52 12 115 166 39 117 169 40
  98834. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 118 170 40
  98835. +118 171 40 102 148 35 64 92 22 34 49 12 65 94 22 106 153 36
  98836. +118 171 40 117 170 40 117 169 40 117 169 40 117 169 40 117 169 40
  98837. +118 170 40 107 154 36 55 80 19 15 21 5 0 0 0 0 0 0
  98838. +0 0 0 0 0 0 0 0 0
  98839. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98840. +29 42 10 101 146 34 118 171 40 117 169 40 117 169 40 117 169 40
  98841. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 40 113 163 39
  98842. +75 109 26 27 40 9 36 52 12 89 128 30 116 167 40 118 171 40
  98843. +117 169 40 117 169 40 117 169 40 117 169 40 118 170 40 104 150 35
  98844. +16 23 5 0 0 0 0 0 0 53 76 18 118 171 40 117 169 40
  98845. +117 169 40 117 169 40 117 169 40 117 169 40 119 171 41 109 157 37
  98846. +67 96 23 23 34 8 42 61 14 96 138 32 118 170 40 118 170 40
  98847. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98848. +117 169 40 117 169 40 74 107 25 10 15 3 0 0 0 0 0 0
  98849. +0 0 0 0 0 0 0 0 0
  98850. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98851. +0 0 0 31 45 11 101 146 34 118 170 40 117 169 40 117 169 40
  98852. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98853. +119 171 41 102 148 35 47 69 16 14 20 5 50 72 17 102 148 35
  98854. +118 171 40 117 169 40 117 169 40 117 169 40 118 170 40 102 148 35
  98855. +15 21 5 0 0 0 0 0 0 50 72 17 118 170 40 117 169 40
  98856. +117 169 40 117 169 40 118 170 40 116 167 40 84 121 28 27 40 9
  98857. +19 27 6 74 107 25 114 165 39 118 171 40 117 169 40 117 169 40
  98858. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98859. +117 169 40 75 109 26 10 15 4 0 0 0 0 0 0 0 0 0
  98860. +0 0 0 0 0 0 0 0 0
  98861. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98862. +0 0 0 38 55 13 102 148 35 118 171 40 117 169 40 117 169 40
  98863. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98864. +117 169 40 118 170 40 115 167 39 77 111 26 17 25 6 19 27 6
  98865. +77 111 26 115 166 39 118 170 40 117 169 40 119 172 41 81 118 28
  98866. +3 4 1 0 0 0 0 0 0 27 40 9 111 160 38 118 170 40
  98867. +117 169 40 118 171 40 105 151 36 50 72 17 10 15 3 38 55 13
  98868. +100 144 34 118 171 40 117 169 40 117 169 40 117 169 40 117 169 40
  98869. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98870. +117 169 40 79 115 27 15 21 5 0 0 0 0 0 0 0 0 0
  98871. +0 0 0 0 0 0 0 0 0
  98872. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98873. +0 0 0 10 15 3 64 92 22 111 160 38 117 169 40 117 169 40
  98874. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98875. +117 169 40 117 169 40 117 169 40 118 171 40 96 138 32 32 47 11
  98876. +3 4 1 50 72 17 107 154 36 120 173 41 105 151 36 31 45 11
  98877. +0 0 0 0 0 0 0 0 0 3 4 1 65 94 22 117 169 40
  98878. +118 170 40 89 128 30 26 37 9 3 4 1 60 86 20 111 161 38
  98879. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98880. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98881. +97 141 33 36 52 12 1 1 0 0 0 0 0 0 0 0 0 0
  98882. +0 0 0 0 0 0 0 0 0
  98883. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98884. +0 0 0 0 0 0 14 20 5 75 109 26 117 168 40 117 169 40
  98885. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98886. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 40 107 154 36
  98887. +45 64 15 2 3 1 31 45 11 75 109 26 32 47 11 0 1 0
  98888. +0 0 0 0 0 0 0 0 0 0 0 0 10 15 3 55 80 19
  98889. +65 94 22 11 16 4 11 16 4 75 109 26 116 168 40 118 170 40
  98890. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98891. +117 169 40 117 169 40 117 169 40 117 169 40 118 170 40 107 154 36
  98892. +47 69 16 3 4 1 0 0 0 0 0 0 0 0 0 0 0 0
  98893. +0 0 0 0 0 0 0 0 0
  98894. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98895. +0 0 0 0 0 0 12 18 4 69 100 23 111 161 38 118 171 40
  98896. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98897. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 118 170 40
  98898. +111 160 38 50 72 17 2 3 1 2 3 1 0 0 0 0 0 0
  98899. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  98900. +1 1 0 12 18 4 81 118 28 118 170 40 117 169 40 117 169 40
  98901. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98902. +117 169 40 117 169 40 117 169 40 117 170 40 118 171 40 101 146 34
  98903. +42 61 14 2 3 1 0 0 0 0 0 0 0 0 0 0 0 0
  98904. +0 0 0 0 0 0 0 0 0
  98905. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98906. +0 0 0 0 0 0 0 0 0 3 4 1 36 52 12 89 128 30
  98907. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98908. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98909. +118 171 41 101 146 34 14 20 5 0 0 0 0 0 0 0 0 0
  98910. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98911. +0 0 0 47 69 16 118 170 40 117 169 40 117 169 40 117 169 40
  98912. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98913. +117 169 40 117 169 40 117 170 40 111 160 38 69 100 23 19 27 6
  98914. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98915. +0 0 0 0 0 0 0 0 0
  98916. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98917. +0 0 0 0 0 0 0 0 0 0 0 0 11 16 4 69 100 23
  98918. +115 167 39 119 172 41 117 169 40 117 169 40 117 169 40 117 169 40
  98919. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98920. +119 172 41 75 109 26 3 4 1 0 0 0 0 0 0 0 0 0
  98921. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98922. +0 0 0 23 34 8 106 153 36 118 170 40 117 169 40 117 169 40
  98923. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98924. +117 169 40 118 170 40 119 172 41 105 151 36 42 61 14 2 3 1
  98925. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98926. +0 0 0 0 0 0 0 0 0
  98927. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98928. +0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 15 21 5
  98929. +45 64 15 80 116 27 114 165 39 118 170 40 117 169 40 117 169 40
  98930. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 119 172 41
  98931. +97 141 33 20 30 7 0 0 0 0 0 0 0 0 0 0 0 0
  98932. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98933. +0 0 0 1 1 0 53 76 18 114 165 39 118 171 40 117 169 40
  98934. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98935. +118 171 40 104 150 35 64 92 22 31 45 11 10 15 3 0 0 0
  98936. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98937. +0 0 0 0 0 0 0 0 0
  98938. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98939. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98940. +0 0 0 36 52 12 97 141 33 109 158 37 113 163 39 116 168 40
  98941. +117 169 40 117 170 40 118 170 40 119 172 41 115 167 39 84 121 28
  98942. +23 34 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98943. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98944. +0 0 0 0 0 0 3 4 1 50 72 17 102 148 35 118 171 40
  98945. +119 171 41 118 170 40 117 169 40 117 169 40 115 166 39 111 161 38
  98946. +109 157 37 79 115 27 12 18 4 0 0 0 0 0 0 0 0 0
  98947. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98948. +0 0 0 0 0 0 0 0 0
  98949. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98950. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98951. +0 0 0 3 4 1 15 21 5 23 34 8 45 64 15 106 153 36
  98952. +116 167 40 111 160 38 101 146 34 79 115 27 42 61 14 10 15 3
  98953. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98954. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98955. +0 0 0 0 0 0 0 0 0 1 1 0 20 30 7 60 86 20
  98956. +89 128 30 106 153 36 113 163 39 117 169 40 84 121 28 29 42 10
  98957. +19 27 6 10 15 3 2 3 1 0 0 0 0 0 0 0 0 0
  98958. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98959. +0 0 0 0 0 0 0 0 0
  98960. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98961. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98962. +0 0 0 0 0 0 0 0 0 0 0 0 16 23 5 38 55 13
  98963. +36 52 12 26 37 9 12 18 4 2 3 1 0 0 0 0 0 0
  98964. +0 0 0 0 0 0 0 0 0 1 0 0 19 2 7 52 5 18
  98965. +78 7 27 88 8 31 81 7 29 56 5 19 25 2 9 3 0 1
  98966. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98967. +3 4 1 19 27 6 31 45 11 38 55 13 32 47 11 3 4 1
  98968. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98969. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98970. +0 0 0 0 0 0 0 0 0
  98971. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98972. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98973. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 1
  98974. +9 0 3 12 1 4 9 0 3 4 0 1 0 0 0 0 0 0
  98975. +0 0 0 0 0 0 28 3 10 99 9 35 156 14 55 182 16 64
  98976. +189 17 66 190 17 67 189 17 66 184 17 65 166 15 58 118 13 41
  98977. +45 4 16 3 0 1 0 0 0 0 0 0 0 0 0 0 0 0
  98978. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98979. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98980. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98981. +0 0 0 0 0 0 0 0 0
  98982. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98983. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98984. +0 0 0 0 0 0 11 1 4 52 5 18 101 9 35 134 12 47
  98985. +151 14 53 154 14 54 151 14 53 113 10 40 11 1 4 0 0 0
  98986. +3 0 1 67 6 24 159 14 56 190 17 67 190 17 67 188 17 66
  98987. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 191 17 67
  98988. +174 16 61 101 9 35 14 1 5 0 0 0 35 3 12 108 10 38
  98989. +122 11 43 122 11 43 112 10 39 87 8 30 50 5 17 13 1 5
  98990. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98991. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98992. +0 0 0 0 0 0 0 0 0
  98993. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98994. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98995. +3 0 1 56 5 19 141 13 49 182 16 64 191 17 67 191 17 67
  98996. +190 17 67 190 17 67 191 17 67 113 10 40 3 0 1 1 0 0
  98997. +79 7 28 180 16 63 190 17 67 188 17 66 188 17 66 188 17 66
  98998. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98999. +189 17 66 188 17 66 122 11 43 11 1 4 41 4 14 176 16 62
  99000. +191 17 67 191 17 67 191 17 67 190 17 67 181 16 63 146 13 51
  99001. +75 7 26 10 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  99002. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99003. +0 0 0 0 0 0 0 0 0
  99004. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99005. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 1 2
  99006. +90 8 32 178 16 62 191 17 67 188 17 66 188 17 66 188 17 66
  99007. +188 17 66 190 17 67 141 13 49 22 2 8 0 0 0 41 4 14
  99008. +173 16 61 190 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  99009. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99010. +188 17 66 188 17 66 188 17 66 88 8 31 1 0 0 89 8 31
  99011. +185 17 65 189 17 66 188 17 66 188 17 66 189 17 66 191 17 67
  99012. +186 17 65 124 11 43 25 2 9 0 0 0 0 0 0 0 0 0
  99013. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99014. +0 0 0 0 0 0 0 0 0
  99015. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99016. +0 0 0 0 0 0 0 0 0 0 0 0 2 0 1 89 8 31
  99017. +184 17 65 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99018. +190 17 67 151 14 53 34 3 12 0 0 0 0 0 0 79 7 28
  99019. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99020. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99021. +188 17 66 188 17 66 191 17 67 146 13 51 9 1 3 7 1 2
  99022. +108 10 38 187 17 66 189 17 66 188 17 66 188 17 66 188 17 66
  99023. +188 17 66 190 17 67 141 13 49 22 2 8 0 0 0 0 0 0
  99024. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99025. +0 0 0 0 0 0 0 0 0
  99026. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99027. +0 0 0 0 0 0 0 0 0 0 0 0 52 5 18 176 16 62
  99028. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  99029. +151 14 53 38 3 13 0 0 0 0 0 0 0 0 0 50 5 17
  99030. +180 16 63 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99031. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99032. +188 17 66 188 17 66 191 17 67 141 13 49 7 1 3 0 0 0
  99033. +11 1 4 112 10 39 187 17 66 189 17 66 188 17 66 188 17 66
  99034. +188 17 66 188 17 66 190 17 67 113 10 40 5 0 2 0 0 0
  99035. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99036. +0 0 0 0 0 0 0 0 0
  99037. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99038. +0 0 0 0 0 0 0 0 0 7 1 3 132 12 46 191 17 67
  99039. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 146 13 51
  99040. +35 3 12 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  99041. +101 9 35 185 17 65 190 17 67 188 17 66 188 17 66 188 17 66
  99042. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99043. +188 17 66 190 17 67 180 16 63 67 6 24 0 0 0 0 0 0
  99044. +0 0 0 11 1 4 108 10 38 186 17 65 189 17 66 188 17 66
  99045. +188 17 66 188 17 66 189 17 66 180 16 63 56 5 19 0 0 0
  99046. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99047. +0 0 0 0 0 0 0 0 0
  99048. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99049. +0 0 0 0 0 0 0 0 0 44 4 15 177 16 62 189 17 66
  99050. +188 17 66 188 17 66 189 17 66 189 17 66 134 12 47 28 3 10
  99051. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99052. +8 1 3 79 7 28 159 14 56 188 17 66 191 17 67 190 17 67
  99053. +189 17 66 189 17 66 189 17 66 189 17 66 190 17 67 191 17 67
  99054. +188 17 66 158 14 55 72 7 25 4 0 1 0 0 0 0 0 0
  99055. +0 0 0 0 0 0 8 1 3 95 9 33 182 16 64 189 17 67
  99056. +188 17 66 188 17 66 188 17 66 191 17 67 122 11 43 3 0 1
  99057. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99058. +0 0 0 0 0 0 0 0 0
  99059. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99060. +0 0 0 0 0 0 0 0 0 88 8 31 190 17 67 188 17 66
  99061. +188 17 66 189 17 66 185 17 65 113 10 40 18 2 6 0 0 0
  99062. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99063. +0 0 0 1 0 0 24 2 8 77 7 27 124 11 43 154 14 54
  99064. +168 15 59 173 16 61 173 16 61 168 15 59 154 14 54 124 11 43
  99065. +77 7 27 22 2 8 0 0 0 0 0 0 0 0 0 0 0 0
  99066. +0 0 0 0 0 0 0 0 0 5 0 2 77 7 27 173 16 61
  99067. +190 17 67 188 17 66 188 17 66 190 17 67 164 15 57 23 2 8
  99068. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99069. +0 0 0 0 0 0 0 0 0
  99070. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99071. +0 0 0 0 0 0 1 0 0 118 13 41 191 17 67 188 17 66
  99072. +190 17 67 174 16 61 87 8 30 8 1 3 0 0 0 0 0 0
  99073. +0 0 0 0 0 0 10 1 4 29 3 10 40 4 14 36 3 13
  99074. +18 2 6 2 0 1 0 0 0 0 0 0 3 0 1 14 1 5
  99075. +26 2 9 33 3 11 32 3 11 25 2 9 13 1 5 3 0 1
  99076. +0 0 0 14 1 5 56 5 19 95 9 33 109 10 38 101 9 35
  99077. +77 7 27 35 3 12 5 0 2 0 0 0 1 0 0 56 5 19
  99078. +156 14 55 190 17 67 188 17 66 188 17 66 182 16 64 50 5 17
  99079. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99080. +0 0 0 0 0 0 0 0 0
  99081. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99082. +0 0 0 0 0 0 5 0 2 134 12 47 191 17 67 189 17 66
  99083. +151 14 53 52 5 18 2 0 1 0 0 0 0 0 0 1 0 0
  99084. +28 3 10 90 8 32 146 13 51 170 15 60 178 16 62 174 16 61
  99085. +158 14 55 112 10 39 40 4 14 1 0 0 0 0 0 0 0 0
  99086. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 1
  99087. +56 5 19 146 13 51 183 17 64 191 17 67 191 17 67 191 17 67
  99088. +188 17 66 173 16 61 122 11 43 41 4 14 1 0 0 0 0 0
  99089. +30 3 10 124 11 43 185 17 65 190 17 67 187 17 66 67 6 24
  99090. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99091. +0 0 0 0 0 0 0 0 0
  99092. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99093. +0 0 0 0 0 0 6 1 2 134 12 47 168 15 59 99 9 35
  99094. +21 2 7 0 0 0 0 0 0 0 0 0 6 1 2 77 7 27
  99095. +162 15 57 190 17 67 191 17 67 189 17 66 189 17 66 189 17 66
  99096. +190 17 67 191 17 67 169 15 59 75 7 26 3 0 1 0 0 0
  99097. +0 0 0 0 0 0 0 0 0 0 0 0 2 0 1 79 7 28
  99098. +178 16 62 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  99099. +188 17 66 189 17 66 191 17 67 170 15 60 79 7 28 5 0 2
  99100. +0 0 0 10 1 3 78 7 27 159 14 56 188 17 66 75 7 26
  99101. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99102. +0 0 0 0 0 0 0 0 0
  99103. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99104. +0 0 0 0 0 0 1 0 0 35 3 12 29 3 10 2 0 1
  99105. +0 0 0 0 0 0 0 0 0 9 1 3 101 9 35 183 17 64
  99106. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99107. +188 17 66 188 17 66 190 17 67 178 16 63 67 6 23 0 0 0
  99108. +0 0 0 0 0 0 0 0 0 0 0 0 52 5 18 174 16 61
  99109. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99110. +188 17 66 188 17 66 188 17 66 190 17 67 182 16 64 89 8 31
  99111. +4 0 1 0 0 0 0 0 0 25 2 9 73 7 26 31 3 11
  99112. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99113. +0 0 0 0 0 0 0 0 0
  99114. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99115. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99116. +0 0 0 0 0 0 4 0 1 98 9 34 187 17 66 189 17 66
  99117. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99118. +188 17 66 188 17 66 188 17 66 190 17 67 158 14 55 25 2 9
  99119. +0 0 0 0 0 0 0 0 0 8 1 3 134 12 47 191 17 67
  99120. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99121. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 180 16 63
  99122. +68 6 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99123. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99124. +0 0 0 0 0 0 0 0 0
  99125. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99126. +0 0 0 6 1 2 19 2 7 3 0 1 0 0 0 0 0 0
  99127. +0 0 0 0 0 0 65 6 23 180 16 63 189 17 66 188 17 66
  99128. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99129. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 83 8 29
  99130. +0 0 0 0 0 0 0 0 0 41 4 14 177 16 62 189 17 66
  99131. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99132. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  99133. +159 14 56 28 3 10 0 0 0 0 0 0 0 0 0 23 2 8
  99134. +41 4 14 5 0 2 0 0 0 0 0 0 0 0 0 0 0 0
  99135. +0 0 0 0 0 0 0 0 0
  99136. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99137. +23 2 8 113 10 40 159 14 56 65 6 23 0 0 0 0 0 0
  99138. +0 0 0 16 1 6 146 13 51 191 17 67 188 17 66 188 17 66
  99139. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99140. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 132 12 46
  99141. +5 0 2 0 0 0 0 0 0 77 7 27 189 17 66 188 17 66
  99142. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99143. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99144. +190 17 67 98 9 34 0 0 0 0 0 0 12 1 4 134 12 47
  99145. +178 16 63 108 10 38 16 1 6 0 0 0 0 0 0 0 0 0
  99146. +0 0 0 0 0 0 0 0 0
  99147. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 30 3 10
  99148. +141 13 49 190 17 67 191 17 67 134 12 47 6 1 2 0 0 0
  99149. +0 0 0 68 6 24 186 17 65 188 17 66 188 17 66 188 17 66
  99150. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99151. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 156 14 55
  99152. +14 1 5 0 0 0 0 0 0 98 9 34 191 17 67 188 17 66
  99153. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99154. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99155. +190 17 67 156 14 55 19 2 7 0 0 0 47 4 16 181 16 63
  99156. +190 17 67 189 17 66 126 14 44 17 2 6 0 0 0 0 0 0
  99157. +0 0 0 0 0 0 0 0 0
  99158. +0 0 0 0 0 0 0 0 0 0 0 0 16 1 6 134 12 47
  99159. +191 17 67 188 17 66 190 17 67 162 15 57 19 2 7 0 0 0
  99160. +3 0 1 123 11 43 191 17 67 188 17 66 188 17 66 188 17 66
  99161. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99162. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 163 15 57
  99163. +20 2 7 0 0 0 0 0 0 101 9 35 191 17 67 188 17 66
  99164. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99165. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99166. +188 17 66 182 16 64 52 5 18 0 0 0 73 7 26 188 17 66
  99167. +188 17 66 188 17 66 189 17 66 109 10 38 5 0 2 0 0 0
  99168. +0 0 0 0 0 0 0 0 0
  99169. +0 0 0 0 0 0 0 0 0 0 0 0 95 9 33 189 17 66
  99170. +188 17 66 188 17 66 189 17 66 171 15 60 29 3 10 0 0 0
  99171. +16 1 6 156 14 55 190 17 67 188 17 66 188 17 66 188 17 66
  99172. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99173. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 158 14 55
  99174. +17 2 6 0 0 0 0 0 0 85 8 30 190 17 67 188 17 66
  99175. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99176. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99177. +188 17 66 189 17 66 81 7 29 0 0 0 85 8 30 190 17 67
  99178. +188 17 66 188 17 66 189 17 66 180 16 63 56 5 19 0 0 0
  99179. +0 0 0 0 0 0 0 0 0
  99180. +0 0 0 0 0 0 0 0 0 25 2 9 162 15 57 190 17 67
  99181. +188 17 66 188 17 66 189 17 66 173 16 61 31 3 11 0 0 0
  99182. +30 3 10 171 15 60 189 17 66 188 17 66 188 17 66 188 17 66
  99183. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99184. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 141 13 49
  99185. +7 1 2 0 0 0 0 0 0 56 5 19 183 17 64 188 17 66
  99186. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99187. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99188. +188 17 66 191 17 67 98 9 34 0 0 0 88 8 31 190 17 67
  99189. +188 17 66 188 17 66 188 17 66 191 17 67 124 11 43 5 0 2
  99190. +0 0 0 0 0 0 0 0 0
  99191. +0 0 0 0 0 0 0 0 0 68 6 24 187 17 66 188 17 66
  99192. +188 17 66 188 17 66 189 17 66 170 15 60 28 3 10 0 0 0
  99193. +34 3 12 174 16 61 189 17 66 188 17 66 188 17 66 188 17 66
  99194. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99195. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 101 9 35
  99196. +0 0 0 0 0 0 0 0 0 21 2 7 159 14 56 190 17 67
  99197. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99198. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99199. +188 17 66 191 17 67 98 9 34 0 0 0 81 7 29 189 17 66
  99200. +188 17 66 188 17 66 188 17 66 189 17 66 168 15 59 28 3 10
  99201. +0 0 0 0 0 0 0 0 0
  99202. +0 0 0 0 0 0 0 0 0 109 10 38 191 17 67 188 17 66
  99203. +188 17 66 188 17 66 190 17 67 163 15 57 21 2 7 0 0 0
  99204. +26 2 9 168 15 59 189 17 66 188 17 66 188 17 66 188 17 66
  99205. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99206. +188 17 66 188 17 66 188 17 66 189 17 66 180 16 63 47 4 16
  99207. +0 0 0 0 0 0 0 0 0 0 0 0 108 10 38 190 17 67
  99208. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99209. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99210. +188 17 66 189 17 66 78 7 27 0 0 0 68 6 24 187 17 66
  99211. +188 17 66 188 17 66 188 17 66 188 17 66 183 17 64 56 5 19
  99212. +0 0 0 0 0 0 0 0 0
  99213. +0 0 0 0 0 0 3 0 1 131 12 46 191 17 67 188 17 66
  99214. +188 17 66 188 17 66 190 17 67 151 14 53 12 1 4 0 0 0
  99215. +11 1 4 146 13 51 190 17 67 188 17 66 188 17 66 188 17 66
  99216. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99217. +188 17 66 188 17 66 188 17 66 191 17 67 126 14 44 7 1 2
  99218. +0 0 0 0 0 0 0 0 0 0 0 0 32 3 11 164 15 58
  99219. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99220. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99221. +189 17 66 178 16 62 44 4 15 0 0 0 50 5 17 182 16 64
  99222. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 72 7 25
  99223. +0 0 0 0 0 0 0 0 0
  99224. +0 0 0 0 0 0 5 0 2 134 12 47 191 17 67 188 17 66
  99225. +188 17 66 188 17 66 191 17 67 131 12 46 3 0 1 0 0 0
  99226. +0 0 0 101 9 35 190 17 67 188 17 66 188 17 66 188 17 66
  99227. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99228. +188 17 66 188 17 66 190 17 67 170 15 60 44 4 15 0 0 0
  99229. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 77 7 27
  99230. +183 17 64 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99231. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99232. +191 17 67 134 12 47 9 1 3 0 0 0 31 3 11 171 15 60
  99233. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 72 7 25
  99234. +0 0 0 0 0 0 0 0 0
  99235. +0 0 0 0 0 0 2 0 1 124 11 43 191 17 67 188 17 66
  99236. +188 17 66 188 17 66 191 17 67 101 9 35 0 0 0 0 0 0
  99237. +0 0 0 35 3 12 168 15 59 190 17 67 188 17 66 188 17 66
  99238. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99239. +188 17 66 189 17 66 182 16 64 77 7 27 0 0 0 0 0 0
  99240. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 1 2
  99241. +99 9 35 185 17 65 189 17 66 188 17 66 188 17 66 188 17 66
  99242. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  99243. +177 16 62 56 5 19 0 0 0 0 0 0 13 1 5 151 14 53
  99244. +190 17 67 188 17 66 188 17 66 188 17 66 185 17 65 56 5 19
  99245. +0 0 0 0 0 0 0 0 0
  99246. +0 0 0 0 0 0 0 0 0 99 9 35 191 17 67 188 17 66
  99247. +188 17 66 188 17 66 186 17 65 65 6 23 0 0 0 0 0 0
  99248. +0 0 0 0 0 0 79 7 28 182 16 64 190 17 67 188 17 66
  99249. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99250. +191 17 67 177 16 62 83 8 29 4 0 1 0 0 0 0 0 0
  99251. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99252. +8 1 3 89 8 31 175 16 62 191 17 67 189 17 66 188 17 66
  99253. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 181 16 63
  99254. +85 8 30 3 0 1 0 0 0 0 0 0 1 0 0 118 13 41
  99255. +191 17 67 188 17 66 188 17 66 189 17 66 173 16 61 34 3 12
  99256. +0 0 0 0 0 0 0 0 0
  99257. +0 0 0 0 0 0 0 0 0 56 5 19 183 17 64 188 17 66
  99258. +188 17 66 189 17 66 169 15 59 30 3 10 0 0 0 0 0 0
  99259. +0 0 0 0 0 0 5 0 2 83 8 29 173 16 61 191 17 67
  99260. +190 17 67 189 17 66 189 17 66 190 17 67 191 17 67 187 17 66
  99261. +151 14 53 56 5 19 3 0 1 0 0 0 16 1 6 50 5 17
  99262. +79 7 28 95 9 33 95 9 33 75 7 26 41 4 14 10 1 4
  99263. +0 0 0 2 0 1 50 5 17 132 12 46 178 16 62 190 17 67
  99264. +191 17 67 191 17 67 191 17 67 186 17 65 154 14 54 68 6 24
  99265. +4 0 1 0 0 0 0 0 0 0 0 0 0 0 0 72 7 25
  99266. +187 17 66 188 17 66 188 17 66 191 17 67 141 13 49 9 1 3
  99267. +0 0 0 0 0 0 0 0 0
  99268. +0 0 0 0 0 0 0 0 0 14 1 5 151 14 53 190 17 67
  99269. +188 17 66 191 17 67 131 12 46 5 0 2 0 0 0 0 0 0
  99270. +0 0 0 0 0 0 0 0 0 2 0 1 44 4 15 113 10 40
  99271. +156 14 55 173 16 61 174 16 61 164 15 58 134 12 47 77 7 27
  99272. +18 2 6 0 0 0 16 1 6 85 8 30 151 14 53 182 16 64
  99273. +189 17 66 191 17 67 190 17 67 188 17 66 177 16 62 141 13 49
  99274. +68 6 24 8 1 3 0 0 0 8 1 3 44 4 15 88 8 31
  99275. +113 10 40 122 11 43 108 10 38 67 6 24 20 2 7 0 0 0
  99276. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 28 3 10
  99277. +166 15 58 190 17 67 188 17 66 187 17 66 79 7 28 0 0 0
  99278. +0 0 0 0 0 0 0 0 0
  99279. +0 0 0 0 0 0 0 0 0 0 0 0 73 7 26 185 17 65
  99280. +189 17 66 184 17 65 65 6 23 0 0 0 0 0 0 0 0 0
  99281. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 1
  99282. +17 2 6 32 3 11 34 3 12 22 2 8 6 1 2 0 0 0
  99283. +0 0 0 38 3 13 141 13 49 188 17 66 190 17 67 188 17 66
  99284. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 191 17 67
  99285. +184 17 65 122 11 43 21 2 7 0 0 0 0 0 0 0 0 0
  99286. +0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99287. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  99288. +108 10 38 191 17 67 191 17 67 141 13 49 16 1 6 0 0 0
  99289. +0 0 0 0 0 0 0 0 0
  99290. +0 0 0 0 0 0 0 0 0 0 0 0 8 1 3 112 10 39
  99291. +186 17 65 124 11 43 10 1 4 0 0 0 0 0 0 0 0 0
  99292. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99293. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99294. +36 3 13 156 14 55 191 17 67 188 17 66 188 17 66 188 17 66
  99295. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99296. +189 17 66 190 17 67 134 12 47 18 2 6 0 0 0 0 0 0
  99297. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99298. +0 0 0 7 1 2 41 4 14 75 7 26 66 5 23 19 2 7
  99299. +26 2 9 144 13 50 154 14 54 40 4 14 0 0 0 0 0 0
  99300. +0 0 0 0 0 0 0 0 0
  99301. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 1 5
  99302. +56 5 19 19 2 7 0 0 0 7 1 2 29 3 10 35 3 12
  99303. +19 2 7 2 0 1 0 0 0 0 0 0 0 0 0 0 0 0
  99304. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 1 5
  99305. +134 12 47 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  99306. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99307. +188 17 66 188 17 66 189 17 67 108 10 38 3 0 1 0 0 0
  99308. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  99309. +40 4 14 124 11 43 177 16 62 188 17 66 187 17 66 144 13 50
  99310. +24 2 8 17 2 6 22 2 8 0 0 0 0 0 0 0 0 0
  99311. +0 0 0 0 0 0 0 0 0
  99312. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99313. +0 0 0 0 0 0 19 2 7 122 11 43 171 15 60 175 16 62
  99314. +159 14 56 112 10 39 40 4 14 2 0 1 0 0 0 0 0 0
  99315. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 72 7 25
  99316. +186 17 65 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99317. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99318. +188 17 66 188 17 66 189 17 66 174 16 61 41 4 14 0 0 0
  99319. +0 0 0 0 0 0 0 0 0 0 0 0 3 0 1 72 7 25
  99320. +168 15 59 191 17 67 189 17 66 188 17 66 188 17 66 190 17 67
  99321. +95 9 33 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99322. +0 0 0 0 0 0 0 0 0
  99323. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99324. +0 0 0 0 0 0 95 9 33 191 17 67 189 17 66 189 17 66
  99325. +190 17 67 191 17 67 171 15 60 90 8 32 12 1 4 0 0 0
  99326. +0 0 0 0 0 0 0 0 0 0 0 0 5 0 2 132 12 46
  99327. +191 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99328. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99329. +188 17 66 188 17 66 188 17 66 190 17 67 98 9 34 0 0 0
  99330. +0 0 0 0 0 0 0 0 0 5 0 2 88 8 31 180 16 63
  99331. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 191 17 67
  99332. +146 13 51 11 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  99333. +0 0 0 0 0 0 0 0 0
  99334. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99335. +0 0 0 9 1 3 144 13 50 191 17 67 188 17 66 188 17 66
  99336. +188 17 66 188 17 66 189 17 66 187 17 66 123 11 43 20 2 7
  99337. +0 0 0 0 0 0 0 0 0 0 0 0 21 2 7 163 15 57
  99338. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99339. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99340. +188 17 66 188 17 66 188 17 66 191 17 67 134 12 47 5 0 2
  99341. +0 0 0 0 0 0 3 0 1 88 8 31 182 16 64 189 17 66
  99342. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  99343. +171 15 60 31 3 11 0 0 0 0 0 0 0 0 0 0 0 0
  99344. +0 0 0 0 0 0 0 0 0
  99345. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99346. +0 0 0 20 2 7 162 15 57 190 17 67 188 17 66 188 17 66
  99347. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 132 12 46
  99348. +20 2 7 0 0 0 0 0 0 0 0 0 32 3 11 173 16 61
  99349. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99350. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99351. +188 17 66 188 17 66 188 17 66 190 17 67 151 14 53 12 1 4
  99352. +0 0 0 0 0 0 72 7 25 180 16 63 189 17 66 188 17 66
  99353. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99354. +181 16 63 47 4 16 0 0 0 0 0 0 0 0 0 0 0 0
  99355. +0 0 0 0 0 0 0 0 0
  99356. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99357. +0 0 0 21 2 7 163 15 57 190 17 67 188 17 66 188 17 66
  99358. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  99359. +122 11 43 9 1 3 0 0 0 0 0 0 30 3 10 171 15 60
  99360. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99361. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99362. +188 17 66 188 17 66 188 17 66 190 17 67 146 13 51 10 1 4
  99363. +0 0 0 38 3 13 166 15 58 190 17 67 188 17 66 188 17 66
  99364. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99365. +183 17 64 52 5 18 0 0 0 0 0 0 0 0 0 0 0 0
  99366. +0 0 0 0 0 0 0 0 0
  99367. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99368. +0 0 0 13 1 5 154 14 54 190 17 67 188 17 66 188 17 66
  99369. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99370. +186 17 65 79 7 28 0 0 0 0 0 0 14 1 5 156 14 54
  99371. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99372. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99373. +188 17 66 188 17 66 188 17 66 191 17 67 124 11 43 2 0 1
  99374. +5 0 2 122 11 43 191 17 67 188 17 66 188 17 66 188 17 66
  99375. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99376. +182 16 64 47 4 16 0 0 0 0 0 0 0 0 0 0 0 0
  99377. +0 0 0 0 0 0 0 0 0
  99378. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99379. +0 0 0 3 0 1 126 14 44 191 17 67 188 17 66 188 17 66
  99380. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99381. +190 17 67 158 14 55 23 2 8 0 0 0 1 0 0 113 10 40
  99382. +191 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99383. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99384. +188 17 66 188 17 66 188 17 66 188 17 66 78 7 27 0 0 0
  99385. +47 4 16 177 16 62 189 17 66 188 17 66 188 17 66 188 17 66
  99386. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  99387. +173 16 61 34 3 12 0 0 0 0 0 0 0 0 0 0 0 0
  99388. +0 0 0 0 0 0 0 0 0
  99389. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99390. +0 0 0 0 0 0 85 8 30 189 17 66 188 17 66 188 17 66
  99391. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99392. +188 17 66 188 17 66 79 7 28 0 0 0 0 0 0 47 4 16
  99393. +175 16 62 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99394. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99395. +188 17 66 188 17 66 190 17 67 156 14 55 22 2 8 0 0 0
  99396. +109 10 38 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  99397. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  99398. +151 14 53 13 1 5 0 0 0 0 0 0 0 0 0 0 0 0
  99399. +0 0 0 0 0 0 0 0 0
  99400. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99401. +0 0 0 0 0 0 35 3 12 173 16 61 189 17 66 188 17 66
  99402. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99403. +188 17 66 191 17 67 134 12 47 7 1 2 0 0 0 3 0 1
  99404. +99 9 35 188 17 66 189 17 66 188 17 66 188 17 66 188 17 66
  99405. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99406. +188 17 66 189 17 66 181 16 63 68 6 24 0 0 0 18 2 6
  99407. +156 14 55 190 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  99408. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  99409. +101 9 35 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99410. +0 0 0 0 0 0 0 0 0
  99411. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99412. +0 0 0 0 0 0 3 0 1 118 13 41 191 17 67 188 17 66
  99413. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99414. +188 17 66 189 17 66 168 15 59 28 3 10 0 0 0 0 0 0
  99415. +12 1 4 113 10 40 187 17 66 189 17 67 188 17 66 188 17 66
  99416. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99417. +190 17 67 180 16 63 88 8 31 4 0 1 0 0 0 47 4 16
  99418. +180 16 63 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99419. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 168 15 59
  99420. +36 3 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99421. +0 0 0 0 0 0 0 0 0
  99422. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99423. +0 0 0 0 0 0 0 0 0 38 3 13 164 15 58 190 17 67
  99424. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99425. +188 17 66 188 17 66 182 16 64 50 5 17 0 0 0 0 0 0
  99426. +0 0 0 11 1 4 90 8 32 169 15 59 190 17 67 190 17 67
  99427. +189 17 66 189 17 66 189 17 66 189 17 66 191 17 67 189 17 66
  99428. +158 14 55 68 6 24 4 0 1 0 0 0 0 0 0 73 7 26
  99429. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99430. +188 17 66 188 17 66 188 17 66 189 17 66 185 17 65 83 8 29
  99431. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99432. +0 0 0 0 0 0 0 0 0
  99433. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99434. +0 0 0 0 0 0 0 0 0 0 0 0 65 6 23 174 16 61
  99435. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99436. +188 17 66 188 17 66 185 17 65 56 5 19 0 0 0 0 0 0
  99437. +0 0 0 0 0 0 2 0 1 35 3 12 99 9 35 146 13 51
  99438. +170 15 60 177 16 62 177 16 62 166 15 58 141 13 49 85 8 30
  99439. +24 2 8 0 0 0 0 0 0 0 0 0 0 0 0 85 8 30
  99440. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99441. +188 17 66 188 17 66 188 17 66 189 17 66 112 10 39 8 1 3
  99442. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99443. +0 0 0 0 0 0 0 0 0
  99444. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99445. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 68 6 24
  99446. +170 15 60 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  99447. +188 17 66 188 17 66 182 16 64 50 5 17 0 0 0 0 0 0
  99448. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 11 1 4
  99449. +28 3 10 40 4 14 38 3 13 25 2 9 8 1 3 0 0 0
  99450. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 78 7 27
  99451. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99452. +188 17 66 189 17 66 187 17 66 113 10 40 14 1 5 0 0 0
  99453. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99454. +0 0 0 0 0 0 0 0 0
  99455. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99456. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  99457. +47 4 16 141 13 49 186 17 65 191 17 67 190 17 67 189 17 66
  99458. +189 17 66 191 17 67 156 14 55 20 2 7 0 0 0 0 0 0
  99459. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99460. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99461. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 44 4 15
  99462. +178 16 62 190 17 67 188 17 66 188 17 66 188 17 66 190 17 67
  99463. +191 17 67 173 16 61 90 8 32 10 1 4 0 0 0 0 0 0
  99464. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99465. +0 0 0 0 0 0 0 0 0
  99466. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99467. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99468. +0 0 0 14 1 5 68 6 24 131 12 46 162 15 57 174 16 61
  99469. +171 15 60 146 13 51 56 5 19 0 0 0 0 0 0 0 0 0
  99470. +0 0 0 0 0 0 0 0 0 3 0 1 14 1 5 29 3 10
  99471. +41 4 14 47 4 16 50 5 17 45 4 16 34 3 12 18 2 6
  99472. +5 0 2 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  99473. +90 8 32 169 15 59 185 17 65 187 17 66 182 16 64 163 15 57
  99474. +113 10 40 41 4 14 2 0 1 0 0 0 0 0 0 0 0 0
  99475. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99476. +0 0 0 0 0 0 0 0 0
  99477. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99478. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99479. +0 0 0 0 0 0 0 0 0 5 0 2 21 2 7 34 3 12
  99480. +29 3 10 11 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  99481. +3 0 1 32 3 11 79 7 28 124 11 43 154 14 54 171 15 60
  99482. +180 16 63 182 16 64 182 16 64 180 16 63 174 16 61 159 14 56
  99483. +132 12 46 88 8 31 34 3 12 3 0 1 0 0 0 0 0 0
  99484. +3 0 1 29 3 10 56 5 19 65 6 23 50 5 17 23 2 8
  99485. +3 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99486. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99487. +0 0 0 0 0 0 0 0 0
  99488. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99489. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99490. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99491. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 25 2 9
  99492. +109 10 38 169 15 59 189 17 66 191 17 67 190 17 67 189 17 66
  99493. +189 17 66 188 17 66 188 17 66 188 17 66 189 17 66 190 17 67
  99494. +191 17 67 190 17 67 171 15 60 98 9 34 10 1 3 0 0 0
  99495. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99496. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99497. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99498. +0 0 0 0 0 0 0 0 0
  99499. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99500. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99501. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99502. +0 0 0 0 0 0 0 0 0 0 0 0 14 1 5 141 13 49
  99503. +191 17 67 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99504. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99505. +188 17 66 188 17 66 189 17 67 186 17 65 65 6 23 0 0 0
  99506. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99507. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99508. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99509. +0 0 0 0 0 0 0 0 0
  99510. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99511. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99512. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99513. +0 0 0 0 0 0 0 0 0 0 0 0 23 2 8 166 15 58
  99514. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99515. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99516. +188 17 66 188 17 66 189 17 66 176 16 62 45 4 16 0 0 0
  99517. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99518. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99519. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99520. +0 0 0 0 0 0 0 0 0
  99521. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99522. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99523. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99524. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 83 8 29
  99525. +183 17 64 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99526. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99527. +188 17 66 189 17 66 185 17 65 95 9 33 3 0 1 0 0 0
  99528. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99529. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99530. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99531. +0 0 0 0 0 0 0 0 0
  99532. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99533. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99534. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99535. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  99536. +85 8 30 176 16 62 191 17 67 188 17 66 188 17 66 188 17 66
  99537. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  99538. +191 17 67 180 16 63 95 9 33 7 1 3 0 0 0 0 0 0
  99539. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99540. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99541. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99542. +0 0 0 0 0 0 0 0 0
  99543. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99544. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99545. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99546. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99547. +2 0 1 52 5 18 141 13 49 185 17 65 191 17 67 189 17 67
  99548. +189 17 66 188 17 66 188 17 66 189 17 66 191 17 67 187 17 66
  99549. +146 13 51 56 5 19 4 0 1 0 0 0 0 0 0 0 0 0
  99550. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99551. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99552. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99553. +0 0 0 0 0 0 0 0 0
  99554. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99555. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99556. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99557. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99558. +0 0 0 0 0 0 14 1 5 68 6 24 131 12 46 166 15 58
  99559. +180 16 63 183 17 64 180 16 63 168 15 59 134 12 47 75 7 26
  99560. +17 2 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99561. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99562. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99563. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99564. +0 0 0 0 0 0 0 0 0
  99565. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99566. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99567. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99568. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99569. +0 0 0 0 0 0 0 0 0 0 0 0 5 0 2 24 2 8
  99570. +44 4 15 52 5 18 45 4 16 26 2 9 6 1 2 0 0 0
  99571. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99572. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99573. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99574. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99575. +0 0 0 0 0 0 0 0 0
  99576. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99577. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99578. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99579. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99580. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99581. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99582. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99583. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99584. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99585. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99586. +0 0 0 0 0 0 0 0 0
  99587. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99588. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99589. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99590. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99591. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99592. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99593. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99594. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99595. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99596. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99597. +0 0 0 0 0 0 0 0 0
  99598. diff -Nur linux-3.15.4/drivers/w1/masters/w1-gpio.c linux-rpi/drivers/w1/masters/w1-gpio.c
  99599. --- linux-3.15.4/drivers/w1/masters/w1-gpio.c 2014-07-07 03:59:25.000000000 +0200
  99600. +++ linux-rpi/drivers/w1/masters/w1-gpio.c 2014-07-07 10:45:47.000000000 +0200
  99601. @@ -23,6 +23,15 @@
  99602. #include "../w1.h"
  99603. #include "../w1_int.h"
  99604. +static int w1_gpio_pullup = -1;
  99605. +static int w1_gpio_pullup_orig = -1;
  99606. +module_param_named(pullup, w1_gpio_pullup, int, 0);
  99607. +MODULE_PARM_DESC(pullup, "GPIO pin pullup number");
  99608. +static int w1_gpio_pin = -1;
  99609. +static int w1_gpio_pin_orig = -1;
  99610. +module_param_named(gpiopin, w1_gpio_pin, int, 0);
  99611. +MODULE_PARM_DESC(gpiopin, "GPIO pin number");
  99612. +
  99613. static u8 w1_gpio_set_pullup(void *data, int delay)
  99614. {
  99615. struct w1_gpio_platform_data *pdata = data;
  99616. @@ -67,6 +76,16 @@
  99617. return gpio_get_value(pdata->pin) ? 1 : 0;
  99618. }
  99619. +static void w1_gpio_bitbang_pullup(void *data, u8 on)
  99620. +{
  99621. + struct w1_gpio_platform_data *pdata = data;
  99622. +
  99623. + if (on)
  99624. + gpio_direction_output(pdata->pin, 1);
  99625. + else
  99626. + gpio_direction_input(pdata->pin);
  99627. +}
  99628. +
  99629. #if defined(CONFIG_OF)
  99630. static struct of_device_id w1_gpio_dt_ids[] = {
  99631. { .compatible = "w1-gpio" },
  99632. @@ -113,13 +132,15 @@
  99633. static int w1_gpio_probe(struct platform_device *pdev)
  99634. {
  99635. struct w1_bus_master *master;
  99636. - struct w1_gpio_platform_data *pdata;
  99637. + struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
  99638. int err;
  99639. - if (of_have_populated_dt()) {
  99640. - err = w1_gpio_probe_dt(pdev);
  99641. - if (err < 0)
  99642. - return err;
  99643. + if(pdata == NULL) {
  99644. + if (of_have_populated_dt()) {
  99645. + err = w1_gpio_probe_dt(pdev);
  99646. + if (err < 0)
  99647. + return err;
  99648. + }
  99649. }
  99650. pdata = dev_get_platdata(&pdev->dev);
  99651. @@ -136,6 +157,19 @@
  99652. return -ENOMEM;
  99653. }
  99654. + w1_gpio_pin_orig = pdata->pin;
  99655. + w1_gpio_pullup_orig = pdata->ext_pullup_enable_pin;
  99656. +
  99657. + if(gpio_is_valid(w1_gpio_pin)) {
  99658. + pdata->pin = w1_gpio_pin;
  99659. + pdata->ext_pullup_enable_pin = -1;
  99660. + }
  99661. + if(gpio_is_valid(w1_gpio_pullup)) {
  99662. + pdata->ext_pullup_enable_pin = w1_gpio_pullup;
  99663. + }
  99664. +
  99665. + dev_info(&pdev->dev, "gpio pin %d, gpio pullup pin %d\n", pdata->pin, pdata->ext_pullup_enable_pin);
  99666. +
  99667. err = devm_gpio_request(&pdev->dev, pdata->pin, "w1");
  99668. if (err) {
  99669. dev_err(&pdev->dev, "gpio_request (pin) failed\n");
  99670. @@ -165,6 +199,14 @@
  99671. master->set_pullup = w1_gpio_set_pullup;
  99672. }
  99673. + if (gpio_is_valid(w1_gpio_pullup)) {
  99674. + if (pdata->is_open_drain)
  99675. + printk(KERN_ERR "w1-gpio 'pullup' option "
  99676. + "doesn't work with open drain GPIO\n");
  99677. + else
  99678. + master->bitbang_pullup = w1_gpio_bitbang_pullup;
  99679. + }
  99680. +
  99681. err = w1_add_master_device(master);
  99682. if (err) {
  99683. dev_err(&pdev->dev, "w1_add_master device failed\n");
  99684. @@ -195,6 +237,9 @@
  99685. w1_remove_master_device(master);
  99686. + pdata->pin = w1_gpio_pin_orig;
  99687. + pdata->ext_pullup_enable_pin = w1_gpio_pullup_orig;
  99688. +
  99689. return 0;
  99690. }
  99691. diff -Nur linux-3.15.4/drivers/w1/w1.h linux-rpi/drivers/w1/w1.h
  99692. --- linux-3.15.4/drivers/w1/w1.h 2014-07-07 03:59:25.000000000 +0200
  99693. +++ linux-rpi/drivers/w1/w1.h 2014-07-07 10:45:47.000000000 +0200
  99694. @@ -171,6 +171,12 @@
  99695. u8 (*set_pullup)(void *, int);
  99696. + /**
  99697. + * Turns the pullup on/off in bitbanging mode, takes an on/off argument.
  99698. + * @return -1=Error, 0=completed
  99699. + */
  99700. + void (*bitbang_pullup) (void *, u8);
  99701. +
  99702. void (*search)(void *, struct w1_master *,
  99703. u8, w1_slave_found_callback);
  99704. };
  99705. diff -Nur linux-3.15.4/drivers/w1/w1_int.c linux-rpi/drivers/w1/w1_int.c
  99706. --- linux-3.15.4/drivers/w1/w1_int.c 2014-07-07 03:59:25.000000000 +0200
  99707. +++ linux-rpi/drivers/w1/w1_int.c 2014-07-07 10:45:47.000000000 +0200
  99708. @@ -124,6 +124,20 @@
  99709. return(-EINVAL);
  99710. }
  99711. + /* bitbanging hardware uses bitbang_pullup, other hardware uses set_pullup
  99712. + * and takes care of timing itself */
  99713. + if (!master->write_byte && !master->touch_bit && master->set_pullup) {
  99714. + printk(KERN_ERR "w1_add_master_device: set_pullup requires "
  99715. + "write_byte or touch_bit, disabling\n");
  99716. + master->set_pullup = NULL;
  99717. + }
  99718. +
  99719. + if (master->set_pullup && master->bitbang_pullup) {
  99720. + printk(KERN_ERR "w1_add_master_device: set_pullup should not "
  99721. + "be set when bitbang_pullup is used, disabling\n");
  99722. + master->set_pullup = NULL;
  99723. + }
  99724. +
  99725. /* Lock until the device is added (or not) to w1_masters. */
  99726. mutex_lock(&w1_mlock);
  99727. /* Search for the first available id (starting at 1). */
  99728. diff -Nur linux-3.15.4/drivers/w1/w1_io.c linux-rpi/drivers/w1/w1_io.c
  99729. --- linux-3.15.4/drivers/w1/w1_io.c 2014-07-07 03:59:25.000000000 +0200
  99730. +++ linux-rpi/drivers/w1/w1_io.c 2014-07-07 10:45:47.000000000 +0200
  99731. @@ -134,10 +134,22 @@
  99732. static void w1_post_write(struct w1_master *dev)
  99733. {
  99734. if (dev->pullup_duration) {
  99735. - if (dev->enable_pullup && dev->bus_master->set_pullup)
  99736. - dev->bus_master->set_pullup(dev->bus_master->data, 0);
  99737. - else
  99738. + if (dev->enable_pullup) {
  99739. + if (dev->bus_master->set_pullup) {
  99740. + dev->bus_master->set_pullup(dev->
  99741. + bus_master->data,
  99742. + 0);
  99743. + } else if (dev->bus_master->bitbang_pullup) {
  99744. + dev->bus_master->
  99745. + bitbang_pullup(dev->bus_master->data, 1);
  99746. msleep(dev->pullup_duration);
  99747. + dev->bus_master->
  99748. + bitbang_pullup(dev->bus_master->data, 0);
  99749. + }
  99750. + } else {
  99751. + msleep(dev->pullup_duration);
  99752. + }
  99753. +
  99754. dev->pullup_duration = 0;
  99755. }
  99756. }
  99757. diff -Nur linux-3.15.4/drivers/watchdog/ath79_wdt.c linux-rpi/drivers/watchdog/ath79_wdt.c
  99758. --- linux-3.15.4/drivers/watchdog/ath79_wdt.c 2014-07-07 03:59:25.000000000 +0200
  99759. +++ linux-rpi/drivers/watchdog/ath79_wdt.c 2014-07-07 10:45:47.000000000 +0200
  99760. @@ -20,7 +20,6 @@
  99761. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  99762. #include <linux/bitops.h>
  99763. -#include <linux/delay.h>
  99764. #include <linux/errno.h>
  99765. #include <linux/fs.h>
  99766. #include <linux/io.h>
  99767. @@ -91,15 +90,6 @@
  99768. static inline void ath79_wdt_enable(void)
  99769. {
  99770. ath79_wdt_keepalive();
  99771. -
  99772. - /*
  99773. - * Updating the TIMER register requires a few microseconds
  99774. - * on the AR934x SoCs at least. Use a small delay to ensure
  99775. - * that the TIMER register is updated within the hardware
  99776. - * before enabling the watchdog.
  99777. - */
  99778. - udelay(2);
  99779. -
  99780. ath79_wdt_wr(WDOG_REG_CTRL, WDOG_CTRL_ACTION_FCR);
  99781. /* flush write */
  99782. ath79_wdt_rr(WDOG_REG_CTRL);
  99783. diff -Nur linux-3.15.4/drivers/watchdog/bcm2708_wdog.c linux-rpi/drivers/watchdog/bcm2708_wdog.c
  99784. --- linux-3.15.4/drivers/watchdog/bcm2708_wdog.c 1970-01-01 01:00:00.000000000 +0100
  99785. +++ linux-rpi/drivers/watchdog/bcm2708_wdog.c 2014-07-07 10:45:47.000000000 +0200
  99786. @@ -0,0 +1,382 @@
  99787. +/*
  99788. + * Broadcom BCM2708 watchdog driver.
  99789. + *
  99790. + * (c) Copyright 2010 Broadcom Europe Ltd
  99791. + *
  99792. + * This program is free software; you can redistribute it and/or
  99793. + * modify it under the terms of the GNU General Public License
  99794. + * as published by the Free Software Foundation; either version
  99795. + * 2 of the License, or (at your option) any later version.
  99796. + *
  99797. + * BCM2708 watchdog driver. Loosely based on wdt driver.
  99798. + */
  99799. +
  99800. +#include <linux/interrupt.h>
  99801. +#include <linux/module.h>
  99802. +#include <linux/moduleparam.h>
  99803. +#include <linux/types.h>
  99804. +#include <linux/miscdevice.h>
  99805. +#include <linux/watchdog.h>
  99806. +#include <linux/fs.h>
  99807. +#include <linux/ioport.h>
  99808. +#include <linux/notifier.h>
  99809. +#include <linux/reboot.h>
  99810. +#include <linux/init.h>
  99811. +#include <linux/io.h>
  99812. +#include <linux/uaccess.h>
  99813. +#include <mach/platform.h>
  99814. +
  99815. +#define SECS_TO_WDOG_TICKS(x) ((x) << 16)
  99816. +#define WDOG_TICKS_TO_SECS(x) ((x) >> 16)
  99817. +
  99818. +static unsigned long wdog_is_open;
  99819. +static uint32_t wdog_ticks; /* Ticks to load into wdog timer */
  99820. +static char expect_close;
  99821. +
  99822. +/*
  99823. + * Module parameters
  99824. + */
  99825. +
  99826. +#define WD_TIMO 10 /* Default heartbeat = 60 seconds */
  99827. +static int heartbeat = WD_TIMO; /* Heartbeat in seconds */
  99828. +
  99829. +module_param(heartbeat, int, 0);
  99830. +MODULE_PARM_DESC(heartbeat,
  99831. + "Watchdog heartbeat in seconds. (0 < heartbeat < 65536, default="
  99832. + __MODULE_STRING(WD_TIMO) ")");
  99833. +
  99834. +static int nowayout = WATCHDOG_NOWAYOUT;
  99835. +module_param(nowayout, int, 0);
  99836. +MODULE_PARM_DESC(nowayout,
  99837. + "Watchdog cannot be stopped once started (default="
  99838. + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  99839. +
  99840. +static DEFINE_SPINLOCK(wdog_lock);
  99841. +
  99842. +/**
  99843. + * Start the watchdog driver.
  99844. + */
  99845. +
  99846. +static int wdog_start(unsigned long timeout)
  99847. +{
  99848. + uint32_t cur;
  99849. + unsigned long flags;
  99850. + spin_lock_irqsave(&wdog_lock, flags);
  99851. +
  99852. + /* enable the watchdog */
  99853. + iowrite32(PM_PASSWORD | (timeout & PM_WDOG_TIME_SET),
  99854. + __io_address(PM_WDOG));
  99855. + cur = ioread32(__io_address(PM_RSTC));
  99856. + iowrite32(PM_PASSWORD | (cur & PM_RSTC_WRCFG_CLR) |
  99857. + PM_RSTC_WRCFG_FULL_RESET, __io_address(PM_RSTC));
  99858. +
  99859. + spin_unlock_irqrestore(&wdog_lock, flags);
  99860. + return 0;
  99861. +}
  99862. +
  99863. +/**
  99864. + * Stop the watchdog driver.
  99865. + */
  99866. +
  99867. +static int wdog_stop(void)
  99868. +{
  99869. + iowrite32(PM_PASSWORD | PM_RSTC_RESET, __io_address(PM_RSTC));
  99870. + printk(KERN_INFO "watchdog stopped\n");
  99871. + return 0;
  99872. +}
  99873. +
  99874. +/**
  99875. + * Reload counter one with the watchdog heartbeat. We don't bother
  99876. + * reloading the cascade counter.
  99877. + */
  99878. +
  99879. +static void wdog_ping(void)
  99880. +{
  99881. + wdog_start(wdog_ticks);
  99882. +}
  99883. +
  99884. +/**
  99885. + * @t: the new heartbeat value that needs to be set.
  99886. + *
  99887. + * Set a new heartbeat value for the watchdog device. If the heartbeat
  99888. + * value is incorrect we keep the old value and return -EINVAL. If
  99889. + * successful we return 0.
  99890. + */
  99891. +
  99892. +static int wdog_set_heartbeat(int t)
  99893. +{
  99894. + if (t < 1 || t > WDOG_TICKS_TO_SECS(PM_WDOG_TIME_SET))
  99895. + return -EINVAL;
  99896. +
  99897. + heartbeat = t;
  99898. + wdog_ticks = SECS_TO_WDOG_TICKS(t);
  99899. + return 0;
  99900. +}
  99901. +
  99902. +/**
  99903. + * @file: file handle to the watchdog
  99904. + * @buf: buffer to write (unused as data does not matter here
  99905. + * @count: count of bytes
  99906. + * @ppos: pointer to the position to write. No seeks allowed
  99907. + *
  99908. + * A write to a watchdog device is defined as a keepalive signal.
  99909. + *
  99910. + * if 'nowayout' is set then normally a close() is ignored. But
  99911. + * if you write 'V' first then the close() will stop the timer.
  99912. + */
  99913. +
  99914. +static ssize_t wdog_write(struct file *file, const char __user *buf,
  99915. + size_t count, loff_t *ppos)
  99916. +{
  99917. + if (count) {
  99918. + if (!nowayout) {
  99919. + size_t i;
  99920. +
  99921. + /* In case it was set long ago */
  99922. + expect_close = 0;
  99923. +
  99924. + for (i = 0; i != count; i++) {
  99925. + char c;
  99926. + if (get_user(c, buf + i))
  99927. + return -EFAULT;
  99928. + if (c == 'V')
  99929. + expect_close = 42;
  99930. + }
  99931. + }
  99932. + wdog_ping();
  99933. + }
  99934. + return count;
  99935. +}
  99936. +
  99937. +static int wdog_get_status(void)
  99938. +{
  99939. + unsigned long flags;
  99940. + int status = 0;
  99941. + spin_lock_irqsave(&wdog_lock, flags);
  99942. + /* FIXME: readback reset reason */
  99943. + spin_unlock_irqrestore(&wdog_lock, flags);
  99944. + return status;
  99945. +}
  99946. +
  99947. +static uint32_t wdog_get_remaining(void)
  99948. +{
  99949. + uint32_t ret = ioread32(__io_address(PM_WDOG));
  99950. + return ret & PM_WDOG_TIME_SET;
  99951. +}
  99952. +
  99953. +/**
  99954. + * @file: file handle to the device
  99955. + * @cmd: watchdog command
  99956. + * @arg: argument pointer
  99957. + *
  99958. + * The watchdog API defines a common set of functions for all watchdogs
  99959. + * according to their available features. We only actually usefully support
  99960. + * querying capabilities and current status.
  99961. + */
  99962. +
  99963. +static long wdog_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  99964. +{
  99965. + void __user *argp = (void __user *)arg;
  99966. + int __user *p = argp;
  99967. + int new_heartbeat;
  99968. + int status;
  99969. + int options;
  99970. + uint32_t remaining;
  99971. +
  99972. + struct watchdog_info ident = {
  99973. + .options = WDIOF_SETTIMEOUT|
  99974. + WDIOF_MAGICCLOSE|
  99975. + WDIOF_KEEPALIVEPING,
  99976. + .firmware_version = 1,
  99977. + .identity = "BCM2708",
  99978. + };
  99979. +
  99980. + switch (cmd) {
  99981. + case WDIOC_GETSUPPORT:
  99982. + return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
  99983. + case WDIOC_GETSTATUS:
  99984. + status = wdog_get_status();
  99985. + return put_user(status, p);
  99986. + case WDIOC_GETBOOTSTATUS:
  99987. + return put_user(0, p);
  99988. + case WDIOC_KEEPALIVE:
  99989. + wdog_ping();
  99990. + return 0;
  99991. + case WDIOC_SETTIMEOUT:
  99992. + if (get_user(new_heartbeat, p))
  99993. + return -EFAULT;
  99994. + if (wdog_set_heartbeat(new_heartbeat))
  99995. + return -EINVAL;
  99996. + wdog_ping();
  99997. + /* Fall */
  99998. + case WDIOC_GETTIMEOUT:
  99999. + return put_user(heartbeat, p);
  100000. + case WDIOC_GETTIMELEFT:
  100001. + remaining = WDOG_TICKS_TO_SECS(wdog_get_remaining());
  100002. + return put_user(remaining, p);
  100003. + case WDIOC_SETOPTIONS:
  100004. + if (get_user(options, p))
  100005. + return -EFAULT;
  100006. + if (options & WDIOS_DISABLECARD)
  100007. + wdog_stop();
  100008. + if (options & WDIOS_ENABLECARD)
  100009. + wdog_start(wdog_ticks);
  100010. + return 0;
  100011. + default:
  100012. + return -ENOTTY;
  100013. + }
  100014. +}
  100015. +
  100016. +/**
  100017. + * @inode: inode of device
  100018. + * @file: file handle to device
  100019. + *
  100020. + * The watchdog device has been opened. The watchdog device is single
  100021. + * open and on opening we load the counters.
  100022. + */
  100023. +
  100024. +static int wdog_open(struct inode *inode, struct file *file)
  100025. +{
  100026. + if (test_and_set_bit(0, &wdog_is_open))
  100027. + return -EBUSY;
  100028. + /*
  100029. + * Activate
  100030. + */
  100031. + wdog_start(wdog_ticks);
  100032. + return nonseekable_open(inode, file);
  100033. +}
  100034. +
  100035. +/**
  100036. + * @inode: inode to board
  100037. + * @file: file handle to board
  100038. + *
  100039. + * The watchdog has a configurable API. There is a religious dispute
  100040. + * between people who want their watchdog to be able to shut down and
  100041. + * those who want to be sure if the watchdog manager dies the machine
  100042. + * reboots. In the former case we disable the counters, in the latter
  100043. + * case you have to open it again very soon.
  100044. + */
  100045. +
  100046. +static int wdog_release(struct inode *inode, struct file *file)
  100047. +{
  100048. + if (expect_close == 42) {
  100049. + wdog_stop();
  100050. + } else {
  100051. + printk(KERN_CRIT
  100052. + "wdt: WDT device closed unexpectedly. WDT will not stop!\n");
  100053. + wdog_ping();
  100054. + }
  100055. + clear_bit(0, &wdog_is_open);
  100056. + expect_close = 0;
  100057. + return 0;
  100058. +}
  100059. +
  100060. +/**
  100061. + * @this: our notifier block
  100062. + * @code: the event being reported
  100063. + * @unused: unused
  100064. + *
  100065. + * Our notifier is called on system shutdowns. Turn the watchdog
  100066. + * off so that it does not fire during the next reboot.
  100067. + */
  100068. +
  100069. +static int wdog_notify_sys(struct notifier_block *this, unsigned long code,
  100070. + void *unused)
  100071. +{
  100072. + if (code == SYS_DOWN || code == SYS_HALT)
  100073. + wdog_stop();
  100074. + return NOTIFY_DONE;
  100075. +}
  100076. +
  100077. +/*
  100078. + * Kernel Interfaces
  100079. + */
  100080. +
  100081. +
  100082. +static const struct file_operations wdog_fops = {
  100083. + .owner = THIS_MODULE,
  100084. + .llseek = no_llseek,
  100085. + .write = wdog_write,
  100086. + .unlocked_ioctl = wdog_ioctl,
  100087. + .open = wdog_open,
  100088. + .release = wdog_release,
  100089. +};
  100090. +
  100091. +static struct miscdevice wdog_miscdev = {
  100092. + .minor = WATCHDOG_MINOR,
  100093. + .name = "watchdog",
  100094. + .fops = &wdog_fops,
  100095. +};
  100096. +
  100097. +/*
  100098. + * The WDT card needs to learn about soft shutdowns in order to
  100099. + * turn the timebomb registers off.
  100100. + */
  100101. +
  100102. +static struct notifier_block wdog_notifier = {
  100103. + .notifier_call = wdog_notify_sys,
  100104. +};
  100105. +
  100106. +/**
  100107. + * cleanup_module:
  100108. + *
  100109. + * Unload the watchdog. You cannot do this with any file handles open.
  100110. + * If your watchdog is set to continue ticking on close and you unload
  100111. + * it, well it keeps ticking. We won't get the interrupt but the board
  100112. + * will not touch PC memory so all is fine. You just have to load a new
  100113. + * module in 60 seconds or reboot.
  100114. + */
  100115. +
  100116. +static void __exit wdog_exit(void)
  100117. +{
  100118. + misc_deregister(&wdog_miscdev);
  100119. + unregister_reboot_notifier(&wdog_notifier);
  100120. +}
  100121. +
  100122. +static int __init wdog_init(void)
  100123. +{
  100124. + int ret;
  100125. +
  100126. + /* Check that the heartbeat value is within it's range;
  100127. + if not reset to the default */
  100128. + if (wdog_set_heartbeat(heartbeat)) {
  100129. + wdog_set_heartbeat(WD_TIMO);
  100130. + printk(KERN_INFO "bcm2708_wdog: heartbeat value must be "
  100131. + "0 < heartbeat < %d, using %d\n",
  100132. + WDOG_TICKS_TO_SECS(PM_WDOG_TIME_SET),
  100133. + WD_TIMO);
  100134. + }
  100135. +
  100136. + ret = register_reboot_notifier(&wdog_notifier);
  100137. + if (ret) {
  100138. + printk(KERN_ERR
  100139. + "wdt: cannot register reboot notifier (err=%d)\n", ret);
  100140. + goto out_reboot;
  100141. + }
  100142. +
  100143. + ret = misc_register(&wdog_miscdev);
  100144. + if (ret) {
  100145. + printk(KERN_ERR
  100146. + "wdt: cannot register miscdev on minor=%d (err=%d)\n",
  100147. + WATCHDOG_MINOR, ret);
  100148. + goto out_misc;
  100149. + }
  100150. +
  100151. + printk(KERN_INFO "bcm2708 watchdog, heartbeat=%d sec (nowayout=%d)\n",
  100152. + heartbeat, nowayout);
  100153. + return 0;
  100154. +
  100155. +out_misc:
  100156. + unregister_reboot_notifier(&wdog_notifier);
  100157. +out_reboot:
  100158. + return ret;
  100159. +}
  100160. +
  100161. +module_init(wdog_init);
  100162. +module_exit(wdog_exit);
  100163. +
  100164. +MODULE_AUTHOR("Luke Diamand");
  100165. +MODULE_DESCRIPTION("Driver for BCM2708 watchdog");
  100166. +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
  100167. +MODULE_ALIAS_MISCDEV(TEMP_MINOR);
  100168. +MODULE_LICENSE("GPL");
  100169. diff -Nur linux-3.15.4/drivers/watchdog/Kconfig linux-rpi/drivers/watchdog/Kconfig
  100170. --- linux-3.15.4/drivers/watchdog/Kconfig 2014-07-07 03:59:25.000000000 +0200
  100171. +++ linux-rpi/drivers/watchdog/Kconfig 2014-07-07 10:45:47.000000000 +0200
  100172. @@ -411,6 +411,12 @@
  100173. To compile this driver as a module, choose M here: the
  100174. module will be called retu_wdt.
  100175. +config BCM2708_WDT
  100176. + tristate "BCM2708 Watchdog"
  100177. + depends on ARCH_BCM2708
  100178. + help
  100179. + Enables BCM2708 watchdog support.
  100180. +
  100181. config MOXART_WDT
  100182. tristate "MOXART watchdog"
  100183. depends on ARCH_MOXART
  100184. diff -Nur linux-3.15.4/drivers/watchdog/kempld_wdt.c linux-rpi/drivers/watchdog/kempld_wdt.c
  100185. --- linux-3.15.4/drivers/watchdog/kempld_wdt.c 2014-07-07 03:59:25.000000000 +0200
  100186. +++ linux-rpi/drivers/watchdog/kempld_wdt.c 2014-07-07 10:45:47.000000000 +0200
  100187. @@ -162,7 +162,7 @@
  100188. kempld_get_mutex(pld);
  100189. stage_cfg = kempld_read8(pld, KEMPLD_WDT_STAGE_CFG(stage->id));
  100190. stage_cfg &= ~STAGE_CFG_PRESCALER_MASK;
  100191. - stage_cfg |= STAGE_CFG_SET_PRESCALER(PRESCALER_21);
  100192. + stage_cfg |= STAGE_CFG_SET_PRESCALER(prescaler);
  100193. kempld_write8(pld, KEMPLD_WDT_STAGE_CFG(stage->id), stage_cfg);
  100194. kempld_write32(pld, KEMPLD_WDT_STAGE_TIMEOUT(stage->id),
  100195. stage_timeout);
  100196. diff -Nur linux-3.15.4/drivers/watchdog/Makefile linux-rpi/drivers/watchdog/Makefile
  100197. --- linux-3.15.4/drivers/watchdog/Makefile 2014-07-07 03:59:25.000000000 +0200
  100198. +++ linux-rpi/drivers/watchdog/Makefile 2014-07-07 10:45:47.000000000 +0200
  100199. @@ -54,6 +54,7 @@
  100200. obj-$(CONFIG_IMX2_WDT) += imx2_wdt.o
  100201. obj-$(CONFIG_UX500_WATCHDOG) += ux500_wdt.o
  100202. obj-$(CONFIG_RETU_WATCHDOG) += retu_wdt.o
  100203. +obj-$(CONFIG_BCM2708_WDT) += bcm2708_wdog.o
  100204. obj-$(CONFIG_BCM2835_WDT) += bcm2835_wdt.o
  100205. obj-$(CONFIG_MOXART_WDT) += moxart_wdt.o
  100206. obj-$(CONFIG_SIRFSOC_WATCHDOG) += sirfsoc_wdt.o
  100207. diff -Nur linux-3.15.4/drivers/watchdog/sp805_wdt.c linux-rpi/drivers/watchdog/sp805_wdt.c
  100208. --- linux-3.15.4/drivers/watchdog/sp805_wdt.c 2014-07-07 03:59:25.000000000 +0200
  100209. +++ linux-rpi/drivers/watchdog/sp805_wdt.c 2014-07-07 10:45:47.000000000 +0200
  100210. @@ -59,6 +59,7 @@
  100211. * @adev: amba device structure of wdt
  100212. * @status: current status of wdt
  100213. * @load_val: load value to be set for current timeout
  100214. + * @timeout: current programmed timeout
  100215. */
  100216. struct sp805_wdt {
  100217. struct watchdog_device wdd;
  100218. @@ -67,6 +68,7 @@
  100219. struct clk *clk;
  100220. struct amba_device *adev;
  100221. unsigned int load_val;
  100222. + unsigned int timeout;
  100223. };
  100224. static bool nowayout = WATCHDOG_NOWAYOUT;
  100225. @@ -96,7 +98,7 @@
  100226. spin_lock(&wdt->lock);
  100227. wdt->load_val = load;
  100228. /* roundup timeout to closest positive integer value */
  100229. - wdd->timeout = div_u64((load + 1) * 2 + (rate / 2), rate);
  100230. + wdt->timeout = div_u64((load + 1) * 2 + (rate / 2), rate);
  100231. spin_unlock(&wdt->lock);
  100232. return 0;
  100233. diff -Nur linux-3.15.4/fs/nfs/inode.c linux-rpi/fs/nfs/inode.c
  100234. --- linux-3.15.4/fs/nfs/inode.c 2014-07-07 03:59:25.000000000 +0200
  100235. +++ linux-rpi/fs/nfs/inode.c 2014-07-07 10:45:51.000000000 +0200
  100236. @@ -1575,20 +1575,18 @@
  100237. inode->i_version = fattr->change_attr;
  100238. }
  100239. } else if (server->caps & NFS_CAP_CHANGE_ATTR)
  100240. - nfsi->cache_validity |= save_cache_validity;
  100241. + invalid |= save_cache_validity;
  100242. if (fattr->valid & NFS_ATTR_FATTR_MTIME) {
  100243. memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime));
  100244. } else if (server->caps & NFS_CAP_MTIME)
  100245. - nfsi->cache_validity |= save_cache_validity &
  100246. - (NFS_INO_INVALID_ATTR
  100247. + invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
  100248. | NFS_INO_REVAL_FORCED);
  100249. if (fattr->valid & NFS_ATTR_FATTR_CTIME) {
  100250. memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime));
  100251. } else if (server->caps & NFS_CAP_CTIME)
  100252. - nfsi->cache_validity |= save_cache_validity &
  100253. - (NFS_INO_INVALID_ATTR
  100254. + invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
  100255. | NFS_INO_REVAL_FORCED);
  100256. /* Check if our cached file size is stale */
  100257. @@ -1610,8 +1608,7 @@
  100258. (long long)new_isize);
  100259. }
  100260. } else
  100261. - nfsi->cache_validity |= save_cache_validity &
  100262. - (NFS_INO_INVALID_ATTR
  100263. + invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
  100264. | NFS_INO_REVAL_PAGECACHE
  100265. | NFS_INO_REVAL_FORCED);
  100266. @@ -1619,8 +1616,7 @@
  100267. if (fattr->valid & NFS_ATTR_FATTR_ATIME)
  100268. memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
  100269. else if (server->caps & NFS_CAP_ATIME)
  100270. - nfsi->cache_validity |= save_cache_validity &
  100271. - (NFS_INO_INVALID_ATIME
  100272. + invalid |= save_cache_validity & (NFS_INO_INVALID_ATIME
  100273. | NFS_INO_REVAL_FORCED);
  100274. if (fattr->valid & NFS_ATTR_FATTR_MODE) {
  100275. @@ -1631,8 +1627,7 @@
  100276. invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
  100277. }
  100278. } else if (server->caps & NFS_CAP_MODE)
  100279. - nfsi->cache_validity |= save_cache_validity &
  100280. - (NFS_INO_INVALID_ATTR
  100281. + invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
  100282. | NFS_INO_INVALID_ACCESS
  100283. | NFS_INO_INVALID_ACL
  100284. | NFS_INO_REVAL_FORCED);
  100285. @@ -1643,8 +1638,7 @@
  100286. inode->i_uid = fattr->uid;
  100287. }
  100288. } else if (server->caps & NFS_CAP_OWNER)
  100289. - nfsi->cache_validity |= save_cache_validity &
  100290. - (NFS_INO_INVALID_ATTR
  100291. + invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
  100292. | NFS_INO_INVALID_ACCESS
  100293. | NFS_INO_INVALID_ACL
  100294. | NFS_INO_REVAL_FORCED);
  100295. @@ -1655,8 +1649,7 @@
  100296. inode->i_gid = fattr->gid;
  100297. }
  100298. } else if (server->caps & NFS_CAP_OWNER_GROUP)
  100299. - nfsi->cache_validity |= save_cache_validity &
  100300. - (NFS_INO_INVALID_ATTR
  100301. + invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
  100302. | NFS_INO_INVALID_ACCESS
  100303. | NFS_INO_INVALID_ACL
  100304. | NFS_INO_REVAL_FORCED);
  100305. @@ -1669,8 +1662,7 @@
  100306. set_nlink(inode, fattr->nlink);
  100307. }
  100308. } else if (server->caps & NFS_CAP_NLINK)
  100309. - nfsi->cache_validity |= save_cache_validity &
  100310. - (NFS_INO_INVALID_ATTR
  100311. + invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
  100312. | NFS_INO_REVAL_FORCED);
  100313. if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) {
  100314. diff -Nur linux-3.15.4/fs/nfs/nfs4filelayout.c linux-rpi/fs/nfs/nfs4filelayout.c
  100315. --- linux-3.15.4/fs/nfs/nfs4filelayout.c 2014-07-07 03:59:25.000000000 +0200
  100316. +++ linux-rpi/fs/nfs/nfs4filelayout.c 2014-07-07 10:45:51.000000000 +0200
  100317. @@ -1330,7 +1330,7 @@
  100318. struct nfs4_filelayout *flo;
  100319. flo = kzalloc(sizeof(*flo), gfp_flags);
  100320. - return flo != NULL ? &flo->generic_hdr : NULL;
  100321. + return &flo->generic_hdr;
  100322. }
  100323. static void
  100324. diff -Nur linux-3.15.4/fs/nfs/nfs4state.c linux-rpi/fs/nfs/nfs4state.c
  100325. --- linux-3.15.4/fs/nfs/nfs4state.c 2014-07-07 03:59:25.000000000 +0200
  100326. +++ linux-rpi/fs/nfs/nfs4state.c 2014-07-07 10:45:51.000000000 +0200
  100327. @@ -1456,7 +1456,7 @@
  100328. * server that doesn't support a grace period.
  100329. */
  100330. spin_lock(&sp->so_lock);
  100331. - raw_write_seqcount_begin(&sp->so_reclaim_seqcount);
  100332. + write_seqcount_begin(&sp->so_reclaim_seqcount);
  100333. restart:
  100334. list_for_each_entry(state, &sp->so_states, open_states) {
  100335. if (!test_and_clear_bit(ops->state_flag_bit, &state->flags))
  100336. @@ -1519,13 +1519,13 @@
  100337. spin_lock(&sp->so_lock);
  100338. goto restart;
  100339. }
  100340. - raw_write_seqcount_end(&sp->so_reclaim_seqcount);
  100341. + write_seqcount_end(&sp->so_reclaim_seqcount);
  100342. spin_unlock(&sp->so_lock);
  100343. return 0;
  100344. out_err:
  100345. nfs4_put_open_state(state);
  100346. spin_lock(&sp->so_lock);
  100347. - raw_write_seqcount_end(&sp->so_reclaim_seqcount);
  100348. + write_seqcount_end(&sp->so_reclaim_seqcount);
  100349. spin_unlock(&sp->so_lock);
  100350. return status;
  100351. }
  100352. diff -Nur linux-3.15.4/fs/nfs/super.c linux-rpi/fs/nfs/super.c
  100353. --- linux-3.15.4/fs/nfs/super.c 2014-07-07 03:59:25.000000000 +0200
  100354. +++ linux-rpi/fs/nfs/super.c 2014-07-07 10:45:51.000000000 +0200
  100355. @@ -2248,7 +2248,6 @@
  100356. data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
  100357. data->version = nfsvers;
  100358. data->minorversion = nfss->nfs_client->cl_minorversion;
  100359. - data->net = current->nsproxy->net_ns;
  100360. memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
  100361. data->nfs_server.addrlen);
  100362. diff -Nur linux-3.15.4/fs/nfs/write.c linux-rpi/fs/nfs/write.c
  100363. --- linux-3.15.4/fs/nfs/write.c 2014-07-07 03:59:25.000000000 +0200
  100364. +++ linux-rpi/fs/nfs/write.c 2014-07-07 10:45:51.000000000 +0200
  100365. @@ -913,14 +913,12 @@
  100366. if (nfs_have_delegated_attributes(inode))
  100367. goto out;
  100368. - if (nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE)
  100369. + if (nfsi->cache_validity & (NFS_INO_INVALID_DATA|NFS_INO_REVAL_PAGECACHE))
  100370. return false;
  100371. smp_rmb();
  100372. if (test_bit(NFS_INO_INVALIDATING, &nfsi->flags))
  100373. return false;
  100374. out:
  100375. - if (nfsi->cache_validity & NFS_INO_INVALID_DATA)
  100376. - return false;
  100377. return PageUptodate(page) != 0;
  100378. }
  100379. diff -Nur linux-3.15.4/fs/nfsd/nfs4state.c linux-rpi/fs/nfsd/nfs4state.c
  100380. --- linux-3.15.4/fs/nfsd/nfs4state.c 2014-07-07 03:59:25.000000000 +0200
  100381. +++ linux-rpi/fs/nfsd/nfs4state.c 2014-07-07 10:45:51.000000000 +0200
  100382. @@ -3726,7 +3726,7 @@
  100383. * correspondance, and we have to delete the lockowner when we
  100384. * delete the lock stateid:
  100385. */
  100386. - release_lockowner(lo);
  100387. + unhash_lockowner(lo);
  100388. return nfs_ok;
  100389. }
  100390. diff -Nur linux-3.15.4/fs/nfsd/nfs4xdr.c linux-rpi/fs/nfsd/nfs4xdr.c
  100391. --- linux-3.15.4/fs/nfsd/nfs4xdr.c 2014-07-07 03:59:25.000000000 +0200
  100392. +++ linux-rpi/fs/nfsd/nfs4xdr.c 2014-07-07 10:45:51.000000000 +0200
  100393. @@ -2095,8 +2095,8 @@
  100394. err = vfs_getattr(&path, &stat);
  100395. if (err)
  100396. goto out_nfserr;
  100397. - if ((bmval0 & (FATTR4_WORD0_FILES_AVAIL | FATTR4_WORD0_FILES_FREE |
  100398. - FATTR4_WORD0_FILES_TOTAL | FATTR4_WORD0_MAXNAME)) ||
  100399. + if ((bmval0 & (FATTR4_WORD0_FILES_FREE | FATTR4_WORD0_FILES_TOTAL |
  100400. + FATTR4_WORD0_MAXNAME)) ||
  100401. (bmval1 & (FATTR4_WORD1_SPACE_AVAIL | FATTR4_WORD1_SPACE_FREE |
  100402. FATTR4_WORD1_SPACE_TOTAL))) {
  100403. err = vfs_statfs(&path, &statfs);
  100404. diff -Nur linux-3.15.4/fs/reiserfs/inode.c linux-rpi/fs/reiserfs/inode.c
  100405. --- linux-3.15.4/fs/reiserfs/inode.c 2014-07-07 03:59:25.000000000 +0200
  100406. +++ linux-rpi/fs/reiserfs/inode.c 2014-07-07 10:45:51.000000000 +0200
  100407. @@ -3220,14 +3220,8 @@
  100408. attr->ia_size != i_size_read(inode)) {
  100409. error = inode_newsize_ok(inode, attr->ia_size);
  100410. if (!error) {
  100411. - /*
  100412. - * Could race against reiserfs_file_release
  100413. - * if called from NFS, so take tailpack mutex.
  100414. - */
  100415. - mutex_lock(&REISERFS_I(inode)->tailpack);
  100416. truncate_setsize(inode, attr->ia_size);
  100417. - reiserfs_truncate_file(inode, 1);
  100418. - mutex_unlock(&REISERFS_I(inode)->tailpack);
  100419. + reiserfs_vfs_truncate_file(inode);
  100420. }
  100421. }
  100422. diff -Nur linux-3.15.4/fs/ubifs/file.c linux-rpi/fs/ubifs/file.c
  100423. --- linux-3.15.4/fs/ubifs/file.c 2014-07-07 03:59:25.000000000 +0200
  100424. +++ linux-rpi/fs/ubifs/file.c 2014-07-07 10:45:52.000000000 +0200
  100425. @@ -1525,7 +1525,8 @@
  100426. }
  100427. wait_for_stable_page(page);
  100428. - return VM_FAULT_LOCKED;
  100429. + unlock_page(page);
  100430. + return 0;
  100431. out_unlock:
  100432. unlock_page(page);
  100433. diff -Nur linux-3.15.4/fs/ubifs/shrinker.c linux-rpi/fs/ubifs/shrinker.c
  100434. --- linux-3.15.4/fs/ubifs/shrinker.c 2014-07-07 03:59:25.000000000 +0200
  100435. +++ linux-rpi/fs/ubifs/shrinker.c 2014-07-07 10:45:52.000000000 +0200
  100436. @@ -128,6 +128,7 @@
  100437. freed = ubifs_destroy_tnc_subtree(znode);
  100438. atomic_long_sub(freed, &ubifs_clean_zn_cnt);
  100439. atomic_long_sub(freed, &c->clean_zn_cnt);
  100440. + ubifs_assert(atomic_long_read(&c->clean_zn_cnt) >= 0);
  100441. total_freed += freed;
  100442. znode = zprev;
  100443. }
  100444. diff -Nur linux-3.15.4/fs/xfs/xfs_mount.c linux-rpi/fs/xfs/xfs_mount.c
  100445. --- linux-3.15.4/fs/xfs/xfs_mount.c 2014-07-07 03:59:25.000000000 +0200
  100446. +++ linux-rpi/fs/xfs/xfs_mount.c 2014-07-07 10:45:52.000000000 +0200
  100447. @@ -323,19 +323,8 @@
  100448. /*
  100449. * Initialize the mount structure from the superblock.
  100450. */
  100451. - xfs_sb_from_disk(sbp, XFS_BUF_TO_SBP(bp));
  100452. - xfs_sb_quota_from_disk(sbp);
  100453. -
  100454. - /*
  100455. - * If we haven't validated the superblock, do so now before we try
  100456. - * to check the sector size and reread the superblock appropriately.
  100457. - */
  100458. - if (sbp->sb_magicnum != XFS_SB_MAGIC) {
  100459. - if (loud)
  100460. - xfs_warn(mp, "Invalid superblock magic number");
  100461. - error = EINVAL;
  100462. - goto release_buf;
  100463. - }
  100464. + xfs_sb_from_disk(&mp->m_sb, XFS_BUF_TO_SBP(bp));
  100465. + xfs_sb_quota_from_disk(&mp->m_sb);
  100466. /*
  100467. * We must be able to do sector-sized and sector-aligned IO.
  100468. @@ -348,11 +337,11 @@
  100469. goto release_buf;
  100470. }
  100471. + /*
  100472. + * Re-read the superblock so the buffer is correctly sized,
  100473. + * and properly verified.
  100474. + */
  100475. if (buf_ops == NULL) {
  100476. - /*
  100477. - * Re-read the superblock so the buffer is correctly sized,
  100478. - * and properly verified.
  100479. - */
  100480. xfs_buf_relse(bp);
  100481. sector_size = sbp->sb_sectsize;
  100482. buf_ops = loud ? &xfs_sb_buf_ops : &xfs_sb_quiet_buf_ops;
  100483. diff -Nur linux-3.15.4/include/linux/broadcom/vc_cma.h linux-rpi/include/linux/broadcom/vc_cma.h
  100484. --- linux-3.15.4/include/linux/broadcom/vc_cma.h 1970-01-01 01:00:00.000000000 +0100
  100485. +++ linux-rpi/include/linux/broadcom/vc_cma.h 2014-07-07 10:45:52.000000000 +0200
  100486. @@ -0,0 +1,29 @@
  100487. +/*****************************************************************************
  100488. +* Copyright 2012 Broadcom Corporation. All rights reserved.
  100489. +*
  100490. +* Unless you and Broadcom execute a separate written software license
  100491. +* agreement governing use of this software, this software is licensed to you
  100492. +* under the terms of the GNU General Public License version 2, available at
  100493. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  100494. +*
  100495. +* Notwithstanding the above, under no circumstances may you combine this
  100496. +* software in any way with any other Broadcom software provided under a
  100497. +* license other than the GPL, without Broadcom's express prior written
  100498. +* consent.
  100499. +*****************************************************************************/
  100500. +
  100501. +#if !defined( VC_CMA_H )
  100502. +#define VC_CMA_H
  100503. +
  100504. +#include <linux/ioctl.h>
  100505. +
  100506. +#define VC_CMA_IOC_MAGIC 0xc5
  100507. +
  100508. +#define VC_CMA_IOC_RESERVE _IO(VC_CMA_IOC_MAGIC, 0)
  100509. +
  100510. +#ifdef __KERNEL__
  100511. +extern void __init vc_cma_early_init(void);
  100512. +extern void __init vc_cma_reserve(void);
  100513. +#endif
  100514. +
  100515. +#endif /* VC_CMA_H */
  100516. diff -Nur linux-3.15.4/include/linux/mmc/host.h linux-rpi/include/linux/mmc/host.h
  100517. --- linux-3.15.4/include/linux/mmc/host.h 2014-07-07 03:59:25.000000000 +0200
  100518. +++ linux-rpi/include/linux/mmc/host.h 2014-07-07 10:45:53.000000000 +0200
  100519. @@ -278,6 +278,7 @@
  100520. #define MMC_CAP2_PACKED_CMD (MMC_CAP2_PACKED_RD | \
  100521. MMC_CAP2_PACKED_WR)
  100522. #define MMC_CAP2_NO_PRESCAN_POWERUP (1 << 14) /* Don't power up before scan */
  100523. +#define MMC_CAP2_FORCE_MULTIBLOCK (1 << 31) /* Always use multiblock transfers */
  100524. mmc_pm_flag_t pm_caps; /* supported pm features */
  100525. diff -Nur linux-3.15.4/include/linux/mmc/sdhci.h linux-rpi/include/linux/mmc/sdhci.h
  100526. --- linux-3.15.4/include/linux/mmc/sdhci.h 2014-07-07 03:59:25.000000000 +0200
  100527. +++ linux-rpi/include/linux/mmc/sdhci.h 2014-07-07 10:45:53.000000000 +0200
  100528. @@ -104,6 +104,7 @@
  100529. #define SDHCI_QUIRK2_BROKEN_DDR50 (1<<7)
  100530. int irq; /* Device IRQ */
  100531. + int second_irq; /* Additional IRQ to disable/enable in low-latency mode */
  100532. void __iomem *ioaddr; /* Mapped address */
  100533. const struct sdhci_ops *ops; /* Low level hw interface */
  100534. @@ -135,6 +136,7 @@
  100535. #define SDHCI_SDIO_IRQ_ENABLED (1<<9) /* SDIO irq enabled */
  100536. #define SDHCI_SDR104_NEEDS_TUNING (1<<10) /* SDR104/HS200 needs tuning */
  100537. #define SDHCI_USING_RETUNING_TIMER (1<<11) /* Host is using a retuning timer for the card */
  100538. +#define SDHCI_USE_PLATDMA (1<<12) /* Host uses 3rd party DMA */
  100539. unsigned int version; /* SDHCI spec. version */
  100540. @@ -150,6 +152,7 @@
  100541. struct mmc_request *mrq; /* Current request */
  100542. struct mmc_command *cmd; /* Current command */
  100543. + int last_cmdop; /* Opcode of last cmd sent */
  100544. struct mmc_data *data; /* Current data request */
  100545. unsigned int data_early:1; /* Data finished before cmd */
  100546. diff -Nur linux-3.15.4/include/linux/ptrace.h linux-rpi/include/linux/ptrace.h
  100547. --- linux-3.15.4/include/linux/ptrace.h 2014-07-07 03:59:25.000000000 +0200
  100548. +++ linux-rpi/include/linux/ptrace.h 2014-07-07 10:45:53.000000000 +0200
  100549. @@ -334,9 +334,6 @@
  100550. * calling arch_ptrace_stop() when it would be superfluous. For example,
  100551. * if the thread has not been back to user mode since the last stop, the
  100552. * thread state might indicate that nothing needs to be done.
  100553. - *
  100554. - * This is guaranteed to be invoked once before a task stops for ptrace and
  100555. - * may include arch-specific operations necessary prior to a ptrace stop.
  100556. */
  100557. #define arch_ptrace_stop_needed(code, info) (0)
  100558. #endif
  100559. diff -Nur linux-3.15.4/include/linux/vmstat.h linux-rpi/include/linux/vmstat.h
  100560. --- linux-3.15.4/include/linux/vmstat.h 2014-07-07 03:59:25.000000000 +0200
  100561. +++ linux-rpi/include/linux/vmstat.h 2014-07-07 10:45:55.000000000 +0200
  100562. @@ -235,7 +235,11 @@
  100563. static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
  100564. {
  100565. atomic_long_dec(&zone->vm_stat[item]);
  100566. + if (item == NR_FILE_DIRTY && unlikely(atomic_long_read(&zone->vm_stat[item]) < 0))
  100567. + atomic_long_set(&zone->vm_stat[item], 0);
  100568. atomic_long_dec(&vm_stat[item]);
  100569. + if (item == NR_FILE_DIRTY && unlikely(atomic_long_read(&vm_stat[item]) < 0))
  100570. + atomic_long_set(&vm_stat[item], 0);
  100571. }
  100572. static inline void __inc_zone_page_state(struct page *page,
  100573. diff -Nur linux-3.15.4/include/trace/syscall.h linux-rpi/include/trace/syscall.h
  100574. --- linux-3.15.4/include/trace/syscall.h 2014-07-07 03:59:25.000000000 +0200
  100575. +++ linux-rpi/include/trace/syscall.h 2014-07-07 10:45:56.000000000 +0200
  100576. @@ -4,7 +4,6 @@
  100577. #include <linux/tracepoint.h>
  100578. #include <linux/unistd.h>
  100579. #include <linux/ftrace_event.h>
  100580. -#include <linux/thread_info.h>
  100581. #include <asm/ptrace.h>
  100582. @@ -33,18 +32,4 @@
  100583. struct ftrace_event_call *exit_event;
  100584. };
  100585. -#if defined(CONFIG_TRACEPOINTS) && defined(CONFIG_HAVE_SYSCALL_TRACEPOINTS)
  100586. -static inline void syscall_tracepoint_update(struct task_struct *p)
  100587. -{
  100588. - if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
  100589. - set_tsk_thread_flag(p, TIF_SYSCALL_TRACEPOINT);
  100590. - else
  100591. - clear_tsk_thread_flag(p, TIF_SYSCALL_TRACEPOINT);
  100592. -}
  100593. -#else
  100594. -static inline void syscall_tracepoint_update(struct task_struct *p)
  100595. -{
  100596. -}
  100597. -#endif
  100598. -
  100599. #endif /* _TRACE_SYSCALL_H */
  100600. diff -Nur linux-3.15.4/include/uapi/linux/fb.h linux-rpi/include/uapi/linux/fb.h
  100601. --- linux-3.15.4/include/uapi/linux/fb.h 2014-07-07 03:59:25.000000000 +0200
  100602. +++ linux-rpi/include/uapi/linux/fb.h 2014-04-13 17:33:21.000000000 +0200
  100603. @@ -34,6 +34,11 @@
  100604. #define FBIOPUT_MODEINFO 0x4617
  100605. #define FBIOGET_DISPINFO 0x4618
  100606. #define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32)
  100607. +/*
  100608. + * HACK: use 'z' in order not to clash with any other ioctl numbers which might
  100609. + * be concurrently added to the mainline kernel
  100610. + */
  100611. +#define FBIOCOPYAREA _IOW('z', 0x21, struct fb_copyarea)
  100612. #define FB_TYPE_PACKED_PIXELS 0 /* Packed Pixels */
  100613. #define FB_TYPE_PLANES 1 /* Non interleaved planes */
  100614. diff -Nur linux-3.15.4/kernel/cgroup.c linux-rpi/kernel/cgroup.c
  100615. --- linux-3.15.4/kernel/cgroup.c 2014-07-07 03:59:25.000000000 +0200
  100616. +++ linux-rpi/kernel/cgroup.c 2014-07-07 10:45:56.000000000 +0200
  100617. @@ -4620,6 +4620,29 @@
  100618. }
  100619. __setup("cgroup_disable=", cgroup_disable);
  100620. +static int __init cgroup_enable(char *str)
  100621. +{
  100622. + struct cgroup_subsys *ss;
  100623. + char *token;
  100624. + int i;
  100625. +
  100626. + while ((token = strsep(&str, ",")) != NULL) {
  100627. + if (!*token)
  100628. + continue;
  100629. +
  100630. + for_each_subsys(ss, i) {
  100631. + if (!strcmp(token, ss->name)) {
  100632. + ss->disabled = 0;
  100633. + printk(KERN_INFO "Enabling %s control group"
  100634. + " subsystem\n", ss->name);
  100635. + break;
  100636. + }
  100637. + }
  100638. + }
  100639. + return 1;
  100640. +}
  100641. +__setup("cgroup_enable=", cgroup_enable);
  100642. +
  100643. /**
  100644. * css_tryget_from_dir - get corresponding css from the dentry of a cgroup dir
  100645. * @dentry: directory dentry of interest
  100646. diff -Nur linux-3.15.4/kernel/fork.c linux-rpi/kernel/fork.c
  100647. --- linux-3.15.4/kernel/fork.c 2014-07-07 03:59:25.000000000 +0200
  100648. +++ linux-rpi/kernel/fork.c 2014-07-07 10:45:56.000000000 +0200
  100649. @@ -1487,9 +1487,7 @@
  100650. total_forks++;
  100651. spin_unlock(&current->sighand->siglock);
  100652. - syscall_tracepoint_update(p);
  100653. write_unlock_irq(&tasklist_lock);
  100654. -
  100655. proc_fork_connector(p);
  100656. cgroup_post_fork(p);
  100657. if (clone_flags & CLONE_THREAD)
  100658. diff -Nur linux-3.15.4/kernel/trace/trace.c linux-rpi/kernel/trace/trace.c
  100659. --- linux-3.15.4/kernel/trace/trace.c 2014-07-07 03:59:25.000000000 +0200
  100660. +++ linux-rpi/kernel/trace/trace.c 2014-07-07 10:45:57.000000000 +0200
  100661. @@ -1461,12 +1461,12 @@
  100662. void trace_stop_cmdline_recording(void);
  100663. -static int trace_save_cmdline(struct task_struct *tsk)
  100664. +static void trace_save_cmdline(struct task_struct *tsk)
  100665. {
  100666. unsigned pid, idx;
  100667. if (!tsk->pid || unlikely(tsk->pid > PID_MAX_DEFAULT))
  100668. - return 0;
  100669. + return;
  100670. /*
  100671. * It's not the end of the world if we don't get
  100672. @@ -1475,7 +1475,7 @@
  100673. * so if we miss here, then better luck next time.
  100674. */
  100675. if (!arch_spin_trylock(&trace_cmdline_lock))
  100676. - return 0;
  100677. + return;
  100678. idx = map_pid_to_cmdline[tsk->pid];
  100679. if (idx == NO_CMDLINE_MAP) {
  100680. @@ -1500,8 +1500,6 @@
  100681. memcpy(&saved_cmdlines[idx], tsk->comm, TASK_COMM_LEN);
  100682. arch_spin_unlock(&trace_cmdline_lock);
  100683. -
  100684. - return 1;
  100685. }
  100686. void trace_find_cmdline(int pid, char comm[])
  100687. @@ -1543,8 +1541,9 @@
  100688. if (!__this_cpu_read(trace_cmdline_save))
  100689. return;
  100690. - if (trace_save_cmdline(tsk))
  100691. - __this_cpu_write(trace_cmdline_save, false);
  100692. + __this_cpu_write(trace_cmdline_save, false);
  100693. +
  100694. + trace_save_cmdline(tsk);
  100695. }
  100696. void
  100697. diff -Nur linux-3.15.4/kernel/watchdog.c linux-rpi/kernel/watchdog.c
  100698. --- linux-3.15.4/kernel/watchdog.c 2014-07-07 03:59:25.000000000 +0200
  100699. +++ linux-rpi/kernel/watchdog.c 2014-07-07 10:45:57.000000000 +0200
  100700. @@ -527,8 +527,10 @@
  100701. int cpu;
  100702. get_online_cpus();
  100703. + preempt_disable();
  100704. for_each_online_cpu(cpu)
  100705. update_timers(cpu);
  100706. + preempt_enable();
  100707. put_online_cpus();
  100708. }
  100709. diff -Nur linux-3.15.4/lib/lz4/lz4_decompress.c linux-rpi/lib/lz4/lz4_decompress.c
  100710. --- linux-3.15.4/lib/lz4/lz4_decompress.c 2014-07-07 03:59:25.000000000 +0200
  100711. +++ linux-rpi/lib/lz4/lz4_decompress.c 2014-07-07 10:45:57.000000000 +0200
  100712. @@ -192,8 +192,6 @@
  100713. int s = 255;
  100714. while ((ip < iend) && (s == 255)) {
  100715. s = *ip++;
  100716. - if (unlikely(length > (size_t)(length + s)))
  100717. - goto _output_error;
  100718. length += s;
  100719. }
  100720. }
  100721. @@ -234,8 +232,6 @@
  100722. if (length == ML_MASK) {
  100723. while (ip < iend) {
  100724. int s = *ip++;
  100725. - if (unlikely(length > (size_t)(length + s)))
  100726. - goto _output_error;
  100727. length += s;
  100728. if (s == 255)
  100729. continue;
  100730. @@ -288,7 +284,7 @@
  100731. /* write overflow error detected */
  100732. _output_error:
  100733. - return -1;
  100734. + return (int) (-(((char *) ip) - source));
  100735. }
  100736. int lz4_decompress(const unsigned char *src, size_t *src_len,
  100737. diff -Nur linux-3.15.4/mm/memcontrol.c linux-rpi/mm/memcontrol.c
  100738. --- linux-3.15.4/mm/memcontrol.c 2014-07-07 03:59:25.000000000 +0200
  100739. +++ linux-rpi/mm/memcontrol.c 2014-07-07 10:45:57.000000000 +0200
  100740. @@ -7158,6 +7158,7 @@
  100741. .bind = mem_cgroup_bind,
  100742. .base_cftypes = mem_cgroup_files,
  100743. .early_init = 0,
  100744. + .disabled = 1,
  100745. };
  100746. #ifdef CONFIG_MEMCG_SWAP
  100747. diff -Nur linux-3.15.4/net/sunrpc/svc_xprt.c linux-rpi/net/sunrpc/svc_xprt.c
  100748. --- linux-3.15.4/net/sunrpc/svc_xprt.c 2014-07-07 03:59:25.000000000 +0200
  100749. +++ linux-rpi/net/sunrpc/svc_xprt.c 2014-07-07 10:46:01.000000000 +0200
  100750. @@ -730,8 +730,6 @@
  100751. newxpt = xprt->xpt_ops->xpo_accept(xprt);
  100752. if (newxpt)
  100753. svc_add_new_temp_xprt(serv, newxpt);
  100754. - else
  100755. - module_put(xprt->xpt_class->xcl_owner);
  100756. } else if (xprt->xpt_ops->xpo_has_wspace(xprt)) {
  100757. /* XPT_DATA|XPT_DEFERRED case: */
  100758. dprintk("svc: server %p, pool %u, transport %p, inuse=%d\n",
  100759. diff -Nur linux-3.15.4/scripts/recordmcount.h linux-rpi/scripts/recordmcount.h
  100760. --- linux-3.15.4/scripts/recordmcount.h 2014-07-07 03:59:25.000000000 +0200
  100761. +++ linux-rpi/scripts/recordmcount.h 2014-04-13 17:33:26.000000000 +0200
  100762. @@ -163,11 +163,11 @@
  100763. static int MIPS_is_fake_mcount(Elf_Rel const *rp)
  100764. {
  100765. - static Elf_Addr old_r_offset = ~(Elf_Addr)0;
  100766. + static Elf_Addr old_r_offset;
  100767. Elf_Addr current_r_offset = _w(rp->r_offset);
  100768. int is_fake;
  100769. - is_fake = (old_r_offset != ~(Elf_Addr)0) &&
  100770. + is_fake = old_r_offset &&
  100771. (current_r_offset - old_r_offset == MIPS_FAKEMCOUNT_OFFSET);
  100772. old_r_offset = current_r_offset;
  100773. diff -Nur linux-3.15.4/sound/arm/bcm2835.c linux-rpi/sound/arm/bcm2835.c
  100774. --- linux-3.15.4/sound/arm/bcm2835.c 1970-01-01 01:00:00.000000000 +0100
  100775. +++ linux-rpi/sound/arm/bcm2835.c 2014-07-07 10:46:02.000000000 +0200
  100776. @@ -0,0 +1,420 @@
  100777. +/*****************************************************************************
  100778. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  100779. +*
  100780. +* Unless you and Broadcom execute a separate written software license
  100781. +* agreement governing use of this software, this software is licensed to you
  100782. +* under the terms of the GNU General Public License version 2, available at
  100783. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  100784. +*
  100785. +* Notwithstanding the above, under no circumstances may you combine this
  100786. +* software in any way with any other Broadcom software provided under a
  100787. +* license other than the GPL, without Broadcom's express prior written
  100788. +* consent.
  100789. +*****************************************************************************/
  100790. +
  100791. +#include <linux/platform_device.h>
  100792. +
  100793. +#include <linux/init.h>
  100794. +#include <linux/slab.h>
  100795. +#include <linux/module.h>
  100796. +
  100797. +#include "bcm2835.h"
  100798. +
  100799. +/* module parameters (see "Module Parameters") */
  100800. +/* SNDRV_CARDS: maximum number of cards supported by this module */
  100801. +static int index[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = -1 };
  100802. +static char *id[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = NULL };
  100803. +static int enable[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = 1 };
  100804. +
  100805. +/* HACKY global pointers needed for successive probes to work : ssp
  100806. + * But compared against the changes we will have to do in VC audio_ipc code
  100807. + * to export 8 audio_ipc devices as a single IPC device and then monitor all
  100808. + * four devices in a thread, this gets things done quickly and should be easier
  100809. + * to debug if we run into issues
  100810. + */
  100811. +
  100812. +static struct snd_card *g_card = NULL;
  100813. +static bcm2835_chip_t *g_chip = NULL;
  100814. +
  100815. +static int snd_bcm2835_free(bcm2835_chip_t * chip)
  100816. +{
  100817. + kfree(chip);
  100818. + return 0;
  100819. +}
  100820. +
  100821. +/* component-destructor
  100822. + * (see "Management of Cards and Components")
  100823. + */
  100824. +static int snd_bcm2835_dev_free(struct snd_device *device)
  100825. +{
  100826. + return snd_bcm2835_free(device->device_data);
  100827. +}
  100828. +
  100829. +/* chip-specific constructor
  100830. + * (see "Management of Cards and Components")
  100831. + */
  100832. +static int snd_bcm2835_create(struct snd_card *card,
  100833. + struct platform_device *pdev,
  100834. + bcm2835_chip_t ** rchip)
  100835. +{
  100836. + bcm2835_chip_t *chip;
  100837. + int err;
  100838. + static struct snd_device_ops ops = {
  100839. + .dev_free = snd_bcm2835_dev_free,
  100840. + };
  100841. +
  100842. + *rchip = NULL;
  100843. +
  100844. + chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  100845. + if (chip == NULL)
  100846. + return -ENOMEM;
  100847. +
  100848. + chip->card = card;
  100849. +
  100850. + err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
  100851. + if (err < 0) {
  100852. + snd_bcm2835_free(chip);
  100853. + return err;
  100854. + }
  100855. +
  100856. + *rchip = chip;
  100857. + return 0;
  100858. +}
  100859. +
  100860. +static int snd_bcm2835_alsa_probe(struct platform_device *pdev)
  100861. +{
  100862. + static int dev;
  100863. + bcm2835_chip_t *chip;
  100864. + struct snd_card *card;
  100865. + int err;
  100866. +
  100867. + if (dev >= MAX_SUBSTREAMS)
  100868. + return -ENODEV;
  100869. +
  100870. + if (!enable[dev]) {
  100871. + dev++;
  100872. + return -ENOENT;
  100873. + }
  100874. +
  100875. + if (dev > 0)
  100876. + goto add_register_map;
  100877. +
  100878. + err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &g_card);
  100879. + if (err < 0)
  100880. + goto out;
  100881. +
  100882. + snd_card_set_dev(g_card, &pdev->dev);
  100883. + strcpy(g_card->driver, "bcm2835");
  100884. + strcpy(g_card->shortname, "bcm2835 ALSA");
  100885. + sprintf(g_card->longname, "%s", g_card->shortname);
  100886. +
  100887. + err = snd_bcm2835_create(g_card, pdev, &chip);
  100888. + if (err < 0) {
  100889. + dev_err(&pdev->dev, "Failed to create bcm2835 chip\n");
  100890. + goto out_bcm2835_create;
  100891. + }
  100892. +
  100893. + g_chip = chip;
  100894. + err = snd_bcm2835_new_pcm(chip);
  100895. + if (err < 0) {
  100896. + dev_err(&pdev->dev, "Failed to create new BCM2835 pcm device\n");
  100897. + goto out_bcm2835_new_pcm;
  100898. + }
  100899. +
  100900. + err = snd_bcm2835_new_spdif_pcm(chip);
  100901. + if (err < 0) {
  100902. + dev_err(&pdev->dev, "Failed to create new BCM2835 spdif pcm device\n");
  100903. + goto out_bcm2835_new_spdif;
  100904. + }
  100905. +
  100906. + err = snd_bcm2835_new_ctl(chip);
  100907. + if (err < 0) {
  100908. + dev_err(&pdev->dev, "Failed to create new BCM2835 ctl\n");
  100909. + goto out_bcm2835_new_ctl;
  100910. + }
  100911. +
  100912. +add_register_map:
  100913. + card = g_card;
  100914. + chip = g_chip;
  100915. +
  100916. + BUG_ON(!(card && chip));
  100917. +
  100918. + chip->avail_substreams |= (1 << dev);
  100919. + chip->pdev[dev] = pdev;
  100920. +
  100921. + if (dev == 0) {
  100922. + err = snd_card_register(card);
  100923. + if (err < 0) {
  100924. + dev_err(&pdev->dev,
  100925. + "Failed to register bcm2835 ALSA card \n");
  100926. + goto out_card_register;
  100927. + }
  100928. + platform_set_drvdata(pdev, card);
  100929. + audio_info("bcm2835 ALSA card created!\n");
  100930. + } else {
  100931. + audio_info("bcm2835 ALSA chip created!\n");
  100932. + platform_set_drvdata(pdev, (void *)dev);
  100933. + }
  100934. +
  100935. + dev++;
  100936. +
  100937. + return 0;
  100938. +
  100939. +out_card_register:
  100940. +out_bcm2835_new_ctl:
  100941. +out_bcm2835_new_spdif:
  100942. +out_bcm2835_new_pcm:
  100943. +out_bcm2835_create:
  100944. + BUG_ON(!g_card);
  100945. + if (snd_card_free(g_card))
  100946. + dev_err(&pdev->dev, "Failed to free Registered alsa card\n");
  100947. + g_card = NULL;
  100948. +out:
  100949. + dev = SNDRV_CARDS; /* stop more avail_substreams from being probed */
  100950. + dev_err(&pdev->dev, "BCM2835 ALSA Probe failed !!\n");
  100951. + return err;
  100952. +}
  100953. +
  100954. +static int snd_bcm2835_alsa_remove(struct platform_device *pdev)
  100955. +{
  100956. + uint32_t idx;
  100957. + void *drv_data;
  100958. +
  100959. + drv_data = platform_get_drvdata(pdev);
  100960. +
  100961. + if (drv_data == (void *)g_card) {
  100962. + /* This is the card device */
  100963. + snd_card_free((struct snd_card *)drv_data);
  100964. + g_card = NULL;
  100965. + g_chip = NULL;
  100966. + } else {
  100967. + idx = (uint32_t) drv_data;
  100968. + if (g_card != NULL) {
  100969. + BUG_ON(!g_chip);
  100970. + /* We pass chip device numbers in audio ipc devices
  100971. + * other than the one we registered our card with
  100972. + */
  100973. + idx = (uint32_t) drv_data;
  100974. + BUG_ON(!idx || idx > MAX_SUBSTREAMS);
  100975. + g_chip->avail_substreams &= ~(1 << idx);
  100976. + /* There should be atleast one substream registered
  100977. + * after we are done here, as it wil be removed when
  100978. + * the *remove* is called for the card device
  100979. + */
  100980. + BUG_ON(!g_chip->avail_substreams);
  100981. + }
  100982. + }
  100983. +
  100984. + platform_set_drvdata(pdev, NULL);
  100985. +
  100986. + return 0;
  100987. +}
  100988. +
  100989. +#ifdef CONFIG_PM
  100990. +static int snd_bcm2835_alsa_suspend(struct platform_device *pdev,
  100991. + pm_message_t state)
  100992. +{
  100993. + return 0;
  100994. +}
  100995. +
  100996. +static int snd_bcm2835_alsa_resume(struct platform_device *pdev)
  100997. +{
  100998. + return 0;
  100999. +}
  101000. +
  101001. +#endif
  101002. +
  101003. +static struct platform_driver bcm2835_alsa0_driver = {
  101004. + .probe = snd_bcm2835_alsa_probe,
  101005. + .remove = snd_bcm2835_alsa_remove,
  101006. +#ifdef CONFIG_PM
  101007. + .suspend = snd_bcm2835_alsa_suspend,
  101008. + .resume = snd_bcm2835_alsa_resume,
  101009. +#endif
  101010. + .driver = {
  101011. + .name = "bcm2835_AUD0",
  101012. + .owner = THIS_MODULE,
  101013. + },
  101014. +};
  101015. +
  101016. +static struct platform_driver bcm2835_alsa1_driver = {
  101017. + .probe = snd_bcm2835_alsa_probe,
  101018. + .remove = snd_bcm2835_alsa_remove,
  101019. +#ifdef CONFIG_PM
  101020. + .suspend = snd_bcm2835_alsa_suspend,
  101021. + .resume = snd_bcm2835_alsa_resume,
  101022. +#endif
  101023. + .driver = {
  101024. + .name = "bcm2835_AUD1",
  101025. + .owner = THIS_MODULE,
  101026. + },
  101027. +};
  101028. +
  101029. +static struct platform_driver bcm2835_alsa2_driver = {
  101030. + .probe = snd_bcm2835_alsa_probe,
  101031. + .remove = snd_bcm2835_alsa_remove,
  101032. +#ifdef CONFIG_PM
  101033. + .suspend = snd_bcm2835_alsa_suspend,
  101034. + .resume = snd_bcm2835_alsa_resume,
  101035. +#endif
  101036. + .driver = {
  101037. + .name = "bcm2835_AUD2",
  101038. + .owner = THIS_MODULE,
  101039. + },
  101040. +};
  101041. +
  101042. +static struct platform_driver bcm2835_alsa3_driver = {
  101043. + .probe = snd_bcm2835_alsa_probe,
  101044. + .remove = snd_bcm2835_alsa_remove,
  101045. +#ifdef CONFIG_PM
  101046. + .suspend = snd_bcm2835_alsa_suspend,
  101047. + .resume = snd_bcm2835_alsa_resume,
  101048. +#endif
  101049. + .driver = {
  101050. + .name = "bcm2835_AUD3",
  101051. + .owner = THIS_MODULE,
  101052. + },
  101053. +};
  101054. +
  101055. +static struct platform_driver bcm2835_alsa4_driver = {
  101056. + .probe = snd_bcm2835_alsa_probe,
  101057. + .remove = snd_bcm2835_alsa_remove,
  101058. +#ifdef CONFIG_PM
  101059. + .suspend = snd_bcm2835_alsa_suspend,
  101060. + .resume = snd_bcm2835_alsa_resume,
  101061. +#endif
  101062. + .driver = {
  101063. + .name = "bcm2835_AUD4",
  101064. + .owner = THIS_MODULE,
  101065. + },
  101066. +};
  101067. +
  101068. +static struct platform_driver bcm2835_alsa5_driver = {
  101069. + .probe = snd_bcm2835_alsa_probe,
  101070. + .remove = snd_bcm2835_alsa_remove,
  101071. +#ifdef CONFIG_PM
  101072. + .suspend = snd_bcm2835_alsa_suspend,
  101073. + .resume = snd_bcm2835_alsa_resume,
  101074. +#endif
  101075. + .driver = {
  101076. + .name = "bcm2835_AUD5",
  101077. + .owner = THIS_MODULE,
  101078. + },
  101079. +};
  101080. +
  101081. +static struct platform_driver bcm2835_alsa6_driver = {
  101082. + .probe = snd_bcm2835_alsa_probe,
  101083. + .remove = snd_bcm2835_alsa_remove,
  101084. +#ifdef CONFIG_PM
  101085. + .suspend = snd_bcm2835_alsa_suspend,
  101086. + .resume = snd_bcm2835_alsa_resume,
  101087. +#endif
  101088. + .driver = {
  101089. + .name = "bcm2835_AUD6",
  101090. + .owner = THIS_MODULE,
  101091. + },
  101092. +};
  101093. +
  101094. +static struct platform_driver bcm2835_alsa7_driver = {
  101095. + .probe = snd_bcm2835_alsa_probe,
  101096. + .remove = snd_bcm2835_alsa_remove,
  101097. +#ifdef CONFIG_PM
  101098. + .suspend = snd_bcm2835_alsa_suspend,
  101099. + .resume = snd_bcm2835_alsa_resume,
  101100. +#endif
  101101. + .driver = {
  101102. + .name = "bcm2835_AUD7",
  101103. + .owner = THIS_MODULE,
  101104. + },
  101105. +};
  101106. +
  101107. +static int bcm2835_alsa_device_init(void)
  101108. +{
  101109. + int err;
  101110. + err = platform_driver_register(&bcm2835_alsa0_driver);
  101111. + if (err) {
  101112. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  101113. + goto out;
  101114. + }
  101115. +
  101116. + err = platform_driver_register(&bcm2835_alsa1_driver);
  101117. + if (err) {
  101118. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  101119. + goto unregister_0;
  101120. + }
  101121. +
  101122. + err = platform_driver_register(&bcm2835_alsa2_driver);
  101123. + if (err) {
  101124. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  101125. + goto unregister_1;
  101126. + }
  101127. +
  101128. + err = platform_driver_register(&bcm2835_alsa3_driver);
  101129. + if (err) {
  101130. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  101131. + goto unregister_2;
  101132. + }
  101133. +
  101134. + err = platform_driver_register(&bcm2835_alsa4_driver);
  101135. + if (err) {
  101136. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  101137. + goto unregister_3;
  101138. + }
  101139. +
  101140. + err = platform_driver_register(&bcm2835_alsa5_driver);
  101141. + if (err) {
  101142. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  101143. + goto unregister_4;
  101144. + }
  101145. +
  101146. + err = platform_driver_register(&bcm2835_alsa6_driver);
  101147. + if (err) {
  101148. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  101149. + goto unregister_5;
  101150. + }
  101151. +
  101152. + err = platform_driver_register(&bcm2835_alsa7_driver);
  101153. + if (err) {
  101154. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  101155. + goto unregister_6;
  101156. + }
  101157. +
  101158. + return 0;
  101159. +
  101160. +unregister_6:
  101161. + platform_driver_unregister(&bcm2835_alsa6_driver);
  101162. +unregister_5:
  101163. + platform_driver_unregister(&bcm2835_alsa5_driver);
  101164. +unregister_4:
  101165. + platform_driver_unregister(&bcm2835_alsa4_driver);
  101166. +unregister_3:
  101167. + platform_driver_unregister(&bcm2835_alsa3_driver);
  101168. +unregister_2:
  101169. + platform_driver_unregister(&bcm2835_alsa2_driver);
  101170. +unregister_1:
  101171. + platform_driver_unregister(&bcm2835_alsa1_driver);
  101172. +unregister_0:
  101173. + platform_driver_unregister(&bcm2835_alsa0_driver);
  101174. +out:
  101175. + return err;
  101176. +}
  101177. +
  101178. +static void bcm2835_alsa_device_exit(void)
  101179. +{
  101180. + platform_driver_unregister(&bcm2835_alsa0_driver);
  101181. + platform_driver_unregister(&bcm2835_alsa1_driver);
  101182. + platform_driver_unregister(&bcm2835_alsa2_driver);
  101183. + platform_driver_unregister(&bcm2835_alsa3_driver);
  101184. + platform_driver_unregister(&bcm2835_alsa4_driver);
  101185. + platform_driver_unregister(&bcm2835_alsa5_driver);
  101186. + platform_driver_unregister(&bcm2835_alsa6_driver);
  101187. + platform_driver_unregister(&bcm2835_alsa7_driver);
  101188. +}
  101189. +
  101190. +late_initcall(bcm2835_alsa_device_init);
  101191. +module_exit(bcm2835_alsa_device_exit);
  101192. +
  101193. +MODULE_AUTHOR("Dom Cobley");
  101194. +MODULE_DESCRIPTION("Alsa driver for BCM2835 chip");
  101195. +MODULE_LICENSE("GPL");
  101196. +MODULE_ALIAS("platform:bcm2835_alsa");
  101197. diff -Nur linux-3.15.4/sound/arm/bcm2835-ctl.c linux-rpi/sound/arm/bcm2835-ctl.c
  101198. --- linux-3.15.4/sound/arm/bcm2835-ctl.c 1970-01-01 01:00:00.000000000 +0100
  101199. +++ linux-rpi/sound/arm/bcm2835-ctl.c 2014-07-07 10:46:02.000000000 +0200
  101200. @@ -0,0 +1,323 @@
  101201. +/*****************************************************************************
  101202. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  101203. +*
  101204. +* Unless you and Broadcom execute a separate written software license
  101205. +* agreement governing use of this software, this software is licensed to you
  101206. +* under the terms of the GNU General Public License version 2, available at
  101207. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  101208. +*
  101209. +* Notwithstanding the above, under no circumstances may you combine this
  101210. +* software in any way with any other Broadcom software provided under a
  101211. +* license other than the GPL, without Broadcom's express prior written
  101212. +* consent.
  101213. +*****************************************************************************/
  101214. +
  101215. +#include <linux/platform_device.h>
  101216. +#include <linux/init.h>
  101217. +#include <linux/io.h>
  101218. +#include <linux/jiffies.h>
  101219. +#include <linux/slab.h>
  101220. +#include <linux/time.h>
  101221. +#include <linux/wait.h>
  101222. +#include <linux/delay.h>
  101223. +#include <linux/moduleparam.h>
  101224. +#include <linux/sched.h>
  101225. +
  101226. +#include <sound/core.h>
  101227. +#include <sound/control.h>
  101228. +#include <sound/pcm.h>
  101229. +#include <sound/pcm_params.h>
  101230. +#include <sound/rawmidi.h>
  101231. +#include <sound/initval.h>
  101232. +#include <sound/tlv.h>
  101233. +#include <sound/asoundef.h>
  101234. +
  101235. +#include "bcm2835.h"
  101236. +
  101237. +/* volume maximum and minimum in terms of 0.01dB */
  101238. +#define CTRL_VOL_MAX 400
  101239. +#define CTRL_VOL_MIN -10239 /* originally -10240 */
  101240. +
  101241. +
  101242. +static int snd_bcm2835_ctl_info(struct snd_kcontrol *kcontrol,
  101243. + struct snd_ctl_elem_info *uinfo)
  101244. +{
  101245. + audio_info(" ... IN\n");
  101246. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
  101247. + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  101248. + uinfo->count = 1;
  101249. + uinfo->value.integer.min = CTRL_VOL_MIN;
  101250. + uinfo->value.integer.max = CTRL_VOL_MAX; /* 2303 */
  101251. + } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
  101252. + uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  101253. + uinfo->count = 1;
  101254. + uinfo->value.integer.min = 0;
  101255. + uinfo->value.integer.max = 1;
  101256. + } else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) {
  101257. + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  101258. + uinfo->count = 1;
  101259. + uinfo->value.integer.min = 0;
  101260. + uinfo->value.integer.max = AUDIO_DEST_MAX-1;
  101261. + }
  101262. + audio_info(" ... OUT\n");
  101263. + return 0;
  101264. +}
  101265. +
  101266. +/* toggles mute on or off depending on the value of nmute, and returns
  101267. + * 1 if the mute value was changed, otherwise 0
  101268. + */
  101269. +static int toggle_mute(struct bcm2835_chip *chip, int nmute)
  101270. +{
  101271. + /* if settings are ok, just return 0 */
  101272. + if(chip->mute == nmute)
  101273. + return 0;
  101274. +
  101275. + /* if the sound is muted then we need to unmute */
  101276. + if(chip->mute == CTRL_VOL_MUTE)
  101277. + {
  101278. + chip->volume = chip->old_volume; /* copy the old volume back */
  101279. + audio_info("Unmuting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume);
  101280. + }
  101281. + else /* otherwise we mute */
  101282. + {
  101283. + chip->old_volume = chip->volume;
  101284. + chip->volume = 26214; /* set volume to minimum level AKA mute */
  101285. + audio_info("Muting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume);
  101286. + }
  101287. +
  101288. + chip->mute = nmute;
  101289. + return 1;
  101290. +}
  101291. +
  101292. +static int snd_bcm2835_ctl_get(struct snd_kcontrol *kcontrol,
  101293. + struct snd_ctl_elem_value *ucontrol)
  101294. +{
  101295. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  101296. +
  101297. + BUG_ON(!chip && !(chip->avail_substreams & AVAIL_SUBSTREAMS_MASK));
  101298. +
  101299. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME)
  101300. + ucontrol->value.integer.value[0] = chip2alsa(chip->volume);
  101301. + else if (kcontrol->private_value == PCM_PLAYBACK_MUTE)
  101302. + ucontrol->value.integer.value[0] = chip->mute;
  101303. + else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE)
  101304. + ucontrol->value.integer.value[0] = chip->dest;
  101305. +
  101306. + return 0;
  101307. +}
  101308. +
  101309. +static int snd_bcm2835_ctl_put(struct snd_kcontrol *kcontrol,
  101310. + struct snd_ctl_elem_value *ucontrol)
  101311. +{
  101312. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  101313. + int changed = 0;
  101314. +
  101315. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
  101316. + audio_info("Volume change attempted.. volume = %d new_volume = %d\n", chip->volume, (int)ucontrol->value.integer.value[0]);
  101317. + if (chip->mute == CTRL_VOL_MUTE) {
  101318. + /* changed = toggle_mute(chip, CTRL_VOL_UNMUTE); */
  101319. + return 1; /* should return 0 to signify no change but the mixer takes this as the opposite sign (no idea why) */
  101320. + }
  101321. + if (changed
  101322. + || (ucontrol->value.integer.value[0] != chip2alsa(chip->volume))) {
  101323. +
  101324. + chip->volume = alsa2chip(ucontrol->value.integer.value[0]);
  101325. + changed = 1;
  101326. + }
  101327. +
  101328. + } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
  101329. + /* Now implemented */
  101330. + audio_info(" Mute attempted\n");
  101331. + changed = toggle_mute(chip, ucontrol->value.integer.value[0]);
  101332. +
  101333. + } else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) {
  101334. + if (ucontrol->value.integer.value[0] != chip->dest) {
  101335. + chip->dest = ucontrol->value.integer.value[0];
  101336. + changed = 1;
  101337. + }
  101338. + }
  101339. +
  101340. + if (changed) {
  101341. + if (bcm2835_audio_set_ctls(chip))
  101342. + printk(KERN_ERR "Failed to set ALSA controls..\n");
  101343. + }
  101344. +
  101345. + return changed;
  101346. +}
  101347. +
  101348. +static DECLARE_TLV_DB_SCALE(snd_bcm2835_db_scale, CTRL_VOL_MIN, 1, 1);
  101349. +
  101350. +static struct snd_kcontrol_new snd_bcm2835_ctl[] = {
  101351. + {
  101352. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  101353. + .name = "PCM Playback Volume",
  101354. + .index = 0,
  101355. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  101356. + .private_value = PCM_PLAYBACK_VOLUME,
  101357. + .info = snd_bcm2835_ctl_info,
  101358. + .get = snd_bcm2835_ctl_get,
  101359. + .put = snd_bcm2835_ctl_put,
  101360. + .count = 1,
  101361. + .tlv = {.p = snd_bcm2835_db_scale}
  101362. + },
  101363. + {
  101364. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  101365. + .name = "PCM Playback Switch",
  101366. + .index = 0,
  101367. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  101368. + .private_value = PCM_PLAYBACK_MUTE,
  101369. + .info = snd_bcm2835_ctl_info,
  101370. + .get = snd_bcm2835_ctl_get,
  101371. + .put = snd_bcm2835_ctl_put,
  101372. + .count = 1,
  101373. + },
  101374. + {
  101375. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  101376. + .name = "PCM Playback Route",
  101377. + .index = 0,
  101378. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  101379. + .private_value = PCM_PLAYBACK_DEVICE,
  101380. + .info = snd_bcm2835_ctl_info,
  101381. + .get = snd_bcm2835_ctl_get,
  101382. + .put = snd_bcm2835_ctl_put,
  101383. + .count = 1,
  101384. + },
  101385. +};
  101386. +
  101387. +static int snd_bcm2835_spdif_default_info(struct snd_kcontrol *kcontrol,
  101388. + struct snd_ctl_elem_info *uinfo)
  101389. +{
  101390. + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  101391. + uinfo->count = 1;
  101392. + return 0;
  101393. +}
  101394. +
  101395. +static int snd_bcm2835_spdif_default_get(struct snd_kcontrol *kcontrol,
  101396. + struct snd_ctl_elem_value *ucontrol)
  101397. +{
  101398. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  101399. + int i;
  101400. +
  101401. + for (i = 0; i < 4; i++)
  101402. + ucontrol->value.iec958.status[i] =
  101403. + (chip->spdif_status >> (i * 8)) && 0xff;
  101404. +
  101405. + return 0;
  101406. +}
  101407. +
  101408. +static int snd_bcm2835_spdif_default_put(struct snd_kcontrol *kcontrol,
  101409. + struct snd_ctl_elem_value *ucontrol)
  101410. +{
  101411. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  101412. + unsigned int val = 0;
  101413. + int i, change;
  101414. +
  101415. + for (i = 0; i < 4; i++)
  101416. + val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8);
  101417. +
  101418. + change = val != chip->spdif_status;
  101419. + chip->spdif_status = val;
  101420. +
  101421. + return change;
  101422. +}
  101423. +
  101424. +static int snd_bcm2835_spdif_mask_info(struct snd_kcontrol *kcontrol,
  101425. + struct snd_ctl_elem_info *uinfo)
  101426. +{
  101427. + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  101428. + uinfo->count = 1;
  101429. + return 0;
  101430. +}
  101431. +
  101432. +static int snd_bcm2835_spdif_mask_get(struct snd_kcontrol *kcontrol,
  101433. + struct snd_ctl_elem_value *ucontrol)
  101434. +{
  101435. + /* bcm2835 supports only consumer mode and sets all other format flags
  101436. + * automatically. So the only thing left is signalling non-audio
  101437. + * content */
  101438. + ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO;
  101439. + return 0;
  101440. +}
  101441. +
  101442. +static int snd_bcm2835_spdif_stream_info(struct snd_kcontrol *kcontrol,
  101443. + struct snd_ctl_elem_info *uinfo)
  101444. +{
  101445. + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  101446. + uinfo->count = 1;
  101447. + return 0;
  101448. +}
  101449. +
  101450. +static int snd_bcm2835_spdif_stream_get(struct snd_kcontrol *kcontrol,
  101451. + struct snd_ctl_elem_value *ucontrol)
  101452. +{
  101453. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  101454. + int i;
  101455. +
  101456. + for (i = 0; i < 4; i++)
  101457. + ucontrol->value.iec958.status[i] =
  101458. + (chip->spdif_status >> (i * 8)) & 0xff;
  101459. + return 0;
  101460. +}
  101461. +
  101462. +static int snd_bcm2835_spdif_stream_put(struct snd_kcontrol *kcontrol,
  101463. + struct snd_ctl_elem_value *ucontrol)
  101464. +{
  101465. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  101466. + unsigned int val = 0;
  101467. + int i, change;
  101468. +
  101469. + for (i = 0; i < 4; i++)
  101470. + val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8);
  101471. + change = val != chip->spdif_status;
  101472. + chip->spdif_status = val;
  101473. +
  101474. + return change;
  101475. +}
  101476. +
  101477. +static struct snd_kcontrol_new snd_bcm2835_spdif[] = {
  101478. + {
  101479. + .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  101480. + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
  101481. + .info = snd_bcm2835_spdif_default_info,
  101482. + .get = snd_bcm2835_spdif_default_get,
  101483. + .put = snd_bcm2835_spdif_default_put
  101484. + },
  101485. + {
  101486. + .access = SNDRV_CTL_ELEM_ACCESS_READ,
  101487. + .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  101488. + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK),
  101489. + .info = snd_bcm2835_spdif_mask_info,
  101490. + .get = snd_bcm2835_spdif_mask_get,
  101491. + },
  101492. + {
  101493. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  101494. + SNDRV_CTL_ELEM_ACCESS_INACTIVE,
  101495. + .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  101496. + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM),
  101497. + .info = snd_bcm2835_spdif_stream_info,
  101498. + .get = snd_bcm2835_spdif_stream_get,
  101499. + .put = snd_bcm2835_spdif_stream_put,
  101500. + },
  101501. +};
  101502. +
  101503. +int snd_bcm2835_new_ctl(bcm2835_chip_t * chip)
  101504. +{
  101505. + int err;
  101506. + unsigned int idx;
  101507. +
  101508. + strcpy(chip->card->mixername, "Broadcom Mixer");
  101509. + for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_ctl); idx++) {
  101510. + err =
  101511. + snd_ctl_add(chip->card,
  101512. + snd_ctl_new1(&snd_bcm2835_ctl[idx], chip));
  101513. + if (err < 0)
  101514. + return err;
  101515. + }
  101516. + for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_spdif); idx++) {
  101517. + err = snd_ctl_add(chip->card,
  101518. + snd_ctl_new1(&snd_bcm2835_spdif[idx], chip));
  101519. + if (err < 0)
  101520. + return err;
  101521. + }
  101522. + return 0;
  101523. +}
  101524. diff -Nur linux-3.15.4/sound/arm/bcm2835.h linux-rpi/sound/arm/bcm2835.h
  101525. --- linux-3.15.4/sound/arm/bcm2835.h 1970-01-01 01:00:00.000000000 +0100
  101526. +++ linux-rpi/sound/arm/bcm2835.h 2014-07-07 10:46:02.000000000 +0200
  101527. @@ -0,0 +1,166 @@
  101528. +/*****************************************************************************
  101529. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  101530. +*
  101531. +* Unless you and Broadcom execute a separate written software license
  101532. +* agreement governing use of this software, this software is licensed to you
  101533. +* under the terms of the GNU General Public License version 2, available at
  101534. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  101535. +*
  101536. +* Notwithstanding the above, under no circumstances may you combine this
  101537. +* software in any way with any other Broadcom software provided under a
  101538. +* license other than the GPL, without Broadcom's express prior written
  101539. +* consent.
  101540. +*****************************************************************************/
  101541. +
  101542. +#ifndef __SOUND_ARM_BCM2835_H
  101543. +#define __SOUND_ARM_BCM2835_H
  101544. +
  101545. +#include <linux/device.h>
  101546. +#include <linux/list.h>
  101547. +#include <linux/interrupt.h>
  101548. +#include <linux/wait.h>
  101549. +#include <sound/core.h>
  101550. +#include <sound/initval.h>
  101551. +#include <sound/pcm.h>
  101552. +#include <sound/pcm_params.h>
  101553. +#include <sound/pcm-indirect.h>
  101554. +#include <linux/workqueue.h>
  101555. +
  101556. +/*
  101557. +#define AUDIO_DEBUG_ENABLE
  101558. +#define AUDIO_VERBOSE_DEBUG_ENABLE
  101559. +*/
  101560. +
  101561. +/* Debug macros */
  101562. +
  101563. +#ifdef AUDIO_DEBUG_ENABLE
  101564. +#ifdef AUDIO_VERBOSE_DEBUG_ENABLE
  101565. +
  101566. +#define audio_debug(fmt, arg...) \
  101567. + printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
  101568. +
  101569. +#define audio_info(fmt, arg...) \
  101570. + printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
  101571. +
  101572. +#else
  101573. +
  101574. +#define audio_debug(fmt, arg...)
  101575. +
  101576. +#define audio_info(fmt, arg...)
  101577. +
  101578. +#endif /* AUDIO_VERBOSE_DEBUG_ENABLE */
  101579. +
  101580. +#else
  101581. +
  101582. +#define audio_debug(fmt, arg...)
  101583. +
  101584. +#define audio_info(fmt, arg...)
  101585. +
  101586. +#endif /* AUDIO_DEBUG_ENABLE */
  101587. +
  101588. +#define audio_error(fmt, arg...) \
  101589. + printk(KERN_ERR"%s:%d " fmt, __func__, __LINE__, ##arg)
  101590. +
  101591. +#define audio_warning(fmt, arg...) \
  101592. + printk(KERN_WARNING"%s:%d " fmt, __func__, __LINE__, ##arg)
  101593. +
  101594. +#define audio_alert(fmt, arg...) \
  101595. + printk(KERN_ALERT"%s:%d " fmt, __func__, __LINE__, ##arg)
  101596. +
  101597. +#define MAX_SUBSTREAMS (8)
  101598. +#define AVAIL_SUBSTREAMS_MASK (0xff)
  101599. +enum {
  101600. + CTRL_VOL_MUTE,
  101601. + CTRL_VOL_UNMUTE
  101602. +};
  101603. +
  101604. +/* macros for alsa2chip and chip2alsa, instead of functions */
  101605. +
  101606. +#define alsa2chip(vol) (uint)(-((vol << 8) / 100)) /* convert alsa to chip volume (defined as macro rather than function call) */
  101607. +#define chip2alsa(vol) -((vol * 100) >> 8) /* convert chip to alsa volume */
  101608. +
  101609. +/* Some constants for values .. */
  101610. +typedef enum {
  101611. + AUDIO_DEST_AUTO = 0,
  101612. + AUDIO_DEST_HEADPHONES = 1,
  101613. + AUDIO_DEST_HDMI = 2,
  101614. + AUDIO_DEST_MAX,
  101615. +} SND_BCM2835_ROUTE_T;
  101616. +
  101617. +typedef enum {
  101618. + PCM_PLAYBACK_VOLUME,
  101619. + PCM_PLAYBACK_MUTE,
  101620. + PCM_PLAYBACK_DEVICE,
  101621. +} SND_BCM2835_CTRL_T;
  101622. +
  101623. +/* definition of the chip-specific record */
  101624. +typedef struct bcm2835_chip {
  101625. + struct snd_card *card;
  101626. + struct snd_pcm *pcm;
  101627. + struct snd_pcm *pcm_spdif;
  101628. + /* Bitmat for valid reg_base and irq numbers */
  101629. + uint32_t avail_substreams;
  101630. + struct platform_device *pdev[MAX_SUBSTREAMS];
  101631. + struct bcm2835_alsa_stream *alsa_stream[MAX_SUBSTREAMS];
  101632. +
  101633. + int volume;
  101634. + int old_volume; /* stores the volume value whist muted */
  101635. + int dest;
  101636. + int mute;
  101637. +
  101638. + unsigned int opened;
  101639. + unsigned int spdif_status;
  101640. +} bcm2835_chip_t;
  101641. +
  101642. +typedef struct bcm2835_alsa_stream {
  101643. + bcm2835_chip_t *chip;
  101644. + struct snd_pcm_substream *substream;
  101645. + struct snd_pcm_indirect pcm_indirect;
  101646. +
  101647. + struct semaphore buffers_update_sem;
  101648. + struct semaphore control_sem;
  101649. + spinlock_t lock;
  101650. + volatile uint32_t control;
  101651. + volatile uint32_t status;
  101652. +
  101653. + int open;
  101654. + int running;
  101655. + int draining;
  101656. +
  101657. + int channels;
  101658. + int params_rate;
  101659. + int pcm_format_width;
  101660. +
  101661. + unsigned int pos;
  101662. + unsigned int buffer_size;
  101663. + unsigned int period_size;
  101664. +
  101665. + uint32_t enable_fifo_irq;
  101666. + irq_handler_t fifo_irq_handler;
  101667. +
  101668. + atomic_t retrieved;
  101669. + struct opaque_AUDIO_INSTANCE_T *instance;
  101670. + struct workqueue_struct *my_wq;
  101671. + int idx;
  101672. +} bcm2835_alsa_stream_t;
  101673. +
  101674. +int snd_bcm2835_new_ctl(bcm2835_chip_t * chip);
  101675. +int snd_bcm2835_new_pcm(bcm2835_chip_t * chip);
  101676. +int snd_bcm2835_new_spdif_pcm(bcm2835_chip_t * chip);
  101677. +
  101678. +int bcm2835_audio_open(bcm2835_alsa_stream_t * alsa_stream);
  101679. +int bcm2835_audio_close(bcm2835_alsa_stream_t * alsa_stream);
  101680. +int bcm2835_audio_set_params(bcm2835_alsa_stream_t * alsa_stream,
  101681. + uint32_t channels, uint32_t samplerate,
  101682. + uint32_t bps);
  101683. +int bcm2835_audio_setup(bcm2835_alsa_stream_t * alsa_stream);
  101684. +int bcm2835_audio_start(bcm2835_alsa_stream_t * alsa_stream);
  101685. +int bcm2835_audio_stop(bcm2835_alsa_stream_t * alsa_stream);
  101686. +int bcm2835_audio_set_ctls(bcm2835_chip_t * chip);
  101687. +int bcm2835_audio_write(bcm2835_alsa_stream_t * alsa_stream, uint32_t count,
  101688. + void *src);
  101689. +uint32_t bcm2835_audio_retrieve_buffers(bcm2835_alsa_stream_t * alsa_stream);
  101690. +void bcm2835_audio_flush_buffers(bcm2835_alsa_stream_t * alsa_stream);
  101691. +void bcm2835_audio_flush_playback_buffers(bcm2835_alsa_stream_t * alsa_stream);
  101692. +
  101693. +#endif /* __SOUND_ARM_BCM2835_H */
  101694. diff -Nur linux-3.15.4/sound/arm/bcm2835-pcm.c linux-rpi/sound/arm/bcm2835-pcm.c
  101695. --- linux-3.15.4/sound/arm/bcm2835-pcm.c 1970-01-01 01:00:00.000000000 +0100
  101696. +++ linux-rpi/sound/arm/bcm2835-pcm.c 2014-07-07 10:46:02.000000000 +0200
  101697. @@ -0,0 +1,518 @@
  101698. +/*****************************************************************************
  101699. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  101700. +*
  101701. +* Unless you and Broadcom execute a separate written software license
  101702. +* agreement governing use of this software, this software is licensed to you
  101703. +* under the terms of the GNU General Public License version 2, available at
  101704. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  101705. +*
  101706. +* Notwithstanding the above, under no circumstances may you combine this
  101707. +* software in any way with any other Broadcom software provided under a
  101708. +* license other than the GPL, without Broadcom's express prior written
  101709. +* consent.
  101710. +*****************************************************************************/
  101711. +
  101712. +#include <linux/interrupt.h>
  101713. +#include <linux/slab.h>
  101714. +
  101715. +#include <sound/asoundef.h>
  101716. +
  101717. +#include "bcm2835.h"
  101718. +
  101719. +/* hardware definition */
  101720. +static struct snd_pcm_hardware snd_bcm2835_playback_hw = {
  101721. + .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
  101722. + SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
  101723. + .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  101724. + .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  101725. + .rate_min = 8000,
  101726. + .rate_max = 48000,
  101727. + .channels_min = 1,
  101728. + .channels_max = 2,
  101729. + .buffer_bytes_max = 128 * 1024,
  101730. + .period_bytes_min = 1 * 1024,
  101731. + .period_bytes_max = 128 * 1024,
  101732. + .periods_min = 1,
  101733. + .periods_max = 128,
  101734. +};
  101735. +
  101736. +static struct snd_pcm_hardware snd_bcm2835_playback_spdif_hw = {
  101737. + .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
  101738. + SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
  101739. + .formats = SNDRV_PCM_FMTBIT_S16_LE,
  101740. + .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_44100 |
  101741. + SNDRV_PCM_RATE_48000,
  101742. + .rate_min = 44100,
  101743. + .rate_max = 48000,
  101744. + .channels_min = 2,
  101745. + .channels_max = 2,
  101746. + .buffer_bytes_max = 128 * 1024,
  101747. + .period_bytes_min = 1 * 1024,
  101748. + .period_bytes_max = 128 * 1024,
  101749. + .periods_min = 1,
  101750. + .periods_max = 128,
  101751. +};
  101752. +
  101753. +static void snd_bcm2835_playback_free(struct snd_pcm_runtime *runtime)
  101754. +{
  101755. + audio_info("Freeing up alsa stream here ..\n");
  101756. + if (runtime->private_data)
  101757. + kfree(runtime->private_data);
  101758. + runtime->private_data = NULL;
  101759. +}
  101760. +
  101761. +static irqreturn_t bcm2835_playback_fifo_irq(int irq, void *dev_id)
  101762. +{
  101763. + bcm2835_alsa_stream_t *alsa_stream = (bcm2835_alsa_stream_t *) dev_id;
  101764. + uint32_t consumed = 0;
  101765. + int new_period = 0;
  101766. +
  101767. + audio_info(" .. IN\n");
  101768. +
  101769. + audio_info("alsa_stream=%p substream=%p\n", alsa_stream,
  101770. + alsa_stream ? alsa_stream->substream : 0);
  101771. +
  101772. + if (alsa_stream->open)
  101773. + consumed = bcm2835_audio_retrieve_buffers(alsa_stream);
  101774. +
  101775. + /* We get called only if playback was triggered, So, the number of buffers we retrieve in
  101776. + * each iteration are the buffers that have been played out already
  101777. + */
  101778. +
  101779. + if (alsa_stream->period_size) {
  101780. + if ((alsa_stream->pos / alsa_stream->period_size) !=
  101781. + ((alsa_stream->pos + consumed) / alsa_stream->period_size))
  101782. + new_period = 1;
  101783. + }
  101784. + audio_debug("updating pos cur: %d + %d max:%d period_bytes:%d, hw_ptr: %d new_period:%d\n",
  101785. + alsa_stream->pos,
  101786. + consumed,
  101787. + alsa_stream->buffer_size,
  101788. + (int)(alsa_stream->period_size*alsa_stream->substream->runtime->periods),
  101789. + frames_to_bytes(alsa_stream->substream->runtime, alsa_stream->substream->runtime->status->hw_ptr),
  101790. + new_period);
  101791. + if (alsa_stream->buffer_size) {
  101792. + alsa_stream->pos += consumed &~ (1<<30);
  101793. + alsa_stream->pos %= alsa_stream->buffer_size;
  101794. + }
  101795. +
  101796. + if (alsa_stream->substream) {
  101797. + if (new_period)
  101798. + snd_pcm_period_elapsed(alsa_stream->substream);
  101799. + } else {
  101800. + audio_warning(" unexpected NULL substream\n");
  101801. + }
  101802. + audio_info(" .. OUT\n");
  101803. +
  101804. + return IRQ_HANDLED;
  101805. +}
  101806. +
  101807. +/* open callback */
  101808. +static int snd_bcm2835_playback_open_generic(
  101809. + struct snd_pcm_substream *substream, int spdif)
  101810. +{
  101811. + bcm2835_chip_t *chip = snd_pcm_substream_chip(substream);
  101812. + struct snd_pcm_runtime *runtime = substream->runtime;
  101813. + bcm2835_alsa_stream_t *alsa_stream;
  101814. + int idx;
  101815. + int err;
  101816. +
  101817. + audio_info(" .. IN (%d)\n", substream->number);
  101818. +
  101819. + audio_info("Alsa open (%d)\n", substream->number);
  101820. + idx = substream->number;
  101821. +
  101822. + if (spdif && chip->opened != 0)
  101823. + return -EBUSY;
  101824. + else if (!spdif && (chip->opened & (1 << idx)))
  101825. + return -EBUSY;
  101826. +
  101827. + if (idx > MAX_SUBSTREAMS) {
  101828. + audio_error
  101829. + ("substream(%d) device doesn't exist max(%d) substreams allowed\n",
  101830. + idx, MAX_SUBSTREAMS);
  101831. + err = -ENODEV;
  101832. + goto out;
  101833. + }
  101834. +
  101835. + /* Check if we are ready */
  101836. + if (!(chip->avail_substreams & (1 << idx))) {
  101837. + /* We are not ready yet */
  101838. + audio_error("substream(%d) device is not ready yet\n", idx);
  101839. + err = -EAGAIN;
  101840. + goto out;
  101841. + }
  101842. +
  101843. + alsa_stream = kzalloc(sizeof(bcm2835_alsa_stream_t), GFP_KERNEL);
  101844. + if (alsa_stream == NULL) {
  101845. + return -ENOMEM;
  101846. + }
  101847. +
  101848. + /* Initialise alsa_stream */
  101849. + alsa_stream->chip = chip;
  101850. + alsa_stream->substream = substream;
  101851. + alsa_stream->idx = idx;
  101852. +
  101853. + sema_init(&alsa_stream->buffers_update_sem, 0);
  101854. + sema_init(&alsa_stream->control_sem, 0);
  101855. + spin_lock_init(&alsa_stream->lock);
  101856. +
  101857. + /* Enabled in start trigger, called on each "fifo irq" after that */
  101858. + alsa_stream->enable_fifo_irq = 0;
  101859. + alsa_stream->fifo_irq_handler = bcm2835_playback_fifo_irq;
  101860. +
  101861. + err = bcm2835_audio_open(alsa_stream);
  101862. + if (err != 0) {
  101863. + kfree(alsa_stream);
  101864. + return err;
  101865. + }
  101866. + runtime->private_data = alsa_stream;
  101867. + runtime->private_free = snd_bcm2835_playback_free;
  101868. + if (spdif) {
  101869. + runtime->hw = snd_bcm2835_playback_spdif_hw;
  101870. + } else {
  101871. + /* clear spdif status, as we are not in spdif mode */
  101872. + chip->spdif_status = 0;
  101873. + runtime->hw = snd_bcm2835_playback_hw;
  101874. + }
  101875. + /* minimum 16 bytes alignment (for vchiq bulk transfers) */
  101876. + snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  101877. + 16);
  101878. +
  101879. + chip->alsa_stream[idx] = alsa_stream;
  101880. +
  101881. + chip->opened |= (1 << idx);
  101882. + alsa_stream->open = 1;
  101883. + alsa_stream->draining = 1;
  101884. +
  101885. +out:
  101886. + audio_info(" .. OUT =%d\n", err);
  101887. +
  101888. + return err;
  101889. +}
  101890. +
  101891. +static int snd_bcm2835_playback_open(struct snd_pcm_substream *substream)
  101892. +{
  101893. + return snd_bcm2835_playback_open_generic(substream, 0);
  101894. +}
  101895. +
  101896. +static int snd_bcm2835_playback_spdif_open(struct snd_pcm_substream *substream)
  101897. +{
  101898. + return snd_bcm2835_playback_open_generic(substream, 1);
  101899. +}
  101900. +
  101901. +/* close callback */
  101902. +static int snd_bcm2835_playback_close(struct snd_pcm_substream *substream)
  101903. +{
  101904. + /* the hardware-specific codes will be here */
  101905. +
  101906. + struct snd_pcm_runtime *runtime = substream->runtime;
  101907. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  101908. + bcm2835_chip_t *chip = snd_pcm_substream_chip(substream);
  101909. +
  101910. + audio_info(" .. IN\n");
  101911. + audio_info("Alsa close\n");
  101912. +
  101913. + /*
  101914. + * Call stop if it's still running. This happens when app
  101915. + * is force killed and we don't get a stop trigger.
  101916. + */
  101917. + if (alsa_stream->running) {
  101918. + int err;
  101919. + err = bcm2835_audio_stop(alsa_stream);
  101920. + alsa_stream->running = 0;
  101921. + if (err != 0)
  101922. + audio_error(" Failed to STOP alsa device\n");
  101923. + }
  101924. +
  101925. + alsa_stream->period_size = 0;
  101926. + alsa_stream->buffer_size = 0;
  101927. +
  101928. + if (alsa_stream->open) {
  101929. + alsa_stream->open = 0;
  101930. + bcm2835_audio_close(alsa_stream);
  101931. + }
  101932. + if (alsa_stream->chip)
  101933. + alsa_stream->chip->alsa_stream[alsa_stream->idx] = NULL;
  101934. + /*
  101935. + * Do not free up alsa_stream here, it will be freed up by
  101936. + * runtime->private_free callback we registered in *_open above
  101937. + */
  101938. +
  101939. + chip->opened &= ~(1 << substream->number);
  101940. +
  101941. + audio_info(" .. OUT\n");
  101942. +
  101943. + return 0;
  101944. +}
  101945. +
  101946. +/* hw_params callback */
  101947. +static int snd_bcm2835_pcm_hw_params(struct snd_pcm_substream *substream,
  101948. + struct snd_pcm_hw_params *params)
  101949. +{
  101950. + struct snd_pcm_runtime *runtime = substream->runtime;
  101951. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  101952. + int err;
  101953. +
  101954. + audio_info(" .. IN\n");
  101955. +
  101956. + err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
  101957. + if (err < 0) {
  101958. + audio_error
  101959. + (" pcm_lib_malloc failed to allocated pages for buffers\n");
  101960. + return err;
  101961. + }
  101962. +
  101963. + alsa_stream->channels = params_channels(params);
  101964. + alsa_stream->params_rate = params_rate(params);
  101965. + alsa_stream->pcm_format_width = snd_pcm_format_width(params_format (params));
  101966. + audio_info(" .. OUT\n");
  101967. +
  101968. + return err;
  101969. +}
  101970. +
  101971. +/* hw_free callback */
  101972. +static int snd_bcm2835_pcm_hw_free(struct snd_pcm_substream *substream)
  101973. +{
  101974. + audio_info(" .. IN\n");
  101975. + return snd_pcm_lib_free_pages(substream);
  101976. +}
  101977. +
  101978. +/* prepare callback */
  101979. +static int snd_bcm2835_pcm_prepare(struct snd_pcm_substream *substream)
  101980. +{
  101981. + bcm2835_chip_t *chip = snd_pcm_substream_chip(substream);
  101982. + struct snd_pcm_runtime *runtime = substream->runtime;
  101983. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  101984. + int channels;
  101985. + int err;
  101986. +
  101987. + audio_info(" .. IN\n");
  101988. +
  101989. + /* notify the vchiq that it should enter spdif passthrough mode by
  101990. + * setting channels=0 (see
  101991. + * https://github.com/raspberrypi/linux/issues/528) */
  101992. + if (chip->spdif_status & IEC958_AES0_NONAUDIO)
  101993. + channels = 0;
  101994. + else
  101995. + channels = alsa_stream->channels;
  101996. +
  101997. + err = bcm2835_audio_set_params(alsa_stream, channels,
  101998. + alsa_stream->params_rate,
  101999. + alsa_stream->pcm_format_width);
  102000. + if (err < 0) {
  102001. + audio_error(" error setting hw params\n");
  102002. + }
  102003. +
  102004. + bcm2835_audio_setup(alsa_stream);
  102005. +
  102006. + /* in preparation of the stream, set the controls (volume level) of the stream */
  102007. + bcm2835_audio_set_ctls(alsa_stream->chip);
  102008. +
  102009. +
  102010. + memset(&alsa_stream->pcm_indirect, 0, sizeof(alsa_stream->pcm_indirect));
  102011. +
  102012. + alsa_stream->pcm_indirect.hw_buffer_size =
  102013. + alsa_stream->pcm_indirect.sw_buffer_size =
  102014. + snd_pcm_lib_buffer_bytes(substream);
  102015. +
  102016. + alsa_stream->buffer_size = snd_pcm_lib_buffer_bytes(substream);
  102017. + alsa_stream->period_size = snd_pcm_lib_period_bytes(substream);
  102018. + alsa_stream->pos = 0;
  102019. +
  102020. + audio_debug("buffer_size=%d, period_size=%d pos=%d frame_bits=%d\n",
  102021. + alsa_stream->buffer_size, alsa_stream->period_size,
  102022. + alsa_stream->pos, runtime->frame_bits);
  102023. +
  102024. + audio_info(" .. OUT\n");
  102025. + return 0;
  102026. +}
  102027. +
  102028. +static void snd_bcm2835_pcm_transfer(struct snd_pcm_substream *substream,
  102029. + struct snd_pcm_indirect *rec, size_t bytes)
  102030. +{
  102031. + struct snd_pcm_runtime *runtime = substream->runtime;
  102032. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  102033. + void *src = (void *)(substream->runtime->dma_area + rec->sw_data);
  102034. + int err;
  102035. +
  102036. + err = bcm2835_audio_write(alsa_stream, bytes, src);
  102037. + if (err)
  102038. + audio_error(" Failed to transfer to alsa device (%d)\n", err);
  102039. +
  102040. +}
  102041. +
  102042. +static int snd_bcm2835_pcm_ack(struct snd_pcm_substream *substream)
  102043. +{
  102044. + struct snd_pcm_runtime *runtime = substream->runtime;
  102045. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  102046. + struct snd_pcm_indirect *pcm_indirect = &alsa_stream->pcm_indirect;
  102047. +
  102048. + pcm_indirect->hw_queue_size = runtime->hw.buffer_bytes_max;
  102049. + snd_pcm_indirect_playback_transfer(substream, pcm_indirect,
  102050. + snd_bcm2835_pcm_transfer);
  102051. + return 0;
  102052. +}
  102053. +
  102054. +/* trigger callback */
  102055. +static int snd_bcm2835_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  102056. +{
  102057. + struct snd_pcm_runtime *runtime = substream->runtime;
  102058. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  102059. + int err = 0;
  102060. +
  102061. + audio_info(" .. IN\n");
  102062. +
  102063. + switch (cmd) {
  102064. + case SNDRV_PCM_TRIGGER_START:
  102065. + audio_debug("bcm2835_AUDIO_TRIGGER_START running=%d\n",
  102066. + alsa_stream->running);
  102067. + if (!alsa_stream->running) {
  102068. + err = bcm2835_audio_start(alsa_stream);
  102069. + if (err == 0) {
  102070. + alsa_stream->pcm_indirect.hw_io =
  102071. + alsa_stream->pcm_indirect.hw_data =
  102072. + bytes_to_frames(runtime,
  102073. + alsa_stream->pos);
  102074. + substream->ops->ack(substream);
  102075. + alsa_stream->running = 1;
  102076. + alsa_stream->draining = 1;
  102077. + } else {
  102078. + audio_error(" Failed to START alsa device (%d)\n", err);
  102079. + }
  102080. + }
  102081. + break;
  102082. + case SNDRV_PCM_TRIGGER_STOP:
  102083. + audio_debug
  102084. + ("bcm2835_AUDIO_TRIGGER_STOP running=%d draining=%d\n",
  102085. + alsa_stream->running, runtime->status->state == SNDRV_PCM_STATE_DRAINING);
  102086. + if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
  102087. + audio_info("DRAINING\n");
  102088. + alsa_stream->draining = 1;
  102089. + } else {
  102090. + audio_info("DROPPING\n");
  102091. + alsa_stream->draining = 0;
  102092. + }
  102093. + if (alsa_stream->running) {
  102094. + err = bcm2835_audio_stop(alsa_stream);
  102095. + if (err != 0)
  102096. + audio_error(" Failed to STOP alsa device (%d)\n", err);
  102097. + alsa_stream->running = 0;
  102098. + }
  102099. + break;
  102100. + default:
  102101. + err = -EINVAL;
  102102. + }
  102103. +
  102104. + audio_info(" .. OUT\n");
  102105. + return err;
  102106. +}
  102107. +
  102108. +/* pointer callback */
  102109. +static snd_pcm_uframes_t
  102110. +snd_bcm2835_pcm_pointer(struct snd_pcm_substream *substream)
  102111. +{
  102112. + struct snd_pcm_runtime *runtime = substream->runtime;
  102113. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  102114. +
  102115. + audio_info(" .. IN\n");
  102116. +
  102117. + audio_debug("pcm_pointer... (%d) hwptr=%d appl=%d pos=%d\n", 0,
  102118. + frames_to_bytes(runtime, runtime->status->hw_ptr),
  102119. + frames_to_bytes(runtime, runtime->control->appl_ptr),
  102120. + alsa_stream->pos);
  102121. +
  102122. + audio_info(" .. OUT\n");
  102123. + return snd_pcm_indirect_playback_pointer(substream,
  102124. + &alsa_stream->pcm_indirect,
  102125. + alsa_stream->pos);
  102126. +}
  102127. +
  102128. +static int snd_bcm2835_pcm_lib_ioctl(struct snd_pcm_substream *substream,
  102129. + unsigned int cmd, void *arg)
  102130. +{
  102131. + int ret = snd_pcm_lib_ioctl(substream, cmd, arg);
  102132. + audio_info(" .. substream=%p, cmd=%d, arg=%p (%x) ret=%d\n", substream,
  102133. + cmd, arg, arg ? *(unsigned *)arg : 0, ret);
  102134. + return ret;
  102135. +}
  102136. +
  102137. +/* operators */
  102138. +static struct snd_pcm_ops snd_bcm2835_playback_ops = {
  102139. + .open = snd_bcm2835_playback_open,
  102140. + .close = snd_bcm2835_playback_close,
  102141. + .ioctl = snd_bcm2835_pcm_lib_ioctl,
  102142. + .hw_params = snd_bcm2835_pcm_hw_params,
  102143. + .hw_free = snd_bcm2835_pcm_hw_free,
  102144. + .prepare = snd_bcm2835_pcm_prepare,
  102145. + .trigger = snd_bcm2835_pcm_trigger,
  102146. + .pointer = snd_bcm2835_pcm_pointer,
  102147. + .ack = snd_bcm2835_pcm_ack,
  102148. +};
  102149. +
  102150. +static struct snd_pcm_ops snd_bcm2835_playback_spdif_ops = {
  102151. + .open = snd_bcm2835_playback_spdif_open,
  102152. + .close = snd_bcm2835_playback_close,
  102153. + .ioctl = snd_bcm2835_pcm_lib_ioctl,
  102154. + .hw_params = snd_bcm2835_pcm_hw_params,
  102155. + .hw_free = snd_bcm2835_pcm_hw_free,
  102156. + .prepare = snd_bcm2835_pcm_prepare,
  102157. + .trigger = snd_bcm2835_pcm_trigger,
  102158. + .pointer = snd_bcm2835_pcm_pointer,
  102159. + .ack = snd_bcm2835_pcm_ack,
  102160. +};
  102161. +
  102162. +/* create a pcm device */
  102163. +int snd_bcm2835_new_pcm(bcm2835_chip_t * chip)
  102164. +{
  102165. + struct snd_pcm *pcm;
  102166. + int err;
  102167. +
  102168. + audio_info(" .. IN\n");
  102169. + err =
  102170. + snd_pcm_new(chip->card, "bcm2835 ALSA", 0, MAX_SUBSTREAMS, 0, &pcm);
  102171. + if (err < 0)
  102172. + return err;
  102173. + pcm->private_data = chip;
  102174. + strcpy(pcm->name, "bcm2835 ALSA");
  102175. + chip->pcm = pcm;
  102176. + chip->dest = AUDIO_DEST_AUTO;
  102177. + chip->volume = alsa2chip(0);
  102178. + chip->mute = CTRL_VOL_UNMUTE; /*disable mute on startup */
  102179. + /* set operators */
  102180. + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  102181. + &snd_bcm2835_playback_ops);
  102182. +
  102183. + /* pre-allocation of buffers */
  102184. + /* NOTE: this may fail */
  102185. + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
  102186. + snd_dma_continuous_data
  102187. + (GFP_KERNEL), 64 * 1024,
  102188. + 64 * 1024);
  102189. +
  102190. + audio_info(" .. OUT\n");
  102191. +
  102192. + return 0;
  102193. +}
  102194. +
  102195. +int snd_bcm2835_new_spdif_pcm(bcm2835_chip_t * chip)
  102196. +{
  102197. + struct snd_pcm *pcm;
  102198. + int err;
  102199. +
  102200. + err = snd_pcm_new(chip->card, "bcm2835 ALSA", 1, 1, 0, &pcm);
  102201. + if (err < 0)
  102202. + return err;
  102203. +
  102204. + pcm->private_data = chip;
  102205. + strcpy(pcm->name, "bcm2835 IEC958/HDMI");
  102206. + chip->pcm_spdif = pcm;
  102207. + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  102208. + &snd_bcm2835_playback_spdif_ops);
  102209. +
  102210. + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
  102211. + snd_dma_continuous_data (GFP_KERNEL),
  102212. + 64 * 1024, 64 * 1024);
  102213. +
  102214. + return 0;
  102215. +}
  102216. diff -Nur linux-3.15.4/sound/arm/bcm2835-vchiq.c linux-rpi/sound/arm/bcm2835-vchiq.c
  102217. --- linux-3.15.4/sound/arm/bcm2835-vchiq.c 1970-01-01 01:00:00.000000000 +0100
  102218. +++ linux-rpi/sound/arm/bcm2835-vchiq.c 2014-07-07 10:46:02.000000000 +0200
  102219. @@ -0,0 +1,879 @@
  102220. +/*****************************************************************************
  102221. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  102222. +*
  102223. +* Unless you and Broadcom execute a separate written software license
  102224. +* agreement governing use of this software, this software is licensed to you
  102225. +* under the terms of the GNU General Public License version 2, available at
  102226. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  102227. +*
  102228. +* Notwithstanding the above, under no circumstances may you combine this
  102229. +* software in any way with any other Broadcom software provided under a
  102230. +* license other than the GPL, without Broadcom's express prior written
  102231. +* consent.
  102232. +*****************************************************************************/
  102233. +
  102234. +#include <linux/device.h>
  102235. +#include <sound/core.h>
  102236. +#include <sound/initval.h>
  102237. +#include <sound/pcm.h>
  102238. +#include <linux/io.h>
  102239. +#include <linux/interrupt.h>
  102240. +#include <linux/fs.h>
  102241. +#include <linux/file.h>
  102242. +#include <linux/mm.h>
  102243. +#include <linux/syscalls.h>
  102244. +#include <asm/uaccess.h>
  102245. +#include <linux/slab.h>
  102246. +#include <linux/delay.h>
  102247. +#include <linux/atomic.h>
  102248. +#include <linux/module.h>
  102249. +#include <linux/completion.h>
  102250. +
  102251. +#include "bcm2835.h"
  102252. +
  102253. +/* ---- Include Files -------------------------------------------------------- */
  102254. +
  102255. +#include "interface/vchi/vchi.h"
  102256. +#include "vc_vchi_audioserv_defs.h"
  102257. +
  102258. +/* ---- Private Constants and Types ------------------------------------------ */
  102259. +
  102260. +#define BCM2835_AUDIO_STOP 0
  102261. +#define BCM2835_AUDIO_START 1
  102262. +#define BCM2835_AUDIO_WRITE 2
  102263. +
  102264. +/* Logging macros (for remapping to other logging mechanisms, i.e., printf) */
  102265. +#ifdef AUDIO_DEBUG_ENABLE
  102266. + #define LOG_ERR( fmt, arg... ) pr_err( "%s:%d " fmt, __func__, __LINE__, ##arg)
  102267. + #define LOG_WARN( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  102268. + #define LOG_INFO( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  102269. + #define LOG_DBG( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  102270. +#else
  102271. + #define LOG_ERR( fmt, arg... ) pr_err( "%s:%d " fmt, __func__, __LINE__, ##arg)
  102272. + #define LOG_WARN( fmt, arg... )
  102273. + #define LOG_INFO( fmt, arg... )
  102274. + #define LOG_DBG( fmt, arg... )
  102275. +#endif
  102276. +
  102277. +typedef struct opaque_AUDIO_INSTANCE_T {
  102278. + uint32_t num_connections;
  102279. + VCHI_SERVICE_HANDLE_T vchi_handle[VCHI_MAX_NUM_CONNECTIONS];
  102280. + struct completion msg_avail_comp;
  102281. + struct mutex vchi_mutex;
  102282. + bcm2835_alsa_stream_t *alsa_stream;
  102283. + int32_t result;
  102284. + short peer_version;
  102285. +} AUDIO_INSTANCE_T;
  102286. +
  102287. +bool force_bulk = false;
  102288. +
  102289. +/* ---- Private Variables ---------------------------------------------------- */
  102290. +
  102291. +/* ---- Private Function Prototypes ------------------------------------------ */
  102292. +
  102293. +/* ---- Private Functions ---------------------------------------------------- */
  102294. +
  102295. +static int bcm2835_audio_stop_worker(bcm2835_alsa_stream_t * alsa_stream);
  102296. +static int bcm2835_audio_start_worker(bcm2835_alsa_stream_t * alsa_stream);
  102297. +static int bcm2835_audio_write_worker(bcm2835_alsa_stream_t *alsa_stream,
  102298. + uint32_t count, void *src);
  102299. +
  102300. +typedef struct {
  102301. + struct work_struct my_work;
  102302. + bcm2835_alsa_stream_t *alsa_stream;
  102303. + int cmd;
  102304. + void *src;
  102305. + uint32_t count;
  102306. +} my_work_t;
  102307. +
  102308. +static void my_wq_function(struct work_struct *work)
  102309. +{
  102310. + my_work_t *w = (my_work_t *) work;
  102311. + int ret = -9;
  102312. + LOG_DBG(" .. IN %p:%d\n", w->alsa_stream, w->cmd);
  102313. + switch (w->cmd) {
  102314. + case BCM2835_AUDIO_START:
  102315. + ret = bcm2835_audio_start_worker(w->alsa_stream);
  102316. + break;
  102317. + case BCM2835_AUDIO_STOP:
  102318. + ret = bcm2835_audio_stop_worker(w->alsa_stream);
  102319. + break;
  102320. + case BCM2835_AUDIO_WRITE:
  102321. + ret = bcm2835_audio_write_worker(w->alsa_stream, w->count,
  102322. + w->src);
  102323. + break;
  102324. + default:
  102325. + LOG_ERR(" Unexpected work: %p:%d\n", w->alsa_stream, w->cmd);
  102326. + break;
  102327. + }
  102328. + kfree((void *)work);
  102329. + LOG_DBG(" .. OUT %d\n", ret);
  102330. +}
  102331. +
  102332. +int bcm2835_audio_start(bcm2835_alsa_stream_t * alsa_stream)
  102333. +{
  102334. + int ret = -1;
  102335. + LOG_DBG(" .. IN\n");
  102336. + if (alsa_stream->my_wq) {
  102337. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  102338. + /*--- Queue some work (item 1) ---*/
  102339. + if (work) {
  102340. + INIT_WORK((struct work_struct *)work, my_wq_function);
  102341. + work->alsa_stream = alsa_stream;
  102342. + work->cmd = BCM2835_AUDIO_START;
  102343. + if (queue_work
  102344. + (alsa_stream->my_wq, (struct work_struct *)work))
  102345. + ret = 0;
  102346. + } else
  102347. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  102348. + }
  102349. + LOG_DBG(" .. OUT %d\n", ret);
  102350. + return ret;
  102351. +}
  102352. +
  102353. +int bcm2835_audio_stop(bcm2835_alsa_stream_t * alsa_stream)
  102354. +{
  102355. + int ret = -1;
  102356. + LOG_DBG(" .. IN\n");
  102357. + if (alsa_stream->my_wq) {
  102358. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  102359. + /*--- Queue some work (item 1) ---*/
  102360. + if (work) {
  102361. + INIT_WORK((struct work_struct *)work, my_wq_function);
  102362. + work->alsa_stream = alsa_stream;
  102363. + work->cmd = BCM2835_AUDIO_STOP;
  102364. + if (queue_work
  102365. + (alsa_stream->my_wq, (struct work_struct *)work))
  102366. + ret = 0;
  102367. + } else
  102368. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  102369. + }
  102370. + LOG_DBG(" .. OUT %d\n", ret);
  102371. + return ret;
  102372. +}
  102373. +
  102374. +int bcm2835_audio_write(bcm2835_alsa_stream_t *alsa_stream,
  102375. + uint32_t count, void *src)
  102376. +{
  102377. + int ret = -1;
  102378. + LOG_DBG(" .. IN\n");
  102379. + if (alsa_stream->my_wq) {
  102380. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  102381. + /*--- Queue some work (item 1) ---*/
  102382. + if (work) {
  102383. + INIT_WORK((struct work_struct *)work, my_wq_function);
  102384. + work->alsa_stream = alsa_stream;
  102385. + work->cmd = BCM2835_AUDIO_WRITE;
  102386. + work->src = src;
  102387. + work->count = count;
  102388. + if (queue_work
  102389. + (alsa_stream->my_wq, (struct work_struct *)work))
  102390. + ret = 0;
  102391. + } else
  102392. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  102393. + }
  102394. + LOG_DBG(" .. OUT %d\n", ret);
  102395. + return ret;
  102396. +}
  102397. +
  102398. +void my_workqueue_init(bcm2835_alsa_stream_t * alsa_stream)
  102399. +{
  102400. + alsa_stream->my_wq = alloc_workqueue("my_queue", WQ_HIGHPRI, 1);
  102401. + return;
  102402. +}
  102403. +
  102404. +void my_workqueue_quit(bcm2835_alsa_stream_t * alsa_stream)
  102405. +{
  102406. + if (alsa_stream->my_wq) {
  102407. + flush_workqueue(alsa_stream->my_wq);
  102408. + destroy_workqueue(alsa_stream->my_wq);
  102409. + alsa_stream->my_wq = NULL;
  102410. + }
  102411. + return;
  102412. +}
  102413. +
  102414. +static void audio_vchi_callback(void *param,
  102415. + const VCHI_CALLBACK_REASON_T reason,
  102416. + void *msg_handle)
  102417. +{
  102418. + AUDIO_INSTANCE_T *instance = (AUDIO_INSTANCE_T *) param;
  102419. + int32_t status;
  102420. + int32_t msg_len;
  102421. + VC_AUDIO_MSG_T m;
  102422. + bcm2835_alsa_stream_t *alsa_stream = 0;
  102423. + LOG_DBG(" .. IN instance=%p, param=%p, reason=%d, handle=%p\n",
  102424. + instance, param, reason, msg_handle);
  102425. +
  102426. + if (!instance || reason != VCHI_CALLBACK_MSG_AVAILABLE) {
  102427. + return;
  102428. + }
  102429. + alsa_stream = instance->alsa_stream;
  102430. + status = vchi_msg_dequeue(instance->vchi_handle[0],
  102431. + &m, sizeof m, &msg_len, VCHI_FLAGS_NONE);
  102432. + if (m.type == VC_AUDIO_MSG_TYPE_RESULT) {
  102433. + LOG_DBG
  102434. + (" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_RESULT, success=%d\n",
  102435. + instance, m.u.result.success);
  102436. + instance->result = m.u.result.success;
  102437. + complete(&instance->msg_avail_comp);
  102438. + } else if (m.type == VC_AUDIO_MSG_TYPE_COMPLETE) {
  102439. + irq_handler_t callback = (irq_handler_t) m.u.complete.callback;
  102440. + LOG_DBG
  102441. + (" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_COMPLETE, complete=%d\n",
  102442. + instance, m.u.complete.count);
  102443. + if (alsa_stream && callback) {
  102444. + atomic_add(m.u.complete.count, &alsa_stream->retrieved);
  102445. + callback(0, alsa_stream);
  102446. + } else {
  102447. + LOG_DBG(" .. unexpected alsa_stream=%p, callback=%p\n",
  102448. + alsa_stream, callback);
  102449. + }
  102450. + } else {
  102451. + LOG_DBG(" .. unexpected m.type=%d\n", m.type);
  102452. + }
  102453. + LOG_DBG(" .. OUT\n");
  102454. +}
  102455. +
  102456. +static AUDIO_INSTANCE_T *vc_vchi_audio_init(VCHI_INSTANCE_T vchi_instance,
  102457. + VCHI_CONNECTION_T **
  102458. + vchi_connections,
  102459. + uint32_t num_connections)
  102460. +{
  102461. + uint32_t i;
  102462. + AUDIO_INSTANCE_T *instance;
  102463. + int status;
  102464. +
  102465. + LOG_DBG("%s: start", __func__);
  102466. +
  102467. + if (num_connections > VCHI_MAX_NUM_CONNECTIONS) {
  102468. + LOG_ERR("%s: unsupported number of connections %u (max=%u)\n",
  102469. + __func__, num_connections, VCHI_MAX_NUM_CONNECTIONS);
  102470. +
  102471. + return NULL;
  102472. + }
  102473. + /* Allocate memory for this instance */
  102474. + instance = kmalloc(sizeof(*instance), GFP_KERNEL);
  102475. +
  102476. + memset(instance, 0, sizeof(*instance));
  102477. + instance->num_connections = num_connections;
  102478. +
  102479. + /* Create a lock for exclusive, serialized VCHI connection access */
  102480. + mutex_init(&instance->vchi_mutex);
  102481. + /* Open the VCHI service connections */
  102482. + for (i = 0; i < num_connections; i++) {
  102483. + SERVICE_CREATION_T params = {
  102484. + VCHI_VERSION_EX(VC_AUDIOSERV_VER, VC_AUDIOSERV_MIN_VER),
  102485. + VC_AUDIO_SERVER_NAME, // 4cc service code
  102486. + vchi_connections[i], // passed in fn pointers
  102487. + 0, // rx fifo size (unused)
  102488. + 0, // tx fifo size (unused)
  102489. + audio_vchi_callback, // service callback
  102490. + instance, // service callback parameter
  102491. + 1, //TODO: remove VCOS_FALSE, // unaligned bulk recieves
  102492. + 1, //TODO: remove VCOS_FALSE, // unaligned bulk transmits
  102493. + 0 // want crc check on bulk transfers
  102494. + };
  102495. +
  102496. + status = vchi_service_open(vchi_instance, &params,
  102497. + &instance->vchi_handle[i]);
  102498. + if (status) {
  102499. + LOG_ERR
  102500. + ("%s: failed to open VCHI service connection (status=%d)\n",
  102501. + __func__, status);
  102502. +
  102503. + goto err_close_services;
  102504. + }
  102505. + /* Finished with the service for now */
  102506. + vchi_service_release(instance->vchi_handle[i]);
  102507. + }
  102508. +
  102509. + return instance;
  102510. +
  102511. +err_close_services:
  102512. + for (i = 0; i < instance->num_connections; i++) {
  102513. + vchi_service_close(instance->vchi_handle[i]);
  102514. + }
  102515. +
  102516. + kfree(instance);
  102517. +
  102518. + return NULL;
  102519. +}
  102520. +
  102521. +static int32_t vc_vchi_audio_deinit(AUDIO_INSTANCE_T * instance)
  102522. +{
  102523. + uint32_t i;
  102524. +
  102525. + LOG_DBG(" .. IN\n");
  102526. +
  102527. + if (instance == NULL) {
  102528. + LOG_ERR("%s: invalid handle %p\n", __func__, instance);
  102529. +
  102530. + return -1;
  102531. + }
  102532. +
  102533. + LOG_DBG(" .. about to lock (%d)\n", instance->num_connections);
  102534. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  102535. + {
  102536. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  102537. + return -EINTR;
  102538. + }
  102539. +
  102540. + /* Close all VCHI service connections */
  102541. + for (i = 0; i < instance->num_connections; i++) {
  102542. + int32_t success;
  102543. + LOG_DBG(" .. %i:closing %p\n", i, instance->vchi_handle[i]);
  102544. + vchi_service_use(instance->vchi_handle[i]);
  102545. +
  102546. + success = vchi_service_close(instance->vchi_handle[i]);
  102547. + if (success != 0) {
  102548. + LOG_ERR
  102549. + ("%s: failed to close VCHI service connection (status=%d)\n",
  102550. + __func__, success);
  102551. + }
  102552. + }
  102553. +
  102554. + mutex_unlock(&instance->vchi_mutex);
  102555. +
  102556. + kfree(instance);
  102557. +
  102558. + LOG_DBG(" .. OUT\n");
  102559. +
  102560. + return 0;
  102561. +}
  102562. +
  102563. +static int bcm2835_audio_open_connection(bcm2835_alsa_stream_t * alsa_stream)
  102564. +{
  102565. + static VCHI_INSTANCE_T vchi_instance;
  102566. + static VCHI_CONNECTION_T *vchi_connection;
  102567. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  102568. + int ret;
  102569. + LOG_DBG(" .. IN\n");
  102570. +
  102571. + LOG_INFO("%s: start", __func__);
  102572. + //BUG_ON(instance);
  102573. + if (instance) {
  102574. + LOG_ERR("%s: VCHI instance already open (%p)\n",
  102575. + __func__, instance);
  102576. + instance->alsa_stream = alsa_stream;
  102577. + alsa_stream->instance = instance;
  102578. + ret = 0; // xxx todo -1;
  102579. + goto err_free_mem;
  102580. + }
  102581. +
  102582. + /* Initialize and create a VCHI connection */
  102583. + ret = vchi_initialise(&vchi_instance);
  102584. + if (ret != 0) {
  102585. + LOG_ERR("%s: failed to initialise VCHI instance (ret=%d)\n",
  102586. + __func__, ret);
  102587. +
  102588. + ret = -EIO;
  102589. + goto err_free_mem;
  102590. + }
  102591. + ret = vchi_connect(NULL, 0, vchi_instance);
  102592. + if (ret != 0) {
  102593. + LOG_ERR("%s: failed to connect VCHI instance (ret=%d)\n",
  102594. + __func__, ret);
  102595. +
  102596. + ret = -EIO;
  102597. + goto err_free_mem;
  102598. + }
  102599. +
  102600. + /* Initialize an instance of the audio service */
  102601. + instance = vc_vchi_audio_init(vchi_instance, &vchi_connection, 1);
  102602. +
  102603. + if (instance == NULL /*|| audio_handle != instance */ ) {
  102604. + LOG_ERR("%s: failed to initialize audio service\n", __func__);
  102605. +
  102606. + ret = -EPERM;
  102607. + goto err_free_mem;
  102608. + }
  102609. +
  102610. + instance->alsa_stream = alsa_stream;
  102611. + alsa_stream->instance = instance;
  102612. +
  102613. + LOG_DBG(" success !\n");
  102614. +err_free_mem:
  102615. + LOG_DBG(" .. OUT\n");
  102616. +
  102617. + return ret;
  102618. +}
  102619. +
  102620. +int bcm2835_audio_open(bcm2835_alsa_stream_t * alsa_stream)
  102621. +{
  102622. + AUDIO_INSTANCE_T *instance;
  102623. + VC_AUDIO_MSG_T m;
  102624. + int32_t success;
  102625. + int ret;
  102626. + LOG_DBG(" .. IN\n");
  102627. +
  102628. + my_workqueue_init(alsa_stream);
  102629. +
  102630. + ret = bcm2835_audio_open_connection(alsa_stream);
  102631. + if (ret != 0) {
  102632. + ret = -1;
  102633. + goto exit;
  102634. + }
  102635. + instance = alsa_stream->instance;
  102636. +
  102637. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  102638. + {
  102639. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  102640. + return -EINTR;
  102641. + }
  102642. + vchi_service_use(instance->vchi_handle[0]);
  102643. +
  102644. + m.type = VC_AUDIO_MSG_TYPE_OPEN;
  102645. +
  102646. + /* Send the message to the videocore */
  102647. + success = vchi_msg_queue(instance->vchi_handle[0],
  102648. + &m, sizeof m,
  102649. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  102650. +
  102651. + if (success != 0) {
  102652. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  102653. + __func__, success);
  102654. +
  102655. + ret = -1;
  102656. + goto unlock;
  102657. + }
  102658. +
  102659. + ret = 0;
  102660. +
  102661. +unlock:
  102662. + vchi_service_release(instance->vchi_handle[0]);
  102663. + mutex_unlock(&instance->vchi_mutex);
  102664. +exit:
  102665. + LOG_DBG(" .. OUT\n");
  102666. + return ret;
  102667. +}
  102668. +
  102669. +static int bcm2835_audio_set_ctls_chan(bcm2835_alsa_stream_t * alsa_stream,
  102670. + bcm2835_chip_t * chip)
  102671. +{
  102672. + VC_AUDIO_MSG_T m;
  102673. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  102674. + int32_t success;
  102675. + int ret;
  102676. + LOG_DBG(" .. IN\n");
  102677. +
  102678. + LOG_INFO
  102679. + (" Setting ALSA dest(%d), volume(%d)\n", chip->dest, chip->volume);
  102680. +
  102681. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  102682. + {
  102683. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  102684. + return -EINTR;
  102685. + }
  102686. + vchi_service_use(instance->vchi_handle[0]);
  102687. +
  102688. + instance->result = -1;
  102689. +
  102690. + m.type = VC_AUDIO_MSG_TYPE_CONTROL;
  102691. + m.u.control.dest = chip->dest;
  102692. + m.u.control.volume = chip->volume;
  102693. +
  102694. + /* Create the message available completion */
  102695. + init_completion(&instance->msg_avail_comp);
  102696. +
  102697. + /* Send the message to the videocore */
  102698. + success = vchi_msg_queue(instance->vchi_handle[0],
  102699. + &m, sizeof m,
  102700. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  102701. +
  102702. + if (success != 0) {
  102703. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  102704. + __func__, success);
  102705. +
  102706. + ret = -1;
  102707. + goto unlock;
  102708. + }
  102709. +
  102710. + /* We are expecting a reply from the videocore */
  102711. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  102712. + if (ret) {
  102713. + LOG_ERR("%s: failed on waiting for event (status=%d)\n",
  102714. + __func__, success);
  102715. + goto unlock;
  102716. + }
  102717. +
  102718. + if (instance->result != 0) {
  102719. + LOG_ERR("%s: result=%d\n", __func__, instance->result);
  102720. +
  102721. + ret = -1;
  102722. + goto unlock;
  102723. + }
  102724. +
  102725. + ret = 0;
  102726. +
  102727. +unlock:
  102728. + vchi_service_release(instance->vchi_handle[0]);
  102729. + mutex_unlock(&instance->vchi_mutex);
  102730. +
  102731. + LOG_DBG(" .. OUT\n");
  102732. + return ret;
  102733. +}
  102734. +
  102735. +int bcm2835_audio_set_ctls(bcm2835_chip_t * chip)
  102736. +{
  102737. + int i;
  102738. + int ret = 0;
  102739. + LOG_DBG(" .. IN\n");
  102740. +
  102741. + /* change ctls for all substreams */
  102742. + for (i = 0; i < MAX_SUBSTREAMS; i++) {
  102743. + if (chip->avail_substreams & (1 << i)) {
  102744. + if (!chip->alsa_stream[i])
  102745. + {
  102746. + LOG_DBG(" No ALSA stream available?! %i:%p (%x)\n", i, chip->alsa_stream[i], chip->avail_substreams);
  102747. + ret = 0;
  102748. + }
  102749. + else if (bcm2835_audio_set_ctls_chan /* returns 0 on success */
  102750. + (chip->alsa_stream[i], chip) != 0)
  102751. + {
  102752. + LOG_DBG("Couldn't set the controls for stream %d\n", i);
  102753. + ret = -1;
  102754. + }
  102755. + else LOG_DBG(" Controls set for stream %d\n", i);
  102756. + }
  102757. + }
  102758. + LOG_DBG(" .. OUT ret=%d\n", ret);
  102759. + return ret;
  102760. +}
  102761. +
  102762. +int bcm2835_audio_set_params(bcm2835_alsa_stream_t * alsa_stream,
  102763. + uint32_t channels, uint32_t samplerate,
  102764. + uint32_t bps)
  102765. +{
  102766. + VC_AUDIO_MSG_T m;
  102767. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  102768. + int32_t success;
  102769. + int ret;
  102770. + LOG_DBG(" .. IN\n");
  102771. +
  102772. + LOG_INFO
  102773. + (" Setting ALSA channels(%d), samplerate(%d), bits-per-sample(%d)\n",
  102774. + channels, samplerate, bps);
  102775. +
  102776. + /* resend ctls - alsa_stream may not have been open when first send */
  102777. + ret = bcm2835_audio_set_ctls_chan(alsa_stream, alsa_stream->chip);
  102778. + if (ret != 0) {
  102779. + LOG_ERR(" Alsa controls not supported\n");
  102780. + return -EINVAL;
  102781. + }
  102782. +
  102783. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  102784. + {
  102785. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  102786. + return -EINTR;
  102787. + }
  102788. + vchi_service_use(instance->vchi_handle[0]);
  102789. +
  102790. + instance->result = -1;
  102791. +
  102792. + m.type = VC_AUDIO_MSG_TYPE_CONFIG;
  102793. + m.u.config.channels = channels;
  102794. + m.u.config.samplerate = samplerate;
  102795. + m.u.config.bps = bps;
  102796. +
  102797. + /* Create the message available completion */
  102798. + init_completion(&instance->msg_avail_comp);
  102799. +
  102800. + /* Send the message to the videocore */
  102801. + success = vchi_msg_queue(instance->vchi_handle[0],
  102802. + &m, sizeof m,
  102803. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  102804. +
  102805. + if (success != 0) {
  102806. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  102807. + __func__, success);
  102808. +
  102809. + ret = -1;
  102810. + goto unlock;
  102811. + }
  102812. +
  102813. + /* We are expecting a reply from the videocore */
  102814. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  102815. + if (ret) {
  102816. + LOG_ERR("%s: failed on waiting for event (status=%d)\n",
  102817. + __func__, success);
  102818. + goto unlock;
  102819. + }
  102820. +
  102821. + if (instance->result != 0) {
  102822. + LOG_ERR("%s: result=%d", __func__, instance->result);
  102823. +
  102824. + ret = -1;
  102825. + goto unlock;
  102826. + }
  102827. +
  102828. + ret = 0;
  102829. +
  102830. +unlock:
  102831. + vchi_service_release(instance->vchi_handle[0]);
  102832. + mutex_unlock(&instance->vchi_mutex);
  102833. +
  102834. + LOG_DBG(" .. OUT\n");
  102835. + return ret;
  102836. +}
  102837. +
  102838. +int bcm2835_audio_setup(bcm2835_alsa_stream_t * alsa_stream)
  102839. +{
  102840. + LOG_DBG(" .. IN\n");
  102841. +
  102842. + LOG_DBG(" .. OUT\n");
  102843. +
  102844. + return 0;
  102845. +}
  102846. +
  102847. +static int bcm2835_audio_start_worker(bcm2835_alsa_stream_t * alsa_stream)
  102848. +{
  102849. + VC_AUDIO_MSG_T m;
  102850. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  102851. + int32_t success;
  102852. + int ret;
  102853. + LOG_DBG(" .. IN\n");
  102854. +
  102855. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  102856. + {
  102857. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  102858. + return -EINTR;
  102859. + }
  102860. + vchi_service_use(instance->vchi_handle[0]);
  102861. +
  102862. + m.type = VC_AUDIO_MSG_TYPE_START;
  102863. +
  102864. + /* Send the message to the videocore */
  102865. + success = vchi_msg_queue(instance->vchi_handle[0],
  102866. + &m, sizeof m,
  102867. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  102868. +
  102869. + if (success != 0) {
  102870. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  102871. + __func__, success);
  102872. +
  102873. + ret = -1;
  102874. + goto unlock;
  102875. + }
  102876. +
  102877. + ret = 0;
  102878. +
  102879. +unlock:
  102880. + vchi_service_release(instance->vchi_handle[0]);
  102881. + mutex_unlock(&instance->vchi_mutex);
  102882. + LOG_DBG(" .. OUT\n");
  102883. + return ret;
  102884. +}
  102885. +
  102886. +static int bcm2835_audio_stop_worker(bcm2835_alsa_stream_t * alsa_stream)
  102887. +{
  102888. + VC_AUDIO_MSG_T m;
  102889. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  102890. + int32_t success;
  102891. + int ret;
  102892. + LOG_DBG(" .. IN\n");
  102893. +
  102894. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  102895. + {
  102896. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  102897. + return -EINTR;
  102898. + }
  102899. + vchi_service_use(instance->vchi_handle[0]);
  102900. +
  102901. + m.type = VC_AUDIO_MSG_TYPE_STOP;
  102902. + m.u.stop.draining = alsa_stream->draining;
  102903. +
  102904. + /* Send the message to the videocore */
  102905. + success = vchi_msg_queue(instance->vchi_handle[0],
  102906. + &m, sizeof m,
  102907. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  102908. +
  102909. + if (success != 0) {
  102910. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  102911. + __func__, success);
  102912. +
  102913. + ret = -1;
  102914. + goto unlock;
  102915. + }
  102916. +
  102917. + ret = 0;
  102918. +
  102919. +unlock:
  102920. + vchi_service_release(instance->vchi_handle[0]);
  102921. + mutex_unlock(&instance->vchi_mutex);
  102922. + LOG_DBG(" .. OUT\n");
  102923. + return ret;
  102924. +}
  102925. +
  102926. +int bcm2835_audio_close(bcm2835_alsa_stream_t * alsa_stream)
  102927. +{
  102928. + VC_AUDIO_MSG_T m;
  102929. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  102930. + int32_t success;
  102931. + int ret;
  102932. + LOG_DBG(" .. IN\n");
  102933. +
  102934. + my_workqueue_quit(alsa_stream);
  102935. +
  102936. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  102937. + {
  102938. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  102939. + return -EINTR;
  102940. + }
  102941. + vchi_service_use(instance->vchi_handle[0]);
  102942. +
  102943. + m.type = VC_AUDIO_MSG_TYPE_CLOSE;
  102944. +
  102945. + /* Create the message available completion */
  102946. + init_completion(&instance->msg_avail_comp);
  102947. +
  102948. + /* Send the message to the videocore */
  102949. + success = vchi_msg_queue(instance->vchi_handle[0],
  102950. + &m, sizeof m,
  102951. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  102952. +
  102953. + if (success != 0) {
  102954. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  102955. + __func__, success);
  102956. + ret = -1;
  102957. + goto unlock;
  102958. + }
  102959. +
  102960. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  102961. + if (ret) {
  102962. + LOG_ERR("%s: failed on waiting for event (status=%d)",
  102963. + __func__, success);
  102964. + goto unlock;
  102965. + }
  102966. + if (instance->result != 0) {
  102967. + LOG_ERR("%s: failed result (status=%d)",
  102968. + __func__, instance->result);
  102969. +
  102970. + ret = -1;
  102971. + goto unlock;
  102972. + }
  102973. +
  102974. + ret = 0;
  102975. +
  102976. +unlock:
  102977. + vchi_service_release(instance->vchi_handle[0]);
  102978. + mutex_unlock(&instance->vchi_mutex);
  102979. +
  102980. + /* Stop the audio service */
  102981. + if (instance) {
  102982. + vc_vchi_audio_deinit(instance);
  102983. + alsa_stream->instance = NULL;
  102984. + }
  102985. + LOG_DBG(" .. OUT\n");
  102986. + return ret;
  102987. +}
  102988. +
  102989. +int bcm2835_audio_write_worker(bcm2835_alsa_stream_t *alsa_stream,
  102990. + uint32_t count, void *src)
  102991. +{
  102992. + VC_AUDIO_MSG_T m;
  102993. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  102994. + int32_t success;
  102995. + int ret;
  102996. +
  102997. + LOG_DBG(" .. IN\n");
  102998. +
  102999. + LOG_INFO(" Writing %d bytes from %p\n", count, src);
  103000. +
  103001. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  103002. + {
  103003. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  103004. + return -EINTR;
  103005. + }
  103006. + vchi_service_use(instance->vchi_handle[0]);
  103007. +
  103008. + if ( instance->peer_version==0 && vchi_get_peer_version(instance->vchi_handle[0], &instance->peer_version) == 0 ) {
  103009. + LOG_DBG("%s: client version %d connected\n", __func__, instance->peer_version);
  103010. + }
  103011. + m.type = VC_AUDIO_MSG_TYPE_WRITE;
  103012. + m.u.write.count = count;
  103013. + // old version uses bulk, new version uses control
  103014. + m.u.write.max_packet = instance->peer_version < 2 || force_bulk ? 0:4000;
  103015. + m.u.write.callback = alsa_stream->fifo_irq_handler;
  103016. + m.u.write.cookie = alsa_stream;
  103017. + m.u.write.silence = src == NULL;
  103018. +
  103019. + /* Send the message to the videocore */
  103020. + success = vchi_msg_queue(instance->vchi_handle[0],
  103021. + &m, sizeof m,
  103022. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  103023. +
  103024. + if (success != 0) {
  103025. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  103026. + __func__, success);
  103027. +
  103028. + ret = -1;
  103029. + goto unlock;
  103030. + }
  103031. + if (!m.u.write.silence) {
  103032. + if (m.u.write.max_packet == 0) {
  103033. + /* Send the message to the videocore */
  103034. + success = vchi_bulk_queue_transmit(instance->vchi_handle[0],
  103035. + src, count,
  103036. + 0 *
  103037. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED
  103038. + +
  103039. + 1 *
  103040. + VCHI_FLAGS_BLOCK_UNTIL_DATA_READ,
  103041. + NULL);
  103042. + } else {
  103043. + while (count > 0) {
  103044. + int bytes = min((int)m.u.write.max_packet, (int)count);
  103045. + success = vchi_msg_queue(instance->vchi_handle[0],
  103046. + src, bytes,
  103047. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  103048. + src = (char *)src + bytes;
  103049. + count -= bytes;
  103050. + }
  103051. + }
  103052. + if (success != 0) {
  103053. + LOG_ERR
  103054. + ("%s: failed on vchi_bulk_queue_transmit (status=%d)",
  103055. + __func__, success);
  103056. +
  103057. + ret = -1;
  103058. + goto unlock;
  103059. + }
  103060. + }
  103061. + ret = 0;
  103062. +
  103063. +unlock:
  103064. + vchi_service_release(instance->vchi_handle[0]);
  103065. + mutex_unlock(&instance->vchi_mutex);
  103066. + LOG_DBG(" .. OUT\n");
  103067. + return ret;
  103068. +}
  103069. +
  103070. +/**
  103071. + * Returns all buffers from arm->vc
  103072. + */
  103073. +void bcm2835_audio_flush_buffers(bcm2835_alsa_stream_t * alsa_stream)
  103074. +{
  103075. + LOG_DBG(" .. IN\n");
  103076. + LOG_DBG(" .. OUT\n");
  103077. + return;
  103078. +}
  103079. +
  103080. +/**
  103081. + * Forces VC to flush(drop) its filled playback buffers and
  103082. + * return them the us. (VC->ARM)
  103083. + */
  103084. +void bcm2835_audio_flush_playback_buffers(bcm2835_alsa_stream_t * alsa_stream)
  103085. +{
  103086. + LOG_DBG(" .. IN\n");
  103087. + LOG_DBG(" .. OUT\n");
  103088. +}
  103089. +
  103090. +uint32_t bcm2835_audio_retrieve_buffers(bcm2835_alsa_stream_t * alsa_stream)
  103091. +{
  103092. + uint32_t count = atomic_read(&alsa_stream->retrieved);
  103093. + atomic_sub(count, &alsa_stream->retrieved);
  103094. + return count;
  103095. +}
  103096. +
  103097. +module_param(force_bulk, bool, 0444);
  103098. +MODULE_PARM_DESC(force_bulk, "Force use of vchiq bulk for audio");
  103099. diff -Nur linux-3.15.4/sound/arm/Kconfig linux-rpi/sound/arm/Kconfig
  103100. --- linux-3.15.4/sound/arm/Kconfig 2014-07-07 03:59:25.000000000 +0200
  103101. +++ linux-rpi/sound/arm/Kconfig 2014-04-13 17:33:26.000000000 +0200
  103102. @@ -39,5 +39,12 @@
  103103. Say Y or M if you want to support any AC97 codec attached to
  103104. the PXA2xx AC97 interface.
  103105. +config SND_BCM2835
  103106. + tristate "BCM2835 ALSA driver"
  103107. + depends on ARCH_BCM2708 && BCM2708_VCHIQ && SND
  103108. + select SND_PCM
  103109. + help
  103110. + Say Y or M if you want to support BCM2835 Alsa pcm card driver
  103111. +
  103112. endif # SND_ARM
  103113. diff -Nur linux-3.15.4/sound/arm/Makefile linux-rpi/sound/arm/Makefile
  103114. --- linux-3.15.4/sound/arm/Makefile 2014-07-07 03:59:25.000000000 +0200
  103115. +++ linux-rpi/sound/arm/Makefile 2014-07-07 10:46:02.000000000 +0200
  103116. @@ -14,3 +14,8 @@
  103117. obj-$(CONFIG_SND_PXA2XX_AC97) += snd-pxa2xx-ac97.o
  103118. snd-pxa2xx-ac97-objs := pxa2xx-ac97.o
  103119. +
  103120. +obj-$(CONFIG_SND_BCM2835) += snd-bcm2835.o
  103121. +snd-bcm2835-objs := bcm2835.o bcm2835-ctl.o bcm2835-pcm.o bcm2835-vchiq.o
  103122. +
  103123. +ccflags-y += -Idrivers/misc/vc04_services -Idrivers/misc/vc04_services/interface/vcos/linuxkernel -D__VCCOREVER__=0x04000000
  103124. diff -Nur linux-3.15.4/sound/arm/vc_vchi_audioserv_defs.h linux-rpi/sound/arm/vc_vchi_audioserv_defs.h
  103125. --- linux-3.15.4/sound/arm/vc_vchi_audioserv_defs.h 1970-01-01 01:00:00.000000000 +0100
  103126. +++ linux-rpi/sound/arm/vc_vchi_audioserv_defs.h 2014-04-13 17:33:26.000000000 +0200
  103127. @@ -0,0 +1,116 @@
  103128. +/*****************************************************************************
  103129. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  103130. +*
  103131. +* Unless you and Broadcom execute a separate written software license
  103132. +* agreement governing use of this software, this software is licensed to you
  103133. +* under the terms of the GNU General Public License version 2, available at
  103134. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  103135. +*
  103136. +* Notwithstanding the above, under no circumstances may you combine this
  103137. +* software in any way with any other Broadcom software provided under a
  103138. +* license other than the GPL, without Broadcom's express prior written
  103139. +* consent.
  103140. +*****************************************************************************/
  103141. +
  103142. +#ifndef _VC_AUDIO_DEFS_H_
  103143. +#define _VC_AUDIO_DEFS_H_
  103144. +
  103145. +#define VC_AUDIOSERV_MIN_VER 1
  103146. +#define VC_AUDIOSERV_VER 2
  103147. +
  103148. +// FourCC code used for VCHI connection
  103149. +#define VC_AUDIO_SERVER_NAME MAKE_FOURCC("AUDS")
  103150. +
  103151. +// Maximum message length
  103152. +#define VC_AUDIO_MAX_MSG_LEN (sizeof( VC_AUDIO_MSG_T ))
  103153. +
  103154. +// List of screens that are currently supported
  103155. +// All message types supported for HOST->VC direction
  103156. +typedef enum {
  103157. + VC_AUDIO_MSG_TYPE_RESULT, // Generic result
  103158. + VC_AUDIO_MSG_TYPE_COMPLETE, // Generic result
  103159. + VC_AUDIO_MSG_TYPE_CONFIG, // Configure audio
  103160. + VC_AUDIO_MSG_TYPE_CONTROL, // Configure audio
  103161. + VC_AUDIO_MSG_TYPE_OPEN, // Configure audio
  103162. + VC_AUDIO_MSG_TYPE_CLOSE, // Configure audio
  103163. + VC_AUDIO_MSG_TYPE_START, // Configure audio
  103164. + VC_AUDIO_MSG_TYPE_STOP, // Configure audio
  103165. + VC_AUDIO_MSG_TYPE_WRITE, // Configure audio
  103166. + VC_AUDIO_MSG_TYPE_MAX
  103167. +} VC_AUDIO_MSG_TYPE;
  103168. +
  103169. +// configure the audio
  103170. +typedef struct {
  103171. + uint32_t channels;
  103172. + uint32_t samplerate;
  103173. + uint32_t bps;
  103174. +
  103175. +} VC_AUDIO_CONFIG_T;
  103176. +
  103177. +typedef struct {
  103178. + uint32_t volume;
  103179. + uint32_t dest;
  103180. +
  103181. +} VC_AUDIO_CONTROL_T;
  103182. +
  103183. +// audio
  103184. +typedef struct {
  103185. + uint32_t dummy;
  103186. +
  103187. +} VC_AUDIO_OPEN_T;
  103188. +
  103189. +// audio
  103190. +typedef struct {
  103191. + uint32_t dummy;
  103192. +
  103193. +} VC_AUDIO_CLOSE_T;
  103194. +// audio
  103195. +typedef struct {
  103196. + uint32_t dummy;
  103197. +
  103198. +} VC_AUDIO_START_T;
  103199. +// audio
  103200. +typedef struct {
  103201. + uint32_t draining;
  103202. +
  103203. +} VC_AUDIO_STOP_T;
  103204. +
  103205. +// configure the write audio samples
  103206. +typedef struct {
  103207. + uint32_t count; // in bytes
  103208. + void *callback;
  103209. + void *cookie;
  103210. + uint16_t silence;
  103211. + uint16_t max_packet;
  103212. +} VC_AUDIO_WRITE_T;
  103213. +
  103214. +// Generic result for a request (VC->HOST)
  103215. +typedef struct {
  103216. + int32_t success; // Success value
  103217. +
  103218. +} VC_AUDIO_RESULT_T;
  103219. +
  103220. +// Generic result for a request (VC->HOST)
  103221. +typedef struct {
  103222. + int32_t count; // Success value
  103223. + void *callback;
  103224. + void *cookie;
  103225. +} VC_AUDIO_COMPLETE_T;
  103226. +
  103227. +// Message header for all messages in HOST->VC direction
  103228. +typedef struct {
  103229. + int32_t type; // Message type (VC_AUDIO_MSG_TYPE)
  103230. + union {
  103231. + VC_AUDIO_CONFIG_T config;
  103232. + VC_AUDIO_CONTROL_T control;
  103233. + VC_AUDIO_OPEN_T open;
  103234. + VC_AUDIO_CLOSE_T close;
  103235. + VC_AUDIO_START_T start;
  103236. + VC_AUDIO_STOP_T stop;
  103237. + VC_AUDIO_WRITE_T write;
  103238. + VC_AUDIO_RESULT_T result;
  103239. + VC_AUDIO_COMPLETE_T complete;
  103240. + } u;
  103241. +} VC_AUDIO_MSG_T;
  103242. +
  103243. +#endif // _VC_AUDIO_DEFS_H_
  103244. diff -Nur linux-3.15.4/sound/pci/hda/hda_intel.c linux-rpi/sound/pci/hda/hda_intel.c
  103245. --- linux-3.15.4/sound/pci/hda/hda_intel.c 2014-07-07 03:59:25.000000000 +0200
  103246. +++ linux-rpi/sound/pci/hda/hda_intel.c 2014-07-07 10:46:02.000000000 +0200
  103247. @@ -282,24 +282,6 @@
  103248. [AZX_DRIVER_GENERIC] = "HD-Audio Generic",
  103249. };
  103250. -
  103251. -/* Intel HSW/BDW display HDA controller Extended Mode registers.
  103252. - * EM4 (M value) and EM5 (N Value) are used to convert CDClk (Core Display
  103253. - * Clock) to 24MHz BCLK: BCLK = CDCLK * M / N
  103254. - * The values will be lost when the display power well is disabled.
  103255. - */
  103256. -#define ICH6_REG_EM4 0x100c
  103257. -#define ICH6_REG_EM5 0x1010
  103258. -
  103259. -struct hda_intel {
  103260. - struct azx chip;
  103261. -
  103262. - /* HSW/BDW display HDA controller to restore BCLK from CDCLK */
  103263. - unsigned int bclk_m;
  103264. - unsigned int bclk_n;
  103265. -};
  103266. -
  103267. -
  103268. #ifdef CONFIG_X86
  103269. static void __mark_pages_wc(struct azx *chip, struct snd_dma_buffer *dmab, bool on)
  103270. {
  103271. @@ -592,22 +574,6 @@
  103272. #define azx_del_card_list(chip) /* NOP */
  103273. #endif /* CONFIG_PM */
  103274. -static void haswell_save_bclk(struct azx *chip)
  103275. -{
  103276. - struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
  103277. -
  103278. - hda->bclk_m = azx_readw(chip, EM4);
  103279. - hda->bclk_n = azx_readw(chip, EM5);
  103280. -}
  103281. -
  103282. -static void haswell_restore_bclk(struct azx *chip)
  103283. -{
  103284. - struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
  103285. -
  103286. - azx_writew(chip, EM4, hda->bclk_m);
  103287. - azx_writew(chip, EM5, hda->bclk_n);
  103288. -}
  103289. -
  103290. #if defined(CONFIG_PM_SLEEP) || defined(SUPPORT_VGA_SWITCHEROO)
  103291. /*
  103292. * power management
  103293. @@ -634,13 +600,6 @@
  103294. free_irq(chip->irq, chip);
  103295. chip->irq = -1;
  103296. }
  103297. -
  103298. - /* Save BCLK M/N values before they become invalid in D3.
  103299. - * Will test if display power well can be released now.
  103300. - */
  103301. - if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
  103302. - haswell_save_bclk(chip);
  103303. -
  103304. if (chip->msi)
  103305. pci_disable_msi(chip->pci);
  103306. pci_disable_device(pci);
  103307. @@ -660,10 +619,8 @@
  103308. if (chip->disabled)
  103309. return 0;
  103310. - if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
  103311. + if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
  103312. hda_display_power(true);
  103313. - haswell_restore_bclk(chip);
  103314. - }
  103315. pci_set_power_state(pci, PCI_D0);
  103316. pci_restore_state(pci);
  103317. if (pci_enable_device(pci) < 0) {
  103318. @@ -707,10 +664,8 @@
  103319. azx_stop_chip(chip);
  103320. azx_enter_link_reset(chip);
  103321. azx_clear_irq_pending(chip);
  103322. - if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
  103323. - haswell_save_bclk(chip);
  103324. + if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
  103325. hda_display_power(false);
  103326. - }
  103327. return 0;
  103328. }
  103329. @@ -728,10 +683,8 @@
  103330. if (!(chip->driver_caps & AZX_DCAPS_PM_RUNTIME))
  103331. return 0;
  103332. - if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
  103333. + if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
  103334. hda_display_power(true);
  103335. - haswell_restore_bclk(chip);
  103336. - }
  103337. /* Read STATESTS before controller reset */
  103338. status = azx_readw(chip, STATESTS);
  103339. @@ -924,8 +877,6 @@
  103340. static int azx_free(struct azx *chip)
  103341. {
  103342. struct pci_dev *pci = chip->pci;
  103343. - struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
  103344. -
  103345. int i;
  103346. if ((chip->driver_caps & AZX_DCAPS_PM_RUNTIME)
  103347. @@ -973,7 +924,7 @@
  103348. hda_display_power(false);
  103349. hda_i915_exit();
  103350. }
  103351. - kfree(hda);
  103352. + kfree(chip);
  103353. return 0;
  103354. }
  103355. @@ -1217,7 +1168,6 @@
  103356. static struct snd_device_ops ops = {
  103357. .dev_free = azx_dev_free,
  103358. };
  103359. - struct hda_intel *hda;
  103360. struct azx *chip;
  103361. int err;
  103362. @@ -1227,14 +1177,13 @@
  103363. if (err < 0)
  103364. return err;
  103365. - hda = kzalloc(sizeof(*hda), GFP_KERNEL);
  103366. - if (!hda) {
  103367. - dev_err(card->dev, "Cannot allocate hda\n");
  103368. + chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  103369. + if (!chip) {
  103370. + dev_err(card->dev, "Cannot allocate chip\n");
  103371. pci_disable_device(pci);
  103372. return -ENOMEM;
  103373. }
  103374. - chip = &hda->chip;
  103375. spin_lock_init(&chip->reg_lock);
  103376. mutex_init(&chip->open_mutex);
  103377. chip->card = card;
  103378. diff -Nur linux-3.15.4/sound/pci/hda/patch_hdmi.c linux-rpi/sound/pci/hda/patch_hdmi.c
  103379. --- linux-3.15.4/sound/pci/hda/patch_hdmi.c 2014-07-07 03:59:25.000000000 +0200
  103380. +++ linux-rpi/sound/pci/hda/patch_hdmi.c 2014-07-07 10:46:02.000000000 +0200
  103381. @@ -2208,7 +2208,7 @@
  103382. struct hdmi_spec *spec = codec->spec;
  103383. int pin_idx;
  103384. - codec->patch_ops.init(codec);
  103385. + generic_hdmi_init(codec);
  103386. snd_hda_codec_resume_amp(codec);
  103387. snd_hda_codec_resume_cache(codec);
  103388. diff -Nur linux-3.15.4/sound/pci/hda/patch_sigmatel.c linux-rpi/sound/pci/hda/patch_sigmatel.c
  103389. --- linux-3.15.4/sound/pci/hda/patch_sigmatel.c 2014-07-07 03:59:25.000000000 +0200
  103390. +++ linux-rpi/sound/pci/hda/patch_sigmatel.c 2014-07-07 10:46:02.000000000 +0200
  103391. @@ -122,12 +122,6 @@
  103392. };
  103393. enum {
  103394. - STAC_92HD95_HP_LED,
  103395. - STAC_92HD95_HP_BASS,
  103396. - STAC_92HD95_MODELS
  103397. -};
  103398. -
  103399. -enum {
  103400. STAC_925x_REF,
  103401. STAC_M1,
  103402. STAC_M1_2,
  103403. @@ -4134,48 +4128,6 @@
  103404. {} /* terminator */
  103405. };
  103406. -static void stac92hd95_fixup_hp_led(struct hda_codec *codec,
  103407. - const struct hda_fixup *fix, int action)
  103408. -{
  103409. - struct sigmatel_spec *spec = codec->spec;
  103410. -
  103411. - if (action != HDA_FIXUP_ACT_PRE_PROBE)
  103412. - return;
  103413. -
  103414. - if (find_mute_led_cfg(codec, spec->default_polarity))
  103415. - codec_dbg(codec, "mute LED gpio %d polarity %d\n",
  103416. - spec->gpio_led,
  103417. - spec->gpio_led_polarity);
  103418. -}
  103419. -
  103420. -static const struct hda_fixup stac92hd95_fixups[] = {
  103421. - [STAC_92HD95_HP_LED] = {
  103422. - .type = HDA_FIXUP_FUNC,
  103423. - .v.func = stac92hd95_fixup_hp_led,
  103424. - },
  103425. - [STAC_92HD95_HP_BASS] = {
  103426. - .type = HDA_FIXUP_VERBS,
  103427. - .v.verbs = (const struct hda_verb[]) {
  103428. - {0x1a, 0x795, 0x00}, /* HPF to 100Hz */
  103429. - {}
  103430. - },
  103431. - .chained = true,
  103432. - .chain_id = STAC_92HD95_HP_LED,
  103433. - },
  103434. -};
  103435. -
  103436. -static const struct snd_pci_quirk stac92hd95_fixup_tbl[] = {
  103437. - SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1911, "HP Spectre 13", STAC_92HD95_HP_BASS),
  103438. - {} /* terminator */
  103439. -};
  103440. -
  103441. -static const struct hda_model_fixup stac92hd95_models[] = {
  103442. - { .id = STAC_92HD95_HP_LED, .name = "hp-led" },
  103443. - { .id = STAC_92HD95_HP_BASS, .name = "hp-bass" },
  103444. - {}
  103445. -};
  103446. -
  103447. -
  103448. static int stac_parse_auto_config(struct hda_codec *codec)
  103449. {
  103450. struct sigmatel_spec *spec = codec->spec;
  103451. @@ -4628,16 +4580,10 @@
  103452. spec->gen.beep_nid = 0x19; /* digital beep */
  103453. spec->pwr_nids = stac92hd95_pwr_nids;
  103454. spec->num_pwrs = ARRAY_SIZE(stac92hd95_pwr_nids);
  103455. - spec->default_polarity = 0;
  103456. + spec->default_polarity = -1; /* no default cfg */
  103457. codec->patch_ops = stac_patch_ops;
  103458. - snd_hda_pick_fixup(codec, stac92hd95_models, stac92hd95_fixup_tbl,
  103459. - stac92hd95_fixups);
  103460. - snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
  103461. -
  103462. - stac_setup_gpio(codec);
  103463. -
  103464. err = stac_parse_auto_config(codec);
  103465. if (err < 0) {
  103466. stac_free(codec);
  103467. @@ -4646,8 +4592,6 @@
  103468. codec->proc_widget_hook = stac92hd_proc_hook;
  103469. - snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
  103470. -
  103471. return 0;
  103472. }
  103473. diff -Nur linux-3.15.4/sound/soc/bcm/bcm2708-i2s.c linux-rpi/sound/soc/bcm/bcm2708-i2s.c
  103474. --- linux-3.15.4/sound/soc/bcm/bcm2708-i2s.c 1970-01-01 01:00:00.000000000 +0100
  103475. +++ linux-rpi/sound/soc/bcm/bcm2708-i2s.c 2014-07-07 10:46:03.000000000 +0200
  103476. @@ -0,0 +1,946 @@
  103477. +/*
  103478. + * ALSA SoC I2S Audio Layer for Broadcom BCM2708 SoC
  103479. + *
  103480. + * Author: Florian Meier <florian.meier@koalo.de>
  103481. + * Copyright 2013
  103482. + *
  103483. + * Based on
  103484. + * Raspberry Pi PCM I2S ALSA Driver
  103485. + * Copyright (c) by Phil Poole 2013
  103486. + *
  103487. + * ALSA SoC I2S (McBSP) Audio Layer for TI DAVINCI processor
  103488. + * Vladimir Barinov, <vbarinov@embeddedalley.com>
  103489. + * Copyright (C) 2007 MontaVista Software, Inc., <source@mvista.com>
  103490. + *
  103491. + * OMAP ALSA SoC DAI driver using McBSP port
  103492. + * Copyright (C) 2008 Nokia Corporation
  103493. + * Contact: Jarkko Nikula <jarkko.nikula@bitmer.com>
  103494. + * Peter Ujfalusi <peter.ujfalusi@ti.com>
  103495. + *
  103496. + * Freescale SSI ALSA SoC Digital Audio Interface (DAI) driver
  103497. + * Author: Timur Tabi <timur@freescale.com>
  103498. + * Copyright 2007-2010 Freescale Semiconductor, Inc.
  103499. + *
  103500. + * This program is free software; you can redistribute it and/or
  103501. + * modify it under the terms of the GNU General Public License
  103502. + * version 2 as published by the Free Software Foundation.
  103503. + *
  103504. + * This program is distributed in the hope that it will be useful, but
  103505. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  103506. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  103507. + * General Public License for more details.
  103508. + */
  103509. +
  103510. +#include <linux/init.h>
  103511. +#include <linux/module.h>
  103512. +#include <linux/device.h>
  103513. +#include <linux/slab.h>
  103514. +#include <linux/delay.h>
  103515. +#include <linux/io.h>
  103516. +#include <linux/clk.h>
  103517. +
  103518. +#include <sound/core.h>
  103519. +#include <sound/pcm.h>
  103520. +#include <sound/pcm_params.h>
  103521. +#include <sound/initval.h>
  103522. +#include <sound/soc.h>
  103523. +#include <sound/dmaengine_pcm.h>
  103524. +
  103525. +/* Clock registers */
  103526. +#define BCM2708_CLK_PCMCTL_REG 0x00
  103527. +#define BCM2708_CLK_PCMDIV_REG 0x04
  103528. +
  103529. +/* Clock register settings */
  103530. +#define BCM2708_CLK_PASSWD (0x5a000000)
  103531. +#define BCM2708_CLK_PASSWD_MASK (0xff000000)
  103532. +#define BCM2708_CLK_MASH(v) ((v) << 9)
  103533. +#define BCM2708_CLK_FLIP BIT(8)
  103534. +#define BCM2708_CLK_BUSY BIT(7)
  103535. +#define BCM2708_CLK_KILL BIT(5)
  103536. +#define BCM2708_CLK_ENAB BIT(4)
  103537. +#define BCM2708_CLK_SRC(v) (v)
  103538. +
  103539. +#define BCM2708_CLK_SHIFT (12)
  103540. +#define BCM2708_CLK_DIVI(v) ((v) << BCM2708_CLK_SHIFT)
  103541. +#define BCM2708_CLK_DIVF(v) (v)
  103542. +#define BCM2708_CLK_DIVF_MASK (0xFFF)
  103543. +
  103544. +enum {
  103545. + BCM2708_CLK_MASH_0 = 0,
  103546. + BCM2708_CLK_MASH_1,
  103547. + BCM2708_CLK_MASH_2,
  103548. + BCM2708_CLK_MASH_3,
  103549. +};
  103550. +
  103551. +enum {
  103552. + BCM2708_CLK_SRC_GND = 0,
  103553. + BCM2708_CLK_SRC_OSC,
  103554. + BCM2708_CLK_SRC_DBG0,
  103555. + BCM2708_CLK_SRC_DBG1,
  103556. + BCM2708_CLK_SRC_PLLA,
  103557. + BCM2708_CLK_SRC_PLLC,
  103558. + BCM2708_CLK_SRC_PLLD,
  103559. + BCM2708_CLK_SRC_HDMI,
  103560. +};
  103561. +
  103562. +/* Most clocks are not useable (freq = 0) */
  103563. +static const unsigned int bcm2708_clk_freq[BCM2708_CLK_SRC_HDMI+1] = {
  103564. + [BCM2708_CLK_SRC_GND] = 0,
  103565. + [BCM2708_CLK_SRC_OSC] = 19200000,
  103566. + [BCM2708_CLK_SRC_DBG0] = 0,
  103567. + [BCM2708_CLK_SRC_DBG1] = 0,
  103568. + [BCM2708_CLK_SRC_PLLA] = 0,
  103569. + [BCM2708_CLK_SRC_PLLC] = 0,
  103570. + [BCM2708_CLK_SRC_PLLD] = 500000000,
  103571. + [BCM2708_CLK_SRC_HDMI] = 0,
  103572. +};
  103573. +
  103574. +/* I2S registers */
  103575. +#define BCM2708_I2S_CS_A_REG 0x00
  103576. +#define BCM2708_I2S_FIFO_A_REG 0x04
  103577. +#define BCM2708_I2S_MODE_A_REG 0x08
  103578. +#define BCM2708_I2S_RXC_A_REG 0x0c
  103579. +#define BCM2708_I2S_TXC_A_REG 0x10
  103580. +#define BCM2708_I2S_DREQ_A_REG 0x14
  103581. +#define BCM2708_I2S_INTEN_A_REG 0x18
  103582. +#define BCM2708_I2S_INTSTC_A_REG 0x1c
  103583. +#define BCM2708_I2S_GRAY_REG 0x20
  103584. +
  103585. +/* I2S register settings */
  103586. +#define BCM2708_I2S_STBY BIT(25)
  103587. +#define BCM2708_I2S_SYNC BIT(24)
  103588. +#define BCM2708_I2S_RXSEX BIT(23)
  103589. +#define BCM2708_I2S_RXF BIT(22)
  103590. +#define BCM2708_I2S_TXE BIT(21)
  103591. +#define BCM2708_I2S_RXD BIT(20)
  103592. +#define BCM2708_I2S_TXD BIT(19)
  103593. +#define BCM2708_I2S_RXR BIT(18)
  103594. +#define BCM2708_I2S_TXW BIT(17)
  103595. +#define BCM2708_I2S_CS_RXERR BIT(16)
  103596. +#define BCM2708_I2S_CS_TXERR BIT(15)
  103597. +#define BCM2708_I2S_RXSYNC BIT(14)
  103598. +#define BCM2708_I2S_TXSYNC BIT(13)
  103599. +#define BCM2708_I2S_DMAEN BIT(9)
  103600. +#define BCM2708_I2S_RXTHR(v) ((v) << 7)
  103601. +#define BCM2708_I2S_TXTHR(v) ((v) << 5)
  103602. +#define BCM2708_I2S_RXCLR BIT(4)
  103603. +#define BCM2708_I2S_TXCLR BIT(3)
  103604. +#define BCM2708_I2S_TXON BIT(2)
  103605. +#define BCM2708_I2S_RXON BIT(1)
  103606. +#define BCM2708_I2S_EN (1)
  103607. +
  103608. +#define BCM2708_I2S_CLKDIS BIT(28)
  103609. +#define BCM2708_I2S_PDMN BIT(27)
  103610. +#define BCM2708_I2S_PDME BIT(26)
  103611. +#define BCM2708_I2S_FRXP BIT(25)
  103612. +#define BCM2708_I2S_FTXP BIT(24)
  103613. +#define BCM2708_I2S_CLKM BIT(23)
  103614. +#define BCM2708_I2S_CLKI BIT(22)
  103615. +#define BCM2708_I2S_FSM BIT(21)
  103616. +#define BCM2708_I2S_FSI BIT(20)
  103617. +#define BCM2708_I2S_FLEN(v) ((v) << 10)
  103618. +#define BCM2708_I2S_FSLEN(v) (v)
  103619. +
  103620. +#define BCM2708_I2S_CHWEX BIT(15)
  103621. +#define BCM2708_I2S_CHEN BIT(14)
  103622. +#define BCM2708_I2S_CHPOS(v) ((v) << 4)
  103623. +#define BCM2708_I2S_CHWID(v) (v)
  103624. +#define BCM2708_I2S_CH1(v) ((v) << 16)
  103625. +#define BCM2708_I2S_CH2(v) (v)
  103626. +
  103627. +#define BCM2708_I2S_TX_PANIC(v) ((v) << 24)
  103628. +#define BCM2708_I2S_RX_PANIC(v) ((v) << 16)
  103629. +#define BCM2708_I2S_TX(v) ((v) << 8)
  103630. +#define BCM2708_I2S_RX(v) (v)
  103631. +
  103632. +#define BCM2708_I2S_INT_RXERR BIT(3)
  103633. +#define BCM2708_I2S_INT_TXERR BIT(2)
  103634. +#define BCM2708_I2S_INT_RXR BIT(1)
  103635. +#define BCM2708_I2S_INT_TXW BIT(0)
  103636. +
  103637. +/* I2S DMA interface */
  103638. +#define BCM2708_I2S_FIFO_PHYSICAL_ADDR 0x7E203004
  103639. +#define BCM2708_DMA_DREQ_PCM_TX 2
  103640. +#define BCM2708_DMA_DREQ_PCM_RX 3
  103641. +
  103642. +/* General device struct */
  103643. +struct bcm2708_i2s_dev {
  103644. + struct device *dev;
  103645. + struct snd_dmaengine_dai_dma_data dma_data[2];
  103646. + unsigned int fmt;
  103647. + unsigned int bclk_ratio;
  103648. +
  103649. + struct regmap *i2s_regmap;
  103650. + struct regmap *clk_regmap;
  103651. +};
  103652. +
  103653. +static void bcm2708_i2s_start_clock(struct bcm2708_i2s_dev *dev)
  103654. +{
  103655. + /* Start the clock if in master mode */
  103656. + unsigned int master = dev->fmt & SND_SOC_DAIFMT_MASTER_MASK;
  103657. +
  103658. + switch (master) {
  103659. + case SND_SOC_DAIFMT_CBS_CFS:
  103660. + case SND_SOC_DAIFMT_CBS_CFM:
  103661. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  103662. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  103663. + BCM2708_CLK_PASSWD | BCM2708_CLK_ENAB);
  103664. + break;
  103665. + default:
  103666. + break;
  103667. + }
  103668. +}
  103669. +
  103670. +static void bcm2708_i2s_stop_clock(struct bcm2708_i2s_dev *dev)
  103671. +{
  103672. + uint32_t clkreg;
  103673. + int timeout = 1000;
  103674. +
  103675. + /* Stop clock */
  103676. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  103677. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  103678. + BCM2708_CLK_PASSWD);
  103679. +
  103680. + /* Wait for the BUSY flag going down */
  103681. + while (--timeout) {
  103682. + regmap_read(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, &clkreg);
  103683. + if (!(clkreg & BCM2708_CLK_BUSY))
  103684. + break;
  103685. + }
  103686. +
  103687. + if (!timeout) {
  103688. + /* KILL the clock */
  103689. + dev_err(dev->dev, "I2S clock didn't stop. Kill the clock!\n");
  103690. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  103691. + BCM2708_CLK_KILL | BCM2708_CLK_PASSWD_MASK,
  103692. + BCM2708_CLK_KILL | BCM2708_CLK_PASSWD);
  103693. + }
  103694. +}
  103695. +
  103696. +static void bcm2708_i2s_clear_fifos(struct bcm2708_i2s_dev *dev,
  103697. + bool tx, bool rx)
  103698. +{
  103699. + int timeout = 1000;
  103700. + uint32_t syncval;
  103701. + uint32_t csreg;
  103702. + uint32_t i2s_active_state;
  103703. + uint32_t clkreg;
  103704. + uint32_t clk_active_state;
  103705. + uint32_t off;
  103706. + uint32_t clr;
  103707. +
  103708. + off = tx ? BCM2708_I2S_TXON : 0;
  103709. + off |= rx ? BCM2708_I2S_RXON : 0;
  103710. +
  103711. + clr = tx ? BCM2708_I2S_TXCLR : 0;
  103712. + clr |= rx ? BCM2708_I2S_RXCLR : 0;
  103713. +
  103714. + /* Backup the current state */
  103715. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  103716. + i2s_active_state = csreg & (BCM2708_I2S_RXON | BCM2708_I2S_TXON);
  103717. +
  103718. + regmap_read(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, &clkreg);
  103719. + clk_active_state = clkreg & BCM2708_CLK_ENAB;
  103720. +
  103721. + /* Start clock if not running */
  103722. + if (!clk_active_state) {
  103723. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  103724. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  103725. + BCM2708_CLK_PASSWD | BCM2708_CLK_ENAB);
  103726. + }
  103727. +
  103728. + /* Stop I2S module */
  103729. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, off, 0);
  103730. +
  103731. + /*
  103732. + * Clear the FIFOs
  103733. + * Requires at least 2 PCM clock cycles to take effect
  103734. + */
  103735. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, clr, clr);
  103736. +
  103737. + /* Wait for 2 PCM clock cycles */
  103738. +
  103739. + /*
  103740. + * Toggle the SYNC flag. After 2 PCM clock cycles it can be read back
  103741. + * FIXME: This does not seem to work for slave mode!
  103742. + */
  103743. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &syncval);
  103744. + syncval &= BCM2708_I2S_SYNC;
  103745. +
  103746. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  103747. + BCM2708_I2S_SYNC, ~syncval);
  103748. +
  103749. + /* Wait for the SYNC flag changing it's state */
  103750. + while (--timeout) {
  103751. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  103752. + if ((csreg & BCM2708_I2S_SYNC) != syncval)
  103753. + break;
  103754. + }
  103755. +
  103756. + if (!timeout)
  103757. + dev_err(dev->dev, "I2S SYNC error!\n");
  103758. +
  103759. + /* Stop clock if it was not running before */
  103760. + if (!clk_active_state)
  103761. + bcm2708_i2s_stop_clock(dev);
  103762. +
  103763. + /* Restore I2S state */
  103764. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  103765. + BCM2708_I2S_RXON | BCM2708_I2S_TXON, i2s_active_state);
  103766. +}
  103767. +
  103768. +static int bcm2708_i2s_set_dai_fmt(struct snd_soc_dai *dai,
  103769. + unsigned int fmt)
  103770. +{
  103771. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  103772. + dev->fmt = fmt;
  103773. + return 0;
  103774. +}
  103775. +
  103776. +static int bcm2708_i2s_set_dai_bclk_ratio(struct snd_soc_dai *dai,
  103777. + unsigned int ratio)
  103778. +{
  103779. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  103780. + dev->bclk_ratio = ratio;
  103781. + return 0;
  103782. +}
  103783. +
  103784. +
  103785. +static void bcm2708_i2s_setup_gpio(void)
  103786. +{
  103787. + /*
  103788. + * This is the common way to handle the GPIO pins for
  103789. + * the Raspberry Pi.
  103790. + * TODO Better way would be to handle
  103791. + * this in the device tree!
  103792. + */
  103793. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  103794. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  103795. +
  103796. + unsigned int *gpio;
  103797. + int pin;
  103798. + gpio = ioremap(GPIO_BASE, SZ_16K);
  103799. +
  103800. + /* SPI is on GPIO 7..11 */
  103801. + for (pin = 28; pin <= 31; pin++) {
  103802. + INP_GPIO(pin); /* set mode to GPIO input first */
  103803. + SET_GPIO_ALT(pin, 2); /* set mode to ALT 0 */
  103804. + }
  103805. +#undef INP_GPIO
  103806. +#undef SET_GPIO_ALT
  103807. +}
  103808. +
  103809. +static int bcm2708_i2s_hw_params(struct snd_pcm_substream *substream,
  103810. + struct snd_pcm_hw_params *params,
  103811. + struct snd_soc_dai *dai)
  103812. +{
  103813. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  103814. +
  103815. + unsigned int sampling_rate = params_rate(params);
  103816. + unsigned int data_length, data_delay, bclk_ratio;
  103817. + unsigned int ch1pos, ch2pos, mode, format;
  103818. + unsigned int mash = BCM2708_CLK_MASH_1;
  103819. + unsigned int divi, divf, target_frequency;
  103820. + int clk_src = -1;
  103821. + unsigned int master = dev->fmt & SND_SOC_DAIFMT_MASTER_MASK;
  103822. + bool bit_master = (master == SND_SOC_DAIFMT_CBS_CFS
  103823. + || master == SND_SOC_DAIFMT_CBS_CFM);
  103824. +
  103825. + bool frame_master = (master == SND_SOC_DAIFMT_CBS_CFS
  103826. + || master == SND_SOC_DAIFMT_CBM_CFS);
  103827. + uint32_t csreg;
  103828. +
  103829. + /*
  103830. + * If a stream is already enabled,
  103831. + * the registers are already set properly.
  103832. + */
  103833. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  103834. +
  103835. + if (csreg & (BCM2708_I2S_TXON | BCM2708_I2S_RXON))
  103836. + return 0;
  103837. +
  103838. +
  103839. + bcm2708_i2s_setup_gpio();
  103840. +
  103841. + /*
  103842. + * Adjust the data length according to the format.
  103843. + * We prefill the half frame length with an integer
  103844. + * divider of 2400 as explained at the clock settings.
  103845. + * Maybe it is overwritten there, if the Integer mode
  103846. + * does not apply.
  103847. + */
  103848. + switch (params_format(params)) {
  103849. + case SNDRV_PCM_FORMAT_S16_LE:
  103850. + data_length = 16;
  103851. + bclk_ratio = 40;
  103852. + break;
  103853. + case SNDRV_PCM_FORMAT_S24_LE:
  103854. + data_length = 24;
  103855. + bclk_ratio = 40;
  103856. + break;
  103857. + case SNDRV_PCM_FORMAT_S32_LE:
  103858. + data_length = 32;
  103859. + bclk_ratio = 80;
  103860. + break;
  103861. + default:
  103862. + return -EINVAL;
  103863. + }
  103864. +
  103865. + /* If bclk_ratio already set, use that one. */
  103866. + if (dev->bclk_ratio)
  103867. + bclk_ratio = dev->bclk_ratio;
  103868. +
  103869. + /*
  103870. + * Clock Settings
  103871. + *
  103872. + * The target frequency of the bit clock is
  103873. + * sampling rate * frame length
  103874. + *
  103875. + * Integer mode:
  103876. + * Sampling rates that are multiples of 8000 kHz
  103877. + * can be driven by the oscillator of 19.2 MHz
  103878. + * with an integer divider as long as the frame length
  103879. + * is an integer divider of 19200000/8000=2400 as set up above.
  103880. + * This is no longer possible if the sampling rate
  103881. + * is too high (e.g. 192 kHz), because the oscillator is too slow.
  103882. + *
  103883. + * MASH mode:
  103884. + * For all other sampling rates, it is not possible to
  103885. + * have an integer divider. Approximate the clock
  103886. + * with the MASH module that induces a slight frequency
  103887. + * variance. To minimize that it is best to have the fastest
  103888. + * clock here. That is PLLD with 500 MHz.
  103889. + */
  103890. + target_frequency = sampling_rate * bclk_ratio;
  103891. + clk_src = BCM2708_CLK_SRC_OSC;
  103892. + mash = BCM2708_CLK_MASH_0;
  103893. +
  103894. + if (bcm2708_clk_freq[clk_src] % target_frequency == 0
  103895. + && bit_master && frame_master) {
  103896. + divi = bcm2708_clk_freq[clk_src] / target_frequency;
  103897. + divf = 0;
  103898. + } else {
  103899. + uint64_t dividend;
  103900. +
  103901. + if (!dev->bclk_ratio) {
  103902. + /*
  103903. + * Overwrite bclk_ratio, because the
  103904. + * above trick is not needed or can
  103905. + * not be used.
  103906. + */
  103907. + bclk_ratio = 2 * data_length;
  103908. + }
  103909. +
  103910. + target_frequency = sampling_rate * bclk_ratio;
  103911. +
  103912. + clk_src = BCM2708_CLK_SRC_PLLD;
  103913. + mash = BCM2708_CLK_MASH_1;
  103914. +
  103915. + dividend = bcm2708_clk_freq[clk_src];
  103916. + dividend <<= BCM2708_CLK_SHIFT;
  103917. + do_div(dividend, target_frequency);
  103918. + divi = dividend >> BCM2708_CLK_SHIFT;
  103919. + divf = dividend & BCM2708_CLK_DIVF_MASK;
  103920. + }
  103921. +
  103922. + /* Set clock divider */
  103923. + regmap_write(dev->clk_regmap, BCM2708_CLK_PCMDIV_REG, BCM2708_CLK_PASSWD
  103924. + | BCM2708_CLK_DIVI(divi)
  103925. + | BCM2708_CLK_DIVF(divf));
  103926. +
  103927. + /* Setup clock, but don't start it yet */
  103928. + regmap_write(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, BCM2708_CLK_PASSWD
  103929. + | BCM2708_CLK_MASH(mash)
  103930. + | BCM2708_CLK_SRC(clk_src));
  103931. +
  103932. + /* Setup the frame format */
  103933. + format = BCM2708_I2S_CHEN;
  103934. +
  103935. + if (data_length >= 24)
  103936. + format |= BCM2708_I2S_CHWEX;
  103937. +
  103938. + format |= BCM2708_I2S_CHWID((data_length-8)&0xf);
  103939. +
  103940. + switch (dev->fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  103941. + case SND_SOC_DAIFMT_I2S:
  103942. + data_delay = 1;
  103943. + break;
  103944. + default:
  103945. + /*
  103946. + * TODO
  103947. + * Others are possible but are not implemented at the moment.
  103948. + */
  103949. + dev_err(dev->dev, "%s:bad format\n", __func__);
  103950. + return -EINVAL;
  103951. + }
  103952. +
  103953. + ch1pos = data_delay;
  103954. + ch2pos = bclk_ratio / 2 + data_delay;
  103955. +
  103956. + switch (params_channels(params)) {
  103957. + case 2:
  103958. + format = BCM2708_I2S_CH1(format) | BCM2708_I2S_CH2(format);
  103959. + format |= BCM2708_I2S_CH1(BCM2708_I2S_CHPOS(ch1pos));
  103960. + format |= BCM2708_I2S_CH2(BCM2708_I2S_CHPOS(ch2pos));
  103961. + break;
  103962. + default:
  103963. + return -EINVAL;
  103964. + }
  103965. +
  103966. + /*
  103967. + * Set format for both streams.
  103968. + * We cannot set another frame length
  103969. + * (and therefore word length) anyway,
  103970. + * so the format will be the same.
  103971. + */
  103972. + regmap_write(dev->i2s_regmap, BCM2708_I2S_RXC_A_REG, format);
  103973. + regmap_write(dev->i2s_regmap, BCM2708_I2S_TXC_A_REG, format);
  103974. +
  103975. + /* Setup the I2S mode */
  103976. + mode = 0;
  103977. +
  103978. + if (data_length <= 16) {
  103979. + /*
  103980. + * Use frame packed mode (2 channels per 32 bit word)
  103981. + * We cannot set another frame length in the second stream
  103982. + * (and therefore word length) anyway,
  103983. + * so the format will be the same.
  103984. + */
  103985. + mode |= BCM2708_I2S_FTXP | BCM2708_I2S_FRXP;
  103986. + }
  103987. +
  103988. + mode |= BCM2708_I2S_FLEN(bclk_ratio - 1);
  103989. + mode |= BCM2708_I2S_FSLEN(bclk_ratio / 2);
  103990. +
  103991. + /* Master or slave? */
  103992. + switch (dev->fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  103993. + case SND_SOC_DAIFMT_CBS_CFS:
  103994. + /* CPU is master */
  103995. + break;
  103996. + case SND_SOC_DAIFMT_CBM_CFS:
  103997. + /*
  103998. + * CODEC is bit clock master
  103999. + * CPU is frame master
  104000. + */
  104001. + mode |= BCM2708_I2S_CLKM;
  104002. + break;
  104003. + case SND_SOC_DAIFMT_CBS_CFM:
  104004. + /*
  104005. + * CODEC is frame master
  104006. + * CPU is bit clock master
  104007. + */
  104008. + mode |= BCM2708_I2S_FSM;
  104009. + break;
  104010. + case SND_SOC_DAIFMT_CBM_CFM:
  104011. + /* CODEC is master */
  104012. + mode |= BCM2708_I2S_CLKM;
  104013. + mode |= BCM2708_I2S_FSM;
  104014. + break;
  104015. + default:
  104016. + dev_err(dev->dev, "%s:bad master\n", __func__);
  104017. + return -EINVAL;
  104018. + }
  104019. +
  104020. + /*
  104021. + * Invert clocks?
  104022. + *
  104023. + * The BCM approach seems to be inverted to the classical I2S approach.
  104024. + */
  104025. + switch (dev->fmt & SND_SOC_DAIFMT_INV_MASK) {
  104026. + case SND_SOC_DAIFMT_NB_NF:
  104027. + /* None. Therefore, both for BCM */
  104028. + mode |= BCM2708_I2S_CLKI;
  104029. + mode |= BCM2708_I2S_FSI;
  104030. + break;
  104031. + case SND_SOC_DAIFMT_IB_IF:
  104032. + /* Both. Therefore, none for BCM */
  104033. + break;
  104034. + case SND_SOC_DAIFMT_NB_IF:
  104035. + /*
  104036. + * Invert only frame sync. Therefore,
  104037. + * invert only bit clock for BCM
  104038. + */
  104039. + mode |= BCM2708_I2S_CLKI;
  104040. + break;
  104041. + case SND_SOC_DAIFMT_IB_NF:
  104042. + /*
  104043. + * Invert only bit clock. Therefore,
  104044. + * invert only frame sync for BCM
  104045. + */
  104046. + mode |= BCM2708_I2S_FSI;
  104047. + break;
  104048. + default:
  104049. + return -EINVAL;
  104050. + }
  104051. +
  104052. + regmap_write(dev->i2s_regmap, BCM2708_I2S_MODE_A_REG, mode);
  104053. +
  104054. + /* Setup the DMA parameters */
  104055. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  104056. + BCM2708_I2S_RXTHR(1)
  104057. + | BCM2708_I2S_TXTHR(1)
  104058. + | BCM2708_I2S_DMAEN, 0xffffffff);
  104059. +
  104060. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_DREQ_A_REG,
  104061. + BCM2708_I2S_TX_PANIC(0x10)
  104062. + | BCM2708_I2S_RX_PANIC(0x30)
  104063. + | BCM2708_I2S_TX(0x30)
  104064. + | BCM2708_I2S_RX(0x20), 0xffffffff);
  104065. +
  104066. + /* Clear FIFOs */
  104067. + bcm2708_i2s_clear_fifos(dev, true, true);
  104068. +
  104069. + return 0;
  104070. +}
  104071. +
  104072. +static int bcm2708_i2s_prepare(struct snd_pcm_substream *substream,
  104073. + struct snd_soc_dai *dai)
  104074. +{
  104075. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  104076. + uint32_t cs_reg;
  104077. +
  104078. + bcm2708_i2s_start_clock(dev);
  104079. +
  104080. + /*
  104081. + * Clear both FIFOs if the one that should be started
  104082. + * is not empty at the moment. This should only happen
  104083. + * after overrun. Otherwise, hw_params would have cleared
  104084. + * the FIFO.
  104085. + */
  104086. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &cs_reg);
  104087. +
  104088. + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK
  104089. + && !(cs_reg & BCM2708_I2S_TXE))
  104090. + bcm2708_i2s_clear_fifos(dev, true, false);
  104091. + else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE
  104092. + && (cs_reg & BCM2708_I2S_RXD))
  104093. + bcm2708_i2s_clear_fifos(dev, false, true);
  104094. +
  104095. + return 0;
  104096. +}
  104097. +
  104098. +static void bcm2708_i2s_stop(struct bcm2708_i2s_dev *dev,
  104099. + struct snd_pcm_substream *substream,
  104100. + struct snd_soc_dai *dai)
  104101. +{
  104102. + uint32_t mask;
  104103. +
  104104. + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  104105. + mask = BCM2708_I2S_RXON;
  104106. + else
  104107. + mask = BCM2708_I2S_TXON;
  104108. +
  104109. + regmap_update_bits(dev->i2s_regmap,
  104110. + BCM2708_I2S_CS_A_REG, mask, 0);
  104111. +
  104112. + /* Stop also the clock when not SND_SOC_DAIFMT_CONT */
  104113. + if (!dai->active && !(dev->fmt & SND_SOC_DAIFMT_CONT))
  104114. + bcm2708_i2s_stop_clock(dev);
  104115. +}
  104116. +
  104117. +static int bcm2708_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
  104118. + struct snd_soc_dai *dai)
  104119. +{
  104120. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  104121. + uint32_t mask;
  104122. +
  104123. + switch (cmd) {
  104124. + case SNDRV_PCM_TRIGGER_START:
  104125. + case SNDRV_PCM_TRIGGER_RESUME:
  104126. + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  104127. + bcm2708_i2s_start_clock(dev);
  104128. +
  104129. + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  104130. + mask = BCM2708_I2S_RXON;
  104131. + else
  104132. + mask = BCM2708_I2S_TXON;
  104133. +
  104134. + regmap_update_bits(dev->i2s_regmap,
  104135. + BCM2708_I2S_CS_A_REG, mask, mask);
  104136. + break;
  104137. +
  104138. + case SNDRV_PCM_TRIGGER_STOP:
  104139. + case SNDRV_PCM_TRIGGER_SUSPEND:
  104140. + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  104141. + bcm2708_i2s_stop(dev, substream, dai);
  104142. + break;
  104143. + default:
  104144. + return -EINVAL;
  104145. + }
  104146. +
  104147. + return 0;
  104148. +}
  104149. +
  104150. +static int bcm2708_i2s_startup(struct snd_pcm_substream *substream,
  104151. + struct snd_soc_dai *dai)
  104152. +{
  104153. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  104154. +
  104155. + if (dai->active)
  104156. + return 0;
  104157. +
  104158. + /* Should this still be running stop it */
  104159. + bcm2708_i2s_stop_clock(dev);
  104160. +
  104161. + /* Enable PCM block */
  104162. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  104163. + BCM2708_I2S_EN, BCM2708_I2S_EN);
  104164. +
  104165. + /*
  104166. + * Disable STBY.
  104167. + * Requires at least 4 PCM clock cycles to take effect.
  104168. + */
  104169. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  104170. + BCM2708_I2S_STBY, BCM2708_I2S_STBY);
  104171. +
  104172. + return 0;
  104173. +}
  104174. +
  104175. +static void bcm2708_i2s_shutdown(struct snd_pcm_substream *substream,
  104176. + struct snd_soc_dai *dai)
  104177. +{
  104178. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  104179. +
  104180. + bcm2708_i2s_stop(dev, substream, dai);
  104181. +
  104182. + /* If both streams are stopped, disable module and clock */
  104183. + if (dai->active)
  104184. + return;
  104185. +
  104186. + /* Disable the module */
  104187. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  104188. + BCM2708_I2S_EN, 0);
  104189. +
  104190. + /*
  104191. + * Stopping clock is necessary, because stop does
  104192. + * not stop the clock when SND_SOC_DAIFMT_CONT
  104193. + */
  104194. + bcm2708_i2s_stop_clock(dev);
  104195. +}
  104196. +
  104197. +static const struct snd_soc_dai_ops bcm2708_i2s_dai_ops = {
  104198. + .startup = bcm2708_i2s_startup,
  104199. + .shutdown = bcm2708_i2s_shutdown,
  104200. + .prepare = bcm2708_i2s_prepare,
  104201. + .trigger = bcm2708_i2s_trigger,
  104202. + .hw_params = bcm2708_i2s_hw_params,
  104203. + .set_fmt = bcm2708_i2s_set_dai_fmt,
  104204. + .set_bclk_ratio = bcm2708_i2s_set_dai_bclk_ratio
  104205. +};
  104206. +
  104207. +static int bcm2708_i2s_dai_probe(struct snd_soc_dai *dai)
  104208. +{
  104209. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  104210. +
  104211. + dai->playback_dma_data = &dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK];
  104212. + dai->capture_dma_data = &dev->dma_data[SNDRV_PCM_STREAM_CAPTURE];
  104213. +
  104214. + return 0;
  104215. +}
  104216. +
  104217. +static struct snd_soc_dai_driver bcm2708_i2s_dai = {
  104218. + .name = "bcm2708-i2s",
  104219. + .probe = bcm2708_i2s_dai_probe,
  104220. + .playback = {
  104221. + .channels_min = 2,
  104222. + .channels_max = 2,
  104223. + .rates = SNDRV_PCM_RATE_8000_192000,
  104224. + .formats = SNDRV_PCM_FMTBIT_S16_LE
  104225. + // | SNDRV_PCM_FMTBIT_S24_LE : disable for now, it causes white noise with xbmc
  104226. + | SNDRV_PCM_FMTBIT_S32_LE
  104227. + },
  104228. + .capture = {
  104229. + .channels_min = 2,
  104230. + .channels_max = 2,
  104231. + .rates = SNDRV_PCM_RATE_8000_192000,
  104232. + .formats = SNDRV_PCM_FMTBIT_S16_LE
  104233. + | SNDRV_PCM_FMTBIT_S24_LE
  104234. + | SNDRV_PCM_FMTBIT_S32_LE
  104235. + },
  104236. + .ops = &bcm2708_i2s_dai_ops,
  104237. + .symmetric_rates = 1
  104238. +};
  104239. +
  104240. +static bool bcm2708_i2s_volatile_reg(struct device *dev, unsigned int reg)
  104241. +{
  104242. + switch (reg) {
  104243. + case BCM2708_I2S_CS_A_REG:
  104244. + case BCM2708_I2S_FIFO_A_REG:
  104245. + case BCM2708_I2S_INTSTC_A_REG:
  104246. + case BCM2708_I2S_GRAY_REG:
  104247. + return true;
  104248. + default:
  104249. + return false;
  104250. + };
  104251. +}
  104252. +
  104253. +static bool bcm2708_i2s_precious_reg(struct device *dev, unsigned int reg)
  104254. +{
  104255. + switch (reg) {
  104256. + case BCM2708_I2S_FIFO_A_REG:
  104257. + return true;
  104258. + default:
  104259. + return false;
  104260. + };
  104261. +}
  104262. +
  104263. +static bool bcm2708_clk_volatile_reg(struct device *dev, unsigned int reg)
  104264. +{
  104265. + switch (reg) {
  104266. + case BCM2708_CLK_PCMCTL_REG:
  104267. + return true;
  104268. + default:
  104269. + return false;
  104270. + };
  104271. +}
  104272. +
  104273. +static const struct regmap_config bcm2708_regmap_config[] = {
  104274. + {
  104275. + .reg_bits = 32,
  104276. + .reg_stride = 4,
  104277. + .val_bits = 32,
  104278. + .max_register = BCM2708_I2S_GRAY_REG,
  104279. + .precious_reg = bcm2708_i2s_precious_reg,
  104280. + .volatile_reg = bcm2708_i2s_volatile_reg,
  104281. + .cache_type = REGCACHE_RBTREE,
  104282. + },
  104283. + {
  104284. + .reg_bits = 32,
  104285. + .reg_stride = 4,
  104286. + .val_bits = 32,
  104287. + .max_register = BCM2708_CLK_PCMDIV_REG,
  104288. + .volatile_reg = bcm2708_clk_volatile_reg,
  104289. + .cache_type = REGCACHE_RBTREE,
  104290. + },
  104291. +};
  104292. +
  104293. +static const struct snd_soc_component_driver bcm2708_i2s_component = {
  104294. + .name = "bcm2708-i2s-comp",
  104295. +};
  104296. +
  104297. +static const struct snd_pcm_hardware bcm2708_pcm_hardware = {
  104298. + .info = SNDRV_PCM_INFO_INTERLEAVED |
  104299. + SNDRV_PCM_INFO_JOINT_DUPLEX,
  104300. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  104301. + SNDRV_PCM_FMTBIT_S24_LE |
  104302. + SNDRV_PCM_FMTBIT_S32_LE,
  104303. + .period_bytes_min = 32,
  104304. + .period_bytes_max = 64 * PAGE_SIZE,
  104305. + .periods_min = 2,
  104306. + .periods_max = 255,
  104307. + .buffer_bytes_max = 128 * PAGE_SIZE,
  104308. +};
  104309. +
  104310. +static const struct snd_dmaengine_pcm_config bcm2708_dmaengine_pcm_config = {
  104311. + .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
  104312. + .pcm_hardware = &bcm2708_pcm_hardware,
  104313. + .prealloc_buffer_size = 256 * PAGE_SIZE,
  104314. +};
  104315. +
  104316. +
  104317. +static int bcm2708_i2s_probe(struct platform_device *pdev)
  104318. +{
  104319. + struct bcm2708_i2s_dev *dev;
  104320. + int i;
  104321. + int ret;
  104322. + struct regmap *regmap[2];
  104323. + struct resource *mem[2];
  104324. +
  104325. + /* Request both ioareas */
  104326. + for (i = 0; i <= 1; i++) {
  104327. + void __iomem *base;
  104328. +
  104329. + mem[i] = platform_get_resource(pdev, IORESOURCE_MEM, i);
  104330. + base = devm_ioremap_resource(&pdev->dev, mem[i]);
  104331. + if (IS_ERR(base))
  104332. + return PTR_ERR(base);
  104333. +
  104334. + regmap[i] = devm_regmap_init_mmio(&pdev->dev, base,
  104335. + &bcm2708_regmap_config[i]);
  104336. + if (IS_ERR(regmap[i])) {
  104337. + dev_err(&pdev->dev, "I2S probe: regmap init failed\n");
  104338. + return PTR_ERR(regmap[i]);
  104339. + }
  104340. + }
  104341. +
  104342. + dev = devm_kzalloc(&pdev->dev, sizeof(*dev),
  104343. + GFP_KERNEL);
  104344. + if (IS_ERR(dev))
  104345. + return PTR_ERR(dev);
  104346. +
  104347. + dev->i2s_regmap = regmap[0];
  104348. + dev->clk_regmap = regmap[1];
  104349. +
  104350. + /* Set the DMA address */
  104351. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr =
  104352. + (dma_addr_t)BCM2708_I2S_FIFO_PHYSICAL_ADDR;
  104353. +
  104354. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr =
  104355. + (dma_addr_t)BCM2708_I2S_FIFO_PHYSICAL_ADDR;
  104356. +
  104357. + /* Set the DREQ */
  104358. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].slave_id =
  104359. + BCM2708_DMA_DREQ_PCM_TX;
  104360. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].slave_id =
  104361. + BCM2708_DMA_DREQ_PCM_RX;
  104362. +
  104363. + /* Set the bus width */
  104364. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr_width =
  104365. + DMA_SLAVE_BUSWIDTH_4_BYTES;
  104366. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr_width =
  104367. + DMA_SLAVE_BUSWIDTH_4_BYTES;
  104368. +
  104369. + /* Set burst */
  104370. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].maxburst = 2;
  104371. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].maxburst = 2;
  104372. +
  104373. + /* BCLK ratio - use default */
  104374. + dev->bclk_ratio = 0;
  104375. +
  104376. + /* Store the pdev */
  104377. + dev->dev = &pdev->dev;
  104378. + dev_set_drvdata(&pdev->dev, dev);
  104379. +
  104380. + ret = snd_soc_register_component(&pdev->dev,
  104381. + &bcm2708_i2s_component, &bcm2708_i2s_dai, 1);
  104382. +
  104383. + if (ret) {
  104384. + dev_err(&pdev->dev, "Could not register DAI: %d\n", ret);
  104385. + ret = -ENOMEM;
  104386. + return ret;
  104387. + }
  104388. +
  104389. + ret = snd_dmaengine_pcm_register(&pdev->dev,
  104390. + &bcm2708_dmaengine_pcm_config,
  104391. + SND_DMAENGINE_PCM_FLAG_COMPAT);
  104392. + if (ret) {
  104393. + dev_err(&pdev->dev, "Could not register PCM: %d\n", ret);
  104394. + snd_soc_unregister_component(&pdev->dev);
  104395. + return ret;
  104396. + }
  104397. +
  104398. + return 0;
  104399. +}
  104400. +
  104401. +static int bcm2708_i2s_remove(struct platform_device *pdev)
  104402. +{
  104403. + snd_dmaengine_pcm_unregister(&pdev->dev);
  104404. + snd_soc_unregister_component(&pdev->dev);
  104405. + return 0;
  104406. +}
  104407. +
  104408. +static struct platform_driver bcm2708_i2s_driver = {
  104409. + .probe = bcm2708_i2s_probe,
  104410. + .remove = bcm2708_i2s_remove,
  104411. + .driver = {
  104412. + .name = "bcm2708-i2s",
  104413. + .owner = THIS_MODULE,
  104414. + },
  104415. +};
  104416. +
  104417. +module_platform_driver(bcm2708_i2s_driver);
  104418. +
  104419. +MODULE_ALIAS("platform:bcm2708-i2s");
  104420. +MODULE_DESCRIPTION("BCM2708 I2S interface");
  104421. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  104422. +MODULE_LICENSE("GPL v2");
  104423. diff -Nur linux-3.15.4/sound/soc/bcm/hifiberry_dac.c linux-rpi/sound/soc/bcm/hifiberry_dac.c
  104424. --- linux-3.15.4/sound/soc/bcm/hifiberry_dac.c 1970-01-01 01:00:00.000000000 +0100
  104425. +++ linux-rpi/sound/soc/bcm/hifiberry_dac.c 2014-04-13 17:33:28.000000000 +0200
  104426. @@ -0,0 +1,100 @@
  104427. +/*
  104428. + * ASoC Driver for HifiBerry DAC
  104429. + *
  104430. + * Author: Florian Meier <florian.meier@koalo.de>
  104431. + * Copyright 2013
  104432. + *
  104433. + * This program is free software; you can redistribute it and/or
  104434. + * modify it under the terms of the GNU General Public License
  104435. + * version 2 as published by the Free Software Foundation.
  104436. + *
  104437. + * This program is distributed in the hope that it will be useful, but
  104438. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  104439. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  104440. + * General Public License for more details.
  104441. + */
  104442. +
  104443. +#include <linux/module.h>
  104444. +#include <linux/platform_device.h>
  104445. +
  104446. +#include <sound/core.h>
  104447. +#include <sound/pcm.h>
  104448. +#include <sound/pcm_params.h>
  104449. +#include <sound/soc.h>
  104450. +#include <sound/jack.h>
  104451. +
  104452. +static int snd_rpi_hifiberry_dac_init(struct snd_soc_pcm_runtime *rtd)
  104453. +{
  104454. + return 0;
  104455. +}
  104456. +
  104457. +static int snd_rpi_hifiberry_dac_hw_params(struct snd_pcm_substream *substream,
  104458. + struct snd_pcm_hw_params *params)
  104459. +{
  104460. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  104461. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  104462. +
  104463. + unsigned int sample_bits =
  104464. + snd_pcm_format_physical_width(params_format(params));
  104465. +
  104466. + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
  104467. +}
  104468. +
  104469. +/* machine stream operations */
  104470. +static struct snd_soc_ops snd_rpi_hifiberry_dac_ops = {
  104471. + .hw_params = snd_rpi_hifiberry_dac_hw_params,
  104472. +};
  104473. +
  104474. +static struct snd_soc_dai_link snd_rpi_hifiberry_dac_dai[] = {
  104475. +{
  104476. + .name = "HifiBerry DAC",
  104477. + .stream_name = "HifiBerry DAC HiFi",
  104478. + .cpu_dai_name = "bcm2708-i2s.0",
  104479. + .codec_dai_name = "pcm5102a-hifi",
  104480. + .platform_name = "bcm2708-i2s.0",
  104481. + .codec_name = "pcm5102a-codec",
  104482. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  104483. + SND_SOC_DAIFMT_CBS_CFS,
  104484. + .ops = &snd_rpi_hifiberry_dac_ops,
  104485. + .init = snd_rpi_hifiberry_dac_init,
  104486. +},
  104487. +};
  104488. +
  104489. +/* audio machine driver */
  104490. +static struct snd_soc_card snd_rpi_hifiberry_dac = {
  104491. + .name = "snd_rpi_hifiberry_dac",
  104492. + .dai_link = snd_rpi_hifiberry_dac_dai,
  104493. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dac_dai),
  104494. +};
  104495. +
  104496. +static int snd_rpi_hifiberry_dac_probe(struct platform_device *pdev)
  104497. +{
  104498. + int ret = 0;
  104499. +
  104500. + snd_rpi_hifiberry_dac.dev = &pdev->dev;
  104501. + ret = snd_soc_register_card(&snd_rpi_hifiberry_dac);
  104502. + if (ret)
  104503. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  104504. +
  104505. + return ret;
  104506. +}
  104507. +
  104508. +static int snd_rpi_hifiberry_dac_remove(struct platform_device *pdev)
  104509. +{
  104510. + return snd_soc_unregister_card(&snd_rpi_hifiberry_dac);
  104511. +}
  104512. +
  104513. +static struct platform_driver snd_rpi_hifiberry_dac_driver = {
  104514. + .driver = {
  104515. + .name = "snd-hifiberry-dac",
  104516. + .owner = THIS_MODULE,
  104517. + },
  104518. + .probe = snd_rpi_hifiberry_dac_probe,
  104519. + .remove = snd_rpi_hifiberry_dac_remove,
  104520. +};
  104521. +
  104522. +module_platform_driver(snd_rpi_hifiberry_dac_driver);
  104523. +
  104524. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  104525. +MODULE_DESCRIPTION("ASoC Driver for HifiBerry DAC");
  104526. +MODULE_LICENSE("GPL v2");
  104527. diff -Nur linux-3.15.4/sound/soc/bcm/hifiberry_digi.c linux-rpi/sound/soc/bcm/hifiberry_digi.c
  104528. --- linux-3.15.4/sound/soc/bcm/hifiberry_digi.c 1970-01-01 01:00:00.000000000 +0100
  104529. +++ linux-rpi/sound/soc/bcm/hifiberry_digi.c 2014-07-07 10:46:03.000000000 +0200
  104530. @@ -0,0 +1,153 @@
  104531. +/*
  104532. + * ASoC Driver for HifiBerry Digi
  104533. + *
  104534. + * Author: Daniel Matuschek <info@crazy-audio.com>
  104535. + * based on the HifiBerry DAC driver by Florian Meier <florian.meier@koalo.de>
  104536. + * Copyright 2013
  104537. + *
  104538. + * This program is free software; you can redistribute it and/or
  104539. + * modify it under the terms of the GNU General Public License
  104540. + * version 2 as published by the Free Software Foundation.
  104541. + *
  104542. + * This program is distributed in the hope that it will be useful, but
  104543. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  104544. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  104545. + * General Public License for more details.
  104546. + */
  104547. +
  104548. +#include <linux/module.h>
  104549. +#include <linux/platform_device.h>
  104550. +
  104551. +#include <sound/core.h>
  104552. +#include <sound/pcm.h>
  104553. +#include <sound/pcm_params.h>
  104554. +#include <sound/soc.h>
  104555. +#include <sound/jack.h>
  104556. +
  104557. +#include "../codecs/wm8804.h"
  104558. +
  104559. +static int samplerate=44100;
  104560. +
  104561. +static int snd_rpi_hifiberry_digi_init(struct snd_soc_pcm_runtime *rtd)
  104562. +{
  104563. + struct snd_soc_codec *codec = rtd->codec;
  104564. +
  104565. + /* enable TX output */
  104566. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
  104567. +
  104568. + return 0;
  104569. +}
  104570. +
  104571. +static int snd_rpi_hifiberry_digi_hw_params(struct snd_pcm_substream *substream,
  104572. + struct snd_pcm_hw_params *params)
  104573. +{
  104574. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  104575. + struct snd_soc_dai *codec_dai = rtd->codec_dai;
  104576. + struct snd_soc_codec *codec = rtd->codec;
  104577. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  104578. +
  104579. + int sysclk = 27000000; /* This is fixed on this board */
  104580. +
  104581. + long mclk_freq=0;
  104582. + int mclk_div=1;
  104583. +
  104584. + int ret;
  104585. +
  104586. + samplerate = params_rate(params);
  104587. +
  104588. + switch (samplerate) {
  104589. + case 44100:
  104590. + case 48000:
  104591. + case 88200:
  104592. + case 96000:
  104593. + mclk_freq=samplerate*256;
  104594. + mclk_div=WM8804_MCLKDIV_256FS;
  104595. + break;
  104596. + case 176400:
  104597. + case 192000:
  104598. + mclk_freq=samplerate*128;
  104599. + mclk_div=WM8804_MCLKDIV_128FS;
  104600. + break;
  104601. + default:
  104602. + dev_err(substream->pcm->dev,
  104603. + "Failed to set WM8804 SYSCLK, unsupported samplerate\n");
  104604. + }
  104605. +
  104606. + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
  104607. + snd_soc_dai_set_pll(codec_dai, 0, 0, sysclk, mclk_freq);
  104608. +
  104609. + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
  104610. + sysclk, SND_SOC_CLOCK_OUT);
  104611. + if (ret < 0) {
  104612. + dev_err(substream->pcm->dev,
  104613. + "Failed to set WM8804 SYSCLK: %d\n", ret);
  104614. + return ret;
  104615. + }
  104616. +
  104617. + /* Enable TX output */
  104618. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
  104619. +
  104620. + /* Power on */
  104621. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0);
  104622. +
  104623. + return snd_soc_dai_set_bclk_ratio(cpu_dai,64);
  104624. +}
  104625. +
  104626. +/* machine stream operations */
  104627. +static struct snd_soc_ops snd_rpi_hifiberry_digi_ops = {
  104628. + .hw_params = snd_rpi_hifiberry_digi_hw_params,
  104629. +};
  104630. +
  104631. +static struct snd_soc_dai_link snd_rpi_hifiberry_digi_dai[] = {
  104632. +{
  104633. + .name = "HifiBerry Digi",
  104634. + .stream_name = "HifiBerry Digi HiFi",
  104635. + .cpu_dai_name = "bcm2708-i2s.0",
  104636. + .codec_dai_name = "wm8804-spdif",
  104637. + .platform_name = "bcm2708-i2s.0",
  104638. + .codec_name = "wm8804.1-003b",
  104639. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  104640. + SND_SOC_DAIFMT_CBM_CFM,
  104641. + .ops = &snd_rpi_hifiberry_digi_ops,
  104642. + .init = snd_rpi_hifiberry_digi_init,
  104643. +},
  104644. +};
  104645. +
  104646. +/* audio machine driver */
  104647. +static struct snd_soc_card snd_rpi_hifiberry_digi = {
  104648. + .name = "snd_rpi_hifiberry_digi",
  104649. + .dai_link = snd_rpi_hifiberry_digi_dai,
  104650. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_digi_dai),
  104651. +};
  104652. +
  104653. +static int snd_rpi_hifiberry_digi_probe(struct platform_device *pdev)
  104654. +{
  104655. + int ret = 0;
  104656. +
  104657. + snd_rpi_hifiberry_digi.dev = &pdev->dev;
  104658. + ret = snd_soc_register_card(&snd_rpi_hifiberry_digi);
  104659. + if (ret)
  104660. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  104661. +
  104662. + return ret;
  104663. +}
  104664. +
  104665. +static int snd_rpi_hifiberry_digi_remove(struct platform_device *pdev)
  104666. +{
  104667. + return snd_soc_unregister_card(&snd_rpi_hifiberry_digi);
  104668. +}
  104669. +
  104670. +static struct platform_driver snd_rpi_hifiberry_digi_driver = {
  104671. + .driver = {
  104672. + .name = "snd-hifiberry-digi",
  104673. + .owner = THIS_MODULE,
  104674. + },
  104675. + .probe = snd_rpi_hifiberry_digi_probe,
  104676. + .remove = snd_rpi_hifiberry_digi_remove,
  104677. +};
  104678. +
  104679. +module_platform_driver(snd_rpi_hifiberry_digi_driver);
  104680. +
  104681. +MODULE_AUTHOR("Daniel Matuschek <info@crazy-audio.com>");
  104682. +MODULE_DESCRIPTION("ASoC Driver for HifiBerry Digi");
  104683. +MODULE_LICENSE("GPL v2");
  104684. diff -Nur linux-3.15.4/sound/soc/bcm/iqaudio-dac.c linux-rpi/sound/soc/bcm/iqaudio-dac.c
  104685. --- linux-3.15.4/sound/soc/bcm/iqaudio-dac.c 1970-01-01 01:00:00.000000000 +0100
  104686. +++ linux-rpi/sound/soc/bcm/iqaudio-dac.c 2014-07-07 10:46:03.000000000 +0200
  104687. @@ -0,0 +1,111 @@
  104688. +/*
  104689. + * ASoC Driver for IQaudIO DAC
  104690. + *
  104691. + * Author: Florian Meier <florian.meier@koalo.de>
  104692. + * Copyright 2013
  104693. + *
  104694. + * This program is free software; you can redistribute it and/or
  104695. + * modify it under the terms of the GNU General Public License
  104696. + * version 2 as published by the Free Software Foundation.
  104697. + *
  104698. + * This program is distributed in the hope that it will be useful, but
  104699. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  104700. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  104701. + * General Public License for more details.
  104702. + */
  104703. +
  104704. +#include <linux/module.h>
  104705. +#include <linux/platform_device.h>
  104706. +
  104707. +#include <sound/core.h>
  104708. +#include <sound/pcm.h>
  104709. +#include <sound/pcm_params.h>
  104710. +#include <sound/soc.h>
  104711. +#include <sound/jack.h>
  104712. +
  104713. +static int snd_rpi_iqaudio_dac_init(struct snd_soc_pcm_runtime *rtd)
  104714. +{
  104715. +// NOT USED struct snd_soc_codec *codec = rtd->codec;
  104716. +
  104717. + return 0;
  104718. +}
  104719. +
  104720. +static int snd_rpi_iqaudio_dac_hw_params(struct snd_pcm_substream *substream,
  104721. + struct snd_pcm_hw_params *params)
  104722. +{
  104723. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  104724. +// NOT USED struct snd_soc_dai *codec_dai = rtd->codec_dai;
  104725. +// NOT USED struct snd_soc_codec *codec = rtd->codec;
  104726. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  104727. +
  104728. + unsigned int sample_bits =
  104729. + snd_pcm_format_physical_width(params_format(params));
  104730. +
  104731. + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
  104732. +}
  104733. +
  104734. +/* machine stream operations */
  104735. +static struct snd_soc_ops snd_rpi_iqaudio_dac_ops = {
  104736. + .hw_params = snd_rpi_iqaudio_dac_hw_params,
  104737. +};
  104738. +
  104739. +static struct snd_soc_dai_link snd_rpi_iqaudio_dac_dai[] = {
  104740. +{
  104741. + .name = "IQaudIO DAC",
  104742. + .stream_name = "IQaudIO DAC HiFi",
  104743. + .cpu_dai_name = "bcm2708-i2s.0",
  104744. + .codec_dai_name = "pcm512x-hifi",
  104745. + .platform_name = "bcm2708-i2s.0",
  104746. + .codec_name = "pcm512x.1-004c",
  104747. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  104748. + SND_SOC_DAIFMT_CBS_CFS,
  104749. + .ops = &snd_rpi_iqaudio_dac_ops,
  104750. + .init = snd_rpi_iqaudio_dac_init,
  104751. +},
  104752. +};
  104753. +
  104754. +/* audio machine driver */
  104755. +static struct snd_soc_card snd_rpi_iqaudio_dac = {
  104756. + .name = "snd_rpi_iqaudio_dac",
  104757. + .dai_link = snd_rpi_iqaudio_dac_dai,
  104758. + .num_links = ARRAY_SIZE(snd_rpi_iqaudio_dac_dai),
  104759. +};
  104760. +
  104761. +static int snd_rpi_iqaudio_dac_probe(struct platform_device *pdev)
  104762. +{
  104763. + int ret = 0;
  104764. +
  104765. + snd_rpi_iqaudio_dac.dev = &pdev->dev;
  104766. + ret = snd_soc_register_card(&snd_rpi_iqaudio_dac);
  104767. + if (ret)
  104768. + dev_err(&pdev->dev,
  104769. + "snd_soc_register_card() failed: %d\n", ret);
  104770. +
  104771. + return ret;
  104772. +}
  104773. +
  104774. +static int snd_rpi_iqaudio_dac_remove(struct platform_device *pdev)
  104775. +{
  104776. + return snd_soc_unregister_card(&snd_rpi_iqaudio_dac);
  104777. +}
  104778. +
  104779. +static const struct of_device_id iqaudio_of_match[] = {
  104780. + { .compatible = "iqaudio,iqaudio-dac", },
  104781. + {},
  104782. +};
  104783. +
  104784. +static struct platform_driver snd_rpi_iqaudio_dac_driver = {
  104785. + .driver = {
  104786. + .name = "snd-rpi-iqaudio-dac",
  104787. + .owner = THIS_MODULE,
  104788. + .of_match_table = iqaudio_of_match,
  104789. + },
  104790. + .probe = snd_rpi_iqaudio_dac_probe,
  104791. + .remove = snd_rpi_iqaudio_dac_remove,
  104792. +};
  104793. +
  104794. +module_platform_driver(snd_rpi_iqaudio_dac_driver);
  104795. +
  104796. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  104797. +MODULE_DESCRIPTION("ASoC Driver for IQAudio DAC");
  104798. +MODULE_LICENSE("GPL v2");
  104799. diff -Nur linux-3.15.4/sound/soc/bcm/Kconfig linux-rpi/sound/soc/bcm/Kconfig
  104800. --- linux-3.15.4/sound/soc/bcm/Kconfig 2014-07-07 03:59:25.000000000 +0200
  104801. +++ linux-rpi/sound/soc/bcm/Kconfig 2014-07-07 10:46:03.000000000 +0200
  104802. @@ -7,3 +7,42 @@
  104803. Say Y or M if you want to add support for codecs attached to
  104804. the BCM2835 I2S interface. You will also need
  104805. to select the audio interfaces to support below.
  104806. +
  104807. +config SND_BCM2708_SOC_I2S
  104808. + tristate "SoC Audio support for the Broadcom BCM2708 I2S module"
  104809. + depends on MACH_BCM2708
  104810. + select REGMAP_MMIO
  104811. + select SND_SOC_DMAENGINE_PCM
  104812. + select SND_SOC_GENERIC_DMAENGINE_PCM
  104813. + help
  104814. + Say Y or M if you want to add support for codecs attached to
  104815. + the BCM2708 I2S interface. You will also need
  104816. + to select the audio interfaces to support below.
  104817. +
  104818. +config SND_BCM2708_SOC_HIFIBERRY_DAC
  104819. + tristate "Support for HifiBerry DAC"
  104820. + depends on SND_BCM2708_SOC_I2S
  104821. + select SND_SOC_PCM5102A
  104822. + help
  104823. + Say Y or M if you want to add support for HifiBerry DAC.
  104824. +
  104825. +config SND_BCM2708_SOC_HIFIBERRY_DIGI
  104826. + tristate "Support for HifiBerry Digi"
  104827. + depends on SND_BCM2708_SOC_I2S
  104828. + select SND_SOC_WM8804
  104829. + help
  104830. + Say Y or M if you want to add support for HifiBerry Digi S/PDIF output board.
  104831. +
  104832. +config SND_BCM2708_SOC_RPI_DAC
  104833. + tristate "Support for RPi-DAC"
  104834. + depends on SND_BCM2708_SOC_I2S
  104835. + select SND_SOC_PCM1794A
  104836. + help
  104837. + Say Y or M if you want to add support for RPi-DAC.
  104838. +
  104839. +config SND_BCM2708_SOC_IQAUDIO_DAC
  104840. + tristate "Support for IQaudIO-DAC"
  104841. + depends on SND_BCM2708_SOC_I2S
  104842. + select SND_SOC_PCM512x
  104843. + help
  104844. + Say Y or M if you want to add support for IQaudIO-DAC.
  104845. diff -Nur linux-3.15.4/sound/soc/bcm/Makefile linux-rpi/sound/soc/bcm/Makefile
  104846. --- linux-3.15.4/sound/soc/bcm/Makefile 2014-07-07 03:59:25.000000000 +0200
  104847. +++ linux-rpi/sound/soc/bcm/Makefile 2014-07-07 10:46:03.000000000 +0200
  104848. @@ -3,3 +3,18 @@
  104849. obj-$(CONFIG_SND_BCM2835_SOC_I2S) += snd-soc-bcm2835-i2s.o
  104850. +# BCM2708 Platform Support
  104851. +snd-soc-bcm2708-i2s-objs := bcm2708-i2s.o
  104852. +
  104853. +obj-$(CONFIG_SND_BCM2708_SOC_I2S) += snd-soc-bcm2708-i2s.o
  104854. +
  104855. +# BCM2708 Machine Support
  104856. +snd-soc-hifiberry-dac-objs := hifiberry_dac.o
  104857. +snd-soc-hifiberry-digi-objs := hifiberry_digi.o
  104858. +snd-soc-rpi-dac-objs := rpi-dac.o
  104859. +snd-soc-iqaudio-dac-objs := iqaudio-dac.o
  104860. +
  104861. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
  104862. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
  104863. +obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
  104864. +obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
  104865. diff -Nur linux-3.15.4/sound/soc/bcm/rpi-dac.c linux-rpi/sound/soc/bcm/rpi-dac.c
  104866. --- linux-3.15.4/sound/soc/bcm/rpi-dac.c 1970-01-01 01:00:00.000000000 +0100
  104867. +++ linux-rpi/sound/soc/bcm/rpi-dac.c 2014-04-13 17:33:28.000000000 +0200
  104868. @@ -0,0 +1,97 @@
  104869. +/*
  104870. + * ASoC Driver for RPi-DAC.
  104871. + *
  104872. + * Author: Florian Meier <florian.meier@koalo.de>
  104873. + * Copyright 2013
  104874. + *
  104875. + * This program is free software; you can redistribute it and/or
  104876. + * modify it under the terms of the GNU General Public License
  104877. + * version 2 as published by the Free Software Foundation.
  104878. + *
  104879. + * This program is distributed in the hope that it will be useful, but
  104880. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  104881. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  104882. + * General Public License for more details.
  104883. + */
  104884. +
  104885. +#include <linux/module.h>
  104886. +#include <linux/platform_device.h>
  104887. +
  104888. +#include <sound/core.h>
  104889. +#include <sound/pcm.h>
  104890. +#include <sound/pcm_params.h>
  104891. +#include <sound/soc.h>
  104892. +#include <sound/jack.h>
  104893. +
  104894. +static int snd_rpi_rpi_dac_init(struct snd_soc_pcm_runtime *rtd)
  104895. +{
  104896. + return 0;
  104897. +}
  104898. +
  104899. +static int snd_rpi_rpi_dac_hw_params(struct snd_pcm_substream *substream,
  104900. + struct snd_pcm_hw_params *params)
  104901. +{
  104902. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  104903. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  104904. +
  104905. + return snd_soc_dai_set_bclk_ratio(cpu_dai, 32*2);
  104906. +}
  104907. +
  104908. +/* machine stream operations */
  104909. +static struct snd_soc_ops snd_rpi_rpi_dac_ops = {
  104910. + .hw_params = snd_rpi_rpi_dac_hw_params,
  104911. +};
  104912. +
  104913. +static struct snd_soc_dai_link snd_rpi_rpi_dac_dai[] = {
  104914. +{
  104915. + .name = "HifiBerry Mini",
  104916. + .stream_name = "HifiBerry Mini HiFi",
  104917. + .cpu_dai_name = "bcm2708-i2s.0",
  104918. + .codec_dai_name = "pcm1794a-hifi",
  104919. + .platform_name = "bcm2708-i2s.0",
  104920. + .codec_name = "pcm1794a-codec",
  104921. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  104922. + SND_SOC_DAIFMT_CBS_CFS,
  104923. + .ops = &snd_rpi_rpi_dac_ops,
  104924. + .init = snd_rpi_rpi_dac_init,
  104925. +},
  104926. +};
  104927. +
  104928. +/* audio machine driver */
  104929. +static struct snd_soc_card snd_rpi_rpi_dac = {
  104930. + .name = "snd_rpi_rpi_dac",
  104931. + .dai_link = snd_rpi_rpi_dac_dai,
  104932. + .num_links = ARRAY_SIZE(snd_rpi_rpi_dac_dai),
  104933. +};
  104934. +
  104935. +static int snd_rpi_rpi_dac_probe(struct platform_device *pdev)
  104936. +{
  104937. + int ret = 0;
  104938. +
  104939. + snd_rpi_rpi_dac.dev = &pdev->dev;
  104940. + ret = snd_soc_register_card(&snd_rpi_rpi_dac);
  104941. + if (ret)
  104942. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  104943. +
  104944. + return ret;
  104945. +}
  104946. +
  104947. +static int snd_rpi_rpi_dac_remove(struct platform_device *pdev)
  104948. +{
  104949. + return snd_soc_unregister_card(&snd_rpi_rpi_dac);
  104950. +}
  104951. +
  104952. +static struct platform_driver snd_rpi_rpi_dac_driver = {
  104953. + .driver = {
  104954. + .name = "snd-rpi-dac",
  104955. + .owner = THIS_MODULE,
  104956. + },
  104957. + .probe = snd_rpi_rpi_dac_probe,
  104958. + .remove = snd_rpi_rpi_dac_remove,
  104959. +};
  104960. +
  104961. +module_platform_driver(snd_rpi_rpi_dac_driver);
  104962. +
  104963. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  104964. +MODULE_DESCRIPTION("ASoC Driver for RPi-DAC");
  104965. +MODULE_LICENSE("GPL v2");
  104966. diff -Nur linux-3.15.4/sound/soc/codecs/Kconfig linux-rpi/sound/soc/codecs/Kconfig
  104967. --- linux-3.15.4/sound/soc/codecs/Kconfig 2014-07-07 03:59:25.000000000 +0200
  104968. +++ linux-rpi/sound/soc/codecs/Kconfig 2014-07-07 10:46:03.000000000 +0200
  104969. @@ -69,6 +69,9 @@
  104970. select SND_SOC_PCM3008
  104971. select SND_SOC_PCM512x_I2C if I2C
  104972. select SND_SOC_PCM512x_SPI if SPI_MASTER
  104973. + select SND_SOC_PCM1794A
  104974. + select SND_SOC_PCM5102A
  104975. + select SND_SOC_PCM512x if SND_SOC_I2C_AND_SPI
  104976. select SND_SOC_RT5631 if I2C
  104977. select SND_SOC_RT5640 if I2C
  104978. select SND_SOC_SGTL5000 if I2C
  104979. @@ -390,6 +393,15 @@
  104980. select SND_SOC_PCM512x
  104981. select REGMAP_SPI
  104982. +config SND_SOC_PCM1794A
  104983. + tristate
  104984. +
  104985. +config SND_SOC_PCM5102A
  104986. + tristate
  104987. +
  104988. +config SND_SOC_PCM512x
  104989. + tristate
  104990. +
  104991. config SND_SOC_RT5631
  104992. tristate
  104993. diff -Nur linux-3.15.4/sound/soc/codecs/Makefile linux-rpi/sound/soc/codecs/Makefile
  104994. --- linux-3.15.4/sound/soc/codecs/Makefile 2014-07-07 03:59:25.000000000 +0200
  104995. +++ linux-rpi/sound/soc/codecs/Makefile 2014-07-07 10:46:03.000000000 +0200
  104996. @@ -58,6 +58,9 @@
  104997. snd-soc-pcm512x-objs := pcm512x.o
  104998. snd-soc-pcm512x-i2c-objs := pcm512x-i2c.o
  104999. snd-soc-pcm512x-spi-objs := pcm512x-spi.o
  105000. +snd-soc-pcm1794a-objs := pcm1794a.o
  105001. +snd-soc-pcm5102a-objs := pcm5102a.o
  105002. +snd-soc-pcm512x-objs := pcm512x.o
  105003. snd-soc-rt5631-objs := rt5631.o
  105004. snd-soc-rt5640-objs := rt5640.o
  105005. snd-soc-sgtl5000-objs := sgtl5000.o
  105006. @@ -209,6 +212,9 @@
  105007. obj-$(CONFIG_SND_SOC_PCM512x) += snd-soc-pcm512x.o
  105008. obj-$(CONFIG_SND_SOC_PCM512x_I2C) += snd-soc-pcm512x-i2c.o
  105009. obj-$(CONFIG_SND_SOC_PCM512x_SPI) += snd-soc-pcm512x-spi.o
  105010. +obj-$(CONFIG_SND_SOC_PCM1794A) += snd-soc-pcm1794a.o
  105011. +obj-$(CONFIG_SND_SOC_PCM5102A) += snd-soc-pcm5102a.o
  105012. +obj-$(CONFIG_SND_SOC_PCM512x) += snd-soc-pcm512x.o
  105013. obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o
  105014. obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o
  105015. obj-$(CONFIG_SND_SOC_SGTL5000) += snd-soc-sgtl5000.o
  105016. diff -Nur linux-3.15.4/sound/soc/codecs/pcm1794a.c linux-rpi/sound/soc/codecs/pcm1794a.c
  105017. --- linux-3.15.4/sound/soc/codecs/pcm1794a.c 1970-01-01 01:00:00.000000000 +0100
  105018. +++ linux-rpi/sound/soc/codecs/pcm1794a.c 2014-04-13 17:33:29.000000000 +0200
  105019. @@ -0,0 +1,62 @@
  105020. +/*
  105021. + * Driver for the PCM1794A codec
  105022. + *
  105023. + * Author: Florian Meier <florian.meier@koalo.de>
  105024. + * Copyright 2013
  105025. + *
  105026. + * This program is free software; you can redistribute it and/or
  105027. + * modify it under the terms of the GNU General Public License
  105028. + * version 2 as published by the Free Software Foundation.
  105029. + *
  105030. + * This program is distributed in the hope that it will be useful, but
  105031. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  105032. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  105033. + * General Public License for more details.
  105034. + */
  105035. +
  105036. +
  105037. +#include <linux/init.h>
  105038. +#include <linux/module.h>
  105039. +#include <linux/platform_device.h>
  105040. +
  105041. +#include <sound/soc.h>
  105042. +
  105043. +static struct snd_soc_dai_driver pcm1794a_dai = {
  105044. + .name = "pcm1794a-hifi",
  105045. + .playback = {
  105046. + .channels_min = 2,
  105047. + .channels_max = 2,
  105048. + .rates = SNDRV_PCM_RATE_8000_192000,
  105049. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  105050. + SNDRV_PCM_FMTBIT_S24_LE
  105051. + },
  105052. +};
  105053. +
  105054. +static struct snd_soc_codec_driver soc_codec_dev_pcm1794a;
  105055. +
  105056. +static int pcm1794a_probe(struct platform_device *pdev)
  105057. +{
  105058. + return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm1794a,
  105059. + &pcm1794a_dai, 1);
  105060. +}
  105061. +
  105062. +static int pcm1794a_remove(struct platform_device *pdev)
  105063. +{
  105064. + snd_soc_unregister_codec(&pdev->dev);
  105065. + return 0;
  105066. +}
  105067. +
  105068. +static struct platform_driver pcm1794a_codec_driver = {
  105069. + .probe = pcm1794a_probe,
  105070. + .remove = pcm1794a_remove,
  105071. + .driver = {
  105072. + .name = "pcm1794a-codec",
  105073. + .owner = THIS_MODULE,
  105074. + },
  105075. +};
  105076. +
  105077. +module_platform_driver(pcm1794a_codec_driver);
  105078. +
  105079. +MODULE_DESCRIPTION("ASoC PCM1794A codec driver");
  105080. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  105081. +MODULE_LICENSE("GPL v2");
  105082. diff -Nur linux-3.15.4/sound/soc/codecs/pcm5102a.c linux-rpi/sound/soc/codecs/pcm5102a.c
  105083. --- linux-3.15.4/sound/soc/codecs/pcm5102a.c 1970-01-01 01:00:00.000000000 +0100
  105084. +++ linux-rpi/sound/soc/codecs/pcm5102a.c 2014-04-13 17:33:29.000000000 +0200
  105085. @@ -0,0 +1,63 @@
  105086. +/*
  105087. + * Driver for the PCM5102A codec
  105088. + *
  105089. + * Author: Florian Meier <florian.meier@koalo.de>
  105090. + * Copyright 2013
  105091. + *
  105092. + * This program is free software; you can redistribute it and/or
  105093. + * modify it under the terms of the GNU General Public License
  105094. + * version 2 as published by the Free Software Foundation.
  105095. + *
  105096. + * This program is distributed in the hope that it will be useful, but
  105097. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  105098. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  105099. + * General Public License for more details.
  105100. + */
  105101. +
  105102. +
  105103. +#include <linux/init.h>
  105104. +#include <linux/module.h>
  105105. +#include <linux/platform_device.h>
  105106. +
  105107. +#include <sound/soc.h>
  105108. +
  105109. +static struct snd_soc_dai_driver pcm5102a_dai = {
  105110. + .name = "pcm5102a-hifi",
  105111. + .playback = {
  105112. + .channels_min = 2,
  105113. + .channels_max = 2,
  105114. + .rates = SNDRV_PCM_RATE_8000_192000,
  105115. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  105116. + // SNDRV_PCM_FMTBIT_S24_LE | : disable for now, it causes white noise with xbmc
  105117. + SNDRV_PCM_FMTBIT_S32_LE
  105118. + },
  105119. +};
  105120. +
  105121. +static struct snd_soc_codec_driver soc_codec_dev_pcm5102a;
  105122. +
  105123. +static int pcm5102a_probe(struct platform_device *pdev)
  105124. +{
  105125. + return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm5102a,
  105126. + &pcm5102a_dai, 1);
  105127. +}
  105128. +
  105129. +static int pcm5102a_remove(struct platform_device *pdev)
  105130. +{
  105131. + snd_soc_unregister_codec(&pdev->dev);
  105132. + return 0;
  105133. +}
  105134. +
  105135. +static struct platform_driver pcm5102a_codec_driver = {
  105136. + .probe = pcm5102a_probe,
  105137. + .remove = pcm5102a_remove,
  105138. + .driver = {
  105139. + .name = "pcm5102a-codec",
  105140. + .owner = THIS_MODULE,
  105141. + },
  105142. +};
  105143. +
  105144. +module_platform_driver(pcm5102a_codec_driver);
  105145. +
  105146. +MODULE_DESCRIPTION("ASoC PCM5102A codec driver");
  105147. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  105148. +MODULE_LICENSE("GPL v2");
  105149. diff -Nur linux-3.15.4/sound/soc/codecs/pcm512x.c linux-rpi/sound/soc/codecs/pcm512x.c
  105150. --- linux-3.15.4/sound/soc/codecs/pcm512x.c 2014-07-07 03:59:25.000000000 +0200
  105151. +++ linux-rpi/sound/soc/codecs/pcm512x.c 2014-07-07 10:46:03.000000000 +0200
  105152. @@ -18,9 +18,11 @@
  105153. #include <linux/init.h>
  105154. #include <linux/module.h>
  105155. #include <linux/clk.h>
  105156. +#include <linux/i2c.h>
  105157. #include <linux/pm_runtime.h>
  105158. #include <linux/regmap.h>
  105159. #include <linux/regulator/consumer.h>
  105160. +#include <linux/spi/spi.h>
  105161. #include <sound/soc.h>
  105162. #include <sound/soc-dapm.h>
  105163. #include <sound/tlv.h>
  105164. @@ -28,7 +30,7 @@
  105165. #include "pcm512x.h"
  105166. #define PCM512x_NUM_SUPPLIES 3
  105167. -static const char * const pcm512x_supply_names[PCM512x_NUM_SUPPLIES] = {
  105168. +static const char *pcm512x_supply_names[PCM512x_NUM_SUPPLIES] = {
  105169. "AVDD",
  105170. "DVDD",
  105171. "CPVDD",
  105172. @@ -64,29 +66,22 @@
  105173. PCM512x_REGULATOR_EVENT(2)
  105174. static const struct reg_default pcm512x_reg_defaults[] = {
  105175. - { PCM512x_RESET, 0x00 },
  105176. - { PCM512x_POWER, 0x00 },
  105177. - { PCM512x_MUTE, 0x00 },
  105178. - { PCM512x_DSP, 0x00 },
  105179. - { PCM512x_PLL_REF, 0x00 },
  105180. - { PCM512x_DAC_ROUTING, 0x11 },
  105181. - { PCM512x_DSP_PROGRAM, 0x01 },
  105182. - { PCM512x_CLKDET, 0x00 },
  105183. - { PCM512x_AUTO_MUTE, 0x00 },
  105184. - { PCM512x_ERROR_DETECT, 0x00 },
  105185. - { PCM512x_DIGITAL_VOLUME_1, 0x00 },
  105186. - { PCM512x_DIGITAL_VOLUME_2, 0x30 },
  105187. - { PCM512x_DIGITAL_VOLUME_3, 0x30 },
  105188. - { PCM512x_DIGITAL_MUTE_1, 0x22 },
  105189. - { PCM512x_DIGITAL_MUTE_2, 0x00 },
  105190. - { PCM512x_DIGITAL_MUTE_3, 0x07 },
  105191. - { PCM512x_OUTPUT_AMPLITUDE, 0x00 },
  105192. - { PCM512x_ANALOG_GAIN_CTRL, 0x00 },
  105193. - { PCM512x_UNDERVOLTAGE_PROT, 0x00 },
  105194. - { PCM512x_ANALOG_MUTE_CTRL, 0x00 },
  105195. - { PCM512x_ANALOG_GAIN_BOOST, 0x00 },
  105196. - { PCM512x_VCOM_CTRL_1, 0x00 },
  105197. - { PCM512x_VCOM_CTRL_2, 0x01 },
  105198. + { PCM512x_RESET, 0x00 },
  105199. + { PCM512x_POWER, 0x00 },
  105200. + { PCM512x_MUTE, 0x00 },
  105201. + { PCM512x_DSP, 0x00 },
  105202. + { PCM512x_PLL_REF, 0x00 },
  105203. + { PCM512x_DAC_ROUTING, 0x11 },
  105204. + { PCM512x_DSP_PROGRAM, 0x01 },
  105205. + { PCM512x_CLKDET, 0x00 },
  105206. + { PCM512x_AUTO_MUTE, 0x00 },
  105207. + { PCM512x_ERROR_DETECT, 0x00 },
  105208. + { PCM512x_DIGITAL_VOLUME_1, 0x00 },
  105209. + { PCM512x_DIGITAL_VOLUME_2, 0x30 },
  105210. + { PCM512x_DIGITAL_VOLUME_3, 0x30 },
  105211. + { PCM512x_DIGITAL_MUTE_1, 0x22 },
  105212. + { PCM512x_DIGITAL_MUTE_2, 0x00 },
  105213. + { PCM512x_DIGITAL_MUTE_3, 0x07 },
  105214. };
  105215. static bool pcm512x_readable(struct device *dev, unsigned int reg)
  105216. @@ -146,18 +141,9 @@
  105217. case PCM512x_ANALOG_MUTE_DET:
  105218. case PCM512x_GPIN:
  105219. case PCM512x_DIGITAL_MUTE_DET:
  105220. - case PCM512x_OUTPUT_AMPLITUDE:
  105221. - case PCM512x_ANALOG_GAIN_CTRL:
  105222. - case PCM512x_UNDERVOLTAGE_PROT:
  105223. - case PCM512x_ANALOG_MUTE_CTRL:
  105224. - case PCM512x_ANALOG_GAIN_BOOST:
  105225. - case PCM512x_VCOM_CTRL_1:
  105226. - case PCM512x_VCOM_CTRL_2:
  105227. - case PCM512x_CRAM_CTRL:
  105228. return true;
  105229. default:
  105230. - /* There are 256 raw register addresses */
  105231. - return reg < 0xff;
  105232. + return false;
  105233. }
  105234. }
  105235. @@ -173,22 +159,17 @@
  105236. case PCM512x_ANALOG_MUTE_DET:
  105237. case PCM512x_GPIN:
  105238. case PCM512x_DIGITAL_MUTE_DET:
  105239. - case PCM512x_CRAM_CTRL:
  105240. return true;
  105241. default:
  105242. - /* There are 256 raw register addresses */
  105243. - return reg < 0xff;
  105244. + return false;
  105245. }
  105246. }
  105247. static const DECLARE_TLV_DB_SCALE(digital_tlv, -10350, 50, 1);
  105248. -static const DECLARE_TLV_DB_SCALE(analog_tlv, -600, 600, 0);
  105249. -static const DECLARE_TLV_DB_SCALE(boost_tlv, 0, 80, 0);
  105250. -static const char * const pcm512x_dsp_program_texts[] = {
  105251. +static const char *pcm512x_dsp_program_texts[] = {
  105252. "FIR interpolation with de-emphasis",
  105253. "Low latency IIR with de-emphasis",
  105254. - "Fixed process flow",
  105255. "High attenuation with de-emphasis",
  105256. "Ringing-less low latency FIR",
  105257. };
  105258. @@ -201,31 +182,31 @@
  105259. 7,
  105260. };
  105261. -static SOC_VALUE_ENUM_SINGLE_DECL(pcm512x_dsp_program,
  105262. - PCM512x_DSP_PROGRAM, 0, 0x1f,
  105263. - pcm512x_dsp_program_texts,
  105264. - pcm512x_dsp_program_values);
  105265. +static const SOC_VALUE_ENUM_SINGLE_DECL(pcm512x_dsp_program,
  105266. + PCM512x_DSP_PROGRAM, 0, 0x1f,
  105267. + pcm512x_dsp_program_texts,
  105268. + pcm512x_dsp_program_values);
  105269. -static const char * const pcm512x_clk_missing_text[] = {
  105270. +static const char *pcm512x_clk_missing_text[] = {
  105271. "1s", "2s", "3s", "4s", "5s", "6s", "7s", "8s"
  105272. };
  105273. static const struct soc_enum pcm512x_clk_missing =
  105274. - SOC_ENUM_SINGLE(PCM512x_CLKDET, 0, 8, pcm512x_clk_missing_text);
  105275. + SOC_ENUM_SINGLE(PCM512x_CLKDET, 0, 7, pcm512x_clk_missing_text);
  105276. -static const char * const pcm512x_autom_text[] = {
  105277. +static const char *pcm512x_autom_text[] = {
  105278. "21ms", "106ms", "213ms", "533ms", "1.07s", "2.13s", "5.33s", "10.66s"
  105279. };
  105280. static const struct soc_enum pcm512x_autom_l =
  105281. - SOC_ENUM_SINGLE(PCM512x_AUTO_MUTE, PCM512x_ATML_SHIFT, 8,
  105282. + SOC_ENUM_SINGLE(PCM512x_AUTO_MUTE, PCM512x_ATML_SHIFT, 7,
  105283. pcm512x_autom_text);
  105284. static const struct soc_enum pcm512x_autom_r =
  105285. - SOC_ENUM_SINGLE(PCM512x_AUTO_MUTE, PCM512x_ATMR_SHIFT, 8,
  105286. + SOC_ENUM_SINGLE(PCM512x_AUTO_MUTE, PCM512x_ATMR_SHIFT, 7,
  105287. pcm512x_autom_text);
  105288. -static const char * const pcm512x_ramp_rate_text[] = {
  105289. +static const char *pcm512x_ramp_rate_text[] = {
  105290. "1 sample/update", "2 samples/update", "4 samples/update",
  105291. "Immediate"
  105292. };
  105293. @@ -242,7 +223,7 @@
  105294. SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_2, PCM512x_VEDF_SHIFT, 4,
  105295. pcm512x_ramp_rate_text);
  105296. -static const char * const pcm512x_ramp_step_text[] = {
  105297. +static const char *pcm512x_ramp_step_text[] = {
  105298. "4dB/step", "2dB/step", "1dB/step", "0.5dB/step"
  105299. };
  105300. @@ -258,13 +239,10 @@
  105301. SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_2, PCM512x_VEDS_SHIFT, 4,
  105302. pcm512x_ramp_step_text);
  105303. +/* Don't let the DAC go into clipping by limiting the alsa volume control range */
  105304. static const struct snd_kcontrol_new pcm512x_controls[] = {
  105305. -SOC_DOUBLE_R_TLV("Playback Digital Volume", PCM512x_DIGITAL_VOLUME_2,
  105306. - PCM512x_DIGITAL_VOLUME_3, 0, 255, 1, digital_tlv),
  105307. -SOC_DOUBLE_TLV("Playback Volume", PCM512x_ANALOG_GAIN_CTRL,
  105308. - PCM512x_LAGN_SHIFT, PCM512x_RAGN_SHIFT, 1, 1, analog_tlv),
  105309. -SOC_DOUBLE_TLV("Playback Boost Volume", PCM512x_ANALOG_GAIN_BOOST,
  105310. - PCM512x_AGBL_SHIFT, PCM512x_AGBR_SHIFT, 1, 0, boost_tlv),
  105311. +SOC_DOUBLE_R_RANGE_TLV("Playback Digital Volume", PCM512x_DIGITAL_VOLUME_2,
  105312. + PCM512x_DIGITAL_VOLUME_3, 0, 40, 255, 1, digital_tlv),
  105313. SOC_DOUBLE("Playback Digital Switch", PCM512x_MUTE, PCM512x_RQML_SHIFT,
  105314. PCM512x_RQMR_SHIFT, 1, 1),
  105315. @@ -365,32 +343,27 @@
  105316. .num_dapm_routes = ARRAY_SIZE(pcm512x_dapm_routes),
  105317. };
  105318. -static const struct regmap_range_cfg pcm512x_range = {
  105319. - .name = "Pages", .range_min = PCM512x_VIRT_BASE,
  105320. - .range_max = PCM512x_MAX_REGISTER,
  105321. - .selector_reg = PCM512x_PAGE,
  105322. - .selector_mask = 0xff,
  105323. - .window_start = 0, .window_len = 0x100,
  105324. -};
  105325. -
  105326. -const struct regmap_config pcm512x_regmap = {
  105327. +static const struct regmap_config pcm512x_regmap = {
  105328. .reg_bits = 8,
  105329. .val_bits = 8,
  105330. .readable_reg = pcm512x_readable,
  105331. .volatile_reg = pcm512x_volatile,
  105332. - .ranges = &pcm512x_range,
  105333. - .num_ranges = 1,
  105334. -
  105335. .max_register = PCM512x_MAX_REGISTER,
  105336. .reg_defaults = pcm512x_reg_defaults,
  105337. .num_reg_defaults = ARRAY_SIZE(pcm512x_reg_defaults),
  105338. .cache_type = REGCACHE_RBTREE,
  105339. };
  105340. -EXPORT_SYMBOL_GPL(pcm512x_regmap);
  105341. -int pcm512x_probe(struct device *dev, struct regmap *regmap)
  105342. +static const struct of_device_id pcm512x_of_match[] = {
  105343. + { .compatible = "ti,pcm5121", },
  105344. + { .compatible = "ti,pcm5122", },
  105345. + { }
  105346. +};
  105347. +MODULE_DEVICE_TABLE(of, pcm512x_of_match);
  105348. +
  105349. +static int pcm512x_probe(struct device *dev, struct regmap *regmap)
  105350. {
  105351. struct pcm512x_priv *pcm512x;
  105352. int i, ret;
  105353. @@ -490,6 +463,8 @@
  105354. goto err_pm;
  105355. }
  105356. + dev_info(dev, "Completed initialisation - pcm512x_probe");
  105357. +
  105358. return 0;
  105359. err_pm:
  105360. @@ -502,9 +477,8 @@
  105361. pcm512x->supplies);
  105362. return ret;
  105363. }
  105364. -EXPORT_SYMBOL_GPL(pcm512x_probe);
  105365. -void pcm512x_remove(struct device *dev)
  105366. +static void pcm512x_remove(struct device *dev)
  105367. {
  105368. struct pcm512x_priv *pcm512x = dev_get_drvdata(dev);
  105369. @@ -515,8 +489,8 @@
  105370. regulator_bulk_disable(ARRAY_SIZE(pcm512x->supplies),
  105371. pcm512x->supplies);
  105372. }
  105373. -EXPORT_SYMBOL_GPL(pcm512x_remove);
  105374. +/* TODO
  105375. static int pcm512x_suspend(struct device *dev)
  105376. {
  105377. struct pcm512x_priv *pcm512x = dev_get_drvdata(dev);
  105378. @@ -579,10 +553,125 @@
  105379. return 0;
  105380. }
  105381. -const struct dev_pm_ops pcm512x_pm_ops = {
  105382. +// END OF PCM512x_suspend and resume calls TODO
  105383. +*/
  105384. +
  105385. +static const struct dev_pm_ops pcm512x_pm_ops = {
  105386. SET_RUNTIME_PM_OPS(pcm512x_suspend, pcm512x_resume, NULL)
  105387. };
  105388. -EXPORT_SYMBOL_GPL(pcm512x_pm_ops);
  105389. +
  105390. +#if IS_ENABLED(CONFIG_I2C)
  105391. +static int pcm512x_i2c_probe(struct i2c_client *i2c,
  105392. + const struct i2c_device_id *id)
  105393. +{
  105394. + struct regmap *regmap;
  105395. +
  105396. + regmap = devm_regmap_init_i2c(i2c, &pcm512x_regmap);
  105397. + if (IS_ERR(regmap))
  105398. + return PTR_ERR(regmap);
  105399. +
  105400. + return pcm512x_probe(&i2c->dev, regmap);
  105401. +}
  105402. +
  105403. +static int pcm512x_i2c_remove(struct i2c_client *i2c)
  105404. +{
  105405. + pcm512x_remove(&i2c->dev);
  105406. + return 0;
  105407. +}
  105408. +
  105409. +static const struct i2c_device_id pcm512x_i2c_id[] = {
  105410. + { "pcm5121", },
  105411. + { "pcm5122", },
  105412. + { }
  105413. +};
  105414. +MODULE_DEVICE_TABLE(i2c, pcm512x_i2c_id);
  105415. +
  105416. +static struct i2c_driver pcm512x_i2c_driver = {
  105417. + .probe = pcm512x_i2c_probe,
  105418. + .remove = pcm512x_i2c_remove,
  105419. + .id_table = pcm512x_i2c_id,
  105420. + .driver = {
  105421. + .name = "pcm512x",
  105422. + .owner = THIS_MODULE,
  105423. + .of_match_table = pcm512x_of_match,
  105424. + .pm = &pcm512x_pm_ops,
  105425. + },
  105426. +};
  105427. +#endif
  105428. +
  105429. +#if defined(CONFIG_SPI_MASTER)
  105430. +static int pcm512x_spi_probe(struct spi_device *spi)
  105431. +{
  105432. + struct regmap *regmap;
  105433. + int ret;
  105434. +
  105435. + regmap = devm_regmap_init_spi(spi, &pcm512x_regmap);
  105436. + if (IS_ERR(regmap)) {
  105437. + ret = PTR_ERR(regmap);
  105438. + return ret;
  105439. + }
  105440. +
  105441. + return pcm512x_probe(&spi->dev, regmap);
  105442. +}
  105443. +
  105444. +static int pcm512x_spi_remove(struct spi_device *spi)
  105445. +{
  105446. + pcm512x_remove(&spi->dev);
  105447. + return 0;
  105448. +}
  105449. +
  105450. +static const struct spi_device_id pcm512x_spi_id[] = {
  105451. + { "pcm5121", },
  105452. + { "pcm5122", },
  105453. + { },
  105454. +};
  105455. +MODULE_DEVICE_TABLE(spi, pcm512x_spi_id);
  105456. +
  105457. +static struct spi_driver pcm512x_spi_driver = {
  105458. + .probe = pcm512x_spi_probe,
  105459. + .remove = pcm512x_spi_remove,
  105460. + .id_table = pcm512x_spi_id,
  105461. + .driver = {
  105462. + .name = "pcm512x",
  105463. + .owner = THIS_MODULE,
  105464. + .of_match_table = pcm512x_of_match,
  105465. + .pm = &pcm512x_pm_ops,
  105466. + },
  105467. +};
  105468. +#endif
  105469. +
  105470. +static int __init pcm512x_modinit(void)
  105471. +{
  105472. + int ret = 0;
  105473. +
  105474. +#if IS_ENABLED(CONFIG_I2C)
  105475. + ret = i2c_add_driver(&pcm512x_i2c_driver);
  105476. + if (ret) {
  105477. + printk(KERN_ERR "Failed to register pcm512x I2C driver: %d\n",
  105478. + ret);
  105479. + }
  105480. +#endif
  105481. +#if defined(CONFIG_SPI_MASTER)
  105482. + ret = spi_register_driver(&pcm512x_spi_driver);
  105483. + if (ret != 0) {
  105484. + printk(KERN_ERR "Failed to register pcm512x SPI driver: %d\n",
  105485. + ret);
  105486. + }
  105487. +#endif
  105488. + return ret;
  105489. +}
  105490. +module_init(pcm512x_modinit);
  105491. +
  105492. +static void __exit pcm512x_exit(void)
  105493. +{
  105494. +#if IS_ENABLED(CONFIG_I2C)
  105495. + i2c_del_driver(&pcm512x_i2c_driver);
  105496. +#endif
  105497. +#if defined(CONFIG_SPI_MASTER)
  105498. + spi_unregister_driver(&pcm512x_spi_driver);
  105499. +#endif
  105500. +}
  105501. +module_exit(pcm512x_exit);
  105502. MODULE_DESCRIPTION("ASoC PCM512x codec driver");
  105503. MODULE_AUTHOR("Mark Brown <broonie@linaro.org>");
  105504. diff -Nur linux-3.15.4/sound/soc/codecs/pcm512x.h linux-rpi/sound/soc/codecs/pcm512x.h
  105505. --- linux-3.15.4/sound/soc/codecs/pcm512x.h 2014-07-07 03:59:25.000000000 +0200
  105506. +++ linux-rpi/sound/soc/codecs/pcm512x.h 2014-04-13 17:33:29.000000000 +0200
  105507. @@ -17,81 +17,66 @@
  105508. #ifndef _SND_SOC_PCM512X
  105509. #define _SND_SOC_PCM512X
  105510. -#include <linux/pm.h>
  105511. -#include <linux/regmap.h>
  105512. -
  105513. -#define PCM512x_VIRT_BASE 0x100
  105514. -#define PCM512x_PAGE_LEN 0x100
  105515. -#define PCM512x_PAGE_BASE(n) (PCM512x_VIRT_BASE + (PCM512x_PAGE_LEN * n))
  105516. +#define PCM512x_PAGE_0_BASE 0
  105517. #define PCM512x_PAGE 0
  105518. -#define PCM512x_RESET (PCM512x_PAGE_BASE(0) + 1)
  105519. -#define PCM512x_POWER (PCM512x_PAGE_BASE(0) + 2)
  105520. -#define PCM512x_MUTE (PCM512x_PAGE_BASE(0) + 3)
  105521. -#define PCM512x_PLL_EN (PCM512x_PAGE_BASE(0) + 4)
  105522. -#define PCM512x_SPI_MISO_FUNCTION (PCM512x_PAGE_BASE(0) + 6)
  105523. -#define PCM512x_DSP (PCM512x_PAGE_BASE(0) + 7)
  105524. -#define PCM512x_GPIO_EN (PCM512x_PAGE_BASE(0) + 8)
  105525. -#define PCM512x_BCLK_LRCLK_CFG (PCM512x_PAGE_BASE(0) + 9)
  105526. -#define PCM512x_DSP_GPIO_INPUT (PCM512x_PAGE_BASE(0) + 10)
  105527. -#define PCM512x_MASTER_MODE (PCM512x_PAGE_BASE(0) + 12)
  105528. -#define PCM512x_PLL_REF (PCM512x_PAGE_BASE(0) + 13)
  105529. -#define PCM512x_PLL_COEFF_0 (PCM512x_PAGE_BASE(0) + 20)
  105530. -#define PCM512x_PLL_COEFF_1 (PCM512x_PAGE_BASE(0) + 21)
  105531. -#define PCM512x_PLL_COEFF_2 (PCM512x_PAGE_BASE(0) + 22)
  105532. -#define PCM512x_PLL_COEFF_3 (PCM512x_PAGE_BASE(0) + 23)
  105533. -#define PCM512x_PLL_COEFF_4 (PCM512x_PAGE_BASE(0) + 24)
  105534. -#define PCM512x_DSP_CLKDIV (PCM512x_PAGE_BASE(0) + 27)
  105535. -#define PCM512x_DAC_CLKDIV (PCM512x_PAGE_BASE(0) + 28)
  105536. -#define PCM512x_NCP_CLKDIV (PCM512x_PAGE_BASE(0) + 29)
  105537. -#define PCM512x_OSR_CLKDIV (PCM512x_PAGE_BASE(0) + 30)
  105538. -#define PCM512x_MASTER_CLKDIV_1 (PCM512x_PAGE_BASE(0) + 32)
  105539. -#define PCM512x_MASTER_CLKDIV_2 (PCM512x_PAGE_BASE(0) + 33)
  105540. -#define PCM512x_FS_SPEED_MODE (PCM512x_PAGE_BASE(0) + 34)
  105541. -#define PCM512x_IDAC_1 (PCM512x_PAGE_BASE(0) + 35)
  105542. -#define PCM512x_IDAC_2 (PCM512x_PAGE_BASE(0) + 36)
  105543. -#define PCM512x_ERROR_DETECT (PCM512x_PAGE_BASE(0) + 37)
  105544. -#define PCM512x_I2S_1 (PCM512x_PAGE_BASE(0) + 40)
  105545. -#define PCM512x_I2S_2 (PCM512x_PAGE_BASE(0) + 41)
  105546. -#define PCM512x_DAC_ROUTING (PCM512x_PAGE_BASE(0) + 42)
  105547. -#define PCM512x_DSP_PROGRAM (PCM512x_PAGE_BASE(0) + 43)
  105548. -#define PCM512x_CLKDET (PCM512x_PAGE_BASE(0) + 44)
  105549. -#define PCM512x_AUTO_MUTE (PCM512x_PAGE_BASE(0) + 59)
  105550. -#define PCM512x_DIGITAL_VOLUME_1 (PCM512x_PAGE_BASE(0) + 60)
  105551. -#define PCM512x_DIGITAL_VOLUME_2 (PCM512x_PAGE_BASE(0) + 61)
  105552. -#define PCM512x_DIGITAL_VOLUME_3 (PCM512x_PAGE_BASE(0) + 62)
  105553. -#define PCM512x_DIGITAL_MUTE_1 (PCM512x_PAGE_BASE(0) + 63)
  105554. -#define PCM512x_DIGITAL_MUTE_2 (PCM512x_PAGE_BASE(0) + 64)
  105555. -#define PCM512x_DIGITAL_MUTE_3 (PCM512x_PAGE_BASE(0) + 65)
  105556. -#define PCM512x_GPIO_OUTPUT_1 (PCM512x_PAGE_BASE(0) + 80)
  105557. -#define PCM512x_GPIO_OUTPUT_2 (PCM512x_PAGE_BASE(0) + 81)
  105558. -#define PCM512x_GPIO_OUTPUT_3 (PCM512x_PAGE_BASE(0) + 82)
  105559. -#define PCM512x_GPIO_OUTPUT_4 (PCM512x_PAGE_BASE(0) + 83)
  105560. -#define PCM512x_GPIO_OUTPUT_5 (PCM512x_PAGE_BASE(0) + 84)
  105561. -#define PCM512x_GPIO_OUTPUT_6 (PCM512x_PAGE_BASE(0) + 85)
  105562. -#define PCM512x_GPIO_CONTROL_1 (PCM512x_PAGE_BASE(0) + 86)
  105563. -#define PCM512x_GPIO_CONTROL_2 (PCM512x_PAGE_BASE(0) + 87)
  105564. -#define PCM512x_OVERFLOW (PCM512x_PAGE_BASE(0) + 90)
  105565. -#define PCM512x_RATE_DET_1 (PCM512x_PAGE_BASE(0) + 91)
  105566. -#define PCM512x_RATE_DET_2 (PCM512x_PAGE_BASE(0) + 92)
  105567. -#define PCM512x_RATE_DET_3 (PCM512x_PAGE_BASE(0) + 93)
  105568. -#define PCM512x_RATE_DET_4 (PCM512x_PAGE_BASE(0) + 94)
  105569. -#define PCM512x_ANALOG_MUTE_DET (PCM512x_PAGE_BASE(0) + 108)
  105570. -#define PCM512x_GPIN (PCM512x_PAGE_BASE(0) + 119)
  105571. -#define PCM512x_DIGITAL_MUTE_DET (PCM512x_PAGE_BASE(0) + 120)
  105572. -
  105573. -#define PCM512x_OUTPUT_AMPLITUDE (PCM512x_PAGE_BASE(1) + 1)
  105574. -#define PCM512x_ANALOG_GAIN_CTRL (PCM512x_PAGE_BASE(1) + 2)
  105575. -#define PCM512x_UNDERVOLTAGE_PROT (PCM512x_PAGE_BASE(1) + 5)
  105576. -#define PCM512x_ANALOG_MUTE_CTRL (PCM512x_PAGE_BASE(1) + 6)
  105577. -#define PCM512x_ANALOG_GAIN_BOOST (PCM512x_PAGE_BASE(1) + 7)
  105578. -#define PCM512x_VCOM_CTRL_1 (PCM512x_PAGE_BASE(1) + 8)
  105579. -#define PCM512x_VCOM_CTRL_2 (PCM512x_PAGE_BASE(1) + 9)
  105580. -
  105581. -#define PCM512x_CRAM_CTRL (PCM512x_PAGE_BASE(44) + 1)
  105582. +#define PCM512x_RESET (PCM512x_PAGE_0_BASE + 1)
  105583. +#define PCM512x_POWER (PCM512x_PAGE_0_BASE + 2)
  105584. +#define PCM512x_MUTE (PCM512x_PAGE_0_BASE + 3)
  105585. +#define PCM512x_PLL_EN (PCM512x_PAGE_0_BASE + 4)
  105586. +#define PCM512x_SPI_MISO_FUNCTION (PCM512x_PAGE_0_BASE + 6)
  105587. +#define PCM512x_DSP (PCM512x_PAGE_0_BASE + 7)
  105588. +#define PCM512x_GPIO_EN (PCM512x_PAGE_0_BASE + 8)
  105589. +#define PCM512x_BCLK_LRCLK_CFG (PCM512x_PAGE_0_BASE + 9)
  105590. +#define PCM512x_DSP_GPIO_INPUT (PCM512x_PAGE_0_BASE + 10)
  105591. +#define PCM512x_MASTER_MODE (PCM512x_PAGE_0_BASE + 12)
  105592. +#define PCM512x_PLL_REF (PCM512x_PAGE_0_BASE + 13)
  105593. +#define PCM512x_PLL_COEFF_0 (PCM512x_PAGE_0_BASE + 20)
  105594. +#define PCM512x_PLL_COEFF_1 (PCM512x_PAGE_0_BASE + 21)
  105595. +#define PCM512x_PLL_COEFF_2 (PCM512x_PAGE_0_BASE + 22)
  105596. +#define PCM512x_PLL_COEFF_3 (PCM512x_PAGE_0_BASE + 23)
  105597. +#define PCM512x_PLL_COEFF_4 (PCM512x_PAGE_0_BASE + 24)
  105598. +#define PCM512x_DSP_CLKDIV (PCM512x_PAGE_0_BASE + 27)
  105599. +#define PCM512x_DAC_CLKDIV (PCM512x_PAGE_0_BASE + 28)
  105600. +#define PCM512x_NCP_CLKDIV (PCM512x_PAGE_0_BASE + 29)
  105601. +#define PCM512x_OSR_CLKDIV (PCM512x_PAGE_0_BASE + 30)
  105602. +#define PCM512x_MASTER_CLKDIV_1 (PCM512x_PAGE_0_BASE + 32)
  105603. +#define PCM512x_MASTER_CLKDIV_2 (PCM512x_PAGE_0_BASE + 33)
  105604. +#define PCM512x_FS_SPEED_MODE (PCM512x_PAGE_0_BASE + 34)
  105605. +#define PCM512x_IDAC_1 (PCM512x_PAGE_0_BASE + 35)
  105606. +#define PCM512x_IDAC_2 (PCM512x_PAGE_0_BASE + 36)
  105607. +#define PCM512x_ERROR_DETECT (PCM512x_PAGE_0_BASE + 37)
  105608. +#define PCM512x_I2S_1 (PCM512x_PAGE_0_BASE + 40)
  105609. +#define PCM512x_I2S_2 (PCM512x_PAGE_0_BASE + 41)
  105610. +#define PCM512x_DAC_ROUTING (PCM512x_PAGE_0_BASE + 42)
  105611. +#define PCM512x_DSP_PROGRAM (PCM512x_PAGE_0_BASE + 43)
  105612. +#define PCM512x_CLKDET (PCM512x_PAGE_0_BASE + 44)
  105613. +#define PCM512x_AUTO_MUTE (PCM512x_PAGE_0_BASE + 59)
  105614. +#define PCM512x_DIGITAL_VOLUME_1 (PCM512x_PAGE_0_BASE + 60)
  105615. +#define PCM512x_DIGITAL_VOLUME_2 (PCM512x_PAGE_0_BASE + 61)
  105616. +#define PCM512x_DIGITAL_VOLUME_3 (PCM512x_PAGE_0_BASE + 62)
  105617. +#define PCM512x_DIGITAL_MUTE_1 (PCM512x_PAGE_0_BASE + 63)
  105618. +#define PCM512x_DIGITAL_MUTE_2 (PCM512x_PAGE_0_BASE + 64)
  105619. +#define PCM512x_DIGITAL_MUTE_3 (PCM512x_PAGE_0_BASE + 65)
  105620. +#define PCM512x_GPIO_OUTPUT_1 (PCM512x_PAGE_0_BASE + 80)
  105621. +#define PCM512x_GPIO_OUTPUT_2 (PCM512x_PAGE_0_BASE + 81)
  105622. +#define PCM512x_GPIO_OUTPUT_3 (PCM512x_PAGE_0_BASE + 82)
  105623. +#define PCM512x_GPIO_OUTPUT_4 (PCM512x_PAGE_0_BASE + 83)
  105624. +#define PCM512x_GPIO_OUTPUT_5 (PCM512x_PAGE_0_BASE + 84)
  105625. +#define PCM512x_GPIO_OUTPUT_6 (PCM512x_PAGE_0_BASE + 85)
  105626. +#define PCM512x_GPIO_CONTROL_1 (PCM512x_PAGE_0_BASE + 86)
  105627. +#define PCM512x_GPIO_CONTROL_2 (PCM512x_PAGE_0_BASE + 87)
  105628. +#define PCM512x_OVERFLOW (PCM512x_PAGE_0_BASE + 90)
  105629. +#define PCM512x_RATE_DET_1 (PCM512x_PAGE_0_BASE + 91)
  105630. +#define PCM512x_RATE_DET_2 (PCM512x_PAGE_0_BASE + 92)
  105631. +#define PCM512x_RATE_DET_3 (PCM512x_PAGE_0_BASE + 93)
  105632. +#define PCM512x_RATE_DET_4 (PCM512x_PAGE_0_BASE + 94)
  105633. +#define PCM512x_ANALOG_MUTE_DET (PCM512x_PAGE_0_BASE + 108)
  105634. +#define PCM512x_GPIN (PCM512x_PAGE_0_BASE + 119)
  105635. +#define PCM512x_DIGITAL_MUTE_DET (PCM512x_PAGE_0_BASE + 120)
  105636. -#define PCM512x_MAX_REGISTER (PCM512x_PAGE_BASE(44) + 1)
  105637. +#define PCM512x_MAX_REGISTER (PCM512x_PAGE_0_BASE + 120)
  105638. /* Page 0, Register 1 - reset */
  105639. #define PCM512x_RSTR (1 << 0)
  105640. @@ -154,18 +139,4 @@
  105641. #define PCM512x_AMLE_SHIFT 1
  105642. #define PCM512x_AMLR_SHIFT 0
  105643. -/* Page 1, Register 2 - analog volume control */
  105644. -#define PCM512x_RAGN_SHIFT 0
  105645. -#define PCM512x_LAGN_SHIFT 4
  105646. -
  105647. -/* Page 1, Register 7 - analog boost control */
  105648. -#define PCM512x_AGBR_SHIFT 0
  105649. -#define PCM512x_AGBL_SHIFT 4
  105650. -
  105651. -extern const struct dev_pm_ops pcm512x_pm_ops;
  105652. -extern const struct regmap_config pcm512x_regmap;
  105653. -
  105654. -int pcm512x_probe(struct device *dev, struct regmap *regmap);
  105655. -void pcm512x_remove(struct device *dev);
  105656. -
  105657. #endif
  105658. diff -Nur linux-3.15.4/sound/soc/codecs/wm8804.c linux-rpi/sound/soc/codecs/wm8804.c
  105659. --- linux-3.15.4/sound/soc/codecs/wm8804.c 2014-07-07 03:59:25.000000000 +0200
  105660. +++ linux-rpi/sound/soc/codecs/wm8804.c 2014-07-07 10:46:03.000000000 +0200
  105661. @@ -63,6 +63,7 @@
  105662. struct regmap *regmap;
  105663. struct regulator_bulk_data supplies[WM8804_NUM_SUPPLIES];
  105664. struct notifier_block disable_nb[WM8804_NUM_SUPPLIES];
  105665. + int mclk_div;
  105666. };
  105667. static int txsrc_get(struct snd_kcontrol *kcontrol,
  105668. @@ -277,6 +278,7 @@
  105669. blen = 0x1;
  105670. break;
  105671. case SNDRV_PCM_FORMAT_S24_LE:
  105672. + case SNDRV_PCM_FORMAT_S32_LE:
  105673. blen = 0x2;
  105674. break;
  105675. default:
  105676. @@ -318,7 +320,7 @@
  105677. #define FIXED_PLL_SIZE ((1ULL << 22) * 10)
  105678. static int pll_factors(struct pll_div *pll_div, unsigned int target,
  105679. - unsigned int source)
  105680. + unsigned int source, unsigned int mclk_div)
  105681. {
  105682. u64 Kpart;
  105683. unsigned long int K, Ndiv, Nmod, tmp;
  105684. @@ -330,7 +332,8 @@
  105685. */
  105686. for (i = 0; i < ARRAY_SIZE(post_table); i++) {
  105687. tmp = target * post_table[i].div;
  105688. - if (tmp >= 90000000 && tmp <= 100000000) {
  105689. + if ((tmp >= 90000000 && tmp <= 100000000) &&
  105690. + (mclk_div == post_table[i].mclkdiv)) {
  105691. pll_div->freqmode = post_table[i].freqmode;
  105692. pll_div->mclkdiv = post_table[i].mclkdiv;
  105693. target *= post_table[i].div;
  105694. @@ -387,8 +390,11 @@
  105695. } else {
  105696. int ret;
  105697. struct pll_div pll_div;
  105698. + struct wm8804_priv *wm8804;
  105699. - ret = pll_factors(&pll_div, freq_out, freq_in);
  105700. + wm8804 = snd_soc_codec_get_drvdata(codec);
  105701. +
  105702. + ret = pll_factors(&pll_div, freq_out, freq_in, wm8804->mclk_div);
  105703. if (ret)
  105704. return ret;
  105705. @@ -452,6 +458,7 @@
  105706. int div_id, int div)
  105707. {
  105708. struct snd_soc_codec *codec;
  105709. + struct wm8804_priv *wm8804;
  105710. codec = dai->codec;
  105711. switch (div_id) {
  105712. @@ -459,6 +466,10 @@
  105713. snd_soc_update_bits(codec, WM8804_PLL5, 0x30,
  105714. (div & 0x3) << 4);
  105715. break;
  105716. + case WM8804_MCLK_DIV:
  105717. + wm8804 = snd_soc_codec_get_drvdata(codec);
  105718. + wm8804->mclk_div = div;
  105719. + break;
  105720. default:
  105721. dev_err(dai->dev, "Unknown clock divider: %d\n", div_id);
  105722. return -EINVAL;
  105723. @@ -633,7 +644,7 @@
  105724. };
  105725. #define WM8804_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
  105726. - SNDRV_PCM_FMTBIT_S24_LE)
  105727. + SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
  105728. #define WM8804_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
  105729. SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | \
  105730. @@ -666,7 +677,7 @@
  105731. .suspend = wm8804_suspend,
  105732. .resume = wm8804_resume,
  105733. .set_bias_level = wm8804_set_bias_level,
  105734. - .idle_bias_off = true,
  105735. + .idle_bias_off = false,
  105736. .controls = wm8804_snd_controls,
  105737. .num_controls = ARRAY_SIZE(wm8804_snd_controls),
  105738. diff -Nur linux-3.15.4/sound/soc/codecs/wm8804.h linux-rpi/sound/soc/codecs/wm8804.h
  105739. --- linux-3.15.4/sound/soc/codecs/wm8804.h 2014-07-07 03:59:25.000000000 +0200
  105740. +++ linux-rpi/sound/soc/codecs/wm8804.h 2014-04-13 17:33:29.000000000 +0200
  105741. @@ -57,5 +57,9 @@
  105742. #define WM8804_CLKOUT_SRC_OSCCLK 4
  105743. #define WM8804_CLKOUT_DIV 1
  105744. +#define WM8804_MCLK_DIV 2
  105745. +
  105746. +#define WM8804_MCLKDIV_256FS 0
  105747. +#define WM8804_MCLKDIV_128FS 1
  105748. #endif /* _WM8804_H */
  105749. diff -Nur linux-3.15.4/sound/soc/soc-core.c linux-rpi/sound/soc/soc-core.c
  105750. --- linux-3.15.4/sound/soc/soc-core.c 2014-07-07 03:59:25.000000000 +0200
  105751. +++ linux-rpi/sound/soc/soc-core.c 2014-07-07 10:46:05.000000000 +0200
  105752. @@ -3024,8 +3024,8 @@
  105753. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  105754. uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
  105755. - uinfo->value.integer.min = 0;
  105756. - uinfo->value.integer.max = platform_max - min;
  105757. + uinfo->value.integer.min = min;
  105758. + uinfo->value.integer.max = platform_max;
  105759. return 0;
  105760. }
  105761. @@ -3056,9 +3056,10 @@
  105762. unsigned int val, val_mask;
  105763. int ret;
  105764. - val = ((ucontrol->value.integer.value[0] + min) & mask);
  105765. if (invert)
  105766. - val = max - val;
  105767. + val = ((max - ucontrol->value.integer.value[0] + min) & mask);
  105768. + else
  105769. + val = (ucontrol->value.integer.value[0] & mask);
  105770. val_mask = mask << shift;
  105771. val = val << shift;
  105772. @@ -3067,9 +3068,10 @@
  105773. return ret;
  105774. if (snd_soc_volsw_is_stereo(mc)) {
  105775. - val = ((ucontrol->value.integer.value[1] + min) & mask);
  105776. if (invert)
  105777. - val = max - val;
  105778. + val = ((max - ucontrol->value.integer.value[1] + min) & mask);
  105779. + else
  105780. + val = (ucontrol->value.integer.value[1] & mask);
  105781. val_mask = mask << shift;
  105782. val = val << shift;
  105783. @@ -3107,18 +3109,14 @@
  105784. (snd_soc_read(codec, reg) >> shift) & mask;
  105785. if (invert)
  105786. ucontrol->value.integer.value[0] =
  105787. - max - ucontrol->value.integer.value[0];
  105788. - ucontrol->value.integer.value[0] =
  105789. - ucontrol->value.integer.value[0] - min;
  105790. + max - ucontrol->value.integer.value[0] + min;
  105791. if (snd_soc_volsw_is_stereo(mc)) {
  105792. ucontrol->value.integer.value[1] =
  105793. (snd_soc_read(codec, rreg) >> shift) & mask;
  105794. if (invert)
  105795. ucontrol->value.integer.value[1] =
  105796. - max - ucontrol->value.integer.value[1];
  105797. - ucontrol->value.integer.value[1] =
  105798. - ucontrol->value.integer.value[1] - min;
  105799. + max - ucontrol->value.integer.value[1] + min;
  105800. }
  105801. return 0;
  105802. diff -Nur linux-3.15.4/sound/usb/card.c linux-rpi/sound/usb/card.c
  105803. --- linux-3.15.4/sound/usb/card.c 2014-07-07 03:59:25.000000000 +0200
  105804. +++ linux-rpi/sound/usb/card.c 2014-07-07 10:46:06.000000000 +0200
  105805. @@ -307,11 +307,6 @@
  105806. static int snd_usb_audio_free(struct snd_usb_audio *chip)
  105807. {
  105808. - struct list_head *p, *n;
  105809. -
  105810. - list_for_each_safe(p, n, &chip->ep_list)
  105811. - snd_usb_endpoint_free(p);
  105812. -
  105813. mutex_destroy(&chip->mutex);
  105814. kfree(chip);
  105815. return 0;
  105816. @@ -590,7 +585,7 @@
  105817. struct snd_usb_audio *chip)
  105818. {
  105819. struct snd_card *card;
  105820. - struct list_head *p;
  105821. + struct list_head *p, *n;
  105822. if (chip == (void *)-1L)
  105823. return;
  105824. @@ -603,16 +598,14 @@
  105825. mutex_lock(&register_mutex);
  105826. chip->num_interfaces--;
  105827. if (chip->num_interfaces <= 0) {
  105828. - struct snd_usb_endpoint *ep;
  105829. -
  105830. snd_card_disconnect(card);
  105831. /* release the pcm resources */
  105832. list_for_each(p, &chip->pcm_list) {
  105833. snd_usb_stream_disconnect(p);
  105834. }
  105835. /* release the endpoint resources */
  105836. - list_for_each_entry(ep, &chip->ep_list, list) {
  105837. - snd_usb_endpoint_release(ep);
  105838. + list_for_each_safe(p, n, &chip->ep_list) {
  105839. + snd_usb_endpoint_free(p);
  105840. }
  105841. /* release the midi resources */
  105842. list_for_each(p, &chip->midi_list) {
  105843. diff -Nur linux-3.15.4/sound/usb/endpoint.c linux-rpi/sound/usb/endpoint.c
  105844. --- linux-3.15.4/sound/usb/endpoint.c 2014-07-07 03:59:25.000000000 +0200
  105845. +++ linux-rpi/sound/usb/endpoint.c 2014-07-07 10:46:06.000000000 +0200
  105846. @@ -987,30 +987,19 @@
  105847. }
  105848. /**
  105849. - * snd_usb_endpoint_release: Tear down an snd_usb_endpoint
  105850. - *
  105851. - * @ep: the endpoint to release
  105852. - *
  105853. - * This function does not care for the endpoint's use count but will tear
  105854. - * down all the streaming URBs immediately.
  105855. - */
  105856. -void snd_usb_endpoint_release(struct snd_usb_endpoint *ep)
  105857. -{
  105858. - release_urbs(ep, 1);
  105859. -}
  105860. -
  105861. -/**
  105862. * snd_usb_endpoint_free: Free the resources of an snd_usb_endpoint
  105863. *
  105864. * @ep: the list header of the endpoint to free
  105865. *
  105866. - * This free all resources of the given ep.
  105867. + * This function does not care for the endpoint's use count but will tear
  105868. + * down all the streaming URBs immediately and free all resources.
  105869. */
  105870. void snd_usb_endpoint_free(struct list_head *head)
  105871. {
  105872. struct snd_usb_endpoint *ep;
  105873. ep = list_entry(head, struct snd_usb_endpoint, list);
  105874. + release_urbs(ep, 1);
  105875. kfree(ep);
  105876. }
  105877. diff -Nur linux-3.15.4/sound/usb/endpoint.h linux-rpi/sound/usb/endpoint.h
  105878. --- linux-3.15.4/sound/usb/endpoint.h 2014-07-07 03:59:25.000000000 +0200
  105879. +++ linux-rpi/sound/usb/endpoint.h 2014-07-07 10:46:06.000000000 +0200
  105880. @@ -23,7 +23,6 @@
  105881. void snd_usb_endpoint_sync_pending_stop(struct snd_usb_endpoint *ep);
  105882. int snd_usb_endpoint_activate(struct snd_usb_endpoint *ep);
  105883. void snd_usb_endpoint_deactivate(struct snd_usb_endpoint *ep);
  105884. -void snd_usb_endpoint_release(struct snd_usb_endpoint *ep);
  105885. void snd_usb_endpoint_free(struct list_head *head);
  105886. int snd_usb_endpoint_implicit_feedback_sink(struct snd_usb_endpoint *ep);